-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdata-lists.tsx
103 lines (98 loc) · 4.03 KB
/
data-lists.tsx
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { useSwapCanisterLists } from '@/hooks/use-swap-canister-lists';
import { Liquidity, toBigNumber } from '@psychedelic/sonic-js';
/**
* Data Lists Section React Component
* Example of a component that displays the swap canister data
*/
export const DataListsSection = () => {
// Use custom hook to get lists
const { tokenList, pairList } = useSwapCanisterLists();
return (
<section>
<h1>Data Lists</h1>
<h2>Tokens</h2>
<div className="card-list">
{tokenList
? // Displaying all token list from swap canister
Object.values(tokenList).map((token) => (
<div className="token-card" key={token.id}>
<h2>{token.symbol}</h2>
<span className="data-row">
<label>Name: </label>
{token.name}
</span>
<span className="data-row">
<label>Id: </label>
{token.id}
</span>
<span className="data-row">
<label>Decimals: </label>
{token.decimals}
</span>
<span className="data-row">
<label>Fee: </label>
{/* Parsing bigint from responses on swap canister */}
{toBigNumber(token.fee)
.applyDecimals(token.decimals)
.toString()}
</span>
<span className="data-row">
<label>Total Supply: </label>
{/* Parsing bigint from responses on swap canister */}
{toBigNumber(token.totalSupply)
.applyDecimals(token.decimals)
.toString()}
</span>
</div>
))
: 'Loading...'}
</div>
<h2>Pairs</h2>
{pairList && tokenList
? /**
* Displaying the pair list by mapping over it with tokens from token list
* The pair list is an object { [token0Id]: { [token1Id]: Pair }}
* So will be repeated and we can verify if a pair exists by doing:
* pairList[token0Id][token1Id]
*/
Object.values(tokenList).map((token) => (
<div key={token.id}>
<h3>{token.symbol} Pairs:</h3>
<div className="card-list">
{Object.values(pairList[token.id]).map((pair) => (
<div className="token-card" key={pair.token1}>
<h2>{tokenList[pair.token1].symbol}</h2>
<span className="data-row">
<label>Total Supply: </label>
{/* The decimals number for a pair can be calculated using Liquidity.getPairDecimals */}
{toBigNumber(pair.totalSupply)
.applyDecimals(Liquidity.PAIR_DECIMALS)
.toString()}
</span>
<span className="data-row">
<label>
{tokenList[pair.token0].symbol} Reserve:
</label>
{/* Parsing bigint from responses on swap canister */}
{toBigNumber(pair.reserve0)
.applyDecimals(tokenList[pair.token0].decimals)
.toString()}
</span>
<span className="data-row">
<label>
{tokenList[pair.token1].symbol} Reserve:
</label>
{/* Parsing bigint from responses on swap canister */}
{toBigNumber(pair.reserve1)
.applyDecimals(tokenList[pair.token1].decimals)
.toString()}
</span>
</div>
))}
</div>
</div>
))
: 'Loading...'}
</section>
);
};