@mezo-org/passport 0.4.0-dev.8 → 0.4.0-dev.81
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 +7 -3
- package/dist/src/api/auth.d.ts.map +1 -1
- package/dist/src/api/auth.js +3 -1
- package/dist/src/api/auth.js.map +1 -1
- package/dist/src/api/client.d.ts +4 -1
- package/dist/src/api/client.d.ts.map +1 -1
- package/dist/src/api/client.js +9 -2
- package/dist/src/api/client.js.map +1 -1
- package/dist/src/api/portal.d.ts +3 -9
- package/dist/src/api/portal.d.ts.map +1 -1
- package/dist/src/api/portal.js +8 -5
- package/dist/src/api/portal.js.map +1 -1
- package/dist/src/components/Dropdown/ConnectedTrigger.d.ts +2 -1
- package/dist/src/components/Dropdown/ConnectedTrigger.d.ts.map +1 -1
- package/dist/src/components/Dropdown/ConnectedTrigger.js +29 -20
- package/dist/src/components/Dropdown/ConnectedTrigger.js.map +1 -1
- package/dist/src/components/Dropdown/Content.d.ts +19 -5
- package/dist/src/components/Dropdown/Content.d.ts.map +1 -1
- package/dist/src/components/Dropdown/Content.js +19 -61
- package/dist/src/components/Dropdown/Content.js.map +1 -1
- package/dist/src/components/Dropdown/DisconnectedTrigger.d.ts.map +1 -1
- package/dist/src/components/Dropdown/DisconnectedTrigger.js +2 -2
- package/dist/src/components/Dropdown/DisconnectedTrigger.js.map +1 -1
- package/dist/src/components/Dropdown/Dropdown.d.ts +13 -6
- package/dist/src/components/Dropdown/Dropdown.d.ts.map +1 -1
- package/dist/src/components/Dropdown/Dropdown.js +32 -9
- 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/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/{AccountBalance.d.ts → Root/AccountBalance.d.ts} +2 -1
- 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/{AccountAddress.js → Root/WalletAddress.js} +21 -15
- package/dist/src/components/Dropdown/Root/WalletAddress.js.map +1 -0
- package/dist/src/components/Dropdown/{WelcomeBlock.d.ts → Root/WelcomeBlock.d.ts} +1 -1
- package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts.map +1 -0
- package/dist/src/components/Dropdown/{WelcomeBlock.js → Root/WelcomeBlock.js} +5 -5
- 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/config.d.ts +29 -6
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +88 -15
- package/dist/src/config.js.map +1 -1
- package/dist/src/constants.d.ts +13 -3
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +14 -4
- package/dist/src/constants.js.map +1 -1
- package/dist/src/hooks/index.d.ts +4 -0
- package/dist/src/hooks/index.d.ts.map +1 -1
- package/dist/src/hooks/index.js +4 -0
- package/dist/src/hooks/index.js.map +1 -1
- package/dist/src/hooks/useAssetsConversionRates.d.ts +23 -0
- package/dist/src/hooks/useAssetsConversionRates.d.ts.map +1 -0
- package/dist/src/hooks/useAssetsConversionRates.js +90 -0
- package/dist/src/hooks/useAssetsConversionRates.js.map +1 -0
- package/dist/src/hooks/useAuthenticateWithWallet.d.ts +13 -13
- package/dist/src/hooks/useAuthenticateWithWallet.d.ts.map +1 -1
- package/dist/src/hooks/useAuthenticateWithWallet.js +8 -7
- package/dist/src/hooks/useAuthenticateWithWallet.js.map +1 -1
- package/dist/src/hooks/useBorrowData.d.ts +82 -0
- package/dist/src/hooks/useBorrowData.d.ts.map +1 -0
- package/dist/src/hooks/useBorrowData.js +159 -0
- package/dist/src/hooks/useBorrowData.js.map +1 -0
- package/dist/src/hooks/useCreateAccount.d.ts.map +1 -1
- package/dist/src/hooks/useCreateAccount.js +22 -1
- package/dist/src/hooks/useCreateAccount.js.map +1 -1
- package/dist/src/hooks/useDropdownData.d.ts +37 -34
- package/dist/src/hooks/useDropdownData.d.ts.map +1 -1
- package/dist/src/hooks/useDropdownData.js +85 -61
- package/dist/src/hooks/useDropdownData.js.map +1 -1
- package/dist/src/hooks/useLinkAccount.d.ts +19 -13
- package/dist/src/hooks/useLinkAccount.d.ts.map +1 -1
- package/dist/src/hooks/useLinkAccount.js +20 -1
- package/dist/src/hooks/useLinkAccount.js.map +1 -1
- 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/useSignInWithWallet.d.ts +13 -13
- package/dist/src/hooks/useSignInWithWallet.d.ts.map +1 -1
- package/dist/src/hooks/useSignUpWithWallet.d.ts +13 -13
- package/dist/src/hooks/useSignUpWithWallet.d.ts.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/useValidateMezoId.d.ts +8 -0
- package/dist/src/hooks/useValidateMezoId.d.ts.map +1 -0
- package/dist/src/hooks/useValidateMezoId.js +24 -0
- package/dist/src/hooks/useValidateMezoId.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 +19 -15
- package/dist/src/hooks/useWalletAccount.js.map +1 -1
- 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 +62 -0
- package/dist/src/lib/contracts/index.js.map +1 -0
- package/dist/src/lib/contracts/priceOracle.d.ts +43 -0
- package/dist/src/lib/contracts/priceOracle.d.ts.map +1 -0
- package/dist/src/lib/contracts/priceOracle.js +52 -0
- package/dist/src/lib/contracts/priceOracle.js.map +1 -0
- package/dist/src/provider.js +1 -1
- 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 +1 -1
- package/dist/src/utils/address.d.ts.map +1 -1
- package/dist/src/utils/address.js +2 -0
- package/dist/src/utils/address.js.map +1 -1
- package/dist/src/utils/address.test.js +8 -5
- package/dist/src/utils/address.test.js.map +1 -1
- 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 +87 -31
- package/dist/src/utils/cryptoAssets.js.map +1 -1
- package/dist/src/utils/cryptoAssets.test.js +51 -33
- package/dist/src/utils/cryptoAssets.test.js.map +1 -1
- package/dist/src/utils/currency.d.ts +8 -0
- package/dist/src/utils/currency.d.ts.map +1 -1
- package/dist/src/utils/currency.js +11 -0
- package/dist/src/utils/currency.js.map +1 -1
- package/dist/src/utils/currency.test.js +1 -0
- package/dist/src/utils/currency.test.js.map +1 -1
- package/dist/src/utils/mezoId.d.ts +7 -0
- package/dist/src/utils/mezoId.d.ts.map +1 -0
- package/dist/src/utils/mezoId.js +41 -0
- package/dist/src/utils/mezoId.js.map +1 -0
- package/dist/src/utils/numbers.d.ts +39 -17
- package/dist/src/utils/numbers.d.ts.map +1 -1
- package/dist/src/utils/numbers.js +91 -33
- package/dist/src/utils/numbers.js.map +1 -1
- package/dist/src/utils/numbers.test.js +144 -22
- package/dist/src/utils/numbers.test.js.map +1 -1
- package/dist/src/utils/siww.d.ts +1 -0
- package/dist/src/utils/siww.d.ts.map +1 -1
- package/dist/src/utils/siww.js +50 -12
- package/dist/src/utils/siww.js.map +1 -1
- package/dist/src/utils/wagmi.d.ts +3 -0
- package/dist/src/utils/wagmi.d.ts.map +1 -0
- package/dist/src/utils/wagmi.js +7 -0
- package/dist/src/utils/wagmi.js.map +1 -0
- package/dist/src/wallet/index.d.ts +1 -1
- package/dist/src/wallet/index.d.ts.map +1 -1
- package/dist/src/wallet/index.js +1 -1
- package/dist/src/wallet/index.js.map +1 -1
- package/package.json +10 -8
- package/src/api/auth.ts +8 -4
- package/src/api/client.ts +11 -2
- package/src/api/portal.ts +11 -14
- package/src/components/Dropdown/ConnectedTrigger.tsx +52 -32
- package/src/components/Dropdown/Content.tsx +67 -117
- package/src/components/Dropdown/DisconnectedTrigger.tsx +2 -1
- package/src/components/Dropdown/Dropdown.tsx +75 -15
- package/src/components/Dropdown/ListingItem.tsx +80 -0
- package/src/components/Dropdown/NestedViewLayout.tsx +75 -0
- package/src/components/Dropdown/README.md +10 -18
- 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/{WelcomeBlock.tsx → Root/WelcomeBlock.tsx} +5 -6
- package/src/components/Dropdown/TestnetTopBanner.tsx +32 -0
- package/src/config.ts +135 -21
- package/src/constants.ts +18 -4
- package/src/hooks/index.ts +7 -0
- package/src/hooks/useAssetsConversionRates.ts +97 -0
- package/src/hooks/useAuthenticateWithWallet.ts +33 -12
- package/src/hooks/useBorrowData.ts +187 -0
- package/src/hooks/useCreateAccount.ts +28 -2
- package/src/hooks/useDropdownData.ts +119 -97
- package/src/hooks/useLinkAccount.ts +36 -4
- package/src/hooks/useRefreshPassport.ts +56 -0
- package/src/hooks/useSignInWithWallet.ts +2 -2
- package/src/hooks/useSignUpWithWallet.ts +2 -2
- package/src/hooks/useTokensBalances.ts +187 -0
- package/src/hooks/useValidateMezoId.ts +31 -0
- package/src/hooks/useWalletAccount.ts +29 -19
- package/src/hooks/useWatchTransferEvents.ts +74 -0
- package/src/index.ts +13 -1
- package/src/lib/contracts/index.ts +92 -0
- package/src/lib/contracts/priceOracle.ts +53 -0
- package/src/provider.ts +1 -1
- package/src/stores/dropdownStore.ts +20 -0
- package/src/utils/address.test.ts +10 -6
- package/src/utils/address.ts +5 -3
- package/src/utils/cryptoAssets.test.ts +57 -37
- package/src/utils/cryptoAssets.ts +113 -35
- package/src/utils/currency.test.ts +2 -0
- package/src/utils/currency.ts +21 -0
- package/src/utils/mezoId.ts +51 -0
- package/src/utils/numbers.test.ts +181 -23
- package/src/utils/numbers.ts +121 -34
- package/src/utils/siww.ts +71 -16
- package/src/utils/wagmi.ts +12 -0
- package/src/wallet/index.ts +3 -2
- package/dist/src/components/Dropdown/AccountAddress.d.ts +0 -8
- package/dist/src/components/Dropdown/AccountAddress.d.ts.map +0 -1
- package/dist/src/components/Dropdown/AccountAddress.js.map +0 -1
- package/dist/src/components/Dropdown/AccountAssets.d.ts +0 -14
- package/dist/src/components/Dropdown/AccountAssets.d.ts.map +0 -1
- package/dist/src/components/Dropdown/AccountAssets.js +0 -44
- package/dist/src/components/Dropdown/AccountAssets.js.map +0 -1
- package/dist/src/components/Dropdown/AccountBalance.d.ts.map +0 -1
- package/dist/src/components/Dropdown/AccountBalance.js +0 -18
- package/dist/src/components/Dropdown/AccountBalance.js.map +0 -1
- package/dist/src/components/Dropdown/WelcomeBlock.d.ts.map +0 -1
- package/dist/src/components/Dropdown/WelcomeBlock.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 +0 -21
- package/dist/src/hooks/useAssetsUSDConversion.js.map +0 -1
- package/src/components/Dropdown/AccountAddress.tsx +0 -111
- package/src/components/Dropdown/AccountAssets.tsx +0 -110
- package/src/components/Dropdown/AccountBalance.tsx +0 -38
- package/src/hooks/useAssetsUSDConversion.ts +0 -31
|
@@ -1,59 +1,79 @@
|
|
|
1
|
+
import { BitcoinCircle, EthCircle, MUsdCircle02 } from "@mezo-org/mezo-clay"
|
|
1
2
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from "
|
|
7
|
-
|
|
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)
|
|
8
10
|
|
|
9
11
|
describe("getCryptoAsset", () => {
|
|
10
|
-
it("returns the correct asset for '
|
|
11
|
-
const asset = getCryptoAsset("
|
|
12
|
+
it("returns the correct asset for 'BTC (mBTC)'", () => {
|
|
13
|
+
const asset = getCryptoAsset("BTC")
|
|
12
14
|
expect(asset.name).toBe("Bitcoin")
|
|
13
15
|
expect(asset.symbol).toBe("BTC")
|
|
14
|
-
expect(asset.decimals).toBe(
|
|
16
|
+
expect(asset.decimals).toBe(18)
|
|
15
17
|
expect(asset.icon).toBe(BitcoinCircle)
|
|
16
18
|
})
|
|
17
19
|
|
|
18
|
-
it("returns the correct asset for '
|
|
19
|
-
const asset = getCryptoAsset("
|
|
20
|
+
it("returns the correct asset for 'ETH'", () => {
|
|
21
|
+
const asset = getCryptoAsset("ETH")
|
|
20
22
|
expect(asset.name).toBe("Ethereum")
|
|
21
23
|
expect(asset.symbol).toBe("ETH")
|
|
22
24
|
expect(asset.decimals).toBe(18)
|
|
23
25
|
expect(asset.icon).toBe(EthCircle)
|
|
24
26
|
})
|
|
25
27
|
|
|
26
|
-
it("returns the correct asset for '
|
|
27
|
-
const asset = getCryptoAsset("
|
|
28
|
-
expect(asset.name).toBe("
|
|
29
|
-
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")
|
|
30
32
|
expect(asset.decimals).toBe(18)
|
|
31
|
-
expect(asset.icon).toBe(
|
|
33
|
+
expect(asset.icon).toBe(MUsdCircle02)
|
|
32
34
|
})
|
|
35
|
+
})
|
|
33
36
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
+
]
|
|
42
51
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
expect(asset.decimals).toBe(18)
|
|
48
|
-
// FIXME: Test should expect the exact icon component
|
|
49
|
-
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
|
+
})
|
|
50
56
|
})
|
|
57
|
+
})
|
|
51
58
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
+
})
|
|
58
78
|
})
|
|
59
79
|
})
|
|
@@ -2,12 +2,15 @@ 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 { convertToUsd, formatUsd } from "./currency"
|
|
11
|
+
import { fromFixedPointToString } from "./numbers"
|
|
9
12
|
|
|
10
|
-
export type CryptoAssetKey =
|
|
13
|
+
export type CryptoAssetKey = MezoChainToken | "BTC" | "ETH"
|
|
11
14
|
|
|
12
15
|
export type CryptoAsset = {
|
|
13
16
|
name: string
|
|
@@ -16,51 +19,85 @@ export type CryptoAsset = {
|
|
|
16
19
|
decimals: number
|
|
17
20
|
}
|
|
18
21
|
|
|
22
|
+
// TODO: Add actual icons for the assets
|
|
23
|
+
|
|
19
24
|
const CRYPTO_ASSETS: Record<CryptoAssetKey, CryptoAsset> = {
|
|
20
|
-
|
|
25
|
+
BTC: {
|
|
21
26
|
name: "Bitcoin",
|
|
22
27
|
symbol: "BTC",
|
|
23
28
|
icon: BitcoinCircle,
|
|
24
|
-
decimals:
|
|
29
|
+
decimals: 18,
|
|
25
30
|
},
|
|
26
|
-
|
|
31
|
+
ETH: {
|
|
27
32
|
name: "Ethereum",
|
|
28
33
|
symbol: "ETH",
|
|
29
34
|
icon: EthCircle,
|
|
30
35
|
decimals: 18,
|
|
31
36
|
},
|
|
32
|
-
|
|
33
|
-
name: "
|
|
34
|
-
symbol: "
|
|
35
|
-
icon:
|
|
37
|
+
MUSD: {
|
|
38
|
+
name: "MUSD",
|
|
39
|
+
symbol: "MUSD",
|
|
40
|
+
icon: MUsdCircle02,
|
|
41
|
+
decimals: 18,
|
|
42
|
+
},
|
|
43
|
+
mDAI: {
|
|
44
|
+
name: "mDAI",
|
|
45
|
+
symbol: "mDAI",
|
|
46
|
+
icon: Cryptocurrency04,
|
|
36
47
|
decimals: 18,
|
|
37
48
|
},
|
|
38
|
-
|
|
39
|
-
name: "
|
|
40
|
-
symbol: "
|
|
41
|
-
icon:
|
|
42
|
-
createElement(BitcoinCircle, {
|
|
43
|
-
...props,
|
|
44
|
-
symbolColor: "#FF8A00",
|
|
45
|
-
color: "#000000",
|
|
46
|
-
}),
|
|
49
|
+
mFBTC: {
|
|
50
|
+
name: "mFBTC",
|
|
51
|
+
symbol: "mFBTC",
|
|
52
|
+
icon: BitcoinCircle,
|
|
47
53
|
decimals: 8,
|
|
48
54
|
},
|
|
49
|
-
|
|
50
|
-
name: "
|
|
51
|
-
symbol: "
|
|
52
|
-
icon:
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
mcbBTC: {
|
|
56
|
+
name: "mcbBTC",
|
|
57
|
+
symbol: "mcbBTC",
|
|
58
|
+
icon: BitcoinCircle,
|
|
59
|
+
decimals: 8,
|
|
60
|
+
},
|
|
61
|
+
mSolvBTC: {
|
|
62
|
+
name: "mSolvBTC",
|
|
63
|
+
symbol: "mSolvBTC",
|
|
64
|
+
icon: BitcoinCircle,
|
|
58
65
|
decimals: 18,
|
|
59
66
|
},
|
|
60
|
-
|
|
61
|
-
name: "
|
|
62
|
-
symbol: "
|
|
63
|
-
icon:
|
|
67
|
+
mswBTC: {
|
|
68
|
+
name: "mswBTC",
|
|
69
|
+
symbol: "mswBTC",
|
|
70
|
+
icon: BitcoinCircle,
|
|
71
|
+
decimals: 8,
|
|
72
|
+
},
|
|
73
|
+
mT: {
|
|
74
|
+
name: "mT",
|
|
75
|
+
symbol: "mT",
|
|
76
|
+
icon: Cryptocurrency04,
|
|
77
|
+
decimals: 18,
|
|
78
|
+
},
|
|
79
|
+
mUSDC: {
|
|
80
|
+
name: "mUSDC",
|
|
81
|
+
symbol: "mUSDC",
|
|
82
|
+
icon: Cryptocurrency04,
|
|
83
|
+
decimals: 6,
|
|
84
|
+
},
|
|
85
|
+
mUSDe: {
|
|
86
|
+
name: "mUSDe",
|
|
87
|
+
symbol: "mUSDe",
|
|
88
|
+
icon: Cryptocurrency04,
|
|
89
|
+
decimals: 18,
|
|
90
|
+
},
|
|
91
|
+
mUSDT: {
|
|
92
|
+
name: "mUSDT",
|
|
93
|
+
symbol: "mUSDT",
|
|
94
|
+
icon: Cryptocurrency04,
|
|
95
|
+
decimals: 6,
|
|
96
|
+
},
|
|
97
|
+
mxSolvBTC: {
|
|
98
|
+
name: "mxSolvBTC",
|
|
99
|
+
symbol: "mxSolvBTC",
|
|
100
|
+
icon: BitcoinCircle,
|
|
64
101
|
decimals: 18,
|
|
65
102
|
},
|
|
66
103
|
}
|
|
@@ -80,7 +117,7 @@ export function getCryptoAsset(key: CryptoAssetKey) {
|
|
|
80
117
|
* @returns True if crypto asset is Bitcoin-like
|
|
81
118
|
*/
|
|
82
119
|
export function isBitcoinLikeCryptoAsset(key: CryptoAssetKey) {
|
|
83
|
-
return
|
|
120
|
+
return /(btc)/i.test(key)
|
|
84
121
|
}
|
|
85
122
|
|
|
86
123
|
/**
|
|
@@ -89,5 +126,46 @@ export function isBitcoinLikeCryptoAsset(key: CryptoAssetKey) {
|
|
|
89
126
|
* @returns True if crypto asset is USD-like
|
|
90
127
|
*/
|
|
91
128
|
export function isUsdLikeCryptoAsset(key: CryptoAssetKey) {
|
|
92
|
-
return
|
|
129
|
+
return /(usd|dai)/i.test(key)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Formats crypto asset to balance details (balance in USD and decimals)
|
|
134
|
+
* @param type The type of crypto asset
|
|
135
|
+
* @param balance The balance of crypto asset
|
|
136
|
+
* @param usdConversionRate The USD conversion rate
|
|
137
|
+
* @returns The balance details
|
|
138
|
+
*/
|
|
139
|
+
export function mapCryptoAssetToDetails(
|
|
140
|
+
type: CryptoAssetKey,
|
|
141
|
+
balance: bigint,
|
|
142
|
+
usdConversionRate: bigint,
|
|
143
|
+
usdConversionRateDecimals: number,
|
|
144
|
+
) {
|
|
145
|
+
const { decimals } = getCryptoAsset(type)
|
|
146
|
+
|
|
147
|
+
const formattedBalance = fromFixedPointToString(
|
|
148
|
+
balance,
|
|
149
|
+
decimals,
|
|
150
|
+
isUsdLikeCryptoAsset(type) ? 2 : 4,
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
const usdBalance = convertToUsd(
|
|
154
|
+
balance,
|
|
155
|
+
decimals,
|
|
156
|
+
usdConversionRate,
|
|
157
|
+
usdConversionRateDecimals,
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
const formattedUsdBalance = formatUsd(usdBalance)
|
|
161
|
+
|
|
162
|
+
return {
|
|
163
|
+
type,
|
|
164
|
+
rawBalance: balance,
|
|
165
|
+
formattedBalance,
|
|
166
|
+
usdBalance,
|
|
167
|
+
formattedUsdBalance,
|
|
168
|
+
}
|
|
93
169
|
}
|
|
170
|
+
|
|
171
|
+
export type DetailedCryptoAsset = ReturnType<typeof mapCryptoAssetToDetails>
|
package/src/utils/currency.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { fromFixedPoint } from "./numbers"
|
|
2
|
+
|
|
1
3
|
const DEFAULT_FORMAT_OPTIONS: Intl.NumberFormatOptions = {
|
|
2
4
|
style: "currency",
|
|
3
5
|
minimumFractionDigits: 2,
|
|
@@ -30,3 +32,22 @@ export function formatCurrency(
|
|
|
30
32
|
export function formatUsd(value: number): string {
|
|
31
33
|
return formatCurrency(value, { currency: "USD" })
|
|
32
34
|
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Converts an asset amount to USD based on a conversion rate and decimals
|
|
38
|
+
* @param assetAmount - The amount of the asset in its smallest unit (e.g., satoshis for BTC)
|
|
39
|
+
* @param conversionRate - The conversion rate from the asset to USD in fixed-point format
|
|
40
|
+
* @param decimals - The number of decimals for the asset
|
|
41
|
+
* @returns - The value in USD as a number
|
|
42
|
+
*/
|
|
43
|
+
export function convertToUsd(
|
|
44
|
+
assetAmount: bigint,
|
|
45
|
+
assetDecimals: number,
|
|
46
|
+
conversionRate: bigint,
|
|
47
|
+
conversionRateDecimals: number,
|
|
48
|
+
): number {
|
|
49
|
+
return fromFixedPoint(
|
|
50
|
+
(assetAmount * conversionRate) / 10n ** BigInt(conversionRateDecimals),
|
|
51
|
+
assetDecimals,
|
|
52
|
+
)
|
|
53
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export type MezoId = `${string}.mezo`
|
|
2
|
+
|
|
3
|
+
// NOTE: This was copied from mezo-portal and is based on the validation from
|
|
4
|
+
// workers/passport-auth/src/utils/mezo-id.ts.
|
|
5
|
+
|
|
6
|
+
// Most of these are restrictions for an DNS hostname label (i.e., the part
|
|
7
|
+
// before/after `.` in a full hostname) as outlined in RFC1034
|
|
8
|
+
// (https://www.rfc-editor.org/rfc/rfc1034).
|
|
9
|
+
//
|
|
10
|
+
// A few addenda are made to ensure that nothing can sneak through that could
|
|
11
|
+
// look like an Ethereum or Bitcoin address.
|
|
12
|
+
export const DISALLOWED_MEZO_ID_PATTERNS: { pattern: RegExp; error: string }[] =
|
|
13
|
+
[
|
|
14
|
+
// RFC1034.
|
|
15
|
+
{ pattern: /^$/, error: "Must not be empty." },
|
|
16
|
+
{ pattern: /^.{16,}$/, error: "Must have 15 characters or fewer." },
|
|
17
|
+
{
|
|
18
|
+
pattern: /^[^A-Za-z]/,
|
|
19
|
+
error: "Must start with one of the letters A-Z or a-z.",
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
pattern: /[^A-Za-z0-9-]/,
|
|
23
|
+
error:
|
|
24
|
+
"Must only use letters or numbers (A-Z, a-z, or 0-9), or hyphen (-).",
|
|
25
|
+
},
|
|
26
|
+
{ pattern: /-$/, error: "Must not end in a hyphen (-)." },
|
|
27
|
+
// On-chain shenanigan avoidance.
|
|
28
|
+
{ pattern: /0x/i, error: "Must not contain 0x." },
|
|
29
|
+
{
|
|
30
|
+
pattern: /^(?:bc1|tb1|[a-z]pub|[a-z]priv)/i,
|
|
31
|
+
error: "Must not start with a Bitcoin magic string.",
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
pattern: /^m[0-9]+$/i,
|
|
35
|
+
error: 'No "m" + "numeric string" prefixes.',
|
|
36
|
+
},
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
export function validateMezoId(mezoId: string): string[] {
|
|
40
|
+
if (!/\.mezo$/.test(mezoId)) {
|
|
41
|
+
return ["Must end with '.mezo'."]
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const mezoIdWithoutSuffix = mezoId.replace(/\.mezo$/, "")
|
|
45
|
+
|
|
46
|
+
const errors = DISALLOWED_MEZO_ID_PATTERNS.flatMap(({ pattern, error }) =>
|
|
47
|
+
pattern.test(mezoIdWithoutSuffix) ? [error] : [],
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
return errors
|
|
51
|
+
}
|
|
@@ -1,38 +1,46 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
formatTokenAmount,
|
|
2
|
+
formatNumberToCompactString,
|
|
4
3
|
fromFixedPoint,
|
|
5
4
|
roundUpNumber,
|
|
5
|
+
formatNumberToLocaleString,
|
|
6
|
+
fromFixedPointToString,
|
|
7
|
+
bigIntMax,
|
|
6
8
|
} from "./numbers"
|
|
7
9
|
|
|
8
|
-
describe("
|
|
10
|
+
describe("formatNumberToCompactString", () => {
|
|
9
11
|
it("formats number less than 1000 with decimals", () => {
|
|
10
|
-
expect(
|
|
12
|
+
expect(formatNumberToCompactString(123.456789, 2)).toBe("123.46")
|
|
11
13
|
})
|
|
12
14
|
|
|
13
15
|
it("formats thousands with K", () => {
|
|
14
|
-
expect(
|
|
16
|
+
expect(formatNumberToCompactString(12_345, 2)).toBe("12.35K")
|
|
15
17
|
})
|
|
16
18
|
|
|
17
19
|
it("formats millions with M", () => {
|
|
18
|
-
expect(
|
|
20
|
+
expect(formatNumberToCompactString(12_345_678, 2)).toBe("12.35M")
|
|
19
21
|
})
|
|
20
22
|
|
|
21
23
|
it("formats billions with B", () => {
|
|
22
|
-
expect(
|
|
24
|
+
expect(formatNumberToCompactString(12_345_678_901, 2)).toBe("12.35B")
|
|
23
25
|
})
|
|
24
26
|
|
|
25
27
|
it("formats trillions with T", () => {
|
|
26
|
-
expect(
|
|
28
|
+
expect(formatNumberToCompactString(12_345_678_901_234, 2)).toBe("12.35T")
|
|
27
29
|
})
|
|
28
30
|
|
|
29
31
|
it("formats bigint as readable number", () => {
|
|
30
|
-
expect(
|
|
32
|
+
expect(formatNumberToCompactString(1234567890123456789n, 2)).toBe(
|
|
33
|
+
"1,234,567.89T",
|
|
34
|
+
)
|
|
31
35
|
})
|
|
32
36
|
|
|
33
37
|
it("caps at > 1000T for huge numbers", () => {
|
|
34
38
|
const hugeNumber = 10 ** 18 // 1e18
|
|
35
|
-
expect(
|
|
39
|
+
expect(formatNumberToCompactString(hugeNumber, 2)).toBe("1,000,000T")
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it("formats numbers with trailing zeros correctly", () => {
|
|
43
|
+
expect(formatNumberToCompactString(1_000, 2)).toBe("1K")
|
|
36
44
|
})
|
|
37
45
|
})
|
|
38
46
|
|
|
@@ -53,7 +61,7 @@ describe("roundUpNumber", () => {
|
|
|
53
61
|
describe("fromFixedPoint", () => {
|
|
54
62
|
it("converts fixed point with 18 decimals to float", () => {
|
|
55
63
|
const raw = 1234567890000000000n // 1.23456789 ETH in 18 decimals
|
|
56
|
-
expect(fromFixedPoint(raw, 18
|
|
64
|
+
expect(fromFixedPoint(raw, 18)).toBe(1.2345)
|
|
57
65
|
})
|
|
58
66
|
|
|
59
67
|
it("converts with truncation to 2 decimals", () => {
|
|
@@ -67,23 +75,173 @@ describe("fromFixedPoint", () => {
|
|
|
67
75
|
})
|
|
68
76
|
})
|
|
69
77
|
|
|
70
|
-
describe("
|
|
71
|
-
it("formats zero
|
|
72
|
-
expect(
|
|
73
|
-
|
|
78
|
+
describe("formatNumberToLocaleString", () => {
|
|
79
|
+
it("formats zero with 0 decimals", () => {
|
|
80
|
+
expect(formatNumberToLocaleString(0, 0)).toBe("0")
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it("formats zero with >0 decimals", () => {
|
|
84
|
+
expect(formatNumberToLocaleString(0, 2)).toBe("0.00")
|
|
85
|
+
expect(formatNumberToLocaleString(0, 4)).toBe("0.0000")
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it("formats small decimal number", () => {
|
|
89
|
+
expect(formatNumberToLocaleString(0.123456, 2)).toBe("0.12")
|
|
90
|
+
expect(formatNumberToLocaleString(0.123456, 4)).toBe("0.1235")
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it("formats number just above 1", () => {
|
|
94
|
+
expect(formatNumberToLocaleString(1.000001, 3)).toBe("1.000")
|
|
95
|
+
expect(formatNumberToLocaleString(1.234567, 2)).toBe("1.23")
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
it("formats whole number", () => {
|
|
99
|
+
expect(formatNumberToLocaleString(1234, 0)).toBe("1,234")
|
|
100
|
+
expect(formatNumberToLocaleString(1000, 2)).toBe("1,000.00")
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
it("formats number with trailing decimal zeroes", () => {
|
|
104
|
+
expect(formatNumberToLocaleString(10.1, 3)).toBe("10.100")
|
|
105
|
+
expect(formatNumberToLocaleString(5.0, 2)).toBe("5.00")
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
it("formats string input", () => {
|
|
109
|
+
expect(formatNumberToLocaleString("123.456", 2)).toBe("123.46")
|
|
110
|
+
expect(formatNumberToLocaleString("0.00123", 4)).toBe("0.0012")
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
it("formats negative number", () => {
|
|
114
|
+
expect(formatNumberToLocaleString(-123.456, 2)).toBe("-123.46")
|
|
115
|
+
expect(formatNumberToLocaleString("-0.00999", 3)).toBe("-0.010")
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
it("formats large number with commas", () => {
|
|
119
|
+
expect(formatNumberToLocaleString(12345678.9, 2)).toBe("12,345,678.90")
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
it("handles max decimals safely", () => {
|
|
123
|
+
expect(formatNumberToLocaleString(1.123456789, 8)).toBe("1.12345679")
|
|
124
|
+
expect(formatNumberToLocaleString("0.000000000000000001", 18)).toBe(
|
|
125
|
+
"0.000000000000000001",
|
|
126
|
+
)
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
it("defaults to 0 decimals if not passed", () => {
|
|
130
|
+
expect(formatNumberToLocaleString(1234.567)).toBe("1,235") // rounds up by default
|
|
131
|
+
})
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
describe("fromFixedPointToString", () => {
|
|
135
|
+
const toFixedPoint = (num: number) => BigInt(Math.round(num * 1e18))
|
|
136
|
+
|
|
137
|
+
const cases = [
|
|
138
|
+
{ input: 2.0, expected: "2.000" },
|
|
139
|
+
{ input: 2.009, expected: "2.009" },
|
|
140
|
+
{ input: 2.01, expected: "2.010" },
|
|
141
|
+
{ input: 2.015, expected: "2.016" },
|
|
142
|
+
{ input: 2.05, expected: "2.050" },
|
|
143
|
+
{ input: 2.09, expected: "2.090" },
|
|
144
|
+
]
|
|
145
|
+
|
|
146
|
+
describe("withRoundUp: true", () => {
|
|
147
|
+
cases.forEach(({ input, expected }) => {
|
|
148
|
+
it(`formats ${input} → ${expected}`, () => {
|
|
149
|
+
const fixed = toFixedPoint(input)
|
|
150
|
+
expect(fromFixedPointToString(fixed, 18, 3, true)).toBe(expected)
|
|
151
|
+
})
|
|
152
|
+
})
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
describe("withRoundUp: false", () => {
|
|
156
|
+
const noRoundCases = [
|
|
157
|
+
{ input: 2.0099, expected: "2.009" },
|
|
158
|
+
{ input: 2.0159, expected: "2.015" },
|
|
159
|
+
{ input: 2.0101, expected: "2.010" },
|
|
160
|
+
{ input: 2.0199, expected: "2.019" },
|
|
161
|
+
]
|
|
162
|
+
|
|
163
|
+
noRoundCases.forEach(({ input, expected }) => {
|
|
164
|
+
it(`formats ${input} → ${expected} (no rounding)`, () => {
|
|
165
|
+
const fixed = toFixedPoint(input)
|
|
166
|
+
expect(fromFixedPointToString(fixed, 18, 3, false)).toBe(expected)
|
|
167
|
+
})
|
|
168
|
+
})
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
describe("zero handling", () => {
|
|
172
|
+
it("formats 0 → 0.000 (3 decimals)", () => {
|
|
173
|
+
expect(fromFixedPointToString(0n, 18, 3)).toBe("0.000")
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
it("formats 0 → 0.0000 (4 decimals)", () => {
|
|
177
|
+
expect(fromFixedPointToString(0n, 18, 4)).toBe("0.0000")
|
|
178
|
+
})
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
describe("very small numbers below display threshold", () => {
|
|
182
|
+
it("returns <0.0001 for small number (3 decimals)", () => {
|
|
183
|
+
const small = BigInt(123) // ~1.23e-16
|
|
184
|
+
expect(fromFixedPointToString(small, 18, 4)).toBe("<0.0001")
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
it("returns <0.01 for small number with only 2 decimals", () => {
|
|
188
|
+
const tiny = BigInt(9999999999999) // <0.01
|
|
189
|
+
expect(fromFixedPointToString(tiny, 18, 2)).toBe("<0.01")
|
|
190
|
+
})
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
describe("input types", () => {
|
|
194
|
+
it("accepts bigint", () => {
|
|
195
|
+
const amount = 2100000000000000000n
|
|
196
|
+
expect(fromFixedPointToString(amount, 18, 3)).toBe("2.100")
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
it("accepts string", () => {
|
|
200
|
+
expect(fromFixedPointToString("2000000000000000000", 18, 3)).toBe("2.000")
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
it("accepts number", () => {
|
|
204
|
+
expect(fromFixedPointToString(Number("1000000000000000000"), 18, 3)).toBe(
|
|
205
|
+
"1.000",
|
|
206
|
+
)
|
|
207
|
+
})
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
describe("high values", () => {
|
|
211
|
+
it("formats 1_000_000.123456789 correctly", () => {
|
|
212
|
+
const big = toFixedPoint(1_000_000.123456789)
|
|
213
|
+
expect(fromFixedPointToString(big, 18, 6)).toBe("1,000,000.123456")
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
it("formats 1e12 ETH", () => {
|
|
217
|
+
const big = BigInt("1000000000000000000000000000000")
|
|
218
|
+
expect(fromFixedPointToString(big, 18, 2)).toBe("1,000,000,000,000.00")
|
|
219
|
+
})
|
|
220
|
+
})
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
describe("bigIntMax", () => {
|
|
224
|
+
it("returns the maximum of positive bigint values", () => {
|
|
225
|
+
expect(bigIntMax(1n, 2n, 3n)).toBe(3n)
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
it("returns the maximum of negative bigint values", () => {
|
|
229
|
+
expect(bigIntMax(-10n, -5n, -20n)).toBe(-5n)
|
|
230
|
+
})
|
|
231
|
+
|
|
232
|
+
it("returns the only element if array has one bigint", () => {
|
|
233
|
+
expect(bigIntMax(42n)).toBe(42n)
|
|
74
234
|
})
|
|
75
235
|
|
|
76
|
-
it("
|
|
77
|
-
expect(
|
|
236
|
+
it("works with a mix of positive and negative bigints", () => {
|
|
237
|
+
expect(bigIntMax(-100n, 0n, 50n, -10n)).toBe(50n)
|
|
78
238
|
})
|
|
79
239
|
|
|
80
|
-
it("
|
|
81
|
-
|
|
82
|
-
expect(result).toBe("1.23")
|
|
240
|
+
it("throws an error if called with no arguments", () => {
|
|
241
|
+
expect(() => bigIntMax()).toThrow()
|
|
83
242
|
})
|
|
84
243
|
|
|
85
|
-
it("
|
|
86
|
-
|
|
87
|
-
expect(result).toBe("1.24")
|
|
244
|
+
it("returns the correct value when all values are equal", () => {
|
|
245
|
+
expect(bigIntMax(5n, 5n, 5n)).toBe(5n)
|
|
88
246
|
})
|
|
89
247
|
})
|