@mezo-org/passport 0.4.0-dev.0 → 0.4.0-dev.10

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 (252) hide show
  1. package/dist/src/api/auth.d.ts +78 -0
  2. package/dist/src/api/auth.d.ts.map +1 -0
  3. package/dist/src/api/auth.js +77 -0
  4. package/dist/src/api/auth.js.map +1 -0
  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 +66 -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 +64 -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 +7 -0
  66. package/dist/src/hooks/constants.d.ts.map +1 -0
  67. package/dist/src/hooks/constants.js +7 -0
  68. package/dist/src/hooks/constants.js.map +1 -0
  69. package/dist/src/hooks/index.d.ts +10 -0
  70. package/dist/src/hooks/index.d.ts.map +1 -1
  71. package/dist/src/hooks/index.js +10 -0
  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 +2 -0
  78. package/dist/src/hooks/useAuthApiClient.d.ts.map +1 -0
  79. package/dist/src/hooks/useAuthApiClient.js +6 -0
  80. package/dist/src/hooks/useAuthApiClient.js.map +1 -0
  81. package/dist/src/hooks/useAuthenticateWithWallet.d.ts +73 -0
  82. package/dist/src/hooks/useAuthenticateWithWallet.d.ts.map +1 -0
  83. package/dist/src/hooks/useAuthenticateWithWallet.js +69 -0
  84. package/dist/src/hooks/useAuthenticateWithWallet.js.map +1 -0
  85. package/dist/src/hooks/useCreateAccount.d.ts +108 -0
  86. package/dist/src/hooks/useCreateAccount.d.ts.map +1 -0
  87. package/dist/src/hooks/useCreateAccount.js +21 -0
  88. package/dist/src/hooks/useCreateAccount.js.map +1 -0
  89. package/dist/src/hooks/useCreateSession.d.ts +76 -0
  90. package/dist/src/hooks/useCreateSession.d.ts.map +1 -0
  91. package/dist/src/hooks/useCreateSession.js +29 -0
  92. package/dist/src/hooks/useCreateSession.js.map +1 -0
  93. package/dist/src/hooks/useDropdownData.d.ts +45 -0
  94. package/dist/src/hooks/useDropdownData.d.ts.map +1 -0
  95. package/dist/src/hooks/useDropdownData.js +74 -0
  96. package/dist/src/hooks/useDropdownData.js.map +1 -0
  97. package/dist/src/hooks/useEnsureNoSessionAndFetchNonce.d.ts +5 -0
  98. package/dist/src/hooks/useEnsureNoSessionAndFetchNonce.d.ts.map +1 -0
  99. package/dist/src/hooks/useEnsureNoSessionAndFetchNonce.js +34 -0
  100. package/dist/src/hooks/useEnsureNoSessionAndFetchNonce.js.map +1 -0
  101. package/dist/src/hooks/useGetAccountByAddress.d.ts +4 -0
  102. package/dist/src/hooks/useGetAccountByAddress.d.ts.map +1 -0
  103. package/dist/src/hooks/useGetAccountByAddress.js +17 -0
  104. package/dist/src/hooks/useGetAccountByAddress.js.map +1 -0
  105. package/dist/src/hooks/useGetAccountByMezoId.d.ts +4 -0
  106. package/dist/src/hooks/useGetAccountByMezoId.d.ts.map +1 -0
  107. package/dist/src/hooks/useGetAccountByMezoId.js +17 -0
  108. package/dist/src/hooks/useGetAccountByMezoId.js.map +1 -0
  109. package/dist/src/hooks/useGetCurrentAccount.d.ts +18 -0
  110. package/dist/src/hooks/useGetCurrentAccount.d.ts.map +1 -0
  111. package/dist/src/hooks/useGetCurrentAccount.js +37 -0
  112. package/dist/src/hooks/useGetCurrentAccount.js.map +1 -0
  113. package/dist/src/hooks/useGetSession.d.ts +4 -0
  114. package/dist/src/hooks/useGetSession.d.ts.map +1 -0
  115. package/dist/src/hooks/useGetSession.js +15 -0
  116. package/dist/src/hooks/useGetSession.js.map +1 -0
  117. package/dist/src/hooks/useLinkAccount.d.ts +72 -0
  118. package/dist/src/hooks/useLinkAccount.d.ts.map +1 -0
  119. package/dist/src/hooks/useLinkAccount.js +19 -0
  120. package/dist/src/hooks/useLinkAccount.js.map +1 -0
  121. package/dist/src/hooks/usePassportContext.d.ts +3 -0
  122. package/dist/src/hooks/usePassportContext.d.ts.map +1 -0
  123. package/dist/src/hooks/usePassportContext.js +10 -0
  124. package/dist/src/hooks/usePassportContext.js.map +1 -0
  125. package/dist/src/hooks/usePortalApiClient.d.ts +2 -0
  126. package/dist/src/hooks/usePortalApiClient.d.ts.map +1 -0
  127. package/dist/src/hooks/usePortalApiClient.js +6 -0
  128. package/dist/src/hooks/usePortalApiClient.js.map +1 -0
  129. package/dist/src/hooks/useSignInWithDiscord.d.ts +73 -0
  130. package/dist/src/hooks/useSignInWithDiscord.d.ts.map +1 -0
  131. package/dist/src/hooks/useSignInWithDiscord.js +25 -0
  132. package/dist/src/hooks/useSignInWithDiscord.js.map +1 -0
  133. package/dist/src/hooks/useSignInWithWallet.d.ts +73 -0
  134. package/dist/src/hooks/useSignInWithWallet.d.ts.map +1 -0
  135. package/dist/src/hooks/useSignInWithWallet.js +11 -0
  136. package/dist/src/hooks/useSignInWithWallet.js.map +1 -0
  137. package/dist/src/hooks/useSignOut.d.ts +72 -0
  138. package/dist/src/hooks/useSignOut.d.ts.map +1 -0
  139. package/dist/src/hooks/useSignOut.js +22 -0
  140. package/dist/src/hooks/useSignOut.js.map +1 -0
  141. package/dist/src/hooks/useSignUpWithWallet.d.ts +73 -0
  142. package/dist/src/hooks/useSignUpWithWallet.d.ts.map +1 -0
  143. package/dist/src/hooks/useSignUpWithWallet.js +11 -0
  144. package/dist/src/hooks/useSignUpWithWallet.js.map +1 -0
  145. package/dist/src/hooks/useUpdateMezoId.d.ts +108 -0
  146. package/dist/src/hooks/useUpdateMezoId.d.ts.map +1 -0
  147. package/dist/src/hooks/useUpdateMezoId.js +19 -0
  148. package/dist/src/hooks/useUpdateMezoId.js.map +1 -0
  149. package/dist/src/hooks/useWalletAccount.d.ts +12 -0
  150. package/dist/src/hooks/useWalletAccount.d.ts.map +1 -0
  151. package/dist/src/hooks/useWalletAccount.js +28 -0
  152. package/dist/src/hooks/useWalletAccount.js.map +1 -0
  153. package/dist/src/index.d.ts +2 -0
  154. package/dist/src/index.d.ts.map +1 -1
  155. package/dist/src/index.js +2 -0
  156. package/dist/src/index.js.map +1 -1
  157. package/dist/src/provider.d.ts +17 -0
  158. package/dist/src/provider.d.ts.map +1 -0
  159. package/dist/src/provider.js +16 -0
  160. package/dist/src/provider.js.map +1 -0
  161. package/dist/src/utils/address.d.ts +15 -0
  162. package/dist/src/utils/address.d.ts.map +1 -0
  163. package/dist/src/utils/address.js +35 -0
  164. package/dist/src/utils/address.js.map +1 -0
  165. package/dist/src/utils/address.test.d.ts +2 -0
  166. package/dist/src/utils/address.test.d.ts.map +1 -0
  167. package/dist/src/utils/address.test.js +32 -0
  168. package/dist/src/utils/address.test.js.map +1 -0
  169. package/dist/src/utils/cryptoAssets.d.ts +28 -0
  170. package/dist/src/utils/cryptoAssets.d.ts.map +1 -0
  171. package/dist/src/utils/cryptoAssets.js +73 -0
  172. package/dist/src/utils/cryptoAssets.js.map +1 -0
  173. package/dist/src/utils/cryptoAssets.test.d.ts +2 -0
  174. package/dist/src/utils/cryptoAssets.test.d.ts.map +1 -0
  175. package/dist/src/utils/cryptoAssets.test.js +50 -0
  176. package/dist/src/utils/cryptoAssets.test.js.map +1 -0
  177. package/dist/src/utils/currency.d.ts +14 -0
  178. package/dist/src/utils/currency.d.ts.map +1 -0
  179. package/dist/src/utils/currency.js +27 -0
  180. package/dist/src/utils/currency.js.map +1 -0
  181. package/dist/src/utils/currency.test.d.ts +2 -0
  182. package/dist/src/utils/currency.test.d.ts.map +1 -0
  183. package/dist/src/utils/currency.test.js +34 -0
  184. package/dist/src/utils/currency.test.js.map +1 -0
  185. package/dist/src/utils/numbers.d.ts +26 -0
  186. package/dist/src/utils/numbers.d.ts.map +1 -0
  187. package/dist/src/utils/numbers.js +40 -0
  188. package/dist/src/utils/numbers.js.map +1 -0
  189. package/dist/src/utils/numbers.test.d.ts +2 -0
  190. package/dist/src/utils/numbers.test.d.ts.map +1 -0
  191. package/dist/src/utils/numbers.test.js +54 -0
  192. package/dist/src/utils/numbers.test.js.map +1 -0
  193. package/dist/src/utils/siww.d.ts +4 -0
  194. package/dist/src/utils/siww.d.ts.map +1 -0
  195. package/dist/src/utils/siww.js +19 -0
  196. package/dist/src/utils/siww.js.map +1 -0
  197. package/dist/src/utils/time.d.ts +5 -0
  198. package/dist/src/utils/time.d.ts.map +1 -0
  199. package/dist/src/utils/time.js +5 -0
  200. package/dist/src/utils/time.js.map +1 -0
  201. package/package.json +13 -5
  202. package/src/api/auth.ts +178 -0
  203. package/src/api/client.ts +78 -0
  204. package/src/api/fetch-error.ts +8 -0
  205. package/src/api/index.ts +2 -0
  206. package/src/api/portal.ts +56 -0
  207. package/src/assets/DefaultAvatar.tsx +74 -0
  208. package/src/components/Dropdown/AccountAddress.tsx +130 -0
  209. package/src/components/Dropdown/AccountAssets.tsx +110 -0
  210. package/src/components/Dropdown/AccountBalance.tsx +38 -0
  211. package/src/components/Dropdown/ConnectedTrigger.tsx +56 -0
  212. package/src/components/Dropdown/Content.tsx +148 -0
  213. package/src/components/Dropdown/DisconnectedTrigger.tsx +36 -0
  214. package/src/components/Dropdown/Dropdown.tsx +111 -0
  215. package/src/components/Dropdown/README.md +51 -0
  216. package/src/components/Dropdown/WelcomeBlock.tsx +92 -0
  217. package/src/components/Dropdown/index.ts +2 -0
  218. package/src/components/index.ts +1 -0
  219. package/src/hooks/constants.ts +6 -0
  220. package/src/hooks/index.ts +10 -0
  221. package/src/hooks/useAssetsUSDConversion.ts +31 -0
  222. package/src/hooks/useAuthApiClient.ts +6 -0
  223. package/src/hooks/useAuthenticateWithWallet.ts +98 -0
  224. package/src/hooks/useCreateAccount.ts +36 -0
  225. package/src/hooks/useCreateSession.ts +44 -0
  226. package/src/hooks/useDropdownData.ts +131 -0
  227. package/src/hooks/useEnsureNoSessionAndFetchNonce.ts +46 -0
  228. package/src/hooks/useGetAccountByAddress.ts +25 -0
  229. package/src/hooks/useGetAccountByMezoId.ts +25 -0
  230. package/src/hooks/useGetCurrentAccount.ts +62 -0
  231. package/src/hooks/useGetSession.ts +22 -0
  232. package/src/hooks/useLinkAccount.ts +33 -0
  233. package/src/hooks/usePassportContext.ts +11 -0
  234. package/src/hooks/usePortalApiClient.ts +6 -0
  235. package/src/hooks/useSignInWithDiscord.ts +35 -0
  236. package/src/hooks/useSignInWithWallet.ts +21 -0
  237. package/src/hooks/useSignOut.ts +35 -0
  238. package/src/hooks/useSignUpWithWallet.ts +21 -0
  239. package/src/hooks/useUpdateMezoId.ts +33 -0
  240. package/src/hooks/useWalletAccount.ts +53 -0
  241. package/src/index.ts +2 -0
  242. package/src/provider.ts +50 -0
  243. package/src/utils/address.test.ts +38 -0
  244. package/src/utils/address.ts +43 -0
  245. package/src/utils/cryptoAssets.test.ts +61 -0
  246. package/src/utils/cryptoAssets.ts +93 -0
  247. package/src/utils/currency.test.ts +38 -0
  248. package/src/utils/currency.ts +32 -0
  249. package/src/utils/numbers.test.ts +73 -0
  250. package/src/utils/numbers.ts +55 -0
  251. package/src/utils/siww.ts +31 -0
  252. package/src/utils/time.ts +4 -0
