forked from Streampay-Org/StreamPay-Frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapping.ts
More file actions
51 lines (46 loc) · 1.71 KB
/
Copy pathmapping.ts
File metadata and controls
51 lines (46 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { OnChainStream } from "./types";
/**
* Documented 1:1 Mapping between DB/UI fields and Contract Storage Keys
*
* | UI Field | Contract Storage Key (Soroban) | Type |
* |--------------------|--------------------------------|-----------|
* | id | id | String |
* | recipient | recipient_address | Address |
* | amount | total_amount | i128 |
* | rate | velocity | i128 |
* | status | status | u32/Enum |
* | lastUpdated | last_update_timestamp | u64 |
*/
export const mapContractToUI = (contractStream: OnChainStream) => {
return {
id: contractStream.id,
recipient: contractStream.recipient_address,
amount: contractStream.total_amount.toString(),
status: contractStream.status,
};
};
export interface MappedStreamState {
id: string;
recipientAddress: string;
totalAmount: bigint;
releasedAmount: bigint;
status: string;
}
export const mapDbStream = (dbStream: any): MappedStreamState => {
return {
id: dbStream.id,
recipientAddress: dbStream.recipient_address,
totalAmount: BigInt(dbStream.total_amount),
releasedAmount: BigInt(dbStream.released_amount),
status: dbStream.status,
};
};
export const mapOnChainStream = (onChainStream: OnChainStream): MappedStreamState => {
return {
id: onChainStream.id,
recipientAddress: onChainStream.recipient_address,
totalAmount: onChainStream.total_amount,
releasedAmount: onChainStream.released_amount,
status: onChainStream.status,
};
};