@mezo-org/passport 0.15.1-dev.7 → 0.16.0-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/assets/DefaultAvatar.d.ts +5 -0
- package/dist/src/assets/DefaultAvatar.d.ts.map +1 -0
- package/dist/src/assets/DefaultAvatar.js +21 -0
- package/dist/src/assets/DefaultAvatar.js.map +1 -0
- package/dist/src/components/Dropdown/ConnectedTrigger.d.ts +8 -0
- package/dist/src/components/Dropdown/ConnectedTrigger.d.ts.map +1 -0
- package/dist/src/components/Dropdown/ConnectedTrigger.js +39 -0
- package/dist/src/components/Dropdown/ConnectedTrigger.js.map +1 -0
- package/dist/src/components/Dropdown/Content.d.ts +8 -0
- package/dist/src/components/Dropdown/Content.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Content.js +27 -0
- package/dist/src/components/Dropdown/Content.js.map +1 -0
- package/dist/src/components/Dropdown/DisconnectedTrigger.d.ts +7 -0
- package/dist/src/components/Dropdown/DisconnectedTrigger.d.ts.map +1 -0
- package/dist/src/components/Dropdown/DisconnectedTrigger.js +13 -0
- package/dist/src/components/Dropdown/DisconnectedTrigger.js.map +1 -0
- package/dist/src/components/Dropdown/Dropdown.d.ts +23 -0
- package/dist/src/components/Dropdown/Dropdown.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Dropdown.js +45 -0
- package/dist/src/components/Dropdown/Dropdown.js.map +1 -0
- package/dist/src/components/Dropdown/ListingItem.d.ts +14 -0
- package/dist/src/components/Dropdown/ListingItem.d.ts.map +1 -0
- package/dist/src/components/Dropdown/ListingItem.js +42 -0
- package/dist/src/components/Dropdown/ListingItem.js.map +1 -0
- package/dist/src/components/Dropdown/NestedViewLayout.d.ts +8 -0
- package/dist/src/components/Dropdown/NestedViewLayout.d.ts.map +1 -0
- package/dist/src/components/Dropdown/NestedViewLayout.js +32 -0
- package/dist/src/components/Dropdown/NestedViewLayout.js.map +1 -0
- package/dist/src/components/Dropdown/Receive/Receive.d.ts +4 -0
- package/dist/src/components/Dropdown/Receive/Receive.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Receive/Receive.js +64 -0
- package/dist/src/components/Dropdown/Receive/Receive.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts +4 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.js +49 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountBalance.d.ts +6 -0
- package/dist/src/components/Dropdown/Root/AccountBalance.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountBalance.js +32 -0
- package/dist/src/components/Dropdown/Root/AccountBalance.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountBtcListing.d.ts +6 -0
- package/dist/src/components/Dropdown/Root/AccountBtcListing.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountBtcListing.js +28 -0
- package/dist/src/components/Dropdown/Root/AccountBtcListing.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountError.d.ts +8 -0
- package/dist/src/components/Dropdown/Root/AccountError.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountError.js +17 -0
- package/dist/src/components/Dropdown/Root/AccountError.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountMusdListing.d.ts +4 -0
- package/dist/src/components/Dropdown/Root/AccountMusdListing.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountMusdListing.js +21 -0
- package/dist/src/components/Dropdown/Root/AccountMusdListing.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts +8 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.js +43 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.js.map +1 -0
- package/dist/src/components/Dropdown/Root/Root.d.ts +8 -0
- package/dist/src/components/Dropdown/Root/Root.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/Root.js +45 -0
- package/dist/src/components/Dropdown/Root/Root.js.map +1 -0
- package/dist/src/components/Dropdown/Root/WalletAddress.d.ts +4 -0
- package/dist/src/components/Dropdown/Root/WalletAddress.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/WalletAddress.js +66 -0
- package/dist/src/components/Dropdown/Root/WalletAddress.js.map +1 -0
- package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts +6 -0
- package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/WelcomeBlock.js +88 -0
- package/dist/src/components/Dropdown/Root/WelcomeBlock.js.map +1 -0
- package/dist/src/components/Dropdown/SlotNumber.d.ts +19 -0
- package/dist/src/components/Dropdown/SlotNumber.d.ts.map +1 -0
- package/dist/src/components/Dropdown/SlotNumber.js +67 -0
- package/dist/src/components/Dropdown/SlotNumber.js.map +1 -0
- package/dist/src/components/Dropdown/TestnetTopBanner.d.ts +3 -0
- package/dist/src/components/Dropdown/TestnetTopBanner.d.ts.map +1 -0
- package/dist/src/components/Dropdown/TestnetTopBanner.js +14 -0
- package/dist/src/components/Dropdown/TestnetTopBanner.js.map +1 -0
- package/dist/src/components/Dropdown/index.d.ts +3 -0
- package/dist/src/components/Dropdown/index.d.ts.map +1 -0
- package/dist/src/components/Dropdown/index.js +2 -0
- package/dist/src/components/Dropdown/index.js.map +1 -0
- package/dist/src/components/index.d.ts +2 -0
- package/dist/src/components/index.d.ts.map +1 -0
- package/dist/src/components/index.js +2 -0
- package/dist/src/components/index.js.map +1 -0
- package/dist/src/config.d.ts +4 -3
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +13 -9
- package/dist/src/config.js.map +1 -1
- package/dist/src/hooks/index.d.ts +0 -1
- package/dist/src/hooks/index.d.ts.map +1 -1
- package/dist/src/hooks/index.js +0 -1
- package/dist/src/hooks/index.js.map +1 -1
- package/dist/src/hooks/useAuthenticateWithWallet.d.ts +11 -11
- package/dist/src/hooks/useAuthenticateWithWallet.js +1 -1
- package/dist/src/hooks/useAuthenticateWithWallet.js.map +1 -1
- package/dist/src/hooks/useBorrowData.js +1 -1
- package/dist/src/hooks/useBorrowData.js.map +1 -1
- package/dist/src/hooks/useCollateralPrice.js +1 -1
- package/dist/src/hooks/useCollateralPrice.js.map +1 -1
- package/dist/src/hooks/useCreateAccount.js +1 -1
- package/dist/src/hooks/useCreateAccount.js.map +1 -1
- package/dist/src/hooks/useLinkAccount.js +1 -1
- package/dist/src/hooks/useLinkAccount.js.map +1 -1
- package/dist/src/hooks/useSignInWithWallet.d.ts +11 -11
- package/dist/src/hooks/useSignUpWithWallet.d.ts +11 -11
- package/dist/src/hooks/useTokensBalances.d.ts.map +1 -1
- package/dist/src/hooks/useTokensBalances.js +10 -2
- package/dist/src/hooks/useTokensBalances.js.map +1 -1
- package/dist/src/hooks/useWalletAccount.d.ts +3 -3
- package/dist/src/hooks/useWalletAccount.d.ts.map +1 -1
- package/dist/src/hooks/useWalletAccount.js +4 -6
- package/dist/src/hooks/useWalletAccount.js.map +1 -1
- package/dist/src/hooks/useWatchTransferEvents.d.ts.map +1 -1
- package/dist/src/hooks/useWatchTransferEvents.js +1 -0
- package/dist/src/hooks/useWatchTransferEvents.js.map +1 -1
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib/contracts/artifacts/MEZO.json +428 -0
- package/dist/src/lib/contracts/index.d.ts +1 -1
- package/dist/src/lib/contracts/index.d.ts.map +1 -1
- package/dist/src/lib/contracts/index.js +3 -0
- package/dist/src/lib/contracts/index.js.map +1 -1
- package/dist/src/utils/assets.d.ts +15 -0
- package/dist/src/utils/assets.d.ts.map +1 -1
- package/dist/src/utils/assets.js +13 -0
- package/dist/src/utils/assets.js.map +1 -1
- package/package.json +8 -7
- package/src/assets/DefaultAvatar.tsx +74 -0
- package/src/components/Dropdown/ConnectedTrigger.tsx +76 -0
- package/src/components/Dropdown/Content.tsx +53 -0
- package/src/components/Dropdown/DisconnectedTrigger.tsx +36 -0
- package/src/components/Dropdown/Dropdown.tsx +100 -0
- package/src/components/Dropdown/ListingItem.tsx +176 -0
- package/src/components/Dropdown/NestedViewLayout.tsx +87 -0
- package/src/components/Dropdown/README.md +41 -0
- package/src/components/Dropdown/Receive/Receive.tsx +144 -0
- package/src/components/Dropdown/Root/AccountAddressActions.tsx +99 -0
- package/src/components/Dropdown/Root/AccountBalance.tsx +69 -0
- package/src/components/Dropdown/Root/AccountBtcListing.tsx +53 -0
- package/src/components/Dropdown/Root/AccountError.tsx +34 -0
- package/src/components/Dropdown/Root/AccountMusdListing.tsx +45 -0
- package/src/components/Dropdown/Root/AccountOtherAssets.tsx +85 -0
- package/src/components/Dropdown/Root/Root.tsx +77 -0
- package/src/components/Dropdown/Root/WalletAddress.tsx +123 -0
- package/src/components/Dropdown/Root/WelcomeBlock.tsx +173 -0
- package/src/components/Dropdown/SlotNumber.tsx +131 -0
- package/src/components/Dropdown/TestnetTopBanner.tsx +32 -0
- package/src/components/Dropdown/index.ts +2 -0
- package/src/components/index.ts +1 -0
- package/src/config.ts +26 -16
- package/src/hooks/index.ts +0 -1
- package/src/hooks/useAuthenticateWithWallet.ts +1 -1
- package/src/hooks/useBorrowData.ts +1 -1
- package/src/hooks/useCollateralPrice.ts +1 -1
- package/src/hooks/useCreateAccount.ts +1 -1
- package/src/hooks/useLinkAccount.ts +1 -1
- package/src/hooks/useTokensBalances.ts +10 -1
- package/src/hooks/useWalletAccount.ts +7 -18
- package/src/hooks/useWatchTransferEvents.ts +1 -0
- package/src/index.ts +2 -0
- package/src/lib/contracts/artifacts/MEZO.json +428 -0
- package/src/lib/contracts/index.ts +4 -0
- package/src/utils/assets.ts +14 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Block,
|
|
3
|
+
Button,
|
|
4
|
+
LabelLarge,
|
|
5
|
+
MezoCircle,
|
|
6
|
+
MonoLabelXSmall,
|
|
7
|
+
ParagraphSmall,
|
|
8
|
+
useStyletron,
|
|
9
|
+
} from "@mezo-org/mezo-clay"
|
|
10
|
+
import React, { useState } from "react"
|
|
11
|
+
import { useCopyToClipboard } from "usehooks-ts"
|
|
12
|
+
import { QRCodeSVG } from "qrcode.react"
|
|
13
|
+
import NestedViewLayout from "../NestedViewLayout"
|
|
14
|
+
import { getAddressExplorerUrl } from "../../../utils/address"
|
|
15
|
+
import { usePassportContext } from "../../../hooks/usePassportContext"
|
|
16
|
+
import useWalletAccount from "../../../hooks/useWalletAccount"
|
|
17
|
+
|
|
18
|
+
function Receive() {
|
|
19
|
+
const { environment } = usePassportContext()
|
|
20
|
+
|
|
21
|
+
const walletAccount = useWalletAccount()
|
|
22
|
+
|
|
23
|
+
const [, theme] = useStyletron()
|
|
24
|
+
|
|
25
|
+
const [, copy] = useCopyToClipboard()
|
|
26
|
+
|
|
27
|
+
const [isCopiedMessageVisible, setIsCopiedMessageVisible] = useState(false)
|
|
28
|
+
|
|
29
|
+
const handleCopyAddress = () => {
|
|
30
|
+
copy(walletAccount.accountAddress!)
|
|
31
|
+
setIsCopiedMessageVisible(true)
|
|
32
|
+
|
|
33
|
+
setTimeout(() => {
|
|
34
|
+
setIsCopiedMessageVisible(false)
|
|
35
|
+
}, 2000)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const blockExplorerUrl = getAddressExplorerUrl(
|
|
39
|
+
walletAccount.accountAddress!,
|
|
40
|
+
"mezo",
|
|
41
|
+
environment === "testnet",
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<NestedViewLayout>
|
|
46
|
+
<LabelLarge>Your Mezo Address</LabelLarge>
|
|
47
|
+
|
|
48
|
+
<ParagraphSmall
|
|
49
|
+
marginTop={0}
|
|
50
|
+
marginBottom={theme.sizing.scale800}
|
|
51
|
+
color={theme.colors.contentTertiary}
|
|
52
|
+
>
|
|
53
|
+
{walletAccount.networkFamily === "bitcoin" ? (
|
|
54
|
+
<>
|
|
55
|
+
Mezo automatically created a smart account that's fully
|
|
56
|
+
controlled by your connected Bitcoin wallet. Use this address to
|
|
57
|
+
receive assets on Mezo.
|
|
58
|
+
</>
|
|
59
|
+
) : (
|
|
60
|
+
<>
|
|
61
|
+
Your connected wallet address is your Mezo address. Use this address
|
|
62
|
+
to receive assets on Mezo.
|
|
63
|
+
</>
|
|
64
|
+
)}
|
|
65
|
+
</ParagraphSmall>
|
|
66
|
+
|
|
67
|
+
<Block
|
|
68
|
+
as={QRCodeSVG}
|
|
69
|
+
value={walletAccount.accountAddress!}
|
|
70
|
+
flex={1}
|
|
71
|
+
overrides={{
|
|
72
|
+
Block: {
|
|
73
|
+
style: {
|
|
74
|
+
aspectRatio: 1,
|
|
75
|
+
width: "fit-content",
|
|
76
|
+
margin: "0 auto",
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
}}
|
|
80
|
+
/>
|
|
81
|
+
|
|
82
|
+
<Block
|
|
83
|
+
display="flex"
|
|
84
|
+
alignItems="center"
|
|
85
|
+
backgroundColor={theme.colors.backgroundSecondary}
|
|
86
|
+
marginTop={theme.sizing.scale800}
|
|
87
|
+
marginBottom={theme.sizing.scale600}
|
|
88
|
+
padding={theme.sizing.scale300}
|
|
89
|
+
overrides={{
|
|
90
|
+
Block: {
|
|
91
|
+
style: {
|
|
92
|
+
gap: theme.sizing.scale300,
|
|
93
|
+
borderRadius: theme.borders.radius400,
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
}}
|
|
97
|
+
>
|
|
98
|
+
<MezoCircle
|
|
99
|
+
size={theme.sizing.scale700}
|
|
100
|
+
color={theme.colors.accent}
|
|
101
|
+
symbolColor={theme.colors.white}
|
|
102
|
+
overrides={{
|
|
103
|
+
Svg: {
|
|
104
|
+
style: {
|
|
105
|
+
backgroundColor: theme.colors.accent,
|
|
106
|
+
overflow: "hidden",
|
|
107
|
+
borderRadius: theme.borders.radius200,
|
|
108
|
+
flexShrink: 0,
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
}}
|
|
112
|
+
/>
|
|
113
|
+
|
|
114
|
+
<MonoLabelXSmall>{walletAccount.accountAddress}</MonoLabelXSmall>
|
|
115
|
+
</Block>
|
|
116
|
+
|
|
117
|
+
<Button
|
|
118
|
+
onClick={handleCopyAddress}
|
|
119
|
+
size="medium"
|
|
120
|
+
overrides={{
|
|
121
|
+
BaseButton: {
|
|
122
|
+
style: {
|
|
123
|
+
marginBottom: theme.sizing.scale500,
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
}}
|
|
127
|
+
>
|
|
128
|
+
{isCopiedMessageVisible ? "Copied!" : "Copy Mezo address"}
|
|
129
|
+
</Button>
|
|
130
|
+
|
|
131
|
+
<Button
|
|
132
|
+
kind="secondary"
|
|
133
|
+
size="medium"
|
|
134
|
+
$as="a"
|
|
135
|
+
href={blockExplorerUrl}
|
|
136
|
+
target="_blank"
|
|
137
|
+
>
|
|
138
|
+
View Mezo explorer
|
|
139
|
+
</Button>
|
|
140
|
+
</NestedViewLayout>
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export default Receive
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ArrowNarrowLeft,
|
|
3
|
+
Block,
|
|
4
|
+
BlockProps,
|
|
5
|
+
Button,
|
|
6
|
+
ButtonProps,
|
|
7
|
+
mergeOverrides,
|
|
8
|
+
useStyletron,
|
|
9
|
+
} from "@mezo-org/mezo-clay"
|
|
10
|
+
import React from "react"
|
|
11
|
+
import { usePassportContext } from "../../../hooks/usePassportContext"
|
|
12
|
+
import { getAddressExplorerUrl } from "../../../utils/address"
|
|
13
|
+
import useDropdownStore, { DropdownView } from "../../../stores/dropdownStore"
|
|
14
|
+
import useWalletAccount from "../../../hooks/useWalletAccount"
|
|
15
|
+
|
|
16
|
+
const buttonStartEnhancerSize = 12
|
|
17
|
+
|
|
18
|
+
const commonButtonProps: Partial<ButtonProps> = {
|
|
19
|
+
kind: "secondary",
|
|
20
|
+
size: "small",
|
|
21
|
+
shape: "pill",
|
|
22
|
+
overrides: {
|
|
23
|
+
BaseButton: {
|
|
24
|
+
style: {
|
|
25
|
+
flex: 1,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
StartEnhancer: {
|
|
29
|
+
style: {
|
|
30
|
+
stroke: "currentColor",
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export default function AccountAddressActions(props: BlockProps) {
|
|
37
|
+
const { overrides, ...restProps } = props
|
|
38
|
+
|
|
39
|
+
const [, theme] = useStyletron()
|
|
40
|
+
const { environment } = usePassportContext()
|
|
41
|
+
const setDropdownView = useDropdownStore((state) => state.setView)
|
|
42
|
+
const handleReceiveClick = () => setDropdownView(DropdownView.RECEIVE)
|
|
43
|
+
|
|
44
|
+
const walletAccount = useWalletAccount()
|
|
45
|
+
|
|
46
|
+
const blockExplorerUrl = getAddressExplorerUrl(
|
|
47
|
+
walletAccount.accountAddress!,
|
|
48
|
+
"mezo",
|
|
49
|
+
environment === "testnet",
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<Block
|
|
54
|
+
display="flex"
|
|
55
|
+
alignItems="center"
|
|
56
|
+
backgroundColor="transparent"
|
|
57
|
+
padding={`0 ${theme.sizing.scale600} ${theme.sizing.scale800}`}
|
|
58
|
+
overrides={mergeOverrides(
|
|
59
|
+
{
|
|
60
|
+
Block: {
|
|
61
|
+
style: {
|
|
62
|
+
gap: theme.sizing.scale600,
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
overrides,
|
|
67
|
+
)}
|
|
68
|
+
{...restProps}
|
|
69
|
+
>
|
|
70
|
+
<Button
|
|
71
|
+
onClick={handleReceiveClick}
|
|
72
|
+
startEnhancer={
|
|
73
|
+
<ArrowNarrowLeft
|
|
74
|
+
size={buttonStartEnhancerSize}
|
|
75
|
+
overrides={{
|
|
76
|
+
Svg: {
|
|
77
|
+
style: {
|
|
78
|
+
transform: "rotate(-45deg)",
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
}}
|
|
82
|
+
/>
|
|
83
|
+
}
|
|
84
|
+
{...commonButtonProps}
|
|
85
|
+
>
|
|
86
|
+
Receive
|
|
87
|
+
</Button>
|
|
88
|
+
|
|
89
|
+
<Button
|
|
90
|
+
$as="a"
|
|
91
|
+
href={blockExplorerUrl}
|
|
92
|
+
target="_blank"
|
|
93
|
+
{...commonButtonProps}
|
|
94
|
+
>
|
|
95
|
+
Block Explorer
|
|
96
|
+
</Button>
|
|
97
|
+
</Block>
|
|
98
|
+
)
|
|
99
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import React from "react"
|
|
2
|
+
import { BlockProps, useStyletron } from "@mezo-org/mezo-clay"
|
|
3
|
+
import { formatUnits } from "viem"
|
|
4
|
+
import ListingItem from "../ListingItem"
|
|
5
|
+
import { useTokensBalances } from "../../../hooks/useTokensBalances"
|
|
6
|
+
import { useBorrowData } from "../../../hooks/useBorrowData"
|
|
7
|
+
import AccountError from "./AccountError"
|
|
8
|
+
import { CONVERSION_RATE_DECIMALS } from "../../../hooks/useAssetsConversionRates"
|
|
9
|
+
import { usePassportContext } from "../../../hooks/usePassportContext"
|
|
10
|
+
|
|
11
|
+
type AccountBalanceProps = Omit<BlockProps, "children">
|
|
12
|
+
|
|
13
|
+
export default function AccountBalance(props: AccountBalanceProps) {
|
|
14
|
+
const { overrides, ...restProps } = props
|
|
15
|
+
const [, theme] = useStyletron()
|
|
16
|
+
const { nativeBalanceRefetchInterval } = usePassportContext()
|
|
17
|
+
|
|
18
|
+
const {
|
|
19
|
+
data: tokensBalancesData,
|
|
20
|
+
isError: isTokensBalancesError,
|
|
21
|
+
isPending: isTokensBalancesDataPending,
|
|
22
|
+
} = useTokensBalances({
|
|
23
|
+
queryOptions: {
|
|
24
|
+
staleTime: nativeBalanceRefetchInterval,
|
|
25
|
+
refetchInterval: nativeBalanceRefetchInterval,
|
|
26
|
+
},
|
|
27
|
+
})
|
|
28
|
+
const {
|
|
29
|
+
data: borrowData,
|
|
30
|
+
isError: isBorrowDataError,
|
|
31
|
+
isPending: isBorrowDataPending,
|
|
32
|
+
} = useBorrowData()
|
|
33
|
+
|
|
34
|
+
if (isTokensBalancesDataPending || isBorrowDataPending) {
|
|
35
|
+
return <ListingItem isLoading overrides={overrides} />
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (isTokensBalancesError || isBorrowDataError) {
|
|
39
|
+
return (
|
|
40
|
+
<AccountError
|
|
41
|
+
padding={`${theme.sizing.scale500} ${theme.sizing.scale800}`}
|
|
42
|
+
topic="account balance"
|
|
43
|
+
overrides={overrides}
|
|
44
|
+
/>
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const totalBalanceInUsd = Object.values(tokensBalancesData).reduce(
|
|
49
|
+
(acc, tokenBalance) => acc + tokenBalance.usd.value,
|
|
50
|
+
0n,
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
const totalBalanceNumber = Number(
|
|
54
|
+
formatUnits(totalBalanceInUsd, CONVERSION_RATE_DECIMALS),
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
const totalDebtNumber = Number(borrowData.debtInUsd.formatted)
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<ListingItem
|
|
61
|
+
label="Total assets"
|
|
62
|
+
value={totalBalanceNumber}
|
|
63
|
+
subLabel="Total liabilities"
|
|
64
|
+
subValue={totalDebtNumber}
|
|
65
|
+
overrides={overrides}
|
|
66
|
+
{...restProps}
|
|
67
|
+
/>
|
|
68
|
+
)
|
|
69
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
staleTime: nativeBalanceRefetchInterval,
|
|
28
|
+
refetchInterval: nativeBalanceRefetchInterval,
|
|
29
|
+
},
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
if (isTokensBalancesPending || isBorrowDataPending) {
|
|
33
|
+
return <ListingItem isLoading />
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (isTokensBalancesError || isBorrowDataError) {
|
|
37
|
+
return <AccountError topic="Bitcoin balance" />
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const btcBalance = Number(tokensBalancesData.BTC.usd.formatted)
|
|
41
|
+
const lockedCollateral = Number(borrowData.collateral.usd.formatted)
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<ListingItem
|
|
45
|
+
icon={<BitcoinCircle />}
|
|
46
|
+
label={getAsset("BTC").name}
|
|
47
|
+
value={btcBalance}
|
|
48
|
+
subLabel="Locked collateral"
|
|
49
|
+
subValue={lockedCollateral}
|
|
50
|
+
{...props}
|
|
51
|
+
/>
|
|
52
|
+
)
|
|
53
|
+
}
|
|
@@ -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 (isBorrowDataPending || isTokensBalancesPending) {
|
|
25
|
+
return <ListingItem isLoading />
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (isBorrowDataError || isTokensBalancesError) {
|
|
29
|
+
return <AccountError topic="MUSD balance" />
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const musdBalance = Number(tokensBalancesData.MUSD.usd.formatted)
|
|
33
|
+
const lockedCollateral = Number(borrowData.debtInUsd.formatted)
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<ListingItem
|
|
37
|
+
icon={<MUsdCircle02 />}
|
|
38
|
+
label={getAsset("MUSD").name}
|
|
39
|
+
value={musdBalance}
|
|
40
|
+
subLabel="Borrowed"
|
|
41
|
+
subValue={lockedCollateral}
|
|
42
|
+
{...props}
|
|
43
|
+
/>
|
|
44
|
+
)
|
|
45
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import React from "react"
|
|
2
|
+
import {
|
|
3
|
+
useStyletron,
|
|
4
|
+
CoinsStacked02,
|
|
5
|
+
mergeOverrides,
|
|
6
|
+
BlockProps,
|
|
7
|
+
} from "@mezo-org/mezo-clay"
|
|
8
|
+
import { formatUnits } from "viem"
|
|
9
|
+
import ListingItem from "../ListingItem"
|
|
10
|
+
import { useTokensBalances } from "../../../hooks/useTokensBalances"
|
|
11
|
+
import AccountError from "./AccountError"
|
|
12
|
+
import { CONVERSION_RATE_DECIMALS } from "../../../hooks/useAssetsConversionRates"
|
|
13
|
+
|
|
14
|
+
type AccountOtherAssetsProps = {
|
|
15
|
+
onClick?: () => void
|
|
16
|
+
} & Omit<BlockProps, "children">
|
|
17
|
+
|
|
18
|
+
export default function AccountOtherAssets(props: AccountOtherAssetsProps) {
|
|
19
|
+
const { onClick, overrides, ...restProps } = props
|
|
20
|
+
|
|
21
|
+
const [, theme] = useStyletron()
|
|
22
|
+
|
|
23
|
+
const {
|
|
24
|
+
data: tokensBalancesData,
|
|
25
|
+
isPending: isTokensBalancesPending,
|
|
26
|
+
isError: isTokensBalancesError,
|
|
27
|
+
} = useTokensBalances()
|
|
28
|
+
|
|
29
|
+
if (isTokensBalancesPending) {
|
|
30
|
+
return <ListingItem isLoading overrides={overrides} />
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (isTokensBalancesError) {
|
|
34
|
+
return (
|
|
35
|
+
<AccountError
|
|
36
|
+
topic="other assets"
|
|
37
|
+
paddingTop={theme.sizing.scale100}
|
|
38
|
+
paddingBottom={theme.sizing.scale100}
|
|
39
|
+
overrides={overrides}
|
|
40
|
+
/>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const otherAssets = Object.values(tokensBalancesData)
|
|
45
|
+
.filter((asset) => !["BTC", "MUSD"].includes(asset.symbol))
|
|
46
|
+
.filter((asset) => asset.value > 0n)
|
|
47
|
+
|
|
48
|
+
const assetsCount = otherAssets.length
|
|
49
|
+
const totalAssetsInUsd = Number(
|
|
50
|
+
formatUnits(
|
|
51
|
+
otherAssets.reduce((total, asset) => total + asset.usd.value, 0n),
|
|
52
|
+
CONVERSION_RATE_DECIMALS,
|
|
53
|
+
),
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
let label = "No other assets"
|
|
57
|
+
if (assetsCount === 1) label = "1 more asset"
|
|
58
|
+
if (assetsCount > 1) label = `${assetsCount} more assets`
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<ListingItem
|
|
62
|
+
icon={<CoinsStacked02 color={theme.colors.contentPrimary} />}
|
|
63
|
+
label={label}
|
|
64
|
+
value={totalAssetsInUsd}
|
|
65
|
+
overrides={mergeOverrides(
|
|
66
|
+
{
|
|
67
|
+
Block: {
|
|
68
|
+
props: {
|
|
69
|
+
$as: "button",
|
|
70
|
+
onClick,
|
|
71
|
+
},
|
|
72
|
+
style: {
|
|
73
|
+
borderWidth: 0,
|
|
74
|
+
cursor: "pointer",
|
|
75
|
+
backgroundColor: "transparent",
|
|
76
|
+
minHeight: "56px",
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
overrides,
|
|
81
|
+
)}
|
|
82
|
+
{...restProps}
|
|
83
|
+
/>
|
|
84
|
+
)
|
|
85
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Block, Button, LogOut01, useStyletron } from "@mezo-org/mezo-clay"
|
|
2
|
+
import React, { useCallback } from "react"
|
|
3
|
+
import { useDisconnect } from "wagmi"
|
|
4
|
+
import { useSignOut } from "../../../hooks"
|
|
5
|
+
import WalletAddress from "./WalletAddress"
|
|
6
|
+
import AccountBalance from "./AccountBalance"
|
|
7
|
+
import WelcomeBlock from "./WelcomeBlock"
|
|
8
|
+
import AccountAddressActions from "./AccountAddressActions"
|
|
9
|
+
import AccountOtherAssets from "./AccountOtherAssets"
|
|
10
|
+
import AccountBtcListing from "./AccountBtcListing"
|
|
11
|
+
import AccountMusdListing from "./AccountMusdListing"
|
|
12
|
+
|
|
13
|
+
type RootProps = {
|
|
14
|
+
onSignOut?: () => void
|
|
15
|
+
onOtherAssetsClick?: () => void
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default function Root(props: RootProps) {
|
|
19
|
+
const { onSignOut, onOtherAssetsClick } = props
|
|
20
|
+
|
|
21
|
+
const [, theme] = useStyletron()
|
|
22
|
+
|
|
23
|
+
const { disconnect } = useDisconnect()
|
|
24
|
+
const { signOut } = useSignOut()
|
|
25
|
+
|
|
26
|
+
const handleLogOut = useCallback(() => {
|
|
27
|
+
if (onSignOut) {
|
|
28
|
+
onSignOut()
|
|
29
|
+
return
|
|
30
|
+
}
|
|
31
|
+
signOut()
|
|
32
|
+
disconnect()
|
|
33
|
+
}, [signOut, disconnect, onSignOut])
|
|
34
|
+
|
|
35
|
+
const overridesWithDivider = {
|
|
36
|
+
Block: {
|
|
37
|
+
style: {
|
|
38
|
+
borderBottomWidth: "1px",
|
|
39
|
+
borderBottomStyle: "solid",
|
|
40
|
+
borderBottomColor: theme.colors.borderOpaque,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<Block display="inline-flex" flexDirection="column">
|
|
47
|
+
<WelcomeBlock />
|
|
48
|
+
|
|
49
|
+
<AccountAddressActions overrides={overridesWithDivider} />
|
|
50
|
+
|
|
51
|
+
<WalletAddress overrides={overridesWithDivider} />
|
|
52
|
+
|
|
53
|
+
<AccountBalance overrides={overridesWithDivider} />
|
|
54
|
+
|
|
55
|
+
<AccountBtcListing />
|
|
56
|
+
|
|
57
|
+
<AccountMusdListing />
|
|
58
|
+
|
|
59
|
+
<AccountOtherAssets
|
|
60
|
+
onClick={onOtherAssetsClick}
|
|
61
|
+
overrides={overridesWithDivider}
|
|
62
|
+
/>
|
|
63
|
+
|
|
64
|
+
<Block padding={theme.sizing.scale300}>
|
|
65
|
+
<Button
|
|
66
|
+
size="small"
|
|
67
|
+
shape="pill"
|
|
68
|
+
kind="tertiary"
|
|
69
|
+
startEnhancer={<LogOut01 color="currentColor" size={16} />}
|
|
70
|
+
onClick={handleLogOut}
|
|
71
|
+
>
|
|
72
|
+
Sign out
|
|
73
|
+
</Button>
|
|
74
|
+
</Block>
|
|
75
|
+
</Block>
|
|
76
|
+
)
|
|
77
|
+
}
|