@mezo-org/passport 0.4.0-dev.5 → 0.4.0-dev.7

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 (223) hide show
  1. package/dist/src/api/auth.d.ts +36 -59
  2. package/dist/src/api/auth.d.ts.map +1 -1
  3. package/dist/src/api/auth.js +21 -49
  4. package/dist/src/api/auth.js.map +1 -1
  5. package/dist/src/api/client.d.ts +24 -0
  6. package/dist/src/api/client.d.ts.map +1 -0
  7. package/dist/src/api/client.js +54 -0
  8. package/dist/src/api/client.js.map +1 -0
  9. package/dist/src/api/fetch-error.d.ts +5 -0
  10. package/dist/src/api/fetch-error.d.ts.map +1 -0
  11. package/dist/src/api/fetch-error.js +8 -0
  12. package/dist/src/api/fetch-error.js.map +1 -0
  13. package/dist/src/api/index.d.ts +3 -0
  14. package/dist/src/api/index.d.ts.map +1 -0
  15. package/dist/src/api/index.js +3 -0
  16. package/dist/src/api/index.js.map +1 -0
  17. package/dist/src/api/portal.d.ts +32 -0
  18. package/dist/src/api/portal.d.ts.map +1 -0
  19. package/dist/src/api/portal.js +23 -0
  20. package/dist/src/api/portal.js.map +1 -0
  21. package/dist/src/assets/DefaultAvatar.d.ts +5 -0
  22. package/dist/src/assets/DefaultAvatar.d.ts.map +1 -0
  23. package/dist/src/assets/DefaultAvatar.js +21 -0
  24. package/dist/src/assets/DefaultAvatar.js.map +1 -0
  25. package/dist/src/components/Dropdown/AccountAddress.d.ts +8 -0
  26. package/dist/src/components/Dropdown/AccountAddress.d.ts.map +1 -0
  27. package/dist/src/components/Dropdown/AccountAddress.js +58 -0
  28. package/dist/src/components/Dropdown/AccountAddress.js.map +1 -0
  29. package/dist/src/components/Dropdown/AccountAssets.d.ts +14 -0
  30. package/dist/src/components/Dropdown/AccountAssets.d.ts.map +1 -0
  31. package/dist/src/components/Dropdown/AccountAssets.js +44 -0
  32. package/dist/src/components/Dropdown/AccountAssets.js.map +1 -0
  33. package/dist/src/components/Dropdown/AccountBalance.d.ts +7 -0
  34. package/dist/src/components/Dropdown/AccountBalance.d.ts.map +1 -0
  35. package/dist/src/components/Dropdown/AccountBalance.js +18 -0
  36. package/dist/src/components/Dropdown/AccountBalance.js.map +1 -0
  37. package/dist/src/components/Dropdown/ConnectedTrigger.d.ts +7 -0
  38. package/dist/src/components/Dropdown/ConnectedTrigger.d.ts.map +1 -0
  39. package/dist/src/components/Dropdown/ConnectedTrigger.js +30 -0
  40. package/dist/src/components/Dropdown/ConnectedTrigger.js.map +1 -0
  41. package/dist/src/components/Dropdown/Content.d.ts +9 -0
  42. package/dist/src/components/Dropdown/Content.d.ts.map +1 -0
  43. package/dist/src/components/Dropdown/Content.js +69 -0
  44. package/dist/src/components/Dropdown/Content.js.map +1 -0
  45. package/dist/src/components/Dropdown/DisconnectedTrigger.d.ts +7 -0
  46. package/dist/src/components/Dropdown/DisconnectedTrigger.d.ts.map +1 -0
  47. package/dist/src/components/Dropdown/DisconnectedTrigger.js +13 -0
  48. package/dist/src/components/Dropdown/DisconnectedTrigger.js.map +1 -0
  49. package/dist/src/components/Dropdown/Dropdown.d.ts +20 -0
  50. package/dist/src/components/Dropdown/Dropdown.d.ts.map +1 -0
  51. package/dist/src/components/Dropdown/Dropdown.js +45 -0
  52. package/dist/src/components/Dropdown/Dropdown.js.map +1 -0
  53. package/dist/src/components/Dropdown/WelcomeBlock.d.ts +8 -0
  54. package/dist/src/components/Dropdown/WelcomeBlock.d.ts.map +1 -0
  55. package/dist/src/components/Dropdown/WelcomeBlock.js +44 -0
  56. package/dist/src/components/Dropdown/WelcomeBlock.js.map +1 -0
  57. package/dist/src/components/Dropdown/index.d.ts +3 -0
  58. package/dist/src/components/Dropdown/index.d.ts.map +1 -0
  59. package/dist/src/components/Dropdown/index.js +2 -0
  60. package/dist/src/components/Dropdown/index.js.map +1 -0
  61. package/dist/src/components/index.d.ts +2 -0
  62. package/dist/src/components/index.d.ts.map +1 -0
  63. package/dist/src/components/index.js +2 -0
  64. package/dist/src/components/index.js.map +1 -0
  65. package/dist/src/hooks/constants.d.ts +1 -0
  66. package/dist/src/hooks/constants.d.ts.map +1 -1
  67. package/dist/src/hooks/constants.js +1 -0
  68. package/dist/src/hooks/constants.js.map +1 -1
  69. package/dist/src/hooks/index.d.ts +0 -1
  70. package/dist/src/hooks/index.d.ts.map +1 -1
  71. package/dist/src/hooks/index.js +0 -1
  72. package/dist/src/hooks/index.js.map +1 -1
  73. package/dist/src/hooks/useAssetsUSDConversion.d.ts +8 -0
  74. package/dist/src/hooks/useAssetsUSDConversion.d.ts.map +1 -0
  75. package/dist/src/hooks/useAssetsUSDConversion.js +21 -0
  76. package/dist/src/hooks/useAssetsUSDConversion.js.map +1 -0
  77. package/dist/src/hooks/useAuthApiClient.d.ts +1 -1
  78. package/dist/src/hooks/useAuthApiClient.d.ts.map +1 -1
  79. package/dist/src/hooks/useAuthenticateWithWallet.d.ts +12 -102
  80. package/dist/src/hooks/useAuthenticateWithWallet.d.ts.map +1 -1
  81. package/dist/src/hooks/useAuthenticateWithWallet.js +23 -11
  82. package/dist/src/hooks/useAuthenticateWithWallet.js.map +1 -1
  83. package/dist/src/hooks/useCreateAccount.d.ts +23 -173
  84. package/dist/src/hooks/useCreateAccount.d.ts.map +1 -1
  85. package/dist/src/hooks/useCreateAccount.js +7 -4
  86. package/dist/src/hooks/useCreateAccount.js.map +1 -1
  87. package/dist/src/hooks/useCreateSession.d.ts +12 -101
  88. package/dist/src/hooks/useCreateSession.d.ts.map +1 -1
  89. package/dist/src/hooks/useCreateSession.js +10 -8
  90. package/dist/src/hooks/useCreateSession.js.map +1 -1
  91. package/dist/src/hooks/useDropdownData.d.ts +44 -0
  92. package/dist/src/hooks/useDropdownData.d.ts.map +1 -0
  93. package/dist/src/hooks/useDropdownData.js +73 -0
  94. package/dist/src/hooks/useDropdownData.js.map +1 -0
  95. package/dist/src/hooks/useGetAccountByAddress.d.ts +2 -2
  96. package/dist/src/hooks/useGetAccountByAddress.d.ts.map +1 -1
  97. package/dist/src/hooks/useGetAccountByMezoId.d.ts +2 -2
  98. package/dist/src/hooks/useGetAccountByMezoId.d.ts.map +1 -1
  99. package/dist/src/hooks/useGetCurrentAccount.d.ts +16 -2
  100. package/dist/src/hooks/useGetCurrentAccount.d.ts.map +1 -1
  101. package/dist/src/hooks/useGetCurrentAccount.js +25 -3
  102. package/dist/src/hooks/useGetCurrentAccount.js.map +1 -1
  103. package/dist/src/hooks/useGetSession.d.ts +1 -1
  104. package/dist/src/hooks/useGetSession.d.ts.map +1 -1
  105. package/dist/src/hooks/useLinkAccount.d.ts +15 -175
  106. package/dist/src/hooks/useLinkAccount.d.ts.map +1 -1
  107. package/dist/src/hooks/useLinkAccount.js +7 -4
  108. package/dist/src/hooks/useLinkAccount.js.map +1 -1
  109. package/dist/src/hooks/usePortalApiClient.d.ts +2 -0
  110. package/dist/src/hooks/usePortalApiClient.d.ts.map +1 -0
  111. package/dist/src/hooks/usePortalApiClient.js +6 -0
  112. package/dist/src/hooks/usePortalApiClient.js.map +1 -0
  113. package/dist/src/hooks/useSignInWithDiscord.d.ts +12 -100
  114. package/dist/src/hooks/useSignInWithDiscord.d.ts.map +1 -1
  115. package/dist/src/hooks/useSignInWithDiscord.js +6 -3
  116. package/dist/src/hooks/useSignInWithDiscord.js.map +1 -1
  117. package/dist/src/hooks/useSignInWithWallet.d.ts +12 -100
  118. package/dist/src/hooks/useSignInWithWallet.d.ts.map +1 -1
  119. package/dist/src/hooks/useSignInWithWallet.js +2 -2
  120. package/dist/src/hooks/useSignInWithWallet.js.map +1 -1
  121. package/dist/src/hooks/useSignOut.d.ts +12 -28
  122. package/dist/src/hooks/useSignOut.d.ts.map +1 -1
  123. package/dist/src/hooks/useSignOut.js +7 -4
  124. package/dist/src/hooks/useSignOut.js.map +1 -1
  125. package/dist/src/hooks/useSignUpWithWallet.d.ts +12 -100
  126. package/dist/src/hooks/useSignUpWithWallet.d.ts.map +1 -1
  127. package/dist/src/hooks/useSignUpWithWallet.js +2 -2
  128. package/dist/src/hooks/useSignUpWithWallet.js.map +1 -1
  129. package/dist/src/hooks/useUpdateMezoId.d.ts +30 -136
  130. package/dist/src/hooks/useUpdateMezoId.d.ts.map +1 -1
  131. package/dist/src/hooks/useUpdateMezoId.js +7 -4
  132. package/dist/src/hooks/useUpdateMezoId.js.map +1 -1
  133. package/dist/src/hooks/useWalletAccount.d.ts +12 -0
  134. package/dist/src/hooks/useWalletAccount.d.ts.map +1 -0
  135. package/dist/src/hooks/useWalletAccount.js +25 -0
  136. package/dist/src/hooks/useWalletAccount.js.map +1 -0
  137. package/dist/src/index.d.ts +1 -0
  138. package/dist/src/index.d.ts.map +1 -1
  139. package/dist/src/index.js +1 -0
  140. package/dist/src/index.js.map +1 -1
  141. package/dist/src/provider.d.ts +10 -13
  142. package/dist/src/provider.d.ts.map +1 -1
  143. package/dist/src/provider.js +11 -20
  144. package/dist/src/provider.js.map +1 -1
  145. package/dist/src/utils/address.d.ts +15 -0
  146. package/dist/src/utils/address.d.ts.map +1 -0
  147. package/dist/src/utils/address.js +35 -0
  148. package/dist/src/utils/address.js.map +1 -0
  149. package/dist/src/utils/address.test.d.ts +2 -0
  150. package/dist/src/utils/address.test.d.ts.map +1 -0
  151. package/dist/src/utils/address.test.js +37 -0
  152. package/dist/src/utils/address.test.js.map +1 -0
  153. package/dist/src/utils/cryptoAssets.d.ts +28 -0
  154. package/dist/src/utils/cryptoAssets.d.ts.map +1 -0
  155. package/dist/src/utils/cryptoAssets.js +73 -0
  156. package/dist/src/utils/cryptoAssets.js.map +1 -0
  157. package/dist/src/utils/cryptoAssets.test.d.ts +2 -0
  158. package/dist/src/utils/cryptoAssets.test.d.ts.map +1 -0
  159. package/dist/src/utils/cryptoAssets.test.js +49 -0
  160. package/dist/src/utils/cryptoAssets.test.js.map +1 -0
  161. package/dist/src/utils/currency.d.ts +14 -0
  162. package/dist/src/utils/currency.d.ts.map +1 -0
  163. package/dist/src/utils/currency.js +27 -0
  164. package/dist/src/utils/currency.js.map +1 -0
  165. package/dist/src/utils/currency.test.d.ts +2 -0
  166. package/dist/src/utils/currency.test.d.ts.map +1 -0
  167. package/dist/src/utils/currency.test.js +34 -0
  168. package/dist/src/utils/currency.test.js.map +1 -0
  169. package/dist/src/utils/numbers.d.ts +43 -0
  170. package/dist/src/utils/numbers.d.ts.map +1 -0
  171. package/dist/src/utils/numbers.js +81 -0
  172. package/dist/src/utils/numbers.js.map +1 -0
  173. package/dist/src/utils/numbers.test.d.ts +2 -0
  174. package/dist/src/utils/numbers.test.d.ts.map +1 -0
  175. package/dist/src/utils/numbers.test.js +68 -0
  176. package/dist/src/utils/numbers.test.js.map +1 -0
  177. package/package.json +8 -2
  178. package/src/api/auth.ts +72 -129
  179. package/src/api/client.ts +78 -0
  180. package/src/api/fetch-error.ts +8 -0
  181. package/src/api/index.ts +2 -0
  182. package/src/api/portal.ts +56 -0
  183. package/src/assets/DefaultAvatar.tsx +74 -0
  184. package/src/components/Dropdown/AccountAddress.tsx +111 -0
  185. package/src/components/Dropdown/AccountAssets.tsx +110 -0
  186. package/src/components/Dropdown/AccountBalance.tsx +38 -0
  187. package/src/components/Dropdown/ConnectedTrigger.tsx +56 -0
  188. package/src/components/Dropdown/Content.tsx +148 -0
  189. package/src/components/Dropdown/DisconnectedTrigger.tsx +35 -0
  190. package/src/components/Dropdown/Dropdown.tsx +88 -0
  191. package/src/components/Dropdown/README.md +49 -0
  192. package/src/components/Dropdown/WelcomeBlock.tsx +92 -0
  193. package/src/components/Dropdown/index.ts +2 -0
  194. package/src/components/index.ts +1 -0
  195. package/src/hooks/constants.ts +1 -0
  196. package/src/hooks/index.ts +0 -1
  197. package/src/hooks/useAssetsUSDConversion.ts +31 -0
  198. package/src/hooks/useAuthenticateWithWallet.ts +38 -14
  199. package/src/hooks/useCreateAccount.ts +19 -5
  200. package/src/hooks/useCreateSession.ts +22 -9
  201. package/src/hooks/useDropdownData.ts +130 -0
  202. package/src/hooks/useGetAccountByAddress.ts +2 -2
  203. package/src/hooks/useGetAccountByMezoId.ts +2 -2
  204. package/src/hooks/useGetCurrentAccount.ts +46 -6
  205. package/src/hooks/useGetSession.ts +1 -1
  206. package/src/hooks/useLinkAccount.ts +18 -5
  207. package/src/hooks/usePortalApiClient.ts +6 -0
  208. package/src/hooks/useSignInWithDiscord.ts +14 -5
  209. package/src/hooks/useSignInWithWallet.ts +9 -2
  210. package/src/hooks/useSignOut.ts +18 -4
  211. package/src/hooks/useSignUpWithWallet.ts +9 -2
  212. package/src/hooks/useUpdateMezoId.ts +19 -4
  213. package/src/hooks/useWalletAccount.ts +41 -0
  214. package/src/index.ts +1 -0
  215. package/src/provider.ts +30 -37
  216. package/src/utils/address.test.ts +44 -0
  217. package/src/utils/address.ts +43 -0
  218. package/src/utils/cryptoAssets.test.ts +59 -0
  219. package/src/utils/cryptoAssets.ts +93 -0
  220. package/src/utils/currency.test.ts +38 -0
  221. package/src/utils/currency.ts +32 -0
  222. package/src/utils/numbers.test.ts +89 -0
  223. package/src/utils/numbers.ts +110 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cryptoAssets.test.d.ts","sourceRoot":"","sources":["../../../src/utils/cryptoAssets.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,49 @@
