@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,8 +1,9 @@
1
1
  import {
2
2
  ArrowLeft,
3
3
  Block,
4
+ BlockProps,
4
5
  ButtonIcon,
5
- LabelMedium,
6
+ HeadingSmall,
6
7
  useStyletron,
7
8
  } from "@mezo-org/mezo-clay"
8
9
  import React, { ReactNode, useCallback } from "react"
@@ -10,21 +11,20 @@ import useDropdownStore, { DropdownView } from "../../stores/dropdownStore"
10
11
 
11
12
  const getHeaderTitle = (view: DropdownView) => {
12
13
  const titleMap: Partial<Record<DropdownView, string>> = {
13
- [DropdownView.RECEIVE]: "Receive",
14
+ [DropdownView.RECEIVE]: "Scan to receive",
14
15
  }
15
16
  return titleMap[view]!
16
17
  }
17
18
 
18
19
  type NestedViewLayoutProps = {
19
20
  children: ReactNode
20
- }
21
+ } & BlockProps
21
22
 
22
23
  function NestedViewLayout(props: NestedViewLayoutProps) {
23
24
  const { children, ...restProps } = props
24
25
 
25
26
  const currentView = useDropdownStore((state) => state.view)
26
27
  const setView = useDropdownStore((state) => state.setView)
27
- const isNested = useDropdownStore((state) => state.isNestedView())
28
28
 
29
29
  const [, theme] = useStyletron()
30
30
 
@@ -37,37 +37,49 @@ function NestedViewLayout(props: NestedViewLayoutProps) {
37
37
  display="flex"
38
38
  flexDirection="column"
39
39
  minHeight="588px"
40
- padding={theme.sizing.scale700}
41
- paddingTop={0}
42
40
  {...restProps}
43
41
  >
44
42
  <Block
45
43
  display="flex"
46
44
  alignItems="center"
47
- paddingTop={theme.sizing.scale600}
48
- paddingBottom={theme.sizing.scale600}
45
+ padding={theme.sizing.scale100}
46
+ paddingTop={theme.sizing.scale800}
47
+ paddingBottom={theme.sizing.scale500}
49
48
  marginBottom={theme.sizing.scale300}
49
+ overrides={{
50
+ Block: {
51
+ style: {
52
+ gap: theme.sizing.scale300,
53
+ },
54
+ },
55
+ }}
50
56
  >
51
57
  <ButtonIcon
52
58
  onClick={handleOnButtonClick}
53
59
  shape="circle"
54
- size="small"
55
- overrides={{
56
- BaseButton: {
57
- style: {
58
- background: theme.colors.backgroundPrimary,
59
- marginRight: isNested ? theme.sizing.scale300 : undefined,
60
- },
61
- },
62
- }}
60
+ size="medium"
61
+ kind="tertiary"
63
62
  >
64
- <ArrowLeft size={theme.sizing.scale700} />
63
+ <ArrowLeft />
65
64
  </ButtonIcon>
66
65
 
67
- <LabelMedium>{getHeaderTitle(currentView)}</LabelMedium>
66
+ <HeadingSmall
67
+ marginTop={theme.sizing.scale300}
68
+ marginBottom={theme.sizing.scale300}
69
+ >
70
+ {getHeaderTitle(currentView)}
71
+ </HeadingSmall>
68
72
  </Block>
69
73
 
70
- {children}
74
+ <Block
75
+ display="flex"
76
+ flexDirection="column"
77
+ padding={theme.sizing.scale600}
78
+ paddingTop={0}
79
+ flex={1}
80
+ >
81
+ {children}
82
+ </Block>
71
83
  </Block>
72
84
  )
73
85
  }
@@ -1,12 +1,13 @@
1
1
  import {
2
2
  Block,
3
3
  Button,
4
- LabelMedium,
4
+ LabelLarge,
5
+ MezoCircle,
5
6
  MonoLabelXSmall,
6
7
  ParagraphSmall,
7
8
  useStyletron,
8
9
  } from "@mezo-org/mezo-clay"
9
- import React, { useCallback, useState } from "react"
10
+ import React, { useState } from "react"
10
11
  import { useCopyToClipboard } from "usehooks-ts"
11
12
  import { QRCodeSVG } from "qrcode.react"
12
13
  import NestedViewLayout from "../NestedViewLayout"
@@ -14,46 +15,54 @@ import { getAddressExplorerUrl } from "../../../utils/address"
14
15
  import { usePassportContext } from "../../../hooks/usePassportContext"
15
16
  import useWalletAccount from "../../../hooks/useWalletAccount"
16
17
 