@@ -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,26 @@
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/2078d339f4ddce79e69c78529c9d72910dd2640a/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/f6b26b7cb4a0a0278b1fccc6319626638f1a6dfa/background/lib/fixed-point.ts#L216-L239
24
+ */
25
+ export declare function fromFixedPoint(fixedPoint: bigint, fixedPointDecimals: number, desiredDecimals?: number): number;
26
+ //# sourceMappingURL=numbers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"numbers.d.ts","sourceRoot":"","sources":["../../../src/utils/numbers.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,QAAQ,SAAI,GACX,MAAM,CAMR;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"}
@@ -0,0 +1,40 @@
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
+ return value.toLocaleString("en-US", {
9
+ notation: "compact",
10
+ compactDisplay: "short",
11
+ maximumFractionDigits: decimals,
12
+ });
13
+ }
14
+ /**
15
+ * Returns a number rounded up to the desired number of decimals.
16
+ * @param amount The number to round up.
17
+ * @param desiredDecimals The number of decimals to round up to.
18
+ * @returns The rounded up number.
19
+ * @see https://github.com/thesis/acre/blob/2078d339f4ddce79e69c78529c9d72910dd2640a/dapp/src/utils/numbersUtils.ts#L1-L3
20
+ */
21
+ export function roundUpNumber(amount, desiredDecimals = 2) {
22
+ return Math.ceil(amount * 10 ** desiredDecimals) / 10 ** desiredDecimals;
23
+ }
24
+ /**
25
+ * Convert a fixed point bigint with precision `fixedPointDecimals` to a
26
+ * floating point number truncated to `desiredDecimals`.
27
+ * @param fixedPoint The fixed point bigint to convert.
28
+ * @param fixedPointDecimals The number of decimals in the fixed point bigint.
29
+ * @param desiredDecimals The number of decimals in the output number.
30
+ * @returns The floating point number truncated to `desiredDecimals`.
31
+ * @see https://github.com/tahowallet/extension/blob/f6b26b7cb4a0a0278b1fccc6319626638f1a6dfa/background/lib/fixed-point.ts#L216-L239
32
+ */
33
+ export function fromFixedPoint(fixedPoint, fixedPointDecimals, desiredDecimals = 2) {
34
+ const fixedPointDesiredDecimalsAmount = fixedPoint /
35
+ 10n ** BigInt(Math.max(1, fixedPointDecimals - desiredDecimals));
36
+ const formattedAmount = Number(fixedPointDesiredDecimalsAmount) /
37
+ 10 ** Math.min(desiredDecimals, fixedPointDecimals);
38
+ return formattedAmount;
39
+ }
40
+ //# sourceMappingURL=numbers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"numbers.js","sourceRoot":"","sources":["../../../src/utils/numbers.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CACvC,KAAsB,EACtB,QAAQ,GAAG,CAAC;IAEZ,OAAO,KAAK,CAAC,cAAc,CAAC,OAAO,EAAE;QACnC,QAAQ,EAAE,SAAS;QACnB,cAAc,EAAE,OAAO;QACvB,qBAAqB,EAAE,QAA2B;KACnD,CAAC,CAAA;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,MAAc,EAAE,eAAe,GAAG,CAAC;IAC/D,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,EAAE,IAAI,eAAe,CAAC,GAAG,EAAE,IAAI,eAAe,CAAA;AAC1E,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAC5B,UAAkB,EAClB,kBAA0B,EAC1B,eAAe,GAAG,CAAC;IAEnB,MAAM,+BAA+B,GACnC,UAAU;QACV,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,kBAAkB,GAAG,eAAe,CAAC,CAAC,CAAA;IAElE,MAAM,eAAe,GACnB,MAAM,CAAC,+BAA+B,CAAC;QACvC,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC,eAAe,EAAE,kBAAkB,CAAC,CAAA;IAErD,OAAO,eAAe,CAAA;AACxB,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,54 @@
1
+ import { formatHumanReadableNumber, 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("1,234,567.89T");
20
+ });
21
+ it("caps at > 1000T for huge numbers", () => {
22
+ const hugeNumber = 10 ** 18; // 1e18
23
+ expect(formatHumanReadableNumber(hugeNumber, 2)).toBe("1,000,000T");
24
+ });
25
+ it("formats numbers with trailing zeros correctly", () => {
26
+ expect(formatHumanReadableNumber(1_000, 2)).toBe("1K");
27
+ });
28
+ });
29
+ describe("roundUpNumber", () => {
30
+ it("rounds up to 2 decimals", () => {
31
+ expect(roundUpNumber(1.234)).toBe(1.24);
32
+ });
33
+ it("rounds up to 3 decimals", () => {
34
+ expect(roundUpNumber(9.87654, 3)).toBe(9.877);
35
+ });
36
+ it("rounds up exact decimal", () => {
37
+ expect(roundUpNumber(2.5, 1)).toBe(2.5);
38
+ });
39
+ });
40
+ describe("fromFixedPoint", () => {
41
+ it("converts fixed point with 18 decimals to float", () => {
42
+ const raw = 1234567890000000000n; // 1.23456789 ETH in 18 decimals
43
+ expect(fromFixedPoint(raw, 18, 4)).toBe(1.2345);
44
+ });
45
+ it("converts with truncation to 2 decimals", () => {
46
+ const raw = 987654321000000000n; // ~0.987654321 ETH
47
+ expect(fromFixedPoint(raw, 18, 2)).toBe(0.98);
48
+ });
49
+ it("handles large fixedPoint decimals", () => {
50
+ const raw = 1000000000000000000000000n; // 1M with 6 decimals
51
+ expect(fromFixedPoint(raw, 6, 2)).toBe(1000000000000000000);
52
+ });
53
+ });
54
+ //# sourceMappingURL=numbers.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"numbers.test.js","sourceRoot":"","sources":["../../../src/utils/numbers.test.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,4 @@
1
+ type NetworkFamily = "evm" | "bitcoin";
2
+ export declare function createSignInWithWalletMessage(address: string, nonce: string, networkFamily: NetworkFamily, chainId?: number): string;
3
+ export {};
4
+ //# sourceMappingURL=siww.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,19 @@
1
+ import { SignInWithWalletMessage } from "@mezo-org/sign-in-with-wallet";
2
+ import { ONE_DAY_MS } from "./time";
3
+ const SESSION_EXPIRATION_DURATION_MS = 14 * ONE_DAY_MS;
4
+ export function createSignInWithWalletMessage(address, nonce, networkFamily, chainId) {
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,
10
+ 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();
18
+ }
19
+ //# sourceMappingURL=siww.js.map
@@ -0,0 +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,SAAS;QACtD,aAAa;KACd,CAAC,CAAA;IAEF,OAAO,OAAO,CAAC,cAAc,EAAE,CAAA;AACjC,CAAC"}
@@ -0,0 +1,5 @@
1
+ export declare const ONE_SECOND_MS = 1000;
2
+ export declare const ONE_MINUTE_MS: number;
3
+ export declare const ONE_HOUR_MS: number;
4
+ export declare const ONE_DAY_MS: number;
5
+ //# sourceMappingURL=time.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../../src/utils/time.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,OAAO,CAAA;AACjC,eAAO,MAAM,aAAa,QAAqB,CAAA;AAC/C,eAAO,MAAM,WAAW,QAAqB,CAAA;AAC7C,eAAO,MAAM,UAAU,QAAmB,CAAA"}
@@ -0,0 +1,5 @@
1
+ export const ONE_SECOND_MS = 1000;
2
+ export const ONE_MINUTE_MS = 60 * ONE_SECOND_MS;
3
+ export const ONE_HOUR_MS = 60 * ONE_MINUTE_MS;
4
+ export const ONE_DAY_MS = 24 * ONE_HOUR_MS;
5
+ //# sourceMappingURL=time.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"time.js","sourceRoot":"","sources":["../../../src/utils/time.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,CAAA;AACjC,MAAM,CAAC,MAAM,aAAa,GAAG,EAAE,GAAG,aAAa,CAAA;AAC/C,MAAM,CAAC,MAAM,WAAW,GAAG,EAAE,GAAG,aAAa,CAAA;AAC7C,MAAM,CAAC,MAAM,UAAU,GAAG,EAAE,GAAG,WAAW,CAAA"}
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@mezo-org/passport",
3
- "version": "0.4.0-dev.0",
3
+ "version": "0.4.0-dev.10",
4
4
  "main": "dist/src/index.js",
