@mezo-org/passport 0.4.0-dev.9 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (300) hide show
  1. package/README.md +18 -22
  2. package/dist/src/api/auth.d.ts +7 -3
  3. package/dist/src/api/auth.d.ts.map +1 -1
  4. package/dist/src/api/auth.js +3 -1
  5. package/dist/src/api/auth.js.map +1 -1
  6. package/dist/src/api/client.d.ts +4 -1
  7. package/dist/src/api/client.d.ts.map +1 -1
  8. package/dist/src/api/client.js +9 -2
  9. package/dist/src/api/client.js.map +1 -1
  10. package/dist/src/api/portal.d.ts +3 -9
  11. package/dist/src/api/portal.d.ts.map +1 -1
  12. package/dist/src/api/portal.js +8 -5
  13. package/dist/src/api/portal.js.map +1 -1
  14. package/dist/src/components/Dropdown/ConnectedTrigger.d.ts +2 -1
  15. package/dist/src/components/Dropdown/ConnectedTrigger.d.ts.map +1 -1
  16. package/dist/src/components/Dropdown/ConnectedTrigger.js +29 -20
  17. package/dist/src/components/Dropdown/ConnectedTrigger.js.map +1 -1
  18. package/dist/src/components/Dropdown/Content.d.ts +4 -5
  19. package/dist/src/components/Dropdown/Content.d.ts.map +1 -1
  20. package/dist/src/components/Dropdown/Content.js +19 -61
  21. package/dist/src/components/Dropdown/Content.js.map +1 -1
  22. package/dist/src/components/Dropdown/DisconnectedTrigger.d.ts.map +1 -1
  23. package/dist/src/components/Dropdown/DisconnectedTrigger.js +2 -2
  24. package/dist/src/components/Dropdown/DisconnectedTrigger.js.map +1 -1
  25. package/dist/src/components/Dropdown/Dropdown.d.ts +9 -6
  26. package/dist/src/components/Dropdown/Dropdown.d.ts.map +1 -1
  27. package/dist/src/components/Dropdown/Dropdown.js +10 -10
  28. package/dist/src/components/Dropdown/Dropdown.js.map +1 -1
  29. package/dist/src/components/Dropdown/ListingItem.d.ts +14 -0
  30. package/dist/src/components/Dropdown/ListingItem.d.ts.map +1 -0
  31. package/dist/src/components/Dropdown/ListingItem.js +42 -0
  32. package/dist/src/components/Dropdown/ListingItem.js.map +1 -0
  33. package/dist/src/components/Dropdown/NestedViewLayout.d.ts +8 -0
  34. package/dist/src/components/Dropdown/NestedViewLayout.d.ts.map +1 -0
  35. package/dist/src/components/Dropdown/NestedViewLayout.js +32 -0
  36. package/dist/src/components/Dropdown/NestedViewLayout.js.map +1 -0
  37. package/dist/src/components/Dropdown/Receive/Receive.d.ts +4 -0
  38. package/dist/src/components/Dropdown/Receive/Receive.d.ts.map +1 -0
  39. package/dist/src/components/Dropdown/Receive/Receive.js +64 -0
  40. package/dist/src/components/Dropdown/Receive/Receive.js.map +1 -0
  41. package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts +4 -0
  42. package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts.map +1 -0
  43. package/dist/src/components/Dropdown/Root/AccountAddressActions.js +49 -0
  44. package/dist/src/components/Dropdown/Root/AccountAddressActions.js.map +1 -0
  45. package/dist/src/components/Dropdown/Root/AccountBalance.d.ts +6 -0
  46. package/dist/src/components/Dropdown/Root/AccountBalance.d.ts.map +1 -0
  47. package/dist/src/components/Dropdown/Root/AccountBalance.js +31 -0
  48. package/dist/src/components/Dropdown/Root/AccountBalance.js.map +1 -0
  49. package/dist/src/components/Dropdown/Root/AccountBtcListing.d.ts +6 -0
  50. package/dist/src/components/Dropdown/Root/AccountBtcListing.d.ts.map +1 -0
  51. package/dist/src/components/Dropdown/Root/AccountBtcListing.js +27 -0
  52. package/dist/src/components/Dropdown/Root/AccountBtcListing.js.map +1 -0
  53. package/dist/src/components/Dropdown/Root/AccountError.d.ts +8 -0
  54. package/dist/src/components/Dropdown/Root/AccountError.d.ts.map +1 -0
  55. package/dist/src/components/Dropdown/Root/AccountError.js +17 -0
  56. package/dist/src/components/Dropdown/Root/AccountError.js.map +1 -0
  57. package/dist/src/components/Dropdown/Root/AccountMusdListing.d.ts +4 -0
  58. package/dist/src/components/Dropdown/Root/AccountMusdListing.d.ts.map +1 -0
  59. package/dist/src/components/Dropdown/Root/AccountMusdListing.js +21 -0
  60. package/dist/src/components/Dropdown/Root/AccountMusdListing.js.map +1 -0
  61. package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts +8 -0
  62. package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts.map +1 -0
  63. package/dist/src/components/Dropdown/Root/AccountOtherAssets.js +43 -0
  64. package/dist/src/components/Dropdown/Root/AccountOtherAssets.js.map +1 -0
  65. package/dist/src/components/Dropdown/Root/Root.d.ts +8 -0
  66. package/dist/src/components/Dropdown/Root/Root.d.ts.map +1 -0
  67. package/dist/src/components/Dropdown/Root/Root.js +45 -0
  68. package/dist/src/components/Dropdown/Root/Root.js.map +1 -0
  69. package/dist/src/components/Dropdown/Root/WalletAddress.d.ts +4 -0
  70. package/dist/src/components/Dropdown/Root/WalletAddress.d.ts.map +1 -0
  71. package/dist/src/components/Dropdown/Root/WalletAddress.js +66 -0
  72. package/dist/src/components/Dropdown/Root/WalletAddress.js.map +1 -0
  73. package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts +6 -0
  74. package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts.map +1 -0
  75. package/dist/src/components/Dropdown/Root/WelcomeBlock.js +88 -0
  76. package/dist/src/components/Dropdown/Root/WelcomeBlock.js.map +1 -0
  77. package/dist/src/components/Dropdown/SlotNumber.d.ts +19 -0
  78. package/dist/src/components/Dropdown/SlotNumber.d.ts.map +1 -0
  79. package/dist/src/components/Dropdown/SlotNumber.js +67 -0
  80. package/dist/src/components/Dropdown/SlotNumber.js.map +1 -0
  81. package/dist/src/components/Dropdown/TestnetTopBanner.d.ts +3 -0
  82. package/dist/src/components/Dropdown/TestnetTopBanner.d.ts.map +1 -0
  83. package/dist/src/components/Dropdown/TestnetTopBanner.js +14 -0
  84. package/dist/src/components/Dropdown/TestnetTopBanner.js.map +1 -0
  85. package/dist/src/config.d.ts +19 -5
  86. package/dist/src/config.d.ts.map +1 -1
  87. package/dist/src/config.js +58 -14
  88. package/dist/src/config.js.map +1 -1
  89. package/dist/src/constants.d.ts +11 -3
  90. package/dist/src/constants.d.ts.map +1 -1
  91. package/dist/src/constants.js +12 -4
  92. package/dist/src/constants.js.map +1 -1
  93. package/dist/src/hooks/index.d.ts +4 -0
  94. package/dist/src/hooks/index.d.ts.map +1 -1
  95. package/dist/src/hooks/index.js +4 -0
  96. package/dist/src/hooks/index.js.map +1 -1
  97. package/dist/src/hooks/useAssetsConversionRates.d.ts +18 -0
  98. package/dist/src/hooks/useAssetsConversionRates.d.ts.map +1 -0
  99. package/dist/src/hooks/useAssetsConversionRates.js +67 -0
  100. package/dist/src/hooks/useAssetsConversionRates.js.map +1 -0
  101. package/dist/src/hooks/useAuthenticateWithWallet.d.ts +13 -13
  102. package/dist/src/hooks/useAuthenticateWithWallet.d.ts.map +1 -1
  103. package/dist/src/hooks/useAuthenticateWithWallet.js +9 -8
  104. package/dist/src/hooks/useAuthenticateWithWallet.js.map +1 -1
  105. package/dist/src/hooks/useBorrowData.d.ts +108 -0
  106. package/dist/src/hooks/useBorrowData.d.ts.map +1 -0
  107. package/dist/src/hooks/useBorrowData.js +201 -0
  108. package/dist/src/hooks/useBorrowData.js.map +1 -0
  109. package/dist/src/hooks/useCreateAccount.d.ts.map +1 -1
  110. package/dist/src/hooks/useCreateAccount.js +22 -1
  111. package/dist/src/hooks/useCreateAccount.js.map +1 -1
  112. package/dist/src/hooks/useGetCurrentAccount.d.ts.map +1 -1
  113. package/dist/src/hooks/useGetCurrentAccount.js +4 -6
  114. package/dist/src/hooks/useGetCurrentAccount.js.map +1 -1
  115. package/dist/src/hooks/useLinkAccount.d.ts +19 -13
  116. package/dist/src/hooks/useLinkAccount.d.ts.map +1 -1
  117. package/dist/src/hooks/useLinkAccount.js +20 -1
  118. package/dist/src/hooks/useLinkAccount.js.map +1 -1
  119. package/dist/src/hooks/useRefreshPassport.d.ts +19 -0
  120. package/dist/src/hooks/useRefreshPassport.d.ts.map +1 -0
  121. package/dist/src/hooks/useRefreshPassport.js +44 -0
  122. package/dist/src/hooks/useRefreshPassport.js.map +1 -0
  123. package/dist/src/hooks/useSignInWithWallet.d.ts +13 -13
  124. package/dist/src/hooks/useSignInWithWallet.d.ts.map +1 -1
  125. package/dist/src/hooks/useSignUpWithWallet.d.ts +13 -13
  126. package/dist/src/hooks/useSignUpWithWallet.d.ts.map +1 -1
  127. package/dist/src/hooks/useTokensBalances.d.ts +75 -0
  128. package/dist/src/hooks/useTokensBalances.d.ts.map +1 -0
  129. package/dist/src/hooks/useTokensBalances.js +181 -0
  130. package/dist/src/hooks/useTokensBalances.js.map +1 -0
  131. package/dist/src/hooks/useValidateMezoId.d.ts +8 -0
  132. package/dist/src/hooks/useValidateMezoId.d.ts.map +1 -0
  133. package/dist/src/hooks/useValidateMezoId.js +24 -0
  134. package/dist/src/hooks/useValidateMezoId.js.map +1 -0
  135. package/dist/src/hooks/useWalletAccount.d.ts +2 -1
  136. package/dist/src/hooks/useWalletAccount.d.ts.map +1 -1
  137. package/dist/src/hooks/useWalletAccount.js +20 -15
  138. package/dist/src/hooks/useWalletAccount.js.map +1 -1
  139. package/dist/src/hooks/useWatchTransferEvents.d.ts +5 -0
  140. package/dist/src/hooks/useWatchTransferEvents.d.ts.map +1 -0
  141. package/dist/src/hooks/useWatchTransferEvents.js +63 -0
  142. package/dist/src/hooks/useWatchTransferEvents.js.map +1 -0
  143. package/dist/src/index.d.ts +2 -1
  144. package/dist/src/index.d.ts.map +1 -1
  145. package/dist/src/index.js +2 -1
  146. package/dist/src/index.js.map +1 -1
  147. package/dist/src/lib/contracts/index.d.ts +13 -0
  148. package/dist/src/lib/contracts/index.d.ts.map +1 -0
  149. package/dist/src/lib/contracts/index.js +66 -0
  150. package/dist/src/lib/contracts/index.js.map +1 -0
  151. package/dist/src/lib/contracts/priceOracle.d.ts +43 -0
  152. package/dist/src/lib/contracts/priceOracle.d.ts.map +1 -0
  153. package/dist/src/lib/contracts/priceOracle.js +52 -0
  154. package/dist/src/lib/contracts/priceOracle.js.map +1 -0
  155. package/dist/src/provider.d.ts +7 -1
  156. package/dist/src/provider.d.ts.map +1 -1
  157. package/dist/src/provider.js +4 -1
  158. package/dist/src/provider.js.map +1 -1
  159. package/dist/src/stores/dropdownStore.d.ts +12 -0
  160. package/dist/src/stores/dropdownStore.d.ts.map +1 -0
  161. package/dist/src/stores/dropdownStore.js +13 -0
  162. package/dist/src/stores/dropdownStore.js.map +1 -0
  163. package/dist/src/utils/address.d.ts +1 -1
  164. package/dist/src/utils/address.d.ts.map +1 -1
  165. package/dist/src/utils/address.js +2 -0
  166. package/dist/src/utils/address.js.map +1 -1
  167. package/dist/src/utils/address.test.js +8 -5
  168. package/dist/src/utils/address.test.js.map +1 -1
  169. package/dist/src/utils/assets.d.ts +145 -0
  170. package/dist/src/utils/assets.d.ts.map +1 -0
  171. package/dist/src/utils/assets.js +100 -0
  172. package/dist/src/utils/assets.js.map +1 -0
  173. package/dist/src/utils/assets.test.d.ts +2 -0
  174. package/dist/src/utils/assets.test.d.ts.map +1 -0
  175. package/dist/src/utils/assets.test.js +46 -0
  176. package/dist/src/utils/assets.test.js.map +1 -0
  177. package/dist/src/utils/currency.d.ts +13 -2
  178. package/dist/src/utils/currency.d.ts.map +1 -1
  179. package/dist/src/utils/currency.js +22 -8
  180. package/dist/src/utils/currency.js.map +1 -1
  181. package/dist/src/utils/currency.test.js +44 -1
  182. package/dist/src/utils/currency.test.js.map +1 -1
  183. package/dist/src/utils/mezoId.d.ts +7 -0
  184. package/dist/src/utils/mezoId.d.ts.map +1 -0
  185. package/dist/src/utils/mezoId.js +41 -0
  186. package/dist/src/utils/mezoId.js.map +1 -0
  187. package/dist/src/utils/numbers.d.ts +15 -33
  188. package/dist/src/utils/numbers.d.ts.map +1 -1
  189. package/dist/src/utils/numbers.js +26 -70
  190. package/dist/src/utils/numbers.js.map +1 -1
  191. package/dist/src/utils/numbers.test.js +46 -42
  192. package/dist/src/utils/numbers.test.js.map +1 -1
  193. package/dist/src/utils/siww.d.ts +1 -0
  194. package/dist/src/utils/siww.d.ts.map +1 -1
  195. package/dist/src/utils/siww.js +50 -12
  196. package/dist/src/utils/siww.js.map +1 -1
  197. package/dist/src/utils/wagmi.d.ts +3 -0
  198. package/dist/src/utils/wagmi.d.ts.map +1 -0
  199. package/dist/src/utils/wagmi.js +7 -0
  200. package/dist/src/utils/wagmi.js.map +1 -0
  201. package/dist/src/wallet/index.d.ts +1 -1
  202. package/dist/src/wallet/index.d.ts.map +1 -1
  203. package/dist/src/wallet/index.js +1 -1
  204. package/dist/src/wallet/index.js.map +1 -1
  205. package/package.json +11 -8
  206. package/src/api/auth.ts +8 -4
  207. package/src/api/client.ts +11 -2
  208. package/src/api/portal.ts +11 -14
  209. package/src/components/Dropdown/ConnectedTrigger.tsx +52 -32
  210. package/src/components/Dropdown/Content.tsx +26 -121
  211. package/src/components/Dropdown/DisconnectedTrigger.tsx +2 -1
  212. package/src/components/Dropdown/Dropdown.tsx +29 -17
  213. package/src/components/Dropdown/ListingItem.tsx +176 -0
  214. package/src/components/Dropdown/NestedViewLayout.tsx +87 -0
  215. package/src/components/Dropdown/README.md +10 -18
  216. package/src/components/Dropdown/Receive/Receive.tsx +144 -0
  217. package/src/components/Dropdown/Root/AccountAddressActions.tsx +99 -0
  218. package/src/components/Dropdown/Root/AccountBalance.tsx +68 -0
  219. package/src/components/Dropdown/Root/AccountBtcListing.tsx +52 -0
  220. package/src/components/Dropdown/Root/AccountError.tsx +34 -0
  221. package/src/components/Dropdown/Root/AccountMusdListing.tsx +45 -0
  222. package/src/components/Dropdown/Root/AccountOtherAssets.tsx +85 -0
  223. package/src/components/Dropdown/Root/Root.tsx +77 -0
  224. package/src/components/Dropdown/Root/WalletAddress.tsx +123 -0
  225. package/src/components/Dropdown/Root/WelcomeBlock.tsx +173 -0
  226. package/src/components/Dropdown/SlotNumber.tsx +131 -0
  227. package/src/components/Dropdown/TestnetTopBanner.tsx +32 -0
  228. package/src/config.ts +88 -20
  229. package/src/constants.ts +12 -4
  230. package/src/hooks/index.ts +7 -0
  231. package/src/hooks/useAssetsConversionRates.ts +79 -0
  232. package/src/hooks/useAuthenticateWithWallet.ts +30 -14
  233. package/src/hooks/useBorrowData.ts +246 -0
  234. package/src/hooks/useCreateAccount.ts +29 -2
  235. package/src/hooks/useGetCurrentAccount.ts +5 -7
  236. package/src/hooks/useLinkAccount.ts +37 -4
  237. package/src/hooks/useRefreshPassport.ts +56 -0
  238. package/src/hooks/useSignInWithWallet.ts +2 -2
  239. package/src/hooks/useSignUpWithWallet.ts +2 -2
  240. package/src/hooks/useTokensBalances.ts +265 -0
  241. package/src/hooks/useValidateMezoId.ts +31 -0
  242. package/src/hooks/useWalletAccount.ts +32 -20
  243. package/src/hooks/useWatchTransferEvents.ts +74 -0
  244. package/src/index.ts +12 -1
  245. package/src/lib/contracts/index.ts +99 -0
  246. package/src/lib/contracts/priceOracle.ts +53 -0
  247. package/src/provider.ts +11 -3
  248. package/src/stores/dropdownStore.ts +20 -0
  249. package/src/utils/address.test.ts +10 -6
  250. package/src/utils/address.ts +5 -3
  251. package/src/utils/assets.test.ts +57 -0
  252. package/src/utils/assets.ts +103 -0
  253. package/src/utils/currency.test.ts +77 -1
  254. package/src/utils/currency.ts +35 -9
  255. package/src/utils/mezoId.ts +51 -0
  256. package/src/utils/numbers.test.ts +49 -42
  257. package/src/utils/numbers.ts +33 -95
  258. package/src/utils/siww.ts +71 -16
  259. package/src/utils/wagmi.ts +12 -0
  260. package/src/wallet/index.ts +3 -2
  261. package/dist/src/components/Dropdown/AccountAddress.d.ts +0 -8
  262. package/dist/src/components/Dropdown/AccountAddress.d.ts.map +0 -1
  263. package/dist/src/components/Dropdown/AccountAddress.js +0 -58
  264. package/dist/src/components/Dropdown/AccountAddress.js.map +0 -1
  265. package/dist/src/components/Dropdown/AccountAssets.d.ts +0 -14
  266. package/dist/src/components/Dropdown/AccountAssets.d.ts.map +0 -1
  267. package/dist/src/components/Dropdown/AccountAssets.js +0 -44
  268. package/dist/src/components/Dropdown/AccountAssets.js.map +0 -1
  269. package/dist/src/components/Dropdown/AccountBalance.d.ts +0 -7
  270. package/dist/src/components/Dropdown/AccountBalance.d.ts.map +0 -1
  271. package/dist/src/components/Dropdown/AccountBalance.js +0 -18
  272. package/dist/src/components/Dropdown/AccountBalance.js.map +0 -1
  273. package/dist/src/components/Dropdown/WelcomeBlock.d.ts +0 -8
  274. package/dist/src/components/Dropdown/WelcomeBlock.d.ts.map +0 -1
  275. package/dist/src/components/Dropdown/WelcomeBlock.js +0 -44
  276. package/dist/src/components/Dropdown/WelcomeBlock.js.map +0 -1
  277. package/dist/src/hooks/useAssetsUSDConversion.d.ts +0 -8
  278. package/dist/src/hooks/useAssetsUSDConversion.d.ts.map +0 -1
  279. package/dist/src/hooks/useAssetsUSDConversion.js +0 -21
  280. package/dist/src/hooks/useAssetsUSDConversion.js.map +0 -1
  281. package/dist/src/hooks/useDropdownData.d.ts +0 -44
  282. package/dist/src/hooks/useDropdownData.d.ts.map +0 -1
  283. package/dist/src/hooks/useDropdownData.js +0 -73
  284. package/dist/src/hooks/useDropdownData.js.map +0 -1
  285. package/dist/src/utils/cryptoAssets.d.ts +0 -28
  286. package/dist/src/utils/cryptoAssets.d.ts.map +0 -1
  287. package/dist/src/utils/cryptoAssets.js +0 -73
  288. package/dist/src/utils/cryptoAssets.js.map +0 -1
  289. package/dist/src/utils/cryptoAssets.test.d.ts +0 -2
  290. package/dist/src/utils/cryptoAssets.test.d.ts.map +0 -1
  291. package/dist/src/utils/cryptoAssets.test.js +0 -49
  292. package/dist/src/utils/cryptoAssets.test.js.map +0 -1
  293. package/src/components/Dropdown/AccountAddress.tsx +0 -111
  294. package/src/components/Dropdown/AccountAssets.tsx +0 -110
  295. package/src/components/Dropdown/AccountBalance.tsx +0 -38
  296. package/src/components/Dropdown/WelcomeBlock.tsx +0 -92
  297. package/src/hooks/useAssetsUSDConversion.ts +0 -31
  298. package/src/hooks/useDropdownData.ts +0 -130
  299. package/src/utils/cryptoAssets.test.ts +0 -59
  300. package/src/utils/cryptoAssets.ts +0 -93
