@mezo-org/passport 0.4.0-dev.6 → 0.4.0-dev.60

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 (248) hide show
  1. package/README.md +18 -22
  2. package/dist/src/api/auth.d.ts.map +1 -1
  3. package/dist/src/api/auth.js +3 -1
  4. package/dist/src/api/auth.js.map +1 -1
  5. package/dist/src/api/client.d.ts +4 -1
  6. package/dist/src/api/client.d.ts.map +1 -1
  7. package/dist/src/api/client.js +9 -2
  8. package/dist/src/api/client.js.map +1 -1
  9. package/dist/src/api/portal.d.ts +3 -9
  10. package/dist/src/api/portal.d.ts.map +1 -1
  11. package/dist/src/api/portal.js +8 -5
  12. package/dist/src/api/portal.js.map +1 -1
  13. package/dist/src/components/Dropdown/ConnectedTrigger.d.ts +2 -1
  14. package/dist/src/components/Dropdown/ConnectedTrigger.d.ts.map +1 -1
  15. package/dist/src/components/Dropdown/ConnectedTrigger.js +29 -20
  16. package/dist/src/components/Dropdown/ConnectedTrigger.js.map +1 -1
  17. package/dist/src/components/Dropdown/Content.d.ts +20 -5
  18. package/dist/src/components/Dropdown/Content.d.ts.map +1 -1
  19. package/dist/src/components/Dropdown/Content.js +19 -57
  20. package/dist/src/components/Dropdown/Content.js.map +1 -1
  21. package/dist/src/components/Dropdown/DisconnectedTrigger.d.ts.map +1 -1
  22. package/dist/src/components/Dropdown/DisconnectedTrigger.js +2 -2
  23. package/dist/src/components/Dropdown/DisconnectedTrigger.js.map +1 -1
  24. package/dist/src/components/Dropdown/Dropdown.d.ts +17 -8
  25. package/dist/src/components/Dropdown/Dropdown.d.ts.map +1 -1
  26. package/dist/src/components/Dropdown/Dropdown.js +35 -9
  27. package/dist/src/components/Dropdown/Dropdown.js.map +1 -1
  28. package/dist/src/components/Dropdown/ListingItem.d.ts +13 -0
  29. package/dist/src/components/Dropdown/ListingItem.d.ts.map +1 -0
  30. package/dist/src/components/Dropdown/ListingItem.js +34 -0
  31. package/dist/src/components/Dropdown/ListingItem.js.map +1 -0
  32. package/dist/src/components/Dropdown/NestedViewLayout.d.ts +7 -0
  33. package/dist/src/components/Dropdown/NestedViewLayout.d.ts.map +1 -0
  34. package/dist/src/components/Dropdown/NestedViewLayout.js +34 -0
  35. package/dist/src/components/Dropdown/NestedViewLayout.js.map +1 -0
  36. package/dist/src/components/Dropdown/Receive/Receive.d.ts +7 -0
  37. package/dist/src/components/Dropdown/Receive/Receive.d.ts.map +1 -0
  38. package/dist/src/components/Dropdown/Receive/Receive.js +53 -0
  39. package/dist/src/components/Dropdown/Receive/Receive.js.map +1 -0
  40. package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts +7 -0
  41. package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts.map +1 -0
  42. package/dist/src/components/Dropdown/Root/AccountAddressActions.js +48 -0
  43. package/dist/src/components/Dropdown/Root/AccountAddressActions.js.map +1 -0
  44. package/dist/src/components/Dropdown/Root/AccountAssetItem.d.ts +11 -0
  45. package/dist/src/components/Dropdown/Root/AccountAssetItem.d.ts.map +1 -0
  46. package/dist/src/components/Dropdown/Root/AccountAssetItem.js +9 -0
  47. package/dist/src/components/Dropdown/Root/AccountAssetItem.js.map +1 -0
  48. package/dist/src/components/Dropdown/{AccountBalance.d.ts → Root/AccountBalance.d.ts} +2 -1
  49. package/dist/src/components/Dropdown/Root/AccountBalance.d.ts.map +1 -0
  50. package/dist/src/components/Dropdown/Root/AccountBalance.js +15 -0
  51. package/dist/src/components/Dropdown/Root/AccountBalance.js.map +1 -0
  52. package/dist/src/components/Dropdown/Root/AccountBtcListing.d.ts +3 -0
  53. package/dist/src/components/Dropdown/Root/AccountBtcListing.d.ts.map +1 -0
  54. package/dist/src/components/Dropdown/Root/AccountBtcListing.js +22 -0
  55. package/dist/src/components/Dropdown/Root/AccountBtcListing.js.map +1 -0
  56. package/dist/src/components/Dropdown/Root/AccountMusdListing.d.ts +3 -0
  57. package/dist/src/components/Dropdown/Root/AccountMusdListing.d.ts.map +1 -0
  58. package/dist/src/components/Dropdown/Root/AccountMusdListing.js +22 -0
  59. package/dist/src/components/Dropdown/Root/AccountMusdListing.js.map +1 -0
  60. package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts +9 -0
  61. package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts.map +1 -0
  62. package/dist/src/components/Dropdown/Root/AccountOtherAssets.js +48 -0
  63. package/dist/src/components/Dropdown/Root/AccountOtherAssets.js.map +1 -0
  64. package/dist/src/components/Dropdown/Root/Root.d.ts +23 -0
  65. package/dist/src/components/Dropdown/Root/Root.d.ts.map +1 -0
  66. package/dist/src/components/Dropdown/Root/Root.js +57 -0
  67. package/dist/src/components/Dropdown/Root/Root.js.map +1 -0
  68. package/dist/src/components/Dropdown/Root/WalletAddress.d.ts +8 -0
  69. package/dist/src/components/Dropdown/Root/WalletAddress.d.ts.map +1 -0
  70. package/dist/src/components/Dropdown/{AccountAddress.js → Root/WalletAddress.js} +21 -15
  71. package/dist/src/components/Dropdown/Root/WalletAddress.js.map +1 -0
  72. package/dist/src/components/Dropdown/{WelcomeBlock.d.ts → Root/WelcomeBlock.d.ts} +1 -1
  73. package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts.map +1 -0
  74. package/dist/src/components/Dropdown/{WelcomeBlock.js → Root/WelcomeBlock.js} +5 -5
  75. package/dist/src/components/Dropdown/Root/WelcomeBlock.js.map +1 -0
  76. package/dist/src/components/Dropdown/TestnetTopBanner.d.ts +3 -0
  77. package/dist/src/components/Dropdown/TestnetTopBanner.d.ts.map +1 -0
  78. package/dist/src/components/Dropdown/TestnetTopBanner.js +14 -0
  79. package/dist/src/components/Dropdown/TestnetTopBanner.js.map +1 -0
  80. package/dist/src/config.d.ts +17 -5
  81. package/dist/src/config.d.ts.map +1 -1
  82. package/dist/src/config.js +51 -14
  83. package/dist/src/config.js.map +1 -1
  84. package/dist/src/constants.d.ts +11 -3
  85. package/dist/src/constants.d.ts.map +1 -1
  86. package/dist/src/constants.js +12 -4
  87. package/dist/src/constants.js.map +1 -1
  88. package/dist/src/hooks/index.d.ts +3 -0
  89. package/dist/src/hooks/index.d.ts.map +1 -1
  90. package/dist/src/hooks/index.js +3 -0
  91. package/dist/src/hooks/index.js.map +1 -1
  92. package/dist/src/hooks/useAssetsConversionRates.d.ts +23 -0
  93. package/dist/src/hooks/useAssetsConversionRates.d.ts.map +1 -0
  94. package/dist/src/hooks/useAssetsConversionRates.js +90 -0
  95. package/dist/src/hooks/useAssetsConversionRates.js.map +1 -0
  96. package/dist/src/hooks/useAuthenticateWithWallet.d.ts.map +1 -1
  97. package/dist/src/hooks/useAuthenticateWithWallet.js +7 -8
  98. package/dist/src/hooks/useAuthenticateWithWallet.js.map +1 -1
  99. package/dist/src/hooks/useAutoConnect.d.ts +10 -0
  100. package/dist/src/hooks/useAutoConnect.d.ts.map +1 -0
  101. package/dist/src/hooks/useAutoConnect.js +41 -0
  102. package/dist/src/hooks/useAutoConnect.js.map +1 -0
  103. package/dist/src/hooks/useBorrowData.d.ts +82 -0
  104. package/dist/src/hooks/useBorrowData.d.ts.map +1 -0
  105. package/dist/src/hooks/useBorrowData.js +157 -0
  106. package/dist/src/hooks/useBorrowData.js.map +1 -0
  107. package/dist/src/hooks/useDropdownData.d.ts +37 -34
  108. package/dist/src/hooks/useDropdownData.d.ts.map +1 -1
  109. package/dist/src/hooks/useDropdownData.js +85 -61
  110. package/dist/src/hooks/useDropdownData.js.map +1 -1
  111. package/dist/src/hooks/useRefreshPassport.d.ts +19 -0
  112. package/dist/src/hooks/useRefreshPassport.d.ts.map +1 -0
  113. package/dist/src/hooks/useRefreshPassport.js +44 -0
  114. package/dist/src/hooks/useRefreshPassport.js.map +1 -0
  115. package/dist/src/hooks/useTokensBalances.d.ts +74 -0
  116. package/dist/src/hooks/useTokensBalances.d.ts.map +1 -0
  117. package/dist/src/hooks/useTokensBalances.js +140 -0
  118. package/dist/src/hooks/useTokensBalances.js.map +1 -0
  119. package/dist/src/hooks/useWalletAccount.d.ts +2 -1
  120. package/dist/src/hooks/useWalletAccount.d.ts.map +1 -1
  121. package/dist/src/hooks/useWalletAccount.js +19 -15
  122. package/dist/src/hooks/useWalletAccount.js.map +1 -1
  123. package/dist/src/hooks/useWatchTransferEvents.d.ts +5 -0
  124. package/dist/src/hooks/useWatchTransferEvents.d.ts.map +1 -0
  125. package/dist/src/hooks/useWatchTransferEvents.js +63 -0
  126. package/dist/src/hooks/useWatchTransferEvents.js.map +1 -0
  127. package/dist/src/index.d.ts +1 -1
  128. package/dist/src/index.d.ts.map +1 -1
  129. package/dist/src/index.js +1 -1
  130. package/dist/src/index.js.map +1 -1
  131. package/dist/src/lib/contracts/index.d.ts +13 -0
  132. package/dist/src/lib/contracts/index.d.ts.map +1 -0
  133. package/dist/src/lib/contracts/index.js +62 -0
  134. package/dist/src/lib/contracts/index.js.map +1 -0
  135. package/dist/src/lib/contracts/priceOracle.d.ts +43 -0
  136. package/dist/src/lib/contracts/priceOracle.d.ts.map +1 -0
  137. package/dist/src/lib/contracts/priceOracle.js +52 -0
  138. package/dist/src/lib/contracts/priceOracle.js.map +1 -0
  139. package/dist/src/provider.js +1 -1
  140. package/dist/src/provider.js.map +1 -1
  141. package/dist/src/stores/connectorStore.d.ts +12 -0
  142. package/dist/src/stores/connectorStore.d.ts.map +1 -0
  143. package/dist/src/stores/connectorStore.js +13 -0
  144. package/dist/src/stores/connectorStore.js.map +1 -0
  145. package/dist/src/stores/dropdownStore copy.d.ts +12 -0
  146. package/dist/src/stores/dropdownStore copy.d.ts.map +1 -0
  147. package/dist/src/stores/dropdownStore copy.js +13 -0
  148. package/dist/src/stores/dropdownStore copy.js.map +1 -0
  149. package/dist/src/stores/dropdownStore.d.ts +12 -0
  150. package/dist/src/stores/dropdownStore.d.ts.map +1 -0
  151. package/dist/src/stores/dropdownStore.js +13 -0
  152. package/dist/src/stores/dropdownStore.js.map +1 -0
  153. package/dist/src/utils/address.d.ts +1 -1
  154. package/dist/src/utils/address.d.ts.map +1 -1
  155. package/dist/src/utils/address.js +2 -0
  156. package/dist/src/utils/address.js.map +1 -1
  157. package/dist/src/utils/address.test.js +8 -5
  158. package/dist/src/utils/address.test.js.map +1 -1
  159. package/dist/src/utils/assets.d.ts +145 -0
  160. package/dist/src/utils/assets.d.ts.map +1 -0
  161. package/dist/src/utils/assets.js +100 -0
  162. package/dist/src/utils/assets.js.map +1 -0
  163. package/dist/src/utils/assets.test.d.ts +2 -0
  164. package/dist/src/utils/assets.test.d.ts.map +1 -0
  165. package/dist/src/utils/assets.test.js +46 -0
  166. package/dist/src/utils/assets.test.js.map +1 -0
  167. package/dist/src/utils/cryptoAssets.d.ts +17 -1
  168. package/dist/src/utils/cryptoAssets.d.ts.map +1 -1
  169. package/dist/src/utils/cryptoAssets.js +87 -31
  170. package/dist/src/utils/cryptoAssets.js.map +1 -1
  171. package/dist/src/utils/cryptoAssets.test.js +51 -33
  172. package/dist/src/utils/cryptoAssets.test.js.map +1 -1
  173. package/dist/src/utils/currency.d.ts +8 -0
  174. package/dist/src/utils/currency.d.ts.map +1 -1
  175. package/dist/src/utils/currency.js +11 -0
  176. package/dist/src/utils/currency.js.map +1 -1
  177. package/dist/src/utils/currency.test.js +1 -0
  178. package/dist/src/utils/currency.test.js.map +1 -1
  179. package/dist/src/utils/numbers.d.ts +32 -17
  180. package/dist/src/utils/numbers.d.ts.map +1 -1
  181. package/dist/src/utils/numbers.js +84 -33
  182. package/dist/src/utils/numbers.js.map +1 -1
  183. package/dist/src/utils/numbers.test.js +124 -22
  184. package/dist/src/utils/numbers.test.js.map +1 -1
  185. package/package.json +11 -9
  186. package/src/api/auth.ts +3 -1
  187. package/src/api/client.ts +11 -2
  188. package/src/api/portal.ts +11 -14
  189. package/src/components/Dropdown/ConnectedTrigger.tsx +52 -32
  190. package/src/components/Dropdown/Content.tsx +69 -113
  191. package/src/components/Dropdown/DisconnectedTrigger.tsx +2 -1
  192. package/src/components/Dropdown/Dropdown.tsx +86 -19
  193. package/src/components/Dropdown/ListingItem.tsx +80 -0
  194. package/src/components/Dropdown/NestedViewLayout.tsx +75 -0
  195. package/src/components/Dropdown/README.md +13 -18
  196. package/src/components/Dropdown/Receive/Receive.tsx +119 -0
  197. package/src/components/Dropdown/Root/AccountAddressActions.tsx +101 -0
  198. package/src/components/Dropdown/Root/AccountAssetItem.tsx +26 -0
  199. package/src/components/Dropdown/Root/AccountBalance.tsx +30 -0
  200. package/src/components/Dropdown/Root/AccountOtherAssets.tsx +68 -0
  201. package/src/components/Dropdown/Root/Root.tsx +147 -0
  202. package/src/components/Dropdown/Root/WalletAddress.tsx +128 -0
  203. package/src/components/Dropdown/{WelcomeBlock.tsx → Root/WelcomeBlock.tsx} +5 -6
  204. package/src/components/Dropdown/TestnetTopBanner.tsx +32 -0
  205. package/src/config.ts +77 -20
  206. package/src/constants.ts +12 -4
  207. package/src/hooks/index.ts +6 -0
  208. package/src/hooks/useAssetsConversionRates.ts +97 -0
  209. package/src/hooks/useAuthenticateWithWallet.ts +8 -11
  210. package/src/hooks/useBorrowData.ts +181 -0
  211. package/src/hooks/useDropdownData.ts +119 -97
  212. package/src/hooks/useRefreshPassport.ts +56 -0
  213. package/src/hooks/useTokensBalances.ts +187 -0
  214. package/src/hooks/useWalletAccount.ts +33 -19
  215. package/src/hooks/useWatchTransferEvents.ts +74 -0
  216. package/src/index.ts +11 -1
  217. package/src/lib/contracts/index.ts +92 -0
  218. package/src/lib/contracts/priceOracle.ts +53 -0
  219. package/src/provider.ts +1 -1
  220. package/src/stores/dropdownStore.ts +20 -0
  221. package/src/utils/address.test.ts +10 -6
  222. package/src/utils/address.ts +5 -3
  223. package/src/utils/cryptoAssets.test.ts +57 -37
  224. package/src/utils/cryptoAssets.ts +113 -35
  225. package/src/utils/currency.test.ts +2 -0
  226. package/src/utils/currency.ts +21 -0
  227. package/src/utils/numbers.test.ts +154 -23
  228. package/src/utils/numbers.ts +112 -34
  229. package/dist/src/components/Dropdown/AccountAddress.d.ts +0 -8
  230. package/dist/src/components/Dropdown/AccountAddress.d.ts.map +0 -1
  231. package/dist/src/components/Dropdown/AccountAddress.js.map +0 -1
  232. package/dist/src/components/Dropdown/AccountAssets.d.ts +0 -14
  233. package/dist/src/components/Dropdown/AccountAssets.d.ts.map +0 -1
  234. package/dist/src/components/Dropdown/AccountAssets.js +0 -44
  235. package/dist/src/components/Dropdown/AccountAssets.js.map +0 -1
  236. package/dist/src/components/Dropdown/AccountBalance.d.ts.map +0 -1
  237. package/dist/src/components/Dropdown/AccountBalance.js +0 -18
  238. package/dist/src/components/Dropdown/AccountBalance.js.map +0 -1
  239. package/dist/src/components/Dropdown/WelcomeBlock.d.ts.map +0 -1
  240. package/dist/src/components/Dropdown/WelcomeBlock.js.map +0 -1
  241. package/dist/src/hooks/useAssetsUSDConversion.d.ts +0 -8
  242. package/dist/src/hooks/useAssetsUSDConversion.d.ts.map +0 -1
  243. package/dist/src/hooks/useAssetsUSDConversion.js +0 -21
  244. package/dist/src/hooks/useAssetsUSDConversion.js.map +0 -1
  245. package/src/components/Dropdown/AccountAddress.tsx +0 -111
  246. package/src/components/Dropdown/AccountAssets.tsx +0 -110
  247. package/src/components/Dropdown/AccountBalance.tsx +0 -38
  248. package/src/hooks/useAssetsUSDConversion.ts +0 -31
