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

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 (187) hide show
  1. package/dist/src/api/auth.d.ts +1 -1
  2. package/dist/src/api/auth.d.ts.map +1 -1
  3. package/dist/src/components/Dropdown/Content.d.ts +0 -15
  4. package/dist/src/components/Dropdown/Content.d.ts.map +1 -1
  5. package/dist/src/components/Dropdown/Content.js +3 -3
  6. package/dist/src/components/Dropdown/Content.js.map +1 -1
  7. package/dist/src/components/Dropdown/Dropdown.d.ts +0 -4
  8. package/dist/src/components/Dropdown/Dropdown.d.ts.map +1 -1
  9. package/dist/src/components/Dropdown/Dropdown.js +10 -33
  10. package/dist/src/components/Dropdown/Dropdown.js.map +1 -1
  11. package/dist/src/components/Dropdown/ListingItem.d.ts +8 -7
  12. package/dist/src/components/Dropdown/ListingItem.d.ts.map +1 -1
  13. package/dist/src/components/Dropdown/ListingItem.js +36 -28
  14. package/dist/src/components/Dropdown/ListingItem.js.map +1 -1
  15. package/dist/src/components/Dropdown/NestedViewLayout.d.ts +2 -1
  16. package/dist/src/components/Dropdown/NestedViewLayout.d.ts.map +1 -1
  17. package/dist/src/components/Dropdown/NestedViewLayout.js +13 -15
  18. package/dist/src/components/Dropdown/NestedViewLayout.js.map +1 -1
  19. package/dist/src/components/Dropdown/Receive/Receive.d.ts +1 -4
  20. package/dist/src/components/Dropdown/Receive/Receive.d.ts.map +1 -1
  21. package/dist/src/components/Dropdown/Receive/Receive.js +36 -19
  22. package/dist/src/components/Dropdown/Receive/Receive.js.map +1 -1
  23. package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts +2 -5
  24. package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts.map +1 -1
  25. package/dist/src/components/Dropdown/Root/AccountAddressActions.js +28 -12
  26. package/dist/src/components/Dropdown/Root/AccountAddressActions.js.map +1 -1
  27. package/dist/src/components/Dropdown/Root/AccountBalance.d.ts +2 -4
  28. package/dist/src/components/Dropdown/Root/AccountBalance.d.ts.map +1 -1
  29. package/dist/src/components/Dropdown/Root/AccountBalance.js +24 -8
  30. package/dist/src/components/Dropdown/Root/AccountBalance.js.map +1 -1
  31. package/dist/src/components/Dropdown/Root/AccountBtcListing.d.ts +6 -0
  32. package/dist/src/components/Dropdown/Root/AccountBtcListing.d.ts.map +1 -0
  33. package/dist/src/components/Dropdown/Root/AccountBtcListing.js +27 -0
  34. package/dist/src/components/Dropdown/Root/AccountBtcListing.js.map +1 -0
  35. package/dist/src/components/Dropdown/Root/AccountError.d.ts +8 -0
  36. package/dist/src/components/Dropdown/Root/AccountError.d.ts.map +1 -0
  37. package/dist/src/components/Dropdown/Root/AccountError.js +17 -0
  38. package/dist/src/components/Dropdown/Root/AccountError.js.map +1 -0
  39. package/dist/src/components/Dropdown/Root/AccountMusdListing.d.ts +4 -0
  40. package/dist/src/components/Dropdown/Root/AccountMusdListing.d.ts.map +1 -0
  41. package/dist/src/components/Dropdown/Root/AccountMusdListing.js +21 -0
  42. package/dist/src/components/Dropdown/Root/AccountMusdListing.js.map +1 -0
  43. package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts +2 -3
  44. package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts.map +1 -1
  45. package/dist/src/components/Dropdown/Root/AccountOtherAssets.js +34 -39
  46. package/dist/src/components/Dropdown/Root/AccountOtherAssets.js.map +1 -1
  47. package/dist/src/components/Dropdown/Root/Root.d.ts +0 -15
  48. package/dist/src/components/Dropdown/Root/Root.d.ts.map +1 -1
  49. package/dist/src/components/Dropdown/Root/Root.js +22 -34
  50. package/dist/src/components/Dropdown/Root/Root.js.map +1 -1
  51. package/dist/src/components/Dropdown/Root/WalletAddress.d.ts +2 -6
  52. package/dist/src/components/Dropdown/Root/WalletAddress.d.ts.map +1 -1
  53. package/dist/src/components/Dropdown/Root/WalletAddress.js +43 -34
  54. package/dist/src/components/Dropdown/Root/WalletAddress.js.map +1 -1
  55. package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts +2 -4
  56. package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts.map +1 -1
  57. package/dist/src/components/Dropdown/Root/WelcomeBlock.js +60 -16
  58. package/dist/src/components/Dropdown/Root/WelcomeBlock.js.map +1 -1
  59. package/dist/src/components/Dropdown/SlotNumber.d.ts +19 -0
  60. package/dist/src/components/Dropdown/SlotNumber.d.ts.map +1 -0
  61. package/dist/src/components/Dropdown/SlotNumber.js +67 -0
  62. package/dist/src/components/Dropdown/SlotNumber.js.map +1 -0
  63. package/dist/src/config.d.ts +1 -11
  64. package/dist/src/config.d.ts.map +1 -1
  65. package/dist/src/config.js +3 -40
  66. package/dist/src/config.js.map +1 -1
  67. package/dist/src/constants.d.ts +0 -2
  68. package/dist/src/constants.d.ts.map +1 -1
  69. package/dist/src/constants.js +0 -2
  70. package/dist/src/constants.js.map +1 -1
  71. package/dist/src/hooks/useAssetsConversionRates.d.ts +8 -13
  72. package/dist/src/hooks/useAssetsConversionRates.d.ts.map +1 -1
  73. package/dist/src/hooks/useAssetsConversionRates.js +44 -67
  74. package/dist/src/hooks/useAssetsConversionRates.js.map +1 -1
  75. package/dist/src/hooks/useAuthenticateWithWallet.d.ts.map +1 -1
  76. package/dist/src/hooks/useAuthenticateWithWallet.js +1 -1
  77. package/dist/src/hooks/useAuthenticateWithWallet.js.map +1 -1
  78. package/dist/src/hooks/useBorrowData.d.ts +31 -5
  79. package/dist/src/hooks/useBorrowData.d.ts.map +1 -1
  80. package/dist/src/hooks/useBorrowData.js +53 -11
  81. package/dist/src/hooks/useBorrowData.js.map +1 -1
  82. package/dist/src/hooks/useCreateAccount.d.ts.map +1 -1
  83. package/dist/src/hooks/useCreateAccount.js +3 -3
  84. package/dist/src/hooks/useCreateAccount.js.map +1 -1
  85. package/dist/src/hooks/useGetCurrentAccount.d.ts +2 -2
  86. package/dist/src/hooks/useGetCurrentAccount.d.ts.map +1 -1
  87. package/dist/src/hooks/useGetCurrentAccount.js +4 -6
  88. package/dist/src/hooks/useGetCurrentAccount.js.map +1 -1
  89. package/dist/src/hooks/useLinkAccount.d.ts.map +1 -1
  90. package/dist/src/hooks/useLinkAccount.js +3 -3
  91. package/dist/src/hooks/useLinkAccount.js.map +1 -1
  92. package/dist/src/hooks/useTokensBalances.d.ts +36 -35
  93. package/dist/src/hooks/useTokensBalances.d.ts.map +1 -1
  94. package/dist/src/hooks/useTokensBalances.js +93 -52
  95. package/dist/src/hooks/useTokensBalances.js.map +1 -1
  96. package/dist/src/hooks/useWalletAccount.d.ts +8 -10
  97. package/dist/src/hooks/useWalletAccount.d.ts.map +1 -1
  98. package/dist/src/hooks/useWalletAccount.js +22 -19
  99. package/dist/src/hooks/useWalletAccount.js.map +1 -1
  100. package/dist/src/index.d.ts +1 -1
  101. package/dist/src/index.d.ts.map +1 -1
  102. package/dist/src/index.js +1 -1
  103. package/dist/src/index.js.map +1 -1
  104. package/dist/src/lib/contracts/index.d.ts +1 -1
  105. package/dist/src/lib/contracts/index.d.ts.map +1 -1
  106. package/dist/src/lib/contracts/index.js +4 -0
  107. package/dist/src/lib/contracts/index.js.map +1 -1
  108. package/dist/src/provider.d.ts +7 -1
  109. package/dist/src/provider.d.ts.map +1 -1
  110. package/dist/src/provider.js +4 -1
  111. package/dist/src/provider.js.map +1 -1
  112. package/dist/src/utils/assets.d.ts +145 -0
  113. package/dist/src/utils/assets.d.ts.map +1 -0
  114. package/dist/src/utils/assets.js +100 -0
  115. package/dist/src/utils/assets.js.map +1 -0
  116. package/dist/src/utils/assets.test.d.ts +2 -0
  117. package/dist/src/utils/assets.test.d.ts.map +1 -0
  118. package/dist/src/utils/assets.test.js +46 -0
  119. package/dist/src/utils/assets.test.js.map +1 -0
  120. package/dist/src/utils/currency.d.ts +6 -3
  121. package/dist/src/utils/currency.d.ts.map +1 -1
  122. package/dist/src/utils/currency.js +13 -10
  123. package/dist/src/utils/currency.js.map +1 -1
  124. package/dist/src/utils/currency.test.js +44 -2
  125. package/dist/src/utils/currency.test.js.map +1 -1
  126. package/dist/src/utils/numbers.d.ts +13 -53
  127. package/dist/src/utils/numbers.d.ts.map +1 -1
  128. package/dist/src/utils/numbers.js +16 -118
  129. package/dist/src/utils/numbers.js.map +1 -1
  130. package/dist/src/utils/numbers.test.js +24 -142
  131. package/dist/src/utils/numbers.test.js.map +1 -1
  132. package/package.json +2 -1
  133. package/src/api/auth.ts +1 -1
  134. package/src/components/Dropdown/Content.tsx +3 -48
  135. package/src/components/Dropdown/Dropdown.tsx +7 -55
  136. package/src/components/Dropdown/ListingItem.tsx +155 -59
  137. package/src/components/Dropdown/NestedViewLayout.tsx +32 -20
  138. package/src/components/Dropdown/Receive/Receive.tsx +69 -32
  139. package/src/components/Dropdown/Root/AccountAddressActions.tsx +64 -35
  140. package/src/components/Dropdown/Root/AccountBalance.tsx +54 -16
  141. package/src/components/Dropdown/Root/AccountBtcListing.tsx +52 -0
  142. package/src/components/Dropdown/Root/AccountError.tsx +34 -0
  143. package/src/components/Dropdown/Root/AccountMusdListing.tsx +45 -0
  144. package/src/components/Dropdown/Root/AccountOtherAssets.tsx +63 -46
  145. package/src/components/Dropdown/Root/Root.tsx +28 -98
  146. package/src/components/Dropdown/Root/WalletAddress.tsx +95 -89
  147. package/src/components/Dropdown/Root/WelcomeBlock.tsx +109 -29
  148. package/src/components/Dropdown/SlotNumber.tsx +131 -0
  149. package/src/config.ts +3 -59
  150. package/src/constants.ts +0 -6
  151. package/src/hooks/useAssetsConversionRates.ts +49 -67
  152. package/src/hooks/useAuthenticateWithWallet.ts +7 -5
  153. package/src/hooks/useBorrowData.ts +71 -12
  154. package/src/hooks/useCreateAccount.ts +5 -4
  155. package/src/hooks/useGetCurrentAccount.ts +5 -7
  156. package/src/hooks/useLinkAccount.ts +5 -4
  157. package/src/hooks/useTokensBalances.ts +152 -74
  158. package/src/hooks/useWalletAccount.ts +27 -36
  159. package/src/index.ts +0 -1
  160. package/src/lib/contracts/index.ts +8 -1
  161. package/src/provider.ts +11 -3
  162. package/src/utils/assets.test.ts +57 -0
  163. package/src/utils/assets.ts +103 -0
  164. package/src/utils/currency.test.ts +76 -2
  165. package/src/utils/currency.ts +20 -15
  166. package/src/utils/numbers.test.ts +29 -180
  167. package/src/utils/numbers.ts +22 -171
  168. package/dist/src/components/Dropdown/Root/AccountAssetItem.d.ts +0 -11
  169. package/dist/src/components/Dropdown/Root/AccountAssetItem.d.ts.map +0 -1
  170. package/dist/src/components/Dropdown/Root/AccountAssetItem.js +0 -9
  171. package/dist/src/components/Dropdown/Root/AccountAssetItem.js.map +0 -1
  172. package/dist/src/hooks/useDropdownData.d.ts +0 -47
  173. package/dist/src/hooks/useDropdownData.d.ts.map +0 -1
  174. package/dist/src/hooks/useDropdownData.js +0 -97
  175. package/dist/src/hooks/useDropdownData.js.map +0 -1
  176. package/dist/src/utils/cryptoAssets.d.ts +0 -44
  177. package/dist/src/utils/cryptoAssets.d.ts.map +0 -1
  178. package/dist/src/utils/cryptoAssets.js +0 -129
  179. package/dist/src/utils/cryptoAssets.js.map +0 -1
  180. package/dist/src/utils/cryptoAssets.test.d.ts +0 -2
  181. package/dist/src/utils/cryptoAssets.test.d.ts.map +0 -1
  182. package/dist/src/utils/cryptoAssets.test.js +0 -67
  183. package/dist/src/utils/cryptoAssets.test.js.map +0 -1
  184. package/src/components/Dropdown/Root/AccountAssetItem.tsx +0 -26
  185. package/src/hooks/useDropdownData.ts +0 -152
  186. package/src/utils/cryptoAssets.test.ts +0 -79
  187. package/src/utils/cryptoAssets.ts +0 -171
