@mezo-org/passport 0.4.0-dev.82 → 0.4.0-dev.84

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 (173) hide show
  1. package/dist/src/components/Dropdown/Content.d.ts +0 -15
  2. package/dist/src/components/Dropdown/Content.d.ts.map +1 -1
  3. package/dist/src/components/Dropdown/Content.js +3 -3
  4. package/dist/src/components/Dropdown/Content.js.map +1 -1
  5. package/dist/src/components/Dropdown/Dropdown.d.ts +0 -4
  6. package/dist/src/components/Dropdown/Dropdown.d.ts.map +1 -1
  7. package/dist/src/components/Dropdown/Dropdown.js +10 -36
  8. package/dist/src/components/Dropdown/Dropdown.js.map +1 -1
  9. package/dist/src/components/Dropdown/ListingItem.d.ts +8 -7
  10. package/dist/src/components/Dropdown/ListingItem.d.ts.map +1 -1
  11. package/dist/src/components/Dropdown/ListingItem.js +36 -28
  12. package/dist/src/components/Dropdown/ListingItem.js.map +1 -1
  13. package/dist/src/components/Dropdown/NestedViewLayout.d.ts +2 -1
  14. package/dist/src/components/Dropdown/NestedViewLayout.d.ts.map +1 -1
  15. package/dist/src/components/Dropdown/NestedViewLayout.js +13 -15
  16. package/dist/src/components/Dropdown/NestedViewLayout.js.map +1 -1
  17. package/dist/src/components/Dropdown/Receive/Receive.d.ts +1 -4
  18. package/dist/src/components/Dropdown/Receive/Receive.d.ts.map +1 -1
  19. package/dist/src/components/Dropdown/Receive/Receive.js +30 -19
  20. package/dist/src/components/Dropdown/Receive/Receive.js.map +1 -1
  21. package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts +2 -5
  22. package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts.map +1 -1
  23. package/dist/src/components/Dropdown/Root/AccountAddressActions.js +13 -12
  24. package/dist/src/components/Dropdown/Root/AccountAddressActions.js.map +1 -1
  25. package/dist/src/components/Dropdown/Root/AccountBalance.d.ts +2 -4
  26. package/dist/src/components/Dropdown/Root/AccountBalance.d.ts.map +1 -1
  27. package/dist/src/components/Dropdown/Root/AccountBalance.js +24 -8
  28. package/dist/src/components/Dropdown/Root/AccountBalance.js.map +1 -1
  29. package/dist/src/components/Dropdown/Root/AccountBtcListing.d.ts +6 -0
  30. package/dist/src/components/Dropdown/Root/AccountBtcListing.d.ts.map +1 -0
  31. package/dist/src/components/Dropdown/Root/AccountBtcListing.js +27 -0
  32. package/dist/src/components/Dropdown/Root/AccountBtcListing.js.map +1 -0
  33. package/dist/src/components/Dropdown/Root/AccountError.d.ts +8 -0
  34. package/dist/src/components/Dropdown/Root/AccountError.d.ts.map +1 -0
  35. package/dist/src/components/Dropdown/Root/AccountError.js +17 -0
  36. package/dist/src/components/Dropdown/Root/AccountError.js.map +1 -0
  37. package/dist/src/components/Dropdown/Root/AccountMusdListing.d.ts +4 -0
  38. package/dist/src/components/Dropdown/Root/AccountMusdListing.d.ts.map +1 -0
  39. package/dist/src/components/Dropdown/Root/AccountMusdListing.js +21 -0
  40. package/dist/src/components/Dropdown/Root/AccountMusdListing.js.map +1 -0
  41. package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts +2 -3
  42. package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts.map +1 -1
  43. package/dist/src/components/Dropdown/Root/AccountOtherAssets.js +34 -39
  44. package/dist/src/components/Dropdown/Root/AccountOtherAssets.js.map +1 -1
  45. package/dist/src/components/Dropdown/Root/Root.d.ts +0 -15
  46. package/dist/src/components/Dropdown/Root/Root.d.ts.map +1 -1
  47. package/dist/src/components/Dropdown/Root/Root.js +22 -34
  48. package/dist/src/components/Dropdown/Root/Root.js.map +1 -1
  49. package/dist/src/components/Dropdown/Root/WalletAddress.d.ts +2 -6
  50. package/dist/src/components/Dropdown/Root/WalletAddress.d.ts.map +1 -1
  51. package/dist/src/components/Dropdown/Root/WalletAddress.js +37 -34
  52. package/dist/src/components/Dropdown/Root/WalletAddress.js.map +1 -1
  53. package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts +2 -4
  54. package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts.map +1 -1
  55. package/dist/src/components/Dropdown/Root/WelcomeBlock.js +60 -16
  56. package/dist/src/components/Dropdown/Root/WelcomeBlock.js.map +1 -1
  57. package/dist/src/components/Dropdown/SlotNumber.d.ts +19 -0
  58. package/dist/src/components/Dropdown/SlotNumber.d.ts.map +1 -0
  59. package/dist/src/components/Dropdown/SlotNumber.js +67 -0
  60. package/dist/src/components/Dropdown/SlotNumber.js.map +1 -0
  61. package/dist/src/config.d.ts +0 -1
  62. package/dist/src/config.d.ts.map +1 -1
  63. package/dist/src/config.js +1 -9
  64. package/dist/src/config.js.map +1 -1
  65. package/dist/src/hooks/useAssetsConversionRates.d.ts +8 -13
  66. package/dist/src/hooks/useAssetsConversionRates.d.ts.map +1 -1
  67. package/dist/src/hooks/useAssetsConversionRates.js +44 -67
  68. package/dist/src/hooks/useAssetsConversionRates.js.map +1 -1
  69. package/dist/src/hooks/useAuthenticateWithWallet.d.ts.map +1 -1
  70. package/dist/src/hooks/useAuthenticateWithWallet.js +1 -1
  71. package/dist/src/hooks/useAuthenticateWithWallet.js.map +1 -1
  72. package/dist/src/hooks/useBorrowData.d.ts +30 -4
  73. package/dist/src/hooks/useBorrowData.d.ts.map +1 -1
  74. package/dist/src/hooks/useBorrowData.js +53 -11
  75. package/dist/src/hooks/useBorrowData.js.map +1 -1
  76. package/dist/src/hooks/useCreateAccount.d.ts.map +1 -1
  77. package/dist/src/hooks/useCreateAccount.js +3 -3
  78. package/dist/src/hooks/useCreateAccount.js.map +1 -1
  79. package/dist/src/hooks/useGetCurrentAccount.d.ts.map +1 -1
  80. package/dist/src/hooks/useGetCurrentAccount.js +4 -6
  81. package/dist/src/hooks/useGetCurrentAccount.js.map +1 -1
  82. package/dist/src/hooks/useLinkAccount.d.ts.map +1 -1
  83. package/dist/src/hooks/useLinkAccount.js +3 -3
  84. package/dist/src/hooks/useLinkAccount.js.map +1 -1
  85. package/dist/src/hooks/useTokensBalances.d.ts +36 -35
  86. package/dist/src/hooks/useTokensBalances.d.ts.map +1 -1
  87. package/dist/src/hooks/useTokensBalances.js +93 -52
  88. package/dist/src/hooks/useTokensBalances.js.map +1 -1
  89. package/dist/src/hooks/useWalletAccount.d.ts +8 -6
  90. package/dist/src/hooks/useWalletAccount.d.ts.map +1 -1
  91. package/dist/src/hooks/useWalletAccount.js +9 -6
  92. package/dist/src/hooks/useWalletAccount.js.map +1 -1
  93. package/dist/src/lib/contracts/index.d.ts +1 -1
  94. package/dist/src/lib/contracts/index.d.ts.map +1 -1
  95. package/dist/src/lib/contracts/index.js +4 -0
  96. package/dist/src/lib/contracts/index.js.map +1 -1
  97. package/dist/src/provider.d.ts +7 -1
  98. package/dist/src/provider.d.ts.map +1 -1
  99. package/dist/src/provider.js +4 -1
  100. package/dist/src/provider.js.map +1 -1
  101. package/dist/src/utils/assets.d.ts +145 -0
  102. package/dist/src/utils/assets.d.ts.map +1 -0
  103. package/dist/src/utils/assets.js +100 -0
  104. package/dist/src/utils/assets.js.map +1 -0
  105. package/dist/src/utils/assets.test.d.ts +2 -0
  106. package/dist/src/utils/assets.test.d.ts.map +1 -0
  107. package/dist/src/utils/assets.test.js +46 -0
  108. package/dist/src/utils/assets.test.js.map +1 -0
  109. package/dist/src/utils/currency.d.ts +6 -3
  110. package/dist/src/utils/currency.d.ts.map +1 -1
  111. package/dist/src/utils/currency.js +13 -10
  112. package/dist/src/utils/currency.js.map +1 -1
  113. package/dist/src/utils/currency.test.js +44 -2
  114. package/dist/src/utils/currency.test.js.map +1 -1
  115. package/dist/src/utils/numbers.d.ts +13 -53
  116. package/dist/src/utils/numbers.d.ts.map +1 -1
  117. package/dist/src/utils/numbers.js +16 -118
  118. package/dist/src/utils/numbers.js.map +1 -1
  119. package/dist/src/utils/numbers.test.js +24 -142
  120. package/dist/src/utils/numbers.test.js.map +1 -1
  121. package/package.json +2 -1
  122. package/src/components/Dropdown/Content.tsx +3 -48
  123. package/src/components/Dropdown/Dropdown.tsx +7 -58
  124. package/src/components/Dropdown/ListingItem.tsx +155 -59
  125. package/src/components/Dropdown/NestedViewLayout.tsx +32 -20
  126. package/src/components/Dropdown/Receive/Receive.tsx +57 -32
  127. package/src/components/Dropdown/Root/AccountAddressActions.tsx +33 -35
  128. package/src/components/Dropdown/Root/AccountBalance.tsx +54 -16
  129. package/src/components/Dropdown/Root/AccountBtcListing.tsx +52 -0
  130. package/src/components/Dropdown/Root/AccountError.tsx +34 -0
  131. package/src/components/Dropdown/Root/AccountMusdListing.tsx +45 -0
  132. package/src/components/Dropdown/Root/AccountOtherAssets.tsx +63 -46
  133. package/src/components/Dropdown/Root/Root.tsx +28 -98
  134. package/src/components/Dropdown/Root/WalletAddress.tsx +87 -89
  135. package/src/components/Dropdown/Root/WelcomeBlock.tsx +112 -30
  136. package/src/components/Dropdown/SlotNumber.tsx +131 -0
  137. package/src/config.ts +1 -11
  138. package/src/hooks/useAssetsConversionRates.ts +49 -67
  139. package/src/hooks/useAuthenticateWithWallet.ts +7 -5
  140. package/src/hooks/useBorrowData.ts +71 -12
  141. package/src/hooks/useCreateAccount.ts +5 -4
  142. package/src/hooks/useGetCurrentAccount.ts +5 -7
  143. package/src/hooks/useLinkAccount.ts +5 -4
  144. package/src/hooks/useTokensBalances.ts +152 -74
  145. package/src/hooks/useWalletAccount.ts +19 -13
  146. package/src/lib/contracts/index.ts +8 -1
  147. package/src/provider.ts +11 -3
  148. package/src/utils/assets.test.ts +57 -0
  149. package/src/utils/assets.ts +103 -0
  150. package/src/utils/currency.test.ts +76 -2
  151. package/src/utils/currency.ts +20 -15
  152. package/src/utils/numbers.test.ts +29 -180
  153. package/src/utils/numbers.ts +22 -171
  154. package/dist/src/components/Dropdown/Root/AccountAssetItem.d.ts +0 -11
  155. package/dist/src/components/Dropdown/Root/AccountAssetItem.d.ts.map +0 -1
  156. package/dist/src/components/Dropdown/Root/AccountAssetItem.js +0 -9
  157. package/dist/src/components/Dropdown/Root/AccountAssetItem.js.map +0 -1
  158. package/dist/src/hooks/useDropdownData.d.ts +0 -47
  159. package/dist/src/hooks/useDropdownData.d.ts.map +0 -1
  160. package/dist/src/hooks/useDropdownData.js +0 -97
  161. package/dist/src/hooks/useDropdownData.js.map +0 -1
  162. package/dist/src/utils/cryptoAssets.d.ts +0 -44
  163. package/dist/src/utils/cryptoAssets.d.ts.map +0 -1
  164. package/dist/src/utils/cryptoAssets.js +0 -129
  165. package/dist/src/utils/cryptoAssets.js.map +0 -1
  166. package/dist/src/utils/cryptoAssets.test.d.ts +0 -2
  167. package/dist/src/utils/cryptoAssets.test.d.ts.map +0 -1
  168. package/dist/src/utils/cryptoAssets.test.js +0 -67
  169. package/dist/src/utils/cryptoAssets.test.js.map +0 -1
  170. package/src/components/Dropdown/Root/AccountAssetItem.tsx +0 -26
  171. package/src/hooks/useDropdownData.ts +0 -152
  172. package/src/utils/cryptoAssets.test.ts +0 -79
  173. package/src/utils/cryptoAssets.ts +0 -171