@@ -10,12 +10,6 @@ describe("trimAddress", () => {
10
10
  const expected = "0x123...bcdef"
11
11
  expect(trimAddress(input)).toBe(expected)
12
12
  })
13
-
14
- it("returns lowercase result", () => {
15
- const input = "0xABCDEF1234567890"
16
- const expected = "0xabc...67890"
17
- expect(trimAddress(input)).toBe(expected)
18
- })
19
13
  })
20
14
 
21
15
  describe("getAddressExplorerUrl", () => {
@@ -41,4 +35,14 @@ describe("getAddressExplorerUrl", () => {
41
35
  const url = getAddressExplorerUrl(evmAddress, "evm", true)
42
36
  expect(url).toBe(`https://sepolia.etherscan.io/address/${evmAddress}`)
43
37
  })
38
+
39
+ it("returns correct mainnet Mezo explorer URL", () => {
40
+ const url = getAddressExplorerUrl(evmAddress, "mezo", false)
41
+ expect(url).toBe(`https://explorer.mezo.org/address/${evmAddress}`)
42
+ })
43
+
44
+ it("returns correct testnet Mezo explorer URL", () => {
45
+ const url = getAddressExplorerUrl(evmAddress, "mezo", true)
46
+ expect(url).toBe(`https://explorer.test.mezo.org/address/${evmAddress}`)
47
+ })
44
48
  })
