@mezo-org/passport 0.4.0-dev.9 → 0.5.1-dev.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 (305) 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 +35 -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/number2.d.ts +106 -0
  188. package/dist/src/utils/number2.d.ts.map +1 -0
  189. package/dist/src/utils/number2.js +289 -0
  190. package/dist/src/utils/number2.js.map +1 -0
  191. package/dist/src/utils/numbers.d.ts +15 -33
  192. package/dist/src/utils/numbers.d.ts.map +1 -1
  193. package/dist/src/utils/numbers.js +26 -70
  194. package/dist/src/utils/numbers.js.map +1 -1
  195. package/dist/src/utils/numbers.test.js +46 -42
  196. package/dist/src/utils/numbers.test.js.map +1 -1
  197. package/dist/src/utils/siww.d.ts +1 -0
  198. package/dist/src/utils/siww.d.ts.map +1 -1
  199. package/dist/src/utils/siww.js +50 -12
  200. package/dist/src/utils/siww.js.map +1 -1
  201. package/dist/src/utils/wagmi.d.ts +3 -0
  202. package/dist/src/utils/wagmi.d.ts.map +1 -0
  203. package/dist/src/utils/wagmi.js +7 -0
  204. package/dist/src/utils/wagmi.js.map +1 -0
  205. package/dist/src/wallet/index.d.ts +1 -1
  206. package/dist/src/wallet/index.d.ts.map +1 -1
  207. package/dist/src/wallet/index.js +1 -1
  208. package/dist/src/wallet/index.js.map +1 -1
  209. package/package.json +11 -8
  210. package/src/api/auth.ts +8 -4
  211. package/src/api/client.ts +11 -2
  212. package/src/api/portal.ts +11 -14
  213. package/src/components/Dropdown/ConnectedTrigger.tsx +52 -32
  214. package/src/components/Dropdown/Content.tsx +26 -121
  215. package/src/components/Dropdown/DisconnectedTrigger.tsx +2 -1
  216. package/src/components/Dropdown/Dropdown.tsx +29 -17
  217. package/src/components/Dropdown/ListingItem.tsx +176 -0
  218. package/src/components/Dropdown/NestedViewLayout.tsx +87 -0
  219. package/src/components/Dropdown/README.md +10 -18
  220. package/src/components/Dropdown/Receive/Receive.tsx +144 -0
  221. package/src/components/Dropdown/Root/AccountAddressActions.tsx +99 -0
  222. package/src/components/Dropdown/Root/AccountBalance.tsx +75 -0
  223. package/src/components/Dropdown/Root/AccountBtcListing.tsx +52 -0
  224. package/src/components/Dropdown/Root/AccountError.tsx +34 -0
  225. package/src/components/Dropdown/Root/AccountMusdListing.tsx +45 -0
  226. package/src/components/Dropdown/Root/AccountOtherAssets.tsx +85 -0
  227. package/src/components/Dropdown/Root/Root.tsx +77 -0
  228. package/src/components/Dropdown/Root/WalletAddress.tsx +123 -0
  229. package/src/components/Dropdown/Root/WelcomeBlock.tsx +173 -0
  230. package/src/components/Dropdown/SlotNumber.tsx +131 -0
  231. package/src/components/Dropdown/TestnetTopBanner.tsx +32 -0
  232. package/src/config.ts +88 -20
  233. package/src/constants.ts +12 -4
  234. package/src/hooks/index.ts +7 -0
  235. package/src/hooks/useAssetsConversionRates.ts +79 -0
  236. package/src/hooks/useAuthenticateWithWallet.ts +30 -14
  237. package/src/hooks/useBorrowData.ts +246 -0
  238. package/src/hooks/useCreateAccount.ts +29 -2
  239. package/src/hooks/useGetCurrentAccount.ts +5 -7
  240. package/src/hooks/useLinkAccount.ts +37 -4
  241. package/src/hooks/useRefreshPassport.ts +56 -0
  242. package/src/hooks/useSignInWithWallet.ts +2 -2
  243. package/src/hooks/useSignUpWithWallet.ts +2 -2
  244. package/src/hooks/useTokensBalances.ts +265 -0
  245. package/src/hooks/useValidateMezoId.ts +31 -0
  246. package/src/hooks/useWalletAccount.ts +32 -20
  247. package/src/hooks/useWatchTransferEvents.ts +74 -0
  248. package/src/index.ts +12 -1
  249. package/src/lib/contracts/index.ts +99 -0
  250. package/src/lib/contracts/priceOracle.ts +53 -0
  251. package/src/provider.ts +11 -3
  252. package/src/stores/dropdownStore.ts +20 -0
  253. package/src/utils/address.test.ts +10 -6
  254. package/src/utils/address.ts +5 -3
  255. package/src/utils/assets.test.ts +57 -0
  256. package/src/utils/assets.ts +103 -0
  257. package/src/utils/currency.test.ts +77 -1
  258. package/src/utils/currency.ts +35 -9
  259. package/src/utils/mezoId.ts +51 -0
  260. package/src/utils/number2.ts +419 -0
  261. package/src/utils/numbers.test.ts +49 -42
  262. package/src/utils/numbers.ts +33 -95
  263. package/src/utils/siww.ts +71 -16
  264. package/src/utils/wagmi.ts +12 -0
  265. package/src/wallet/index.ts +3 -2
  266. package/dist/src/components/Dropdown/AccountAddress.d.ts +0 -8
  267. package/dist/src/components/Dropdown/AccountAddress.d.ts.map +0 -1
  268. package/dist/src/components/Dropdown/AccountAddress.js +0 -58
  269. package/dist/src/components/Dropdown/AccountAddress.js.map +0 -1
  270. package/dist/src/components/Dropdown/AccountAssets.d.ts +0 -14
  271. package/dist/src/components/Dropdown/AccountAssets.d.ts.map +0 -1
  272. package/dist/src/components/Dropdown/AccountAssets.js +0 -44
  273. package/dist/src/components/Dropdown/AccountAssets.js.map +0 -1
  274. package/dist/src/components/Dropdown/AccountBalance.d.ts +0 -7
  275. package/dist/src/components/Dropdown/AccountBalance.d.ts.map +0 -1
  276. package/dist/src/components/Dropdown/AccountBalance.js +0 -18
  277. package/dist/src/components/Dropdown/AccountBalance.js.map +0 -1
  278. package/dist/src/components/Dropdown/WelcomeBlock.d.ts +0 -8
  279. package/dist/src/components/Dropdown/WelcomeBlock.d.ts.map +0 -1
  280. package/dist/src/components/Dropdown/WelcomeBlock.js +0 -44
  281. package/dist/src/components/Dropdown/WelcomeBlock.js.map +0 -1
  282. package/dist/src/hooks/useAssetsUSDConversion.d.ts +0 -8
  283. package/dist/src/hooks/useAssetsUSDConversion.d.ts.map +0 -1
  284. package/dist/src/hooks/useAssetsUSDConversion.js +0 -21
  285. package/dist/src/hooks/useAssetsUSDConversion.js.map +0 -1
  286. package/dist/src/hooks/useDropdownData.d.ts +0 -44
  287. package/dist/src/hooks/useDropdownData.d.ts.map +0 -1
  288. package/dist/src/hooks/useDropdownData.js +0 -73
  289. package/dist/src/hooks/useDropdownData.js.map +0 -1
  290. package/dist/src/utils/cryptoAssets.d.ts +0 -28
  291. package/dist/src/utils/cryptoAssets.d.ts.map +0 -1
  292. package/dist/src/utils/cryptoAssets.js +0 -73
  293. package/dist/src/utils/cryptoAssets.js.map +0 -1
  294. package/dist/src/utils/cryptoAssets.test.d.ts +0 -2
  295. package/dist/src/utils/cryptoAssets.test.d.ts.map +0 -1
  296. package/dist/src/utils/cryptoAssets.test.js +0 -49
  297. package/dist/src/utils/cryptoAssets.test.js.map +0 -1
  298. package/src/components/Dropdown/AccountAddress.tsx +0 -111
  299. package/src/components/Dropdown/AccountAssets.tsx +0 -110
  300. package/src/components/Dropdown/AccountBalance.tsx +0 -38
  301. package/src/components/Dropdown/WelcomeBlock.tsx +0 -92
  302. package/src/hooks/useAssetsUSDConversion.ts +0 -31
  303. package/src/hooks/useDropdownData.ts +0 -130
  304. package/src/utils/cryptoAssets.test.ts +0 -59
  305. 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
+ }