@@ -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>
@@ -1,47 +1,55 @@
1
1
  import {
2
+ BitcoinCircle,
2
3
  Block,
3
- Copy03 as CopyIcon,
4
- LinkExternal02 as LinkIcon,
5
- ParagraphSmall,
4
+ BlockProps,
5
+ EthCircle,
6
+ LabelMedium,
7
+ LabelXSmall,
8
+ mergeOverrides,
9
+ MonoLabelXSmall,
6
10
  useStyletron,
7
11
  } from "@mezo-org/mezo-clay"
8
- import React, { useCallback, useState } from "react"
12
+ import React, { useState } from "react"
9
13
  import { useCopyToClipboard } from "usehooks-ts"
10
14
  import { usePassportContext } from "../../../hooks/usePassportContext"
11
15
  import { getAddressExplorerUrl, trimAddress } from "../../../utils/address"
12
- import { getCryptoAsset } from "../../../utils/cryptoAssets"
16
+ import useWalletAccount from "../../../hooks/useWalletAccount"
13
17
 
14
- type WalletAddressProps = {
15
- address: string
16
- type: "bitcoin" | "evm"
17
- }
18
-
19
- export default function WalletAddress(props: WalletAddressProps) {
20
- const { address, type } = props
21
-
22
- const { environment } = usePassportContext()
23
- const blockExplorerUrl = getAddressExplorerUrl(
24
- address,
25
- type,
26
- environment === "testnet",
27
- )
28
- const trimmedAddress = trimAddress(address)
29
- const { icon: accountIcon } = getCryptoAsset(
30
- type === "bitcoin" ? "BTC" : "ETH",
31
- )
18
+ export default function WalletAddress(props: BlockProps) {
19
+ const { overrides, ...restProps } = props
32
20
 
21
+ const { data, isError, isPending } = useWalletAccount()
22
+ const { environment = "mainnet" } = usePassportContext()
33
23
  const [, theme] = useStyletron()
34
-
35
24
  const [, copy] = useCopyToClipboard()
36
25
  const [isCopiedMessageVisible, setIsCopiedMessageVisible] = useState(false)
37
- const handleCopyAddress = useCallback(() => {
38
- copy(address)
26
+
27
+ if (isError) {
28
+ return "Error loading wallet address"
29
+ }
30
+
31
+ if (isPending) {
32
+ return "Loading..."
33
+ }
34
+
35
+ const { walletAddress, networkFamily } = data
36
+
37
+ const handleCopyAddress = () => {
38
+ copy(walletAddress)
39
39
  setIsCopiedMessageVisible(true)
40
40
 
41
41
  setTimeout(() => {
42
42
  setIsCopiedMessageVisible(false)
43
43
  }, 2000)
44
- }, [copy, address])
44
+ }
45
+
46
+ const blockExplorerUrl = getAddressExplorerUrl(
47
+ walletAddress,
48
+ networkFamily,
49
+ environment === "testnet",
50
+ )
51
+ const trimmedAddress = trimAddress(walletAddress)
52
+ const AccountIcon = networkFamily === "bitcoin" ? BitcoinCircle : EthCircle
45
53
 
46
54
  return (
47
55
  <Block
@@ -50,79 +58,77 @@ export default function WalletAddress(props: WalletAddressProps) {
50
58
  display="flex"
51
59
  alignItems="center"
52
60
  backgroundColor="transparent"
53
- padding={`${theme.sizing.scale600} ${theme.sizing.scale500}`}
54
- overrides={{
55
- Block: {
56
- style: {
57
- borderWidth: 0,
58
- cursor: "pointer",
59
- ":hover": {
60
- backgroundColor: theme.colors.backgroundTertiary,
61
+ padding={`${theme.sizing.scale800} ${theme.sizing.scale700}`}
62
+ overrides={mergeOverrides(
63
+ {
64
+ Block: {
65
+ style: {
66
+ gap: theme.sizing.scale700,
67
+ borderWidth: 0,
68
+ cursor: "pointer",
69
+ ":hover": {
70
+ backgroundColor: theme.colors.backgroundTertiary,
71
+ },
61
72
  },
62
73
  },
63
74
  },
64
- }}
65
- >
66
- <Block as={accountIcon} size={theme.sizing.scale600} />
67
- {isCopiedMessageVisible ? (
68
- <ParagraphSmall
69
- margin={0}
70
- marginLeft={theme.sizing.scale500}
71
- color={theme.colors.contentPrimary}
72
- >
73
- Copied address to clipboard
74
- </ParagraphSmall>
75
- ) : (
76
- <Block
77
- as="a"
78
- marginLeft={theme.sizing.scale500}
79
- href={blockExplorerUrl}
80
- target="_blank"
81
- overrides={{
82
- Block: {
83
- style: {
84
- color: "inherit",
85
- textDecoration: "none",
86
- ":hover": {
87
- textDecoration: "underline",
88
- },
89
- },
90
- },
91
- }}
92
- >
93
- <ParagraphSmall
94
- display="flex"
95
- alignItems="center"
96
- margin={0}
97
- color={theme.colors.contentPrimary}
98
- >
99
- {trimmedAddress}
100
- <LinkIcon
101
- display="inline"
102
- size={theme.sizing.scale550}
103
- overrides={{
104
- Svg: {
105
- style: {
106
- stroke: "currentColor",
107
- marginLeft: theme.sizing.scale300,
108
- },
109
- },
110
- }}
111
- />
112
- </ParagraphSmall>
113
- </Block>
75
+ overrides,
114
76
  )}
115
- <CopyIcon
116
- size={theme.sizing.scale550}
117
- color={theme.colors.contentPrimary}
77
+ {...restProps}
78
+ >
79
+ <AccountIcon
80
+ color={theme.colors.black}
81
+ size={theme.sizing.scale800}
118
82
  overrides={{
119
83
  Svg: {
120
84
  style: {
121
- marginLeft: "auto",
85
+ backgroundColor: theme.colors.black,
86
+ overflow: "hidden",
87
+ borderRadius: theme.borders.radius200,
122
88
  },
123
89
  },
124
90
  }}
125
91
  />
92
+ <Block
93
+ display="flex"
94
+ flexDirection="column"
95
+ alignItems="flex-start"
96
+ overrides={{
97
+ Block: {
98
+ style: {
99
+ gap: theme.sizing.scale100,
100
+ },
101
+ },
102
+ }}
103
+ >
104
+ <LabelMedium>Connected Wallet</LabelMedium>
105
+
106
+ {isCopiedMessageVisible ? (
107
+ <LabelXSmall color={theme.colors.contentSecondary}>
108
+ Copied address to clipboard
109
+ </LabelXSmall>
110
+ ) : (
111
+ <Block
112
+ as="a"
113
+ color={theme.colors.contentSecondary}
114
+ href={blockExplorerUrl}
115
+ target="_blank"
116
+ overrides={{
117
+ Block: {
118
+ style: {
119
+ color: "inherit",
120
+ textDecoration: "none",
121
+ ":hover": {
122
+ textDecoration: "underline",
123
+ },
124
+ },
125
+ },
126
+ }}
127
+ >
128
+ <MonoLabelXSmall>{trimmedAddress}</MonoLabelXSmall>
129
+ </Block>
130
+ )}
131
+ </Block>
126
132
  </Block>
127
133
  )
128
134
  }