@@ -1,25 +1,24 @@
1
1
  import {
2
2
  ArrowNarrowLeft,
3
3
  Block,
4
+ BlockProps,
4
5
  Button,
5
6
  ButtonProps,
6
- Cube01,
7
+ mergeOverrides,
7
8
  useStyletron,
8
9
  } from "@mezo-org/mezo-clay"
9
- import React, { useCallback } from "react"
10
+ import React from "react"
10
11
  import { usePassportContext } from "../../../hooks/usePassportContext"
11
12
  import { getAddressExplorerUrl } from "../../../utils/address"
12
13
  import useDropdownStore, { DropdownView } from "../../../stores/dropdownStore"
13
-
14
- type AccountAddressActionsProps = {
15
- address: string
16
- }
14
+ import useWalletAccount from "../../../hooks/useWalletAccount"
17
15
 
18
16
  const buttonStartEnhancerSize = 12
19
17
 
20
18
  const commonButtonProps: Partial<ButtonProps> = {
21
19
  kind: "secondary",
22
- size: "xsmall",
20
+ size: "small",
21
+ shape: "pill",
23
22
  overrides: {
24
23
  BaseButton: {
25
24
  style: {
@@ -34,50 +33,40 @@ const commonButtonProps: Partial<ButtonProps> = {
34
33
  },
35
34
  }
36
35
 
37
- export default function AccountAddressActions(
38
- props: AccountAddressActionsProps,
39
- ) {
40
- const { address } = props
36
+ export default function AccountAddressActions(props: BlockProps) {
37
+ const { overrides, ...restProps } = props
41
38
 
42
39
  const [, theme] = useStyletron()
43
-
44
40
  const { environment } = usePassportContext()
41
+ const setDropdownView = useDropdownStore((state) => state.setView)
42
+ const handleReceiveClick = () => setDropdownView(DropdownView.RECEIVE)
43
+
44
+ const { data: walletAccountData } = useWalletAccount()
45
+
45
46
  const blockExplorerUrl = getAddressExplorerUrl(
46
- address,
47
+ walletAccountData.accountAddress!,
47
48
  "mezo",
48
49
  environment === "testnet",
49
50
  )
50
51
 
51
- const setDropdownView = useDropdownStore((state) => state.setView)
52
-
53
- const handleReceiveClick = useCallback(() => {
54
- setDropdownView(DropdownView.RECEIVE)
55
- }, [setDropdownView])
56
-
57
52
  return (
58
53
  <Block
59
54
  display="flex"
60
55
  alignItems="center"
61
56
  backgroundColor="transparent"
62
- marginBottom={theme.sizing.scale600}
63
- overrides={{
64
- Block: {
65
- style: {
66
- gap: theme.sizing.scale600,
57
+ padding={`0 ${theme.sizing.scale600} ${theme.sizing.scale800}`}
58
+ overrides={mergeOverrides(
59
+ {
60
+ Block: {
61
+ style: {
62
+ gap: theme.sizing.scale600,
63
+ },
67
64
  },
68
65
  },
69
- }}
66
+ overrides,
67
+ )}
68
+ {...restProps}
70
69
  >
71
- <Button
72
- startEnhancer={<Cube01 size={buttonStartEnhancerSize} />}
73
- $as="a"
74
- href={blockExplorerUrl}
75
- target="_blank"
76
- {...commonButtonProps}
77
- >
78
- View Mezo Explorer
79
- </Button>
80
-
81
70
  <Button
82
71
  onClick={handleReceiveClick}
83
72
  startEnhancer={
@@ -96,6 +85,15 @@ export default function AccountAddressActions(
96
85
  >
97
86
  Receive
98
87
  </Button>
88
+
89
+ <Button
90
+ $as="a"
91
+ href={blockExplorerUrl}
92
+ target="_blank"
93
+ {...commonButtonProps}
94
+ >
95
+ Block Explorer
96
+ </Button>
99
97
  </Block>
100
98
  )
101
99
  }
@@ -1,30 +1,68 @@
1
1
  import React from "react"
2
- import { useStyletron } from "@mezo-org/mezo-clay"
2
+ import { BlockProps, useStyletron } from "@mezo-org/mezo-clay"
3
+ import { formatUnits } from "viem"
3
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"
4
10
 
5
- type AccountBalanceProps = {
6
- totalBalance: string
7
- totalDebt: string
8
- }
11
+ type AccountBalanceProps = Omit<BlockProps, "children">
9
12
 
10
13
  export default function AccountBalance(props: AccountBalanceProps) {
11
- const { totalBalance, totalDebt } = props
12
-
14
+ const { overrides, ...restProps } = props
13
15
  const [, theme] = useStyletron()
16
+ const { nativeBalanceRefetchInterval } = usePassportContext()
17
+
18
+ const {
19
+ data: tokensBalancesData,
20
+ isError: isTokensBalancesError,
21
+ isPending: isTokensBalancesDataPending,
22
+ } = useTokensBalances({
23
+ queryOptions: {
24
+ refetchInterval: nativeBalanceRefetchInterval,
25
+ },
26
+ })
27
+ const {
28
+ data: borrowData,
29
+ isError: isBorrowDataError,
30
+ isPending: isBorrowDataPending,
31
+ } = useBorrowData()
32
+
33
+ if (isTokensBalancesDataPending || isBorrowDataPending) {
34
+ return <ListingItem isLoading overrides={overrides} />
35
+ }
36
+
37
+ if (isTokensBalancesError || isBorrowDataError) {
38
+ return (
39
+ <AccountError
40
+ padding={`${theme.sizing.scale500} ${theme.sizing.scale800}`}
41
+ topic="account balance"
42
+ overrides={overrides}
43
+ />
44
+ )
45
+ }
46
+
47
+ const totalBalanceInUsd = Object.values(tokensBalancesData).reduce(
48
+ (acc, tokenBalance) => acc + tokenBalance.usd.value,
49
+ 0n,
50
+ )
51
+
52
+ const totalBalanceNumber = Number(
53
+ formatUnits(totalBalanceInUsd, CONVERSION_RATE_DECIMALS),
54
+ )
55
+
56
+ const totalDebtNumber = Number(borrowData.debtInUsd.formatted)
14
57
 
15
58
  return (
16
59
  <ListingItem
17
60
  label="Total assets"
18
- value={totalBalance}
61
+ value={totalBalanceNumber}
19
62
  subLabel="Total liabilities"
20
- subValue={totalDebt}
21
- overrides={{
22
- Root: {
23
- style: {
24
- borderBottom: `1px solid ${theme.colors.borderInverseSelected}`,
25
- },
26
- },
27
- }}
63
+ subValue={totalDebtNumber}
64
+ overrides={overrides}
65
+ {...restProps}
28
66
  />
29
67
  )
30
68
  }
@@ -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
+ }
@@ -1,68 +1,85 @@
1
- import React, { useMemo } from "react"
2
- import { Block, useStyletron, CoinsStacked02 } from "@mezo-org/mezo-clay"
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"
3
9
  import ListingItem from "../ListingItem"
4
- import { formatUsd } from "../../../utils/currency"
10
+ import { useTokensBalances } from "../../../hooks/useTokensBalances"
11
+ import AccountError from "./AccountError"
12
+ import { CONVERSION_RATE_DECIMALS } from "../../../hooks/useAssetsConversionRates"
5
13
 
6
14
  type AccountOtherAssetsProps = {
7
- assetsCount: number
8
- assetsUsdTotal: number
9
15
  onClick?: () => void
10
- }
16
+ } & Omit<BlockProps, "children">
11
17
 
12
18
  export default function AccountOtherAssets(props: AccountOtherAssetsProps) {
13
- const { assetsCount, assetsUsdTotal, onClick } = props
19
+ const { onClick, overrides, ...restProps } = props
14
20
 
15
21
  const [, theme] = useStyletron()
16
22
 
17
- const label = useMemo(() => {
18
- if (assetsCount === 0) return "No other assets"
19
- if (assetsCount === 1) return "1 more asset"
20
- return `${assetsCount} more assets`
21
- }, [assetsCount])
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
+ }
22
39
 
23
- const formattedAssetsUsdTotal = formatUsd(assetsUsdTotal)
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`
24
59
 
25
60
  return (
26
- <Block
27
- aria-label={label}
28
- as="li"
29
- overrides={{
30
- Block: {
31
- style: {
32
- listStyle: "none",
33
- borderTop: `1px solid ${theme.colors.borderInverseSelected}`,
34
- },
35
- },
36
- }}
37
- >
38
- <ListingItem
39
- icon={CoinsStacked02}
40
- label={label}
41
- value={formattedAssetsUsdTotal}
42
- overrides={{
43
- Root: {
61
+ <ListingItem
62
+ icon={<CoinsStacked02 color={theme.colors.contentPrimary} />}
63
+ label={label}
64
+ value={totalAssetsInUsd}
65
+ overrides={mergeOverrides(
66
+ {
67
+ Block: {
44
68
  props: {
45
69
  $as: "button",
46
70
  onClick,
47
71
  },
48
72
  style: {
49
- border: 0,
50
- padding: 0,
73
+ borderWidth: 0,
51
74
  cursor: "pointer",
75
+ backgroundColor: "transparent",
76
+ minHeight: "56px",
52
77
  },
53
78
  },
54
- ArtworkContainer: {
55
- style: {
56
- stroke: theme.colors.contentPrimary,
57
- },
58
- },
59
- Content: {
60
- style: {
61
- minHeight: theme.sizing.scale1200,
62
- },
63
- },
64
- }}
65
- />
66
- </Block>
79
+ },
80
+ overrides,
81
+ )}
82
+ {...restProps}
83
+ />
67
84
  )
68
85
  }
@@ -6,47 +6,17 @@ import WalletAddress from "./WalletAddress"
6
6
  import AccountBalance from "./AccountBalance"
7
7
  import WelcomeBlock from "./WelcomeBlock"
8
8
  import AccountAddressActions from "./AccountAddressActions"
9
- import AccountAssetItem from "./AccountAssetItem"
10
- import { DetailedCryptoAsset } from "../../../utils/cryptoAssets"
11
- import { formatNumberToCompactString } from "../../../utils/numbers"
12
- import { formatUsd } from "../../../utils/currency"
13
9
  import AccountOtherAssets from "./AccountOtherAssets"
10
+ import AccountBtcListing from "./AccountBtcListing"
11
+ import AccountMusdListing from "./AccountMusdListing"
14
12
 
15
13
  type RootProps = {
16
- mezoId: string
17
- matsBalance: number
18
- accountAddress: string
19
- walletAddress: string
20
- walletType: "bitcoin" | "evm"
21
- usdTotalBalance: number
22
- usdTroveDebt: number
23
- usdCollateral: number
24
- assets: {
25
- btc: DetailedCryptoAsset
26
- musd: DetailedCryptoAsset
27
- }
28
- otherAssetsCount: number
29
- otherAssetsUsdTotal: number
30
14
  onSignOut?: () => void
31
15
  onOtherAssetsClick?: () => void
32
16
  }
33
17
 
34
18
  export default function Root(props: RootProps) {
35
- const {
36
- mezoId,
37
- walletAddress,
38
- accountAddress,
39
- walletType,
40
- usdTotalBalance,
41
- usdTroveDebt,
42
- usdCollateral,
43
- matsBalance,
44
- assets,
45
- otherAssetsCount,
46
- otherAssetsUsdTotal,
47
- onSignOut,
48
- onOtherAssetsClick,
49
- } = props
19
+ const { onSignOut, onOtherAssetsClick } = props
50
20
 
51
21
  const [, theme] = useStyletron()
52
22
 
@@ -58,88 +28,48 @@ export default function Root(props: RootProps) {
58
28
  onSignOut()
59
29
  return
60
30
  }
61
-
62
31
  signOut()
63
32
  disconnect()
64
33
  }, [signOut, disconnect, onSignOut])
65
34
 
66
- const formattedMatsBalance = formatNumberToCompactString(matsBalance, 2)
67
- const formattedUsdTotalBalance = formatUsd(usdTotalBalance)
68
- const formattedUsdTroveDebt = formatUsd(usdTroveDebt)
69
- const formattedUsdCollateral = formatUsd(usdCollateral)
35
+ const overridesWithDivider = {
36
+ Block: {
37
+ style: {
38
+ borderBottomWidth: "1px",
39
+ borderBottomStyle: "solid",
40
+ borderBottomColor: theme.colors.borderOpaque,
41
+ },
42
+ },
43
+ }
70
44
 
71
45
  return (
72
- <Block
73
- display="inline-flex"
74
- flexDirection="column"
75
- padding={theme.sizing.scale600}
76
- >
77
- <WelcomeBlock mezoId={mezoId} matsBalance={formattedMatsBalance} />
46
+ <Block display="inline-flex" flexDirection="column">
47
+ <WelcomeBlock />
78
48
 
79
- <AccountAddressActions address={accountAddress} />
49
+ <AccountAddressActions overrides={overridesWithDivider} />
80
50
 
81
- <Block
82
- display="flex"
83
- flexDirection="column"
84
- backgroundColor={theme.colors.backgroundSecondary}
85
- overflow="hidden"
86
- overrides={{
87
- Block: { style: { borderRadius: theme.borders.radius300 } },
88
- }}
89
- >
90
- <WalletAddress address={walletAddress} type={walletType} />
51
+ <WalletAddress overrides={overridesWithDivider} />
91
52
 
92
- <AccountBalance
93
- totalBalance={formattedUsdTotalBalance}
94
- totalDebt={formattedUsdTroveDebt}
95
- />
53
+ <AccountBalance overrides={overridesWithDivider} />
96
54
 
97
- <AccountAssetItem
98
- type="BTC"
99
- amount={assets.btc.formattedUsdBalance}
100
- subLabel="Locked collateral"
101
- subValue={formattedUsdCollateral}
102
- />
55
+ <AccountBtcListing />
103
56
 
104
- <AccountAssetItem
105
- type="MUSD"
106
- amount={assets.musd.formattedUsdBalance}
107
- subLabel="Borrowed"
108
- subValue={formattedUsdTroveDebt}
109
- />
57
+ <AccountMusdListing />
110
58
 
111
- <AccountOtherAssets
112
- assetsCount={otherAssetsCount}
113
- assetsUsdTotal={otherAssetsUsdTotal}
114
- onClick={onOtherAssetsClick}
115
- />
116
- </Block>
59
+ <AccountOtherAssets
60
+ onClick={onOtherAssetsClick}
61
+ overrides={overridesWithDivider}
62
+ />
117
63
 
118
- <Block
119
- marginTop={theme.sizing.scale700}
120
- padding={`0 ${theme.sizing.scale100}`}
121
- >
64
+ <Block padding={theme.sizing.scale300}>
122
65
  <Button
123
66
  size="small"
67
+ shape="pill"
124
68
  kind="tertiary"
125
- startEnhancer={<LogOut01 color="currentColor" size={12} />}
126
- onClick={() => handleLogOut()}
127
- overrides={{
128
- Root: {
129
- style: {
130
- ":hover": {
131
- backgroundColor: theme.colors.backgroundSecondary,
132
- boxShadow: "none",
133
- },
134
- ":active": {
135
- backgroundColor: theme.colors.backgroundSecondary,
136
- color: theme.colors.contentPrimary,
137
- },
138
- },
139
- },
140
- }}
69
+ startEnhancer={<LogOut01 color="currentColor" size={16} />}
70
+ onClick={handleLogOut}
141
71
  >
142
- Log out
72
+ Sign out
143
73
  </Button>
144
74
  </Block>
145
75
  </Block>