@@ -1,72 +1,64 @@
1
- import {
2
- Block,
3
- Button,
4
- LogOut01,
5
- Mats,
6
- ParagraphSmall,
7
- useStyletron,
8
- } from "@mezo-org/mezo-clay"
9
- import React, { useCallback } from "react"
10
- import { useDisconnect } from "wagmi"
11
- import { useSignOut } from "../../hooks"
12
- import { DropdownData } from "../../hooks/useDropdownData"
13
- import AccountAddress from "./AccountAddress"
14
- import AccountAssets from "./AccountAssets"
15
- import AccountBalance from "./AccountBalance"
16
- import WelcomeBlock from "./WelcomeBlock"
1
+ import { Block, useStyletron } from "@mezo-org/mezo-clay"
2
+ import React, { useEffect } from "react"
3
+ import useDropdownStore, { DropdownView } from "../../stores/dropdownStore"
4
+ import Root from "./Root/Root"
5
+ import Receive from "./Receive/Receive"
6
+ import { DetailedCryptoAsset } from "../../utils/cryptoAssets"
7
+ import TestnetTopBanner from "./TestnetTopBanner"
17
8
 
18
- function MatsnetLabel() {
19
- const [, theme] = useStyletron()
20
- return (
21
- <ParagraphSmall color={theme.colors.contentTertiary}>
22
- <Mats
23
- color="currentColor"
24
- size={theme.sizing.scale400}
25
- overrides={{
26
- Svg: {
27
- style: {
28
- marginRight: theme.sizing.scale300,
29
- },
30
- },
31
- }}
32
- />
33
- Matsnet Assets
34
- </ParagraphSmall>
35
- )
9
+ type ContentProps = {
10
+ mezoId: string
11
+ matsBalance: number
12
+ accountAddress: string
13
+ walletAddress: string
14
+ walletType: "bitcoin" | "evm"
15
+ usdTotalBalance: number
16
+ usdTroveDebt: number
17
+ usdCollateral: number
18
+ assets: {
19
+ btc: DetailedCryptoAsset
20
+ musd: DetailedCryptoAsset
21
+ }
22
+ otherAssetsCount: number
23
+ otherAssetsUsdTotal: number
24
+ onSignOut?: () => void
25
+ onOtherAssetsClick?: () => void
36
26
  }
37
27
 
38
- type DropdownContentProps = {
39
- data: DropdownData
40
- }
41
-
42
- export default function DropdownContent(props: DropdownContentProps) {
43
- const { data } = props
44
-
45
- const [, theme] = useStyletron()
46
-
28
+ function Content(props: ContentProps) {
47
29
  const {
48
30
  mezoId,
49
- address,
31
+ accountAddress,
32
+ walletAddress,
50
33
  walletType,
51
- totalBalanceInUsd,
52
- formattedNativeAssets,
53
- matsnet,
54
- } = data
34
+ usdTotalBalance,
35
+ assets,
36
+ matsBalance,
37
+ usdTroveDebt,
38
+ usdCollateral,
39
+ otherAssetsCount,
40
+ otherAssetsUsdTotal,
41
+ onSignOut,
42
+ onOtherAssetsClick,
43
+ } = props
55
44
 
56
- const { disconnect } = useDisconnect()
57
- const { signOut } = useSignOut()
45
+ const [_, theme] = useStyletron()
58
46
 
59
- const handleLogOut = useCallback(() => {
60
- signOut()
61
- disconnect()
62
- }, [signOut, disconnect])
47
+ const currentView = useDropdownStore((state) => state.view)
48
+ const setView = useDropdownStore((state) => state.setView)
49
+
50
+ useEffect(
51
+ () => () => {
52
+ setView(DropdownView.ROOT)
53
+ },
54
+ [setView],
55
+ )
63
56
 
64
57
  return (
65
58
  <Block
66
59
  display="inline-flex"
67
60
  flexDirection="column"
68
61
  backgroundColor={theme.colors.backgroundPrimary}
69
- padding={theme.sizing.scale500}
70
62
  width="100%"
71
63
  overrides={{
72
64
  Block: {
@@ -76,67 +68,31 @@ export default function DropdownContent(props: DropdownContentProps) {
76
68
  },
77
69
  }}
78
70
  >
79
- <WelcomeBlock mezoId={mezoId} matsBalance={matsnet.mats} />
80
-
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
- <AccountAddress address={address} type={walletType} />
91
-
92
- <AccountBalance amount={totalBalanceInUsd} />
71
+ <TestnetTopBanner />
93
72
 
94
- <AccountAssets label="Assets" assets={formattedNativeAssets} />
95
- </Block>
96
-
97
- {matsnet.formattedAssets.length > 0 && (
98
- <Block
99
- marginTop={theme.sizing.scale600}
100
- backgroundColor={theme.colors.backgroundSecondary}
101
- overflow="hidden"
102
- overrides={{
103
- Block: { style: { borderRadius: theme.borders.radius300 } },
104
- }}
105
- >
106
- <AccountAssets
107
- label={<MatsnetLabel />}
108
- assets={matsnet.formattedAssets}
109
- />
110
- </Block>
73
+ {currentView === DropdownView.ROOT && (
74
+ <Root
75
+ mezoId={mezoId}
76
+ accountAddress={accountAddress}
77
+ walletAddress={walletAddress}
78
+ walletType={walletType}
79
+ usdTotalBalance={usdTotalBalance}
80
+ assets={assets}
81
+ matsBalance={matsBalance}
82
+ usdTroveDebt={usdTroveDebt}
83
+ usdCollateral={usdCollateral}
84
+ otherAssetsCount={otherAssetsCount}
85
+ otherAssetsUsdTotal={otherAssetsUsdTotal}
86
+ onSignOut={onSignOut}
87
+ onOtherAssetsClick={onOtherAssetsClick}
88
+ />
111
89
  )}
112
90
 
113
- <Block
114
- marginTop={theme.sizing.scale700}
115
- padding={`0 ${theme.sizing.scale100}`}
116
- >
117
- <Button
118
- size="small"
119
- kind="tertiary"
120
- startEnhancer={<LogOut01 color="currentColor" size={12} />}
121
- onClick={() => handleLogOut()}
122
- overrides={{
123
- Root: {
124
- style: {
125
- ":hover": {
126
- backgroundColor: theme.colors.backgroundSecondary,
127
- boxShadow: "none",
128
- },
129
- ":active": {
130
- backgroundColor: theme.colors.backgroundSecondary,
131
- color: theme.colors.contentPrimary,
132
- },
133
- },
134
- },
135
- }}
136
- >
137
- Log out
138
- </Button>
139
- </Block>
91
+ {currentView === DropdownView.RECEIVE && (
92
+ <Receive address={accountAddress} />
93
+ )}
140
94
  </Block>
141
95
  )
142
96
  }
97
+
98
+ export default Content
@@ -20,12 +20,13 @@ const DisconnectedTrigger = forwardRef<
20
20
  }
21
21
  overrides={{
22
22
  Root: {
23
- props: { ref, ...restProps },
23
+ props: { ref },
24
24
  },
25
25
  }}
26
26
  size="small"
27
27
  shape="pill"
28
28
  onClick={onClick}
29
+ {...restProps}
29
30
  >
30
31
  {children}
31
32
  </Button>
@@ -1,26 +1,37 @@
1
1
  import {
2
+ ButtonProps,
2
3
  StatefulPopover,
3
4
  StatefulPopoverProps,
4
5
  useStyletron,
5
6
  } from "@mezo-org/mezo-clay"
6
7
  import { useConnectModal } from "@rainbow-me/rainbowkit"
7
- import React from "react"
8
+ import React, { useEffect, useMemo } from "react"
9
+ import { useDisconnect } from "wagmi"
8
10
  import DefaultAvatar from "../../assets/DefaultAvatar"
9
- import useDropdownData, {
10
- DropdownCryptoAsset,
11
- } from "../../hooks/useDropdownData"
12
11
  import useWalletAccount from "../../hooks/useWalletAccount"
13
12
  import ConnectedTrigger from "./ConnectedTrigger"
14
13
  import Content from "./Content"
15
14
  import DisconnectedTrigger from "./DisconnectedTrigger"
15
+ import { useSignInWithWallet } from "../../hooks"
16
+ import useDropdownData from "../../hooks/useDropdownData"
16
17
 
17
18
  export type DropdownProps = {
18
- /** The callback to be called when the user clicks on the button in sign-in state */
19
- onSignInClick?: () => void
20
- /** The set of EVM native assets to be displayed in the dropdown */
21
- evmNativeAssets?: DropdownCryptoAsset<"tbtc" | "wbtc">[]
22
- /** The set of Matsnet assets to be displayed in the dropdown */
23
- matsnetAssets?: DropdownCryptoAsset<"mbtc" | "musd">[]
19
+ /** The callback to be called when the user clicks the sign-out button */
20
+ onSignOut?: () => void
21
+ /** The callback to be called when the user clicks the button in sign-in state */
22
+ onSignIn?: () => void
23
+ /** The props to be passed to the trigger button */
24
+ triggerProps?: {
25
+ signedIn?: Omit<ButtonProps, "onClick" | "size"> & {
26
+ size: "medium" | "large"
27
+ }
28
+ signedOut?: Omit<ButtonProps, "onClick">
29
+ }
30
+ onOtherAssetsClick?: () => void
31
+ /** Time in milliseconds after which account data (like mats or mezo id) in dropdown should be re-fetched. Default is 90000 (90 secs) */
32
+ accountDataRefetchInterval?: number
33
+ /** Time in milliseconds after which native balance in dropdown should be re-fetched. Default is 90000 (90 secs) */
34
+ nativeBalanceRefetchInterval?: number
24
35
  } & Omit<StatefulPopoverProps, "children" | "content">
25
36
 
26
37
  /**
@@ -32,26 +43,60 @@ export function Dropdown(props: DropdownProps) {
32
43
  const {
33
44
  placement = "bottomRight",
34
45
  animateOutTime = 120,
35
- onSignInClick,
36
- evmNativeAssets,
37
- matsnetAssets,
46
+ onSignIn,
47
+ onSignOut,
48
+ overrides,
49
+ triggerProps,
50
+ onOtherAssetsClick,
51
+ accountDataRefetchInterval,
52
+ nativeBalanceRefetchInterval,
38
53
  ...restProps
39
54
  } = props
40
55
 
41
56
  const [, theme] = useStyletron()
42
57
 
43
- const dropdownData = useDropdownData({ evmNativeAssets, matsnetAssets })
58
+ const data = useDropdownData({
59
+ accountDataRefetchInterval,
60
+ nativeBalanceRefetchInterval,
61
+ })
62
+
63
+ const isCriticalDropdownDataLoaded = useMemo(
64
+ () => Boolean(data.mezoId && data.accountAddress && data.walletAddress),
65
+ [data],
66
+ )
44
67
 
45
68
  const { openConnectModal } = useConnectModal()
46
69
 
47
70
  const { isConnected } = useWalletAccount()
48
71
 
49
- if (!dropdownData || !isConnected) {
72
+ const { signInWithWalletAsync, isPending } = useSignInWithWallet()
73
+
74
+ const { disconnectAsync } = useDisconnect()
75
+
76
+ useEffect(() => {
77
+ if (onSignIn) return
78
+
79
+ const handleSignIn = async () => {
80
+ if (!isConnected) return
81
+
82
+ try {
83
+ await signInWithWalletAsync()
84
+ } catch (error) {
85
+ await disconnectAsync()
86
+ }
87
+ }
88
+
89
+ handleSignIn()
90
+ }, [disconnectAsync, isConnected, onSignIn, signInWithWalletAsync])
91
+
92
+ if (!isConnected || !isCriticalDropdownDataLoaded) {
50
93
  return (
51
94
  <DisconnectedTrigger
52
95
  // If connect wallet flow is not provided it fallbacks to RainbowKit's
53
96
  // connect modal
54
- onClick={onSignInClick || openConnectModal}
97
+ onClick={onSignIn || openConnectModal}
98
+ isLoading={isPending}
99
+ {...triggerProps?.signedOut}
55
100
  >
56
101
  Sign in
57
102
  </DisconnectedTrigger>
@@ -60,22 +105,44 @@ export function Dropdown(props: DropdownProps) {
60
105
 
61
106
  return (
62
107
  <StatefulPopover
63
- content={<Content data={dropdownData} />}
108
+ content={
109
+ <Content
110
+ mezoId={data.mezoId!}
111
+ matsBalance={data.matsBalance}
112
+ accountAddress={data.accountAddress!}
113
+ walletAddress={data.walletAddress!}
114
+ walletType={data.walletType}
115
+ usdTotalBalance={data.usdTotalBalance}
116
+ usdTroveDebt={data.usdTroveDebt}
117
+ usdCollateral={data.usdCollateral}
118
+ assets={data.assets}
119
+ otherAssetsCount={data.otherAssetsCount}
120
+ otherAssetsUsdTotal={data.otherAssetsUsdTotal}
121
+ onSignOut={onSignOut}
122
+ onOtherAssetsClick={onOtherAssetsClick}
123
+ />
124
+ }
64
125
  placement={placement}
65
126
  animateOutTime={animateOutTime}
66
127
  overrides={{
128
+ ...overrides,
67
129
  Body: {
130
+ ...overrides?.Body,
68
131
  style: {
69
- minWidth: "378px",
132
+ width: "396px",
70
133
  borderRadius: theme.borders.radius500,
71
134
  boxShadow: theme.lighting.shadow500,
72
135
  overflow: "hidden",
136
+ ...overrides?.Body?.style,
73
137
  },
74
138
  },
75
139
  }}
76
140
  {...restProps}
77
141
  >
78
- <ConnectedTrigger avatar={<DefaultAvatar />} />
142
+ <ConnectedTrigger
143
+ avatar={<DefaultAvatar />}
144
+ {...triggerProps?.signedIn}
145
+ />
79
146
  </StatefulPopover>
80
147
  )
81
148
  }
@@ -0,0 +1,80 @@
1
+ import {
2
+ ListItem,
3
+ ListItemLabel,
4
+ mergeOverrides,
5
+ ListItemLabelProps,
6
+ IconProps,
7
+ ListItemProps,
8
+ } from "@mezo-org/mezo-clay"
9
+ import React, { FC } from "react"
10
+
11
+ const SHARED_LABEL_OVERRIDES: ListItemLabelProps["overrides"] = {
12
+ LabelDescription: {
13
+ style: {
14
+ color: "#4B4B4B", // contentSecondary
15
+ },
16
+ },
17
+ }
18
+
19
+ type ListingItemProps = {
20
+ icon?: FC<IconProps>
21
+ label: string
22
+ subLabel?: string
23
+ value: string
24
+ subValue?: string
25
+ overrides?: ListItemProps["overrides"]
26
+ }
27
+
28
+ export default function ListingItem(props: ListingItemProps) {
29
+ const {
30
+ icon: Icon,
31
+ label,
32
+ subLabel = "",
33
+ value,
34
+ subValue = "",
35
+ overrides,
36
+ } = props
37
+
38
+ return (
39
+ <ListItem
40
+ artwork={Icon}
41
+ // eslint-disable-next-line react/no-unstable-nested-components
42
+ endEnhancer={() => (
43
+ <ListItemLabel
44
+ description={subValue}
45
+ overrides={mergeOverrides(
46
+ {
47
+ LabelRoot: {
48
+ style: {
49
+ textAlign: "right",
50
+ },
51
+ },
52
+ },
53
+ SHARED_LABEL_OVERRIDES,
54
+ )}
55
+ >
56
+ {value}
57
+ </ListItemLabel>
58
+ )}
59
+ overrides={mergeOverrides(
60
+ {
61
+ Root: {
62
+ style: {
63
+ backgroundColor: "transparent",
64
+ },
65
+ },
66
+ Content: {
67
+ style: {
68
+ border: 0,
69
+ },
70
+ },
71
+ },
72
+ overrides,
73
+ )}
74
+ >
75
+ <ListItemLabel description={subLabel} overrides={SHARED_LABEL_OVERRIDES}>
76
+ {label}
77
+ </ListItemLabel>
78
+ </ListItem>
79
+ )
80
+ }
@@ -0,0 +1,75 @@
1
+ import {
2
+ ArrowLeft,
3
+ Block,
4
+ ButtonIcon,
5
+ LabelMedium,
6
+ useStyletron,
7
+ } from "@mezo-org/mezo-clay"
8
+ import React, { ReactNode, useCallback } from "react"
9
+ import useDropdownStore, { DropdownView } from "../../stores/dropdownStore"
10
+
11
+ const getHeaderTitle = (view: DropdownView) => {
12
+ const titleMap: Partial<Record<DropdownView, string>> = {
13
+ [DropdownView.RECEIVE]: "Receive",
14
+ }
15
+ return titleMap[view]!
16
+ }
17
+
18
+ type NestedViewLayoutProps = {
19
+ children: ReactNode
20
+ }
21
+
22
+ function NestedViewLayout(props: NestedViewLayoutProps) {
23
+ const { children, ...restProps } = props
24
+
25
+ const currentView = useDropdownStore((state) => state.view)
26
+ const setView = useDropdownStore((state) => state.setView)
27
+ const isNested = useDropdownStore((state) => state.isNestedView())
28
+
29
+ const [, theme] = useStyletron()
30
+
31
+ const handleOnButtonClick = useCallback(() => {
32
+ setView(DropdownView.ROOT)
33
+ }, [setView])
34
+
35
+ return (
36
+ <Block
37
+ display="flex"
38
+ flexDirection="column"
39
+ minHeight="588px"
40
+ padding={theme.sizing.scale700}
41
+ paddingTop={0}
42
+ {...restProps}
43
+ >
44
+ <Block
45
+ display="flex"
46
+ alignItems="center"
47
+ paddingTop={theme.sizing.scale600}
48
+ paddingBottom={theme.sizing.scale600}
49
+ marginBottom={theme.sizing.scale300}
50
+ >
51
+ <ButtonIcon
52
+ onClick={handleOnButtonClick}
53
+ 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
+ }}
63
+ >
64
+ <ArrowLeft size={theme.sizing.scale700} />
65
+ </ButtonIcon>
66
+
67
+ <LabelMedium>{getHeaderTitle(currentView)}</LabelMedium>
68
+ </Block>
69
+
70
+ {children}
71
+ </Block>
72
+ )
73
+ }
74
+
75
+ export default NestedViewLayout
@@ -5,24 +5,19 @@ component. It allows to establish the session and interact with the API.
5
5
 
6
6
  ## Props
7
7
 
8
- - `onSignInClick` (`() => void`) - The callback to be exected on trigger click
9
- when the state is disconnected, it's optional since by default it triggers the
10
- [Rainbow Kit's wallet connection modal](https://www.rainbowkit.com/docs/modal-hooks) -
11
- **optional**
12
- - `evmNativeAssets` (`Asset<"tbtc" | "wbtc">[]`) - Array of Matsnet assets. -
13
- **optional**
14
- - `matsnetAssets` (`Asset<"mbtc" | "musd">[]`) - Array of Matsnet assets. -
15
- **optional**
16
- ```ts
17
- type Asset = {
18
- type: "btc" | "tbtc" | "wbtc" | "mbtc" | "musd"
19
- decimals: number
20
- amount: {
21
- token: bigint
22
- usd: number
23
- }
24
- }
25
- ```
8
+ - `onSignIn` (`() => void`) - The callback to be executed on trigger click when
9
+ the state is disconnected. It's optional since by default it triggers the
10
+ [Rainbow Kit's wallet connection modal](https://www.rainbowkit.com/docs/modal-hooks).
11
+ If the callback is not provided it will automatically establish the Passport
12
+ Session. If not, you have to handle it manually using `useSignInWithWallet`
13
+ hook. - **optional**
14
+ - `onSignOut` (`() => void`) - The callback to be executed on click of the
15
+ **Sign out** button. It's optional since by default it disconnects the current
16
+ wallet connector and closes the Passport session. - **optional**
17
+ - `triggerProps.signedIn` (`ButtonProps`) - Props to be passed to the trigger
18
+ button in signed-in state.
19
+ - `triggerProps.signedOut` (`ButtonProps`) - Props to be passed to the trigger
20
+ button in signed-out state
26
21
 
27
22
  Besides that, component allows
28
23
  [Clay's `StatefulPopover` props](https://baseweb.design/components/popover/)