@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
@@ -1,81 +1,37 @@
1
1
  /**
2
- * Formats a number or bigint into a human-readable string with K, M, B, or T suffix.
2
+ * Formats a number or bigint into compact string with K, M, B, or T suffix.
3
3
  * @param value The number or bigint to format.
4
4
  * @param decimals Number of decimal places to include (ignored for bigint to avoid floating point issues).
5
5
  * @returns The formatted number as a string.
6
6
  */
7
- export function formatHumanReadableNumber(value, decimals = 4) {
8
- const suffixes = ["", "K", "M", "B", "T"];
9
- const numericValue = typeof value === "bigint" ? Number(value) : value;
10
- if (numericValue < 1000)
11
- return numericValue.toFixed(decimals);
12
- const magnitude = Math.floor(Math.log10(numericValue) / 3);
13
- if (magnitude >= suffixes.length) {
14
- const max = 10 ** ((suffixes.length - 1) * 3) * 1000 - 1;
15
- const capped = max / 10 ** ((suffixes.length - 1) * 3);
16
- return `> ${capped.toFixed(0)}${suffixes[suffixes.length - 1]}`;
17
- }
18
- const scaledValue = numericValue / 10 ** (magnitude * 3);
19
- return `${scaledValue.toFixed(decimals)}${suffixes[magnitude]}`;
20
- }
21
- /**
22
- * Returns a number rounded up to the desired number of decimals.
23
- * @param amount The number to round up.
24
- * @param desiredDecimals The number of decimals to round up to.
25
- * @returns The rounded up number.
26
- * @see https://github.com/thesis/acre/blob/main/dapp/src/utils/numbersUtils.ts#L1-L3
27
- */
28
- export function roundUpNumber(amount, desiredDecimals = 2) {
29
- return Math.ceil(amount * 10 ** desiredDecimals) / 10 ** desiredDecimals;
30
- }
31
- /**
32
- * Convert a fixed point bigint with precision `fixedPointDecimals` to a
33
- * floating point number truncated to `desiredDecimals`.
34
- * @param fixedPoint The fixed point bigint to convert.
35
- * @param fixedPointDecimals The number of decimals in the fixed point bigint.
36
- * @param desiredDecimals The number of decimals in the output number.
37
- * @returns The floating point number truncated to `desiredDecimals`.
38
- * @see https://github.com/tahowallet/extension/blob/main/background/lib/fixed-point.ts#L216-L239
39
- */
40
- export function fromFixedPoint(fixedPoint, fixedPointDecimals, desiredDecimals = 2) {
41
- const fixedPointDesiredDecimalsAmount = fixedPoint /
42
- 10n ** BigInt(Math.max(1, fixedPointDecimals - desiredDecimals));
43
- const formattedAmount = Number(fixedPointDesiredDecimalsAmount) /
44
- 10 ** Math.min(desiredDecimals, fixedPointDecimals);
45
- return formattedAmount;
7
+ export function formatNumberToCompactString(value, decimals = 2) {
8
+ return value.toLocaleString("en-US", {
9
+ notation: "compact",
10
+ compactDisplay: "short",
11
+ maximumFractionDigits: decimals,
12
+ });
46
13
  }
47
14
  /**
48
- * Display a cryptoAsset amount correctly with desired decimals.
49
- * The function returns a string with a language-sensitive representation of this number.
50
- * - If the amount entered is zero, return the result with the desired decimals.
51
- * For example, 0.00 for a precision of 2.
52
- * - If `formattedAmount` is less than the minimum amount to display
53
- * for the specified precision return information about this.
54
- * For example, <0.01 for a precision of 2.
55
- * - Other amounts are formatted according to the use of the `bigIntToUserAmount` function.
56
- * @param amount The amount of tokens to format.
57
- * @param decimals The number of decimals the cryptoAsset has.
58
- * @param desiredDecimals The number of decimals to display.
59
- * @param withRoundUp If true, the amount will be rounded up.
60
- * @returns The formatted cryptoAsset amount.
61
- * @see https://github.com/thesis/acre/blob/main/dapp/src/utils/numbersUtils.ts#L57-L87
15
+ * Normalizes a bigint value to a target precision.
16
+ * @param value The bigint value to normalize.
17
+ * @param currentPrecision The current precision of the value.
18
+ * @param targetPrecision The target precision to normalize to.
19
+ * @returns The normalized bigint value.
62
20
  */
63
- export function formatTokenAmount(amount, decimals = 18, desiredDecimals = 2, withRoundUp = false) {
64
- const fixedPoint = BigInt(amount);
65
- if (fixedPoint === 0n) {
66
- return `0.${"0".repeat(desiredDecimals)}`;
21
+ export const normalizePrecision = (value, currentPrecision, targetPrecision = currentPrecision) => {
22
+ if (currentPrecision > targetPrecision) {
23
+ return value / 10n ** BigInt(currentPrecision - targetPrecision);
67
24
  }
68
- const formattedAmount = fromFixedPoint(fixedPoint, decimals,
69
- // To round the amount up, let's increase the precision by one.
70
- // The desired decimal numbers will be set later anyway.
71
- withRoundUp ? desiredDecimals + 1 : desiredDecimals);
72
- const minAmountToDisplay = 1 / 10 ** Math.min(desiredDecimals, decimals);
73
- if (minAmountToDisplay > formattedAmount) {
74
- return `<0.${"0".repeat(desiredDecimals - 1)}1`;
25
+ if (currentPrecision < targetPrecision) {
26
+ return value * 10n ** BigInt(targetPrecision - currentPrecision);
75
27
  }
76
- const finalFormattedAmount = withRoundUp
77
- ? roundUpNumber(formattedAmount, desiredDecimals)
78
- : formattedAmount;
79
- return formatHumanReadableNumber(finalFormattedAmount, desiredDecimals);
80
- }
28
+ return value;
29
+ };
30
+ /**
31
+ * Utility function to find the maximum value from given `BigInt` values.
32
+ * @param values Array of BigInt values to find the maximum from.
33
+ * @returns The maximum value from the provided `BigInt` values.
34
+ * @dev Works exactly like `Math.max` but for `BigInt` values.
35
+ */
36
+ export const bigIntMax = (...values) => values.reduce((max, value) => (value > max ? value : max));
81
37
  //# sourceMappingURL=numbers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"numbers.js","sourceRoot":"","sources":["../../../src/utils/numbers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CACvC,KAAsB,EACtB,WAAmB,CAAC;IAEpB,MAAM,QAAQ,GAAG,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;IACzC,MAAM,YAAY,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;IAEtE,IAAI,YAAY,GAAG,IAAI;QAAE,OAAO,YAAY,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;IAE9D,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAA;IAE1D,IAAI,SAAS,IAAI,QAAQ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G,CAChC,KAAa,EACb,gBAAwB,EACxB,eAAe,GAAG,gBAAgB,EAC1B,EAAE;IACV,IAAI,gBAAgB,GAAG,eAAe,EAAE,CAAC;QACvC,OAAO,KAAK,GAAG,GAAG,IAAI,MAAM,CAAC,gBAAgB,GAAG,eAAe,CAAC,CAAA;IAClE,CAAC;IACD,IAAI,gBAAgB,GAAG,eAAe,EAAE,CAAC;QACvC,OAAO,KAAK,GAAG,GAAG,IAAI,MAAM,CAAC,eAAe,GAAG,gBAAgB,CAAC,CAAA;IAClE,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,GAAG,MAAgB,EAAU,EAAE,CACvD,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA"}
@@ -1,68 +1,72 @@
1
- import { formatHumanReadableNumber, formatTokenAmount, fromFixedPoint, roundUpNumber, } from "./numbers";
2
- describe("formatHumanReadableNumber", () => {
1
+ import { formatNumberToCompactString, bigIntMax, normalizePrecision, } from "./numbers";
2
+ describe("formatNumberToCompactString", () => {
3
3
  it("formats number less than 1000 with decimals", () => {
4
- expect(formatHumanReadableNumber(123.456789, 2)).toBe("123.46");
4
+ expect(formatNumberToCompactString(123.456789, 2)).toBe("123.46");
5
5
  });
6
6
  it("formats thousands with K", () => {
7
- expect(formatHumanReadableNumber(12_345, 2)).toBe("12.35K");
7
+ expect(formatNumberToCompactString(12_345, 2)).toBe("12.35K");
8
8
  });
9
9
  it("formats millions with M", () => {
10
- expect(formatHumanReadableNumber(12_345_678, 2)).toBe("12.35M");
10
+ expect(formatNumberToCompactString(12_345_678, 2)).toBe("12.35M");
11
11
  });
12
12
  it("formats billions with B", () => {
13
- expect(formatHumanReadableNumber(12_345_678_901, 2)).toBe("12.35B");
13
+ expect(formatNumberToCompactString(12_345_678_901, 2)).toBe("12.35B");
14
14
  });
15
15
  it("formats trillions with T", () => {
16
- expect(formatHumanReadableNumber(12_345_678_901_234, 2)).toBe("12.35T");
16
+ expect(formatNumberToCompactString(12_345_678_901_234, 2)).toBe("12.35T");
17
17
  });
18
18
  it("formats bigint as readable number", () => {
19
- expect(formatHumanReadableNumber(1234567890123456789n, 2)).toBe("> 1000T");
19
+ expect(formatNumberToCompactString(1234567890123456789n, 2)).toBe("1,234,567.89T");
20
20
  });
21
21
  it("caps at > 1000T for huge numbers", () => {
22
22
  const hugeNumber = 10 ** 18; // 1e18
23
- expect(formatHumanReadableNumber(hugeNumber, 2)).toBe("> 1000T");
23
+ expect(formatNumberToCompactString(hugeNumber, 2)).toBe("1,000,000T");
24
24
  });
25
- });
26
- describe("roundUpNumber", () => {
27
- it("rounds up to 2 decimals", () => {
28
- expect(roundUpNumber(1.234)).toBe(1.24);
29
- });
30
- it("rounds up to 3 decimals", () => {
31
- expect(roundUpNumber(9.87654, 3)).toBe(9.877);
32
- });
33
- it("rounds up exact decimal", () => {
34
- expect(roundUpNumber(2.5, 1)).toBe(2.5);
25
+ it("formats numbers with trailing zeros correctly", () => {
26
+ expect(formatNumberToCompactString(1_000, 2)).toBe("1K");
35
27
  });
36
28
  });
37
- describe("fromFixedPoint", () => {
38
- it("converts fixed point with 18 decimals to float", () => {
39
- const raw = 1234567890000000000n; // 1.23456789 ETH in 18 decimals
40
- expect(fromFixedPoint(raw, 18, 4)).toBe(1.2345);
29
+ describe("bigIntMax", () => {
30
+ it("returns the maximum of positive bigint values", () => {
31
+ expect(bigIntMax(1n, 2n, 3n)).toBe(3n);
41
32
  });
42
- it("converts with truncation to 2 decimals", () => {
43
- const raw = 987654321000000000n; // ~0.987654321 ETH
44
- expect(fromFixedPoint(raw, 18, 2)).toBe(0.98);
33
+ it("returns the maximum of negative bigint values", () => {
34
+ expect(bigIntMax(-10n, -5n, -20n)).toBe(-5n);
45
35
  });
46
- it("handles large fixedPoint decimals", () => {
47
- const raw = 1000000000000000000000000n; // 1M with 6 decimals
48
- expect(fromFixedPoint(raw, 6, 2)).toBe(1000000000000000000);
36
+ it("returns the only element if array has one bigint", () => {
37
+ expect(bigIntMax(42n)).toBe(42n);
49
38
  });
50
- });
51
- describe("formatTokenAmount", () => {
52
- it("formats zero value with desired decimals", () => {
53
- expect(formatTokenAmount(0, 18, 3)).toBe("0.000");
54
- expect(formatTokenAmount("0", 18, 2)).toBe("0.00");
39
+ it("works with a mix of positive and negative bigints", () => {
40
+ expect(bigIntMax(-100n, 0n, 50n, -10n)).toBe(50n);
55
41
  });
56
- it("returns <0.01 if amount is less than minimum display value", () => {
57
- expect(formatTokenAmount("1", 18, 2)).toBe("<0.01"); // 1 wei = 1e-18
42
+ it("throws an error if called with no arguments", () => {
43
+ expect(() => bigIntMax()).toThrow();
58
44
  });
59
- it("formats a normal value without rounding", () => {
60
- const result = formatTokenAmount("1230000000000000000", 18, 2);
61
- expect(result).toBe("1.23");
45
+ it("returns the correct value when all values are equal", () => {
46
+ expect(bigIntMax(5n, 5n, 5n)).toBe(5n);
62
47
  });
63
- it("formats with rounding if withRoundUp = true", () => {
64
- const result = formatTokenAmount("1234560000000000000", 18, 2, true);
65
- expect(result).toBe("1.24");
48
+ });
49
+ describe("normalizePrecision", () => {
50
+ it("reduces precision correctly (scale down)", () => {
51
+ const result = normalizePrecision(1234500n, 6, 3);
52
+ expect(result).toBe(1234n);
53
+ });
54
+ it("increases precision correctly (scale up)", () => {
55
+ const result = normalizePrecision(1234n, 3, 6);
56
+ expect(result).toBe(1234000n);
57
+ });
58
+ it("returns the same value when precision is equal", () => {
59
+ const result = normalizePrecision(987654321n, 5, 5);
60
+ expect(result).toBe(987654321n);
61
+ });
62
+ it("handles zero value correctly", () => {
63
+ const result = normalizePrecision(0n, 4, 8);
64
+ expect(result).toBe(0n);
65
+ });
66
+ it("handles large numbers without precision loss", () => {
67
+ const value = 123456789012345678901234567890n;
68
+ const result = normalizePrecision(value, 18, 20);
69
+ expect(result).toBe(value * 100n);
66
70
  });
67
71
  });
68
72
  //# sourceMappingURL=numbers.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"numbers.test.js","sourceRoot":"","sources":["../../../src/utils/numbers.test.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,iBAAiB,EACjB,cAAc,EACd,aAAa,GACd,MAAM,WAAW,CAAA;AAElB,QAAQ,CAAC,2BAA2B,EAAE,GAAG,EAAE;IACzC,EAAE,CAAC,6CAA6C,EAAE,GAAG,EAAE;QACrD,MAAM,CAAC,yBAAyB,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IACjE,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,0BAA0B,EAAE,GAAG,EAAE;QAClC,MAAM,CAAC,yBAAyB,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAC7D,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,yBAAyB,EAAE,GAAG,EAAE;QACjC,MAAM,CAAC,yBAAyB,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IACjE,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,yBAAyB,EAAE,GAAG,EAAE;QACjC,MAAM,CAAC,yBAAyB,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IACrE,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,0BAA0B,EAAE,GAAG,EAAE;QAClC,MAAM,CAAC,yBAAyB,CAAC,kBAAkB,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IACzE,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,mCAAmC,EAAE,GAAG,EAAE;QAC3C,MAAM,C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,EAAE,CAAC,8BAA8B,EAAE,GAAG,EAAE;QACtC,MAAM,MAAM,GAAG,kBAAkB,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;QAC3C,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IACzB,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,8CAA8C,EAAE,GAAG,EAAE;QACtD,MAAM,KAAK,GAAG,+BAA+B,CAAA;QAC7C,MAAM,MAAM,GAAG,kBAAkB,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,CAAA;QAChD,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,CAAA;IACnC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -1,4 +1,5 @@
1
1
  type NetworkFamily = "evm" | "bitcoin";
2
2
  export declare function createSignInWithWalletMessage(address: string, nonce: string, networkFamily: NetworkFamily, chainId?: number): string;
3
+ export declare function verifyDomainInSignInWithWalletMessage(message: string, signature: string, nonce: string): Promise<void>;
3
4
  export {};
4
5
  //# sourceMappingURL=siww.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"siww.d.ts","sourceRoot":"","sources":["../../../src/utils/siww.ts"],"names":[],"mappings":"AAKA,KAAK,aAAa,GAAG,KAAK,GAAG,SAAS,CAAA;AAEtC,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,aAAa,EAAE,aAAa,EAC5B,OAAO,CAAC,EAAE,MAAM,UAmBjB"}
1
+ {"version":3,"file":"siww.d.ts","sourceRoot":"","sources":["../../../src/utils/siww.ts"],"names":[],"mappings":"AAQA,KAAK,aAAa,GAAG,KAAK,GAAG,SAAS,CAAA;AAEtC,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,aAAa,EAAE,aAAa,EAC5B,OAAO,CAAC,EAAE,MAAM,UAwBjB;AASD,wBAAsB,qCAAqC,CACzD,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,iBAmCd"}
@@ -1,19 +1,57 @@
1
- import { SignInWithWalletMessage } from "@mezo-org/sign-in-with-wallet";
1
+ import { SignInWithWalletErrorType, SignInWithWalletMessage, } from "@mezo-org/sign-in-with-wallet";
2
2
  import { ONE_DAY_MS } from "./time";
3
3
  const SESSION_EXPIRATION_DURATION_MS = 14 * ONE_DAY_MS;
4
4
  export function createSignInWithWalletMessage(address, nonce, networkFamily, chainId) {
5
5
  const { host: domain, origin: uri } = window.location;
6
- const message = new SignInWithWalletMessage({
7
- domain,
8
- address, // if "bitcoin" this should be btc address, not underlaying eth address
9
- uri,
6
+ let siwwMessage;
7
+ try {
8
+ siwwMessage = new SignInWithWalletMessage({
9
+ domain,
10
+ address, // if "bitcoin" this should be btc address, not underlaying eth address
11
+ uri,
12
+ nonce,
13
+ issuedAt: new Date().toISOString(),
14
+ expirationTime: new Date(Date.now() + SESSION_EXPIRATION_DURATION_MS).toISOString(),
15
+ version: "1",
16
+ chainId: networkFamily === "evm" ? chainId : undefined,
17
+ networkFamily,
18
+ });
19
+ }
20
+ catch (error) {
21
+ throw new Error(`Failed to create sign in with wallet message: ${error}`);
22
+ }
23
+ return siwwMessage.prepareMessage();
24
+ }
25
+ class SIWWDomainError extends Error {
26
+ constructor(message) {
27
+ super(`Error when verifying domain in SIWW message: ${message}`);
28
+ this.name = "SIWWDomainError";
29
+ }
30
+ }
31
+ export async function verifyDomainInSignInWithWalletMessage(message, signature, nonce) {
32
+ const { host: domain } = window.location;
33
+ let siwwMessage;
34
+ try {
35
+ siwwMessage = new SignInWithWalletMessage(message);
36
+ }
37
+ catch (error) {
38
+ throw new SIWWDomainError("Failed to parse SIWW message");
39
+ }
40
+ if (!siwwMessage.expirationTime) {
41
+ throw new SIWWDomainError("SIWW messages must have an expiration time set");
42
+ }
43
+ const result = await siwwMessage.verify({
44
+ signature,
45
+ // Nonce has to match the session ID carried in the request.
10
46
  nonce,
11
- issuedAt: new Date().toISOString(),
12
- expirationTime: new Date(Date.now() + SESSION_EXPIRATION_DURATION_MS).toISOString(),
13
- version: "1",
14
- chainId: networkFamily === "evm" ? chainId : undefined,
15
- networkFamily,
16
- });
17
- return message.prepareMessage();
47
+ domain,
48
+ // Time is used as a reference to verify the expiration time set in the
49
+ // message.
50
+ time: new Date().toISOString(),
51
+ }, { suppressExceptions: true });
52
+ if (result.error &&
53
+ result.error.type === SignInWithWalletErrorType.DOMAIN_MISMATCH) {
54
+ throw new SIWWDomainError("Domain does not match provided domain for verification.");
55
+ }
18
56
  }
19
57
  //# sourceMappingURL=siww.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"siww.js","sourceRoot":"","sources":["../../../src/utils/siww.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAA;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAEnC,MAAM,8BAA8B,GAAG,EAAE,GAAG,UAAU,CAAA;AAItD,MAAM,UAAU,6BAA6B,CAC3C,OAAe,EACf,KAAa,EACb,aAA4B,EAC5B,OAAgB;IAEhB,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAA;IAErD,MAAM,OAAO,GAAG,IAAI,uBAAuB,CAAC;QAC1C,MAAM;QACN,OAAO,EAAE,uEAAuE;QAChF,GAAG;QACH,KAAK;QACL,QAAQ,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QAClC,cAAc,EAAE,IAAI,IAAI,CACtB,IAAI,CAAC,GAAG,EAAE,GAAG,8BAA8B,CAC5C,CAAC,WAAW,EAAE;QACf,OAAO,EAAE,GAAG;QACZ,OAAO,EAAE,aAAa,KAAK,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,S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BAAiB,CAAA;IAC/B,CAAC;CACF;AAED,MAAM,CAAC,KAAK,UAAU,qCAAqC,CACzD,OAAe,EACf,SAAiB,EACjB,KAAa;IAEb,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAA;IACxC,IAAI,WAAoC,CAAA;IACxC,IAAI,CAAC;QACH,WAAW,GAAG,IAAI,uBAAuB,CAAC,OAAO,CAAC,CAAA;IACpD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,eAAe,CAAC,8BAA8B,CAAC,CAAA;IAC3D,CAAC;IAED,IAAI,CAAC,WAAW,CAAC,cAAc,EAAE,CAAC;QAChC,MAAM,IAAI,eAAe,CAAC,gDAAgD,CAAC,CAAA;IAC7E,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,MAAM,CACrC;QACE,SAAS;QACT,4DAA4D;QAC5D,KAAK;QACL,MAAM;QACN,uEAAuE;QACvE,WAAW;QACX,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KAC/B,EACD,EAAE,kBAAkB,EAAE,IAAI,EAAE,CAC7B,CAAA;IAED,IACE,MAAM,CAAC,KAAK;QACZ,MAAM,CAAC,KAAK,CAAC,IAAI,KAAK,yBAAyB,CAAC,eAAe,EAC/D,CAAC;QACD,MAAM,IAAI,eAAe,CACvB,yDAAyD,CAC1D,CAAA;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { Connector } from "wagmi";
2
+ export declare function getBitcoinPublicKeyFromConnector(connector: Connector): Promise<string | undefined>;
3
+ //# sourceMappingURL=wagmi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wagmi.d.ts","sourceRoot":"","sources":["../../../src/utils/wagmi.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEjC,wBAAsB,gCAAgC,CAAC,SAAS,EAAE,SAAS,+BAQ1E"}
@@ -0,0 +1,7 @@
1
+ export async function getBitcoinPublicKeyFromConnector(connector) {
2
+ if (connector.type !== "orangekit")
3
+ return undefined;
4
+ const provider = connector.getBitcoinProvider();
5
+ return provider.getPublicKey();
6
+ }
7
+ //# sourceMappingURL=wagmi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wagmi.js","sourceRoot":"","sources":["../../../src/utils/wagmi.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,KAAK,UAAU,gCAAgC,CAAC,SAAoB;IACzE,IAAI,SAAS,CAAC,IAAI,KAAK,WAAW;QAAE,OAAO,SAAS,CAAA;IAEpD,MAAM,QAAQ,GACZ,SACD,CAAC,kBAAkB,EAAE,CAAA;IAEtB,OAAO,QAAQ,CAAC,YAAY,EAAE,CAAA;AAChC,CAAC"}
@@ -1,2 +1,2 @@
1
- export { getOKXWallet, getUnisatWallet, getXverseWallet, BitcoinWalletConnectionError, WalletNetworkDoesNotMatchProviderChainError, isUnsupportedBitcoinAddressError, isWalletNetworkDoesNotMatchProviderChainError, } from "@mezo-org/orangekit";
1
+ export { BitcoinWalletConnectionError, getOKXWallet, getUnisatWallet, getXverseWallet, isUnsupportedBitcoinAddressError, isWalletNetworkDoesNotMatchProviderChainError, OrangeKitConnector, WalletNetworkDoesNotMatchProviderChainError, } from "@mezo-org/orangekit";
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/wallet/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,eAAe,EACf,eAAe,EACf,4BAA4B,EAC5B,2CAA2C,EAC3C,gCAAgC,EAChC,6CAA6C,GAC9C,MAAM,qBAAqB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/wallet/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,YAAY,EACZ,eAAe,EACf,eAAe,EACf,gCAAgC,EAChC,6CAA6C,EAC7C,kBAAkB,EAClB,2CAA2C,GAC5C,MAAM,qBAAqB,CAAA"}
@@ -1,2 +1,2 @@
1
- export { getOKXWallet, getUnisatWallet, getXverseWallet, BitcoinWalletConnectionError, WalletNetworkDoesNotMatchProviderChainError, isUnsupportedBitcoinAddressError, isWalletNetworkDoesNotMatchProviderChainError, } from "@mezo-org/orangekit";
1
+ export { BitcoinWalletConnectionError, getOKXWallet, getUnisatWallet, getXverseWallet, isUnsupportedBitcoinAddressError, isWalletNetworkDoesNotMatchProviderChainError, WalletNetworkDoesNotMatchProviderChainError, } from "@mezo-org/orangekit";
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/wallet/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,eAAe,EACf,eAAe,EACf,4BAA4B,EAC5B,2CAA2C,EAC3C,gCAAgC,EAChC,6CAA6C,GAC9C,MAAM,qBAAqB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/wallet/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,YAAY,EACZ,eAAe,EACf,eAAe,EACf,gCAAgC,EAChC,6CAA6C,EAE7C,2CAA2C,GAC5C,MAAM,qBAAqB,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mezo-org/passport",
3
- "version": "0.4.0-dev.9",
3
+ "version": "0.5.0",
4
4
  "main": "dist/src/index.js",
5
5
  "license": "GPL-3.0-only",
6
6
  "scripts": {
@@ -28,8 +28,6 @@
28
28
  "@types/jest": "^29.5.12",
29
29
  "@types/node": "^20.11.30",
30
30
  "@types/react": "^18.2.64",
31
- "@types/ungap__structured-clone": "^1.2.0",
32
- "@ungap/structured-clone": "^1.3.0",
33
31
  "eslint": "^8.57.1",
34
32
  "jest": "^29.7.0",
35
33
  "jest-environment-jsdom": "^29.7.0",
@@ -39,16 +37,21 @@
39
37
  "typescript": "^5.4.3"
40
38
  },
41
39
  "dependencies": {
42
- "@mezo-org/mezo-clay": "0.1.0-dev.18",
43
- "@mezo-org/orangekit": "1.0.0-beta.40-dev.0",
44
- "@mezo-org/sign-in-with-wallet": "1.0.0-beta.8"
40
+ "@mezo-org/mezo-clay": "0.1.0-dev.30",
41
+ "@mezo-org/mezod-contracts": "^1.0.0",
42
+ "@mezo-org/musd-contracts": "^1.0.1",
43
+ "@mezo-org/orangekit": "1.0.0-beta.40-dev.19",
44
+ "@mezo-org/sign-in-with-wallet": "1.0.0-beta.8",
45
+ "qrcode.react": "^4.2.0",
46
+ "styletron-engine-monolithic": "^1.0.0",
47
+ "usehooks-ts": "^3.1.1",
48
+ "motion": "^12.23.6",
49
+ "zustand": "^5.0.3"
45
50
  },
46
51
  "peerDependencies": {
47
52
  "@rainbow-me/rainbowkit": "2.0.2",
48
53
  "@tanstack/react-query": "^5.28.4",
49
54
  "react": "^18.2.0",
50
- "styletron-engine-monolithic": "^1.0.0",
51
- "usehooks-ts": "^3.1.1",
52
55
  "viem": "2.22.8",
53
56
  "wagmi": "2.5.12"
54
57
  }
package/src/api/auth.ts CHANGED
@@ -38,7 +38,7 @@ export type AuthenticationProviderRedirectResponse = {
38
38
  redirectTo: string
39
39
  }
40
40
 
41
- type SignatureData = {
41
+ export type SignatureData = {
42
42
  message: string
43
43
  signature: string
44
44
  }
@@ -62,12 +62,14 @@ export type GetAccountByMezoIdOrAddressResponse = {
62
62
  linkedAccounts?: Extract<LinkedAccount, { type: "wallet" }>[]
63
63
  }
64
64
 
65
- export type LinkAccountRequest = CreateSessionRequest
65
+ export type LinkAccountRequest = CreateAccountRequest | { type: "discord" }
66
66
  export type LinkAccountResponse =
67
67
  | Account
68
68
  | AuthenticationProviderRedirectResponse
69
69
 
70
- export type CreateAccountRequest = { type: "wallet" } & SignatureData
70
+ export type CreateAccountRequest = { type: "wallet" } & SignatureData & {
71
+ bitcoinPublicKey?: string
72
+ }
71
73
  export type CreateAccountResponse = Account
72
74
 
73
75
  export type UpdateMezoIdResponse = Account
@@ -82,7 +84,9 @@ export class AuthApiClient extends ApiClient {
82
84
  environment: keyof typeof AUTH_API_ENDPOINTS_BY_ENV = "mainnet",
83
85
  apiUrl?: string,
84
86
  ) {
85
- super(apiUrl ?? AUTH_API_ENDPOINTS_BY_ENV[environment])
87
+ super({
88
+ apiUrl: apiUrl ?? AUTH_API_ENDPOINTS_BY_ENV[environment],
89
+ })
86
90
  }
87
91
 
88
92
  async getSession(code?: string) {
package/src/api/client.ts CHANGED
@@ -5,10 +5,19 @@ type RequestHandlerOptions = Omit<RequestInit, "credentials" | "body"> & {
5
5
  queryParams?: Record<string, string | undefined>
6
6
  }
7
7
 
8
+ const ENDS_WITH_VERSIONING_REGEX = /\/v\d+(?=\/|$)/
9
+ const TRAILING_SLASH_REGEX = /\/$/
10
+
8
11
  export abstract class ApiClient {
9
12
  private apiUrl: string
10
13
 
11
- constructor(apiUrl: string) {
14
+ constructor(opts: { apiUrl: string; removeVersioning?: boolean }) {
15
+ const { apiUrl, removeVersioning = false } = opts
16
+
17
+ if (removeVersioning) {
18
+ this.apiUrl = apiUrl.replace(ENDS_WITH_VERSIONING_REGEX, "")
19
+ return
20
+ }
12
21
  this.apiUrl = apiUrl
13
22
  }
14
23
 
@@ -33,7 +42,7 @@ export abstract class ApiClient {
33
42
  const { method, body, queryParams = {}, ...restOptions } = options
34
43
 
35
44
  // If last character in apiUrl is forward slash we are removing it
36
- const authApiUrlRoute = this.apiUrl.replace(/\/$/, "")
45
+ const authApiUrlRoute = this.apiUrl.replace(TRAILING_SLASH_REGEX, "")
37
46
  const url = new URL(`${authApiUrlRoute}${endpoint}`)
38
47
 
39
48
  // Removes falsy values (e.g. null, undefined etc.) from query params and
package/src/api/portal.ts CHANGED
@@ -6,25 +6,19 @@ type PortalStatistics = {
6
6
  tvl: number
7
7
  currentUsdPerBtc: string
8
8
  currentUsdPerEth: string
9
+ currentUsdPerTToken: string
9
10
  usdPerBtc24hChange: string
10
11
  }
11
12
 
12
13
  type PortalMats = {
13
- address: string
14
14
  totalMats: number
15
- matsFromDeposits: number
16
- matsFromReferrals: number
17
- matsFromSecondaryReferrals: number
18
- netMatsTransferred: number
19
- dailyMats: number
20
- dailyMatsFromDeposits: number
21
- dailyMatsFromReferrals: number
22
- dailyMatsFromSecondaryReferrals: number
15
+ inactiveMats: number
16
+ matsActivated: boolean
23
17
  }
24
18
 
25
19
  export const PORTAL_API_ENDPOINTS_BY_ENV = {
26
- mainnet: "https://api.mezo.org/api/v1",
27
- testnet: "https://api.test.mezo.org/api/v1",
20
+ mainnet: "https://api.mezo.org/api/",
21
+ testnet: "https://api.test.mezo.org/api/",
28
22
  }
29
23
 
30
24
  export class PortalApiClient extends ApiClient {
@@ -32,11 +26,14 @@ export class PortalApiClient extends ApiClient {
32
26
  environment: keyof typeof PORTAL_API_ENDPOINTS_BY_ENV = "mainnet",
33
27
  apiUrl?: string,
34
28
  ) {
35
- super(apiUrl ?? PORTAL_API_ENDPOINTS_BY_ENV[environment])
29
+ super({
30
+ apiUrl: apiUrl ?? PORTAL_API_ENDPOINTS_BY_ENV[environment],
31
+ removeVersioning: true,
32
+ })
36
33
  }
37
34
 
38
35
  async getPortalStatistics() {
39
- const data = await this.handleRequest<PortalStatistics>("/statistics", {
36
+ const data = await this.handleRequest<PortalStatistics>("/v1/statistics", {
40
37
  method: "GET",
41
38
  })
42
39
 
@@ -45,7 +42,7 @@ export class PortalApiClient extends ApiClient {
45
42
 
46
43
  async getPortalMats(address: string) {
47
44
  const data = await this.handleRequest<PortalMats>(
48
- `/accounts/${address}/mats`,
45
+ `/v2/account/${address}/mats`,
49
46
  {
50
47
  method: "GET",
51
48
  },