5
5
  "license": "GPL-3.0-only",
6
6
  "scripts": {
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,22 +24,29 @@
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
- "eslint": "^8.54.0",
31
+ "eslint": "^8.57.1",
32
32
  "jest": "^29.7.0",
33
- "prettier": "^3.1.0",
33
+ "jest-environment-jsdom": "^29.7.0",
34
+ "prettier": "^3.2.5",
34
35
  "ts-jest": "^29.1.2",
35
36
  "ts-node": "^10.9.2",
36
37
  "typescript": "^5.4.3"
37
38
  },
39
+ "dependencies": {
40
+ "@mezo-org/mezo-clay": "0.1.0-dev.18",
41
+ "@mezo-org/orangekit": "1.0.0-beta.40-dev.0",
42
+ "@mezo-org/sign-in-with-wallet": "1.0.0-beta.8"
43
+ },
38
44
  "peerDependencies": {
39
- "@mezo-org/orangekit": "1.0.0-beta.39",
40
45
  "@rainbow-me/rainbowkit": "2.0.2",
46
+ "@tanstack/react-query": "^5.28.4",
41
47
  "react": "^18.2.0",
48
+ "styletron-engine-monolithic": "^1.0.0",
49
+ "usehooks-ts": "^3.1.1",
42
50
  "viem": "2.22.8",
43
51
  "wagmi": "2.5.12"
44
52
  }
