@mezo-org/passport 0.4.0-dev.8 → 0.4.0-dev.81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (262) 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 +19 -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 +13 -6
  26. package/dist/src/components/Dropdown/Dropdown.d.ts.map +1 -1
  27. package/dist/src/components/Dropdown/Dropdown.js +32 -9
  28. package/dist/src/components/Dropdown/Dropdown.js.map +1 -1
  29. package/dist/src/components/Dropdown/ListingItem.d.ts +13 -0
  30. package/dist/src/components/Dropdown/ListingItem.d.ts.map +1 -0
  31. package/dist/src/components/Dropdown/ListingItem.js +34 -0
  32. package/dist/src/components/Dropdown/ListingItem.js.map +1 -0
  33. package/dist/src/components/Dropdown/NestedViewLayout.d.ts +7 -0
  34. package/dist/src/components/Dropdown/NestedViewLayout.d.ts.map +1 -0
  35. package/dist/src/components/Dropdown/NestedViewLayout.js +34 -0
  36. package/dist/src/components/Dropdown/NestedViewLayout.js.map +1 -0
  37. package/dist/src/components/Dropdown/Receive/Receive.d.ts +7 -0
  38. package/dist/src/components/Dropdown/Receive/Receive.d.ts.map +1 -0
  39. package/dist/src/components/Dropdown/Receive/Receive.js +53 -0
  40. package/dist/src/components/Dropdown/Receive/Receive.js.map +1 -0
  41. package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts +7 -0
  42. package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts.map +1 -0
  43. package/dist/src/components/Dropdown/Root/AccountAddressActions.js +48 -0
  44. package/dist/src/components/Dropdown/Root/AccountAddressActions.js.map +1 -0
  45. package/dist/src/components/Dropdown/Root/AccountAssetItem.d.ts +11 -0
  46. package/dist/src/components/Dropdown/Root/AccountAssetItem.d.ts.map +1 -0
  47. package/dist/src/components/Dropdown/Root/AccountAssetItem.js +9 -0
  48. package/dist/src/components/Dropdown/Root/AccountAssetItem.js.map +1 -0
  49. package/dist/src/components/Dropdown/{AccountBalance.d.ts → Root/AccountBalance.d.ts} +2 -1
  50. package/dist/src/components/Dropdown/Root/AccountBalance.d.ts.map +1 -0
  51. package/dist/src/components/Dropdown/Root/AccountBalance.js +15 -0
  52. package/dist/src/components/Dropdown/Root/AccountBalance.js.map +1 -0
  53. package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts +9 -0
  54. package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts.map +1 -0
  55. package/dist/src/components/Dropdown/Root/AccountOtherAssets.js +48 -0
  56. package/dist/src/components/Dropdown/Root/AccountOtherAssets.js.map +1 -0
  57. package/dist/src/components/Dropdown/Root/Root.d.ts +23 -0
  58. package/dist/src/components/Dropdown/Root/Root.d.ts.map +1 -0
  59. package/dist/src/components/Dropdown/Root/Root.js +57 -0
  60. package/dist/src/components/Dropdown/Root/Root.js.map +1 -0
  61. package/dist/src/components/Dropdown/Root/WalletAddress.d.ts +8 -0
  62. package/dist/src/components/Dropdown/Root/WalletAddress.d.ts.map +1 -0
  63. package/dist/src/components/Dropdown/{AccountAddress.js → Root/WalletAddress.js} +21 -15
  64. package/dist/src/components/Dropdown/Root/WalletAddress.js.map +1 -0
  65. package/dist/src/components/Dropdown/{WelcomeBlock.d.ts → Root/WelcomeBlock.d.ts} +1 -1
  66. package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts.map +1 -0
  67. package/dist/src/components/Dropdown/{WelcomeBlock.js → Root/WelcomeBlock.js} +5 -5
  68. package/dist/src/components/Dropdown/Root/WelcomeBlock.js.map +1 -0
  69. package/dist/src/components/Dropdown/TestnetTopBanner.d.ts +3 -0
  70. package/dist/src/components/Dropdown/TestnetTopBanner.d.ts.map +1 -0
  71. package/dist/src/components/Dropdown/TestnetTopBanner.js +14 -0
  72. package/dist/src/components/Dropdown/TestnetTopBanner.js.map +1 -0
  73. package/dist/src/config.d.ts +29 -6
  74. package/dist/src/config.d.ts.map +1 -1
  75. package/dist/src/config.js +88 -15
  76. package/dist/src/config.js.map +1 -1
  77. package/dist/src/constants.d.ts +13 -3
  78. package/dist/src/constants.d.ts.map +1 -1
  79. package/dist/src/constants.js +14 -4
  80. package/dist/src/constants.js.map +1 -1
  81. package/dist/src/hooks/index.d.ts +4 -0
  82. package/dist/src/hooks/index.d.ts.map +1 -1
  83. package/dist/src/hooks/index.js +4 -0
  84. package/dist/src/hooks/index.js.map +1 -1
  85. package/dist/src/hooks/useAssetsConversionRates.d.ts +23 -0
  86. package/dist/src/hooks/useAssetsConversionRates.d.ts.map +1 -0
  87. package/dist/src/hooks/useAssetsConversionRates.js +90 -0
  88. package/dist/src/hooks/useAssetsConversionRates.js.map +1 -0
  89. package/dist/src/hooks/useAuthenticateWithWallet.d.ts +13 -13
  90. package/dist/src/hooks/useAuthenticateWithWallet.d.ts.map +1 -1
  91. package/dist/src/hooks/useAuthenticateWithWallet.js +8 -7
  92. package/dist/src/hooks/useAuthenticateWithWallet.js.map +1 -1
  93. package/dist/src/hooks/useBorrowData.d.ts +82 -0
  94. package/dist/src/hooks/useBorrowData.d.ts.map +1 -0
  95. package/dist/src/hooks/useBorrowData.js +159 -0
  96. package/dist/src/hooks/useBorrowData.js.map +1 -0
  97. package/dist/src/hooks/useCreateAccount.d.ts.map +1 -1
  98. package/dist/src/hooks/useCreateAccount.js +22 -1
  99. package/dist/src/hooks/useCreateAccount.js.map +1 -1
  100. package/dist/src/hooks/useDropdownData.d.ts +37 -34
  101. package/dist/src/hooks/useDropdownData.d.ts.map +1 -1
  102. package/dist/src/hooks/useDropdownData.js +85 -61
  103. package/dist/src/hooks/useDropdownData.js.map +1 -1
  104. package/dist/src/hooks/useLinkAccount.d.ts +19 -13
  105. package/dist/src/hooks/useLinkAccount.d.ts.map +1 -1
  106. package/dist/src/hooks/useLinkAccount.js +20 -1
  107. package/dist/src/hooks/useLinkAccount.js.map +1 -1
  108. package/dist/src/hooks/useRefreshPassport.d.ts +19 -0
  109. package/dist/src/hooks/useRefreshPassport.d.ts.map +1 -0
  110. package/dist/src/hooks/useRefreshPassport.js +44 -0
  111. package/dist/src/hooks/useRefreshPassport.js.map +1 -0
  112. package/dist/src/hooks/useSignInWithWallet.d.ts +13 -13
  113. package/dist/src/hooks/useSignInWithWallet.d.ts.map +1 -1
  114. package/dist/src/hooks/useSignUpWithWallet.d.ts +13 -13
  115. package/dist/src/hooks/useSignUpWithWallet.d.ts.map +1 -1
  116. package/dist/src/hooks/useTokensBalances.d.ts +74 -0
  117. package/dist/src/hooks/useTokensBalances.d.ts.map +1 -0
  118. package/dist/src/hooks/useTokensBalances.js +140 -0
  119. package/dist/src/hooks/useTokensBalances.js.map +1 -0
  120. package/dist/src/hooks/useValidateMezoId.d.ts +8 -0
  121. package/dist/src/hooks/useValidateMezoId.d.ts.map +1 -0
  122. package/dist/src/hooks/useValidateMezoId.js +24 -0
  123. package/dist/src/hooks/useValidateMezoId.js.map +1 -0
  124. package/dist/src/hooks/useWalletAccount.d.ts +2 -1
  125. package/dist/src/hooks/useWalletAccount.d.ts.map +1 -1
  126. package/dist/src/hooks/useWalletAccount.js +19 -15
  127. package/dist/src/hooks/useWalletAccount.js.map +1 -1
  128. package/dist/src/hooks/useWatchTransferEvents.d.ts +5 -0
  129. package/dist/src/hooks/useWatchTransferEvents.d.ts.map +1 -0
  130. package/dist/src/hooks/useWatchTransferEvents.js +63 -0
  131. package/dist/src/hooks/useWatchTransferEvents.js.map +1 -0
  132. package/dist/src/index.d.ts +2 -1
  133. package/dist/src/index.d.ts.map +1 -1
  134. package/dist/src/index.js +2 -1
  135. package/dist/src/index.js.map +1 -1
  136. package/dist/src/lib/contracts/index.d.ts +13 -0
  137. package/dist/src/lib/contracts/index.d.ts.map +1 -0
  138. package/dist/src/lib/contracts/index.js +62 -0
  139. package/dist/src/lib/contracts/index.js.map +1 -0
  140. package/dist/src/lib/contracts/priceOracle.d.ts +43 -0
  141. package/dist/src/lib/contracts/priceOracle.d.ts.map +1 -0
  142. package/dist/src/lib/contracts/priceOracle.js +52 -0
  143. package/dist/src/lib/contracts/priceOracle.js.map +1 -0
  144. package/dist/src/provider.js +1 -1
  145. package/dist/src/provider.js.map +1 -1
  146. package/dist/src/stores/dropdownStore.d.ts +12 -0
  147. package/dist/src/stores/dropdownStore.d.ts.map +1 -0
  148. package/dist/src/stores/dropdownStore.js +13 -0
  149. package/dist/src/stores/dropdownStore.js.map +1 -0
  150. package/dist/src/utils/address.d.ts +1 -1
  151. package/dist/src/utils/address.d.ts.map +1 -1
  152. package/dist/src/utils/address.js +2 -0
  153. package/dist/src/utils/address.js.map +1 -1
  154. package/dist/src/utils/address.test.js +8 -5
  155. package/dist/src/utils/address.test.js.map +1 -1
  156. package/dist/src/utils/cryptoAssets.d.ts +17 -1
  157. package/dist/src/utils/cryptoAssets.d.ts.map +1 -1
  158. package/dist/src/utils/cryptoAssets.js +87 -31
  159. package/dist/src/utils/cryptoAssets.js.map +1 -1
  160. package/dist/src/utils/cryptoAssets.test.js +51 -33
  161. package/dist/src/utils/cryptoAssets.test.js.map +1 -1
  162. package/dist/src/utils/currency.d.ts +8 -0
  163. package/dist/src/utils/currency.d.ts.map +1 -1
  164. package/dist/src/utils/currency.js +11 -0
  165. package/dist/src/utils/currency.js.map +1 -1
  166. package/dist/src/utils/currency.test.js +1 -0
  167. package/dist/src/utils/currency.test.js.map +1 -1
  168. package/dist/src/utils/mezoId.d.ts +7 -0
  169. package/dist/src/utils/mezoId.d.ts.map +1 -0
  170. package/dist/src/utils/mezoId.js +41 -0
  171. package/dist/src/utils/mezoId.js.map +1 -0
  172. package/dist/src/utils/numbers.d.ts +39 -17
  173. package/dist/src/utils/numbers.d.ts.map +1 -1
  174. package/dist/src/utils/numbers.js +91 -33
  175. package/dist/src/utils/numbers.js.map +1 -1
  176. package/dist/src/utils/numbers.test.js +144 -22
  177. package/dist/src/utils/numbers.test.js.map +1 -1
  178. package/dist/src/utils/siww.d.ts +1 -0
  179. package/dist/src/utils/siww.d.ts.map +1 -1
  180. package/dist/src/utils/siww.js +50 -12
  181. package/dist/src/utils/siww.js.map +1 -1
  182. package/dist/src/utils/wagmi.d.ts +3 -0
  183. package/dist/src/utils/wagmi.d.ts.map +1 -0
  184. package/dist/src/utils/wagmi.js +7 -0
  185. package/dist/src/utils/wagmi.js.map +1 -0
  186. package/dist/src/wallet/index.d.ts +1 -1
  187. package/dist/src/wallet/index.d.ts.map +1 -1
  188. package/dist/src/wallet/index.js +1 -1
  189. package/dist/src/wallet/index.js.map +1 -1
  190. package/package.json +10 -8
  191. package/src/api/auth.ts +8 -4
  192. package/src/api/client.ts +11 -2
  193. package/src/api/portal.ts +11 -14
  194. package/src/components/Dropdown/ConnectedTrigger.tsx +52 -32
  195. package/src/components/Dropdown/Content.tsx +67 -117
  196. package/src/components/Dropdown/DisconnectedTrigger.tsx +2 -1
  197. package/src/components/Dropdown/Dropdown.tsx +75 -15
  198. package/src/components/Dropdown/ListingItem.tsx +80 -0
  199. package/src/components/Dropdown/NestedViewLayout.tsx +75 -0
  200. package/src/components/Dropdown/README.md +10 -18
  201. package/src/components/Dropdown/Receive/Receive.tsx +119 -0
  202. package/src/components/Dropdown/Root/AccountAddressActions.tsx +101 -0
  203. package/src/components/Dropdown/Root/AccountAssetItem.tsx +26 -0
  204. package/src/components/Dropdown/Root/AccountBalance.tsx +30 -0
  205. package/src/components/Dropdown/Root/AccountOtherAssets.tsx +68 -0
  206. package/src/components/Dropdown/Root/Root.tsx +147 -0
  207. package/src/components/Dropdown/Root/WalletAddress.tsx +128 -0
  208. package/src/components/Dropdown/{WelcomeBlock.tsx → Root/WelcomeBlock.tsx} +5 -6
  209. package/src/components/Dropdown/TestnetTopBanner.tsx +32 -0
  210. package/src/config.ts +135 -21
  211. package/src/constants.ts +18 -4
  212. package/src/hooks/index.ts +7 -0
  213. package/src/hooks/useAssetsConversionRates.ts +97 -0
  214. package/src/hooks/useAuthenticateWithWallet.ts +33 -12
  215. package/src/hooks/useBorrowData.ts +187 -0
  216. package/src/hooks/useCreateAccount.ts +28 -2
  217. package/src/hooks/useDropdownData.ts +119 -97
  218. package/src/hooks/useLinkAccount.ts +36 -4
  219. package/src/hooks/useRefreshPassport.ts +56 -0
  220. package/src/hooks/useSignInWithWallet.ts +2 -2
  221. package/src/hooks/useSignUpWithWallet.ts +2 -2
  222. package/src/hooks/useTokensBalances.ts +187 -0
  223. package/src/hooks/useValidateMezoId.ts +31 -0
  224. package/src/hooks/useWalletAccount.ts +29 -19
  225. package/src/hooks/useWatchTransferEvents.ts +74 -0
  226. package/src/index.ts +13 -1
  227. package/src/lib/contracts/index.ts +92 -0
  228. package/src/lib/contracts/priceOracle.ts +53 -0
  229. package/src/provider.ts +1 -1
  230. package/src/stores/dropdownStore.ts +20 -0
  231. package/src/utils/address.test.ts +10 -6
  232. package/src/utils/address.ts +5 -3
  233. package/src/utils/cryptoAssets.test.ts +57 -37
  234. package/src/utils/cryptoAssets.ts +113 -35
  235. package/src/utils/currency.test.ts +2 -0
  236. package/src/utils/currency.ts +21 -0
  237. package/src/utils/mezoId.ts +51 -0
  238. package/src/utils/numbers.test.ts +181 -23
  239. package/src/utils/numbers.ts +121 -34
  240. package/src/utils/siww.ts +71 -16
  241. package/src/utils/wagmi.ts +12 -0
  242. package/src/wallet/index.ts +3 -2
  243. package/dist/src/components/Dropdown/AccountAddress.d.ts +0 -8
  244. package/dist/src/components/Dropdown/AccountAddress.d.ts.map +0 -1
  245. package/dist/src/components/Dropdown/AccountAddress.js.map +0 -1
  246. package/dist/src/components/Dropdown/AccountAssets.d.ts +0 -14
  247. package/dist/src/components/Dropdown/AccountAssets.d.ts.map +0 -1
  248. package/dist/src/components/Dropdown/AccountAssets.js +0 -44
  249. package/dist/src/components/Dropdown/AccountAssets.js.map +0 -1
  250. package/dist/src/components/Dropdown/AccountBalance.d.ts.map +0 -1
  251. package/dist/src/components/Dropdown/AccountBalance.js +0 -18
  252. package/dist/src/components/Dropdown/AccountBalance.js.map +0 -1
  253. package/dist/src/components/Dropdown/WelcomeBlock.d.ts.map +0 -1
  254. package/dist/src/components/Dropdown/WelcomeBlock.js.map +0 -1
  255. package/dist/src/hooks/useAssetsUSDConversion.d.ts +0 -8
  256. package/dist/src/hooks/useAssetsUSDConversion.d.ts.map +0 -1
  257. package/dist/src/hooks/useAssetsUSDConversion.js +0 -21
  258. package/dist/src/hooks/useAssetsUSDConversion.js.map +0 -1
  259. package/src/components/Dropdown/AccountAddress.tsx +0 -111
  260. package/src/components/Dropdown/AccountAssets.tsx +0 -110
  261. package/src/components/Dropdown/AccountBalance.tsx +0 -38
  262. package/src/hooks/useAssetsUSDConversion.ts +0 -31
