@mezo-org/passport 0.4.0-dev.9 → 0.5.0
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 +4 -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 +9 -6
- package/dist/src/components/Dropdown/Dropdown.d.ts.map +1 -1
- package/dist/src/components/Dropdown/Dropdown.js +10 -10
- package/dist/src/components/Dropdown/Dropdown.js.map +1 -1
- package/dist/src/components/Dropdown/ListingItem.d.ts +14 -0
- package/dist/src/components/Dropdown/ListingItem.d.ts.map +1 -0
- package/dist/src/components/Dropdown/ListingItem.js +42 -0
- package/dist/src/components/Dropdown/ListingItem.js.map +1 -0
- package/dist/src/components/Dropdown/NestedViewLayout.d.ts +8 -0
- package/dist/src/components/Dropdown/NestedViewLayout.d.ts.map +1 -0
- package/dist/src/components/Dropdown/NestedViewLayout.js +32 -0
- package/dist/src/components/Dropdown/NestedViewLayout.js.map +1 -0
- package/dist/src/components/Dropdown/Receive/Receive.d.ts +4 -0
- package/dist/src/components/Dropdown/Receive/Receive.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Receive/Receive.js +64 -0
- package/dist/src/components/Dropdown/Receive/Receive.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts +4 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.js +49 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountBalance.d.ts +6 -0
- package/dist/src/components/Dropdown/Root/AccountBalance.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountBalance.js +31 -0
- package/dist/src/components/Dropdown/Root/AccountBalance.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountBtcListing.d.ts +6 -0
- package/dist/src/components/Dropdown/Root/AccountBtcListing.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountBtcListing.js +27 -0
- package/dist/src/components/Dropdown/Root/AccountBtcListing.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountError.d.ts +8 -0
- package/dist/src/components/Dropdown/Root/AccountError.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountError.js +17 -0
- package/dist/src/components/Dropdown/Root/AccountError.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountMusdListing.d.ts +4 -0
- package/dist/src/components/Dropdown/Root/AccountMusdListing.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountMusdListing.js +21 -0
- package/dist/src/components/Dropdown/Root/AccountMusdListing.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts +8 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.js +43 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.js.map +1 -0
- package/dist/src/components/Dropdown/Root/Root.d.ts +8 -0
- package/dist/src/components/Dropdown/Root/Root.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/Root.js +45 -0
- package/dist/src/components/Dropdown/Root/Root.js.map +1 -0
- package/dist/src/components/Dropdown/Root/WalletAddress.d.ts +4 -0
- package/dist/src/components/Dropdown/Root/WalletAddress.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/WalletAddress.js +66 -0
- package/dist/src/components/Dropdown/Root/WalletAddress.js.map +1 -0
- package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts +6 -0
- package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/WelcomeBlock.js +88 -0
- package/dist/src/components/Dropdown/Root/WelcomeBlock.js.map +1 -0
- package/dist/src/components/Dropdown/SlotNumber.d.ts +19 -0
- package/dist/src/components/Dropdown/SlotNumber.d.ts.map +1 -0
- package/dist/src/components/Dropdown/SlotNumber.js +67 -0
- package/dist/src/components/Dropdown/SlotNumber.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 +19 -5
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +58 -14
- package/dist/src/config.js.map +1 -1
- package/dist/src/constants.d.ts +11 -3
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +12 -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 +18 -0
- package/dist/src/hooks/useAssetsConversionRates.d.ts.map +1 -0
- package/dist/src/hooks/useAssetsConversionRates.js +67 -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 +9 -8
- package/dist/src/hooks/useAuthenticateWithWallet.js.map +1 -1
- package/dist/src/hooks/useBorrowData.d.ts +108 -0
- package/dist/src/hooks/useBorrowData.d.ts.map +1 -0
- package/dist/src/hooks/useBorrowData.js +201 -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/useGetCurrentAccount.d.ts.map +1 -1
- package/dist/src/hooks/useGetCurrentAccount.js +4 -6
- package/dist/src/hooks/useGetCurrentAccount.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 +75 -0
- package/dist/src/hooks/useTokensBalances.d.ts.map +1 -0
- package/dist/src/hooks/useTokensBalances.js +181 -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 +20 -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 +66 -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.d.ts +7 -1
- package/dist/src/provider.d.ts.map +1 -1
- package/dist/src/provider.js +4 -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/assets.d.ts +145 -0
- package/dist/src/utils/assets.d.ts.map +1 -0
- package/dist/src/utils/assets.js +100 -0
- package/dist/src/utils/assets.js.map +1 -0
- package/dist/src/utils/assets.test.d.ts +2 -0
- package/dist/src/utils/assets.test.d.ts.map +1 -0
- package/dist/src/utils/assets.test.js +46 -0
- package/dist/src/utils/assets.test.js.map +1 -0
- package/dist/src/utils/currency.d.ts +13 -2
- package/dist/src/utils/currency.d.ts.map +1 -1
- package/dist/src/utils/currency.js +22 -8
- package/dist/src/utils/currency.js.map +1 -1
- package/dist/src/utils/currency.test.js +44 -1
- 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 +15 -33
- package/dist/src/utils/numbers.d.ts.map +1 -1
- package/dist/src/utils/numbers.js +26 -70
- package/dist/src/utils/numbers.js.map +1 -1
- package/dist/src/utils/numbers.test.js +46 -42
- 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 +11 -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 +26 -121
- package/src/components/Dropdown/DisconnectedTrigger.tsx +2 -1
- package/src/components/Dropdown/Dropdown.tsx +29 -17
- package/src/components/Dropdown/ListingItem.tsx +176 -0
- package/src/components/Dropdown/NestedViewLayout.tsx +87 -0
- package/src/components/Dropdown/README.md +10 -18
- package/src/components/Dropdown/Receive/Receive.tsx +144 -0
- package/src/components/Dropdown/Root/AccountAddressActions.tsx +99 -0
- package/src/components/Dropdown/Root/AccountBalance.tsx +68 -0
- package/src/components/Dropdown/Root/AccountBtcListing.tsx +52 -0
- package/src/components/Dropdown/Root/AccountError.tsx +34 -0
- package/src/components/Dropdown/Root/AccountMusdListing.tsx +45 -0
- package/src/components/Dropdown/Root/AccountOtherAssets.tsx +85 -0
- package/src/components/Dropdown/Root/Root.tsx +77 -0
- package/src/components/Dropdown/Root/WalletAddress.tsx +123 -0
- package/src/components/Dropdown/Root/WelcomeBlock.tsx +173 -0
- package/src/components/Dropdown/SlotNumber.tsx +131 -0
- package/src/components/Dropdown/TestnetTopBanner.tsx +32 -0
- package/src/config.ts +88 -20
- package/src/constants.ts +12 -4
- package/src/hooks/index.ts +7 -0
- package/src/hooks/useAssetsConversionRates.ts +79 -0
- package/src/hooks/useAuthenticateWithWallet.ts +30 -14
- package/src/hooks/useBorrowData.ts +246 -0
- package/src/hooks/useCreateAccount.ts +29 -2
- package/src/hooks/useGetCurrentAccount.ts +5 -7
- package/src/hooks/useLinkAccount.ts +37 -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 +265 -0
- package/src/hooks/useValidateMezoId.ts +31 -0
- package/src/hooks/useWalletAccount.ts +32 -20
- package/src/hooks/useWatchTransferEvents.ts +74 -0
- package/src/index.ts +12 -1
- package/src/lib/contracts/index.ts +99 -0
- package/src/lib/contracts/priceOracle.ts +53 -0
- package/src/provider.ts +11 -3
- 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/assets.test.ts +57 -0
- package/src/utils/assets.ts +103 -0
- package/src/utils/currency.test.ts +77 -1
- package/src/utils/currency.ts +35 -9
- package/src/utils/mezoId.ts +51 -0
- package/src/utils/numbers.test.ts +49 -42
- package/src/utils/numbers.ts +33 -95
- 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 +0 -58
- 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 +0 -7
- 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 +0 -8
- package/dist/src/components/Dropdown/WelcomeBlock.d.ts.map +0 -1
- package/dist/src/components/Dropdown/WelcomeBlock.js +0 -44
- 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/dist/src/hooks/useDropdownData.d.ts +0 -44
- package/dist/src/hooks/useDropdownData.d.ts.map +0 -1
- package/dist/src/hooks/useDropdownData.js +0 -73
- package/dist/src/hooks/useDropdownData.js.map +0 -1
- package/dist/src/utils/cryptoAssets.d.ts +0 -28
- package/dist/src/utils/cryptoAssets.d.ts.map +0 -1
- package/dist/src/utils/cryptoAssets.js +0 -73
- package/dist/src/utils/cryptoAssets.js.map +0 -1
- package/dist/src/utils/cryptoAssets.test.d.ts +0 -2
- package/dist/src/utils/cryptoAssets.test.d.ts.map +0 -1
- package/dist/src/utils/cryptoAssets.test.js +0 -49
- package/dist/src/utils/cryptoAssets.test.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/components/Dropdown/WelcomeBlock.tsx +0 -92
- package/src/hooks/useAssetsUSDConversion.ts +0 -31
- package/src/hooks/useDropdownData.ts +0 -130
- package/src/utils/cryptoAssets.test.ts +0 -59
- package/src/utils/cryptoAssets.ts +0 -93
|
@@ -10,12 +10,6 @@ describe("trimAddress", () => {
|
|
|
10
10
|
const expected = "0x123...bcdef"
|
|
11
11
|
expect(trimAddress(input)).toBe(expected)
|
|
12
12
|
})
|
|
13
|
-
|
|
14
|
-
it("returns lowercase result", () => {
|
|
15
|
-
const input = "0xABCDEF1234567890"
|
|
16
|
-
const expected = "0xabc...67890"
|
|
17
|
-
expect(trimAddress(input)).toBe(expected)
|
|
18
|
-
})
|
|
19
13
|
})
|
|
20
14
|
|
|
21
15
|
describe("getAddressExplorerUrl", () => {
|
|
@@ -41,4 +35,14 @@ describe("getAddressExplorerUrl", () => {
|
|
|
41
35
|
const url = getAddressExplorerUrl(evmAddress, "evm", true)
|
|
42
36
|
expect(url).toBe(`https://sepolia.etherscan.io/address/${evmAddress}`)
|
|
43
37
|
})
|
|
38
|
+
|
|
39
|
+
it("returns correct mainnet Mezo explorer URL", () => {
|
|
40
|
+
const url = getAddressExplorerUrl(evmAddress, "mezo", false)
|
|
41
|
+
expect(url).toBe(`https://explorer.mezo.org/address/${evmAddress}`)
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it("returns correct testnet Mezo explorer URL", () => {
|
|
45
|
+
const url = getAddressExplorerUrl(evmAddress, "mezo", true)
|
|
46
|
+
expect(url).toBe(`https://explorer.test.mezo.org/address/${evmAddress}`)
|
|
47
|
+
})
|
|
44
48
|
})
|
package/src/utils/address.ts
CHANGED
|
@@ -11,14 +11,16 @@ export function trimAddress(address: string): string {
|
|
|
11
11
|
return trimmedAddress
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
const MAINNET_EXPLORER_URLS: Record<"bitcoin" | "evm", string> = {
|
|
14
|
+
const MAINNET_EXPLORER_URLS: Record<"bitcoin" | "evm" | "mezo", string> = {
|
|
15
15
|
bitcoin: "https://mempool.space",
|
|
16
16
|
evm: "https://etherscan.io",
|
|
17
|
+
mezo: "https://explorer.mezo.org",
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
const TESTNET_EXPLORER_URLS: Record<"bitcoin" | "evm", string> = {
|
|
20
|
+
const TESTNET_EXPLORER_URLS: Record<"bitcoin" | "evm" | "mezo", string> = {
|
|
20
21
|
bitcoin: "https://mempool.space/testnet",
|
|
21
22
|
evm: "https://sepolia.etherscan.io",
|
|
23
|
+
mezo: "https://explorer.test.mezo.org",
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
/**
|
|
@@ -30,7 +32,7 @@ const TESTNET_EXPLORER_URLS: Record<"bitcoin" | "evm", string> = {
|
|
|
30
32
|
*/
|
|
31
33
|
export function getAddressExplorerUrl(
|
|
32
34
|
address: string,
|
|
33
|
-
chainType: "bitcoin" | "evm",
|
|
35
|
+
chainType: "bitcoin" | "evm" | "mezo",
|
|
34
36
|
isTestnet: boolean,
|
|
35
37
|
) {
|
|
36
38
|
const EXPLORER_URLS = isTestnet
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getAsset,
|
|
3
|
+
isBitcoinLikeCryptoAsset,
|
|
4
|
+
isUsdLikeCryptoAsset,
|
|
5
|
+
isTTokenCryptoAsset,
|
|
6
|
+
} from "./assets"
|
|
7
|
+
|
|
8
|
+
describe("getAsset", () => {
|
|
9
|
+
it("should return correct asset data", () => {
|
|
10
|
+
const asset = getAsset("BTC")
|
|
11
|
+
expect(asset).toEqual({
|
|
12
|
+
name: "Bitcoin",
|
|
13
|
+
symbol: "BTC",
|
|
14
|
+
decimals: 18,
|
|
15
|
+
})
|
|
16
|
+
})
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
describe("isBitcoinLikeCryptoAsset", () => {
|
|
20
|
+
it('should return true for keys containing "btc"', () => {
|
|
21
|
+
expect(isBitcoinLikeCryptoAsset("BTC")).toBe(true)
|
|
22
|
+
expect(isBitcoinLikeCryptoAsset("mFBTC")).toBe(true)
|
|
23
|
+
expect(isBitcoinLikeCryptoAsset("mcbBTC")).toBe(true)
|
|
24
|
+
expect(isBitcoinLikeCryptoAsset("mxSolvBTC")).toBe(true)
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it("should return false for non-Bitcoin assets", () => {
|
|
28
|
+
expect(isBitcoinLikeCryptoAsset("ETH")).toBe(false)
|
|
29
|
+
expect(isBitcoinLikeCryptoAsset("mUSDC")).toBe(false)
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
describe("isUsdLikeCryptoAsset", () => {
|
|
34
|
+
it('should return true for keys containing "usd" or "dai"', () => {
|
|
35
|
+
expect(isUsdLikeCryptoAsset("mUSDC")).toBe(true)
|
|
36
|
+
expect(isUsdLikeCryptoAsset("mUSDT")).toBe(true)
|
|
37
|
+
expect(isUsdLikeCryptoAsset("mUSDe")).toBe(true)
|
|
38
|
+
expect(isUsdLikeCryptoAsset("mDAI")).toBe(true)
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it("should return false for other tokens", () => {
|
|
42
|
+
expect(isUsdLikeCryptoAsset("BTC")).toBe(false)
|
|
43
|
+
expect(isUsdLikeCryptoAsset("mT")).toBe(false)
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
describe("isTTokenCryptoAsset", () => {
|
|
48
|
+
it('should return true for keys like "mT" or "t"', () => {
|
|
49
|
+
expect(isTTokenCryptoAsset("mT")).toBe(true)
|
|
50
|
+
expect(isTTokenCryptoAsset("T")).toBe(true)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it("should return false for other tokens", () => {
|
|
54
|
+
expect(isTTokenCryptoAsset("BTC")).toBe(false)
|
|
55
|
+
expect(isTTokenCryptoAsset("mUSDT")).toBe(false)
|
|
56
|
+
})
|
|
57
|
+
})
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
const ASSETS = {
|
|
2
|
+
BTC: {
|
|
3
|
+
name: "Bitcoin",
|
|
4
|
+
symbol: "BTC",
|
|
5
|
+
decimals: 18,
|
|
6
|
+
},
|
|
7
|
+
ETH: {
|
|
8
|
+
name: "Ethereum",
|
|
9
|
+
symbol: "ETH",
|
|
10
|
+
decimals: 18,
|
|
11
|
+
},
|
|
12
|
+
MUSD: {
|
|
13
|
+
name: "MUSD",
|
|
14
|
+
symbol: "MUSD",
|
|
15
|
+
decimals: 18,
|
|
16
|
+
},
|
|
17
|
+
mDAI: {
|
|
18
|
+
name: "Mezo Dai Stablecoin",
|
|
19
|
+
symbol: "mDAI",
|
|
20
|
+
decimals: 18,
|
|
21
|
+
},
|
|
22
|
+
mFBTC: {
|
|
23
|
+
name: "Mezo Fire Bitcoin",
|
|
24
|
+
symbol: "mFBTC",
|
|
25
|
+
decimals: 8,
|
|
26
|
+
},
|
|
27
|
+
mcbBTC: {
|
|
28
|
+
name: "Mezo Coinbase Wrapped BTC",
|
|
29
|
+
symbol: "mcbBTC",
|
|
30
|
+
decimals: 8,
|
|
31
|
+
},
|
|
32
|
+
mSolvBTC: {
|
|
33
|
+
name: "Mezo SolvBTC",
|
|
34
|
+
symbol: "mSolvBTC",
|
|
35
|
+
decimals: 18,
|
|
36
|
+
},
|
|
37
|
+
mswBTC: {
|
|
38
|
+
name: "Mezo swBTC",
|
|
39
|
+
symbol: "mswBTC",
|
|
40
|
+
decimals: 8,
|
|
41
|
+
},
|
|
42
|
+
mT: {
|
|
43
|
+
name: "Mezo Threshold Network Token",
|
|
44
|
+
symbol: "mT",
|
|
45
|
+
decimals: 18,
|
|
46
|
+
},
|
|
47
|
+
mUSDC: {
|
|
48
|
+
name: "Mezo Circle USDC",
|
|
49
|
+
symbol: "mUSDC",
|
|
50
|
+
decimals: 6,
|
|
51
|
+
},
|
|
52
|
+
mUSDe: {
|
|
53
|
+
name: "Mezo Ethena USDe",
|
|
54
|
+
symbol: "mUSDe",
|
|
55
|
+
decimals: 18,
|
|
56
|
+
},
|
|
57
|
+
mUSDT: {
|
|
58
|
+
name: "Mezo Tether USDe",
|
|
59
|
+
symbol: "mUSDT",
|
|
60
|
+
decimals: 6,
|
|
61
|
+
},
|
|
62
|
+
mxSolvBTC: {
|
|
63
|
+
name: "Mezo xSolvBTC",
|
|
64
|
+
symbol: "mxSolvBTC",
|
|
65
|
+
decimals: 18,
|
|
66
|
+
},
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Gets details of given crypto asset
|
|
71
|
+
* @param key The key of crypto asset
|
|
72
|
+
* @returns The crypto asset details
|
|
73
|
+
*/
|
|
74
|
+
export function getAsset(key: keyof typeof ASSETS) {
|
|
75
|
+
return ASSETS[key]
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Checks if given crypto asset is Bitcoin-like
|
|
80
|
+
* @param key The key of crypto asset
|
|
81
|
+
* @returns True if crypto asset is Bitcoin-like
|
|
82
|
+
*/
|
|
83
|
+
export function isBitcoinLikeCryptoAsset(key: string) {
|
|
84
|
+
return /(btc)/i.test(key)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Checks if given crypto asset is USD-like
|
|
89
|
+
* @param key The key of crypto asset
|
|
90
|
+
* @returns True if crypto asset is USD-like
|
|
91
|
+
*/
|
|
92
|
+
export function isUsdLikeCryptoAsset(key: string) {
|
|
93
|
+
return /(usd|dai)/i.test(key)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Checks if given crypto asset is T token
|
|
98
|
+
* @param key The key of crypto asset
|
|
99
|
+
* @returns True if crypto asset is T token
|
|
100
|
+
*/
|
|
101
|
+
export function isTTokenCryptoAsset(key: string) {
|
|
102
|
+
return /^(mt|t)$/i.test(key)
|
|
103
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { formatCurrency, formatUsd } from "./currency"
|
|
1
|
+
import { convertToUsd, formatCurrency, formatUsd } from "./currency"
|
|
2
2
|
|
|
3
3
|
describe("formatCurrency", () => {
|
|
4
4
|
it("formats a number as currency with default options", () => {
|
|
@@ -36,3 +36,79 @@ describe("formatUsd", () => {
|
|
|
36
36
|
expect(result).toBe("$0.00")
|
|
37
37
|
})
|
|
38
38
|
})
|
|
39
|
+
|
|
40
|
+
describe("convertToUsd", () => {
|
|
41
|
+
it("converts 1 BTC (8 decimals) with $30,000 rate (6 decimals)", () => {
|
|
42
|
+
const assetAmount = 1_00000000n // 1 BTC
|
|
43
|
+
const assetDecimals = 8
|
|
44
|
+
const conversionRate = 30_000_000000n // $30,000 in 6 decimals
|
|
45
|
+
const conversionRateDecimals = 6
|
|
46
|
+
|
|
47
|
+
const result = convertToUsd(
|
|
48
|
+
assetAmount,
|
|
49
|
+
assetDecimals,
|
|
50
|
+
conversionRate,
|
|
51
|
+
conversionRateDecimals,
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
expect(result.value).toBe(30_000_000000n)
|
|
55
|
+
expect(result.formatted).toBe("30000")
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it("converts 0.5 BTC correctly", () => {
|
|
59
|
+
const assetAmount = 50_000000n // 0.5 BTC
|
|
60
|
+
const assetDecimals = 8
|
|
61
|
+
const conversionRate = 40_000_000000n // $40,000
|
|
62
|
+
const conversionRateDecimals = 6
|
|
63
|
+
|
|
64
|
+
const result = convertToUsd(
|
|
65
|
+
assetAmount,
|
|
66
|
+
assetDecimals,
|
|
67
|
+
conversionRate,
|
|
68
|
+
conversionRateDecimals,
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
expect(result.value).toBe(20_000_000000n)
|
|
72
|
+
expect(result.formatted).toBe("20000")
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it("converts 1 ETH (18 decimals) with $2,000 rate (6 decimals)", () => {
|
|
76
|
+
const assetAmount = 1_000000000000000000n // 1 ETH
|
|
77
|
+
const assetDecimals = 18
|
|
78
|
+
const conversionRate = 2_000_000000n
|
|
79
|
+
const conversionRateDecimals = 6
|
|
80
|
+
|
|
81
|
+
const result = convertToUsd(
|
|
82
|
+
assetAmount,
|
|
83
|
+
assetDecimals,
|
|
84
|
+
conversionRate,
|
|
85
|
+
conversionRateDecimals,
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
expect(result.value).toBe(2_000_000000n)
|
|
89
|
+
expect(result.formatted).toBe("2000")
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
it("handles zero amount correctly", () => {
|
|
93
|
+
const result = convertToUsd(0n, 18, 999_999999n, 6)
|
|
94
|
+
expect(result.value).toBe(0n)
|
|
95
|
+
expect(result.formatted).toBe("0")
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
it("handles assets with fewer decimals than conversion rate", () => {
|
|
99
|
+
const assetAmount = 100n
|
|
100
|
+
const assetDecimals = 2
|
|
101
|
+
const conversionRate = 1_500_000000n // $1500
|
|
102
|
+
const conversionRateDecimals = 6
|
|
103
|
+
|
|
104
|
+
const result = convertToUsd(
|
|
105
|
+
assetAmount,
|
|
106
|
+
assetDecimals,
|
|
107
|
+
conversionRate,
|
|
108
|
+
conversionRateDecimals,
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
expect(result.value).toBe(1_500_000000n)
|
|
112
|
+
expect(result.formatted).toBe("1500")
|
|
113
|
+
})
|
|
114
|
+
})
|
package/src/utils/currency.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
minimumFractionDigits: 2,
|
|
4
|
-
maximumFractionDigits: 2,
|
|
5
|
-
}
|
|
1
|
+
import { formatUnits } from "viem"
|
|
2
|
+
import { normalizePrecision } from "./numbers"
|
|
6
3
|
|
|
7
4
|
/**
|
|
8
5
|
* Formats a number as a currency
|
|
@@ -12,10 +9,12 @@ const DEFAULT_FORMAT_OPTIONS: Intl.NumberFormatOptions = {
|
|
|
12
9
|
*/
|
|
13
10
|
export function formatCurrency(
|
|
14
11
|
value: number,
|
|
15
|
-
options: Omit<Intl.NumberFormatOptions, "style"
|
|
12
|
+
options: Omit<Intl.NumberFormatOptions, "style">,
|
|
16
13
|
): string {
|
|
17
14
|
const formatter = new Intl.NumberFormat("en-US", {
|
|
18
|
-
|
|
15
|
+
style: "currency",
|
|
16
|
+
minimumFractionDigits: 2,
|
|
17
|
+
maximumFractionDigits: 2,
|
|
19
18
|
...options,
|
|
20
19
|
})
|
|
21
20
|
|
|
@@ -27,6 +26,33 @@ export function formatCurrency(
|
|
|
27
26
|
* @param value The value to format
|
|
28
27
|
* @returns The formatted currency
|
|
29
28
|
*/
|
|
30
|
-
export function formatUsd(value: number): string {
|
|
31
|
-
return formatCurrency(value, { currency: "USD" })
|
|
29
|
+
export function formatUsd(value: number | string): string {
|
|
30
|
+
return formatCurrency(Number(value), { currency: "USD" })
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Converts an asset amount to USD based on a conversion rate and decimals
|
|
35
|
+
* @param assetAmount - The amount of the asset in its smallest unit (e.g., satoshis for BTC)
|
|
36
|
+
* @param conversionRate - The conversion rate from the asset to USD in fixed-point format
|
|
37
|
+
* @param decimals - The number of decimals for the asset
|
|
38
|
+
* @returns - The value in USD as a number
|
|
39
|
+
*/
|
|
40
|
+
export function convertToUsd(
|
|
41
|
+
assetAmount: bigint,
|
|
42
|
+
assetDecimals: number,
|
|
43
|
+
conversionRate: bigint,
|
|
44
|
+
conversionRateDecimals: number,
|
|
45
|
+
) {
|
|
46
|
+
const value = normalizePrecision(
|
|
47
|
+
assetAmount * conversionRate,
|
|
48
|
+
assetDecimals + conversionRateDecimals,
|
|
49
|
+
conversionRateDecimals,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
const formatted = formatUnits(value, conversionRateDecimals)
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
value,
|
|
56
|
+
formatted,
|
|
57
|
+
}
|
|
32
58
|
}
|
|
@@ -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,89 +1,96 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
roundUpNumber,
|
|
2
|
+
formatNumberToCompactString,
|
|
3
|
+
bigIntMax,
|
|
4
|
+
normalizePrecision,
|
|
6
5
|
} from "./numbers"
|
|
7
6
|
|
|
8
|
-
describe("
|
|
7
|
+
describe("formatNumberToCompactString", () => {
|
|
9
8
|
it("formats number less than 1000 with decimals", () => {
|
|
10
|
-
expect(
|
|
9
|
+
expect(formatNumberToCompactString(123.456789, 2)).toBe("123.46")
|
|
11
10
|
})
|
|
12
11
|
|
|
13
12
|
it("formats thousands with K", () => {
|
|
14
|
-
expect(
|
|
13
|
+
expect(formatNumberToCompactString(12_345, 2)).toBe("12.35K")
|
|
15
14
|
})
|
|
16
15
|
|
|
17
16
|
it("formats millions with M", () => {
|
|
18
|
-
expect(
|
|
17
|
+
expect(formatNumberToCompactString(12_345_678, 2)).toBe("12.35M")
|
|
19
18
|
})
|
|
20
19
|
|
|
21
20
|
it("formats billions with B", () => {
|
|
22
|
-
expect(
|
|
21
|
+
expect(formatNumberToCompactString(12_345_678_901, 2)).toBe("12.35B")
|
|
23
22
|
})
|
|
24
23
|
|
|
25
24
|
it("formats trillions with T", () => {
|
|
26
|
-
expect(
|
|
25
|
+
expect(formatNumberToCompactString(12_345_678_901_234, 2)).toBe("12.35T")
|
|
27
26
|
})
|
|
28
27
|
|
|
29
28
|
it("formats bigint as readable number", () => {
|
|
30
|
-
expect(
|
|
29
|
+
expect(formatNumberToCompactString(1234567890123456789n, 2)).toBe(
|
|
30
|
+
"1,234,567.89T",
|
|
31
|
+
)
|
|
31
32
|
})
|
|
32
33
|
|
|
33
34
|
it("caps at > 1000T for huge numbers", () => {
|
|
34
35
|
const hugeNumber = 10 ** 18 // 1e18
|
|
35
|
-
expect(
|
|
36
|
+
expect(formatNumberToCompactString(hugeNumber, 2)).toBe("1,000,000T")
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it("formats numbers with trailing zeros correctly", () => {
|
|
40
|
+
expect(formatNumberToCompactString(1_000, 2)).toBe("1K")
|
|
36
41
|
})
|
|
37
42
|
})
|
|
38
43
|
|
|
39
|
-
describe("
|
|
40
|
-
it("
|
|
41
|
-
expect(
|
|
44
|
+
describe("bigIntMax", () => {
|
|
45
|
+
it("returns the maximum of positive bigint values", () => {
|
|
46
|
+
expect(bigIntMax(1n, 2n, 3n)).toBe(3n)
|
|
42
47
|
})
|
|
43
48
|
|
|
44
|
-
it("
|
|
45
|
-
expect(
|
|
49
|
+
it("returns the maximum of negative bigint values", () => {
|
|
50
|
+
expect(bigIntMax(-10n, -5n, -20n)).toBe(-5n)
|
|
46
51
|
})
|
|
47
52
|
|
|
48
|
-
it("
|
|
49
|
-
expect(
|
|
53
|
+
it("returns the only element if array has one bigint", () => {
|
|
54
|
+
expect(bigIntMax(42n)).toBe(42n)
|
|
50
55
|
})
|
|
51
|
-
})
|
|
52
56
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const raw = 1234567890000000000n // 1.23456789 ETH in 18 decimals
|
|
56
|
-
expect(fromFixedPoint(raw, 18, 4)).toBe(1.2345)
|
|
57
|
+
it("works with a mix of positive and negative bigints", () => {
|
|
58
|
+
expect(bigIntMax(-100n, 0n, 50n, -10n)).toBe(50n)
|
|
57
59
|
})
|
|
58
60
|
|
|
59
|
-
it("
|
|
60
|
-
|
|
61
|
-
expect(fromFixedPoint(raw, 18, 2)).toBe(0.98)
|
|
61
|
+
it("throws an error if called with no arguments", () => {
|
|
62
|
+
expect(() => bigIntMax()).toThrow()
|
|
62
63
|
})
|
|
63
64
|
|
|
64
|
-
it("
|
|
65
|
-
|
|
66
|
-
expect(fromFixedPoint(raw, 6, 2)).toBe(1000000000000000000)
|
|
65
|
+
it("returns the correct value when all values are equal", () => {
|
|
66
|
+
expect(bigIntMax(5n, 5n, 5n)).toBe(5n)
|
|
67
67
|
})
|
|
68
68
|
})
|
|
69
69
|
|
|
70
|
-
describe("
|
|
71
|
-
it("
|
|
72
|
-
|
|
73
|
-
expect(
|
|
70
|
+
describe("normalizePrecision", () => {
|
|
71
|
+
it("reduces precision correctly (scale down)", () => {
|
|
72
|
+
const result = normalizePrecision(1234500n, 6, 3)
|
|
73
|
+
expect(result).toBe(1234n)
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
it("increases precision correctly (scale up)", () => {
|
|
77
|
+
const result = normalizePrecision(1234n, 3, 6)
|
|
78
|
+
expect(result).toBe(1234000n)
|
|
74
79
|
})
|
|
75
80
|
|
|
76
|
-
it("returns
|
|
77
|
-
|
|
81
|
+
it("returns the same value when precision is equal", () => {
|
|
82
|
+
const result = normalizePrecision(987654321n, 5, 5)
|
|
83
|
+
expect(result).toBe(987654321n)
|
|
78
84
|
})
|
|
79
85
|
|
|
80
|
-
it("
|
|
81
|
-
const result =
|
|
82
|
-
expect(result).toBe(
|
|
86
|
+
it("handles zero value correctly", () => {
|
|
87
|
+
const result = normalizePrecision(0n, 4, 8)
|
|
88
|
+
expect(result).toBe(0n)
|
|
83
89
|
})
|
|
84
90
|
|
|
85
|
-
it("
|
|
86
|
-
const
|
|
87
|
-
|
|
91
|
+
it("handles large numbers without precision loss", () => {
|
|
92
|
+
const value = 123456789012345678901234567890n
|
|
93
|
+
const result = normalizePrecision(value, 18, 20)
|
|
94
|
+
expect(result).toBe(value * 100n)
|
|
88
95
|
})
|
|
89
96
|
})
|