@@ -0,0 +1,178 @@
1
+ import { ApiClient } from "./client"
2
+ import { FetchError } from "./fetch-error"
3
+
4
+ type AuthProvider = "discord"
5
+
6
+ export type LinkedWalletAccount = {
7
+ type: "wallet"
8
+ btcAddress?: string
9
+ evmAddress: string
10
+ }
11
+
12
+ export type LinkedProviderAccount = {
13
+ type: AuthProvider
14
+ name: string
15
+ id: string
16
+ avatarUrl: string
17
+ }
18
+
19
+ export type LinkedAccount = LinkedWalletAccount | LinkedProviderAccount
20
+
21
+ type Account = {
22
+ mezoId: string
23
+ hasModifiedMezoId: boolean
24
+ linkedAccounts: LinkedAccount[]
25
+ }
26
+
27
+ export type Session = {
28
+ expiresIn: number
29
+ expiresAt: number
30
+ sessionLinks: {
31
+ _links: {
32
+ account: string
33
+ }
34
+ }
35
+ }
36
+
37
+ export type AuthenticationProviderRedirectResponse = {
38
+ redirectTo: string
39
+ }
40
+
41
+ type SignatureData = {
42
+ message: string
43
+ signature: string
44
+ }
45
+
46
+ // Request and Response types
47
+ export type GetSessionResponse = Session | { nonce: string }
48
+
49
+ export type CreateSessionRequest =
50
+ | ({ type: "wallet" } & SignatureData)
51
+ | { type: "discord" }
52
+ export type CreateSessionResponse =
53
+ | Session
54
+ | AuthenticationProviderRedirectResponse
55
+
56
+ export type DeleteSessionResponse = { message: string }
57
+
58
+ export type GetCurrentAccountResponse = Partial<Account> | null
59
+
60
+ export type GetAccountByMezoIdOrAddressResponse = {
61
+ mezoId?: string
62
+ linkedAccounts?: Extract<LinkedAccount, { type: "wallet" }>[]
63
+ }
64
+
65
+ export type LinkAccountRequest = CreateSessionRequest
66
+ export type LinkAccountResponse =
67
+ | Account
68
+ | AuthenticationProviderRedirectResponse
69
+
70
+ export type CreateAccountRequest = { type: "wallet" } & SignatureData
71
+ export type CreateAccountResponse = Account
72
+
73
+ export type UpdateMezoIdResponse = Account
74
+
75
+ export const AUTH_API_ENDPOINTS_BY_ENV = {
76
+ mainnet: "https://api.mezo.org",
77
+ testnet: "https://api.test.mezo.org",
78
+ }
79
+
80
+ export class AuthApiClient extends ApiClient {
81
+ constructor(
82
+ environment: keyof typeof AUTH_API_ENDPOINTS_BY_ENV = "mainnet",
83
+ apiUrl?: string,
84
+ ) {
85
+ super(apiUrl ?? AUTH_API_ENDPOINTS_BY_ENV[environment])
86
+ }
87
+
88
+ async getSession(code?: string) {
89
+ const data = await this.handleRequest<GetSessionResponse>("/session", {
90
+ method: "GET",
91
+ queryParams: { code },
92
+ })
93
+
94
+ return data
95
+ }
96
+
97
+ async createSession(createSessionRequest: CreateSessionRequest) {
98
+ const data = await this.handleRequest<CreateSessionResponse>("/session", {
99
+ method: "POST",
100
+ body: createSessionRequest,
101
+ })
102
+
103
+ return data
104
+ }
105
+
106
+ async deleteSession() {
107
+ const data = await this.handleRequest<DeleteSessionResponse>("/session", {
108
+ method: "DELETE",
109
+ })
110
+
111
+ return data
112
+ }
113
+
114
+ async getCurrentAccount() {
115
+ const data = await this.handleRequest<GetCurrentAccountResponse>(
116
+ "/session/account",
117
+ {
118
+ method: "GET",
119
+ },
120
+ )
121
+
122
+ return data
123
+ }
124
+
125
+ async getAccountByMezoIdOrAddress(mezoIdOrAddress: string) {
126
+ let data
127
+ try {
128
+ data = await this.handleRequest<GetAccountByMezoIdOrAddressResponse>(
129
+ `/accounts/${mezoIdOrAddress}`,
130
+ {
131
+ method: "GET",
132
+ },
133
+ )
134
+ } catch (error) {
135
+ // Return null if account is not found instead of throwing an error
136
+ if (error instanceof FetchError && error.status === 404) {
137
+ data = null
138
+ } else {
139
+ throw error
140
+ }
141
+ }
142
+
143
+ return data
144
+ }
145
+
146
+ async linkAccount(linkAccountRequest: LinkAccountRequest) {
147
+ const data = await this.handleRequest<LinkAccountResponse>(
148
+ "/session/account/linked-accounts",
149
+ {
150
+ method: "POST",
151
+ body: linkAccountRequest,
152
+ },
153
+ )
154
+
155
+ return data
156
+ }
157
+
158
+ async createAccount(createAccountRequest: CreateAccountRequest) {
159
+ const data = await this.handleRequest<CreateAccountResponse>("/accounts", {
160
+ method: "POST",
161
+ body: createAccountRequest,
162
+ })
163
+
164
+ return data
165
+ }
166
+
167
+ async updateMezoId(newMezoId: string) {
168
+ const data = await this.handleRequest<UpdateMezoIdResponse>(
169
+ "/session/account",
170
+ {
171
+ method: "PATCH",
172
+ body: { mezoId: newMezoId },
173
+ },
174
+ )
175
+
176
+ return data
177
+ }
178
+ }
@@ -0,0 +1,78 @@
1
+ import { FetchError } from "./fetch-error"
2
+
3
+ type RequestHandlerOptions = Omit<RequestInit, "credentials" | "body"> & {
4
+ body?: Record<string, unknown>
5
+ queryParams?: Record<string, string | undefined>
6
+ }
7
+
8
+ export abstract class ApiClient {
9
+ private apiUrl: string
10
+
11
+ constructor(apiUrl: string) {
12
+ this.apiUrl = apiUrl
13
+ }
14
+
15
+ /**
16
+ * The request handler for the Passport API. It accepts an API endpoint and
17
+ * request options.
18
+ * @dev Generic type `D` is a type of returned object from the function
19
+ * @dev WARNING: This function hardcodes `credentials: "include"`, meaning
20
+ * cookies and authentication headers will be sent with every request. Ensure
21
+ * this is safe if you plan to use it in other contexts than auth api worker.
22
+ * @param endpoint - The API endpoint to request. Should start with
23
+ * forward slash ("/")
24
+ * @param options - The request options, the `RequestInit` type with
25
+ * additional type-safe properties
26
+ * @returns The promise of the API response
27
+ */
28
+ protected async handleRequest<D>(
29
+ endpoint: `/${string}`,
30
+ options: RequestHandlerOptions = {},
31
+ ): Promise<D> {
32
+ try {
33
+ const { method, body, queryParams = {}, ...restOptions } = options
34
+
35
+ // If last character in apiUrl is forward slash we are removing it
36
+ const authApiUrlRoute = this.apiUrl.replace(/\/$/, "")
37
+ const url = new URL(`${authApiUrlRoute}${endpoint}`)
38
+
39
+ // Removes falsy values (e.g. null, undefined etc.) from query params and
40
+ // appends remaining ones to the URL
41
+ Object.entries(queryParams)
42
+ .filter(([, value]) => value) // Remove falsy values
43
+ .forEach(([key, value]) => url.searchParams.append(key, value!))
44
+
45
+ const response = await fetch(url, {
46
+ method,
47
+ credentials: "include",
48
+ body: body ? JSON.stringify(body) : undefined,
49
+ ...restOptions,
50
+ })
51
+
52
+ const data = await response.json()
53
+
54
+ if (!response.ok || data?.error) {
55
+ const error =
56
+ data?.error ||
57
+ `An error occurred when handling API request: ${JSON.stringify(data)}`
58
+ throw new FetchError(
59
+ response.status,
60
+ `Error [${response.status}]: ${error}`,
61
+ )
62
+ }
63
+
64
+ return data as D
65
+ } catch (error) {
66
+ if (error instanceof FetchError) {
67
+ throw error
68
+ }
69
+
70
+ const errorMessage =
71
+ error instanceof Error ? error.message : JSON.stringify(error)
72
+ throw new FetchError(
73
+ 500,
74
+ `Error [500]: An error occurred when handling API request: ${errorMessage}`,
75
+ )
76
+ }
77
+ }
78
+ }
@@ -0,0 +1,8 @@
1
+ export class FetchError extends Error {
2
+ constructor(
3
+ public status: number,
4
+ message?: string,
5
+ ) {
6
+ super(message)
7
+ }
8
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./auth"
2
+ export * from "./portal"
@@ -0,0 +1,56 @@
1
+ import { ApiClient } from "./client"
2
+
3
+ type PortalStatistics = {
4
+ hodlers: number
5
+ depositedBitcoin: string
6
+ tvl: number
7
+ currentUsdPerBtc: string
8
+ currentUsdPerEth: string
9
+ usdPerBtc24hChange: string
10
+ }
11
+
12
+ type PortalMats = {
13
+ address: string
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
23
+ }
24
+
25
+ export const PORTAL_API_ENDPOINTS_BY_ENV = {
26
+ mainnet: "https://api.mezo.org/api/v1",
27
+ testnet: "https://api.test.mezo.org/api/v1",
28
+ }
29
+
30
+ export class PortalApiClient extends ApiClient {
31
+ constructor(
32
+ environment: keyof typeof PORTAL_API_ENDPOINTS_BY_ENV = "mainnet",
33
+ apiUrl?: string,
34
+ ) {
35
+ super(apiUrl ?? PORTAL_API_ENDPOINTS_BY_ENV[environment])
36
+ }
37
+
38
+ async getPortalStatistics() {
39
+ const data = await this.handleRequest<PortalStatistics>("/statistics", {
40
+ method: "GET",
41
+ })
42
+
43
+ return data
44
+ }
45
+
46
+ async getPortalMats(address: string) {
47
+ const data = await this.handleRequest<PortalMats>(
48
+ `/accounts/${address}/mats`,
49
+ {
50
+ method: "GET",
51
+ },
52
+ )
53
+
54
+ return data
55
+ }
56
+ }
@@ -0,0 +1,74 @@
1
+ import { Block, BlockProps } from "@mezo-org/mezo-clay"
2
+ import React, { SVGProps } from "react"
3
+
4
+ function DefaultAvatar(props: SVGProps<SVGSVGElement>) {
5
+ return (
6
+ <svg viewBox="0 0 214 214" fill="none" {...props}>
7
+ <rect y="-0.478027" width="166.379" height="81.7091" fill="#FF004D" />
8
+ <rect x="166" y="-0.478027" width="48" height="82" fill="black" />
9
+ <rect
10
+ x="166.379"
11
+ y="81.231"
12
+ width="24.1044"
13
+ height="132.291"
14
+ fill="#DFFF80"
15
+ />
16
+ <rect
17
+ x="118.758"
18
+ y="81.231"
19
+ width="24.1044"
20
+ height="132.291"
21
+ fill="#FF5500"
22
+ />
23
+ <rect
24
+ x="71.1372"
25
+ y="81.231"
26
+ width="24.1044"
27
+ height="132.291"
28
+ fill="#5A59A7"
29
+ />
30
+ <rect
31
+ x="23.5166"
32
+ y="81.231"
33
+ width="24.1044"
34
+ height="132.291"
35
+ fill="#47B5FF"
36
+ />
37
+ <rect y="81.231" width="23.5165" height="132.291" fill="#A3C238" />
38
+ <rect
39
+ x="190.483"
40
+ y="81.231"
41
+ width="23.5165"
42
+ height="132.291"
43
+ fill="#6E6E70"
44
+ />
45
+ <rect
46
+ x="142.863"
47
+ y="81.231"
48
+ width="23.5165"
49
+ height="132.291"
50
+ fill="#0A3C01"
51
+ />
52
+ <rect
53
+ x="95.2417"
54
+ y="81.231"
55
+ width="23.5165"
56
+ height="132.291"
57
+ fill="#F2A91F"
58
+ />
59
+ <rect
60
+ x="47.6211"
61
+ y="81.231"
62
+ width="23.5165"
63
+ height="132.291"
64
+ fill="#6B3D01"
65
+ />
66
+ </svg>
67
+ )
68
+ }
69
+
70
+ function DefaultAvatarComponent(props: BlockProps) {
71
+ return <Block as={DefaultAvatar} {...props} />
72
+ }
73
+
74
+ export default DefaultAvatarComponent