@@ -1,28 +1,44 @@
1
+ type DesiredDecimals = Intl.NumberFormatOptions &
2
+ BigIntToLocaleStringOptions["minimumFractionDigits"]
3
+
1
4
  /**
2
- * Formats a number or bigint into a human-readable string with K, M, B, or T suffix.
5
+ * Formats a number or bigint into compact string with K, M, B, or T suffix.
3
6
  * @param value The number or bigint to format.
4
7
  * @param decimals Number of decimal places to include (ignored for bigint to avoid floating point issues).
5
8
  * @returns The formatted number as a string.
6
9
  */
7
- export function formatHumanReadableNumber(
10
+ export function formatNumberToCompactString(
8
11
  value: number | bigint,
9
- decimals: number = 4,
12
+ decimals = 4,
10
13
  ): string {
11
- const suffixes = ["", "K", "M", "B", "T"]
12
- const numericValue = typeof value === "bigint" ? Number(value) : value
14
+ return value.toLocaleString("en-US", {
15
+ notation: "compact",
16
+ compactDisplay: "short",
17
+ maximumFractionDigits: decimals as DesiredDecimals,
18
+ })
19
+ }
13
20
 
14
- if (numericValue < 1000) return numericValue.toFixed(decimals)
21
+ /**
22
+ * Formats a number or string into a locale-sensitive string with the desired number of decimals.
23
+ * @param value The number or string to format.
24
+ * @param desiredDecimals The number of decimal places to include.
25
+ * @returns The formatted number as a string.
26
+ * @see https://github.com/thesis/acre/blob/2078d339f4ddce79e69c78529c9d72910dd2640a/dapp/src/utils/numbersUtils.ts#L5-L19
27
+ */
28
+ export function formatNumberToLocaleString(
29
+ value: string | number,
30
+ desiredDecimals = 0,
31
+ ) {
32
+ const number = typeof value === "number" ? value : parseFloat(value)
15
33
 
16
- const magnitude = Math.floor(Math.log10(numericValue) / 3)
34
+ if (number === 0 && desiredDecimals === 0) return "0"
17
35
 
18
- if (magnitude >= suffixes.length) {
19
- const max = 10 ** ((suffixes.length - 1) * 3) * 1000 - 1
20
- const capped = max / 10 ** ((suffixes.length - 1) * 3)
21
- return `> ${capped.toFixed(0)}${suffixes[suffixes.length - 1]}`
22
- }
36
+ if (number === 0) return `0.${"0".repeat(desiredDecimals)}`
23
37
 
24
- const scaledValue = numericValue / 10 ** (magnitude * 3)
25
- return `${scaledValue.toFixed(decimals)}${suffixes[magnitude]}`
38
+ return number.toLocaleString("en-US", {
39
+ minimumFractionDigits: desiredDecimals,
40
+ maximumFractionDigits: desiredDecimals,
41
+ })
26
42
  }
27
43
 
28
44
  /**
@@ -30,7 +46,7 @@ export function formatHumanReadableNumber(
30
46
  * @param amount The number to round up.
31
47
  * @param desiredDecimals The number of decimals to round up to.
32
48
  * @returns The rounded up number.
33
- * @see https://github.com/thesis/acre/blob/main/dapp/src/utils/numbersUtils.ts#L1-L3
49
+ * @see https://github.com/thesis/acre/blob/2078d339f4ddce79e69c78529c9d72910dd2640a/dapp/src/utils/numbersUtils.ts#L1-L3
34
50
  */
35
51
  export function roundUpNumber(amount: number, desiredDecimals = 2): number {
36
52
  return Math.ceil(amount * 10 ** desiredDecimals) / 10 ** desiredDecimals
@@ -43,12 +59,12 @@ export function roundUpNumber(amount: number, desiredDecimals = 2): number {
43
59
  * @param fixedPointDecimals The number of decimals in the fixed point bigint.
44
60
  * @param desiredDecimals The number of decimals in the output number.
45
61
  * @returns The floating point number truncated to `desiredDecimals`.
46
- * @see https://github.com/tahowallet/extension/blob/main/background/lib/fixed-point.ts#L216-L239
62
+ * @see https://github.com/tahowallet/extension/blob/f6b26b7cb4a0a0278b1fccc6319626638f1a6dfa/background/lib/fixed-point.ts#L216-L239
47
63
  */
48
64
  export function fromFixedPoint(
49
65
  fixedPoint: bigint,
50
66
  fixedPointDecimals: number,
51
- desiredDecimals = 2,
67
+ desiredDecimals = 4,
52
68
  ): number {
53
69
  const fixedPointDesiredDecimalsAmount =
54
70
  fixedPoint /
@@ -62,27 +78,21 @@ export function fromFixedPoint(
62
78
  }
63
79
 
64
80
  /**
65
- * Display a cryptoAsset amount correctly with desired decimals.
81
+ * Display a token amount correctly with desired decimals.
66
82
  * The function returns a string with a language-sensitive representation of this number.
67
- * - If the amount entered is zero, return the result with the desired decimals.
68
- * For example, 0.00 for a precision of 2.
69
- * - If `formattedAmount` is less than the minimum amount to display
70
- * for the specified precision return information about this.
71
- * For example, <0.01 for a precision of 2.
72
- * - Other amounts are formatted according to the use of the `bigIntToUserAmount` function.
73
- * @param amount The amount of tokens to format.
74
- * @param decimals The number of decimals the cryptoAsset has.
83
+ * @param amount The fixed point number to convert.
84
+ * @param decimals The number of decimals in the fixed point number.
75
85
  * @param desiredDecimals The number of decimals to display.
76
- * @param withRoundUp If true, the amount will be rounded up.
77
- * @returns The formatted cryptoAsset amount.
78
- * @see https://github.com/thesis/acre/blob/main/dapp/src/utils/numbersUtils.ts#L57-L87
86
+ * @param withRoundUp Whether to round up the number.
87
+ * @returns The formatted number as a string.
88
+ * @see https://github.com/thesis/acre/blob/2078d339f4ddce79e69c78529c9d72910dd2640a/dapp/src/utils/numbersUtils.ts#L57-L87
79
89
  */
80
- export function formatTokenAmount(
90
+ export const fromFixedPointToString = (
81
91
  amount: number | string | bigint,
82
92
  decimals = 18,
83
- desiredDecimals = 2,
93
+ desiredDecimals = 4,
84
94
  withRoundUp = false,
85
- ) {
95
+ ) => {
86
96
  const fixedPoint = BigInt(amount)
87
97
 
88
98
  if (fixedPoint === 0n) {
@@ -104,7 +114,84 @@ export function formatTokenAmount(
104
114
  }
105
115
 
106
116
  const finalFormattedAmount = withRoundUp
107
- ? roundUpNumber(formattedAmount, desiredDecimals)
117
+ ? Math.ceil(formattedAmount * 10 ** desiredDecimals) / 10 ** desiredDecimals
108
118
  : formattedAmount
109
- return formatHumanReadableNumber(finalFormattedAmount, desiredDecimals)
119
+ return formatNumberToLocaleString(finalFormattedAmount, desiredDecimals)
120
+ }
121
+
122
+ /**
123
+ * Converts a floating-point number or string to a bigint representation
124
+ * scaled by the specified number of decimal places (default: 18).
125
+ *
126
+ * This function avoids floating-point precision issues by manually
127
+ * parsing and scaling the number.
128
+ *
129
+ * @param amount - A number or string containing a floating point number.
130
+ * @param decimals - Number of decimals to scale to (default: 18).
131
+ * @returns A bigint representation scaled to the given decimal places.
132
+ * @see https://github.com/thesis/mezo-portal/blob/3bd4f39cb77c39948af2886a6ce7415a0c60307a/dapp/src/shared/utils/numbers.ts#L55
133
+ */
134
+ export const fromFloatToBigInt = (
135
+ amount: string | number,
136
+ decimals = 18,
137
+ ): bigint => {
138
+ const FLOATING_POINT_REGEX = /^-?\d{1,3}(,\d{3})*(\.\d+)?$|^-?\d+(\.\d+)?$/
139
+
140
+ const parseToFixedPointNumber = (
141
+ floatingPointString: string,
142
+ ): { amount: bigint; decimals: number } | undefined => {
143
+ if (!floatingPointString.match(FLOATING_POINT_REGEX)) {
144
+ return undefined
145
+ }
146
+
147
+ const [whole, decimalsPart, ...extra] = floatingPointString.split(".")
148
+
149
+ if (extra.length > 0) return undefined
150
+
151
+ const noThousandsSeparatorWhole = whole.replace(/,/g, "")
152
+ const setDecimals = decimalsPart ?? ""
153
+
154
+ try {
155
+ return {
156
+ amount: BigInt([noThousandsSeparatorWhole, setDecimals].join("")),
157
+ decimals: setDecimals.length,
158
+ }
159
+ } catch {
160
+ return undefined
161
+ }
162
+ }
163
+
164
+ const convertFixedPoint = (
165
+ fixedPoint: bigint,
166
+ fixedPointDecimals: number,
167
+ targetDecimals: number,
168
+ ): bigint => {
169
+ if (fixedPointDecimals >= targetDecimals) {
170
+ return fixedPoint / 10n ** BigInt(fixedPointDecimals - targetDecimals)
171
+ }
172
+
173
+ return fixedPoint * 10n ** BigInt(targetDecimals - fixedPointDecimals)
174
+ }
175
+
176
+ const parsedAmount = amount.toString()
177
+ const fixedPointAmount = parseToFixedPointNumber(parsedAmount)
178
+
179
+ if (typeof fixedPointAmount === "undefined") {
180
+ return 0n
181
+ }
182
+
183
+ return convertFixedPoint(
184
+ fixedPointAmount.amount,
185
+ fixedPointAmount.decimals,
186
+ decimals,
187
+ )
110
188
  }
189
+
190
+ /**
191
+ * Utility function to find the maximum value from an array of bigint values.
192
+ * @param values Array of bigint values to find the maximum from.
193
+ * @returns The maximum value from the provided bigint values.
194
+ * @dev Works exactly like `Math.max` but for bigint values.
195
+ */
196
+ export const bigIntMax = (...values: bigint[]) =>
197
+ values.reduce((max, value) => (value > max ? value : max))
package/src/utils/siww.ts CHANGED
@@ -1,4 +1,7 @@
1
- import { SignInWithWalletMessage } from "@mezo-org/sign-in-with-wallet"
1
+ import {
2
+ SignInWithWalletErrorType,
3
+ SignInWithWalletMessage,
4
+ } from "@mezo-org/sign-in-with-wallet"
2
5
  import { ONE_DAY_MS } from "./time"
3
6
 
4
7
  const SESSION_EXPIRATION_DURATION_MS = 14 * ONE_DAY_MS
@@ -13,19 +16,71 @@ export function createSignInWithWalletMessage(
13
16
  ) {
14
17
  const { host: domain, origin: uri } = window.location
15
18
 
16
- const message = new SignInWithWalletMessage({
17
- domain,
18
- address, // if "bitcoin" this should be btc address, not underlaying eth address
19
- uri,
20
- nonce,
21
- issuedAt: new Date().toISOString(),
22
- expirationTime: new Date(
23
- Date.now() + SESSION_EXPIRATION_DURATION_MS,
24
- ).toISOString(),
25
- version: "1",
26
- chainId: networkFamily === "evm" ? chainId : undefined,
27
- networkFamily,
28
- })
29
-
30
- return message.prepareMessage()
19
+ let siwwMessage
20
+ try {
21
+ siwwMessage = new SignInWithWalletMessage({
22
+ domain,
23
+ address, // if "bitcoin" this should be btc address, not underlaying eth address
24
+ uri,
25
+ nonce,
26
+ issuedAt: new Date().toISOString(),
27
+ expirationTime: new Date(
28
+ Date.now() + SESSION_EXPIRATION_DURATION_MS,
29
+ ).toISOString(),
30
+ version: "1",
31
+ chainId: networkFamily === "evm" ? chainId : undefined,
32
+ networkFamily,
33
+ })
34
+ } catch (error) {
35
+ throw new Error(`Failed to create sign in with wallet message: ${error}`)
36
+ }
37
+
38
+ return siwwMessage.prepareMessage()
39
+ }
40
+
41
+ class SIWWDomainError extends Error {
42
+ constructor(message: string) {
43
+ super(`Error when verifying domain in SIWW message: ${message}`)
44
+ this.name = "SIWWDomainError"
45
+ }
46
+ }
47
+
48
+ export async function verifyDomainInSignInWithWalletMessage(
49
+ message: string,
50
+ signature: string,
51
+ nonce: string,
52
+ ) {
53
+ const { host: domain } = window.location
54
+ let siwwMessage: SignInWithWalletMessage
55
+ try {
56
+ siwwMessage = new SignInWithWalletMessage(message)
57
+ } catch (error) {
58
+ throw new SIWWDomainError("Failed to parse SIWW message")
59
+ }
60
+
61
+ if (!siwwMessage.expirationTime) {
62
+ throw new SIWWDomainError("SIWW messages must have an expiration time set")
63
+ }
64
+
65
+ const result = await siwwMessage.verify(
66
+ {
67
+ signature,
68
+ // Nonce has to match the session ID carried in the request.
69
+ nonce,
70
+ domain,
71
+ // Time is used as a reference to verify the expiration time set in the
72
+ // message.
73
+ time: new Date().toISOString(),
74
+ },
75
+ { suppressExceptions: true },
76
+ )
77
+
78
+ if (
79
+ result.error &&
80
+ result.error.type === SignInWithWalletErrorType.DOMAIN_MISMATCH
81
+ ) {
82
+ throw new SIWWDomainError(
83
+ "Domain does not match provided domain for verification.",
84
+ )
85
+ }
31
86
  }
@@ -0,0 +1,12 @@
1
+ import { OrangeKitConnector } from "@mezo-org/orangekit"
2
+ import { Connector } from "wagmi"
3
+
4
+ export async function getBitcoinPublicKeyFromConnector(connector: Connector) {
5
+ if (connector.type !== "orangekit") return undefined
6
+
7
+ const provider = (
8
+ connector as unknown as OrangeKitConnector
9
+ ).getBitcoinProvider()
10
+
11
+ return provider.getPublicKey()
12
+ }
@@ -1,9 +1,10 @@
1
1
  export {
2
+ BitcoinWalletConnectionError,
2
3
  getOKXWallet,
3
4
  getUnisatWallet,
4
5
  getXverseWallet,
5
- BitcoinWalletConnectionError,
6
- WalletNetworkDoesNotMatchProviderChainError,
7
6
  isUnsupportedBitcoinAddressError,
8
7
  isWalletNetworkDoesNotMatchProviderChainError,
8
+ OrangeKitConnector,
9
+ WalletNetworkDoesNotMatchProviderChainError,
9
10
  } from "@mezo-org/orangekit"
@@ -1,8 +0,0 @@
1
- import React from "react";
2
- type AccountAddressProps = {
3
- address: string;
4
- type: "bitcoin" | "evm";
5
- };
6
- export default function AccountAddress(props: AccountAddressProps): React.JSX.Element;
7
- export {};
8
- //# sourceMappingURL=AccountAddress.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AccountAddress.d.ts","sourceRoot":"","sources":["../../../../src/components/Dropdown/AccountAddress.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,MAAM,OAAO,CAAA;AAMzB,KAAK,mBAAmB,GAAG;IACzB,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,SAAS,GAAG,KAAK,CAAA;CACxB,CAAA;AAID,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,KAAK,EAAE,mBAAmB,qBA0FhE"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"AccountAddress.js","sourceRoot":"","sources":["../../../../src/components/Dropdown/AccountAddress.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,MAAM,IAAI,QAAQ,EAClB,cAAc,IAAI,QAAQ,EAC1B,cAAc,EACd,YAAY,GACb,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AACnE,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAOzD,oCAAoC;AAEpC,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,KAA0B;IAC/D,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,KAAK,CAAA;IAE/B,MAAM,EAAE,WAAW,EAAE,GAAG,kBAAkB,EAAE,CAAA;IAC5C,MAAM,gBAAgB,GAAG,qBAAqB,CAC5C,OAAO,EACP,IAAI,EACJ,WAAW,KAAK,SAAS,CAC1B,CAAA;IACD,MAAM,cAAc,GAAG,WAAW,CAAC,OAAO,CAAC,CAAA;IAC3C,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,cAAc,CAC1C,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,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IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,QAAQ,EAC3B,SAAS,EAAE;wBACT,GAAG,EAAE;4BACH,KAAK,EAAE;gCACL,MAAM,EAAE,cAAc;gCACtB,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,QAAQ;6BAClC;yBACF;qBACF,GACD,CACa,CACX;QACR,oBAAC,QAAQ,IACP,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,QAAQ,EAC3B,SAAS,EAAE;gBACT,GAAG,EAAE;oBACH,KAAK,EAAE;wBACL,UAAU,EAAE,MAAM;wBAClB,MAAM,EAAE,cAAc;qBACvB;iBACF;aACF,GACD,CACI,CACT,CAAA;AACH,CAAC"}
@@ -1,14 +0,0 @@
1
- import React from "react";
2
- import { CryptoAssetKey } from "../../utils/cryptoAssets";
3
- type AccountAssetsProps = {
4
- label: string | React.ReactNode;
5
- assets: {
6
- type: CryptoAssetKey;
7
- decimals: number;
8
- balance: number;
9
- balanceInUsd: number;
10
- }[];
11
- };
12
- export default function AccountAssets(props: AccountAssetsProps): React.JSX.Element | null;
13
- export {};
14
- //# sourceMappingURL=AccountAssets.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AccountAssets.d.ts","sourceRoot":"","sources":["../../../../src/components/Dropdown/AccountAssets.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAkB,MAAM,OAAO,CAAA;AACtC,OAAO,EAAE,cAAc,EAAkB,MAAM,0BAA0B,CAAA;AAGzE,KAAK,kBAAkB,GAAG;IACxB,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC,SAAS,CAAA;IAC/B,MAAM,EAAE;QACN,IAAI,EAAE,cAAc,CAAA;QACpB,QAAQ,EAAE,MAAM,CAAA;QAChB,OAAO,EAAE,MAAM,CAAA;QACf,YAAY,EAAE,MAAM,CAAA;KACrB,EAAE,CAAA;CACJ,CAAA;AAED,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,KAAK,EAAE,kBAAkB,4BAyF9D"}
@@ -1,44 +0,0 @@
1
- import { Block, LabelSmall, ParagraphSmall, useStyletron, } from "@mezo-org/mezo-clay";
2
- import React, { useMemo } from "react";
3
- import { getCryptoAsset } from "../../utils/cryptoAssets";
4
- import { formatUsd } from "../../utils/currency";
5
- export default function AccountAssets(props) {
6
- const { label, assets } = props;
7
- const [, theme] = useStyletron();
8
- const assetsData = useMemo(() => assets.map((token) => {
9
- const { name, symbol, icon } = getCryptoAsset(token.type);
10
- return {
11
- ...token,
12
- icon,
13
- label: name,
14
- symbol,
15
- };
16
- }), [assets]);
17
- const labelContent = typeof label === "string" ? (React.createElement(ParagraphSmall, { margin: 0, color: theme.colors.gray800 }, label)) : (label);
18
- if (assetsData.length === 0) {
19
- return null;
20
- }
21
- return (React.createElement(Block, { padding: `0 ${theme.sizing.scale500}` },
22
- React.createElement(Block, { margin: `${theme.sizing.scale400} 0` }, labelContent),
23
- React.createElement(Block, { as: "ul", marginBottom: theme.sizing.scale600, padding: 0, display: "flex", flexDirection: "column", overrides: {
24
- Block: {
25
- style: {
26
- gap: theme.sizing.scale100,
27
- },
28
- },
29
- } }, assetsData.map((asset) => (React.createElement(Block, { as: "li", key: `${asset.type}-${asset.balance}`, display: "flex", justifyContent: "space-between", alignItems: "center", margin: `${theme.sizing.scale100} 0` },
30
- React.createElement(asset.icon, { size: theme.sizing.scale800, overrides: {
31
- Svg: {
32
- style: {
33
- marginRight: theme.sizing.scale500,
34
- },
35
- },
36
- } }),
37
- React.createElement(Block, { flex: 1 },
38
- React.createElement(LabelSmall, { margin: 0 }, asset.label),
39
- React.createElement(ParagraphSmall, { margin: 0, color: theme.colors.gray500 }, asset.symbol)),
40
- React.createElement(Block, { display: "flex", alignItems: "end", flexDirection: "column" },
41
- React.createElement(LabelSmall, { margin: 0 }, asset.balance),
42
- React.createElement(ParagraphSmall, { margin: 0, color: theme.colors.gray500 }, formatUsd(asset.balanceInUsd)))))))));
43
- }
44
- //# sourceMappingURL=AccountAssets.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AccountAssets.js","sourceRoot":"","sources":["../../../../src/components/Dropdown/AccountAssets.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,UAAU,EACV,cAAc,EACd,YAAY,GACb,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AACtC,OAAO,EAAkB,cAAc,EAAE,MAAM,0BAA0B,CAAA;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAYhD,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,KAAyB;IAC7D,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,KAAK,CAAA;IAE/B,MAAM,CAAC,EAAE,KAAK,CAAC,GAAG,YAAY,EAAE,CAAA;IAEhC,MAAM,UAAU,GAAG,OAAO,CACxB,GAAG,EAAE,CACH,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QACnB,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QAEzD,OAAO;YACL,GAAG,KAAK;YACR,IAAI;YACJ,KAAK,EAAE,IAAI;YACX,MAAM;SACP,CAAA;IACH,CAAC,CAAC,EACJ,CAAC,MAAM,CAAC,CACT,CAAA;IAED,MAAM,YAAY,GAChB,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,CAC1B,oBAAC,cAAc,IAAC,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,OAAO,IACnD,KAAK,CACS,CAClB,CAAC,CAAC,CAAC,CACF,KAAK,CACN,CAAA;IAEH,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5B,OAAO,IAAI,CAAA;IACb,CAAC;IAED,OAAO,CACL,oBAAC,KAAK,IAAC,OAAO,EAAE,KAAK,KAAK,CAAC,MAAM,CAAC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AC,aAAa,EAAC,QAAQ;gBAC3D,oBAAC,UAAU,IAAC,MAAM,EAAE,CAAC,IAAG,KAAK,CAAC,OAAO,CAAc;gBACnD,oBAAC,cAAc,IAAC,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,OAAO,IACnD,SAAS,CAAC,KAAK,CAAC,YAAY,CAAC,CACf,CACX,CACF,CACT,CAAC,CACI,CACF,CACT,CAAA;AACH,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"AccountBalance.d.ts","sourceRoot":"","sources":["../../../../src/components/Dropdown/AccountBalance.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,KAAK,mBAAmB,GAAG;IACzB,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,KAAK,EAAE,mBAAmB,qBAwBhE"}
@@ -1,18 +0,0 @@
1
- import { Block, HeadingSmall, ParagraphSmall, useStyletron, } from "@mezo-org/mezo-clay";
2
- import React from "react";
3
- import { formatUsd } from "../../utils/currency";
4
- export default function AccountBalance(props) {
5
- const { amount } = props;
6
- const formattedUsdBalance = formatUsd(amount);
7
- const [, theme] = useStyletron();
8
- return (React.createElement(Block, { padding: theme.sizing.scale500, overrides: {
9
- Block: {
10
- style: {
11
- borderBottom: `1px solid ${theme.colors.backgroundPrimary}`,
12
- },
13
- },
14
- } },
15
- React.createElement(ParagraphSmall, { margin: 0, color: theme.colors.gray800 }, "Available balance"),
16
- React.createElement(HeadingSmall, { margin: 0 }, formattedUsdBalance)));
17
- }
18
- //# sourceMappingURL=AccountBalance.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AccountBalance.js","sourceRoot":"","sources":["../../../../src/components/Dropdown/AccountBalance.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,YAAY,EACZ,cAAc,EACd,YAAY,GACb,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAMhD,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,KAA0B;IAC/D,MAAM,EAAE,MAAM,EAAE,GAAG,KAAK,CAAA;IAExB,MAAM,mBAAmB,GAAG,SAAS,CAAC,MAAM,CAAC,CAAA;IAE7C,MAAM,CAAC,EAAE,KAAK,CAAC,GAAG,YAAY,EAAE,CAAA;IAEhC,OAAO,CACL,oBAAC,KAAK,IACJ,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,QAAQ,EAC9B,SAAS,EAAE;YACT,KAAK,EAAE;gBACL,KAAK,EAAE;oBACL,YAAY,EAAE,aAAa,KAAK,CAAC,MAAM,CAAC,iBAAiB,EAAE;iBAC5D;aACF;SACF;QAED,oBAAC,cAAc,IAAC,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,OAAO,wBAErC;QACjB,oBAAC,YAAY,IAAC,MAAM,EAAE,CAAC,IAAG,mBAAmB,CAAgB,CACvD,CACT,CAAA;AACH,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"WelcomeBlock.d.ts","sourceRoot":"","sources":["../../../../src/components/Dropdown/WelcomeBlock.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,MAAM,OAAO,CAAA;AAMzB,KAAK,iBAAiB,GAAG;IACvB,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,KAAK,EAAE,iBAAiB,qBAyE5D"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"WelcomeBlock.js","sourceRoot":"","sources":["../../../../src/components/Dropdown/WelcomeBlock.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,YAAY,EACZ,UAAU,EACV,IAAI,EACJ,YAAY,GACb,MAAM,qBAAqB,CAAA;AAC5B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K,IAAC,EAAE,EAAC,MAAM,IAAE,IAAI,CAAS;gBAC/B,oBAAC,KAAK,IAAC,EAAE,EAAC,MAAM,EAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,OAAO,IACzC,UAAU,CACL,CACK;YAEf,oBAAC,UAAU,IACT,OAAO,EAAC,MAAM,EACd,UAAU,EAAC,QAAQ,EACnB,MAAM,EAAE,CAAC,EACT,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,eAAe,EACnC,SAAS,EAAE;oBACT,KAAK,EAAE;wBACL,KAAK,EAAE;4BACL,GAAG,EAAE,KAAK,CAAC,MAAM,CAAC,QAAQ;yBAC3B;qBACF;iBACF;gBAED,oBAAC,IAAI,IACH,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,cAAc,EAClC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,QAAQ,GAC3B;gBACD,yBAAyB,CAAC,WAAW,EAAE,CAAC,CAAC,CAC/B,CACP,CACF,CACT,CAAA;AACH,CAAC"}
@@ -1,8 +0,0 @@
1
- import { UseBaseQueryOptions } from "@tanstack/react-query";
2
- type AssetsUsdConversion = {
3
- btcUsd: string;
4
- ethUsd: string;
5
- };
6
- export declare function useAssetsUsdConversion(useQueryOptions?: Partial<UseBaseQueryOptions<AssetsUsdConversion>>): import("@tanstack/react-query").UseQueryResult<AssetsUsdConversion, Error>;
7
- export {};
8
- //# sourceMappingURL=useAssetsUSDConversion.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useAssetsUSDConversion.d.ts","sourceRoot":"","sources":["../../../src/hooks/useAssetsUSDConversion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAY,MAAM,uBAAuB,CAAA;AAKrE,KAAK,mBAAmB,GAAG;IACzB,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED,wBAAgB,sBAAsB,CACpC,eAAe,GAAE,OAAO,CAAC,mBAAmB,CAAC,mBAAmB,CAAC,CAAM,8EAmBxE"}
@@ -1,21 +0,0 @@
1
- import { useQuery } from "@tanstack/react-query";
2
- import { ONE_MINUTE_MS } from "../utils/time";
3
- import { QUERY_KEYS } from "./constants";
4
- import { usePortalApiClient } from "./usePortalApiClient";
5
- export function useAssetsUsdConversion(useQueryOptions = {}) {
6
- const portalApiClient = usePortalApiClient();
7
- return useQuery({
8
- queryKey: [QUERY_KEYS.ASSETS_USD_CONVERSION],
9
- queryFn: async () => {
10
- const { currentUsdPerBtc, currentUsdPerEth } = await portalApiClient.getPortalStatistics();
11
- return {
12
- btcUsd: currentUsdPerBtc,
13
- ethUsd: currentUsdPerEth,
14
- };
15
- },
16
- staleTime: 30 * ONE_MINUTE_MS,
17
- retry: 1,
18
- ...useQueryOptions,
19
- });
20
- }
21
- //# sourceMappingURL=useAssetsUSDConversion.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useAssetsUSDConversion.js","sourceRoot":"","sources":["../../../src/hooks/useAssetsUSDConversion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAOzD,MAAM,UAAU,sBAAsB,CACpC,kBAAqE,EAAE;IAEvE,MAAM,eAAe,GAAG,kBAAkB,EAAE,CAAA;IAE5C,OAAO,QAAQ,CAAC;QACd,QAAQ,EAAE,CAAC,UAAU,CAAC,qBAAqB,CAAC;QAC5C,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,MAAM,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,GAC1C,MAAM,eAAe,CAAC,mBAAmB,EAAE,CAAA;YAE7C,OAAO;gBACL,MAAM,EAAE,gBAAgB;gBACxB,MAAM,EAAE,gBAAgB;aACzB,CAAA;QACH,CAAC;QACD,SAAS,EAAE,EAAE,GAAG,aAAa;QAC7B,KAAK,EAAE,CAAC;QACR,GAAG,eAAe;KACnB,CAAC,CAAA;AACJ,CAAC"}
@@ -1,111 +0,0 @@
1
- import {
2
- Block,
3
- Copy03 as CopyIcon,
4
- LinkExternal02 as LinkIcon,
5
- ParagraphSmall,
6
- useStyletron,
7
- } from "@mezo-org/mezo-clay"
8
- import React from "react"
9
- import { useCopyToClipboard } from "usehooks-ts"
10
- import { usePassportContext } from "../../hooks/usePassportContext"
11
- import { getAddressExplorerUrl, trimAddress } from "../../utils/address"
12
- import { getCryptoAsset } from "../../utils/cryptoAssets"
13
-
14
- type AccountAddressProps = {
15
- address: string
16
- type: "bitcoin" | "evm"
17
- }
18
-
19
- // TODO: Add visual feedback on copy
20
-
21
- export default function AccountAddress(props: AccountAddressProps) {
22
- const { address, type } = props
23
-
24
- const { environment } = usePassportContext()
25
- const blockExplorerUrl = getAddressExplorerUrl(
26
- address,
27
- type,
28
- environment === "testnet",
29
- )
30
- const trimmedAddress = trimAddress(address)
31
- const { icon: accountIcon } = getCryptoAsset(
32
- type === "bitcoin" ? "btc" : "eth",
33
- )
34
-
35
- const [, theme] = useStyletron()
36
-
37
- const [, copy] = useCopyToClipboard()
38
-
39
- return (
40
- <Block
41
- as="button"
42
- onClick={() => copy(address)}
43
- display="flex"
44
- alignItems="center"
45
- backgroundColor="transparent"
46
- padding={`${theme.sizing.scale600} ${theme.sizing.scale500}`}
47
- overrides={{
48
- Block: {
49
- style: {
50
- borderWidth: 0,
51
- cursor: "pointer",
52
- ":hover": {
53
- backgroundColor: theme.colors.backgroundTertiary,
54
- },
55
- },
56
- },
57
- }}
58
- >
59
- <Block as={accountIcon} size={theme.sizing.scale600} />
60
- <Block
61
- as="a"
62
- marginLeft={theme.sizing.scale300}
63
- href={blockExplorerUrl}
64
- target="_blank"
65
- overrides={{
66
- Block: {
67
- style: {
68
- color: "inherit",
69
- textDecoration: "none",
70
- ":hover": {
71
- textDecoration: "underline",
72
- },
73
- },
74
- },
75
- }}
76
- >
77
- <ParagraphSmall
78
- display="flex"
79
- alignItems="center"
80
- margin={0}
81
- color={theme.colors.gray800}
82
- >
83
- {trimmedAddress}
84
- <LinkIcon
85
- display="inline"
86
- size={theme.sizing.scale550}
87
- overrides={{
88
- Svg: {
89
- style: {
90
- stroke: "currentColor",
91
- marginLeft: theme.sizing.scale200,
92
- },
93
- },
94
- }}
95
- />
96
- </ParagraphSmall>
97
- </Block>
98
- <CopyIcon
99
- size={theme.sizing.scale550}
100
- overrides={{
101
- Svg: {
102
- style: {
103
- marginLeft: "auto",
104
- stroke: "currentColor",
105
- },
106
- },
107
- }}
108
- />
109
- </Block>
110
- )
111
- }