@mezo-org/passport 0.4.0-dev.20 → 0.4.0-dev.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -22
- package/dist/src/api/portal.d.ts +1 -0
- package/dist/src/api/portal.d.ts.map +1 -1
- package/dist/src/api/portal.js.map +1 -1
- package/dist/src/components/Dropdown/Content.d.ts +16 -2
- package/dist/src/components/Dropdown/Content.d.ts.map +1 -1
- package/dist/src/components/Dropdown/Content.js +5 -3
- package/dist/src/components/Dropdown/Content.js.map +1 -1
- package/dist/src/components/Dropdown/Dropdown.d.ts +1 -5
- package/dist/src/components/Dropdown/Dropdown.d.ts.map +1 -1
- package/dist/src/components/Dropdown/Dropdown.js +7 -6
- package/dist/src/components/Dropdown/Dropdown.js.map +1 -1
- package/dist/src/components/Dropdown/ListingItem.d.ts +13 -0
- package/dist/src/components/Dropdown/ListingItem.d.ts.map +1 -0
- package/dist/src/components/Dropdown/ListingItem.js +34 -0
- package/dist/src/components/Dropdown/ListingItem.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountAssetItem.d.ts +11 -0
- package/dist/src/components/Dropdown/Root/AccountAssetItem.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountAssetItem.js +9 -0
- package/dist/src/components/Dropdown/Root/AccountAssetItem.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountBalance.d.ts +2 -1
- package/dist/src/components/Dropdown/Root/AccountBalance.d.ts.map +1 -1
- package/dist/src/components/Dropdown/Root/AccountBalance.js +7 -8
- package/dist/src/components/Dropdown/Root/AccountBalance.js.map +1 -1
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts +9 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.js +47 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.js.map +1 -0
- package/dist/src/components/Dropdown/Root/Root.d.ts +17 -2
- package/dist/src/components/Dropdown/Root/Root.d.ts.map +1 -1
- package/dist/src/components/Dropdown/Root/Root.js +15 -22
- package/dist/src/components/Dropdown/Root/Root.js.map +1 -1
- package/dist/src/components/Dropdown/Root/WalletAddress.js +5 -6
- package/dist/src/components/Dropdown/Root/WalletAddress.js.map +1 -1
- package/dist/src/components/Dropdown/Root/WelcomeBlock.js +4 -3
- package/dist/src/components/Dropdown/Root/WelcomeBlock.js.map +1 -1
- package/dist/src/components/Dropdown/TestnetTopBanner.d.ts +3 -0
- package/dist/src/components/Dropdown/TestnetTopBanner.d.ts.map +1 -0
- package/dist/src/components/Dropdown/TestnetTopBanner.js +14 -0
- package/dist/src/components/Dropdown/TestnetTopBanner.js.map +1 -0
- package/dist/src/config.js +2 -2
- package/dist/src/config.js.map +1 -1
- package/dist/src/constants.d.ts +2 -1
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +5 -4
- package/dist/src/constants.js.map +1 -1
- package/dist/src/hooks/index.d.ts +2 -0
- package/dist/src/hooks/index.d.ts.map +1 -1
- package/dist/src/hooks/index.js +2 -0
- package/dist/src/hooks/index.js.map +1 -1
- package/dist/src/hooks/useAssetsConversionRates.d.ts +7 -0
- package/dist/src/hooks/useAssetsConversionRates.d.ts.map +1 -0
- package/dist/src/hooks/{useAssetsUSDConversion.js → useAssetsConversionRates.js} +8 -5
- package/dist/src/hooks/useAssetsConversionRates.js.map +1 -0
- package/dist/src/hooks/useAuthenticateWithWallet.d.ts.map +1 -1
- package/dist/src/hooks/useAuthenticateWithWallet.js +4 -4
- package/dist/src/hooks/useAuthenticateWithWallet.js.map +1 -1
- package/dist/src/hooks/useBorrowData.d.ts +1418 -0
- package/dist/src/hooks/useBorrowData.d.ts.map +1 -0
- package/dist/src/hooks/useBorrowData.js +65 -0
- package/dist/src/hooks/useBorrowData.js.map +1 -0
- package/dist/src/hooks/useDropdownData.d.ts +28 -34
- package/dist/src/hooks/useDropdownData.d.ts.map +1 -1
- package/dist/src/hooks/useDropdownData.js +48 -65
- package/dist/src/hooks/useDropdownData.js.map +1 -1
- package/dist/src/hooks/useTokensBalances.d.ts +74 -0
- package/dist/src/hooks/useTokensBalances.d.ts.map +1 -0
- package/dist/src/hooks/useTokensBalances.js +140 -0
- package/dist/src/hooks/useTokensBalances.js.map +1 -0
- package/dist/src/hooks/useWalletAccount.d.ts +2 -1
- package/dist/src/hooks/useWalletAccount.d.ts.map +1 -1
- package/dist/src/hooks/useWalletAccount.js +2 -1
- package/dist/src/hooks/useWalletAccount.js.map +1 -1
- package/dist/src/lib/contracts/index.d.ts +10 -0
- package/dist/src/lib/contracts/index.d.ts.map +1 -0
- package/dist/src/lib/contracts/index.js +49 -0
- package/dist/src/lib/contracts/index.js.map +1 -0
- package/dist/src/lib/contracts/musd.d.ts +107 -0
- package/dist/src/lib/contracts/musd.d.ts.map +1 -0
- package/dist/src/lib/contracts/musd.js +1070 -0
- package/dist/src/lib/contracts/musd.js.map +1 -0
- package/dist/src/lib/contracts/troveManager.d.ts +1401 -0
- package/dist/src/lib/contracts/troveManager.d.ts.map +1 -0
- package/dist/src/lib/contracts/troveManager.js +1820 -0
- package/dist/src/lib/contracts/troveManager.js.map +1 -0
- package/dist/src/utils/cryptoAssets.d.ts +17 -1
- package/dist/src/utils/cryptoAssets.d.ts.map +1 -1
- package/dist/src/utils/cryptoAssets.js +88 -30
- package/dist/src/utils/cryptoAssets.js.map +1 -1
- package/dist/src/utils/cryptoAssets.test.js +47 -30
- package/dist/src/utils/cryptoAssets.test.js.map +1 -1
- package/dist/src/utils/numbers.d.ts +13 -0
- package/dist/src/utils/numbers.d.ts.map +1 -1
- package/dist/src/utils/numbers.js +46 -0
- package/dist/src/utils/numbers.js.map +1 -1
- package/package.json +6 -5
- package/src/api/portal.ts +1 -0
- package/src/components/Dropdown/Content.tsx +47 -11
- package/src/components/Dropdown/Dropdown.tsx +28 -13
- package/src/components/Dropdown/ListingItem.tsx +80 -0
- package/src/components/Dropdown/README.md +0 -14
- package/src/components/Dropdown/Root/AccountAssetItem.tsx +26 -0
- package/src/components/Dropdown/Root/AccountBalance.tsx +13 -18
- package/src/components/Dropdown/Root/AccountOtherAssets.tsx +63 -0
- package/src/components/Dropdown/Root/Root.tsx +59 -53
- package/src/components/Dropdown/Root/WalletAddress.tsx +7 -7
- package/src/components/Dropdown/Root/WelcomeBlock.tsx +3 -3
- package/src/components/Dropdown/TestnetTopBanner.tsx +32 -0
- package/src/config.ts +2 -2
- package/src/constants.ts +5 -4
- package/src/hooks/index.ts +5 -0
- package/src/hooks/{useAssetsUSDConversion.ts → useAssetsConversionRates.ts} +8 -7
- package/src/hooks/useAuthenticateWithWallet.ts +11 -7
- package/src/hooks/useBorrowData.ts +79 -0
- package/src/hooks/useDropdownData.ts +64 -123
- package/src/hooks/useTokensBalances.ts +187 -0
- package/src/hooks/useWalletAccount.ts +4 -2
- package/src/lib/contracts/index.ts +75 -0
- package/src/lib/contracts/musd.ts +1071 -0
- package/src/lib/contracts/troveManager.ts +1819 -0
- package/src/utils/cryptoAssets.test.ts +52 -34
- package/src/utils/cryptoAssets.ts +114 -34
- package/src/utils/numbers.ts +68 -0
- package/dist/src/components/Dropdown/Root/AccountAssets.d.ts +0 -13
- package/dist/src/components/Dropdown/Root/AccountAssets.d.ts.map +0 -1
- package/dist/src/components/Dropdown/Root/AccountAssets.js +0 -43
- package/dist/src/components/Dropdown/Root/AccountAssets.js.map +0 -1
- package/dist/src/hooks/useAssetsUSDConversion.d.ts +0 -8
- package/dist/src/hooks/useAssetsUSDConversion.d.ts.map +0 -1
- package/dist/src/hooks/useAssetsUSDConversion.js.map +0 -1
- package/src/components/Dropdown/Root/AccountAssets.tsx +0 -108
|
@@ -1,16 +1,16 @@
|
|
|
1
|
+
import { BitcoinCircle, EthCircle, MUsdCircle02 } from "@mezo-org/mezo-clay"
|
|
1
2
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from "
|
|
7
|
-
import { getCryptoAsset } from "./cryptoAssets"
|
|
3
|
+
CryptoAssetKey,
|
|
4
|
+
getCryptoAsset,
|
|
5
|
+
isBitcoinLikeCryptoAsset,
|
|
6
|
+
isUsdLikeCryptoAsset,
|
|
7
|
+
} from "./cryptoAssets"
|
|
8
8
|
|
|
9
9
|
// FIXME: Test fails if run in full suite (pnpm test) but works when run in isolation (pnpm test cryptoAssets)
|
|
10
10
|
|
|
11
11
|
describe("getCryptoAsset", () => {
|
|
12
12
|
it("returns the correct asset for 'btc'", () => {
|
|
13
|
-
const asset = getCryptoAsset("
|
|
13
|
+
const asset = getCryptoAsset("BTC")
|
|
14
14
|
expect(asset.name).toBe("Bitcoin")
|
|
15
15
|
expect(asset.symbol).toBe("BTC")
|
|
16
16
|
expect(asset.decimals).toBe(8)
|
|
@@ -18,44 +18,62 @@ describe("getCryptoAsset", () => {
|
|
|
18
18
|
})
|
|
19
19
|
|
|
20
20
|
it("returns the correct asset for 'eth'", () => {
|
|
21
|
-
const asset = getCryptoAsset("
|
|
21
|
+
const asset = getCryptoAsset("ETH")
|
|
22
22
|
expect(asset.name).toBe("Ethereum")
|
|
23
23
|
expect(asset.symbol).toBe("ETH")
|
|
24
24
|
expect(asset.decimals).toBe(18)
|
|
25
25
|
expect(asset.icon).toBe(EthCircle)
|
|
26
26
|
})
|
|
27
27
|
|
|
28
|
-
it("returns the correct asset for '
|
|
29
|
-
const asset = getCryptoAsset("
|
|
30
|
-
expect(asset.name).toBe("
|
|
31
|
-
expect(asset.symbol).toBe("
|
|
28
|
+
it("returns the correct asset for 'musd'", () => {
|
|
29
|
+
const asset = getCryptoAsset("MUSD")
|
|
30
|
+
expect(asset.name).toBe("MUSD")
|
|
31
|
+
expect(asset.symbol).toBe("MUSD")
|
|
32
32
|
expect(asset.decimals).toBe(18)
|
|
33
|
-
expect(asset.icon).toBe(
|
|
33
|
+
expect(asset.icon).toBe(MUsdCircle02)
|
|
34
34
|
})
|
|
35
|
+
})
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
describe("isBitcoinLikeCryptoAsset", () => {
|
|
38
|
+
const cases = [
|
|
39
|
+
{ input: "mcbBTC", expected: true },
|
|
40
|
+
{ input: "mDAI", expected: false },
|
|
41
|
+
{ input: "mFBTC", expected: true },
|
|
42
|
+
{ input: "mSolvBTC", expected: true },
|
|
43
|
+
{ input: "mswBTC", expected: true },
|
|
44
|
+
{ input: "mT", expected: false },
|
|
45
|
+
{ input: "mUSDC", expected: false },
|
|
46
|
+
{ input: "mUSDe", expected: false },
|
|
47
|
+
{ input: "mUSDT", expected: false },
|
|
48
|
+
{ input: "mxSolvBTC", expected: true },
|
|
49
|
+
{ input: "MUSD", expected: false },
|
|
50
|
+
]
|
|
44
51
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
expect(asset.decimals).toBe(18)
|
|
50
|
-
// FIXME: Test should expect the exact icon component
|
|
51
|
-
expect(asset.icon).toEqual(expect.any(Function))
|
|
52
|
+
cases.forEach(({ input, expected }) => {
|
|
53
|
+
it(`returns ${expected} for ${input}`, () => {
|
|
54
|
+
expect(isBitcoinLikeCryptoAsset(input as CryptoAssetKey)).toBe(expected)
|
|
55
|
+
})
|
|
52
56
|
})
|
|
57
|
+
})
|
|
53
58
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
describe("isUsdLikeCryptoAsset", () => {
|
|
60
|
+
const cases = [
|
|
61
|
+
{ input: "mcbBTC", expected: false },
|
|
62
|
+
{ input: "mDAI", expected: true },
|
|
63
|
+
{ input: "mFBTC", expected: false },
|
|
64
|
+
{ input: "mSolvBTC", expected: false },
|
|
65
|
+
{ input: "mswBTC", expected: false },
|
|
66
|
+
{ input: "mT", expected: false },
|
|
67
|
+
{ input: "mUSDC", expected: true },
|
|
68
|
+
{ input: "mUSDe", expected: true },
|
|
69
|
+
{ input: "mUSDT", expected: true },
|
|
70
|
+
{ input: "mxSolvBTC", expected: false },
|
|
71
|
+
{ input: "MUSD", expected: true },
|
|
72
|
+
]
|
|
73
|
+
|
|
74
|
+
cases.forEach(({ input, expected }) => {
|
|
75
|
+
it(`returns ${expected} for ${input}`, () => {
|
|
76
|
+
expect(isUsdLikeCryptoAsset(input as CryptoAssetKey)).toBe(expected)
|
|
77
|
+
})
|
|
60
78
|
})
|
|
61
79
|
})
|
|
@@ -2,12 +2,19 @@ import {
|
|
|
2
2
|
BitcoinCircle,
|
|
3
3
|
EthCircle,
|
|
4
4
|
IconProps,
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
MUsdCircle02,
|
|
6
|
+
Cryptocurrency04,
|
|
7
7
|
} from "@mezo-org/mezo-clay"
|
|
8
|
-
import {
|
|
8
|
+
import { FC } from "react"
|
|
9
|
+
import { MezoChainToken } from "../lib/contracts"
|
|
10
|
+
import { formatUsd } from "./currency"
|
|
11
|
+
import {
|
|
12
|
+
fromFixedPointToString,
|
|
13
|
+
fromFixedPoint,
|
|
14
|
+
fromFloatToBigInt,
|
|
15
|
+
} from "./numbers"
|
|
9
16
|
|
|
10
|
-
export type CryptoAssetKey =
|
|
17
|
+
export type CryptoAssetKey = MezoChainToken | "BTC" | "ETH"
|
|
11
18
|
|
|
12
19
|
export type CryptoAsset = {
|
|
13
20
|
name: string
|
|
@@ -16,51 +23,85 @@ export type CryptoAsset = {
|
|
|
16
23
|
decimals: number
|
|
17
24
|
}
|
|
18
25
|
|
|
26
|
+
// TODO: Add actual icons for the assets
|
|
27
|
+
|
|
19
28
|
const CRYPTO_ASSETS: Record<CryptoAssetKey, CryptoAsset> = {
|
|
20
|
-
|
|
29
|
+
BTC: {
|
|
21
30
|
name: "Bitcoin",
|
|
22
31
|
symbol: "BTC",
|
|
23
32
|
icon: BitcoinCircle,
|
|
24
33
|
decimals: 8,
|
|
25
34
|
},
|
|
26
|
-
|
|
35
|
+
ETH: {
|
|
27
36
|
name: "Ethereum",
|
|
28
37
|
symbol: "ETH",
|
|
29
38
|
icon: EthCircle,
|
|
30
39
|
decimals: 18,
|
|
31
40
|
},
|
|
32
|
-
|
|
33
|
-
name: "
|
|
34
|
-
symbol: "
|
|
35
|
-
icon:
|
|
41
|
+
MUSD: {
|
|
42
|
+
name: "MUSD",
|
|
43
|
+
symbol: "MUSD",
|
|
44
|
+
icon: MUsdCircle02,
|
|
45
|
+
decimals: 18,
|
|
46
|
+
},
|
|
47
|
+
mDAI: {
|
|
48
|
+
name: "mDAI",
|
|
49
|
+
symbol: "mDAI",
|
|
50
|
+
icon: Cryptocurrency04,
|
|
36
51
|
decimals: 18,
|
|
37
52
|
},
|
|
38
|
-
|
|
39
|
-
name: "
|
|
40
|
-
symbol: "
|
|
41
|
-
icon:
|
|
42
|
-
createElement(BitcoinCircle, {
|
|
43
|
-
...props,
|
|
44
|
-
symbolColor: "#FF8A00",
|
|
45
|
-
color: "#000000",
|
|
46
|
-
}),
|
|
53
|
+
mFBTC: {
|
|
54
|
+
name: "mFBTC",
|
|
55
|
+
symbol: "mFBTC",
|
|
56
|
+
icon: BitcoinCircle,
|
|
47
57
|
decimals: 8,
|
|
48
58
|
},
|
|
49
|
-
|
|
50
|
-
name: "
|
|
51
|
-
symbol: "
|
|
52
|
-
icon:
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
59
|
+
mcbBTC: {
|
|
60
|
+
name: "mcbBTC",
|
|
61
|
+
symbol: "mcbBTC",
|
|
62
|
+
icon: BitcoinCircle,
|
|
63
|
+
decimals: 8,
|
|
64
|
+
},
|
|
65
|
+
mSolvBTC: {
|
|
66
|
+
name: "mSolvBTC",
|
|
67
|
+
symbol: "mSolvBTC",
|
|
68
|
+
icon: BitcoinCircle,
|
|
58
69
|
decimals: 18,
|
|
59
70
|
},
|
|
60
|
-
|
|
61
|
-
name: "
|
|
62
|
-
symbol: "
|
|
63
|
-
icon:
|
|
71
|
+
mswBTC: {
|
|
72
|
+
name: "mswBTC",
|
|
73
|
+
symbol: "mswBTC",
|
|
74
|
+
icon: BitcoinCircle,
|
|
75
|
+
decimals: 8,
|
|
76
|
+
},
|
|
77
|
+
mT: {
|
|
78
|
+
name: "mT",
|
|
79
|
+
symbol: "mT",
|
|
80
|
+
icon: Cryptocurrency04,
|
|
81
|
+
decimals: 18,
|
|
82
|
+
},
|
|
83
|
+
mUSDC: {
|
|
84
|
+
name: "mUSDC",
|
|
85
|
+
symbol: "mUSDC",
|
|
86
|
+
icon: Cryptocurrency04,
|
|
87
|
+
decimals: 6,
|
|
88
|
+
},
|
|
89
|
+
mUSDe: {
|
|
90
|
+
name: "mUSDe",
|
|
91
|
+
symbol: "mUSDe",
|
|
92
|
+
icon: Cryptocurrency04,
|
|
93
|
+
decimals: 18,
|
|
94
|
+
},
|
|
95
|
+
mUSDT: {
|
|
96
|
+
name: "mUSDT",
|
|
97
|
+
symbol: "mUSDT",
|
|
98
|
+
icon: Cryptocurrency04,
|
|
99
|
+
decimals: 6,
|
|
100
|
+
},
|
|
101
|
+
mxSolvBTC: {
|
|
102
|
+
name: "mxSolvBTC",
|
|
103
|
+
symbol: "mxSolvBTC",
|
|
104
|
+
icon: BitcoinCircle,
|
|
64
105
|
decimals: 18,
|
|
65
106
|
},
|
|
66
107
|
}
|
|
@@ -80,7 +121,7 @@ export function getCryptoAsset(key: CryptoAssetKey) {
|
|
|
80
121
|
* @returns True if crypto asset is Bitcoin-like
|
|
81
122
|
*/
|
|
82
123
|
export function isBitcoinLikeCryptoAsset(key: CryptoAssetKey) {
|
|
83
|
-
return
|
|
124
|
+
return /(btc)/i.test(key)
|
|
84
125
|
}
|
|
85
126
|
|
|
86
127
|
/**
|
|
@@ -89,5 +130,44 @@ export function isBitcoinLikeCryptoAsset(key: CryptoAssetKey) {
|
|
|
89
130
|
* @returns True if crypto asset is USD-like
|
|
90
131
|
*/
|
|
91
132
|
export function isUsdLikeCryptoAsset(key: CryptoAssetKey) {
|
|
92
|
-
return
|
|
133
|
+
return /(usd|dai)/i.test(key)
|
|
93
134
|
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Formats crypto asset to balance details (balance in USD and decimals)
|
|
138
|
+
* @param type The type of crypto asset
|
|
139
|
+
* @param balance The balance of crypto asset
|
|
140
|
+
* @param usdConversionRate The USD conversion rate
|
|
141
|
+
* @returns The balance details
|
|
142
|
+
*/
|
|
143
|
+
export function mapCryptoAssetToDetails(
|
|
144
|
+
type: CryptoAssetKey,
|
|
145
|
+
balance: bigint,
|
|
146
|
+
usdConversionRate: number,
|
|
147
|
+
) {
|
|
148
|
+
const { decimals } = getCryptoAsset(type)
|
|
149
|
+
|
|
150
|
+
const formattedBalance = fromFixedPointToString(
|
|
151
|
+
balance,
|
|
152
|
+
decimals,
|
|
153
|
+
isUsdLikeCryptoAsset(type) ? 2 : 4,
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
const usdBalance = fromFixedPoint(
|
|
157
|
+
// Native BigInt constructor doesn't support floating point numbers.
|
|
158
|
+
balance * fromFloatToBigInt(usdConversionRate, 0),
|
|
159
|
+
decimals,
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
const formattedUsdBalance = formatUsd(usdBalance)
|
|
163
|
+
|
|
164
|
+
return {
|
|
165
|
+
type,
|
|
166
|
+
rawBalance: balance,
|
|
167
|
+
formattedBalance,
|
|
168
|
+
usdBalance,
|
|
169
|
+
formattedUsdBalance,
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export type DetailedCryptoAsset = ReturnType<typeof mapCryptoAssetToDetails>
|
package/src/utils/numbers.ts
CHANGED
|
@@ -118,3 +118,71 @@ export const fromFixedPointToString = (
|
|
|
118
118
|
: formattedAmount
|
|
119
119
|
return formatNumberToLocaleString(finalFormattedAmount, desiredDecimals)
|
|
120
120
|
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Converts a floating-point number or string to a bigint representation
|
|
124
|
+
* scaled by the specified number of decimal places (default: 18).
|
|
125
|
+
*
|
|
126
|
+
* This function avoids floating-point precision issues by manually
|
|
127
|
+
* parsing and scaling the number.
|
|
128
|
+
*
|
|
129
|
+
* @param amount - A number or string containing a floating point number.
|
|
130
|
+
* @param decimals - Number of decimals to scale to (default: 18).
|
|
131
|
+
* @returns A bigint representation scaled to the given decimal places.
|
|
132
|
+
* @see https://github.com/thesis/mezo-portal/blob/3bd4f39cb77c39948af2886a6ce7415a0c60307a/dapp/src/shared/utils/numbers.ts#L55
|
|
133
|
+
*/
|
|
134
|
+
export const fromFloatToBigInt = (
|
|
135
|
+
amount: string | number,
|
|
136
|
+
decimals = 18,
|
|
137
|
+
): bigint => {
|
|
138
|
+
const FLOATING_POINT_REGEX = /^-?\d{1,3}(,\d{3})*(\.\d+)?$|^-?\d+(\.\d+)?$/
|
|
139
|
+
|
|
140
|
+
const parseToFixedPointNumber = (
|
|
141
|
+
floatingPointString: string,
|
|
142
|
+
): { amount: bigint; decimals: number } | undefined => {
|
|
143
|
+
if (!floatingPointString.match(FLOATING_POINT_REGEX)) {
|
|
144
|
+
return undefined
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const [whole, decimalsPart, ...extra] = floatingPointString.split(".")
|
|
148
|
+
|
|
149
|
+
if (extra.length > 0) return undefined
|
|
150
|
+
|
|
151
|
+
const noThousandsSeparatorWhole = whole.replace(/,/g, "")
|
|
152
|
+
const setDecimals = decimalsPart ?? ""
|
|
153
|
+
|
|
154
|
+
try {
|
|
155
|
+
return {
|
|
156
|
+
amount: BigInt([noThousandsSeparatorWhole, setDecimals].join("")),
|
|
157
|
+
decimals: setDecimals.length,
|
|
158
|
+
}
|
|
159
|
+
} catch {
|
|
160
|
+
return undefined
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const convertFixedPoint = (
|
|
165
|
+
fixedPoint: bigint,
|
|
166
|
+
fixedPointDecimals: number,
|
|
167
|
+
targetDecimals: number,
|
|
168
|
+
): bigint => {
|
|
169
|
+
if (fixedPointDecimals >= targetDecimals) {
|
|
170
|
+
return fixedPoint / 10n ** BigInt(fixedPointDecimals - targetDecimals)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return fixedPoint * 10n ** BigInt(targetDecimals - fixedPointDecimals)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const parsedAmount = amount.toString()
|
|
177
|
+
const fixedPointAmount = parseToFixedPointNumber(parsedAmount)
|
|
178
|
+
|
|
179
|
+
if (typeof fixedPointAmount === "undefined") {
|
|
180
|
+
return 0n
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return convertFixedPoint(
|
|
184
|
+
fixedPointAmount.amount,
|
|
185
|
+
fixedPointAmount.decimals,
|
|
186
|
+
decimals,
|
|
187
|
+
)
|
|
188
|
+
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { CryptoAssetKey } from "../../../utils/cryptoAssets";
|
|
3
|
-
type AccountAssetsProps = {
|
|
4
|
-
label: string | React.ReactNode;
|
|
5
|
-
assets: {
|
|
6
|
-
type: CryptoAssetKey;
|
|
7
|
-
balance: string;
|
|
8
|
-
balanceInUsd: string;
|
|
9
|
-
}[];
|
|
10
|
-
};
|
|
11
|
-
export default function AccountAssets(props: AccountAssetsProps): React.JSX.Element | null;
|
|
12
|
-
export {};
|
|
13
|
-
//# sourceMappingURL=AccountAssets.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AccountAssets.d.ts","sourceRoot":"","sources":["../../../../../src/components/Dropdown/Root/AccountAssets.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAkB,MAAM,OAAO,CAAA;AACtC,OAAO,EAAE,cAAc,EAAkB,MAAM,6BAA6B,CAAA;AAE5E,KAAK,kBAAkB,GAAG;IACxB,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC,SAAS,CAAA;IAC/B,MAAM,EAAE;QACN,IAAI,EAAE,cAAc,CAAA;QACpB,OAAO,EAAE,MAAM,CAAA;QACf,YAAY,EAAE,MAAM,CAAA;KACrB,EAAE,CAAA;CACJ,CAAA;AAED,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,KAAK,EAAE,kBAAkB,4BAyF9D"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { Block, LabelSmall, ParagraphSmall, useStyletron, } from "@mezo-org/mezo-clay";
|
|
2
|
-
import React, { useMemo } from "react";
|
|
3
|
-
import { getCryptoAsset } from "../../../utils/cryptoAssets";
|
|
4
|
-
export default function AccountAssets(props) {
|
|
5
|
-
const { label, assets } = props;
|
|
6
|
-
const [, theme] = useStyletron();
|
|
7
|
-
const assetsData = useMemo(() => assets.map((token) => {
|
|
8
|
-
const { name, symbol, icon } = getCryptoAsset(token.type);
|
|
9
|
-
return {
|
|
10
|
-
...token,
|
|
11
|
-
icon,
|
|
12
|
-
label: name,
|
|
13
|
-
symbol,
|
|
14
|
-
};
|
|
15
|
-
}), [assets]);
|
|
16
|
-
const labelContent = typeof label === "string" ? (React.createElement(ParagraphSmall, { margin: 0, color: theme.colors.gray800 }, label)) : (label);
|
|
17
|
-
if (assetsData.length === 0) {
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
return (React.createElement(Block, { padding: `0 ${theme.sizing.scale500}` },
|
|
21
|
-
React.createElement(Block, { margin: `${theme.sizing.scale400} 0` }, labelContent),
|
|
22
|
-
React.createElement(Block, { as: "ul", marginBottom: theme.sizing.scale600, padding: 0, display: "flex", flexDirection: "column", overrides: {
|
|
23
|
-
Block: {
|
|
24
|
-
style: {
|
|
25
|
-
gap: theme.sizing.scale100,
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
} }, assetsData.map((asset) => (React.createElement(Block, { as: "li", key: `${asset.type}-${asset.balance}`, display: "flex", justifyContent: "space-between", alignItems: "center", margin: `${theme.sizing.scale100} 0` },
|
|
29
|
-
React.createElement(asset.icon, { size: theme.sizing.scale800, overrides: {
|
|
30
|
-
Svg: {
|
|
31
|
-
style: {
|
|
32
|
-
marginRight: theme.sizing.scale500,
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
} }),
|
|
36
|
-
React.createElement(Block, { flex: 1 },
|
|
37
|
-
React.createElement(LabelSmall, { margin: 0 }, asset.label),
|
|
38
|
-
React.createElement(ParagraphSmall, { margin: 0, color: theme.colors.gray500 }, asset.symbol)),
|
|
39
|
-
React.createElement(Block, { display: "flex", alignItems: "end", flexDirection: "column" },
|
|
40
|
-
React.createElement(LabelSmall, { margin: 0 }, asset.balance),
|
|
41
|
-
React.createElement(ParagraphSmall, { margin: 0, color: theme.colors.gray500 }, asset.balanceInUsd))))))));
|
|
42
|
-
}
|
|
43
|
-
//# sourceMappingURL=AccountAssets.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AccountAssets.js","sourceRoot":"","sources":["../../../../../src/components/Dropdown/Root/AccountAssets.tsx"],"names":[],"mappings":"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"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { UseBaseQueryOptions } from "@tanstack/react-query";
|
|
2
|
-
type AssetsUsdConversion = {
|
|
3
|
-
btcUsd: string;
|
|
4
|
-
ethUsd: string;
|
|
5
|
-
};
|
|
6
|
-
export declare function useAssetsUsdConversion(useQueryOptions?: Partial<UseBaseQueryOptions<AssetsUsdConversion>>): import("@tanstack/react-query").UseQueryResult<AssetsUsdConversion, Error>;
|
|
7
|
-
export {};
|
|
8
|
-
//# sourceMappingURL=useAssetsUSDConversion.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useAssetsUSDConversion.d.ts","sourceRoot":"","sources":["../../../src/hooks/useAssetsUSDConversion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAY,MAAM,uBAAuB,CAAA;AAKrE,KAAK,mBAAmB,GAAG;IACzB,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED,wBAAgB,sBAAsB,CACpC,eAAe,GAAE,OAAO,CAAC,mBAAmB,CAAC,mBAAmB,CAAC,CAAM,8EAmBxE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useAssetsUSDConversion.js","sourceRoot":"","sources":["../../../src/hooks/useAssetsUSDConversion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAOzD,MAAM,UAAU,sBAAsB,CACpC,kBAAqE,EAAE;IAEvE,MAAM,eAAe,GAAG,kBAAkB,EAAE,CAAA;IAE5C,OAAO,QAAQ,CAAC;QACd,QAAQ,EAAE,CAAC,UAAU,CAAC,qBAAqB,CAAC;QAC5C,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,MAAM,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,GAC1C,MAAM,eAAe,CAAC,mBAAmB,EAAE,CAAA;YAE7C,OAAO;gBACL,MAAM,EAAE,gBAAgB;gBACxB,MAAM,EAAE,gBAAgB;aACzB,CAAA;QACH,CAAC;QACD,SAAS,EAAE,EAAE,GAAG,aAAa;QAC7B,KAAK,EAAE,CAAC;QACR,GAAG,eAAe;KACnB,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Block,
|
|
3
|
-
LabelSmall,
|
|
4
|
-
ParagraphSmall,
|
|
5
|
-
useStyletron,
|
|
6
|
-
} from "@mezo-org/mezo-clay"
|
|
7
|
-
import React, { useMemo } from "react"
|
|
8
|
-
import { CryptoAssetKey, getCryptoAsset } from "../../../utils/cryptoAssets"
|
|
9
|
-
|
|
10
|
-
type AccountAssetsProps = {
|
|
11
|
-
label: string | React.ReactNode
|
|
12
|
-
assets: {
|
|
13
|
-
type: CryptoAssetKey
|
|
14
|
-
balance: string
|
|
15
|
-
balanceInUsd: string
|
|
16
|
-
}[]
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export default function AccountAssets(props: AccountAssetsProps) {
|
|
20
|
-
const { label, assets } = props
|
|
21
|
-
|
|
22
|
-
const [, theme] = useStyletron()
|
|
23
|
-
|
|
24
|
-
const assetsData = useMemo(
|
|
25
|
-
() =>
|
|
26
|
-
assets.map((token) => {
|
|
27
|
-
const { name, symbol, icon } = getCryptoAsset(token.type)
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
...token,
|
|
31
|
-
icon,
|
|
32
|
-
label: name,
|
|
33
|
-
symbol,
|
|
34
|
-
}
|
|
35
|
-
}),
|
|
36
|
-
[assets],
|
|
37
|
-
)
|
|
38
|
-
|
|
39
|
-
const labelContent =
|
|
40
|
-
typeof label === "string" ? (
|
|
41
|
-
<ParagraphSmall margin={0} color={theme.colors.gray800}>
|
|
42
|
-
{label}
|
|
43
|
-
</ParagraphSmall>
|
|
44
|
-
) : (
|
|
45
|
-
label
|
|
46
|
-
)
|
|
47
|
-
|
|
48
|
-
if (assetsData.length === 0) {
|
|
49
|
-
return null
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return (
|
|
53
|
-
<Block padding={`0 ${theme.sizing.scale500}`}>
|
|
54
|
-
<Block margin={`${theme.sizing.scale400} 0`}>{labelContent}</Block>
|
|
55
|
-
|
|
56
|
-
<Block
|
|
57
|
-
as="ul"
|
|
58
|
-
marginBottom={theme.sizing.scale600}
|
|
59
|
-
padding={0}
|
|
60
|
-
display="flex"
|
|
61
|
-
flexDirection="column"
|
|
62
|
-
overrides={{
|
|
63
|
-
Block: {
|
|
64
|
-
style: {
|
|
65
|
-
gap: theme.sizing.scale100,
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
}}
|
|
69
|
-
>
|
|
70
|
-
{assetsData.map((asset) => (
|
|
71
|
-
<Block
|
|
72
|
-
as="li"
|
|
73
|
-
key={`${asset.type}-${asset.balance}`}
|
|
74
|
-
display="flex"
|
|
75
|
-
justifyContent="space-between"
|
|
76
|
-
alignItems="center"
|
|
77
|
-
margin={`${theme.sizing.scale100} 0`}
|
|
78
|
-
>
|
|
79
|
-
<asset.icon
|
|
80
|
-
size={theme.sizing.scale800}
|
|
81
|
-
overrides={{
|
|
82
|
-
Svg: {
|
|
83
|
-
style: {
|
|
84
|
-
marginRight: theme.sizing.scale500,
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
}}
|
|
88
|
-
/>
|
|
89
|
-
|
|
90
|
-
<Block flex={1}>
|
|
91
|
-
<LabelSmall margin={0}>{asset.label}</LabelSmall>
|
|
92
|
-
<ParagraphSmall margin={0} color={theme.colors.gray500}>
|
|
93
|
-
{asset.symbol}
|
|
94
|
-
</ParagraphSmall>
|
|
95
|
-
</Block>
|
|
96
|
-
|
|
97
|
-
<Block display="flex" alignItems="end" flexDirection="column">
|
|
98
|
-
<LabelSmall margin={0}>{asset.balance}</LabelSmall>
|
|
99
|
-
<ParagraphSmall margin={0} color={theme.colors.gray500}>
|
|
100
|
-
{asset.balanceInUsd}
|
|
101
|
-
</ParagraphSmall>
|
|
102
|
-
</Block>
|
|
103
|
-
</Block>
|
|
104
|
-
))}
|
|
105
|
-
</Block>
|
|
106
|
-
</Block>
|
|
107
|
-
)
|
|
108
|
-
}
|