@mezo-org/passport 0.4.0-dev.9 → 0.5.1-dev.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (305) hide show
  1. package/README.md +18 -22
  2. package/dist/src/api/auth.d.ts +7 -3
  3. package/dist/src/api/auth.d.ts.map +1 -1
  4. package/dist/src/api/auth.js +3 -1
  5. package/dist/src/api/auth.js.map +1 -1
  6. package/dist/src/api/client.d.ts +4 -1
  7. package/dist/src/api/client.d.ts.map +1 -1
  8. package/dist/src/api/client.js +9 -2
  9. package/dist/src/api/client.js.map +1 -1
  10. package/dist/src/api/portal.d.ts +3 -9
  11. package/dist/src/api/portal.d.ts.map +1 -1
  12. package/dist/src/api/portal.js +8 -5
  13. package/dist/src/api/portal.js.map +1 -1
  14. package/dist/src/components/Dropdown/ConnectedTrigger.d.ts +2 -1
  15. package/dist/src/components/Dropdown/ConnectedTrigger.d.ts.map +1 -1
  16. package/dist/src/components/Dropdown/ConnectedTrigger.js +29 -20
  17. package/dist/src/components/Dropdown/ConnectedTrigger.js.map +1 -1
  18. package/dist/src/components/Dropdown/Content.d.ts +4 -5
  19. package/dist/src/components/Dropdown/Content.d.ts.map +1 -1
  20. package/dist/src/components/Dropdown/Content.js +19 -61
  21. package/dist/src/components/Dropdown/Content.js.map +1 -1
  22. package/dist/src/components/Dropdown/DisconnectedTrigger.d.ts.map +1 -1
  23. package/dist/src/components/Dropdown/DisconnectedTrigger.js +2 -2
  24. package/dist/src/components/Dropdown/DisconnectedTrigger.js.map +1 -1
  25. package/dist/src/components/Dropdown/Dropdown.d.ts +9 -6
  26. package/dist/src/components/Dropdown/Dropdown.d.ts.map +1 -1
  27. package/dist/src/components/Dropdown/Dropdown.js +10 -10
  28. package/dist/src/components/Dropdown/Dropdown.js.map +1 -1
  29. package/dist/src/components/Dropdown/ListingItem.d.ts +14 -0
  30. package/dist/src/components/Dropdown/ListingItem.d.ts.map +1 -0
  31. package/dist/src/components/Dropdown/ListingItem.js +42 -0
  32. package/dist/src/components/Dropdown/ListingItem.js.map +1 -0
  33. package/dist/src/components/Dropdown/NestedViewLayout.d.ts +8 -0
  34. package/dist/src/components/Dropdown/NestedViewLayout.d.ts.map +1 -0
  35. package/dist/src/components/Dropdown/NestedViewLayout.js +32 -0
  36. package/dist/src/components/Dropdown/NestedViewLayout.js.map +1 -0
  37. package/dist/src/components/Dropdown/Receive/Receive.d.ts +4 -0
  38. package/dist/src/components/Dropdown/Receive/Receive.d.ts.map +1 -0
  39. package/dist/src/components/Dropdown/Receive/Receive.js +64 -0
  40. package/dist/src/components/Dropdown/Receive/Receive.js.map +1 -0
  41. package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts +4 -0
  42. package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts.map +1 -0
  43. package/dist/src/components/Dropdown/Root/AccountAddressActions.js +49 -0
  44. package/dist/src/components/Dropdown/Root/AccountAddressActions.js.map +1 -0
  45. package/dist/src/components/Dropdown/Root/AccountBalance.d.ts +6 -0
  46. package/dist/src/components/Dropdown/Root/AccountBalance.d.ts.map +1 -0
  47. package/dist/src/components/Dropdown/Root/AccountBalance.js +35 -0
  48. package/dist/src/components/Dropdown/Root/AccountBalance.js.map +1 -0
  49. package/dist/src/components/Dropdown/Root/AccountBtcListing.d.ts +6 -0
  50. package/dist/src/components/Dropdown/Root/AccountBtcListing.d.ts.map +1 -0
  51. package/dist/src/components/Dropdown/Root/AccountBtcListing.js +27 -0
  52. package/dist/src/components/Dropdown/Root/AccountBtcListing.js.map +1 -0
  53. package/dist/src/components/Dropdown/Root/AccountError.d.ts +8 -0
  54. package/dist/src/components/Dropdown/Root/AccountError.d.ts.map +1 -0
  55. package/dist/src/components/Dropdown/Root/AccountError.js +17 -0
  56. package/dist/src/components/Dropdown/Root/AccountError.js.map +1 -0
  57. package/dist/src/components/Dropdown/Root/AccountMusdListing.d.ts +4 -0
  58. package/dist/src/components/Dropdown/Root/AccountMusdListing.d.ts.map +1 -0
  59. package/dist/src/components/Dropdown/Root/AccountMusdListing.js +21 -0
  60. package/dist/src/components/Dropdown/Root/AccountMusdListing.js.map +1 -0
  61. package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts +8 -0
  62. package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts.map +1 -0
  63. package/dist/src/components/Dropdown/Root/AccountOtherAssets.js +43 -0
  64. package/dist/src/components/Dropdown/Root/AccountOtherAssets.js.map +1 -0
  65. package/dist/src/components/Dropdown/Root/Root.d.ts +8 -0
  66. package/dist/src/components/Dropdown/Root/Root.d.ts.map +1 -0
  67. package/dist/src/components/Dropdown/Root/Root.js +45 -0
  68. package/dist/src/components/Dropdown/Root/Root.js.map +1 -0
  69. package/dist/src/components/Dropdown/Root/WalletAddress.d.ts +4 -0
  70. package/dist/src/components/Dropdown/Root/WalletAddress.d.ts.map +1 -0
  71. package/dist/src/components/Dropdown/Root/WalletAddress.js +66 -0
  72. package/dist/src/components/Dropdown/Root/WalletAddress.js.map +1 -0
  73. package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts +6 -0
  74. package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts.map +1 -0
  75. package/dist/src/components/Dropdown/Root/WelcomeBlock.js +88 -0
  76. package/dist/src/components/Dropdown/Root/WelcomeBlock.js.map +1 -0
  77. package/dist/src/components/Dropdown/SlotNumber.d.ts +19 -0
  78. package/dist/src/components/Dropdown/SlotNumber.d.ts.map +1 -0
  79. package/dist/src/components/Dropdown/SlotNumber.js +67 -0
  80. package/dist/src/components/Dropdown/SlotNumber.js.map +1 -0
  81. package/dist/src/components/Dropdown/TestnetTopBanner.d.ts +3 -0
  82. package/dist/src/components/Dropdown/TestnetTopBanner.d.ts.map +1 -0
  83. package/dist/src/components/Dropdown/TestnetTopBanner.js +14 -0
  84. package/dist/src/components/Dropdown/TestnetTopBanner.js.map +1 -0
  85. package/dist/src/config.d.ts +19 -5
  86. package/dist/src/config.d.ts.map +1 -1
  87. package/dist/src/config.js +58 -14
  88. package/dist/src/config.js.map +1 -1
  89. package/dist/src/constants.d.ts +11 -3
  90. package/dist/src/constants.d.ts.map +1 -1
  91. package/dist/src/constants.js +12 -4
  92. package/dist/src/constants.js.map +1 -1
  93. package/dist/src/hooks/index.d.ts +4 -0
  94. package/dist/src/hooks/index.d.ts.map +1 -1
  95. package/dist/src/hooks/index.js +4 -0
  96. package/dist/src/hooks/index.js.map +1 -1
  97. package/dist/src/hooks/useAssetsConversionRates.d.ts +18 -0
  98. package/dist/src/hooks/useAssetsConversionRates.d.ts.map +1 -0
  99. package/dist/src/hooks/useAssetsConversionRates.js +67 -0
  100. package/dist/src/hooks/useAssetsConversionRates.js.map +1 -0
  101. package/dist/src/hooks/useAuthenticateWithWallet.d.ts +13 -13
  102. package/dist/src/hooks/useAuthenticateWithWallet.d.ts.map +1 -1
  103. package/dist/src/hooks/useAuthenticateWithWallet.js +9 -8
  104. package/dist/src/hooks/useAuthenticateWithWallet.js.map +1 -1
  105. package/dist/src/hooks/useBorrowData.d.ts +108 -0
  106. package/dist/src/hooks/useBorrowData.d.ts.map +1 -0
  107. package/dist/src/hooks/useBorrowData.js +201 -0
  108. package/dist/src/hooks/useBorrowData.js.map +1 -0
  109. package/dist/src/hooks/useCreateAccount.d.ts.map +1 -1
  110. package/dist/src/hooks/useCreateAccount.js +22 -1
  111. package/dist/src/hooks/useCreateAccount.js.map +1 -1
  112. package/dist/src/hooks/useGetCurrentAccount.d.ts.map +1 -1
  113. package/dist/src/hooks/useGetCurrentAccount.js +4 -6
  114. package/dist/src/hooks/useGetCurrentAccount.js.map +1 -1
  115. package/dist/src/hooks/useLinkAccount.d.ts +19 -13
  116. package/dist/src/hooks/useLinkAccount.d.ts.map +1 -1
  117. package/dist/src/hooks/useLinkAccount.js +20 -1
  118. package/dist/src/hooks/useLinkAccount.js.map +1 -1
  119. package/dist/src/hooks/useRefreshPassport.d.ts +19 -0
  120. package/dist/src/hooks/useRefreshPassport.d.ts.map +1 -0
  121. package/dist/src/hooks/useRefreshPassport.js +44 -0
  122. package/dist/src/hooks/useRefreshPassport.js.map +1 -0
  123. package/dist/src/hooks/useSignInWithWallet.d.ts +13 -13
  124. package/dist/src/hooks/useSignInWithWallet.d.ts.map +1 -1
  125. package/dist/src/hooks/useSignUpWithWallet.d.ts +13 -13
  126. package/dist/src/hooks/useSignUpWithWallet.d.ts.map +1 -1
  127. package/dist/src/hooks/useTokensBalances.d.ts +75 -0
  128. package/dist/src/hooks/useTokensBalances.d.ts.map +1 -0
  129. package/dist/src/hooks/useTokensBalances.js +181 -0
  130. package/dist/src/hooks/useTokensBalances.js.map +1 -0
  131. package/dist/src/hooks/useValidateMezoId.d.ts +8 -0
  132. package/dist/src/hooks/useValidateMezoId.d.ts.map +1 -0
  133. package/dist/src/hooks/useValidateMezoId.js +24 -0
  134. package/dist/src/hooks/useValidateMezoId.js.map +1 -0
  135. package/dist/src/hooks/useWalletAccount.d.ts +2 -1
  136. package/dist/src/hooks/useWalletAccount.d.ts.map +1 -1
  137. package/dist/src/hooks/useWalletAccount.js +20 -15
  138. package/dist/src/hooks/useWalletAccount.js.map +1 -1
  139. package/dist/src/hooks/useWatchTransferEvents.d.ts +5 -0
  140. package/dist/src/hooks/useWatchTransferEvents.d.ts.map +1 -0
  141. package/dist/src/hooks/useWatchTransferEvents.js +63 -0
  142. package/dist/src/hooks/useWatchTransferEvents.js.map +1 -0
  143. package/dist/src/index.d.ts +2 -1
  144. package/dist/src/index.d.ts.map +1 -1
  145. package/dist/src/index.js +2 -1
  146. package/dist/src/index.js.map +1 -1
  147. package/dist/src/lib/contracts/index.d.ts +13 -0
  148. package/dist/src/lib/contracts/index.d.ts.map +1 -0
  149. package/dist/src/lib/contracts/index.js +66 -0
  150. package/dist/src/lib/contracts/index.js.map +1 -0
  151. package/dist/src/lib/contracts/priceOracle.d.ts +43 -0
  152. package/dist/src/lib/contracts/priceOracle.d.ts.map +1 -0
  153. package/dist/src/lib/contracts/priceOracle.js +52 -0
  154. package/dist/src/lib/contracts/priceOracle.js.map +1 -0
  155. package/dist/src/provider.d.ts +7 -1
  156. package/dist/src/provider.d.ts.map +1 -1
  157. package/dist/src/provider.js +4 -1
  158. package/dist/src/provider.js.map +1 -1
  159. package/dist/src/stores/dropdownStore.d.ts +12 -0
  160. package/dist/src/stores/dropdownStore.d.ts.map +1 -0
  161. package/dist/src/stores/dropdownStore.js +13 -0
  162. package/dist/src/stores/dropdownStore.js.map +1 -0
  163. package/dist/src/utils/address.d.ts +1 -1
  164. package/dist/src/utils/address.d.ts.map +1 -1
  165. package/dist/src/utils/address.js +2 -0
  166. package/dist/src/utils/address.js.map +1 -1
  167. package/dist/src/utils/address.test.js +8 -5
  168. package/dist/src/utils/address.test.js.map +1 -1
  169. package/dist/src/utils/assets.d.ts +145 -0
  170. package/dist/src/utils/assets.d.ts.map +1 -0
  171. package/dist/src/utils/assets.js +100 -0
  172. package/dist/src/utils/assets.js.map +1 -0
  173. package/dist/src/utils/assets.test.d.ts +2 -0
  174. package/dist/src/utils/assets.test.d.ts.map +1 -0
  175. package/dist/src/utils/assets.test.js +46 -0
  176. package/dist/src/utils/assets.test.js.map +1 -0
  177. package/dist/src/utils/currency.d.ts +13 -2
  178. package/dist/src/utils/currency.d.ts.map +1 -1
  179. package/dist/src/utils/currency.js +22 -8
  180. package/dist/src/utils/currency.js.map +1 -1
  181. package/dist/src/utils/currency.test.js +44 -1
  182. package/dist/src/utils/currency.test.js.map +1 -1
  183. package/dist/src/utils/mezoId.d.ts +7 -0
  184. package/dist/src/utils/mezoId.d.ts.map +1 -0
  185. package/dist/src/utils/mezoId.js +41 -0
  186. package/dist/src/utils/mezoId.js.map +1 -0
  187. package/dist/src/utils/number2.d.ts +106 -0
  188. package/dist/src/utils/number2.d.ts.map +1 -0
  189. package/dist/src/utils/number2.js +289 -0
  190. package/dist/src/utils/number2.js.map +1 -0
  191. package/dist/src/utils/numbers.d.ts +15 -33
  192. package/dist/src/utils/numbers.d.ts.map +1 -1
  193. package/dist/src/utils/numbers.js +26 -70
  194. package/dist/src/utils/numbers.js.map +1 -1
  195. package/dist/src/utils/numbers.test.js +46 -42
  196. package/dist/src/utils/numbers.test.js.map +1 -1
  197. package/dist/src/utils/siww.d.ts +1 -0
  198. package/dist/src/utils/siww.d.ts.map +1 -1
  199. package/dist/src/utils/siww.js +50 -12
  200. package/dist/src/utils/siww.js.map +1 -1
  201. package/dist/src/utils/wagmi.d.ts +3 -0
  202. package/dist/src/utils/wagmi.d.ts.map +1 -0
  203. package/dist/src/utils/wagmi.js +7 -0
  204. package/dist/src/utils/wagmi.js.map +1 -0
  205. package/dist/src/wallet/index.d.ts +1 -1
  206. package/dist/src/wallet/index.d.ts.map +1 -1
  207. package/dist/src/wallet/index.js +1 -1
  208. package/dist/src/wallet/index.js.map +1 -1
  209. package/package.json +11 -8
  210. package/src/api/auth.ts +8 -4
  211. package/src/api/client.ts +11 -2
  212. package/src/api/portal.ts +11 -14
  213. package/src/components/Dropdown/ConnectedTrigger.tsx +52 -32
  214. package/src/components/Dropdown/Content.tsx +26 -121
  215. package/src/components/Dropdown/DisconnectedTrigger.tsx +2 -1
  216. package/src/components/Dropdown/Dropdown.tsx +29 -17
  217. package/src/components/Dropdown/ListingItem.tsx +176 -0
  218. package/src/components/Dropdown/NestedViewLayout.tsx +87 -0
  219. package/src/components/Dropdown/README.md +10 -18
  220. package/src/components/Dropdown/Receive/Receive.tsx +144 -0
  221. package/src/components/Dropdown/Root/AccountAddressActions.tsx +99 -0
  222. package/src/components/Dropdown/Root/AccountBalance.tsx +75 -0
  223. package/src/components/Dropdown/Root/AccountBtcListing.tsx +52 -0
  224. package/src/components/Dropdown/Root/AccountError.tsx +34 -0
  225. package/src/components/Dropdown/Root/AccountMusdListing.tsx +45 -0
  226. package/src/components/Dropdown/Root/AccountOtherAssets.tsx +85 -0
  227. package/src/components/Dropdown/Root/Root.tsx +77 -0
  228. package/src/components/Dropdown/Root/WalletAddress.tsx +123 -0
  229. package/src/components/Dropdown/Root/WelcomeBlock.tsx +173 -0
  230. package/src/components/Dropdown/SlotNumber.tsx +131 -0
  231. package/src/components/Dropdown/TestnetTopBanner.tsx +32 -0
  232. package/src/config.ts +88 -20
  233. package/src/constants.ts +12 -4
  234. package/src/hooks/index.ts +7 -0
  235. package/src/hooks/useAssetsConversionRates.ts +79 -0
  236. package/src/hooks/useAuthenticateWithWallet.ts +30 -14
  237. package/src/hooks/useBorrowData.ts +246 -0
  238. package/src/hooks/useCreateAccount.ts +29 -2
  239. package/src/hooks/useGetCurrentAccount.ts +5 -7
  240. package/src/hooks/useLinkAccount.ts +37 -4
  241. package/src/hooks/useRefreshPassport.ts +56 -0
  242. package/src/hooks/useSignInWithWallet.ts +2 -2
  243. package/src/hooks/useSignUpWithWallet.ts +2 -2
  244. package/src/hooks/useTokensBalances.ts +265 -0
  245. package/src/hooks/useValidateMezoId.ts +31 -0
  246. package/src/hooks/useWalletAccount.ts +32 -20
  247. package/src/hooks/useWatchTransferEvents.ts +74 -0
  248. package/src/index.ts +12 -1
  249. package/src/lib/contracts/index.ts +99 -0
  250. package/src/lib/contracts/priceOracle.ts +53 -0
  251. package/src/provider.ts +11 -3
  252. package/src/stores/dropdownStore.ts +20 -0
  253. package/src/utils/address.test.ts +10 -6
  254. package/src/utils/address.ts +5 -3
  255. package/src/utils/assets.test.ts +57 -0
  256. package/src/utils/assets.ts +103 -0
  257. package/src/utils/currency.test.ts +77 -1
  258. package/src/utils/currency.ts +35 -9
  259. package/src/utils/mezoId.ts +51 -0
  260. package/src/utils/number2.ts +419 -0
  261. package/src/utils/numbers.test.ts +49 -42
  262. package/src/utils/numbers.ts +33 -95
  263. package/src/utils/siww.ts +71 -16
  264. package/src/utils/wagmi.ts +12 -0
  265. package/src/wallet/index.ts +3 -2
  266. package/dist/src/components/Dropdown/AccountAddress.d.ts +0 -8
  267. package/dist/src/components/Dropdown/AccountAddress.d.ts.map +0 -1
  268. package/dist/src/components/Dropdown/AccountAddress.js +0 -58
  269. package/dist/src/components/Dropdown/AccountAddress.js.map +0 -1
  270. package/dist/src/components/Dropdown/AccountAssets.d.ts +0 -14
  271. package/dist/src/components/Dropdown/AccountAssets.d.ts.map +0 -1
  272. package/dist/src/components/Dropdown/AccountAssets.js +0 -44
  273. package/dist/src/components/Dropdown/AccountAssets.js.map +0 -1
  274. package/dist/src/components/Dropdown/AccountBalance.d.ts +0 -7
  275. package/dist/src/components/Dropdown/AccountBalance.d.ts.map +0 -1
  276. package/dist/src/components/Dropdown/AccountBalance.js +0 -18
  277. package/dist/src/components/Dropdown/AccountBalance.js.map +0 -1
  278. package/dist/src/components/Dropdown/WelcomeBlock.d.ts +0 -8
  279. package/dist/src/components/Dropdown/WelcomeBlock.d.ts.map +0 -1
  280. package/dist/src/components/Dropdown/WelcomeBlock.js +0 -44
  281. package/dist/src/components/Dropdown/WelcomeBlock.js.map +0 -1
  282. package/dist/src/hooks/useAssetsUSDConversion.d.ts +0 -8
  283. package/dist/src/hooks/useAssetsUSDConversion.d.ts.map +0 -1
  284. package/dist/src/hooks/useAssetsUSDConversion.js +0 -21
  285. package/dist/src/hooks/useAssetsUSDConversion.js.map +0 -1
  286. package/dist/src/hooks/useDropdownData.d.ts +0 -44
  287. package/dist/src/hooks/useDropdownData.d.ts.map +0 -1
  288. package/dist/src/hooks/useDropdownData.js +0 -73
  289. package/dist/src/hooks/useDropdownData.js.map +0 -1
  290. package/dist/src/utils/cryptoAssets.d.ts +0 -28
  291. package/dist/src/utils/cryptoAssets.d.ts.map +0 -1
  292. package/dist/src/utils/cryptoAssets.js +0 -73
  293. package/dist/src/utils/cryptoAssets.js.map +0 -1
  294. package/dist/src/utils/cryptoAssets.test.d.ts +0 -2
  295. package/dist/src/utils/cryptoAssets.test.d.ts.map +0 -1
  296. package/dist/src/utils/cryptoAssets.test.js +0 -49
  297. package/dist/src/utils/cryptoAssets.test.js.map +0 -1
  298. package/src/components/Dropdown/AccountAddress.tsx +0 -111
  299. package/src/components/Dropdown/AccountAssets.tsx +0 -110
  300. package/src/components/Dropdown/AccountBalance.tsx +0 -38
  301. package/src/components/Dropdown/WelcomeBlock.tsx +0 -92
  302. package/src/hooks/useAssetsUSDConversion.ts +0 -31
  303. package/src/hooks/useDropdownData.ts +0 -130
  304. package/src/utils/cryptoAssets.test.ts +0 -59
  305. package/src/utils/cryptoAssets.ts +0 -93