@@ -11,14 +11,16 @@ export function trimAddress(address: string): string {
11
11
  return trimmedAddress
12
12
  }
13
13
 
14
- const MAINNET_EXPLORER_URLS: Record<"bitcoin" | "evm", string> = {
14
+ const MAINNET_EXPLORER_URLS: Record<"bitcoin" | "evm" | "mezo", string> = {
15
15
  bitcoin: "https://mempool.space",
16
16
  evm: "https://etherscan.io",
17
+ mezo: "https://explorer.mezo.org",
17
18
  }
18
19
 
19
- const TESTNET_EXPLORER_URLS: Record<"bitcoin" | "evm", string> = {
20
+ const TESTNET_EXPLORER_URLS: Record<"bitcoin" | "evm" | "mezo", string> = {
20
21
  bitcoin: "https://mempool.space/testnet",
21
22
  evm: "https://sepolia.etherscan.io",
23
+ mezo: "https://explorer.test.mezo.org",
22
24
  }
23
25
 
24
26
  /**
@@ -30,7 +32,7 @@ const TESTNET_EXPLORER_URLS: Record<"bitcoin" | "evm", string> = {
30
32
  */
31
33
  export function getAddressExplorerUrl(
32
34
  address: string,
33
- chainType: "bitcoin" | "evm",
35
+ chainType: "bitcoin" | "evm" | "mezo",
34
36
  isTestnet: boolean,
35
37
  ) {
36
38
  const EXPLORER_URLS = isTestnet
@@ -0,0 +1,57 @@
1
+ import {
2
+ getAsset,
3
+ isBitcoinLikeCryptoAsset,
4
+ isUsdLikeCryptoAsset,
5
+ isTTokenCryptoAsset,
6
+ } from "./assets"
7
+
8
+ describe("getAsset", () => {
9
+ it("should return correct asset data", () => {
10
+ const asset = getAsset("BTC")
11
+ expect(asset).toEqual({
12
+ name: "Bitcoin",
13
+ symbol: "BTC",
14
+ decimals: 18,
15
+ })
16
+ })
17
+ })
18
+
19
+ describe("isBitcoinLikeCryptoAsset", () => {
20
+ it('should return true for keys containing "btc"', () => {
21
+ expect(isBitcoinLikeCryptoAsset("BTC")).toBe(true)
22
+ expect(isBitcoinLikeCryptoAsset("mFBTC")).toBe(true)
23
+ expect(isBitcoinLikeCryptoAsset("mcbBTC")).toBe(true)
24
+ expect(isBitcoinLikeCryptoAsset("mxSolvBTC")).toBe(true)
25
+ })
26
+
27
+ it("should return false for non-Bitcoin assets", () => {
28
+ expect(isBitcoinLikeCryptoAsset("ETH")).toBe(false)
29
+ expect(isBitcoinLikeCryptoAsset("mUSDC")).toBe(false)
30
+ })
31
+ })
32
+
33
+ describe("isUsdLikeCryptoAsset", () => {
34
+ it('should return true for keys containing "usd" or "dai"', () => {
35
+ expect(isUsdLikeCryptoAsset("mUSDC")).toBe(true)
36
+ expect(isUsdLikeCryptoAsset("mUSDT")).toBe(true)
37
+ expect(isUsdLikeCryptoAsset("mUSDe")).toBe(true)
38
+ expect(isUsdLikeCryptoAsset("mDAI")).toBe(true)
39
+ })
40
+
41
+ it("should return false for other tokens", () => {
42
+ expect(isUsdLikeCryptoAsset("BTC")).toBe(false)
43
+ expect(isUsdLikeCryptoAsset("mT")).toBe(false)
44
+ })
45
+ })
46
+
47
+ describe("isTTokenCryptoAsset", () => {
48
+ it('should return true for keys like "mT" or "t"', () => {
49
+ expect(isTTokenCryptoAsset("mT")).toBe(true)
50
+ expect(isTTokenCryptoAsset("T")).toBe(true)
51
+ })
52
+
53
+ it("should return false for other tokens", () => {
54
+ expect(isTTokenCryptoAsset("BTC")).toBe(false)
55
+ expect(isTTokenCryptoAsset("mUSDT")).toBe(false)
56
+ })
57
+ })
@@ -0,0 +1,103 @@
1
+ const ASSETS = {
2
+ BTC: {
3
+ name: "Bitcoin",
4
+ symbol: "BTC",
5
+ decimals: 18,
6
+ },
7
+ ETH: {
8
+ name: "Ethereum",
9
+ symbol: "ETH",
10
+ decimals: 18,
11
+ },
12
+ MUSD: {
13
+ name: "MUSD",
14
+ symbol: "MUSD",
15
+ decimals: 18,
16
+ },
17
+ mDAI: {
18
+ name: "Mezo Dai Stablecoin",
19
+ symbol: "mDAI",
20
+ decimals: 18,
21
+ },
22
+ mFBTC: {
23
+ name: "Mezo Fire Bitcoin",
24
+ symbol: "mFBTC",
25
+ decimals: 8,
26
+ },
27
+ mcbBTC: {
28
+ name: "Mezo Coinbase Wrapped BTC",
29
+ symbol: "mcbBTC",
30
+ decimals: 8,
31
+ },
32
+ mSolvBTC: {
33
+ name: "Mezo SolvBTC",
34
+ symbol: "mSolvBTC",
35
+ decimals: 18,
36
+ },
37
+ mswBTC: {
38
+ name: "Mezo swBTC",
39
+ symbol: "mswBTC",
40
+ decimals: 8,
41
+ },
42
+ mT: {
43
+ name: "Mezo Threshold Network Token",
44
+ symbol: "mT",
45
+ decimals: 18,
46
+ },
47
+ mUSDC: {
48
+ name: "Mezo Circle USDC",
49
+ symbol: "mUSDC",
50
+ decimals: 6,
51
+ },
52
+ mUSDe: {
53
+ name: "Mezo Ethena USDe",
54
+ symbol: "mUSDe",
55
+ decimals: 18,
56
+ },
57
+ mUSDT: {
58
+ name: "Mezo Tether USDe",
59
+ symbol: "mUSDT",
60
+ decimals: 6,
61
+ },
62
+ mxSolvBTC: {
63
+ name: "Mezo xSolvBTC",
64
+ symbol: "mxSolvBTC",
65
+ decimals: 18,
66
+ },
67
+ }
68
+
69
+ /**
70
+ * Gets details of given crypto asset
71
+ * @param key The key of crypto asset
72
+ * @returns The crypto asset details
73
+ */
74
+ export function getAsset(key: keyof typeof ASSETS) {
75
+ return ASSETS[key]
76
+ }
77
+
78
+ /**
79
+ * Checks if given crypto asset is Bitcoin-like
80
+ * @param key The key of crypto asset
81
+ * @returns True if crypto asset is Bitcoin-like
82
+ */
83
+ export function isBitcoinLikeCryptoAsset(key: string) {
84
+ return /(btc)/i.test(key)
85
+ }
86
+
87
+ /**
88
+ * Checks if given crypto asset is USD-like
89
+ * @param key The key of crypto asset
90
+ * @returns True if crypto asset is USD-like
91
+ */
92
+ export function isUsdLikeCryptoAsset(key: string) {
93
+ return /(usd|dai)/i.test(key)
94
+ }
95
+
96
+ /**
97
+ * Checks if given crypto asset is T token
98
+ * @param key The key of crypto asset
99
+ * @returns True if crypto asset is T token
100
+ */
101
+ export function isTTokenCryptoAsset(key: string) {
102
+ return /^(mt|t)$/i.test(key)
103
+ }
@@ -1,4 +1,4 @@
1
- import { formatCurrency, formatUsd } from "./currency"
1
+ import { convertToUsd, formatCurrency, formatUsd } from "./currency"
2
2
 
3
3
  describe("formatCurrency", () => {
4
4
  it("formats a number as currency with default options", () => {
@@ -36,3 +36,79 @@ describe("formatUsd", () => {
36
36
  expect(result).toBe("$0.00")
37
37
  })
38
38
  })
39
+
40
+ describe("convertToUsd", () => {
41
+ it("converts 1 BTC (8 decimals) with $30,000 rate (6 decimals)", () => {
42
+ const assetAmount = 1_00000000n // 1 BTC
43
+ const assetDecimals = 8
44
+ const conversionRate = 30_000_000000n // $30,000 in 6 decimals
45
+ const conversionRateDecimals = 6
46
+
47
+ const result = convertToUsd(
48
+ assetAmount,
49
+ assetDecimals,
50
+ conversionRate,
51
+ conversionRateDecimals,
52
+ )
53
+
54
+ expect(result.value).toBe(30_000_000000n)
55
+ expect(result.formatted).toBe("30000")
56
+ })
57
+
58
+ it("converts 0.5 BTC correctly", () => {
59
+ const assetAmount = 50_000000n // 0.5 BTC
60
+ const assetDecimals = 8
61
+ const conversionRate = 40_000_000000n // $40,000
62
+ const conversionRateDecimals = 6
63
+
64
+ const result = convertToUsd(
65
+ assetAmount,
66
+ assetDecimals,
67
+ conversionRate,
68
+ conversionRateDecimals,
69
+ )
70
+
71
+ expect(result.value).toBe(20_000_000000n)
72
+ expect(result.formatted).toBe("20000")
73
+ })
74
+
75
+ it("converts 1 ETH (18 decimals) with $2,000 rate (6 decimals)", () => {
76
+ const assetAmount = 1_000000000000000000n // 1 ETH
77
+ const assetDecimals = 18
78
+ const conversionRate = 2_000_000000n
79
+ const conversionRateDecimals = 6
80
+
81
+ const result = convertToUsd(
82
+ assetAmount,
83
+ assetDecimals,
84
+ conversionRate,
85
+ conversionRateDecimals,
86
+ )
87
+
88
+ expect(result.value).toBe(2_000_000000n)
89
+ expect(result.formatted).toBe("2000")
90
+ })
91
+
92
+ it("handles zero amount correctly", () => {
93
+ const result = convertToUsd(0n, 18, 999_999999n, 6)
94
+ expect(result.value).toBe(0n)
95
+ expect(result.formatted).toBe("0")
96
+ })
97
+
98
+ it("handles assets with fewer decimals than conversion rate", () => {
99
+ const assetAmount = 100n
100
+ const assetDecimals = 2
101
+ const conversionRate = 1_500_000000n // $1500
102
+ const conversionRateDecimals = 6
103
+
104
+ const result = convertToUsd(
105
+ assetAmount,
106
+ assetDecimals,
107
+ conversionRate,
108
+ conversionRateDecimals,
109
+ )
110
+
111
+ expect(result.value).toBe(1_500_000000n)
112
+ expect(result.formatted).toBe("1500")
113
+ })
114
+ })
@@ -1,8 +1,5 @@
1
- const DEFAULT_FORMAT_OPTIONS: Intl.NumberFormatOptions = {
2
- style: "currency",
3
- minimumFractionDigits: 2,
4
- maximumFractionDigits: 2,
5
- }
1
+ import { formatUnits } from "viem"
2
+ import { normalizePrecision } from "./numbers"
6
3
 
7
4
  /**
8
5
  * Formats a number as a currency
@@ -12,10 +9,12 @@ const DEFAULT_FORMAT_OPTIONS: Intl.NumberFormatOptions = {
12
9
  */
13
10
  export function formatCurrency(
14
11
  value: number,
15
- options: Omit<Intl.NumberFormatOptions, "style"> = {},
12
+ options: Omit<Intl.NumberFormatOptions, "style">,
16
13
  ): string {
17
14
  const formatter = new Intl.NumberFormat("en-US", {
18
- ...DEFAULT_FORMAT_OPTIONS,
15
+ style: "currency",
16
+ minimumFractionDigits: 2,
17
+ maximumFractionDigits: 2,
19
18
  ...options,
20
19
  })
21
20
 
@@ -27,6 +26,33 @@ export function formatCurrency(
27
26
  * @param value The value to format
28
27
  * @returns The formatted currency
29
28
  */
30
- export function formatUsd(value: number): string {
31
- return formatCurrency(value, { currency: "USD" })
29
+ export function formatUsd(value: number | string): string {
30
+ return formatCurrency(Number(value), { currency: "USD" })
31
+ }
32
+
33
+ /**
34
+ * Converts an asset amount to USD based on a conversion rate and decimals
35
+ * @param assetAmount - The amount of the asset in its smallest unit (e.g., satoshis for BTC)
36
+ * @param conversionRate - The conversion rate from the asset to USD in fixed-point format
37
+ * @param decimals - The number of decimals for the asset
38
+ * @returns - The value in USD as a number
39
+ */
40
+ export function convertToUsd(
41
+ assetAmount: bigint,
42
+ assetDecimals: number,
43
+ conversionRate: bigint,
44
+ conversionRateDecimals: number,
45
+ ) {
46
+ const value = normalizePrecision(
47
+ assetAmount * conversionRate,
48
+ assetDecimals + conversionRateDecimals,
49
+ conversionRateDecimals,
50
+ )
51
+
52
+ const formatted = formatUnits(value, conversionRateDecimals)
53
+
54
+ return {
55
+ value,
56
+ formatted,
57
+ }
32
58
  }
@@ -0,0 +1,51 @@
1
+ export type MezoId = `${string}.mezo`
2
+
3
+ // NOTE: This was copied from mezo-portal and is based on the validation from
4
+ // workers/passport-auth/src/utils/mezo-id.ts.
5
+
6
+ // Most of these are restrictions for an DNS hostname label (i.e., the part
7
+ // before/after `.` in a full hostname) as outlined in RFC1034
8
+ // (https://www.rfc-editor.org/rfc/rfc1034).
9
+ //
10
+ // A few addenda are made to ensure that nothing can sneak through that could
11
+ // look like an Ethereum or Bitcoin address.
12
+ export const DISALLOWED_MEZO_ID_PATTERNS: { pattern: RegExp; error: string }[] =
13
+ [
14
+ // RFC1034.
15
+ { pattern: /^$/, error: "Must not be empty." },
16
+ { pattern: /^.{16,}$/, error: "Must have 15 characters or fewer." },
17
+ {
18
+ pattern: /^[^A-Za-z]/,
19
+ error: "Must start with one of the letters A-Z or a-z.",
20
+ },
21
+ {
22
+ pattern: /[^A-Za-z0-9-]/,
23
+ error:
24
+ "Must only use letters or numbers (A-Z, a-z, or 0-9), or hyphen (-).",
25
+ },
26
+ { pattern: /-$/, error: "Must not end in a hyphen (-)." },
27
+ // On-chain shenanigan avoidance.
28
+ { pattern: /0x/i, error: "Must not contain 0x." },
29
+ {
30
+ pattern: /^(?:bc1|tb1|[a-z]pub|[a-z]priv)/i,
31
+ error: "Must not start with a Bitcoin magic string.",
32
+ },
33
+ {
34
+ pattern: /^m[0-9]+$/i,
35
+ error: 'No "m" + "numeric string" prefixes.',
36
+ },
37
+ ]
38
+
39
+ export function validateMezoId(mezoId: string): string[] {
40
+ if (!/\.mezo$/.test(mezoId)) {
41
+ return ["Must end with '.mezo'."]
42
+ }
43
+
44
+ const mezoIdWithoutSuffix = mezoId.replace(/\.mezo$/, "")
45
+
46
+ const errors = DISALLOWED_MEZO_ID_PATTERNS.flatMap(({ pattern, error }) =>
47
+ pattern.test(mezoIdWithoutSuffix) ? [error] : [],
48
+ )
49
+
50
+ return errors
51
+ }
@@ -1,89 +1,96 @@
1
1
  import {
2
- formatHumanReadableNumber,
3
- formatTokenAmount,
4
- fromFixedPoint,
5
- roundUpNumber,
2
+ formatNumberToCompactString,
3
+ bigIntMax,
4
+ normalizePrecision,
6
5
  } from "./numbers"
7
6
 
8
- describe("formatHumanReadableNumber", () => {
7
+ describe("formatNumberToCompactString", () => {
9
8
  it("formats number less than 1000 with decimals", () => {
10
- expect(formatHumanReadableNumber(123.456789, 2)).toBe("123.46")
9
+ expect(formatNumberToCompactString(123.456789, 2)).toBe("123.46")
11
10
  })
12
11
 
13
12
  it("formats thousands with K", () => {
14
- expect(formatHumanReadableNumber(12_345, 2)).toBe("12.35K")
13
+ expect(formatNumberToCompactString(12_345, 2)).toBe("12.35K")
15
14
  })
16
15
 
17
16
  it("formats millions with M", () => {
18
- expect(formatHumanReadableNumber(12_345_678, 2)).toBe("12.35M")
17
+ expect(formatNumberToCompactString(12_345_678, 2)).toBe("12.35M")
19
18
  })
20
19
 
21
20
  it("formats billions with B", () => {
22
- expect(formatHumanReadableNumber(12_345_678_901, 2)).toBe("12.35B")
21
+ expect(formatNumberToCompactString(12_345_678_901, 2)).toBe("12.35B")
23
22
  })
24
23
 
25
24
  it("formats trillions with T", () => {
26
- expect(formatHumanReadableNumber(12_345_678_901_234, 2)).toBe("12.35T")
25
+ expect(formatNumberToCompactString(12_345_678_901_234, 2)).toBe("12.35T")
27
26
  })
28
27
 
29
28
  it("formats bigint as readable number", () => {
30
- expect(formatHumanReadableNumber(1234567890123456789n, 2)).toBe("> 1000T")
29
+ expect(formatNumberToCompactString(1234567890123456789n, 2)).toBe(
30
+ "1,234,567.89T",
31
+ )
31
32
  })
32
33
 
33
34
  it("caps at > 1000T for huge numbers", () => {
34
35
  const hugeNumber = 10 ** 18 // 1e18
35
- expect(formatHumanReadableNumber(hugeNumber, 2)).toBe("> 1000T")
36
+ expect(formatNumberToCompactString(hugeNumber, 2)).toBe("1,000,000T")
37
+ })
38
+
39
+ it("formats numbers with trailing zeros correctly", () => {
40
+ expect(formatNumberToCompactString(1_000, 2)).toBe("1K")
36
41
  })
37
42
  })
38
43
 
39
- describe("roundUpNumber", () => {
40
- it("rounds up to 2 decimals", () => {
41
- expect(roundUpNumber(1.234)).toBe(1.24)
44
+ describe("bigIntMax", () => {
45
+ it("returns the maximum of positive bigint values", () => {
46
+ expect(bigIntMax(1n, 2n, 3n)).toBe(3n)
42
47
  })
43
48
 
44
- it("rounds up to 3 decimals", () => {
45
- expect(roundUpNumber(9.87654, 3)).toBe(9.877)
49
+ it("returns the maximum of negative bigint values", () => {
50
+ expect(bigIntMax(-10n, -5n, -20n)).toBe(-5n)
46
51
  })
47
52
 
48
- it("rounds up exact decimal", () => {
49
- expect(roundUpNumber(2.5, 1)).toBe(2.5)
53
+ it("returns the only element if array has one bigint", () => {
54
+ expect(bigIntMax(42n)).toBe(42n)
50
55
  })
51
- })
52
56
 
53
- describe("fromFixedPoint", () => {
54
- it("converts fixed point with 18 decimals to float", () => {
55
- const raw = 1234567890000000000n // 1.23456789 ETH in 18 decimals
56
- expect(fromFixedPoint(raw, 18, 4)).toBe(1.2345)
57
+ it("works with a mix of positive and negative bigints", () => {
58
+ expect(bigIntMax(-100n, 0n, 50n, -10n)).toBe(50n)
57
59
  })
58
60
 
59
- it("converts with truncation to 2 decimals", () => {
60
- const raw = 987654321000000000n // ~0.987654321 ETH
61
- expect(fromFixedPoint(raw, 18, 2)).toBe(0.98)
61
+ it("throws an error if called with no arguments", () => {
62
+ expect(() => bigIntMax()).toThrow()
62
63
  })
63
64
 
64
- it("handles large fixedPoint decimals", () => {
65
- const raw = 1_000_000_000_000_000_000_000_000n // 1M with 6 decimals
66
- expect(fromFixedPoint(raw, 6, 2)).toBe(1000000000000000000)
65
+ it("returns the correct value when all values are equal", () => {
66
+ expect(bigIntMax(5n, 5n, 5n)).toBe(5n)
67
67
  })
68
68
  })
69
69
 
70
- describe("formatTokenAmount", () => {
71
- it("formats zero value with desired decimals", () => {
72
- expect(formatTokenAmount(0, 18, 3)).toBe("0.000")
73
- expect(formatTokenAmount("0", 18, 2)).toBe("0.00")
70
+ describe("normalizePrecision", () => {
71
+ it("reduces precision correctly (scale down)", () => {
72
+ const result = normalizePrecision(1234500n, 6, 3)
73
+ expect(result).toBe(1234n)
74
+ })
75
+
76
+ it("increases precision correctly (scale up)", () => {
77
+ const result = normalizePrecision(1234n, 3, 6)
78
+ expect(result).toBe(1234000n)
74
79
  })
75
80
 
76
- it("returns <0.01 if amount is less than minimum display value", () => {
77
- expect(formatTokenAmount("1", 18, 2)).toBe("<0.01") // 1 wei = 1e-18
81
+ it("returns the same value when precision is equal", () => {
82
+ const result = normalizePrecision(987654321n, 5, 5)
83
+ expect(result).toBe(987654321n)
78
84
  })
79
85
 
80
- it("formats a normal value without rounding", () => {
81
- const result = formatTokenAmount("1230000000000000000", 18, 2)
82
- expect(result).toBe("1.23")
86
+ it("handles zero value correctly", () => {
87
+ const result = normalizePrecision(0n, 4, 8)
88
+ expect(result).toBe(0n)
83
89
  })
84
90
 
85
- it("formats with rounding if withRoundUp = true", () => {
86
- const result = formatTokenAmount("1234560000000000000", 18, 2, true)
87
- expect(result).toBe("1.24")
91
+ it("handles large numbers without precision loss", () => {
92
+ const value = 123456789012345678901234567890n
93
+ const result = normalizePrecision(value, 18, 20)
94
+ expect(result).toBe(value * 100n)
88
95
  })
89
96
  })