@mezo-org/passport 0.4.0-dev.4 → 0.4.0-dev.42
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/auth.d.ts +36 -59
- package/dist/src/api/auth.d.ts.map +1 -1
- package/dist/src/api/auth.js +21 -49
- package/dist/src/api/auth.js.map +1 -1
- package/dist/src/api/client.d.ts +24 -0
- package/dist/src/api/client.d.ts.map +1 -0
- package/dist/src/api/client.js +54 -0
- package/dist/src/api/client.js.map +1 -0
- package/dist/src/api/fetch-error.d.ts +5 -0
- package/dist/src/api/fetch-error.d.ts.map +1 -0
- package/dist/src/api/fetch-error.js +8 -0
- package/dist/src/api/fetch-error.js.map +1 -0
- package/dist/src/api/index.d.ts +3 -0
- package/dist/src/api/index.d.ts.map +1 -0
- package/dist/src/api/index.js +3 -0
- package/dist/src/api/index.js.map +1 -0
- package/dist/src/api/portal.d.ts +33 -0
- package/dist/src/api/portal.d.ts.map +1 -0
- package/dist/src/api/portal.js +23 -0
- package/dist/src/api/portal.js.map +1 -0
- package/dist/src/assets/DefaultAvatar.d.ts +5 -0
- package/dist/src/assets/DefaultAvatar.d.ts.map +1 -0
- package/dist/src/assets/DefaultAvatar.js +21 -0
- package/dist/src/assets/DefaultAvatar.js.map +1 -0
- package/dist/src/components/Dropdown/ConnectedTrigger.d.ts +8 -0
- package/dist/src/components/Dropdown/ConnectedTrigger.d.ts.map +1 -0
- package/dist/src/components/Dropdown/ConnectedTrigger.js +39 -0
- package/dist/src/components/Dropdown/ConnectedTrigger.js.map +1 -0
- package/dist/src/components/Dropdown/Content.d.ts +23 -0
- package/dist/src/components/Dropdown/Content.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Content.js +27 -0
- package/dist/src/components/Dropdown/Content.js.map +1 -0
- package/dist/src/components/Dropdown/DisconnectedTrigger.d.ts +7 -0
- package/dist/src/components/Dropdown/DisconnectedTrigger.d.ts.map +1 -0
- package/dist/src/components/Dropdown/DisconnectedTrigger.js +13 -0
- package/dist/src/components/Dropdown/DisconnectedTrigger.js.map +1 -0
- package/dist/src/components/Dropdown/Dropdown.d.ts +27 -0
- package/dist/src/components/Dropdown/Dropdown.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Dropdown.js +68 -0
- package/dist/src/components/Dropdown/Dropdown.js.map +1 -0
- 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/NestedViewLayout.d.ts +7 -0
- package/dist/src/components/Dropdown/NestedViewLayout.d.ts.map +1 -0
- package/dist/src/components/Dropdown/NestedViewLayout.js +34 -0
- package/dist/src/components/Dropdown/NestedViewLayout.js.map +1 -0
- package/dist/src/components/Dropdown/Receive/Receive.d.ts +7 -0
- package/dist/src/components/Dropdown/Receive/Receive.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Receive/Receive.js +53 -0
- package/dist/src/components/Dropdown/Receive/Receive.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts +7 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.js +48 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.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 +8 -0
- package/dist/src/components/Dropdown/Root/AccountBalance.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountBalance.js +15 -0
- package/dist/src/components/Dropdown/Root/AccountBalance.js.map +1 -0
- 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 +48 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.js.map +1 -0
- package/dist/src/components/Dropdown/Root/Root.d.ts +23 -0
- package/dist/src/components/Dropdown/Root/Root.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/Root.js +57 -0
- package/dist/src/components/Dropdown/Root/Root.js.map +1 -0
- package/dist/src/components/Dropdown/Root/WalletAddress.d.ts +8 -0
- package/dist/src/components/Dropdown/Root/WalletAddress.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/WalletAddress.js +64 -0
- package/dist/src/components/Dropdown/Root/WalletAddress.js.map +1 -0
- package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts +8 -0
- package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/WelcomeBlock.js +44 -0
- package/dist/src/components/Dropdown/Root/WelcomeBlock.js.map +1 -0
- 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/components/Dropdown/index.d.ts +3 -0
- package/dist/src/components/Dropdown/index.d.ts.map +1 -0
- package/dist/src/components/Dropdown/index.js +2 -0
- package/dist/src/components/Dropdown/index.js.map +1 -0
- package/dist/src/components/index.d.ts +2 -0
- package/dist/src/components/index.d.ts.map +1 -0
- package/dist/src/components/index.js +2 -0
- package/dist/src/components/index.js.map +1 -0
- package/dist/src/config.d.ts +41 -0
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +17 -5
- package/dist/src/config.js.map +1 -1
- package/dist/src/constants.d.ts +6 -2
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +8 -4
- package/dist/src/constants.js.map +1 -1
- package/dist/src/hooks/constants.d.ts +1 -0
- package/dist/src/hooks/constants.d.ts.map +1 -1
- package/dist/src/hooks/constants.js +1 -0
- package/dist/src/hooks/constants.js.map +1 -1
- package/dist/src/hooks/index.d.ts +4 -1
- package/dist/src/hooks/index.d.ts.map +1 -1
- package/dist/src/hooks/index.js +4 -1
- 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/useAssetsConversionRates.js +24 -0
- package/dist/src/hooks/useAssetsConversionRates.js.map +1 -0
- package/dist/src/hooks/useAuthApiClient.d.ts +1 -1
- package/dist/src/hooks/useAuthApiClient.d.ts.map +1 -1
- package/dist/src/hooks/useAuthenticateWithWallet.d.ts +73 -0
- package/dist/src/hooks/useAuthenticateWithWallet.d.ts.map +1 -0
- package/dist/src/hooks/useAuthenticateWithWallet.js +69 -0
- package/dist/src/hooks/useAuthenticateWithWallet.js.map +1 -0
- package/dist/src/hooks/useBorrowData.d.ts +60 -0
- package/dist/src/hooks/useBorrowData.d.ts.map +1 -0
- package/dist/src/hooks/useBorrowData.js +122 -0
- package/dist/src/hooks/useBorrowData.js.map +1 -0
- package/dist/src/hooks/useCreateAccount.d.ts +23 -173
- package/dist/src/hooks/useCreateAccount.d.ts.map +1 -1
- package/dist/src/hooks/useCreateAccount.js +7 -4
- package/dist/src/hooks/useCreateAccount.js.map +1 -1
- package/dist/src/hooks/useCreateSession.d.ts +12 -101
- package/dist/src/hooks/useCreateSession.d.ts.map +1 -1
- package/dist/src/hooks/useCreateSession.js +10 -8
- package/dist/src/hooks/useCreateSession.js.map +1 -1
- package/dist/src/hooks/useDropdownData.d.ts +47 -0
- package/dist/src/hooks/useDropdownData.d.ts.map +1 -0
- package/dist/src/hooks/useDropdownData.js +95 -0
- package/dist/src/hooks/useDropdownData.js.map +1 -0
- package/dist/src/hooks/useEnsureNoSessionAndFetchNonce.d.ts.map +1 -1
- package/dist/src/hooks/useEnsureNoSessionAndFetchNonce.js +1 -0
- package/dist/src/hooks/useEnsureNoSessionAndFetchNonce.js.map +1 -1
- package/dist/src/hooks/useGetAccountByAddress.d.ts +2 -2
- package/dist/src/hooks/useGetAccountByAddress.d.ts.map +1 -1
- package/dist/src/hooks/useGetAccountByMezoId.d.ts +2 -2
- package/dist/src/hooks/useGetAccountByMezoId.d.ts.map +1 -1
- package/dist/src/hooks/useGetCurrentAccount.d.ts +16 -2
- package/dist/src/hooks/useGetCurrentAccount.d.ts.map +1 -1
- package/dist/src/hooks/useGetCurrentAccount.js +25 -3
- package/dist/src/hooks/useGetCurrentAccount.js.map +1 -1
- package/dist/src/hooks/useGetSession.d.ts +1 -1
- package/dist/src/hooks/useGetSession.d.ts.map +1 -1
- package/dist/src/hooks/useLinkAccount.d.ts +15 -175
- package/dist/src/hooks/useLinkAccount.d.ts.map +1 -1
- package/dist/src/hooks/useLinkAccount.js +7 -4
- package/dist/src/hooks/useLinkAccount.js.map +1 -1
- package/dist/src/hooks/usePortalApiClient.d.ts +2 -0
- package/dist/src/hooks/usePortalApiClient.d.ts.map +1 -0
- package/dist/src/hooks/usePortalApiClient.js +6 -0
- package/dist/src/hooks/usePortalApiClient.js.map +1 -0
- package/dist/src/hooks/useRefreshPassport.d.ts +19 -0
- package/dist/src/hooks/useRefreshPassport.d.ts.map +1 -0
- package/dist/src/hooks/useRefreshPassport.js +44 -0
- package/dist/src/hooks/useRefreshPassport.js.map +1 -0
- package/dist/src/hooks/useSignInWithDiscord.d.ts +12 -100
- package/dist/src/hooks/useSignInWithDiscord.d.ts.map +1 -1
- package/dist/src/hooks/useSignInWithDiscord.js +6 -3
- package/dist/src/hooks/useSignInWithDiscord.js.map +1 -1
- package/dist/src/hooks/useSignInWithWallet.d.ts +12 -100
- package/dist/src/hooks/useSignInWithWallet.d.ts.map +1 -1
- package/dist/src/hooks/useSignInWithWallet.js +6 -34
- package/dist/src/hooks/useSignInWithWallet.js.map +1 -1
- package/dist/src/hooks/useSignOut.d.ts +12 -28
- package/dist/src/hooks/useSignOut.d.ts.map +1 -1
- package/dist/src/hooks/useSignOut.js +7 -4
- package/dist/src/hooks/useSignOut.js.map +1 -1
- package/dist/src/hooks/useSignUpWithWallet.d.ts +73 -0
- package/dist/src/hooks/useSignUpWithWallet.d.ts.map +1 -0
- package/dist/src/hooks/useSignUpWithWallet.js +11 -0
- package/dist/src/hooks/useSignUpWithWallet.js.map +1 -0
- 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/useUpdateMezoId.d.ts +30 -136
- package/dist/src/hooks/useUpdateMezoId.d.ts.map +1 -1
- package/dist/src/hooks/useUpdateMezoId.js +7 -4
- package/dist/src/hooks/useUpdateMezoId.js.map +1 -1
- package/dist/src/hooks/useWalletAccount.d.ts +13 -0
- package/dist/src/hooks/useWalletAccount.d.ts.map +1 -0
- package/dist/src/hooks/useWalletAccount.js +29 -0
- package/dist/src/hooks/useWalletAccount.js.map +1 -0
- package/dist/src/hooks/useWatchTransferEvents.d.ts +5 -0
- package/dist/src/hooks/useWatchTransferEvents.d.ts.map +1 -0
- package/dist/src/hooks/useWatchTransferEvents.js +63 -0
- package/dist/src/hooks/useWatchTransferEvents.js.map +1 -0
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib/contracts/index.d.ts +13 -0
- package/dist/src/lib/contracts/index.d.ts.map +1 -0
- package/dist/src/lib/contracts/index.js +57 -0
- package/dist/src/lib/contracts/index.js.map +1 -0
- package/dist/src/provider.d.ts +10 -13
- package/dist/src/provider.d.ts.map +1 -1
- package/dist/src/provider.js +11 -20
- package/dist/src/provider.js.map +1 -1
- package/dist/src/stores/dropdownStore.d.ts +12 -0
- package/dist/src/stores/dropdownStore.d.ts.map +1 -0
- package/dist/src/stores/dropdownStore.js +13 -0
- package/dist/src/stores/dropdownStore.js.map +1 -0
- package/dist/src/utils/address.d.ts +15 -0
- package/dist/src/utils/address.d.ts.map +1 -0
- package/dist/src/utils/address.js +37 -0
- package/dist/src/utils/address.js.map +1 -0
- package/dist/src/utils/address.test.d.ts +2 -0
- package/dist/src/utils/address.test.d.ts.map +1 -0
- package/dist/src/utils/address.test.js +40 -0
- package/dist/src/utils/address.test.js.map +1 -0
- package/dist/src/utils/cryptoAssets.d.ts +44 -0
- package/dist/src/utils/cryptoAssets.d.ts.map +1 -0
- package/dist/src/utils/cryptoAssets.js +131 -0
- package/dist/src/utils/cryptoAssets.js.map +1 -0
- package/dist/src/utils/cryptoAssets.test.d.ts +2 -0
- package/dist/src/utils/cryptoAssets.test.d.ts.map +1 -0
- package/dist/src/utils/cryptoAssets.test.js +67 -0
- package/dist/src/utils/cryptoAssets.test.js.map +1 -0
- package/dist/src/utils/currency.d.ts +14 -0
- package/dist/src/utils/currency.d.ts.map +1 -0
- package/dist/src/utils/currency.js +27 -0
- package/dist/src/utils/currency.js.map +1 -0
- package/dist/src/utils/currency.test.d.ts +2 -0
- package/dist/src/utils/currency.test.d.ts.map +1 -0
- package/dist/src/utils/currency.test.js +34 -0
- package/dist/src/utils/currency.test.js.map +1 -0
- package/dist/src/utils/numbers.d.ts +58 -0
- package/dist/src/utils/numbers.d.ts.map +1 -0
- package/dist/src/utils/numbers.js +132 -0
- package/dist/src/utils/numbers.js.map +1 -0
- package/dist/src/utils/numbers.test.d.ts +2 -0
- package/dist/src/utils/numbers.test.d.ts.map +1 -0
- package/dist/src/utils/numbers.test.js +170 -0
- package/dist/src/utils/numbers.test.js.map +1 -0
- package/package.json +13 -5
- package/src/api/auth.ts +72 -129
- package/src/api/client.ts +78 -0
- package/src/api/fetch-error.ts +8 -0
- package/src/api/index.ts +2 -0
- package/src/api/portal.ts +57 -0
- package/src/assets/DefaultAvatar.tsx +74 -0
- package/src/components/Dropdown/ConnectedTrigger.tsx +76 -0
- package/src/components/Dropdown/Content.tsx +98 -0
- package/src/components/Dropdown/DisconnectedTrigger.tsx +36 -0
- package/src/components/Dropdown/Dropdown.tsx +148 -0
- package/src/components/Dropdown/ListingItem.tsx +80 -0
- package/src/components/Dropdown/NestedViewLayout.tsx +75 -0
- package/src/components/Dropdown/README.md +41 -0
- package/src/components/Dropdown/Receive/Receive.tsx +119 -0
- package/src/components/Dropdown/Root/AccountAddressActions.tsx +101 -0
- package/src/components/Dropdown/Root/AccountAssetItem.tsx +26 -0
- package/src/components/Dropdown/Root/AccountBalance.tsx +30 -0
- package/src/components/Dropdown/Root/AccountOtherAssets.tsx +68 -0
- package/src/components/Dropdown/Root/Root.tsx +147 -0
- package/src/components/Dropdown/Root/WalletAddress.tsx +128 -0
- package/src/components/Dropdown/Root/WelcomeBlock.tsx +91 -0
- package/src/components/Dropdown/TestnetTopBanner.tsx +32 -0
- package/src/components/Dropdown/index.ts +2 -0
- package/src/components/index.ts +1 -0
- package/src/config.ts +24 -6
- package/src/constants.ts +8 -4
- package/src/hooks/constants.ts +1 -0
- package/src/hooks/index.ts +7 -1
- package/src/hooks/useAssetsConversionRates.ts +32 -0
- package/src/hooks/useAuthenticateWithWallet.ts +102 -0
- package/src/hooks/useBorrowData.ts +143 -0
- package/src/hooks/useCreateAccount.ts +19 -5
- package/src/hooks/useCreateSession.ts +22 -9
- package/src/hooks/useDropdownData.ts +139 -0
- package/src/hooks/useEnsureNoSessionAndFetchNonce.ts +1 -0
- package/src/hooks/useGetAccountByAddress.ts +2 -2
- package/src/hooks/useGetAccountByMezoId.ts +2 -2
- package/src/hooks/useGetCurrentAccount.ts +46 -6
- package/src/hooks/useGetSession.ts +1 -1
- package/src/hooks/useLinkAccount.ts +18 -5
- package/src/hooks/usePortalApiClient.ts +6 -0
- package/src/hooks/useRefreshPassport.ts +56 -0
- package/src/hooks/useSignInWithDiscord.ts +14 -5
- package/src/hooks/useSignInWithWallet.ts +14 -42
- package/src/hooks/useSignOut.ts +18 -4
- package/src/hooks/useSignUpWithWallet.ts +21 -0
- package/src/hooks/useTokensBalances.ts +187 -0
- package/src/hooks/useUpdateMezoId.ts +19 -4
- package/src/hooks/useWalletAccount.ts +55 -0
- package/src/hooks/useWatchTransferEvents.ts +74 -0
- package/src/index.ts +9 -1
- package/src/lib/contracts/index.ts +88 -0
- package/src/provider.ts +30 -37
- package/src/stores/dropdownStore.ts +20 -0
- package/src/utils/address.test.ts +48 -0
- package/src/utils/address.ts +45 -0
- package/src/utils/cryptoAssets.test.ts +79 -0
- package/src/utils/cryptoAssets.ts +173 -0
- package/src/utils/currency.test.ts +38 -0
- package/src/utils/currency.ts +32 -0
- package/src/utils/numbers.test.ts +220 -0
- package/src/utils/numbers.ts +188 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { BitcoinCircle, EthCircle, MUsdCircle02 } from "@mezo-org/mezo-clay"
|
|
2
|
+
import {
|
|
3
|
+
CryptoAssetKey,
|
|
4
|
+
getCryptoAsset,
|
|
5
|
+
isBitcoinLikeCryptoAsset,
|
|
6
|
+
isUsdLikeCryptoAsset,
|
|
7
|
+
} from "./cryptoAssets"
|
|
8
|
+
|
|
9
|
+
// FIXME: Test fails if run in full suite (pnpm test) but works when run in isolation (pnpm test cryptoAssets)
|
|
10
|
+
|
|
11
|
+
describe("getCryptoAsset", () => {
|
|
12
|
+
it("returns the correct asset for 'BTC (mBTC)'", () => {
|
|
13
|
+
const asset = getCryptoAsset("BTC")
|
|
14
|
+
expect(asset.name).toBe("Bitcoin")
|
|
15
|
+
expect(asset.symbol).toBe("BTC")
|
|
16
|
+
expect(asset.decimals).toBe(18)
|
|
17
|
+
expect(asset.icon).toBe(BitcoinCircle)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it("returns the correct asset for 'ETH'", () => {
|
|
21
|
+
const asset = getCryptoAsset("ETH")
|
|
22
|
+
expect(asset.name).toBe("Ethereum")
|
|
23
|
+
expect(asset.symbol).toBe("ETH")
|
|
24
|
+
expect(asset.decimals).toBe(18)
|
|
25
|
+
expect(asset.icon).toBe(EthCircle)
|
|
26
|
+
})
|
|
27
|
+
|
|
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
|
+
expect(asset.decimals).toBe(18)
|
|
33
|
+
expect(asset.icon).toBe(MUsdCircle02)
|
|
34
|
+
})
|
|
35
|
+
})
|
|
36
|
+
|
|
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
|
+
]
|
|
51
|
+
|
|
52
|
+
cases.forEach(({ input, expected }) => {
|
|
53
|
+
it(`returns ${expected} for ${input}`, () => {
|
|
54
|
+
expect(isBitcoinLikeCryptoAsset(input as CryptoAssetKey)).toBe(expected)
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
|
|
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
|
+
})
|
|
78
|
+
})
|
|
79
|
+
})
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BitcoinCircle,
|
|
3
|
+
EthCircle,
|
|
4
|
+
IconProps,
|
|
5
|
+
MUsdCircle02,
|
|
6
|
+
Cryptocurrency04,
|
|
7
|
+
} from "@mezo-org/mezo-clay"
|
|
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"
|
|
16
|
+
|
|
17
|
+
export type CryptoAssetKey = MezoChainToken | "BTC" | "ETH"
|
|
18
|
+
|
|
19
|
+
export type CryptoAsset = {
|
|
20
|
+
name: string
|
|
21
|
+
symbol: string
|
|
22
|
+
icon: FC<IconProps>
|
|
23
|
+
decimals: number
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// TODO: Add actual icons for the assets
|
|
27
|
+
|
|
28
|
+
const CRYPTO_ASSETS: Record<CryptoAssetKey, CryptoAsset> = {
|
|
29
|
+
BTC: {
|
|
30
|
+
name: "Bitcoin",
|
|
31
|
+
symbol: "BTC",
|
|
32
|
+
icon: BitcoinCircle,
|
|
33
|
+
decimals: 18,
|
|
34
|
+
},
|
|
35
|
+
ETH: {
|
|
36
|
+
name: "Ethereum",
|
|
37
|
+
symbol: "ETH",
|
|
38
|
+
icon: EthCircle,
|
|
39
|
+
decimals: 18,
|
|
40
|
+
},
|
|
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,
|
|
51
|
+
decimals: 18,
|
|
52
|
+
},
|
|
53
|
+
mFBTC: {
|
|
54
|
+
name: "mFBTC",
|
|
55
|
+
symbol: "mFBTC",
|
|
56
|
+
icon: BitcoinCircle,
|
|
57
|
+
decimals: 8,
|
|
58
|
+
},
|
|
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,
|
|
69
|
+
decimals: 18,
|
|
70
|
+
},
|
|
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,
|
|
105
|
+
decimals: 18,
|
|
106
|
+
},
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Gets details of given crypto asset
|
|
111
|
+
* @param key The key of crypto asset
|
|
112
|
+
* @returns The crypto asset details
|
|
113
|
+
*/
|
|
114
|
+
export function getCryptoAsset(key: CryptoAssetKey) {
|
|
115
|
+
return CRYPTO_ASSETS[key]
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Checks if given crypto asset is Bitcoin-like
|
|
120
|
+
* @param key The key of crypto asset
|
|
121
|
+
* @returns True if crypto asset is Bitcoin-like
|
|
122
|
+
*/
|
|
123
|
+
export function isBitcoinLikeCryptoAsset(key: CryptoAssetKey) {
|
|
124
|
+
return /(btc)/i.test(key)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Checks if given crypto asset is USD-like
|
|
129
|
+
* @param key The key of crypto asset
|
|
130
|
+
* @returns True if crypto asset is USD-like
|
|
131
|
+
*/
|
|
132
|
+
export function isUsdLikeCryptoAsset(key: CryptoAssetKey) {
|
|
133
|
+
return /(usd|dai)/i.test(key)
|
|
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>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { formatCurrency, formatUsd } from "./currency"
|
|
2
|
+
|
|
3
|
+
describe("formatCurrency", () => {
|
|
4
|
+
it("formats a number as currency with default options", () => {
|
|
5
|
+
const result = formatCurrency(1234.5, { currency: "EUR" })
|
|
6
|
+
expect(result).toBe("€1,234.50")
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
it("respects minimumFractionDigits (min = 3, max = 3)", () => {
|
|
10
|
+
const result = formatCurrency(1.2, {
|
|
11
|
+
currency: "USD",
|
|
12
|
+
minimumFractionDigits: 3,
|
|
13
|
+
maximumFractionDigits: 3,
|
|
14
|
+
})
|
|
15
|
+
expect(result).toBe("$1.200")
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it("respects maximumFractionDigits (min = 0, max = 1)", () => {
|
|
19
|
+
const result = formatCurrency(1.234567, {
|
|
20
|
+
currency: "USD",
|
|
21
|
+
minimumFractionDigits: 0,
|
|
22
|
+
maximumFractionDigits: 1,
|
|
23
|
+
})
|
|
24
|
+
expect(result).toBe("$1.2")
|
|
25
|
+
})
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
describe("formatUsd", () => {
|
|
29
|
+
it("formats a number as USD", () => {
|
|
30
|
+
const result = formatUsd(99.99)
|
|
31
|
+
expect(result).toBe("$99.99")
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it("formats zero", () => {
|
|
35
|
+
const result = formatUsd(0)
|
|
36
|
+
expect(result).toBe("$0.00")
|
|
37
|
+
})
|
|
38
|
+
})
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const DEFAULT_FORMAT_OPTIONS: Intl.NumberFormatOptions = {
|
|
2
|
+
style: "currency",
|
|
3
|
+
minimumFractionDigits: 2,
|
|
4
|
+
maximumFractionDigits: 2,
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Formats a number as a currency
|
|
9
|
+
* @param value The value to format
|
|
10
|
+
* @param options The options to pass to the formatter
|
|
11
|
+
* @returns The formatted currency
|
|
12
|
+
*/
|
|
13
|
+
export function formatCurrency(
|
|
14
|
+
value: number,
|
|
15
|
+
options: Omit<Intl.NumberFormatOptions, "style"> = {},
|
|
16
|
+
): string {
|
|
17
|
+
const formatter = new Intl.NumberFormat("en-US", {
|
|
18
|
+
...DEFAULT_FORMAT_OPTIONS,
|
|
19
|
+
...options,
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
return formatter.format(value)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Formats a number as a USD currency
|
|
27
|
+
* @param value The value to format
|
|
28
|
+
* @returns The formatted currency
|
|
29
|
+
*/
|
|
30
|
+
export function formatUsd(value: number): string {
|
|
31
|
+
return formatCurrency(value, { currency: "USD" })
|
|
32
|
+
}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import {
|
|
2
|
+
formatNumberToCompactString,
|
|
3
|
+
fromFixedPoint,
|
|
4
|
+
roundUpNumber,
|
|
5
|
+
formatNumberToLocaleString,
|
|
6
|
+
fromFixedPointToString,
|
|
7
|
+
} from "./numbers"
|
|
8
|
+
|
|
9
|
+
describe("formatNumberToCompactString", () => {
|
|
10
|
+
it("formats number less than 1000 with decimals", () => {
|
|
11
|
+
expect(formatNumberToCompactString(123.456789, 2)).toBe("123.46")
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it("formats thousands with K", () => {
|
|
15
|
+
expect(formatNumberToCompactString(12_345, 2)).toBe("12.35K")
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it("formats millions with M", () => {
|
|
19
|
+
expect(formatNumberToCompactString(12_345_678, 2)).toBe("12.35M")
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it("formats billions with B", () => {
|
|
23
|
+
expect(formatNumberToCompactString(12_345_678_901, 2)).toBe("12.35B")
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it("formats trillions with T", () => {
|
|
27
|
+
expect(formatNumberToCompactString(12_345_678_901_234, 2)).toBe("12.35T")
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it("formats bigint as readable number", () => {
|
|
31
|
+
expect(formatNumberToCompactString(1234567890123456789n, 2)).toBe(
|
|
32
|
+
"1,234,567.89T",
|
|
33
|
+
)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it("caps at > 1000T for huge numbers", () => {
|
|
37
|
+
const hugeNumber = 10 ** 18 // 1e18
|
|
38
|
+
expect(formatNumberToCompactString(hugeNumber, 2)).toBe("1,000,000T")
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it("formats numbers with trailing zeros correctly", () => {
|
|
42
|
+
expect(formatNumberToCompactString(1_000, 2)).toBe("1K")
|
|
43
|
+
})
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
describe("roundUpNumber", () => {
|
|
47
|
+
it("rounds up to 2 decimals", () => {
|
|
48
|
+
expect(roundUpNumber(1.234)).toBe(1.24)
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it("rounds up to 3 decimals", () => {
|
|
52
|
+
expect(roundUpNumber(9.87654, 3)).toBe(9.877)
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it("rounds up exact decimal", () => {
|
|
56
|
+
expect(roundUpNumber(2.5, 1)).toBe(2.5)
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
describe("fromFixedPoint", () => {
|
|
61
|
+
it("converts fixed point with 18 decimals to float", () => {
|
|
62
|
+
const raw = 1234567890000000000n // 1.23456789 ETH in 18 decimals
|
|
63
|
+
expect(fromFixedPoint(raw, 18)).toBe(1.2345)
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it("converts with truncation to 2 decimals", () => {
|
|
67
|
+
const raw = 987654321000000000n // ~0.987654321 ETH
|
|
68
|
+
expect(fromFixedPoint(raw, 18, 2)).toBe(0.98)
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it("handles large fixedPoint decimals", () => {
|
|
72
|
+
const raw = 1_000_000_000_000_000_000_000_000n // 1M with 6 decimals
|
|
73
|
+
expect(fromFixedPoint(raw, 6, 2)).toBe(1000000000000000000)
|
|
74
|
+
})
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
describe("formatNumberToLocaleString", () => {
|
|
78
|
+
it("formats zero with 0 decimals", () => {
|
|
79
|
+
expect(formatNumberToLocaleString(0, 0)).toBe("0")
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
it("formats zero with >0 decimals", () => {
|
|
83
|
+
expect(formatNumberToLocaleString(0, 2)).toBe("0.00")
|
|
84
|
+
expect(formatNumberToLocaleString(0, 4)).toBe("0.0000")
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it("formats small decimal number", () => {
|
|
88
|
+
expect(formatNumberToLocaleString(0.123456, 2)).toBe("0.12")
|
|
89
|
+
expect(formatNumberToLocaleString(0.123456, 4)).toBe("0.1235")
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
it("formats number just above 1", () => {
|
|
93
|
+
expect(formatNumberToLocaleString(1.000001, 3)).toBe("1.000")
|
|
94
|
+
expect(formatNumberToLocaleString(1.234567, 2)).toBe("1.23")
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
it("formats whole number", () => {
|
|
98
|
+
expect(formatNumberToLocaleString(1234, 0)).toBe("1,234")
|
|
99
|
+
expect(formatNumberToLocaleString(1000, 2)).toBe("1,000.00")
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
it("formats number with trailing decimal zeroes", () => {
|
|
103
|
+
expect(formatNumberToLocaleString(10.1, 3)).toBe("10.100")
|
|
104
|
+
expect(formatNumberToLocaleString(5.0, 2)).toBe("5.00")
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
it("formats string input", () => {
|
|
108
|
+
expect(formatNumberToLocaleString("123.456", 2)).toBe("123.46")
|
|
109
|
+
expect(formatNumberToLocaleString("0.00123", 4)).toBe("0.0012")
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
it("formats negative number", () => {
|
|
113
|
+
expect(formatNumberToLocaleString(-123.456, 2)).toBe("-123.46")
|
|
114
|
+
expect(formatNumberToLocaleString("-0.00999", 3)).toBe("-0.010")
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
it("formats large number with commas", () => {
|
|
118
|
+
expect(formatNumberToLocaleString(12345678.9, 2)).toBe("12,345,678.90")
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
it("handles max decimals safely", () => {
|
|
122
|
+
expect(formatNumberToLocaleString(1.123456789, 8)).toBe("1.12345679")
|
|
123
|
+
expect(formatNumberToLocaleString("0.000000000000000001", 18)).toBe(
|
|
124
|
+
"0.000000000000000001",
|
|
125
|
+
)
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
it("defaults to 0 decimals if not passed", () => {
|
|
129
|
+
expect(formatNumberToLocaleString(1234.567)).toBe("1,235") // rounds up by default
|
|
130
|
+
})
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
describe("fromFixedPointToString", () => {
|
|
134
|
+
const toFixedPoint = (num: number) => BigInt(Math.round(num * 1e18))
|
|
135
|
+
|
|
136
|
+
const cases = [
|
|
137
|
+
{ input: 2.0, expected: "2.000" },
|
|
138
|
+
{ input: 2.009, expected: "2.009" },
|
|
139
|
+
{ input: 2.01, expected: "2.010" },
|
|
140
|
+
{ input: 2.015, expected: "2.016" },
|
|
141
|
+
{ input: 2.05, expected: "2.050" },
|
|
142
|
+
{ input: 2.09, expected: "2.090" },
|
|
143
|
+
]
|
|
144
|
+
|
|
145
|
+
describe("withRoundUp: true", () => {
|
|
146
|
+
cases.forEach(({ input, expected }) => {
|
|
147
|
+
it(`formats ${input} → ${expected}`, () => {
|
|
148
|
+
const fixed = toFixedPoint(input)
|
|
149
|
+
expect(fromFixedPointToString(fixed, 18, 3, true)).toBe(expected)
|
|
150
|
+
})
|
|
151
|
+
})
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
describe("withRoundUp: false", () => {
|
|
155
|
+
const noRoundCases = [
|
|
156
|
+
{ input: 2.0099, expected: "2.009" },
|
|
157
|
+
{ input: 2.0159, expected: "2.015" },
|
|
158
|
+
{ input: 2.0101, expected: "2.010" },
|
|
159
|
+
{ input: 2.0199, expected: "2.019" },
|
|
160
|
+
]
|
|
161
|
+
|
|
162
|
+
noRoundCases.forEach(({ input, expected }) => {
|
|
163
|
+
it(`formats ${input} → ${expected} (no rounding)`, () => {
|
|
164
|
+
const fixed = toFixedPoint(input)
|
|
165
|
+
expect(fromFixedPointToString(fixed, 18, 3, false)).toBe(expected)
|
|
166
|
+
})
|
|
167
|
+
})
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
describe("zero handling", () => {
|
|
171
|
+
it("formats 0 → 0.000 (3 decimals)", () => {
|
|
172
|
+
expect(fromFixedPointToString(0n, 18, 3)).toBe("0.000")
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
it("formats 0 → 0.0000 (4 decimals)", () => {
|
|
176
|
+
expect(fromFixedPointToString(0n, 18, 4)).toBe("0.0000")
|
|
177
|
+
})
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
describe("very small numbers below display threshold", () => {
|
|
181
|
+
it("returns <0.0001 for small number (3 decimals)", () => {
|
|
182
|
+
const small = BigInt(123) // ~1.23e-16
|
|
183
|
+
expect(fromFixedPointToString(small, 18, 4)).toBe("<0.0001")
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
it("returns <0.01 for small number with only 2 decimals", () => {
|
|
187
|
+
const tiny = BigInt(9999999999999) // <0.01
|
|
188
|
+
expect(fromFixedPointToString(tiny, 18, 2)).toBe("<0.01")
|
|
189
|
+
})
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
describe("input types", () => {
|
|
193
|
+
it("accepts bigint", () => {
|
|
194
|
+
const amount = 2100000000000000000n
|
|
195
|
+
expect(fromFixedPointToString(amount, 18, 3)).toBe("2.100")
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
it("accepts string", () => {
|
|
199
|
+
expect(fromFixedPointToString("2000000000000000000", 18, 3)).toBe("2.000")
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
it("accepts number", () => {
|
|
203
|
+
expect(fromFixedPointToString(Number("1000000000000000000"), 18, 3)).toBe(
|
|
204
|
+
"1.000",
|
|
205
|
+
)
|
|
206
|
+
})
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
describe("high values", () => {
|
|
210
|
+
it("formats 1_000_000.123456789 correctly", () => {
|
|
211
|
+
const big = toFixedPoint(1_000_000.123456789)
|
|
212
|
+
expect(fromFixedPointToString(big, 18, 6)).toBe("1,000,000.123456")
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
it("formats 1e12 ETH", () => {
|
|
216
|
+
const big = BigInt("1000000000000000000000000000000")
|
|
217
|
+
expect(fromFixedPointToString(big, 18, 2)).toBe("1,000,000,000,000.00")
|
|
218
|
+
})
|
|
219
|
+
})
|
|
220
|
+
})
|