1
+ import { BitcoinCircle, EthCircle, MUsdCircle, TBtcCircle, } from "@mezo-org/mezo-clay";
2
+ import { getCryptoAsset } from "./cryptoAssets";
3
+ describe("getCryptoAsset", () => {
4
+ it("returns the correct asset for 'btc'", () => {
5
+ const asset = getCryptoAsset("btc");
6
+ expect(asset.name).toBe("Bitcoin");
7
+ expect(asset.symbol).toBe("BTC");
8
+ expect(asset.decimals).toBe(8);
9
+ expect(asset.icon).toBe(BitcoinCircle);
10
+ });
11
+ it("returns the correct asset for 'eth'", () => {
12
+ const asset = getCryptoAsset("eth");
13
+ expect(asset.name).toBe("Ethereum");
14
+ expect(asset.symbol).toBe("ETH");
15
+ expect(asset.decimals).toBe(18);
16
+ expect(asset.icon).toBe(EthCircle);
17
+ });
18
+ it("returns the correct asset for 'tbtc'", () => {
19
+ const asset = getCryptoAsset("tbtc");
20
+ expect(asset.name).toBe("Threshold Bitcoin");
21
+ expect(asset.symbol).toBe("tBTC");
22
+ expect(asset.decimals).toBe(18);
23
+ expect(asset.icon).toBe(TBtcCircle);
24
+ });
25
+ it("returns the correct asset for 'wbtc'", () => {
26
+ const asset = getCryptoAsset("wbtc");
27
+ expect(asset.name).toBe("Wrapped Bitcoin");
28
+ expect(asset.symbol).toBe("wBTC");
29
+ expect(asset.decimals).toBe(8);
30
+ // FIXME: Test should expect the exact icon component
31
+ expect(asset.icon).toEqual(expect.any(Function));
32
+ });
33
+ it("returns the correct asset for 'mbtc'", () => {
34
+ const asset = getCryptoAsset("mbtc");
35
+ expect(asset.name).toBe("Matsnet Bitcoin");
36
+ expect(asset.symbol).toBe("BTC");
37
+ expect(asset.decimals).toBe(18);
38
+ // FIXME: Test should expect the exact icon component
39
+ expect(asset.icon).toEqual(expect.any(Function));
40
+ });
41
+ it("returns the correct asset for 'musd'", () => {
42
+ const asset = getCryptoAsset("musd");
43
+ expect(asset.name).toBe("Mezo USD");
44
+ expect(asset.symbol).toBe("mUSD");
45
+ expect(asset.decimals).toBe(18);
46
+ expect(asset.icon).toBe(MUsdCircle);
47
+ });
48
+ });
49
+ //# sourceMappingURL=cryptoAssets.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cryptoAssets.test.js","sourceRoot":"","sources":["../../../src/utils/cryptoAssets.test.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,SAAS,EACT,UAAU,EACV,UAAU,GACX,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAE/C,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,EAAE,CAAC,qCAAqC,EAAE,GAAG,EAAE;QAC7C,MAAM,KAAK,GAAG,cAAc,CAAC,KAAK,CAAC,CAAA;QACnC,MAAM,CAAC,KAAK,CA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,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QAC/B,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;IACrC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Formats a number as a currency
3
+ * @param value The value to format
4
+ * @param options The options to pass to the formatter
5
+ * @returns The formatted currency
6
+ */
7
+ export declare function formatCurrency(value: number, options?: Omit<Intl.NumberFormatOptions, "style">): string;
8
+ /**
9
+ * Formats a number as a USD currency
10
+ * @param value The value to format
11
+ * @returns The formatted currency
12
+ */
13
+ export declare function formatUsd(value: number): string;
14
+ //# sourceMappingURL=currency.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"currency.d.ts","sourceRoot":"","sources":["../../../src/utils/currency.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,IAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE,OAAO,CAAM,GACpD,MAAM,CAOR;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE/C"}
@@ -0,0 +1,27 @@
1
+ const DEFAULT_FORMAT_OPTIONS = {
2
+ style: "currency",
3
+ minimumFractionDigits: 2,
4
+ maximumFractionDigits: 2,
5
+ };
6
+ /**
7
+ * Formats a number as a currency
8
+ * @param value The value to format
9
+ * @param options The options to pass to the formatter
10
+ * @returns The formatted currency
11
+ */
12
+ export function formatCurrency(value, options = {}) {
13
+ const formatter = new Intl.NumberFormat("en-US", {
14
+ ...DEFAULT_FORMAT_OPTIONS,
15
+ ...options,
16
+ });
17
+ return formatter.format(value);
18
+ }
19
+ /**
20
+ * Formats a number as a USD currency
21
+ * @param value The value to format
22
+ * @returns The formatted currency
23
+ */
24
+ export function formatUsd(value) {
25
+ return formatCurrency(value, { currency: "USD" });
26
+ }
27
+ //# sourceMappingURL=currency.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"currency.js","sourceRoot":"","sources":["../../../src/utils/currency.ts"],"names":[],"mappings":"AAAA,MAAM,sBAAsB,GAA6B;IACvD,KAAK,EAAE,UAAU;IACjB,qBAAqB,EAAE,CAAC;IACxB,qBAAqB,EAAE,CAAC;CACzB,CAAA;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAC5B,KAAa,EACb,UAAmD,EAAE;IAErD,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE;QAC/C,GAAG,sBAAsB;QACzB,GAAG,OAAO;KACX,CAAC,CAAA;IAEF,OAAO,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAChC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,KAAa;IACrC,OAAO,cAAc,CAAC,KAAK,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAA;AACnD,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=currency.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"currency.test.d.ts","sourceRoot":"","sources":["../../../src/utils/currency.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,34 @@
1
+ import { formatCurrency, formatUsd } from "./currency";
2
+ describe("formatCurrency", () => {
3
+ it("formats a number as currency with default options", () => {
4
+ const result = formatCurrency(1234.5, { currency: "EUR" });
5
+ expect(result).toBe("€1,234.50");
6
+ });
7
+ it("respects minimumFractionDigits (min = 3, max = 3)", () => {
8
+ const result = formatCurrency(1.2, {
9
+ currency: "USD",
10
+ minimumFractionDigits: 3,
11
+ maximumFractionDigits: 3,
12
+ });
13
+ expect(result).toBe("$1.200");
14
+ });
15
+ it("respects maximumFractionDigits (min = 0, max = 1)", () => {
16
+ const result = formatCurrency(1.234567, {
17
+ currency: "USD",
18
+ minimumFractionDigits: 0,
19
+ maximumFractionDigits: 1,
20
+ });
21
+ expect(result).toBe("$1.2");
22
+ });
23
+ });
24
+ describe("formatUsd", () => {
25
+ it("formats a number as USD", () => {
26
+ const result = formatUsd(99.99);
27
+ expect(result).toBe("$99.99");
28
+ });
29
+ it("formats zero", () => {
30
+ const result = formatUsd(0);
31
+ expect(result).toBe("$0.00");
32
+ });
33
+ });
34
+ //# sourceMappingURL=currency.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"currency.test.js","sourceRoot":"","sources":["../../../src/utils/currency.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAEtD,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,EAAE,CAAC,mDAAmD,EAAE,GAAG,EAAE;QAC3D,MAAM,MAAM,GAAG,cAAc,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAA;QAC1D,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;IAClC,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,mDAAmD,EAAE,GAAG,EAAE;QAC3D,MAAM,MAAM,GAAG,cAAc,CAAC,GAAG,EAAE;YACjC,QAAQ,EAAE,KAAK;YACf,qBAAqB,EAAE,CAAC;YACxB,qBAAqB,EAAE,CAAC;SACzB,CAAC,CAAA;QACF,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAC/B,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,mDAAmD,EAAE,GAAG,EAAE;QAC3D,MAAM,MAAM,GAAG,cAAc,CAAC,QAAQ,EAAE;YACtC,QAAQ,EAAE,KAAK;YACf,qBAAqB,EAAE,CAAC;YACxB,qBAAqB,EAAE,CAAC;SACzB,CAAC,CAAA;QACF,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAC7B,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA;AAEF,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,EAAE,CAAC,yBAAyB,EAAE,GAAG,EAAE;QACjC,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,CAAA;QAC/B,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAC/B,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,cAAc,EAAE,GAAG,EAAE;QACtB,MAAM,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,CAAA;QAC3B,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAC9B,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Formats a number or bigint into a human-readable string with K, M, B, or T suffix.
3
+ * @param value The number or bigint to format.
4
+ * @param decimals Number of decimal places to include (ignored for bigint to avoid floating point issues).
5
+ * @returns The formatted number as a string.
6
+ */
7
+ export declare function formatHumanReadableNumber(value: number | bigint, decimals?: number): string;
8
+ /**
9
+ * Returns a number rounded up to the desired number of decimals.
10
+ * @param amount The number to round up.
11
+ * @param desiredDecimals The number of decimals to round up to.
12
+ * @returns The rounded up number.
13
+ * @see https://github.com/thesis/acre/blob/main/dapp/src/utils/numbersUtils.ts#L1-L3
14
+ */
15
+ export declare function roundUpNumber(amount: number, desiredDecimals?: number): number;
16
+ /**
17
+ * Convert a fixed point bigint with precision `fixedPointDecimals` to a
18
+ * floating point number truncated to `desiredDecimals`.
19
+ * @param fixedPoint The fixed point bigint to convert.
20
+ * @param fixedPointDecimals The number of decimals in the fixed point bigint.
21
+ * @param desiredDecimals The number of decimals in the output number.
22
+ * @returns The floating point number truncated to `desiredDecimals`.
23
+ * @see https://github.com/tahowallet/extension/blob/main/background/lib/fixed-point.ts#L216-L239
24
+ */
25
+ export declare function fromFixedPoint(fixedPoint: bigint, fixedPointDecimals: number, desiredDecimals?: number): number;
26
+ /**
27
+ * Display a cryptoAsset amount correctly with desired decimals.
28
+ * The function returns a string with a language-sensitive representation of this number.
29
+ * - If the amount entered is zero, return the result with the desired decimals.
30
+ * For example, 0.00 for a precision of 2.
31
+ * - If `formattedAmount` is less than the minimum amount to display
32
+ * for the specified precision return information about this.
33
+ * For example, <0.01 for a precision of 2.
34
+ * - Other amounts are formatted according to the use of the `bigIntToUserAmount` function.
35
+ * @param amount The amount of tokens to format.
36
+ * @param decimals The number of decimals the cryptoAsset has.
37
+ * @param desiredDecimals The number of decimals to display.
38
+ * @param withRoundUp If true, the amount will be rounded up.
39
+ * @returns The formatted cryptoAsset amount.
40
+ * @see https://github.com/thesis/acre/blob/main/dapp/src/utils/numbersUtils.ts#L57-L87
41
+ */
42
+ export declare function formatTokenAmount(amount: number | string | bigint, decimals?: number, desiredDecimals?: number, withRoundUp?: boolean): string;
43
+ //# sourceMappingURL=numbers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"numbers.d.ts","sourceRoot":"","sources":["../../../src/utils/numbers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,QAAQ,GAAE,MAAU,GACnB,MAAM,CAgBR;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,SAAI,GAAG,MAAM,CAEzE;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,UAAU,EAAE,MAAM,EAClB,kBAAkB,EAAE,MAAM,EAC1B,eAAe,SAAI,GAClB,MAAM,CAUR;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAChC,QAAQ,SAAK,EACb,eAAe,SAAI,EACnB,WAAW,UAAQ,UA0BpB"}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Formats a number or bigint into a human-readable string with K, M, B, or T suffix.
3
+ * @param value The number or bigint to format.
4
+ * @param decimals Number of decimal places to include (ignored for bigint to avoid floating point issues).
5
+ * @returns The formatted number as a string.
6
+ */
7
+ export 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;
46
+ }
47
+ /**
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
62
+ */
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)}`;
67
+ }
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`;
75
+ }
76
+ const finalFormattedAmount = withRoundUp
77
+ ? roundUpNumber(formattedAmount, desiredDecimals)
78
+ : formattedAmount;
79
+ return formatHumanReadableNumber(finalFormattedAmount, desiredDecimals);
80
+ }
81
+ //# sourceMappingURL=numbers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"numbers.js","sourceRoot":"","sources":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ACjD,CAAC;IAED,MAAM,oBAAoB,GAAG,WAAW;QACtC,CAAC,CAAC,aAAa,CAAC,eAAe,EAAE,eAAe,CAAC;QACjD,CAAC,CAAC,eAAe,CAAA;IACnB,OAAO,yBAAyB,CAAC,oBAAoB,EAAE,eAAe,CAAC,CAAA;AACzE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=numbers.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"numbers.test.d.ts","sourceRoot":"","sources":["../../../src/utils/numbers.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,68 @@
1
+ import { formatHumanReadableNumber, formatTokenAmount, fromFixedPoint, roundUpNumber, } from "./numbers";
2
+ describe("formatHumanReadableNumber", () => {
3
+ it("formats number less than 1000 with decimals", () => {
4
+ expect(formatHumanReadableNumber(123.456789, 2)).toBe("123.46");
5
+ });
6
+ it("formats thousands with K", () => {
7
+ expect(formatHumanReadableNumber(12_345, 2)).toBe("12.35K");
8
+ });
9
+ it("formats millions with M", () => {
10
+ expect(formatHumanReadableNumber(12_345_678, 2)).toBe("12.35M");
11
+ });
12
+ it("formats billions with B", () => {
13
+ expect(formatHumanReadableNumber(12_345_678_901, 2)).toBe("12.35B");
14
+ });
15
+ it("formats trillions with T", () => {
16
+ expect(formatHumanReadableNumber(12_345_678_901_234, 2)).toBe("12.35T");
17
+ });
18
+ it("formats bigint as readable number", () => {
19
+ expect(formatHumanReadableNumber(1234567890123456789n, 2)).toBe("> 1000T");
20
+ });
21
+ it("caps at > 1000T for huge numbers", () => {
22
+ const hugeNumber = 10 ** 18; // 1e18
23
+ expect(formatHumanReadableNumber(hugeNumber, 2)).toBe("> 1000T");
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);
35
+ });
36
+ });
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);
41
+ });
42
+ it("converts with truncation to 2 decimals", () => {
43
+ const raw = 987654321000000000n; // ~0.987654321 ETH
44
+ expect(fromFixedPoint(raw, 18, 2)).toBe(0.98);
45
+ });
46
+ it("handles large fixedPoint decimals", () => {
47
+ const raw = 1000000000000000000000000n; // 1M with 6 decimals
48
+ expect(fromFixedPoint(raw, 6, 2)).toBe(1000000000000000000);
49
+ });
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");
55
+ });
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
58
+ });
59
+ it("formats a normal value without rounding", () => {
60
+ const result = formatTokenAmount("1230000000000000000", 18, 2);
61
+ expect(result).toBe("1.23");
62
+ });
63
+ it("formats with rounding if withRoundUp = true", () => {
64
+ const result = formatTokenAmount("1234560000000000000", 18, 2, true);
65
+ expect(result).toBe("1.24");
66
+ });
67
+ });
68
+ //# sourceMappingURL=numbers.test.js.map
@@ -0,0 +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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": {
7
7
  "build": "tsc",
