@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
|
@@ -11,5 +11,5 @@ export declare function trimAddress(address: string): string;
|
|
|
11
11
|
* @param isTestnet - Whether the address is on testnet.
|
|
12
12
|
* @returns The URL of the block explorer page for the address.
|
|
13
13
|
*/
|
|
14
|
-
export declare function getAddressExplorerUrl(address: string, chainType: "bitcoin" | "evm", isTestnet: boolean): string;
|
|
14
|
+
export declare function getAddressExplorerUrl(address: string, chainType: "bitcoin" | "evm" | "mezo", isTestnet: boolean): string;
|
|
15
15
|
//# sourceMappingURL=address.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../../src/utils/address.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAMnD;
|
|
1
|
+
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../../src/utils/address.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAMnD;AAcD;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,SAAS,GAAG,KAAK,GAAG,MAAM,EACrC,SAAS,EAAE,OAAO,UASnB"}
|
|
@@ -12,10 +12,12 @@ export function trimAddress(address) {
|
|
|
12
12
|
const MAINNET_EXPLORER_URLS = {
|
|
13
13
|
bitcoin: "https://mempool.space",
|
|
14
14
|
evm: "https://etherscan.io",
|
|
15
|
+
mezo: "https://explorer.mezo.org",
|
|
15
16
|
};
|
|
16
17
|
const TESTNET_EXPLORER_URLS = {
|
|
17
18
|
bitcoin: "https://mempool.space/testnet",
|
|
18
19
|
evm: "https://sepolia.etherscan.io",
|
|
20
|
+
mezo: "https://explorer.test.mezo.org",
|
|
19
21
|
};
|
|
20
22
|
/**
|
|
21
23
|
* Get the URL of the block explorer page for an address.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address.js","sourceRoot":"","sources":["../../../src/utils/address.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,OAAe;IACzC,IAAI,OAAO,CAAC,MAAM,GAAG,EAAE;QAAE,OAAO,OAAO,CAAA;IAEvC,MAAM,cAAc,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IAEtE,OAAO,cAAc,CAAA;AACvB,CAAC;AAED,MAAM,qBAAqB,
|
|
1
|
+
{"version":3,"file":"address.js","sourceRoot":"","sources":["../../../src/utils/address.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,OAAe;IACzC,IAAI,OAAO,CAAC,MAAM,GAAG,EAAE;QAAE,OAAO,OAAO,CAAA;IAEvC,MAAM,cAAc,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IAEtE,OAAO,cAAc,CAAA;AACvB,CAAC;AAED,MAAM,qBAAqB,GAA+C;IACxE,OAAO,EAAE,uBAAuB;IAChC,GAAG,EAAE,sBAAsB;IAC3B,IAAI,EAAE,2BAA2B;CAClC,CAAA;AAED,MAAM,qBAAqB,GAA+C;IACxE,OAAO,EAAE,+BAA+B;IACxC,GAAG,EAAE,8BAA8B;IACnC,IAAI,EAAE,gCAAgC;CACvC,CAAA;AAED;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CACnC,OAAe,EACf,SAAqC,EACrC,SAAkB;IAElB,MAAM,aAAa,GAAG,SAAS;QAC7B,CAAC,CAAC,qBAAqB;QACvB,CAAC,CAAC,qBAAqB,CAAA;IACzB,MAAM,OAAO,GAAG,aAAa,CAAC,SAAS,CAAC,CAAA;IACxC,MAAM,QAAQ,GAAG,WAAW,OAAO,EAAE,CAAA;IAErC,OAAO,GAAG,OAAO,IAAI,QAAQ,EAAE,CAAA;AACjC,CAAC"}
|
|
@@ -8,11 +8,6 @@ describe("trimAddress", () => {
|
|
|
8
8
|
const expected = "0x123...bcdef";
|
|
9
9
|
expect(trimAddress(input)).toBe(expected);
|
|
10
10
|
});
|
|
11
|
-
it("returns lowercase result", () => {
|
|
12
|
-
const input = "0xABCDEF1234567890";
|
|
13
|
-
const expected = "0xabc...67890";
|
|
14
|
-
expect(trimAddress(input)).toBe(expected);
|
|
15
|
-
});
|
|
16
11
|
});
|
|
17
12
|
describe("getAddressExplorerUrl", () => {
|
|
18
13
|
const btcAddress = "bc1qxyz123";
|
|
@@ -33,5 +28,13 @@ describe("getAddressExplorerUrl", () => {
|
|
|
33
28
|
const url = getAddressExplorerUrl(evmAddress, "evm", true);
|
|
34
29
|
expect(url).toBe(`https://sepolia.etherscan.io/address/${evmAddress}`);
|
|
35
30
|
});
|
|
31
|
+
it("returns correct mainnet Mezo explorer URL", () => {
|
|
32
|
+
const url = getAddressExplorerUrl(evmAddress, "mezo", false);
|
|
33
|
+
expect(url).toBe(`https://explorer.mezo.org/address/${evmAddress}`);
|
|
34
|
+
});
|
|
35
|
+
it("returns correct testnet Mezo explorer URL", () => {
|
|
36
|
+
const url = getAddressExplorerUrl(evmAddress, "mezo", true);
|
|
37
|
+
expect(url).toBe(`https://explorer.test.mezo.org/address/${evmAddress}`);
|
|
38
|
+
});
|
|
36
39
|
});
|
|
37
40
|
//# sourceMappingURL=address.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address.test.js","sourceRoot":"","sources":["../../../src/utils/address.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAE9D,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,EAAE,CAAC,gDAAgD,EAAE,GAAG,EAAE;QACxD,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IAChD,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,iDAAiD,EAAE,GAAG,EAAE;QACzD,MAAM,KAAK,GAAG,mBAAmB,CAAA;QACjC,MAAM,QAAQ,GAAG,eAAe,CAAA;QAChC,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAC3C,CAAC,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"address.test.js","sourceRoot":"","sources":["../../../src/utils/address.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAE9D,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,EAAE,CAAC,gDAAgD,EAAE,GAAG,EAAE;QACxD,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IAChD,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,iDAAiD,EAAE,GAAG,EAAE;QACzD,MAAM,KAAK,GAAG,mBAAmB,C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AE,CAAC,2CAA2C,EAAE,GAAG,EAAE;QACnD,MAAM,GAAG,GAAG,qBAAqB,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,CAAC,CAAA;QAC5D,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,qCAAqC,UAAU,EAAE,CAAC,CAAA;IACrE,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;QACnD,MAAM,GAAG,GAAG,qBAAqB,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,CAAA;QAC3D,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,0CAA0C,UAAU,EAAE,CAAC,CAAA;IAC1E,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { IconProps } from "@mezo-org/mezo-clay";
|
|
2
2
|
import { FC } from "react";
|
|
3
|
-
|
|
3
|
+
import { MezoChainToken } from "../lib/contracts";
|
|
4
|
+
export type CryptoAssetKey = MezoChainToken | "BTC" | "ETH";
|
|
4
5
|
export type CryptoAsset = {
|
|
5
6
|
name: string;
|
|
6
7
|
symbol: string;
|
|
@@ -25,4 +26,19 @@ export declare function isBitcoinLikeCryptoAsset(key: CryptoAssetKey): boolean;
|
|
|
25
26
|
* @returns True if crypto asset is USD-like
|
|
26
27
|
*/
|
|
27
28
|
export declare function isUsdLikeCryptoAsset(key: CryptoAssetKey): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Formats crypto asset to balance details (balance in USD and decimals)
|
|
31
|
+
* @param type The type of crypto asset
|
|
32
|
+
* @param balance The balance of crypto asset
|
|
33
|
+
* @param usdConversionRate The USD conversion rate
|
|
34
|
+
* @returns The balance details
|
|
35
|
+
*/
|
|
36
|
+
export declare function mapCryptoAssetToDetails(type: CryptoAssetKey, balance: bigint, usdConversionRate: bigint, usdConversionRateDecimals: number): {
|
|
37
|
+
type: CryptoAssetKey;
|
|
38
|
+
rawBalance: bigint;
|
|
39
|
+
formattedBalance: string;
|
|
40
|
+
usdBalance: number;
|
|
41
|
+
formattedUsdBalance: string;
|
|
42
|
+
};
|
|
43
|
+
export type DetailedCryptoAsset = ReturnType<typeof mapCryptoAssetToDetails>;
|
|
28
44
|
//# sourceMappingURL=cryptoAssets.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cryptoAssets.d.ts","sourceRoot":"","sources":["../../../src/utils/cryptoAssets.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,SAAS,EAGV,MAAM,qBAAqB,CAAA;AAC5B,OAAO,
|
|
1
|
+
{"version":3,"file":"cryptoAssets.d.ts","sourceRoot":"","sources":["../../../src/utils/cryptoAssets.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,SAAS,EAGV,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAA;AAC1B,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAIjD,MAAM,MAAM,cAAc,GAAG,cAAc,GAAG,KAAK,GAAG,KAAK,CAAA;AAE3D,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,CAAA;IACnB,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAqFD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,cAAc,eAEjD;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,cAAc,WAE3D;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,cAAc,WAEvD;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,cAAc,EACpB,OAAO,EAAE,MAAM,EACf,iBAAiB,EAAE,MAAM,EACzB,yBAAyB,EAAE,MAAM;;;;;;EA0BlC;AAED,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC,OAAO,uBAAuB,CAAC,CAAA"}
|
|
@@ -1,48 +1,84 @@
|
|
|
1
|
-
import { BitcoinCircle, EthCircle,
|
|
2
|
-
import {
|
|
1
|
+
import { BitcoinCircle, EthCircle, MUsdCircle02, Cryptocurrency04, } from "@mezo-org/mezo-clay";
|
|
2
|
+
import { convertToUsd, formatUsd } from "./currency";
|
|
3
|
+
import { fromFixedPointToString } from "./numbers";
|
|
4
|
+
// TODO: Add actual icons for the assets
|
|
3
5
|
const CRYPTO_ASSETS = {
|
|
4
|
-
|
|
6
|
+
BTC: {
|
|
5
7
|
name: "Bitcoin",
|
|
6
8
|
symbol: "BTC",
|
|
7
9
|
icon: BitcoinCircle,
|
|
8
|
-
decimals:
|
|
10
|
+
decimals: 18,
|
|
9
11
|
},
|
|
10
|
-
|
|
12
|
+
ETH: {
|
|
11
13
|
name: "Ethereum",
|
|
12
14
|
symbol: "ETH",
|
|
13
15
|
icon: EthCircle,
|
|
14
16
|
decimals: 18,
|
|
15
17
|
},
|
|
16
|
-
|
|
17
|
-
name: "
|
|
18
|
-
symbol: "
|
|
19
|
-
icon:
|
|
18
|
+
MUSD: {
|
|
19
|
+
name: "MUSD",
|
|
20
|
+
symbol: "MUSD",
|
|
21
|
+
icon: MUsdCircle02,
|
|
20
22
|
decimals: 18,
|
|
21
23
|
},
|
|
22
|
-
|
|
23
|
-
name: "
|
|
24
|
-
symbol: "
|
|
25
|
-
icon:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
mDAI: {
|
|
25
|
+
name: "mDAI",
|
|
26
|
+
symbol: "mDAI",
|
|
27
|
+
icon: Cryptocurrency04,
|
|
28
|
+
decimals: 18,
|
|
29
|
+
},
|
|
30
|
+
mFBTC: {
|
|
31
|
+
name: "mFBTC",
|
|
32
|
+
symbol: "mFBTC",
|
|
33
|
+
icon: BitcoinCircle,
|
|
30
34
|
decimals: 8,
|
|
31
35
|
},
|
|
32
|
-
|
|
33
|
-
name: "
|
|
34
|
-
symbol: "
|
|
35
|
-
icon:
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
mcbBTC: {
|
|
37
|
+
name: "mcbBTC",
|
|
38
|
+
symbol: "mcbBTC",
|
|
39
|
+
icon: BitcoinCircle,
|
|
40
|
+
decimals: 8,
|
|
41
|
+
},
|
|
42
|
+
mSolvBTC: {
|
|
43
|
+
name: "mSolvBTC",
|
|
44
|
+
symbol: "mSolvBTC",
|
|
45
|
+
icon: BitcoinCircle,
|
|
40
46
|
decimals: 18,
|
|
41
47
|
},
|
|
42
|
-
|
|
43
|
-
name: "
|
|
44
|
-
symbol: "
|
|
45
|
-
icon:
|
|
48
|
+
mswBTC: {
|
|
49
|
+
name: "mswBTC",
|
|
50
|
+
symbol: "mswBTC",
|
|
51
|
+
icon: BitcoinCircle,
|
|
52
|
+
decimals: 8,
|
|
53
|
+
},
|
|
54
|
+
mT: {
|
|
55
|
+
name: "mT",
|
|
56
|
+
symbol: "mT",
|
|
57
|
+
icon: Cryptocurrency04,
|
|
58
|
+
decimals: 18,
|
|
59
|
+
},
|
|
60
|
+
mUSDC: {
|
|
61
|
+
name: "mUSDC",
|
|
62
|
+
symbol: "mUSDC",
|
|
63
|
+
icon: Cryptocurrency04,
|
|
64
|
+
decimals: 6,
|
|
65
|
+
},
|
|
66
|
+
mUSDe: {
|
|
67
|
+
name: "mUSDe",
|
|
68
|
+
symbol: "mUSDe",
|
|
69
|
+
icon: Cryptocurrency04,
|
|
70
|
+
decimals: 18,
|
|
71
|
+
},
|
|
72
|
+
mUSDT: {
|
|
73
|
+
name: "mUSDT",
|
|
74
|
+
symbol: "mUSDT",
|
|
75
|
+
icon: Cryptocurrency04,
|
|
76
|
+
decimals: 6,
|
|
77
|
+
},
|
|
78
|
+
mxSolvBTC: {
|
|
79
|
+
name: "mxSolvBTC",
|
|
80
|
+
symbol: "mxSolvBTC",
|
|
81
|
+
icon: BitcoinCircle,
|
|
46
82
|
decimals: 18,
|
|
47
83
|
},
|
|
48
84
|
};
|
|
@@ -60,7 +96,7 @@ export function getCryptoAsset(key) {
|
|
|
60
96
|
* @returns True if crypto asset is Bitcoin-like
|
|
61
97
|
*/
|
|
62
98
|
export function isBitcoinLikeCryptoAsset(key) {
|
|
63
|
-
return
|
|
99
|
+
return /(btc)/i.test(key);
|
|
64
100
|
}
|
|
65
101
|
/**
|
|
66
102
|
* Checks if given crypto asset is USD-like
|
|
@@ -68,6 +104,26 @@ export function isBitcoinLikeCryptoAsset(key) {
|
|
|
68
104
|
* @returns True if crypto asset is USD-like
|
|
69
105
|
*/
|
|
70
106
|
export function isUsdLikeCryptoAsset(key) {
|
|
71
|
-
return
|
|
107
|
+
return /(usd|dai)/i.test(key);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Formats crypto asset to balance details (balance in USD and decimals)
|
|
111
|
+
* @param type The type of crypto asset
|
|
112
|
+
* @param balance The balance of crypto asset
|
|
113
|
+
* @param usdConversionRate The USD conversion rate
|
|
114
|
+
* @returns The balance details
|
|
115
|
+
*/
|
|
116
|
+
export function mapCryptoAssetToDetails(type, balance, usdConversionRate, usdConversionRateDecimals) {
|
|
117
|
+
const { decimals } = getCryptoAsset(type);
|
|
118
|
+
const formattedBalance = fromFixedPointToString(balance, decimals, isUsdLikeCryptoAsset(type) ? 2 : 4);
|
|
119
|
+
const usdBalance = convertToUsd(balance, decimals, usdConversionRate, usdConversionRateDecimals);
|
|
120
|
+
const formattedUsdBalance = formatUsd(usdBalance);
|
|
121
|
+
return {
|
|
122
|
+
type,
|
|
123
|
+
rawBalance: balance,
|
|
124
|
+
formattedBalance,
|
|
125
|
+
usdBalance,
|
|
126
|
+
formattedUsdBalance,
|
|
127
|
+
};
|
|
72
128
|
}
|
|
73
129
|
//# sourceMappingURL=cryptoAssets.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cryptoAssets.js","sourceRoot":"","sources":["../../../src/utils/cryptoAssets.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,SAAS,EAET,
|
|
1
|
+
{"version":3,"file":"cryptoAssets.js","sourceRoot":"","sources":["../../../src/utils/cryptoAssets.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,SAAS,EAET,YAAY,EACZ,gBAAgB,GACjB,MAAM,qBAAqB,CAAA;AAG5B,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAA;AAWlD,wCAAwC;AAExC,MAAM,aAAa,GAAwC;IACzD,GAAG,EAAE;QACH,IAAI,EAAE,SAAS;QACf,MAAM,EAAE,KAAK;QACb,IAAI,EAAE,aAAa;QACnB,QAAQ,EAAE,EAAE;KACb;IACD,GAAG,EAAE;QACH,IAAI,EAAE,UAAU;QAChB,MAAM,EAAE,KAAK;QACb,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,EAAE;KACb;IACD,IAAI,EAAE;QACJ,IAAI,EAAE,MAAM;QACZ,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,YAAY;QAClB,QAAQ,EAAE,EAAE;KACb;IACD,IAAI,EAAE;QACJ,IAAI,EAAE,MAAM;QACZ,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,gBAAgB;QACtB,QAAQ,EAAE,EAAE;KACb;IACD,KAAK,EAAE;QACL,IAAI,EAAE,OAAO;QACb,MAAM,EAAE,OAAO;QACf,IAAI,EAAE,aAAa;QACnB,QAAQ,EAAE,CAAC;KACZ;IACD,MAAM,EAAE;QACN,IAAI,EAAE,QAAQ;QACd,MAAM,EAAE,QAAQ;QAChB,IAAI,EAAE,aAAa;QACnB,QAAQ,EAAE,CAAC;KACZ;IACD,QAAQ,EAAE;QACR,IAAI,EAAE,UAAU;QAChB,MAAM,EAAE,UAAU;QAClB,IAAI,EAAE,aAAa;QACnB,QAAQ,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AC,IAAI,CAAC,CAAA;IAEzC,MAAM,gBAAgB,GAAG,sBAAsB,CAC7C,OAAO,EACP,QAAQ,EACR,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CACnC,CAAA;IAED,MAAM,UAAU,GAAG,YAAY,CAC7B,OAAO,EACP,QAAQ,EACR,iBAAiB,EACjB,yBAAyB,CAC1B,CAAA;IAED,MAAM,mBAAmB,GAAG,SAAS,CAAC,UAAU,CAAC,CAAA;IAEjD,OAAO;QACL,IAAI;QACJ,UAAU,EAAE,OAAO;QACnB,gBAAgB;QAChB,UAAU;QACV,mBAAmB;KACpB,CAAA;AACH,CAAC"}
|
|
@@ -1,49 +1,67 @@
|
|
|
1
|
-
import { BitcoinCircle, EthCircle,
|
|
2
|
-
import { getCryptoAsset } from "./cryptoAssets";
|
|
1
|
+
import { BitcoinCircle, EthCircle, MUsdCircle02 } from "@mezo-org/mezo-clay";
|
|
2
|
+
import { getCryptoAsset, isBitcoinLikeCryptoAsset, isUsdLikeCryptoAsset, } from "./cryptoAssets";
|
|
3
|
+
// FIXME: Test fails if run in full suite (pnpm test) but works when run in isolation (pnpm test cryptoAssets)
|
|
3
4
|
describe("getCryptoAsset", () => {
|
|
4
|
-
it("returns the correct asset for '
|
|
5
|
-
const asset = getCryptoAsset("
|
|
5
|
+
it("returns the correct asset for 'BTC (mBTC)'", () => {
|
|
6
|
+
const asset = getCryptoAsset("BTC");
|
|
6
7
|
expect(asset.name).toBe("Bitcoin");
|
|
7
8
|
expect(asset.symbol).toBe("BTC");
|
|
8
|
-
expect(asset.decimals).toBe(
|
|
9
|
+
expect(asset.decimals).toBe(18);
|
|
9
10
|
expect(asset.icon).toBe(BitcoinCircle);
|
|
10
11
|
});
|
|
11
|
-
it("returns the correct asset for '
|
|
12
|
-
const asset = getCryptoAsset("
|
|
12
|
+
it("returns the correct asset for 'ETH'", () => {
|
|
13
|
+
const asset = getCryptoAsset("ETH");
|
|
13
14
|
expect(asset.name).toBe("Ethereum");
|
|
14
15
|
expect(asset.symbol).toBe("ETH");
|
|
15
16
|
expect(asset.decimals).toBe(18);
|
|
16
17
|
expect(asset.icon).toBe(EthCircle);
|
|
17
18
|
});
|
|
18
|
-
it("returns the correct asset for '
|
|
19
|
-
const asset = getCryptoAsset("
|
|
20
|
-
expect(asset.name).toBe("
|
|
21
|
-
expect(asset.symbol).toBe("
|
|
19
|
+
it("returns the correct asset for 'MUSD'", () => {
|
|
20
|
+
const asset = getCryptoAsset("MUSD");
|
|
21
|
+
expect(asset.name).toBe("MUSD");
|
|
22
|
+
expect(asset.symbol).toBe("MUSD");
|
|
22
23
|
expect(asset.decimals).toBe(18);
|
|
23
|
-
expect(asset.icon).toBe(
|
|
24
|
-
});
|
|
25
|
-
it("returns the correct asset for 'wbtc'", () => {
|
|
26
|
-
const asset = getCryptoAsset("wbtc");
|
|
27
|
-
expect(asset.name).toBe("Wrapped Bitcoin");
|
|
28
|
-
expect(asset.symbol).toBe("wBTC");
|
|
29
|
-
expect(asset.decimals).toBe(8);
|
|
30
|
-
// FIXME: Test should expect the exact icon component
|
|
31
|
-
expect(asset.icon).toEqual(expect.any(Function));
|
|
24
|
+
expect(asset.icon).toBe(MUsdCircle02);
|
|
32
25
|
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
26
|
+
});
|
|
27
|
+
describe("isBitcoinLikeCryptoAsset", () => {
|
|
28
|
+
const cases = [
|
|
29
|
+
{ input: "mcbBTC", expected: true },
|
|
30
|
+
{ input: "mDAI", expected: false },
|
|
31
|
+
{ input: "mFBTC", expected: true },
|
|
32
|
+
{ input: "mSolvBTC", expected: true },
|
|
33
|
+
{ input: "mswBTC", expected: true },
|
|
34
|
+
{ input: "mT", expected: false },
|
|
35
|
+
{ input: "mUSDC", expected: false },
|
|
36
|
+
{ input: "mUSDe", expected: false },
|
|
37
|
+
{ input: "mUSDT", expected: false },
|
|
38
|
+
{ input: "mxSolvBTC", expected: true },
|
|
39
|
+
{ input: "MUSD", expected: false },
|
|
40
|
+
];
|
|
41
|
+
cases.forEach(({ input, expected }) => {
|
|
42
|
+
it(`returns ${expected} for ${input}`, () => {
|
|
43
|
+
expect(isBitcoinLikeCryptoAsset(input)).toBe(expected);
|
|
44
|
+
});
|
|
40
45
|
});
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
});
|
|
47
|
+
describe("isUsdLikeCryptoAsset", () => {
|
|
48
|
+
const cases = [
|
|
49
|
+
{ input: "mcbBTC", expected: false },
|
|
50
|
+
{ input: "mDAI", expected: true },
|
|
51
|
+
{ input: "mFBTC", expected: false },
|
|
52
|
+
{ input: "mSolvBTC", expected: false },
|
|
53
|
+
{ input: "mswBTC", expected: false },
|
|
54
|
+
{ input: "mT", expected: false },
|
|
55
|
+
{ input: "mUSDC", expected: true },
|
|
56
|
+
{ input: "mUSDe", expected: true },
|
|
57
|
+
{ input: "mUSDT", expected: true },
|
|
58
|
+
{ input: "mxSolvBTC", expected: false },
|
|
59
|
+
{ input: "MUSD", expected: true },
|
|
60
|
+
];
|
|
61
|
+
cases.forEach(({ input, expected }) => {
|
|
62
|
+
it(`returns ${expected} for ${input}`, () => {
|
|
63
|
+
expect(isUsdLikeCryptoAsset(input)).toBe(expected);
|
|
64
|
+
});
|
|
47
65
|
});
|
|
48
66
|
});
|
|
49
67
|
//# sourceMappingURL=cryptoAssets.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cryptoAssets.test.js","sourceRoot":"","sources":["../../../src/utils/cryptoAssets.test.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"cryptoAssets.test.js","sourceRoot":"","sources":["../../../src/utils/cryptoAssets.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,YAAY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?: Omit<Intl.Number
|
|
|
11
11
|
* @returns The formatted currency
|
|
12
12
|
*/
|
|
13
13
|
export declare function formatUsd(value: number): string;
|
|
14
|
+
/**
|
|
15
|
+
* Converts an asset amount to USD based on a conversion rate and decimals
|
|
16
|
+
* @param assetAmount - The amount of the asset in its smallest unit (e.g., satoshis for BTC)
|
|
17
|
+
* @param conversionRate - The conversion rate from the asset to USD in fixed-point format
|
|
18
|
+
* @param decimals - The number of decimals for the asset
|
|
19
|
+
* @returns - The value in USD as a number
|
|
20
|
+
*/
|
|
21
|
+
export declare function convertToUsd(assetAmount: bigint, assetDecimals: number, conversionRate: bigint, conversionRateDecimals: number): number;
|
|
14
22
|
//# sourceMappingURL=currency.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currency.d.ts","sourceRoot":"","sources":["../../../src/utils/currency.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"currency.d.ts","sourceRoot":"","sources":["../../../src/utils/currency.ts"],"names":[],"mappings":"AAQA;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,IAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE,OAAO,CAAM,GACpD,MAAM,CAOR;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,MAAM,EACrB,cAAc,EAAE,MAAM,EACtB,sBAAsB,EAAE,MAAM,GAC7B,MAAM,CAKR"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { fromFixedPoint } from "./numbers";
|
|
1
2
|
const DEFAULT_FORMAT_OPTIONS = {
|
|
2
3
|
style: "currency",
|
|
3
4
|
minimumFractionDigits: 2,
|
|
@@ -24,4 +25,14 @@ export function formatCurrency(value, options = {}) {
|
|
|
24
25
|
export function formatUsd(value) {
|
|
25
26
|
return formatCurrency(value, { currency: "USD" });
|
|
26
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Converts an asset amount to USD based on a conversion rate and decimals
|
|
30
|
+
* @param assetAmount - The amount of the asset in its smallest unit (e.g., satoshis for BTC)
|
|
31
|
+
* @param conversionRate - The conversion rate from the asset to USD in fixed-point format
|
|
32
|
+
* @param decimals - The number of decimals for the asset
|
|
33
|
+
* @returns - The value in USD as a number
|
|
34
|
+
*/
|
|
35
|
+
export function convertToUsd(assetAmount, assetDecimals, conversionRate, conversionRateDecimals) {
|
|
36
|
+
return fromFixedPoint((assetAmount * conversionRate) / 10n ** BigInt(conversionRateDecimals), assetDecimals);
|
|
37
|
+
}
|
|
27
38
|
//# sourceMappingURL=currency.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currency.js","sourceRoot":"","sources":["../../../src/utils/currency.ts"],"names":[],"mappings":"AAAA,MAAM,sBAAsB,GAA6B;IACvD,KAAK,EAAE,UAAU;IACjB,qBAAqB,EAAE,CAAC;IACxB,qBAAqB,EAAE,CAAC;CACzB,CAAA;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAC5B,KAAa,EACb,UAAmD,EAAE;IAErD,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE;QAC/C,GAAG,sBAAsB;QACzB,GAAG,OAAO;KACX,CAAC,CAAA;IAEF,OAAO,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAChC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,KAAa;IACrC,OAAO,cAAc,CAAC,KAAK,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAA;AACnD,CAAC"}
|
|
1
|
+
{"version":3,"file":"currency.js","sourceRoot":"","sources":["../../../src/utils/currency.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAE1C,M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,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mezoId.d.ts","sourceRoot":"","sources":["../../../src/utils/mezoId.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,GAAG,GAAG,MAAM,OAAO,CAAA;AAWrC,eAAO,MAAM,2BAA2B,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EAyBzE,CAAA;AAEH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAYvD"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// NOTE: This was copied from mezo-portal and is based on the validation from
|
|
2
|
+
// workers/passport-auth/src/utils/mezo-id.ts.
|
|
3
|
+
// Most of these are restrictions for an DNS hostname label (i.e., the part
|
|
4
|
+
// before/after `.` in a full hostname) as outlined in RFC1034
|
|
5
|
+
// (https://www.rfc-editor.org/rfc/rfc1034).
|
|
6
|
+
//
|
|
7
|
+
// A few addenda are made to ensure that nothing can sneak through that could
|
|
8
|
+
// look like an Ethereum or Bitcoin address.
|
|
9
|
+
export const DISALLOWED_MEZO_ID_PATTERNS = [
|
|
10
|
+
// RFC1034.
|
|
11
|
+
{ pattern: /^$/, error: "Must not be empty." },
|
|
12
|
+
{ pattern: /^.{16,}$/, error: "Must have 15 characters or fewer." },
|
|
13
|
+
{
|
|
14
|
+
pattern: /^[^A-Za-z]/,
|
|
15
|
+
error: "Must start with one of the letters A-Z or a-z.",
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
pattern: /[^A-Za-z0-9-]/,
|
|
19
|
+
error: "Must only use letters or numbers (A-Z, a-z, or 0-9), or hyphen (-).",
|
|
20
|
+
},
|
|
21
|
+
{ pattern: /-$/, error: "Must not end in a hyphen (-)." },
|
|
22
|
+
// On-chain shenanigan avoidance.
|
|
23
|
+
{ pattern: /0x/i, error: "Must not contain 0x." },
|
|
24
|
+
{
|
|
25
|
+
pattern: /^(?:bc1|tb1|[a-z]pub|[a-z]priv)/i,
|
|
26
|
+
error: "Must not start with a Bitcoin magic string.",
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
pattern: /^m[0-9]+$/i,
|
|
30
|
+
error: 'No "m" + "numeric string" prefixes.',
|
|
31
|
+
},
|
|
32
|
+
];
|
|
33
|
+
export function validateMezoId(mezoId) {
|
|
34
|
+
if (!/\.mezo$/.test(mezoId)) {
|
|
35
|
+
return ["Must end with '.mezo'."];
|
|
36
|
+
}
|
|
37
|
+
const mezoIdWithoutSuffix = mezoId.replace(/\.mezo$/, "");
|
|
38
|
+
const errors = DISALLOWED_MEZO_ID_PATTERNS.flatMap(({ pattern, error }) => pattern.test(mezoIdWithoutSuffix) ? [error] : []);
|
|
39
|
+
return errors;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=mezoId.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mezoId.js","sourceRoot":"","sources":["../../../src/utils/mezoId.ts"],"names":[],"mappings":"AAEA,6EAA6E;AAC7E,8CAA8C;AAE9C,2EAA2E;AAC3E,8DAA8D;AAC9D,4CAA4C;AAC5C,EAAE;AACF,6EAA6E;AAC7E,4CAA4C;AAC5C,MAAM,CAAC,MAAM,2BAA2B,GACtC;IACE,WAAW;IACX,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,oBAAoB,EAAE;IAC9C,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,mCAAmC,EAAE;IACnE;QACE,OAAO,EAAE,YAAY;QACrB,KAAK,EAAE,gDAAgD;KACxD;IACD;QACE,OAAO,EAAE,eAAe;QACxB,KAAK,EACH,qEAAqE;KACxE;IACD,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,+BAA+B,EAAE;IACzD,iCAAiC;IACjC,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,sBAAsB,EAAE;IACjD;QACE,OAAO,EAAE,kCAAkC;QAC3C,KAAK,EAAE,6CAA6C;KACrD;IACD;QACE,OAAO,EAAE,YAAY;QACrB,KAAK,EAAE,qCAAqC;KAC7C;CACF,CAAA;AAEH,MAAM,UAAU,cAAc,CAAC,MAAc;IAC3C,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5B,OAAO,CAAC,wBAAwB,CAAC,CAAA;IACnC,CAAC;IAED,MAAM,mBAAmB,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAA;IAEzD,MAAM,MAAM,GAAG,2BAA2B,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,CACxE,OAAO,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CACjD,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Formats a number or bigint into
|
|
2
|
+
* Formats a number or bigint into compact string with K, M, B, or T suffix.
|
|
3
3
|
* @param value The number or bigint to format.
|
|
4
4
|
* @param decimals Number of decimal places to include (ignored for bigint to avoid floating point issues).
|
|
5
5
|
* @returns The formatted number as a string.
|
|
6
6
|
*/
|
|
7
|
-
export declare function
|
|
7
|
+
export declare function formatNumberToCompactString(value: number | bigint, decimals?: number): string;
|
|
8
|
+
/**
|
|
9
|
+
* Formats a number or string into a locale-sensitive string with the desired number of decimals.
|
|
10
|
+
* @param value The number or string to format.
|
|
11
|
+
* @param desiredDecimals The number of decimal places to include.
|
|
12
|
+
* @returns The formatted number as a string.
|
|
13
|
+
* @see https://github.com/thesis/acre/blob/2078d339f4ddce79e69c78529c9d72910dd2640a/dapp/src/utils/numbersUtils.ts#L5-L19
|
|
14
|
+
*/
|
|
15
|
+
export declare function formatNumberToLocaleString(value: string | number, desiredDecimals?: number): string;
|
|
8
16
|
/**
|
|
9
17
|
* Returns a number rounded up to the desired number of decimals.
|
|
10
18
|
* @param amount The number to round up.
|
|
11
19
|
* @param desiredDecimals The number of decimals to round up to.
|
|
12
20
|
* @returns The rounded up number.
|
|
13
|
-
* @see https://github.com/thesis/acre/blob/
|
|
21
|
+
* @see https://github.com/thesis/acre/blob/2078d339f4ddce79e69c78529c9d72910dd2640a/dapp/src/utils/numbersUtils.ts#L1-L3
|
|
14
22
|
*/
|
|
15
23
|
export declare function roundUpNumber(amount: number, desiredDecimals?: number): number;
|
|
16
24
|
/**
|
|
@@ -20,24 +28,38 @@ export declare function roundUpNumber(amount: number, desiredDecimals?: number):
|
|
|
20
28
|
* @param fixedPointDecimals The number of decimals in the fixed point bigint.
|
|
21
29
|
* @param desiredDecimals The number of decimals in the output number.
|
|
22
30
|
* @returns The floating point number truncated to `desiredDecimals`.
|
|
23
|
-
* @see https://github.com/tahowallet/extension/blob/
|
|
31
|
+
* @see https://github.com/tahowallet/extension/blob/f6b26b7cb4a0a0278b1fccc6319626638f1a6dfa/background/lib/fixed-point.ts#L216-L239
|
|
24
32
|
*/
|
|
25
33
|
export declare function fromFixedPoint(fixedPoint: bigint, fixedPointDecimals: number, desiredDecimals?: number): number;
|
|
26
34
|
/**
|
|
27
|
-
* Display a
|
|
35
|
+
* Display a token amount correctly with desired decimals.
|
|
28
36
|
* The function returns a string with a language-sensitive representation of this number.
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* - If `formattedAmount` is less than the minimum amount to display
|
|
32
|
-
* for the specified precision return information about this.
|
|
33
|
-
* For example, <0.01 for a precision of 2.
|
|
34
|
-
* - Other amounts are formatted according to the use of the `bigIntToUserAmount` function.
|
|
35
|
-
* @param amount The amount of tokens to format.
|
|
36
|
-
* @param decimals The number of decimals the cryptoAsset has.
|
|
37
|
+
* @param amount The fixed point number to convert.
|
|
38
|
+
* @param decimals The number of decimals in the fixed point number.
|
|
37
39
|
* @param desiredDecimals The number of decimals to display.
|
|
38
|
-
* @param withRoundUp
|
|
39
|
-
* @returns The formatted
|
|
40
|
-
* @see https://github.com/thesis/acre/blob/
|
|
40
|
+
* @param withRoundUp Whether to round up the number.
|
|
41
|
+
* @returns The formatted number as a string.
|
|
42
|
+
* @see https://github.com/thesis/acre/blob/2078d339f4ddce79e69c78529c9d72910dd2640a/dapp/src/utils/numbersUtils.ts#L57-L87
|
|
43
|
+
*/
|
|
44
|
+
export declare const fromFixedPointToString: (amount: number | string | bigint, decimals?: number, desiredDecimals?: number, withRoundUp?: boolean) => string;
|
|
45
|
+
/**
|
|
46
|
+
* Converts a floating-point number or string to a bigint representation
|
|
47
|
+
* scaled by the specified number of decimal places (default: 18).
|
|
48
|
+
*
|
|
49
|
+
* This function avoids floating-point precision issues by manually
|
|
50
|
+
* parsing and scaling the number.
|
|
51
|
+
*
|
|
52
|
+
* @param amount - A number or string containing a floating point number.
|
|
53
|
+
* @param decimals - Number of decimals to scale to (default: 18).
|
|
54
|
+
* @returns A bigint representation scaled to the given decimal places.
|
|
55
|
+
* @see https://github.com/thesis/mezo-portal/blob/3bd4f39cb77c39948af2886a6ce7415a0c60307a/dapp/src/shared/utils/numbers.ts#L55
|
|
56
|
+
*/
|
|
57
|
+
export declare const fromFloatToBigInt: (amount: string | number, decimals?: number) => bigint;
|
|
58
|
+
/**
|
|
59
|
+
* Utility function to find the maximum value from an array of bigint values.
|
|
60
|
+
* @param values Array of bigint values to find the maximum from.
|
|
61
|
+
* @returns The maximum value from the provided bigint values.
|
|
62
|
+
* @dev Works exactly like `Math.max` but for bigint values.
|
|
41
63
|
*/
|
|
42
|
-
export declare
|
|
64
|
+
export declare const bigIntMax: (...values: bigint[]) => bigint;
|
|
43
65
|
//# sourceMappingURL=numbers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"numbers.d.ts","sourceRoot":"","sources":["../../../src/utils/numbers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"numbers.d.ts","sourceRoot":"","sources":["../../../src/utils/numbers.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,QAAQ,SAAI,GACX,MAAM,CAMR;AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,eAAe,SAAI,UAYpB;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,SAAI,GAAG,MAAM,CAEzE;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,UAAU,EAAE,MAAM,EAClB,kBAAkB,EAAE,MAAM,EAC1B,eAAe,SAAI,GAClB,MAAM,CAUR;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,sBAAsB,GACjC,QAAQ,MAAM,GAAG,MAAM,GAAG,MAAM,EAChC,iBAAa,EACb,wBAAmB,EACnB,qBAAmB,WA0BpB,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,iBAAiB,GAC5B,QAAQ,MAAM,GAAG,MAAM,EACvB,iBAAa,KACZ,MAmDF,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,SAAS,GAAI,GAAG,QAAQ,MAAM,EAAE,WACe,CAAA"}
|