17
- type ReceiveProps = {
18
- address: string
19
- }
20
-
21
- function Receive(props: ReceiveProps) {
22
- const { address } = props
23
-
18
+ function Receive() {
24
19
  const { environment } = usePassportContext()
25
20
 
26
- const blockExplorerUrl = getAddressExplorerUrl(
27
- address,
28
- "mezo",
29
- environment === "testnet",
30
- )
21
+ const {
22
+ data: walletAccountData,
23
+ isError: isWalletAccountDataError,
24
+ isPending: isWalletAccountDataPending,
25
+ } = useWalletAccount()
31
26
 
32
27
  const [, theme] = useStyletron()
33
28
 
34
29
  const [, copy] = useCopyToClipboard()
30
+
35
31
  const [isCopiedMessageVisible, setIsCopiedMessageVisible] = useState(false)
36
- const handleCopyAddress = useCallback(() => {
37
- copy(address)
32
+
33
+ if (isWalletAccountDataError) {
34
+ return "Error loading wallet account data"
35
+ }
36
+
37
+ if (isWalletAccountDataPending) {
38
+ return "Loading wallet account data..."
39
+ }
40
+
41
+ const handleCopyAddress = () => {
42
+ copy(walletAccountData.accountAddress)
38
43
  setIsCopiedMessageVisible(true)
39
44
 
40
45
  setTimeout(() => {
41
46
  setIsCopiedMessageVisible(false)
42
47
  }, 2000)
43
- }, [copy, address])
48
+ }
44
49
 
45
- const { networkFamily } = useWalletAccount()
50
+ const blockExplorerUrl = getAddressExplorerUrl(
51
+ walletAccountData.accountAddress,
52
+ "mezo",
53
+ environment === "testnet",
54
+ )
46
55
 
47
56
  return (
48
57
  <NestedViewLayout>
49
- <LabelMedium>Your Mezo Address</LabelMedium>
58
+ <LabelLarge>Your Mezo Address</LabelLarge>
50
59
 
51
60
  <ParagraphSmall
52
- marginTop={theme.sizing.scale300}
53
- marginBottom={theme.sizing.scale600}
61
+ marginTop={0}
62
+ marginBottom={theme.sizing.scale800}
54
63
  color={theme.colors.contentTertiary}
55
64
  >
56
- {networkFamily === "bitcoin" ? (
65
+ {walletAccountData.networkFamily === "bitcoin" ? (
57
66
  <>
58
67
  Mezo automatically created a smart account that&apos;s fully
59
68
  controlled by your connected Bitcoin wallet. Use this address to
@@ -69,7 +78,7 @@ function Receive(props: ReceiveProps) {
69
78
 
70
79
  <Block
71
80
  as={QRCodeSVG}
72
- value={address}
81
+ value={walletAccountData.accountAddress}
73
82
  flex={1}
74
83
  overrides={{
75
84
  Block: {
@@ -82,35 +91,63 @@ function Receive(props: ReceiveProps) {
82
91
  }}
83
92
  />
84
93
 
85
- <MonoLabelXSmall
94
+ <Block
95
+ display="flex"
96
+ alignItems="center"
97
+ backgroundColor={theme.colors.backgroundSecondary}
86
98
  marginTop={theme.sizing.scale800}
87
- marginBottom={theme.sizing.scale800}
99
+ marginBottom={theme.sizing.scale600}
100
+ padding={theme.sizing.scale300}
88
101
  overrides={{
89
102
  Block: {
90
103
  style: {
91
- textAlign: "center",
104
+ gap: theme.sizing.scale300,
105
+ borderRadius: theme.borders.radius400,
92
106
  },
93
107
  },
94
108
  }}
95
109
  >
96
- {address}
97
- </MonoLabelXSmall>
110
+ <MezoCircle
111
+ size={theme.sizing.scale700}
112
+ color={theme.colors.accent}
113
+ symbolColor={theme.colors.white}
114
+ overrides={{
115
+ Svg: {
116
+ style: {
117
+ backgroundColor: theme.colors.accent,
118
+ overflow: "hidden",
119
+ borderRadius: theme.borders.radius200,
120
+ flexShrink: 0,
121
+ },
122
+ },
123
+ }}
124
+ />
125
+
126
+ <MonoLabelXSmall>{walletAccountData.accountAddress}</MonoLabelXSmall>
127
+ </Block>
98
128
 
99
129
  <Button
100
130
  onClick={handleCopyAddress}
131
+ size="medium"
101
132
  overrides={{
102
133
  BaseButton: {
103
134
  style: {
104
- marginBottom: theme.sizing.scale400,
135
+ marginBottom: theme.sizing.scale500,
105
136
  },
106
137
  },
107
138
  }}
108
139
  >
109
- {isCopiedMessageVisible ? "Copied!" : "Copy Mezo Address"}
140
+ {isCopiedMessageVisible ? "Copied!" : "Copy Mezo address"}
110
141
  </Button>
111
142
 
112
- <Button kind="secondary" $as="a" href={blockExplorerUrl} target="_blank">
113
- View Explorer
143
+ <Button
144
+ kind="secondary"
145
+ size="medium"
146
+ $as="a"
147
+ href={blockExplorerUrl}
148
+ target="_blank"
149
+ >
150
+ View Mezo explorer
114
151
  </Button>
115
152
  </NestedViewLayout>
116
153
  )
@@ -1,25 +1,26 @@
1
1
  import {
2
2
  ArrowNarrowLeft,
3
3
  Block,
4
+ BlockProps,
4
5
  Button,
5
6
  ButtonProps,
6
- Cube01,
7
+ mergeOverrides,
8
+ Skeleton,
7
9
  useStyletron,
8
10
  } from "@mezo-org/mezo-clay"
9
- import React, { useCallback } from "react"
11
+ import React from "react"
10
12
  import { usePassportContext } from "../../../hooks/usePassportContext"
11
13
  import { getAddressExplorerUrl } from "../../../utils/address"
12
14
  import useDropdownStore, { DropdownView } from "../../../stores/dropdownStore"
13
-
14
- type AccountAddressActionsProps = {
15
- address: string
16
- }
15
+ import useWalletAccount from "../../../hooks/useWalletAccount"
16
+ import AccountError from "./AccountError"
17
17
 
18
18
  const buttonStartEnhancerSize = 12
19
19
 
20
20
  const commonButtonProps: Partial<ButtonProps> = {
21
21
  kind: "secondary",
22
- size: "xsmall",
22
+ size: "small",
23
+ shape: "pill",
23
24
  overrides: {
24
25
  BaseButton: {
25
26
  style: {
@@ -34,50 +35,69 @@ const commonButtonProps: Partial<ButtonProps> = {
34
35
  },
35
36
  }
36
37
 
37
- export default function AccountAddressActions(
38
- props: AccountAddressActionsProps,
39
- ) {
40
- const { address } = props
38
+ export default function AccountAddressActions(props: BlockProps) {
39
+ const { overrides, ...restProps } = props
41
40
 
42
41
  const [, theme] = useStyletron()
43
-
44
42
  const { environment } = usePassportContext()
43
+ const setDropdownView = useDropdownStore((state) => state.setView)
44
+ const handleReceiveClick = () => setDropdownView(DropdownView.RECEIVE)
45
+
46
+ const {
47
+ data: walletAccountData,
48
+ isError: isWalletAccountDataError,
49
+ isPending: isWalletAccountDataPending,
50
+ } = useWalletAccount()
51
+
52
+ if (isWalletAccountDataError) {
53
+ return <AccountError topic="wallet account data" />
54
+ }
55
+
56
+ if (isWalletAccountDataPending) {
57
+ return (
58
+ <Block
59
+ display="flex"
60
+ alignItems="center"
61
+ backgroundColor="transparent"
62
+ marginBottom={theme.sizing.scale600}
63
+ overrides={{
64
+ Block: {
65
+ style: {
66
+ gap: theme.sizing.scale600,
67
+ },
68
+ },
69
+ }}
70
+ >
71
+ <Skeleton animation width="100%" height="28px" />
72
+ <Skeleton animation width="100%" height="28px" />
73
+ </Block>
74
+ )
75
+ }
76
+
45
77
  const blockExplorerUrl = getAddressExplorerUrl(
46
- address,
78
+ walletAccountData.accountAddress,
47
79
  "mezo",
48
80
  environment === "testnet",
49
81
  )
50
82
 
51
- const setDropdownView = useDropdownStore((state) => state.setView)
52
-
53
- const handleReceiveClick = useCallback(() => {
54
- setDropdownView(DropdownView.RECEIVE)
55
- }, [setDropdownView])
56
-
57
83
  return (
58
84
  <Block
59
85
  display="flex"
60
86
  alignItems="center"
61
87
  backgroundColor="transparent"
62
- marginBottom={theme.sizing.scale600}
63
- overrides={{
64
- Block: {
65
- style: {
66
- gap: theme.sizing.scale600,
88
+ padding={`0 ${theme.sizing.scale600} ${theme.sizing.scale800}`}
89
+ overrides={mergeOverrides(
90
+ {
91
+ Block: {
92
+ style: {
93
+ gap: theme.sizing.scale600,
94
+ },
67
95
  },
68
96
  },
69
- }}
97
+ overrides,
98
+ )}
99
+ {...restProps}
70
100
  >
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
101
  <Button
82
102
  onClick={handleReceiveClick}
83
103
  startEnhancer={
@@ -96,6 +116,15 @@ export default function AccountAddressActions(
96
116
  >
97
117
  Receive
98
118
  </Button>
119
+
120
+ <Button
121
+ $as="a"
122
+ href={blockExplorerUrl}
123
+ target="_blank"
124
+ {...commonButtonProps}
125
+ >
126
+ Block Explorer
127
+ </Button>
99
128
  </Block>
100
129
  )
101
130
  }
@@ -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
+ }