8
+ "dev": "tsc --watch",
8
9
  "format": "npm run lint:js && npm run lint:config",
9
10
  "format:fix": "npm run lint:js:fix && npm run lint:config:fix",
10
11
  "lint:js": "eslint .",
@@ -23,19 +24,22 @@
23
24
  "directory": "typescript/passport"
24
25
  },
25
26
  "devDependencies": {
26
- "@babel/preset-env": "^7.23.7",
27
27
  "@thesis-co/eslint-config": "github:thesis/eslint-config#7b9bc8c",
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",
31
33
  "eslint": "^8.57.1",
32
34
  "jest": "^29.7.0",
35
+ "jest-environment-jsdom": "^29.7.0",
33
36
  "prettier": "^3.2.5",
34
37
  "ts-jest": "^29.1.2",
35
38
  "ts-node": "^10.9.2",
36
39
  "typescript": "^5.4.3"
37
40
  },
38
41
  "dependencies": {
42
+ "@mezo-org/mezo-clay": "0.1.0-dev.18",
39
43
  "@mezo-org/orangekit": "1.0.0-beta.40-dev.0",
40
44
  "@mezo-org/sign-in-with-wallet": "1.0.0-beta.8"
41
45
  },
@@ -43,6 +47,8 @@
43
47
  "@rainbow-me/rainbowkit": "2.0.2",
44
48
  "@tanstack/react-query": "^5.28.4",
45
49
  "react": "^18.2.0",
50
+ "styletron-engine-monolithic": "^1.0.0",
51
+ "usehooks-ts": "^3.1.1",
46
52
  "viem": "2.22.8",
47
53
  "wagmi": "2.5.12"
48
54
  }