@mezo-org/passport 0.4.0-dev.4 → 0.4.0-dev.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (303) hide show
  1. package/README.md +18 -22
  2. package/dist/src/api/auth.d.ts +36 -59
  3. package/dist/src/api/auth.d.ts.map +1 -1
  4. package/dist/src/api/auth.js +21 -49
  5. package/dist/src/api/auth.js.map +1 -1
  6. package/dist/src/api/client.d.ts +24 -0
  7. package/dist/src/api/client.d.ts.map +1 -0
  8. package/dist/src/api/client.js +54 -0
  9. package/dist/src/api/client.js.map +1 -0
  10. package/dist/src/api/fetch-error.d.ts +5 -0
  11. package/dist/src/api/fetch-error.d.ts.map +1 -0
  12. package/dist/src/api/fetch-error.js +8 -0
  13. package/dist/src/api/fetch-error.js.map +1 -0
  14. package/dist/src/api/index.d.ts +3 -0
  15. package/dist/src/api/index.d.ts.map +1 -0
  16. package/dist/src/api/index.js +3 -0
  17. package/dist/src/api/index.js.map +1 -0
  18. package/dist/src/api/portal.d.ts +33 -0
  19. package/dist/src/api/portal.d.ts.map +1 -0
  20. package/dist/src/api/portal.js +23 -0
  21. package/dist/src/api/portal.js.map +1 -0
  22. package/dist/src/assets/DefaultAvatar.d.ts +5 -0
  23. package/dist/src/assets/DefaultAvatar.d.ts.map +1 -0
  24. package/dist/src/assets/DefaultAvatar.js +21 -0
  25. package/dist/src/assets/DefaultAvatar.js.map +1 -0
  26. package/dist/src/components/Dropdown/ConnectedTrigger.d.ts +8 -0
  27. package/dist/src/components/Dropdown/ConnectedTrigger.d.ts.map +1 -0
  28. package/dist/src/components/Dropdown/ConnectedTrigger.js +39 -0
  29. package/dist/src/components/Dropdown/ConnectedTrigger.js.map +1 -0
  30. package/dist/src/components/Dropdown/Content.d.ts +23 -0
  31. package/dist/src/components/Dropdown/Content.d.ts.map +1 -0
  32. package/dist/src/components/Dropdown/Content.js +27 -0
  33. package/dist/src/components/Dropdown/Content.js.map +1 -0
  34. package/dist/src/components/Dropdown/DisconnectedTrigger.d.ts +7 -0
  35. package/dist/src/components/Dropdown/DisconnectedTrigger.d.ts.map +1 -0
  36. package/dist/src/components/Dropdown/DisconnectedTrigger.js +13 -0
  37. package/dist/src/components/Dropdown/DisconnectedTrigger.js.map +1 -0
  38. package/dist/src/components/Dropdown/Dropdown.d.ts +27 -0
  39. package/dist/src/components/Dropdown/Dropdown.d.ts.map +1 -0
  40. package/dist/src/components/Dropdown/Dropdown.js +68 -0
  41. package/dist/src/components/Dropdown/Dropdown.js.map +1 -0
  42. package/dist/src/components/Dropdown/ListingItem.d.ts +13 -0
  43. package/dist/src/components/Dropdown/ListingItem.d.ts.map +1 -0
  44. package/dist/src/components/Dropdown/ListingItem.js +34 -0
  45. package/dist/src/components/Dropdown/ListingItem.js.map +1 -0
  46. package/dist/src/components/Dropdown/NestedViewLayout.d.ts +7 -0
  47. package/dist/src/components/Dropdown/NestedViewLayout.d.ts.map +1 -0
  48. package/dist/src/components/Dropdown/NestedViewLayout.js +34 -0
  49. package/dist/src/components/Dropdown/NestedViewLayout.js.map +1 -0
  50. package/dist/src/components/Dropdown/Receive/Receive.d.ts +7 -0
  51. package/dist/src/components/Dropdown/Receive/Receive.d.ts.map +1 -0
  52. package/dist/src/components/Dropdown/Receive/Receive.js +53 -0
  53. package/dist/src/components/Dropdown/Receive/Receive.js.map +1 -0
  54. package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts +7 -0
  55. package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts.map +1 -0
  56. package/dist/src/components/Dropdown/Root/AccountAddressActions.js +48 -0
  57. package/dist/src/components/Dropdown/Root/AccountAddressActions.js.map +1 -0
  58. package/dist/src/components/Dropdown/Root/AccountAssetItem.d.ts +11 -0
  59. package/dist/src/components/Dropdown/Root/AccountAssetItem.d.ts.map +1 -0
  60. package/dist/src/components/Dropdown/Root/AccountAssetItem.js +9 -0
  61. package/dist/src/components/Dropdown/Root/AccountAssetItem.js.map +1 -0
  62. package/dist/src/components/Dropdown/Root/AccountBalance.d.ts +8 -0
  63. package/dist/src/components/Dropdown/Root/AccountBalance.d.ts.map +1 -0
  64. package/dist/src/components/Dropdown/Root/AccountBalance.js +15 -0
  65. package/dist/src/components/Dropdown/Root/AccountBalance.js.map +1 -0
  66. package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts +9 -0
  67. package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts.map +1 -0
  68. package/dist/src/components/Dropdown/Root/AccountOtherAssets.js +48 -0
  69. package/dist/src/components/Dropdown/Root/AccountOtherAssets.js.map +1 -0
  70. package/dist/src/components/Dropdown/Root/Root.d.ts +23 -0
  71. package/dist/src/components/Dropdown/Root/Root.d.ts.map +1 -0
  72. package/dist/src/components/Dropdown/Root/Root.js +57 -0
  73. package/dist/src/components/Dropdown/Root/Root.js.map +1 -0
  74. package/dist/src/components/Dropdown/Root/WalletAddress.d.ts +8 -0
  75. package/dist/src/components/Dropdown/Root/WalletAddress.d.ts.map +1 -0
  76. package/dist/src/components/Dropdown/Root/WalletAddress.js +64 -0
  77. package/dist/src/components/Dropdown/Root/WalletAddress.js.map +1 -0
  78. package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts +8 -0
  79. package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts.map +1 -0
  80. package/dist/src/components/Dropdown/Root/WelcomeBlock.js +44 -0
  81. package/dist/src/components/Dropdown/Root/WelcomeBlock.js.map +1 -0
  82. package/dist/src/components/Dropdown/TestnetTopBanner.d.ts +3 -0
  83. package/dist/src/components/Dropdown/TestnetTopBanner.d.ts.map +1 -0
  84. package/dist/src/components/Dropdown/TestnetTopBanner.js +14 -0
  85. package/dist/src/components/Dropdown/TestnetTopBanner.js.map +1 -0
  86. package/dist/src/components/Dropdown/index.d.ts +3 -0
  87. package/dist/src/components/Dropdown/index.d.ts.map +1 -0
  88. package/dist/src/components/Dropdown/index.js +2 -0
  89. package/dist/src/components/Dropdown/index.js.map +1 -0
  90. package/dist/src/components/index.d.ts +2 -0
  91. package/dist/src/components/index.d.ts.map +1 -0
  92. package/dist/src/components/index.js +2 -0
  93. package/dist/src/components/index.js.map +1 -0
  94. package/dist/src/config.d.ts +41 -0
  95. package/dist/src/config.d.ts.map +1 -1
  96. package/dist/src/config.js +17 -5
  97. package/dist/src/config.js.map +1 -1
  98. package/dist/src/constants.d.ts +6 -2
  99. package/dist/src/constants.d.ts.map +1 -1
  100. package/dist/src/constants.js +8 -4
  101. package/dist/src/constants.js.map +1 -1
  102. package/dist/src/hooks/constants.d.ts +1 -0
  103. package/dist/src/hooks/constants.d.ts.map +1 -1
  104. package/dist/src/hooks/constants.js +1 -0
  105. package/dist/src/hooks/constants.js.map +1 -1
  106. package/dist/src/hooks/index.d.ts +4 -1
  107. package/dist/src/hooks/index.d.ts.map +1 -1
  108. package/dist/src/hooks/index.js +4 -1
  109. package/dist/src/hooks/index.js.map +1 -1
  110. package/dist/src/hooks/useAssetsConversionRates.d.ts +7 -0
  111. package/dist/src/hooks/useAssetsConversionRates.d.ts.map +1 -0
  112. package/dist/src/hooks/useAssetsConversionRates.js +24 -0
  113. package/dist/src/hooks/useAssetsConversionRates.js.map +1 -0
  114. package/dist/src/hooks/useAuthApiClient.d.ts +1 -1
  115. package/dist/src/hooks/useAuthApiClient.d.ts.map +1 -1
  116. package/dist/src/hooks/useAuthenticateWithWallet.d.ts +73 -0
  117. package/dist/src/hooks/useAuthenticateWithWallet.d.ts.map +1 -0
  118. package/dist/src/hooks/useAuthenticateWithWallet.js +69 -0
  119. package/dist/src/hooks/useAuthenticateWithWallet.js.map +1 -0
  120. package/dist/src/hooks/useBorrowData.d.ts +60 -0
  121. package/dist/src/hooks/useBorrowData.d.ts.map +1 -0
  122. package/dist/src/hooks/useBorrowData.js +122 -0
  123. package/dist/src/hooks/useBorrowData.js.map +1 -0
  124. package/dist/src/hooks/useCreateAccount.d.ts +23 -173
  125. package/dist/src/hooks/useCreateAccount.d.ts.map +1 -1
  126. package/dist/src/hooks/useCreateAccount.js +7 -4
  127. package/dist/src/hooks/useCreateAccount.js.map +1 -1
  128. package/dist/src/hooks/useCreateSession.d.ts +12 -101
  129. package/dist/src/hooks/useCreateSession.d.ts.map +1 -1
  130. package/dist/src/hooks/useCreateSession.js +10 -8
  131. package/dist/src/hooks/useCreateSession.js.map +1 -1
  132. package/dist/src/hooks/useDropdownData.d.ts +47 -0
  133. package/dist/src/hooks/useDropdownData.d.ts.map +1 -0
  134. package/dist/src/hooks/useDropdownData.js +95 -0
  135. package/dist/src/hooks/useDropdownData.js.map +1 -0
  136. package/dist/src/hooks/useEnsureNoSessionAndFetchNonce.d.ts.map +1 -1
  137. package/dist/src/hooks/useEnsureNoSessionAndFetchNonce.js +1 -0
  138. package/dist/src/hooks/useEnsureNoSessionAndFetchNonce.js.map +1 -1
  139. package/dist/src/hooks/useGetAccountByAddress.d.ts +2 -2
  140. package/dist/src/hooks/useGetAccountByAddress.d.ts.map +1 -1
  141. package/dist/src/hooks/useGetAccountByMezoId.d.ts +2 -2
  142. package/dist/src/hooks/useGetAccountByMezoId.d.ts.map +1 -1
  143. package/dist/src/hooks/useGetCurrentAccount.d.ts +16 -2
  144. package/dist/src/hooks/useGetCurrentAccount.d.ts.map +1 -1
  145. package/dist/src/hooks/useGetCurrentAccount.js +25 -3
  146. package/dist/src/hooks/useGetCurrentAccount.js.map +1 -1
  147. package/dist/src/hooks/useGetSession.d.ts +1 -1
  148. package/dist/src/hooks/useGetSession.d.ts.map +1 -1
  149. package/dist/src/hooks/useLinkAccount.d.ts +15 -175
  150. package/dist/src/hooks/useLinkAccount.d.ts.map +1 -1
  151. package/dist/src/hooks/useLinkAccount.js +7 -4
  152. package/dist/src/hooks/useLinkAccount.js.map +1 -1
  153. package/dist/src/hooks/usePortalApiClient.d.ts +2 -0
  154. package/dist/src/hooks/usePortalApiClient.d.ts.map +1 -0
  155. package/dist/src/hooks/usePortalApiClient.js +6 -0
  156. package/dist/src/hooks/usePortalApiClient.js.map +1 -0
  157. package/dist/src/hooks/useRefreshPassport.d.ts +19 -0
  158. package/dist/src/hooks/useRefreshPassport.d.ts.map +1 -0
  159. package/dist/src/hooks/useRefreshPassport.js +44 -0
  160. package/dist/src/hooks/useRefreshPassport.js.map +1 -0
  161. package/dist/src/hooks/useSignInWithDiscord.d.ts +12 -100
  162. package/dist/src/hooks/useSignInWithDiscord.d.ts.map +1 -1
  163. package/dist/src/hooks/useSignInWithDiscord.js +6 -3
  164. package/dist/src/hooks/useSignInWithDiscord.js.map +1 -1
  165. package/dist/src/hooks/useSignInWithWallet.d.ts +12 -100
  166. package/dist/src/hooks/useSignInWithWallet.d.ts.map +1 -1
  167. package/dist/src/hooks/useSignInWithWallet.js +6 -34
  168. package/dist/src/hooks/useSignInWithWallet.js.map +1 -1
  169. package/dist/src/hooks/useSignOut.d.ts +12 -28
  170. package/dist/src/hooks/useSignOut.d.ts.map +1 -1
  171. package/dist/src/hooks/useSignOut.js +7 -4
  172. package/dist/src/hooks/useSignOut.js.map +1 -1
  173. package/dist/src/hooks/useSignUpWithWallet.d.ts +73 -0
  174. package/dist/src/hooks/useSignUpWithWallet.d.ts.map +1 -0
  175. package/dist/src/hooks/useSignUpWithWallet.js +11 -0
  176. package/dist/src/hooks/useSignUpWithWallet.js.map +1 -0
  177. package/dist/src/hooks/useTokensBalances.d.ts +74 -0
  178. package/dist/src/hooks/useTokensBalances.d.ts.map +1 -0
  179. package/dist/src/hooks/useTokensBalances.js +140 -0
  180. package/dist/src/hooks/useTokensBalances.js.map +1 -0
  181. package/dist/src/hooks/useUpdateMezoId.d.ts +30 -136
  182. package/dist/src/hooks/useUpdateMezoId.d.ts.map +1 -1
  183. package/dist/src/hooks/useUpdateMezoId.js +7 -4
  184. package/dist/src/hooks/useUpdateMezoId.js.map +1 -1
  185. package/dist/src/hooks/useWalletAccount.d.ts +13 -0
  186. package/dist/src/hooks/useWalletAccount.d.ts.map +1 -0
  187. package/dist/src/hooks/useWalletAccount.js +29 -0
  188. package/dist/src/hooks/useWalletAccount.js.map +1 -0
  189. package/dist/src/hooks/useWatchTransferEvents.d.ts +5 -0
  190. package/dist/src/hooks/useWatchTransferEvents.d.ts.map +1 -0
  191. package/dist/src/hooks/useWatchTransferEvents.js +63 -0
  192. package/dist/src/hooks/useWatchTransferEvents.js.map +1 -0
  193. package/dist/src/index.d.ts +2 -1
  194. package/dist/src/index.d.ts.map +1 -1
  195. package/dist/src/index.js +2 -1
  196. package/dist/src/index.js.map +1 -1
  197. package/dist/src/lib/contracts/index.d.ts +13 -0
  198. package/dist/src/lib/contracts/index.d.ts.map +1 -0
  199. package/dist/src/lib/contracts/index.js +57 -0
  200. package/dist/src/lib/contracts/index.js.map +1 -0
  201. package/dist/src/provider.d.ts +10 -13
  202. package/dist/src/provider.d.ts.map +1 -1
  203. package/dist/src/provider.js +11 -20
  204. package/dist/src/provider.js.map +1 -1
  205. package/dist/src/stores/dropdownStore.d.ts +12 -0
  206. package/dist/src/stores/dropdownStore.d.ts.map +1 -0
  207. package/dist/src/stores/dropdownStore.js +13 -0
  208. package/dist/src/stores/dropdownStore.js.map +1 -0
  209. package/dist/src/utils/address.d.ts +15 -0
  210. package/dist/src/utils/address.d.ts.map +1 -0
  211. package/dist/src/utils/address.js +37 -0
  212. package/dist/src/utils/address.js.map +1 -0
  213. package/dist/src/utils/address.test.d.ts +2 -0
  214. package/dist/src/utils/address.test.d.ts.map +1 -0
  215. package/dist/src/utils/address.test.js +40 -0
  216. package/dist/src/utils/address.test.js.map +1 -0
  217. package/dist/src/utils/cryptoAssets.d.ts +44 -0
  218. package/dist/src/utils/cryptoAssets.d.ts.map +1 -0
  219. package/dist/src/utils/cryptoAssets.js +131 -0
  220. package/dist/src/utils/cryptoAssets.js.map +1 -0
  221. package/dist/src/utils/cryptoAssets.test.d.ts +2 -0
  222. package/dist/src/utils/cryptoAssets.test.d.ts.map +1 -0
  223. package/dist/src/utils/cryptoAssets.test.js +67 -0
  224. package/dist/src/utils/cryptoAssets.test.js.map +1 -0
  225. package/dist/src/utils/currency.d.ts +14 -0
  226. package/dist/src/utils/currency.d.ts.map +1 -0
  227. package/dist/src/utils/currency.js +27 -0
  228. package/dist/src/utils/currency.js.map +1 -0
  229. package/dist/src/utils/currency.test.d.ts +2 -0
  230. package/dist/src/utils/currency.test.d.ts.map +1 -0
  231. package/dist/src/utils/currency.test.js +34 -0
  232. package/dist/src/utils/currency.test.js.map +1 -0
  233. package/dist/src/utils/numbers.d.ts +58 -0
  234. package/dist/src/utils/numbers.d.ts.map +1 -0
  235. package/dist/src/utils/numbers.js +132 -0
  236. package/dist/src/utils/numbers.js.map +1 -0
  237. package/dist/src/utils/numbers.test.d.ts +2 -0
  238. package/dist/src/utils/numbers.test.d.ts.map +1 -0
  239. package/dist/src/utils/numbers.test.js +170 -0
  240. package/dist/src/utils/numbers.test.js.map +1 -0
  241. package/package.json +13 -5
  242. package/src/api/auth.ts +72 -129
  243. package/src/api/client.ts +78 -0
  244. package/src/api/fetch-error.ts +8 -0
  245. package/src/api/index.ts +2 -0
  246. package/src/api/portal.ts +57 -0
  247. package/src/assets/DefaultAvatar.tsx +74 -0
  248. package/src/components/Dropdown/ConnectedTrigger.tsx +76 -0
  249. package/src/components/Dropdown/Content.tsx +98 -0
  250. package/src/components/Dropdown/DisconnectedTrigger.tsx +36 -0
  251. package/src/components/Dropdown/Dropdown.tsx +148 -0
  252. package/src/components/Dropdown/ListingItem.tsx +80 -0
  253. package/src/components/Dropdown/NestedViewLayout.tsx +75 -0
  254. package/src/components/Dropdown/README.md +41 -0
  255. package/src/components/Dropdown/Receive/Receive.tsx +119 -0
  256. package/src/components/Dropdown/Root/AccountAddressActions.tsx +101 -0
  257. package/src/components/Dropdown/Root/AccountAssetItem.tsx +26 -0
  258. package/src/components/Dropdown/Root/AccountBalance.tsx +30 -0
  259. package/src/components/Dropdown/Root/AccountOtherAssets.tsx +68 -0
  260. package/src/components/Dropdown/Root/Root.tsx +147 -0
  261. package/src/components/Dropdown/Root/WalletAddress.tsx +128 -0
  262. package/src/components/Dropdown/Root/WelcomeBlock.tsx +91 -0
  263. package/src/components/Dropdown/TestnetTopBanner.tsx +32 -0
  264. package/src/components/Dropdown/index.ts +2 -0
  265. package/src/components/index.ts +1 -0
  266. package/src/config.ts +24 -6
  267. package/src/constants.ts +8 -4
  268. package/src/hooks/constants.ts +1 -0
  269. package/src/hooks/index.ts +7 -1
  270. package/src/hooks/useAssetsConversionRates.ts +32 -0
  271. package/src/hooks/useAuthenticateWithWallet.ts +102 -0
  272. package/src/hooks/useBorrowData.ts +143 -0
  273. package/src/hooks/useCreateAccount.ts +19 -5
  274. package/src/hooks/useCreateSession.ts +22 -9
  275. package/src/hooks/useDropdownData.ts +139 -0
  276. package/src/hooks/useEnsureNoSessionAndFetchNonce.ts +1 -0
  277. package/src/hooks/useGetAccountByAddress.ts +2 -2
  278. package/src/hooks/useGetAccountByMezoId.ts +2 -2
  279. package/src/hooks/useGetCurrentAccount.ts +46 -6
  280. package/src/hooks/useGetSession.ts +1 -1
  281. package/src/hooks/useLinkAccount.ts +18 -5
  282. package/src/hooks/usePortalApiClient.ts +6 -0
  283. package/src/hooks/useRefreshPassport.ts +56 -0
  284. package/src/hooks/useSignInWithDiscord.ts +14 -5
  285. package/src/hooks/useSignInWithWallet.ts +14 -42
  286. package/src/hooks/useSignOut.ts +18 -4
  287. package/src/hooks/useSignUpWithWallet.ts +21 -0
  288. package/src/hooks/useTokensBalances.ts +187 -0
  289. package/src/hooks/useUpdateMezoId.ts +19 -4
  290. package/src/hooks/useWalletAccount.ts +55 -0
  291. package/src/hooks/useWatchTransferEvents.ts +74 -0
  292. package/src/index.ts +9 -1
  293. package/src/lib/contracts/index.ts +88 -0
  294. package/src/provider.ts +30 -37
  295. package/src/stores/dropdownStore.ts +20 -0
  296. package/src/utils/address.test.ts +48 -0
  297. package/src/utils/address.ts +45 -0
  298. package/src/utils/cryptoAssets.test.ts +79 -0
  299. package/src/utils/cryptoAssets.ts +173 -0
  300. package/src/utils/currency.test.ts +38 -0
  301. package/src/utils/currency.ts +32 -0
  302. package/src/utils/numbers.test.ts +220 -0
  303. package/src/utils/numbers.ts +188 -0
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Trims the address to the first 5 and last 5 characters.
3
+ * @param address The address to trim.
4
+ * @returns The trimmed address.
5
+ */
6
+ export declare function trimAddress(address: string): string;
7
+ /**
8
+ * Get the URL of the block explorer page for an address.
9
+ * @param address - The address to link to.
10
+ * @param chainType - The chain type of the address.
11
+ * @param isTestnet - Whether the address is on testnet.
12
+ * @returns The URL of the block explorer page for the address.
13
+ */
14
+ export declare function getAddressExplorerUrl(address: string, chainType: "bitcoin" | "evm" | "mezo", isTestnet: boolean): string;
15
+ //# sourceMappingURL=address.d.ts.map
@@ -0,0 +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;AAcD;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,SAAS,GAAG,KAAK,GAAG,MAAM,EACrC,SAAS,EAAE,OAAO,UASnB"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Trims the address to the first 5 and last 5 characters.
3
+ * @param address The address to trim.
4
+ * @returns The trimmed address.
5
+ */
6
+ export function trimAddress(address) {
7
+ if (address.length < 11)
8
+ return address;
9
+ const trimmedAddress = `${address.slice(0, 5)}...${address.slice(-5)}`;
10
+ return trimmedAddress;
11
+ }
12
+ const MAINNET_EXPLORER_URLS = {
13
+ bitcoin: "https://mempool.space",
14
+ evm: "https://etherscan.io",
15
+ mezo: "https://explorer.mezo.org",
16
+ };
17
+ const TESTNET_EXPLORER_URLS = {
18
+ bitcoin: "https://mempool.space/testnet",
19
+ evm: "https://sepolia.etherscan.io",
20
+ mezo: "https://explorer.test.mezo.org",
21
+ };
22
+ /**
23
+ * Get the URL of the block explorer page for an address.
24
+ * @param address - The address to link to.
25
+ * @param chainType - The chain type of the address.
26
+ * @param isTestnet - Whether the address is on testnet.
27
+ * @returns The URL of the block explorer page for the address.
28
+ */
29
+ export function getAddressExplorerUrl(address, chainType, isTestnet) {
30
+ const EXPLORER_URLS = isTestnet
31
+ ? TESTNET_EXPLORER_URLS
32
+ : MAINNET_EXPLORER_URLS;
33
+ const baseUrl = EXPLORER_URLS[chainType];
34
+ const endpoint = `address/${address}`;
35
+ return `${baseUrl}/${endpoint}`;
36
+ }
37
+ //# sourceMappingURL=address.js.map
@@ -0,0 +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,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"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=address.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"address.test.d.ts","sourceRoot":"","sources":["../../../src/utils/address.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,40 @@
1
+ import { getAddressExplorerUrl, trimAddress } from "./address";
2
+ describe("trimAddress", () => {
3
+ it("returns full address if length is less than 11", () => {
4
+ expect(trimAddress("0x12345")).toBe("0x12345");
5
+ });
6
+ it("returns trimmed address if length is 11 or more", () => {
7
+ const input = "0x123456789abcdef";
8
+ const expected = "0x123...bcdef";
9
+ expect(trimAddress(input)).toBe(expected);
10
+ });
11
+ });
12
+ describe("getAddressExplorerUrl", () => {
13
+ const btcAddress = "bc1qxyz123";
14
+ const evmAddress = "0x1234567890abcdef";
15
+ it("returns correct mainnet Bitcoin explorer URL", () => {
16
+ const url = getAddressExplorerUrl(btcAddress, "bitcoin", false);
17
+ expect(url).toBe(`https://mempool.space/address/${btcAddress}`);
18
+ });
19
+ it("returns correct testnet Bitcoin explorer URL", () => {
20
+ const url = getAddressExplorerUrl(btcAddress, "bitcoin", true);
21
+ expect(url).toBe(`https://mempool.space/testnet/address/${btcAddress}`);
22
+ });
23
+ it("returns correct mainnet EVM explorer URL", () => {
24
+ const url = getAddressExplorerUrl(evmAddress, "evm", false);
25
+ expect(url).toBe(`https://etherscan.io/address/${evmAddress}`);
26
+ });
27
+ it("returns correct testnet EVM explorer URL", () => {
28
+ const url = getAddressExplorerUrl(evmAddress, "evm", true);
29
+ expect(url).toBe(`https://sepolia.etherscan.io/address/${evmAddress}`);
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
+ });
39
+ });
40
+ //# sourceMappingURL=address.test.js.map
@@ -0,0 +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;AACJ,CAAC,CAAC,CAAA;AAEF,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,MAAM,UAAU,GAAG,YAAY,CAAA;IAC/B,MAAM,UAAU,GAAG,oBAAoB,CAAA;IAEvC,EAAE,CAAC,8CAA8C,EAAE,GAAG,EAAE;QACtD,MAAM,GAAG,GAAG,qBAAqB,CAAC,UAAU,EAAE,SAAS,EAAE,KAAK,CAAC,CAAA;QAC/D,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,iCAAiC,UAAU,EAAE,CAAC,CAAA;IACjE,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,8CAA8C,EAAE,GAAG,EAAE;QACtD,MAAM,GAAG,GAAG,qBAAqB,CAAC,UAAU,EAAE,SAAS,EAAE,IAAI,CAAC,CAAA;QAC9D,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,yCAAyC,UAAU,EAAE,CAAC,CAAA;IACzE,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,0CAA0C,EAAE,GAAG,EAAE;QAClD,MAAM,GAAG,GAAG,qBAAqB,CAAC,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,CAAA;QAC3D,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,gCAAgC,UAAU,EAAE,CAAC,CAAA;IAChE,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,0CAA0C,EAAE,GAAG,EAAE;QAClD,MAAM,GAAG,GAAG,qBAAqB,CAAC,UAAU,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;QAC1D,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,wCAAwC,UAAU,EAAE,CAAC,CAAA;IACxE,CAAC,CAAC,CAAA;IAEF,EAAE,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"}
@@ -0,0 +1,44 @@
1
+ import { IconProps } from "@mezo-org/mezo-clay";
2
+ import { FC } from "react";
3
+ import { MezoChainToken } from "../lib/contracts";
4
+ export type CryptoAssetKey = MezoChainToken | "BTC" | "ETH";
5
+ export type CryptoAsset = {
6
+ name: string;
7
+ symbol: string;
8
+ icon: FC<IconProps>;
9
+ decimals: number;
10
+ };
11
+ /**
12
+ * Gets details of given crypto asset
13
+ * @param key The key of crypto asset
14
+ * @returns The crypto asset details
15
+ */
16
+ export declare function getCryptoAsset(key: CryptoAssetKey): CryptoAsset;
17
+ /**
18
+ * Checks if given crypto asset is Bitcoin-like
19
+ * @param key The key of crypto asset
20
+ * @returns True if crypto asset is Bitcoin-like
21
+ */
22
+ export declare function isBitcoinLikeCryptoAsset(key: CryptoAssetKey): boolean;
23
+ /**
24
+ * Checks if given crypto asset is USD-like
25
+ * @param key The key of crypto asset
26
+ * @returns True if crypto asset is USD-like
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: number): {
37
+ type: CryptoAssetKey;
38
+ rawBalance: bigint;
39
+ formattedBalance: string;
40
+ usdBalance: number;
41
+ formattedUsdBalance: string;
42
+ };
43
+ export type DetailedCryptoAsset = ReturnType<typeof mapCryptoAssetToDetails>;
44
+ //# sourceMappingURL=cryptoAssets.d.ts.map
@@ -0,0 +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,EAAE,EAAE,EAAE,MAAM,OAAO,CAAA;AAC1B,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAQjD,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;;;;;;EAyB1B;AAED,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC,OAAO,uBAAuB,CAAC,CAAA"}
@@ -0,0 +1,131 @@
1
+ import { BitcoinCircle, EthCircle, MUsdCircle02, Cryptocurrency04, } from "@mezo-org/mezo-clay";
2
+ import { formatUsd } from "./currency";
3
+ import { fromFixedPointToString, fromFixedPoint, fromFloatToBigInt, } from "./numbers";
4
+ // TODO: Add actual icons for the assets
5
+ const CRYPTO_ASSETS = {
6
+ BTC: {
7
+ name: "Bitcoin",
8
+ symbol: "BTC",
9
+ icon: BitcoinCircle,
10
+ decimals: 18,
11
+ },
12
+ ETH: {
13
+ name: "Ethereum",
14
+ symbol: "ETH",
15
+ icon: EthCircle,
16
+ decimals: 18,
17
+ },
18
+ MUSD: {
19
+ name: "MUSD",
20
+ symbol: "MUSD",
21
+ icon: MUsdCircle02,
22
+ decimals: 18,
23
+ },
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,
34
+ decimals: 8,
35
+ },
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,
46
+ decimals: 18,
47
+ },
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,
82
+ decimals: 18,
83
+ },
84
+ };
85
+ /**
86
+ * Gets details of given crypto asset
87
+ * @param key The key of crypto asset
88
+ * @returns The crypto asset details
89
+ */
90
+ export function getCryptoAsset(key) {
91
+ return CRYPTO_ASSETS[key];
92
+ }
93
+ /**
94
+ * Checks if given crypto asset is Bitcoin-like
95
+ * @param key The key of crypto asset
96
+ * @returns True if crypto asset is Bitcoin-like
97
+ */
98
+ export function isBitcoinLikeCryptoAsset(key) {
99
+ return /(btc)/i.test(key);
100
+ }
101
+ /**
102
+ * Checks if given crypto asset is USD-like
103
+ * @param key The key of crypto asset
104
+ * @returns True if crypto asset is USD-like
105
+ */
106
+ export function isUsdLikeCryptoAsset(key) {
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) {
117
+ const { decimals } = getCryptoAsset(type);
118
+ const formattedBalance = fromFixedPointToString(balance, decimals, isUsdLikeCryptoAsset(type) ? 2 : 4);
119
+ const usdBalance = fromFixedPoint(
120
+ // Native BigInt constructor doesn't support floating point numbers.
121
+ balance * fromFloatToBigInt(usdConversionRate, 0), decimals);
122
+ const formattedUsdBalance = formatUsd(usdBalance);
123
+ return {
124
+ type,
125
+ rawBalance: balance,
126
+ formattedBalance,
127
+ usdBalance,
128
+ formattedUsdBalance,
129
+ };
130
+ }
131
+ //# sourceMappingURL=cryptoAssets.js.map
@@ -0,0 +1 @@
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,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,iBAAiB,GAClB,MAAM,WAAW,CAAA;AAWlB,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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AAM,UAAU,wBAAwB,CAAC,GAAmB;IAC1D,OAAO,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC3B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,GAAmB;IACtD,OAAO,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC/B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,uBAAuB,CACrC,IAAoB,EACpB,OAAe,EACf,iBAAyB;IAEzB,MAAM,EAAE,QAAQ,EAAE,GAAG,cAAc,CAAC,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,cAAc;IAC/B,oEAAoE;IACpE,OAAO,GAAG,iBAAiB,CAAC,iBAAiB,EAAE,CAAC,CAAC,EACjD,QAAQ,CACT,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"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=cryptoAssets.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cryptoAssets.test.d.ts","sourceRoot":"","sources":["../../../src/utils/cryptoAssets.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,67 @@
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)
4
+ describe("getCryptoAsset", () => {
5
+ it("returns the correct asset for 'BTC (mBTC)'", () => {
6
+ const asset = getCryptoAsset("BTC");
7
+ expect(asset.name).toBe("Bitcoin");
8
+ expect(asset.symbol).toBe("BTC");
9
+ expect(asset.decimals).toBe(18);
10
+ expect(asset.icon).toBe(BitcoinCircle);
11
+ });
12
+ it("returns the correct asset for 'ETH'", () => {
13
+ const asset = getCryptoAsset("ETH");
14
+ expect(asset.name).toBe("Ethereum");
15
+ expect(asset.symbol).toBe("ETH");
16
+ expect(asset.decimals).toBe(18);
17
+ expect(asset.icon).toBe(EthCircle);
18
+ });
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");
23
+ expect(asset.decimals).toBe(18);
24
+ expect(asset.icon).toBe(MUsdCircle02);
25
+ });
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
+ });
45
+ });
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
+ });
65
+ });
66
+ });
67
+ //# sourceMappingURL=cryptoAssets.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cryptoAssets.test.js","sourceRoot":"","sources":["../../../src/utils/cryptoAssets.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAC5E,OAAO,EAEL,cAAc,EACd,wBAAwB,EACxB,oBAAoB,GACrB,MAAM,gBAAgB,CAAA;AAEvB,8GAA8G;AAE9G,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,EAAE,CAAC,4CAA4C,EAAE,GAAG,EAAE;QACpD,MAAM,KAAK,GAAG,cAAc,CAAC,KAAK,CAAC,CAAA;QACnC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;QAClC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QAChC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QAC/B,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAA;IACxC,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,qCAAqC,EAAE,GAAG,EAAE;QAC7C,MAAM,KAAK,GAAG,cAAc,CAAC,KAAK,CAAC,CAAA;QACnC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;QACnC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,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EAAE;KAClC,CAAA;IAED,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE;QACpC,EAAE,CAAC,WAAW,QAAQ,QAAQ,KAAK,EAAE,EAAE,GAAG,EAAE;YAC1C,MAAM,CAAC,oBAAoB,CAAC,KAAuB,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QACtE,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Formats a number as a currency
3
+ * @param value The value to format
4
+ * @param options The options to pass to the formatter
5
+ * @returns The formatted currency
6
+ */
7
+ export declare function formatCurrency(value: number, options?: Omit<Intl.NumberFormatOptions, "style">): string;
8
+ /**
9
+ * Formats a number as a USD currency
10
+ * @param value The value to format
11
+ * @returns The formatted currency
12
+ */
13
+ export declare function formatUsd(value: number): string;
14
+ //# sourceMappingURL=currency.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"currency.d.ts","sourceRoot":"","sources":["../../../src/utils/currency.ts"],"names":[],"mappings":"AAMA;;;;;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"}
@@ -0,0 +1,27 @@
1
+ const DEFAULT_FORMAT_OPTIONS = {
2
+ style: "currency",
3
+ minimumFractionDigits: 2,
4
+ maximumFractionDigits: 2,
5
+ };
6
+ /**
7
+ * Formats a number as a currency
8
+ * @param value The value to format
9
+ * @param options The options to pass to the formatter
10
+ * @returns The formatted currency
11
+ */
12
+ export function formatCurrency(value, options = {}) {
13
+ const formatter = new Intl.NumberFormat("en-US", {
14
+ ...DEFAULT_FORMAT_OPTIONS,
15
+ ...options,
16
+ });
17
+ return formatter.format(value);
18
+ }
19
+ /**
20
+ * Formats a number as a USD currency
21
+ * @param value The value to format
22
+ * @returns The formatted currency
23
+ */
24
+ export function formatUsd(value) {
25
+ return formatCurrency(value, { currency: "USD" });
26
+ }
27
+ //# sourceMappingURL=currency.js.map
@@ -0,0 +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"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=currency.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"currency.test.d.ts","sourceRoot":"","sources":["../../../src/utils/currency.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,34 @@
1
+ import { formatCurrency, formatUsd } from "./currency";
2
+ describe("formatCurrency", () => {
3
+ it("formats a number as currency with default options", () => {
4
+ const result = formatCurrency(1234.5, { currency: "EUR" });
5
+ expect(result).toBe("€1,234.50");
6
+ });
7
+ it("respects minimumFractionDigits (min = 3, max = 3)", () => {
8
+ const result = formatCurrency(1.2, {
9
+ currency: "USD",
10
+ minimumFractionDigits: 3,
11
+ maximumFractionDigits: 3,
12
+ });
13
+ expect(result).toBe("$1.200");
14
+ });
15
+ it("respects maximumFractionDigits (min = 0, max = 1)", () => {
16
+ const result = formatCurrency(1.234567, {
17
+ currency: "USD",
18
+ minimumFractionDigits: 0,
19
+ maximumFractionDigits: 1,
20
+ });
21
+ expect(result).toBe("$1.2");
22
+ });
23
+ });
24
+ describe("formatUsd", () => {
25
+ it("formats a number as USD", () => {
26
+ const result = formatUsd(99.99);
27
+ expect(result).toBe("$99.99");
28
+ });
29
+ it("formats zero", () => {
30
+ const result = formatUsd(0);
31
+ expect(result).toBe("$0.00");
32
+ });
33
+ });
34
+ //# sourceMappingURL=currency.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"currency.test.js","sourceRoot":"","sources":["../../../src/utils/currency.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAEtD,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,EAAE,CAAC,mDAAmD,EAAE,GAAG,EAAE;QAC3D,MAAM,MAAM,GAAG,cAAc,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAA;QAC1D,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;IAClC,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,mDAAmD,EAAE,GAAG,EAAE;QAC3D,MAAM,MAAM,GAAG,cAAc,CAAC,GAAG,EAAE;YACjC,QAAQ,EAAE,KAAK;YACf,qBAAqB,EAAE,CAAC;YACxB,qBAAqB,EAAE,CAAC;SACzB,CAAC,CAAA;QACF,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAC/B,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,mDAAmD,EAAE,GAAG,EAAE;QAC3D,MAAM,MAAM,GAAG,cAAc,CAAC,QAAQ,EAAE;YACtC,QAAQ,EAAE,KAAK;YACf,qBAAqB,EAAE,CAAC;YACxB,qBAAqB,EAAE,CAAC;SACzB,CAAC,CAAA;QACF,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAC7B,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA;AAEF,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,EAAE,CAAC,yBAAyB,EAAE,GAAG,EAAE;QACjC,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,CAAA;QAC/B,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAC/B,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,cAAc,EAAE,GAAG,EAAE;QACtB,MAAM,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,CAAA;QAC3B,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAC9B,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Formats a number or bigint into compact string with K, M, B, or T suffix.
3
+ * @param value The number or bigint to format.
4
+ * @param decimals Number of decimal places to include (ignored for bigint to avoid floating point issues).
5
+ * @returns The formatted number as a string.
6
+ */
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;
16
+ /**
17
+ * Returns a number rounded up to the desired number of decimals.
18
+ * @param amount The number to round up.
19
+ * @param desiredDecimals The number of decimals to round up to.
20
+ * @returns The rounded up number.
21
+ * @see https://github.com/thesis/acre/blob/2078d339f4ddce79e69c78529c9d72910dd2640a/dapp/src/utils/numbersUtils.ts#L1-L3
22
+ */
23
+ export declare function roundUpNumber(amount: number, desiredDecimals?: number): number;
24
+ /**
25
+ * Convert a fixed point bigint with precision `fixedPointDecimals` to a
26
+ * floating point number truncated to `desiredDecimals`.
27
+ * @param fixedPoint The fixed point bigint to convert.
28
+ * @param fixedPointDecimals The number of decimals in the fixed point bigint.
29
+ * @param desiredDecimals The number of decimals in the output number.
30
+ * @returns The floating point number truncated to `desiredDecimals`.
31
+ * @see https://github.com/tahowallet/extension/blob/f6b26b7cb4a0a0278b1fccc6319626638f1a6dfa/background/lib/fixed-point.ts#L216-L239
32
+ */
33
+ export declare function fromFixedPoint(fixedPoint: bigint, fixedPointDecimals: number, desiredDecimals?: number): number;
34
+ /**
35
+ * Display a token amount correctly with desired decimals.
36
+ * The function returns a string with a language-sensitive representation of this number.
37
+ * @param amount The fixed point number to convert.
38
+ * @param decimals The number of decimals in the fixed point number.
39
+ * @param desiredDecimals The number of decimals to display.
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
+ //# sourceMappingURL=numbers.d.ts.map
@@ -0,0 +1 @@
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"}