@@ -0,0 +1,75 @@
1
+ import React from "react"
2
+ import { BlockProps, useStyletron } from "@mezo-org/mezo-clay"
3
+ import { formatUnits } from "viem"
4
+ import ListingItem from "../ListingItem"
5
+ import { useTokensBalances } from "../../../hooks/useTokensBalances"
6
+ import { useBorrowData } from "../../../hooks/useBorrowData"
7
+ import AccountError from "./AccountError"
8
+ import { CONVERSION_RATE_DECIMALS } from "../../../hooks/useAssetsConversionRates"
9
+ import { usePassportContext } from "../../../hooks/usePassportContext"
10
+
11
+ type AccountBalanceProps = Omit<BlockProps, "children">
12
+
13
+ export default function AccountBalance(props: AccountBalanceProps) {
14
+ const { overrides, ...restProps } = props
15
+ const [, theme] = useStyletron()
16
+ const { nativeBalanceRefetchInterval } = usePassportContext()
17
+
18
+ const {
19
+ data: tokensBalancesData,
20
+ isError: isTokensBalancesError,
21
+ isPending: isTokensBalancesDataPending,
22
+ error: tokensBalancesError,
23
+ } = useTokensBalances({
24
+ queryOptions: {
25
+ refetchInterval: nativeBalanceRefetchInterval,
26
+ },
27
+ })
28
+ const {
29
+ data: borrowData,
30
+ isError: isBorrowDataError,
31
+ isPending: isBorrowDataPending,
32
+ error: borrowDataError,
33
+ } = useBorrowData()
34
+
35
+ if (isTokensBalancesDataPending || isBorrowDataPending) {
36
+ return <ListingItem isLoading overrides={overrides} />
37
+ }
38
+
39
+ if (isTokensBalancesError || isBorrowDataError) {
40
+ console.log("isTokensBalancesError: ", isTokensBalancesError)
41
+ console.log("tokensBalancesError: ", tokensBalancesError)
42
+ console.log("isBorrowDataError: ", isBorrowDataError)
43
+ console.log("borrowDataError: ", borrowDataError)
44
+
45
+ return (
46
+ <AccountError
47
+ padding={`${theme.sizing.scale500} ${theme.sizing.scale800}`}
48
+ topic="account balance"
49
+ overrides={overrides}
50
+ />
51
+ )
52
+ }
53
+
54
+ const totalBalanceInUsd = Object.values(tokensBalancesData).reduce(
55
+ (acc, tokenBalance) => acc + tokenBalance.usd.value,
56
+ 0n,
57
+ )
58
+
59
+ const totalBalanceNumber = Number(
60
+ formatUnits(totalBalanceInUsd, CONVERSION_RATE_DECIMALS),
61
+ )
62
+
63
+ const totalDebtNumber = Number(borrowData.debtInUsd.formatted)
64
+
65
+ return (
66
+ <ListingItem
67
+ label="Total assets"
68
+ value={totalBalanceNumber}
69
+ subLabel="Total liabilities"
70
+ subValue={totalDebtNumber}
71
+ overrides={overrides}
72
+ {...restProps}
73
+ />
74
+ )
75
+ }
@@ -0,0 +1,52 @@
1
+ import React from "react"
2
+ import { BitcoinCircle, BlockProps } from "@mezo-org/mezo-clay"
3
+ import ListingItem from "../ListingItem"
4
+ import { getAsset } from "../../../utils/assets"
5
+ import { useBorrowData } from "../../../hooks/useBorrowData"
6
+ import { useTokensBalances } from "../../../hooks/useTokensBalances"
7
+ import AccountError from "./AccountError"
8
+ import { usePassportContext } from "../../../hooks/usePassportContext"
9
+
10
+ type AccountBTCListingProps = Omit<BlockProps, "children">
11
+
12
+ export default function AccountBTCListing(props: AccountBTCListingProps) {
13
+ const { nativeBalanceRefetchInterval } = usePassportContext()
14
+
15
+ const {
16
+ data: borrowData,
17
+ isError: isBorrowDataError,
18
+ isPending: isBorrowDataPending,
19
+ } = useBorrowData()
20
+
21
+ const {
22
+ data: tokensBalancesData,
23
+ isError: isTokensBalancesError,
24
+ isPending: isTokensBalancesPending,
25
+ } = useTokensBalances({
26
+ queryOptions: {
27
+ refetchInterval: nativeBalanceRefetchInterval,
28
+ },
29
+ })
30
+
31
+ if (isTokensBalancesError || isBorrowDataError) {
32
+ return <AccountError topic="Bitcoin balance" />
33
+ }
34
+
35
+ if (isTokensBalancesPending || isBorrowDataPending) {
36
+ return <ListingItem isLoading />
37
+ }
38
+
39
+ const btcBalance = Number(tokensBalancesData.BTC.usd.formatted)
40
+ const lockedCollateral = Number(borrowData.collateral.usd.formatted)
41
+
42
+ return (
43
+ <ListingItem
44
+ icon={<BitcoinCircle />}
45
+ label={getAsset("BTC").name}
46
+ value={btcBalance}
47
+ subLabel="Locked collateral"
48
+ subValue={lockedCollateral}
49
+ {...props}
50
+ />
51
+ )
52
+ }
@@ -0,0 +1,34 @@
1
+ import React from "react"
2
+ import {
3
+ BlockProps,
4
+ LabelSmall,
5
+ mergeOverrides,
6
+ useStyletron,
7
+ } from "@mezo-org/mezo-clay"
8
+
9
+ type AccountErrorProps = {
10
+ topic: string
11
+ } & BlockProps
12
+
13
+ export default function AccountError(props: AccountErrorProps) {
14
+ const { topic, overrides, ...restProps } = props
15
+
16
+ const [, theme] = useStyletron()
17
+
18
+ return (
19
+ <LabelSmall
20
+ padding={`${theme.sizing.scale600} ${theme.sizing.scale800}`}
21
+ color="negative"
22
+ overrides={mergeOverrides(overrides, {
23
+ Block: {
24
+ style: {
25
+ lineHeight: theme.sizing.scale700,
26
+ },
27
+ },
28
+ })}
29
+ {...restProps}
30
+ >
31
+ An error occured loading {topic}.
32
+ </LabelSmall>
33
+ )
34
+ }
@@ -0,0 +1,45 @@
1
+ import React from "react"
2
+ import { BlockProps, MUsdCircle02 } from "@mezo-org/mezo-clay"
3
+ import ListingItem from "../ListingItem"
4
+ import { getAsset } from "../../../utils/assets"
5
+ import { useBorrowData } from "../../../hooks/useBorrowData"
6
+ import { useTokensBalances } from "../../../hooks/useTokensBalances"
7
+ import AccountError from "./AccountError"
8
+
9
+ export default function AccountMusdListing(
10
+ props: Omit<BlockProps, "children">,
11
+ ) {
12
+ const {
13
+ data: borrowData,
14
+ isError: isBorrowDataError,
15
+ isPending: isBorrowDataPending,
16
+ } = useBorrowData()
17
+
18
+ const {
19
+ data: tokensBalancesData,
20
+ isError: isTokensBalancesError,
21
+ isPending: isTokensBalancesPending,
22
+ } = useTokensBalances()
23
+
24
+ if (isBorrowDataError || isTokensBalancesError) {
25
+ return <AccountError topic="MUSD balance" />
26
+ }
27
+
28
+ if (isBorrowDataPending || isTokensBalancesPending) {
29
+ return <ListingItem isLoading />
30
+ }
31
+
32
+ const musdBalance = Number(tokensBalancesData.MUSD.usd.formatted)
33
+ const lockedCollateral = Number(borrowData.debtInUsd.formatted)
34
+
35
+ return (
36
+ <ListingItem
37
+ icon={<MUsdCircle02 />}
38
+ label={getAsset("MUSD").name}
39
+ value={musdBalance}
40
+ subLabel="Borrowed"
41
+ subValue={lockedCollateral}
42
+ {...props}
43
+ />
44
+ )
45
+ }
@@ -0,0 +1,85 @@
1
+ import React from "react"
2
+ import {
3
+ useStyletron,
4
+ CoinsStacked02,
5
+ mergeOverrides,
6
+ BlockProps,
7
+ } from "@mezo-org/mezo-clay"
8
+ import { formatUnits } from "viem"
9
+ import ListingItem from "../ListingItem"
10
+ import { useTokensBalances } from "../../../hooks/useTokensBalances"
11
+ import AccountError from "./AccountError"
12
+ import { CONVERSION_RATE_DECIMALS } from "../../../hooks/useAssetsConversionRates"
13
+
14
+ type AccountOtherAssetsProps = {
15
+ onClick?: () => void
16
+ } & Omit<BlockProps, "children">
17
+
18
+ export default function AccountOtherAssets(props: AccountOtherAssetsProps) {
19
+ const { onClick, overrides, ...restProps } = props
20
+
21
+ const [, theme] = useStyletron()
22
+
23
+ const {
24
+ data: tokensBalancesData,
25
+ isPending: isTokensBalancesPending,
26
+ isError: isTokensBalancesError,
27
+ } = useTokensBalances()
28
+
29
+ if (isTokensBalancesError) {
30
+ return (
31
+ <AccountError
32
+ topic="other assets"
33
+ paddingTop={theme.sizing.scale100}
34
+ paddingBottom={theme.sizing.scale100}
35
+ overrides={overrides}
36
+ />
37
+ )
38
+ }
39
+
40
+ if (isTokensBalancesPending) {
41
+ return <ListingItem isLoading overrides={overrides} />
42
+ }
43
+
44
+ const otherAssets = Object.values(tokensBalancesData)
45
+ .filter((asset) => !["BTC", "MUSD"].includes(asset.symbol))
46
+ .filter((asset) => asset.value > 0n)
47
+
48
+ const assetsCount = otherAssets.length
49
+ const totalAssetsInUsd = Number(
50
+ formatUnits(
51
+ otherAssets.reduce((total, asset) => total + asset.usd.value, 0n),
52
+ CONVERSION_RATE_DECIMALS,
53
+ ),
54
+ )
55
+
56
+ let label = "No other assets"
57
+ if (assetsCount === 1) label = "1 more asset"
58
+ if (assetsCount > 1) label = `${assetsCount} more assets`
59
+
60
+ return (
61
+ <ListingItem
62
+ icon={<CoinsStacked02 color={theme.colors.contentPrimary} />}
63
+ label={label}
64
+ value={totalAssetsInUsd}
65
+ overrides={mergeOverrides(
66
+ {
67
+ Block: {
68
+ props: {
69
+ $as: "button",
70
+ onClick,
71
+ },
72
+ style: {
73
+ borderWidth: 0,
74
+ cursor: "pointer",
75
+ backgroundColor: "transparent",
76
+ minHeight: "56px",
77
+ },
78
+ },
79
+ },
80
+ overrides,
81
+ )}
82
+ {...restProps}
83
+ />
84
+ )
85
+ }
@@ -0,0 +1,77 @@
1
+ import { Block, Button, LogOut01, useStyletron } from "@mezo-org/mezo-clay"
2
+ import React, { useCallback } from "react"
3
+ import { useDisconnect } from "wagmi"
4
+ import { useSignOut } from "../../../hooks"
5
+ import WalletAddress from "./WalletAddress"
6
+ import AccountBalance from "./AccountBalance"
7
+ import WelcomeBlock from "./WelcomeBlock"
8
+ import AccountAddressActions from "./AccountAddressActions"
9
+ import AccountOtherAssets from "./AccountOtherAssets"
10
+ import AccountBtcListing from "./AccountBtcListing"
11
+ import AccountMusdListing from "./AccountMusdListing"
12
+
13
+ type RootProps = {
14
+ onSignOut?: () => void
15
+ onOtherAssetsClick?: () => void
16
+ }
17
+
18
+ export default function Root(props: RootProps) {
19
+ const { onSignOut, onOtherAssetsClick } = props
20
+
21
+ const [, theme] = useStyletron()
22
+
23
+ const { disconnect } = useDisconnect()
24
+ const { signOut } = useSignOut()
25
+
26
+ const handleLogOut = useCallback(() => {
27
+ if (onSignOut) {
28
+ onSignOut()
29
+ return
30
+ }
31
+ signOut()
32
+ disconnect()
33
+ }, [signOut, disconnect, onSignOut])
34
+
35
+ const overridesWithDivider = {
36
+ Block: {
37
+ style: {
38
+ borderBottomWidth: "1px",
39
+ borderBottomStyle: "solid",
40
+ borderBottomColor: theme.colors.borderOpaque,
41
+ },
42
+ },
43
+ }
44
+
45
+ return (
46
+ <Block display="inline-flex" flexDirection="column">
47
+ <WelcomeBlock />
48
+
49
+ <AccountAddressActions overrides={overridesWithDivider} />
50
+
51
+ <WalletAddress overrides={overridesWithDivider} />
52
+
53
+ <AccountBalance overrides={overridesWithDivider} />
54
+
55
+ <AccountBtcListing />
56
+
57
+ <AccountMusdListing />
58
+
59
+ <AccountOtherAssets
60
+ onClick={onOtherAssetsClick}
61
+ overrides={overridesWithDivider}
62
+ />
63
+
64
+ <Block padding={theme.sizing.scale300}>
65
+ <Button
66
+ size="small"
67
+ shape="pill"
68
+ kind="tertiary"
69
+ startEnhancer={<LogOut01 color="currentColor" size={16} />}
70
+ onClick={handleLogOut}
71
+ >
72
+ Sign out
73
+ </Button>
74
+ </Block>
75
+ </Block>
76
+ )
77
+ }
@@ -0,0 +1,123 @@
1
+ import {
2
+ BitcoinCircle,
3
+ Block,
4
+ BlockProps,
5
+ EthCircle,
6
+ LabelMedium,
7
+ LabelXSmall,
8
+ mergeOverrides,
9
+ MonoLabelXSmall,
10
+ useStyletron,
11
+ } from "@mezo-org/mezo-clay"
12
+ import React, { useState } from "react"
13
+ import { useCopyToClipboard } from "usehooks-ts"
14
+ import { usePassportContext } from "../../../hooks/usePassportContext"
15
+ import { getAddressExplorerUrl, trimAddress } from "../../../utils/address"
16
+ import useWalletAccount from "../../../hooks/useWalletAccount"
17
+
18
+ export default function WalletAddress(props: BlockProps) {
19
+ const { overrides, ...restProps } = props
20
+ const { walletAddress, networkFamily } = useWalletAccount()
21
+ const { environment = "mainnet" } = usePassportContext()
22
+ const [, theme] = useStyletron()
23
+ const [, copy] = useCopyToClipboard()
24
+ const [isCopiedMessageVisible, setIsCopiedMessageVisible] = useState(false)
25
+
26
+ const handleCopyAddress = () => {
27
+ copy(walletAddress!)
28
+ setIsCopiedMessageVisible(true)
29
+
30
+ setTimeout(() => {
31
+ setIsCopiedMessageVisible(false)
32
+ }, 2000)
33
+ }
34
+
35
+ const blockExplorerUrl = getAddressExplorerUrl(
36
+ walletAddress!,
37
+ networkFamily,
38
+ environment === "testnet",
39
+ )
40
+ const trimmedAddress = trimAddress(walletAddress!)
41
+ const AccountIcon = networkFamily === "bitcoin" ? BitcoinCircle : EthCircle
42
+
43
+ return (
44
+ <Block
45
+ as="button"
46
+ onClick={handleCopyAddress}
47
+ display="flex"
48
+ alignItems="center"
49
+ backgroundColor="transparent"
50
+ padding={`${theme.sizing.scale800} ${theme.sizing.scale700}`}
51
+ overrides={mergeOverrides(
52
+ {
53
+ Block: {
54
+ style: {
55
+ gap: theme.sizing.scale700,
56
+ borderWidth: 0,
57
+ cursor: "pointer",
58
+ ":hover": {
59
+ backgroundColor: theme.colors.backgroundTertiary,
60
+ },
61
+ },
62
+ },
63
+ },
64
+ overrides,
65
+ )}
66
+ {...restProps}
67
+ >
68
+ <AccountIcon
69
+ color={theme.colors.black}
70
+ size={theme.sizing.scale800}
71
+ overrides={{
72
+ Svg: {
73
+ style: {
74
+ backgroundColor: theme.colors.black,
75
+ overflow: "hidden",
76
+ borderRadius: theme.borders.radius200,
77
+ },
78
+ },
79
+ }}
80
+ />
81
+ <Block
82
+ display="flex"
83
+ flexDirection="column"
84
+ alignItems="flex-start"
85
+ overrides={{
86
+ Block: {
87
+ style: {
88
+ gap: theme.sizing.scale100,
89
+ },
90
+ },
91
+ }}
92
+ >
93
+ <LabelMedium>Connected Wallet</LabelMedium>
94
+
95
+ {isCopiedMessageVisible ? (
96
+ <LabelXSmall color={theme.colors.contentSecondary}>
97
+ Copied address to clipboard
98
+ </LabelXSmall>
99
+ ) : (
100
+ <Block
101
+ as="a"
102
+ color={theme.colors.contentSecondary}
103
+ href={blockExplorerUrl}
104
+ target="_blank"
105
+ overrides={{
106
+ Block: {
107
+ style: {
108
+ color: "inherit",
109
+ textDecoration: "none",
110
+ ":hover": {
111
+ textDecoration: "underline",
112
+ },
113
+ },
114
+ },
115
+ }}
116
+ >
117
+ <MonoLabelXSmall>{trimmedAddress}</MonoLabelXSmall>
118
+ </Block>
119
+ )}
120
+ </Block>
121
+ </Block>
122
+ )
123
+ }
@@ -0,0 +1,173 @@
1
+ import {
2
+ Block,
3
+ BlockProps,
4
+ HeadingMedium,
5
+ LabelLarge,
6
+ Mats,
7
+ mergeOverrides,
8
+ Skeleton,
9
+ useStyletron,
10
+ } from "@mezo-org/mezo-clay"
11
+ import React from "react"
12
+ import DefaultAvatar from "../../../assets/DefaultAvatar"
13
+ import { useGetCurrentAccount } from "../../../hooks"
14
+ import { formatNumberToCompactString } from "../../../utils/numbers"
15
+ import AccountError from "./AccountError"
16
+ import { usePassportContext } from "../../../hooks/usePassportContext"
17
+ import SlotNumber from "../SlotNumber"
18
+
19
+ const DOT_DELIMITER_REGEX = /(?=\.)/
20
+
21
+ function WelcomeBlockSkeleton() {
22
+ const [, theme] = useStyletron()
23
+
24
+ return (
25
+ <Block
26
+ display="flex"
27
+ alignItems="center"
28
+ padding={theme.sizing.scale600}
29
+ paddingTop={theme.sizing.scale900}
30
+ paddingBottom={theme.sizing.scale800}
31
+ overrides={{
32
+ Block: {
33
+ style: {
34
+ gap: theme.sizing.scale600,
35
+ },
36
+ },
37
+ }}
38
+ >
39
+ <Skeleton
40
+ animation
41
+ width={theme.sizing.scale1200}
42
+ height={theme.sizing.scale1200}
43
+ overrides={{
44
+ Root: {
45
+ style: {
46
+ borderRadius: "100%",
47
+ },
48
+ },
49
+ }}
50
+ />
51
+
52
+ <Block
53
+ display="flex"
54
+ flexDirection="column"
55
+ flex={1}
56
+ overrides={{
57
+ Block: {
58
+ style: {
59
+ gap: theme.sizing.scale100,
60
+ },
61
+ },
62
+ }}
63
+ >
64
+ <Skeleton animation width="60%" height={theme.sizing.scale900} />
65
+ <Skeleton animation width="40%" height={theme.sizing.scale800} />
66
+ </Block>
67
+ </Block>
68
+ )
69
+ }
70
+
71
+ type WelcomeBlockProps = BlockProps
72
+
73
+ export default function WelcomeBlock(props: WelcomeBlockProps) {
74
+ const { overrides, ...restProps } = props
75
+ const { accountDataRefetchInterval } = usePassportContext()
76
+
77
+ const { data, isError, isPending } = useGetCurrentAccount({
78
+ staleTime: accountDataRefetchInterval,
79
+ refetchInterval: accountDataRefetchInterval,
80
+ })
81
+ const [, theme] = useStyletron()
82
+
83
+ if (isError) {
84
+ return (
85
+ <AccountError
86
+ padding={theme.sizing.scale600}
87
+ paddingTop={theme.sizing.scale900}
88
+ paddingBottom={theme.sizing.scale800}
89
+ marginBottom={theme.sizing.scale300}
90
+ topic="account information"
91
+ />
92
+ )
93
+ }
94
+
95
+ if (isPending) {
96
+ return <WelcomeBlockSkeleton />
97
+ }
98
+
99
+ const [mezoId, mezoIdSuffix] = (data.mezoId ?? "").split(DOT_DELIMITER_REGEX)
100
+
101
+ return (
102
+ <Block
103
+ display="flex"
104
+ alignItems="center"
105
+ paddingLeft={theme.sizing.scale600}
106
+ paddingRight={theme.sizing.scale600}
107
+ paddingTop={theme.sizing.scale900}
108
+ paddingBottom={theme.sizing.scale800}
109
+ overrides={mergeOverrides(overrides, {
110
+ Block: {
111
+ style: {
112
+ gap: theme.sizing.scale600,
113
+ },
114
+ },
115
+ })}
116
+ {...restProps}
117
+ >
118
+ <Block
119
+ as={DefaultAvatar}
120
+ width={theme.sizing.scale1200}
121
+ height={theme.sizing.scale1200}
122
+ overrides={{
123
+ Block: {
124
+ style: {
125
+ borderRadius: "100%",
126
+ },
127
+ },
128
+ }}
129
+ />
130
+
131
+ <Block display="flex" flexDirection="column">
132
+ {mezoId && mezoIdSuffix && (
133
+ <HeadingMedium as="span">
134
+ <Block as="span">{mezoId}</Block>
135
+ <Block as="span" color={theme.colors.contentSecondary}>
136
+ {mezoIdSuffix}
137
+ </Block>
138
+ </HeadingMedium>
139
+ )}
140
+
141
+ <Block
142
+ display="flex"
143
+ alignItems="center"
144
+ overrides={{
145
+ Block: {
146
+ style: {
147
+ gap: theme.sizing.scale100,
148
+ },
149
+ },
150
+ }}
151
+ >
152
+ <Mats
153
+ size={theme.sizing.scale600}
154
+ overrides={{
155
+ Svg: {
156
+ style: {
157
+ margin: theme.sizing.scale100, // To reduce gap
158
+ },
159
+ },
160
+ }}
161
+ />
162
+
163
+ <LabelLarge color={theme.colors.contentPrimary}>
164
+ <SlotNumber formatFunction={formatNumberToCompactString}>
165
+ {data.mats.totalMats}
166
+ </SlotNumber>{" "}
167
+ mats
168
+ </LabelLarge>
169
+ </Block>
170
+ </Block>
171
+ </Block>
172
+ )
173
+ }