@mezo-org/passport 0.4.0-dev.1 → 0.4.0-dev.10
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/api/auth.d.ts +57 -52
- package/dist/src/api/auth.d.ts.map +1 -1
- package/dist/src/api/auth.js +22 -53
- package/dist/src/api/auth.js.map +1 -1
- package/dist/src/api/client.d.ts +24 -0
- package/dist/src/api/client.d.ts.map +1 -0
- package/dist/src/api/client.js +54 -0
- package/dist/src/api/client.js.map +1 -0
- package/dist/src/api/fetch-error.d.ts +5 -0
- package/dist/src/api/fetch-error.d.ts.map +1 -0
- package/dist/src/api/fetch-error.js +8 -0
- package/dist/src/api/fetch-error.js.map +1 -0
- package/dist/src/api/index.d.ts +3 -0
- package/dist/src/api/index.d.ts.map +1 -0
- package/dist/src/api/index.js +3 -0
- package/dist/src/api/index.js.map +1 -0
- package/dist/src/api/portal.d.ts +32 -0
- package/dist/src/api/portal.d.ts.map +1 -0
- package/dist/src/api/portal.js +23 -0
- package/dist/src/api/portal.js.map +1 -0
- 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/AccountAddress.d.ts +8 -0
- package/dist/src/components/Dropdown/AccountAddress.d.ts.map +1 -0
- package/dist/src/components/Dropdown/AccountAddress.js +66 -0
- package/dist/src/components/Dropdown/AccountAddress.js.map +1 -0
- package/dist/src/components/Dropdown/AccountAssets.d.ts +14 -0
- package/dist/src/components/Dropdown/AccountAssets.d.ts.map +1 -0
- package/dist/src/components/Dropdown/AccountAssets.js +44 -0
- package/dist/src/components/Dropdown/AccountAssets.js.map +1 -0
- package/dist/src/components/Dropdown/AccountBalance.d.ts +7 -0
- package/dist/src/components/Dropdown/AccountBalance.d.ts.map +1 -0
- package/dist/src/components/Dropdown/AccountBalance.js +18 -0
- package/dist/src/components/Dropdown/AccountBalance.js.map +1 -0
- package/dist/src/components/Dropdown/ConnectedTrigger.d.ts +7 -0
- package/dist/src/components/Dropdown/ConnectedTrigger.d.ts.map +1 -0
- package/dist/src/components/Dropdown/ConnectedTrigger.js +30 -0
- package/dist/src/components/Dropdown/ConnectedTrigger.js.map +1 -0
- package/dist/src/components/Dropdown/Content.d.ts +9 -0
- package/dist/src/components/Dropdown/Content.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Content.js +69 -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 +20 -0
- package/dist/src/components/Dropdown/Dropdown.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Dropdown.js +64 -0
- package/dist/src/components/Dropdown/Dropdown.js.map +1 -0
- package/dist/src/components/Dropdown/WelcomeBlock.d.ts +8 -0
- package/dist/src/components/Dropdown/WelcomeBlock.d.ts.map +1 -0
- package/dist/src/components/Dropdown/WelcomeBlock.js +44 -0
- package/dist/src/components/Dropdown/WelcomeBlock.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/hooks/constants.d.ts +3 -3
- package/dist/src/hooks/constants.js +4 -4
- package/dist/src/hooks/constants.js.map +1 -1
- package/dist/src/hooks/index.d.ts +1 -4
- package/dist/src/hooks/index.d.ts.map +1 -1
- package/dist/src/hooks/index.js +1 -4
- package/dist/src/hooks/index.js.map +1 -1
- package/dist/src/hooks/useAssetsUSDConversion.d.ts +8 -0
- package/dist/src/hooks/useAssetsUSDConversion.d.ts.map +1 -0
- package/dist/src/hooks/useAssetsUSDConversion.js +21 -0
- package/dist/src/hooks/useAssetsUSDConversion.js.map +1 -0
- package/dist/src/hooks/useAuthApiClient.d.ts +1 -1
- package/dist/src/hooks/useAuthApiClient.d.ts.map +1 -1
- package/dist/src/hooks/useAuthenticateWithWallet.d.ts +73 -0
- package/dist/src/hooks/useAuthenticateWithWallet.d.ts.map +1 -0
- package/dist/src/hooks/useAuthenticateWithWallet.js +69 -0
- package/dist/src/hooks/useAuthenticateWithWallet.js.map +1 -0
- package/dist/src/hooks/useCreateAccount.d.ts +41 -137
- package/dist/src/hooks/useCreateAccount.d.ts.map +1 -1
- package/dist/src/hooks/useCreateAccount.js +8 -10
- package/dist/src/hooks/useCreateAccount.js.map +1 -1
- package/dist/src/hooks/useCreateSession.d.ts +12 -182
- package/dist/src/hooks/useCreateSession.d.ts.map +1 -1
- package/dist/src/hooks/useCreateSession.js +12 -18
- package/dist/src/hooks/useCreateSession.js.map +1 -1
- package/dist/src/hooks/useDropdownData.d.ts +45 -0
- package/dist/src/hooks/useDropdownData.d.ts.map +1 -0
- package/dist/src/hooks/useDropdownData.js +74 -0
- package/dist/src/hooks/useDropdownData.js.map +1 -0
- package/dist/src/hooks/useEnsureNoSessionAndFetchNonce.d.ts +5 -0
- package/dist/src/hooks/useEnsureNoSessionAndFetchNonce.d.ts.map +1 -0
- package/dist/src/hooks/useEnsureNoSessionAndFetchNonce.js +34 -0
- package/dist/src/hooks/useEnsureNoSessionAndFetchNonce.js.map +1 -0
- package/dist/src/hooks/useGetAccountByAddress.d.ts +3 -5
- package/dist/src/hooks/useGetAccountByAddress.d.ts.map +1 -1
- package/dist/src/hooks/useGetAccountByAddress.js +3 -4
- package/dist/src/hooks/useGetAccountByAddress.js.map +1 -1
- package/dist/src/hooks/useGetAccountByMezoId.d.ts +3 -5
- package/dist/src/hooks/useGetAccountByMezoId.d.ts.map +1 -1
- package/dist/src/hooks/useGetAccountByMezoId.js +3 -4
- package/dist/src/hooks/useGetAccountByMezoId.js.map +1 -1
- package/dist/src/hooks/useGetCurrentAccount.d.ts +14 -8
- package/dist/src/hooks/useGetCurrentAccount.d.ts.map +1 -1
- package/dist/src/hooks/useGetCurrentAccount.js +28 -6
- package/dist/src/hooks/useGetCurrentAccount.js.map +1 -1
- package/dist/src/hooks/useGetSession.d.ts +3 -20
- package/dist/src/hooks/useGetSession.d.ts.map +1 -1
- package/dist/src/hooks/useGetSession.js +2 -2
- package/dist/src/hooks/useGetSession.js.map +1 -1
- package/dist/src/hooks/useLinkAccount.d.ts +15 -121
- package/dist/src/hooks/useLinkAccount.d.ts.map +1 -1
- package/dist/src/hooks/useLinkAccount.js +8 -21
- package/dist/src/hooks/useLinkAccount.js.map +1 -1
- package/dist/src/hooks/usePortalApiClient.d.ts +2 -0
- package/dist/src/hooks/usePortalApiClient.d.ts.map +1 -0
- package/dist/src/hooks/usePortalApiClient.js +6 -0
- package/dist/src/hooks/usePortalApiClient.js.map +1 -0
- package/dist/src/hooks/useSignInWithDiscord.d.ts +12 -181
- package/dist/src/hooks/useSignInWithDiscord.d.ts.map +1 -1
- package/dist/src/hooks/useSignInWithDiscord.js +11 -22
- package/dist/src/hooks/useSignInWithDiscord.js.map +1 -1
- package/dist/src/hooks/useSignInWithWallet.d.ts +12 -181
- package/dist/src/hooks/useSignInWithWallet.d.ts.map +1 -1
- package/dist/src/hooks/useSignInWithWallet.js +6 -43
- package/dist/src/hooks/useSignInWithWallet.js.map +1 -1
- package/dist/src/hooks/useSignOut.d.ts +12 -28
- package/dist/src/hooks/useSignOut.d.ts.map +1 -1
- package/dist/src/hooks/useSignOut.js +11 -6
- package/dist/src/hooks/useSignOut.js.map +1 -1
- package/dist/src/hooks/useSignUpWithWallet.d.ts +73 -0
- package/dist/src/hooks/useSignUpWithWallet.d.ts.map +1 -0
- package/dist/src/hooks/useSignUpWithWallet.js +11 -0
- package/dist/src/hooks/useSignUpWithWallet.js.map +1 -0
- package/dist/src/hooks/useUpdateMezoId.d.ts +30 -82
- package/dist/src/hooks/useUpdateMezoId.d.ts.map +1 -1
- package/dist/src/hooks/useUpdateMezoId.js +8 -12
- package/dist/src/hooks/useUpdateMezoId.js.map +1 -1
- package/dist/src/hooks/useWalletAccount.d.ts +12 -0
- package/dist/src/hooks/useWalletAccount.d.ts.map +1 -0
- package/dist/src/hooks/useWalletAccount.js +28 -0
- package/dist/src/hooks/useWalletAccount.js.map +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/provider.d.ts +10 -13
- package/dist/src/provider.d.ts.map +1 -1
- package/dist/src/provider.js +11 -20
- package/dist/src/provider.js.map +1 -1
- package/dist/src/utils/address.d.ts +15 -0
- package/dist/src/utils/address.d.ts.map +1 -0
- package/dist/src/utils/address.js +35 -0
- package/dist/src/utils/address.js.map +1 -0
- package/dist/src/utils/address.test.d.ts +2 -0
- package/dist/src/utils/address.test.d.ts.map +1 -0
- package/dist/src/utils/address.test.js +32 -0
- package/dist/src/utils/address.test.js.map +1 -0
- package/dist/src/utils/cryptoAssets.d.ts +28 -0
- package/dist/src/utils/cryptoAssets.d.ts.map +1 -0
- package/dist/src/utils/cryptoAssets.js +73 -0
- package/dist/src/utils/cryptoAssets.js.map +1 -0
- package/dist/src/utils/cryptoAssets.test.d.ts +2 -0
- package/dist/src/utils/cryptoAssets.test.d.ts.map +1 -0
- package/dist/src/utils/cryptoAssets.test.js +50 -0
- package/dist/src/utils/cryptoAssets.test.js.map +1 -0
- package/dist/src/utils/currency.d.ts +14 -0
- package/dist/src/utils/currency.d.ts.map +1 -0
- package/dist/src/utils/currency.js +27 -0
- package/dist/src/utils/currency.js.map +1 -0
- package/dist/src/utils/currency.test.d.ts +2 -0
- package/dist/src/utils/currency.test.d.ts.map +1 -0
- package/dist/src/utils/currency.test.js +34 -0
- package/dist/src/utils/currency.test.js.map +1 -0
- package/dist/src/utils/numbers.d.ts +26 -0
- package/dist/src/utils/numbers.d.ts.map +1 -0
- package/dist/src/utils/numbers.js +40 -0
- package/dist/src/utils/numbers.js.map +1 -0
- package/dist/src/utils/numbers.test.d.ts +2 -0
- package/dist/src/utils/numbers.test.d.ts.map +1 -0
- package/dist/src/utils/numbers.test.js +54 -0
- package/dist/src/utils/numbers.test.js.map +1 -0
- package/package.json +9 -3
- package/src/api/auth.ts +104 -129
- package/src/api/client.ts +78 -0
- package/src/api/fetch-error.ts +8 -0
- package/src/api/index.ts +2 -0
- package/src/api/portal.ts +56 -0
- package/src/assets/DefaultAvatar.tsx +74 -0
- package/src/components/Dropdown/AccountAddress.tsx +130 -0
- package/src/components/Dropdown/AccountAssets.tsx +110 -0
- package/src/components/Dropdown/AccountBalance.tsx +38 -0
- package/src/components/Dropdown/ConnectedTrigger.tsx +56 -0
- package/src/components/Dropdown/Content.tsx +148 -0
- package/src/components/Dropdown/DisconnectedTrigger.tsx +36 -0
- package/src/components/Dropdown/Dropdown.tsx +111 -0
- package/src/components/Dropdown/README.md +51 -0
- package/src/components/Dropdown/WelcomeBlock.tsx +92 -0
- package/src/components/Dropdown/index.ts +2 -0
- package/src/components/index.ts +1 -0
- package/src/hooks/constants.ts +4 -4
- package/src/hooks/index.ts +1 -4
- package/src/hooks/useAssetsUSDConversion.ts +31 -0
- package/src/hooks/useAuthenticateWithWallet.ts +98 -0
- package/src/hooks/useCreateAccount.ts +20 -11
- package/src/hooks/useCreateSession.ts +24 -18
- package/src/hooks/useDropdownData.ts +131 -0
- package/src/hooks/useEnsureNoSessionAndFetchNonce.ts +46 -0
- package/src/hooks/useGetAccountByAddress.ts +11 -5
- package/src/hooks/useGetAccountByMezoId.ts +11 -5
- package/src/hooks/useGetCurrentAccount.ts +53 -7
- package/src/hooks/useGetSession.ts +10 -3
- package/src/hooks/useLinkAccount.ts +19 -31
- package/src/hooks/usePortalApiClient.ts +6 -0
- package/src/hooks/useSignInWithDiscord.ts +19 -28
- package/src/hooks/useSignInWithWallet.ts +14 -54
- package/src/hooks/useSignOut.ts +22 -6
- package/src/hooks/useSignUpWithWallet.ts +21 -0
- package/src/hooks/useUpdateMezoId.ts +20 -12
- package/src/hooks/useWalletAccount.ts +53 -0
- package/src/index.ts +1 -0
- package/src/provider.ts +30 -37
- package/src/utils/address.test.ts +38 -0
- package/src/utils/address.ts +43 -0
- package/src/utils/cryptoAssets.test.ts +61 -0
- package/src/utils/cryptoAssets.ts +93 -0
- package/src/utils/currency.test.ts +38 -0
- package/src/utils/currency.ts +32 -0
- package/src/utils/numbers.test.ts +73 -0
- package/src/utils/numbers.ts +55 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Block, BlockProps } from "@mezo-org/mezo-clay"
|
|
2
|
+
import React, { SVGProps } from "react"
|
|
3
|
+
|
|
4
|
+
function DefaultAvatar(props: SVGProps<SVGSVGElement>) {
|
|
5
|
+
return (
|
|
6
|
+
<svg viewBox="0 0 214 214" fill="none" {...props}>
|
|
7
|
+
<rect y="-0.478027" width="166.379" height="81.7091" fill="#FF004D" />
|
|
8
|
+
<rect x="166" y="-0.478027" width="48" height="82" fill="black" />
|
|
9
|
+
<rect
|
|
10
|
+
x="166.379"
|
|
11
|
+
y="81.231"
|
|
12
|
+
width="24.1044"
|
|
13
|
+
height="132.291"
|
|
14
|
+
fill="#DFFF80"
|
|
15
|
+
/>
|
|
16
|
+
<rect
|
|
17
|
+
x="118.758"
|
|
18
|
+
y="81.231"
|
|
19
|
+
width="24.1044"
|
|
20
|
+
height="132.291"
|
|
21
|
+
fill="#FF5500"
|
|
22
|
+
/>
|
|
23
|
+
<rect
|
|
24
|
+
x="71.1372"
|
|
25
|
+
y="81.231"
|
|
26
|
+
width="24.1044"
|
|
27
|
+
height="132.291"
|
|
28
|
+
fill="#5A59A7"
|
|
29
|
+
/>
|
|
30
|
+
<rect
|
|
31
|
+
x="23.5166"
|
|
32
|
+
y="81.231"
|
|
33
|
+
width="24.1044"
|
|
34
|
+
height="132.291"
|
|
35
|
+
fill="#47B5FF"
|
|
36
|
+
/>
|
|
37
|
+
<rect y="81.231" width="23.5165" height="132.291" fill="#A3C238" />
|
|
38
|
+
<rect
|
|
39
|
+
x="190.483"
|
|
40
|
+
y="81.231"
|
|
41
|
+
width="23.5165"
|
|
42
|
+
height="132.291"
|
|
43
|
+
fill="#6E6E70"
|
|
44
|
+
/>
|
|
45
|
+
<rect
|
|
46
|
+
x="142.863"
|
|
47
|
+
y="81.231"
|
|
48
|
+
width="23.5165"
|
|
49
|
+
height="132.291"
|
|
50
|
+
fill="#0A3C01"
|
|
51
|
+
/>
|
|
52
|
+
<rect
|
|
53
|
+
x="95.2417"
|
|
54
|
+
y="81.231"
|
|
55
|
+
width="23.5165"
|
|
56
|
+
height="132.291"
|
|
57
|
+
fill="#F2A91F"
|
|
58
|
+
/>
|
|
59
|
+
<rect
|
|
60
|
+
x="47.6211"
|
|
61
|
+
y="81.231"
|
|
62
|
+
width="23.5165"
|
|
63
|
+
height="132.291"
|
|
64
|
+
fill="#6B3D01"
|
|
65
|
+
/>
|
|
66
|
+
</svg>
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function DefaultAvatarComponent(props: BlockProps) {
|
|
71
|
+
return <Block as={DefaultAvatar} {...props} />
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export default DefaultAvatarComponent
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Block,
|
|
3
|
+
Copy03 as CopyIcon,
|
|
4
|
+
LinkExternal02 as LinkIcon,
|
|
5
|
+
ParagraphSmall,
|
|
6
|
+
useStyletron,
|
|
7
|
+
} from "@mezo-org/mezo-clay"
|
|
8
|
+
import React, { useCallback, useState } from "react"
|
|
9
|
+
import { useCopyToClipboard } from "usehooks-ts"
|
|
10
|
+
import { usePassportContext } from "../../hooks/usePassportContext"
|
|
11
|
+
import { getAddressExplorerUrl, trimAddress } from "../../utils/address"
|
|
12
|
+
import { getCryptoAsset } from "../../utils/cryptoAssets"
|
|
13
|
+
|
|
14
|
+
type AccountAddressProps = {
|
|
15
|
+
address: string
|
|
16
|
+
type: "bitcoin" | "evm"
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// TODO: Add visual feedback on copy
|
|
20
|
+
|
|
21
|
+
export default function AccountAddress(props: AccountAddressProps) {
|
|
22
|
+
const { address, type } = props
|
|
23
|
+
|
|
24
|
+
const { environment } = usePassportContext()
|
|
25
|
+
const blockExplorerUrl = getAddressExplorerUrl(
|
|
26
|
+
address,
|
|
27
|
+
type,
|
|
28
|
+
environment === "testnet",
|
|
29
|
+
)
|
|
30
|
+
const trimmedAddress = trimAddress(address)
|
|
31
|
+
const { icon: accountIcon } = getCryptoAsset(
|
|
32
|
+
type === "bitcoin" ? "btc" : "eth",
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
const [, theme] = useStyletron()
|
|
36
|
+
|
|
37
|
+
const [, copy] = useCopyToClipboard()
|
|
38
|
+
const [isCopiedMessageVisible, setIsCopiedMessageVisible] = useState(false)
|
|
39
|
+
const handleCopyAddress = useCallback(() => {
|
|
40
|
+
copy(address)
|
|
41
|
+
setIsCopiedMessageVisible(true)
|
|
42
|
+
|
|
43
|
+
setTimeout(() => {
|
|
44
|
+
setIsCopiedMessageVisible(false)
|
|
45
|
+
}, 2000)
|
|
46
|
+
}, [copy, address])
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<Block
|
|
50
|
+
as="button"
|
|
51
|
+
onClick={handleCopyAddress}
|
|
52
|
+
display="flex"
|
|
53
|
+
alignItems="center"
|
|
54
|
+
backgroundColor="transparent"
|
|
55
|
+
padding={`${theme.sizing.scale600} ${theme.sizing.scale500}`}
|
|
56
|
+
overrides={{
|
|
57
|
+
Block: {
|
|
58
|
+
style: {
|
|
59
|
+
borderWidth: 0,
|
|
60
|
+
cursor: "pointer",
|
|
61
|
+
":hover": {
|
|
62
|
+
backgroundColor: theme.colors.backgroundTertiary,
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
}}
|
|
67
|
+
>
|
|
68
|
+
<Block as={accountIcon} size={theme.sizing.scale600} />
|
|
69
|
+
{isCopiedMessageVisible ? (
|
|
70
|
+
<ParagraphSmall
|
|
71
|
+
margin={0}
|
|
72
|
+
marginLeft={theme.sizing.scale300}
|
|
73
|
+
color={theme.colors.gray800}
|
|
74
|
+
>
|
|
75
|
+
Copied address to clipboard
|
|
76
|
+
</ParagraphSmall>
|
|
77
|
+
) : (
|
|
78
|
+
<Block
|
|
79
|
+
as="a"
|
|
80
|
+
marginLeft={theme.sizing.scale300}
|
|
81
|
+
href={blockExplorerUrl}
|
|
82
|
+
target="_blank"
|
|
83
|
+
overrides={{
|
|
84
|
+
Block: {
|
|
85
|
+
style: {
|
|
86
|
+
color: "inherit",
|
|
87
|
+
textDecoration: "none",
|
|
88
|
+
":hover": {
|
|
89
|
+
textDecoration: "underline",
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
}}
|
|
94
|
+
>
|
|
95
|
+
<ParagraphSmall
|
|
96
|
+
display="flex"
|
|
97
|
+
alignItems="center"
|
|
98
|
+
margin={0}
|
|
99
|
+
color={theme.colors.gray800}
|
|
100
|
+
>
|
|
101
|
+
{trimmedAddress}
|
|
102
|
+
<LinkIcon
|
|
103
|
+
display="inline"
|
|
104
|
+
size={theme.sizing.scale550}
|
|
105
|
+
overrides={{
|
|
106
|
+
Svg: {
|
|
107
|
+
style: {
|
|
108
|
+
stroke: "currentColor",
|
|
109
|
+
marginLeft: theme.sizing.scale200,
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
}}
|
|
113
|
+
/>
|
|
114
|
+
</ParagraphSmall>
|
|
115
|
+
</Block>
|
|
116
|
+
)}
|
|
117
|
+
<CopyIcon
|
|
118
|
+
size={theme.sizing.scale550}
|
|
119
|
+
overrides={{
|
|
120
|
+
Svg: {
|
|
121
|
+
style: {
|
|
122
|
+
marginLeft: "auto",
|
|
123
|
+
stroke: "currentColor",
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
}}
|
|
127
|
+
/>
|
|
128
|
+
</Block>
|
|
129
|
+
)
|
|
130
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Block,
|
|
3
|
+
LabelSmall,
|
|
4
|
+
ParagraphSmall,
|
|
5
|
+
useStyletron,
|
|
6
|
+
} from "@mezo-org/mezo-clay"
|
|
7
|
+
import React, { useMemo } from "react"
|
|
8
|
+
import { CryptoAssetKey, getCryptoAsset } from "../../utils/cryptoAssets"
|
|
9
|
+
import { formatUsd } from "../../utils/currency"
|
|
10
|
+
|
|
11
|
+
type AccountAssetsProps = {
|
|
12
|
+
label: string | React.ReactNode
|
|
13
|
+
assets: {
|
|
14
|
+
type: CryptoAssetKey
|
|
15
|
+
decimals: number
|
|
16
|
+
balance: number
|
|
17
|
+
balanceInUsd: number
|
|
18
|
+
}[]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default function AccountAssets(props: AccountAssetsProps) {
|
|
22
|
+
const { label, assets } = props
|
|
23
|
+
|
|
24
|
+
const [, theme] = useStyletron()
|
|
25
|
+
|
|
26
|
+
const assetsData = useMemo(
|
|
27
|
+
() =>
|
|
28
|
+
assets.map((token) => {
|
|
29
|
+
const { name, symbol, icon } = getCryptoAsset(token.type)
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
...token,
|
|
33
|
+
icon,
|
|
34
|
+
label: name,
|
|
35
|
+
symbol,
|
|
36
|
+
}
|
|
37
|
+
}),
|
|
38
|
+
[assets],
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
const labelContent =
|
|
42
|
+
typeof label === "string" ? (
|
|
43
|
+
<ParagraphSmall margin={0} color={theme.colors.gray800}>
|
|
44
|
+
{label}
|
|
45
|
+
</ParagraphSmall>
|
|
46
|
+
) : (
|
|
47
|
+
label
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
if (assetsData.length === 0) {
|
|
51
|
+
return null
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<Block padding={`0 ${theme.sizing.scale500}`}>
|
|
56
|
+
<Block margin={`${theme.sizing.scale400} 0`}>{labelContent}</Block>
|
|
57
|
+
|
|
58
|
+
<Block
|
|
59
|
+
as="ul"
|
|
60
|
+
marginBottom={theme.sizing.scale600}
|
|
61
|
+
padding={0}
|
|
62
|
+
display="flex"
|
|
63
|
+
flexDirection="column"
|
|
64
|
+
overrides={{
|
|
65
|
+
Block: {
|
|
66
|
+
style: {
|
|
67
|
+
gap: theme.sizing.scale100,
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
}}
|
|
71
|
+
>
|
|
72
|
+
{assetsData.map((asset) => (
|
|
73
|
+
<Block
|
|
74
|
+
as="li"
|
|
75
|
+
key={`${asset.type}-${asset.balance}`}
|
|
76
|
+
display="flex"
|
|
77
|
+
justifyContent="space-between"
|
|
78
|
+
alignItems="center"
|
|
79
|
+
margin={`${theme.sizing.scale100} 0`}
|
|
80
|
+
>
|
|
81
|
+
<asset.icon
|
|
82
|
+
size={theme.sizing.scale800}
|
|
83
|
+
overrides={{
|
|
84
|
+
Svg: {
|
|
85
|
+
style: {
|
|
86
|
+
marginRight: theme.sizing.scale500,
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
}}
|
|
90
|
+
/>
|
|
91
|
+
|
|
92
|
+
<Block flex={1}>
|
|
93
|
+
<LabelSmall margin={0}>{asset.label}</LabelSmall>
|
|
94
|
+
<ParagraphSmall margin={0} color={theme.colors.gray500}>
|
|
95
|
+
{asset.symbol}
|
|
96
|
+
</ParagraphSmall>
|
|
97
|
+
</Block>
|
|
98
|
+
|
|
99
|
+
<Block display="flex" alignItems="end" flexDirection="column">
|
|
100
|
+
<LabelSmall margin={0}>{asset.balance}</LabelSmall>
|
|
101
|
+
<ParagraphSmall margin={0} color={theme.colors.gray500}>
|
|
102
|
+
{formatUsd(asset.balanceInUsd)}
|
|
103
|
+
</ParagraphSmall>
|
|
104
|
+
</Block>
|
|
105
|
+
</Block>
|
|
106
|
+
))}
|
|
107
|
+
</Block>
|
|
108
|
+
</Block>
|
|
109
|
+
)
|
|
110
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Block,
|
|
3
|
+
HeadingSmall,
|
|
4
|
+
ParagraphSmall,
|
|
5
|
+
useStyletron,
|
|
6
|
+
} from "@mezo-org/mezo-clay"
|
|
7
|
+
import React from "react"
|
|
8
|
+
import { formatUsd } from "../../utils/currency"
|
|
9
|
+
|
|
10
|
+
type AccountBalanceProps = {
|
|
11
|
+
amount: number
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default function AccountBalance(props: AccountBalanceProps) {
|
|
15
|
+
const { amount } = props
|
|
16
|
+
|
|
17
|
+
const formattedUsdBalance = formatUsd(amount)
|
|
18
|
+
|
|
19
|
+
const [, theme] = useStyletron()
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<Block
|
|
23
|
+
padding={theme.sizing.scale500}
|
|
24
|
+
overrides={{
|
|
25
|
+
Block: {
|
|
26
|
+
style: {
|
|
27
|
+
borderBottom: `1px solid ${theme.colors.backgroundPrimary}`,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
}}
|
|
31
|
+
>
|
|
32
|
+
<ParagraphSmall margin={0} color={theme.colors.gray800}>
|
|
33
|
+
Available balance
|
|
34
|
+
</ParagraphSmall>
|
|
35
|
+
<HeadingSmall margin={0}>{formattedUsdBalance}</HeadingSmall>
|
|
36
|
+
</Block>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Block, ButtonProps, useStyletron } from "@mezo-org/mezo-clay"
|
|
2
|
+
import React, { forwardRef, ReactNode } from "react"
|
|
3
|
+
|
|
4
|
+
type ConnectedTriggerProps = Omit<ButtonProps, "children"> & {
|
|
5
|
+
avatar: ReactNode
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const ConnectedTrigger = forwardRef<HTMLButtonElement, ConnectedTriggerProps>(
|
|
9
|
+
(props, ref) => {
|
|
10
|
+
const { onClick, avatar, ...restProps } = props
|
|
11
|
+
|
|
12
|
+
const [, theme] = useStyletron()
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<Block
|
|
16
|
+
as="button"
|
|
17
|
+
overrides={{
|
|
18
|
+
Block: {
|
|
19
|
+
props: { ref, ...restProps },
|
|
20
|
+
style: {
|
|
21
|
+
border: "none",
|
|
22
|
+
background: "none",
|
|
23
|
+
padding: 0,
|
|
24
|
+
margin: 0,
|
|
25
|
+
cursor: "pointer",
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
}}
|
|
29
|
+
onClick={onClick}
|
|
30
|
+
>
|
|
31
|
+
<Block
|
|
32
|
+
width={theme.sizing.scale950}
|
|
33
|
+
height={theme.sizing.scale950}
|
|
34
|
+
overrides={{
|
|
35
|
+
Block: {
|
|
36
|
+
style: {
|
|
37
|
+
borderRadius: "100%",
|
|
38
|
+
border: `2px solid ${theme.colors.contentPrimary}`,
|
|
39
|
+
boxSizing: "border-box",
|
|
40
|
+
overflow: "hidden",
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
}}
|
|
44
|
+
>
|
|
45
|
+
{typeof avatar === "string" ? (
|
|
46
|
+
<Block as="img" src={avatar} alt="" />
|
|
47
|
+
) : (
|
|
48
|
+
avatar
|
|
49
|
+
)}
|
|
50
|
+
</Block>
|
|
51
|
+
</Block>
|
|
52
|
+
)
|
|
53
|
+
},
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
export default ConnectedTrigger
|
|
@@ -0,0 +1,148 @@
|
|
|
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"
|
|
17
|
+
|
|
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
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
type DropdownContentProps = {
|
|
39
|
+
data: DropdownData
|
|
40
|
+
onSignOut?: () => void
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export default function DropdownContent(props: DropdownContentProps) {
|
|
44
|
+
const { data, onSignOut } = props
|
|
45
|
+
|
|
46
|
+
const [, theme] = useStyletron()
|
|
47
|
+
|
|
48
|
+
const {
|
|
49
|
+
mezoId,
|
|
50
|
+
address,
|
|
51
|
+
walletType,
|
|
52
|
+
totalBalanceInUsd,
|
|
53
|
+
formattedNativeAssets,
|
|
54
|
+
matsnet,
|
|
55
|
+
} = data
|
|
56
|
+
|
|
57
|
+
const { disconnect } = useDisconnect()
|
|
58
|
+
const { signOut } = useSignOut()
|
|
59
|
+
|
|
60
|
+
const handleLogOut = useCallback(() => {
|
|
61
|
+
if (onSignOut) {
|
|
62
|
+
onSignOut()
|
|
63
|
+
return
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
signOut()
|
|
67
|
+
disconnect()
|
|
68
|
+
}, [signOut, disconnect, onSignOut])
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<Block
|
|
72
|
+
display="inline-flex"
|
|
73
|
+
flexDirection="column"
|
|
74
|
+
backgroundColor={theme.colors.backgroundPrimary}
|
|
75
|
+
padding={theme.sizing.scale500}
|
|
76
|
+
width="100%"
|
|
77
|
+
overrides={{
|
|
78
|
+
Block: {
|
|
79
|
+
style: {
|
|
80
|
+
boxSizing: "border-box",
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
}}
|
|
84
|
+
>
|
|
85
|
+
<WelcomeBlock mezoId={mezoId} matsBalance={matsnet.mats} />
|
|
86
|
+
|
|
87
|
+
<Block
|
|
88
|
+
display="flex"
|
|
89
|
+
flexDirection="column"
|
|
90
|
+
backgroundColor={theme.colors.backgroundSecondary}
|
|
91
|
+
overflow="hidden"
|
|
92
|
+
overrides={{
|
|
93
|
+
Block: { style: { borderRadius: theme.borders.radius300 } },
|
|
94
|
+
}}
|
|
95
|
+
>
|
|
96
|
+
<AccountAddress address={address} type={walletType} />
|
|
97
|
+
|
|
98
|
+
<AccountBalance amount={totalBalanceInUsd} />
|
|
99
|
+
|
|
100
|
+
<AccountAssets label="Assets" assets={formattedNativeAssets} />
|
|
101
|
+
</Block>
|
|
102
|
+
|
|
103
|
+
{matsnet.formattedAssets.length > 0 && (
|
|
104
|
+
<Block
|
|
105
|
+
marginTop={theme.sizing.scale600}
|
|
106
|
+
backgroundColor={theme.colors.backgroundSecondary}
|
|
107
|
+
overflow="hidden"
|
|
108
|
+
overrides={{
|
|
109
|
+
Block: { style: { borderRadius: theme.borders.radius300 } },
|
|
110
|
+
}}
|
|
111
|
+
>
|
|
112
|
+
<AccountAssets
|
|
113
|
+
label={<MatsnetLabel />}
|
|
114
|
+
assets={matsnet.formattedAssets}
|
|
115
|
+
/>
|
|
116
|
+
</Block>
|
|
117
|
+
)}
|
|
118
|
+
|
|
119
|
+
<Block
|
|
120
|
+
marginTop={theme.sizing.scale700}
|
|
121
|
+
padding={`0 ${theme.sizing.scale100}`}
|
|
122
|
+
>
|
|
123
|
+
<Button
|
|
124
|
+
size="small"
|
|
125
|
+
kind="tertiary"
|
|
126
|
+
startEnhancer={<LogOut01 color="currentColor" size={12} />}
|
|
127
|
+
onClick={() => handleLogOut()}
|
|
128
|
+
overrides={{
|
|
129
|
+
Root: {
|
|
130
|
+
style: {
|
|
131
|
+
":hover": {
|
|
132
|
+
backgroundColor: theme.colors.backgroundSecondary,
|
|
133
|
+
boxShadow: "none",
|
|
134
|
+
},
|
|
135
|
+
":active": {
|
|
136
|
+
backgroundColor: theme.colors.backgroundSecondary,
|
|
137
|
+
color: theme.colors.contentPrimary,
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
}}
|
|
142
|
+
>
|
|
143
|
+
Log out
|
|
144
|
+
</Button>
|
|
145
|
+
</Block>
|
|
146
|
+
</Block>
|
|
147
|
+
)
|
|
148
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Button, ButtonProps, LogIn01, useStyletron } from "@mezo-org/mezo-clay"
|
|
2
|
+
import React, { forwardRef } from "react"
|
|
3
|
+
|
|
4
|
+
type DisconnectedTriggerProps = Omit<ButtonProps, "children"> & {
|
|
5
|
+
children: string
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const DisconnectedTrigger = forwardRef<
|
|
9
|
+
HTMLButtonElement,
|
|
10
|
+
DisconnectedTriggerProps
|
|
11
|
+
>((props, ref) => {
|
|
12
|
+
const { onClick, children, ...restProps } = props
|
|
13
|
+
|
|
14
|
+
const [, theme] = useStyletron()
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<Button
|
|
18
|
+
startEnhancer={
|
|
19
|
+
<LogIn01 color="currentColor" size={theme.sizing.scale600} />
|
|
20
|
+
}
|
|
21
|
+
overrides={{
|
|
22
|
+
Root: {
|
|
23
|
+
props: { ref },
|
|
24
|
+
},
|
|
25
|
+
}}
|
|
26
|
+
size="small"
|
|
27
|
+
shape="pill"
|
|
28
|
+
onClick={onClick}
|
|
29
|
+
{...restProps}
|
|
30
|
+
>
|
|
31
|
+
{children}
|
|
32
|
+
</Button>
|
|
33
|
+
)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
export default DisconnectedTrigger
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import {
|
|
2
|
+
StatefulPopover,
|
|
3
|
+
StatefulPopoverProps,
|
|
4
|
+
useStyletron,
|
|
5
|
+
} from "@mezo-org/mezo-clay"
|
|
6
|
+
import { useConnectModal } from "@rainbow-me/rainbowkit"
|
|
7
|
+
import React, { useEffect } from "react"
|
|
8
|
+
import { useDisconnect } from "wagmi"
|
|
9
|
+
import DefaultAvatar from "../../assets/DefaultAvatar"
|
|
10
|
+
import useDropdownData, {
|
|
11
|
+
DropdownCryptoAsset,
|
|
12
|
+
} from "../../hooks/useDropdownData"
|
|
13
|
+
import useWalletAccount from "../../hooks/useWalletAccount"
|
|
14
|
+
import ConnectedTrigger from "./ConnectedTrigger"
|
|
15
|
+
import Content from "./Content"
|
|
16
|
+
import DisconnectedTrigger from "./DisconnectedTrigger"
|
|
17
|
+
import { useSignInWithWallet } from "../../hooks"
|
|
18
|
+
|
|
19
|
+
export type DropdownProps = {
|
|
20
|
+
/** The callback to be called when the user clicks the sign-out button */
|
|
21
|
+
onSignOut?: () => void
|
|
22
|
+
/** The callback to be called when the user clicks the button in sign-in state */
|
|
23
|
+
onSignIn?: () => void
|
|
24
|
+
/** The set of EVM native assets to be displayed in the dropdown */
|
|
25
|
+
evmNativeAssets?: DropdownCryptoAsset<"tbtc" | "wbtc">[]
|
|
26
|
+
/** The set of Matsnet assets to be displayed in the dropdown */
|
|
27
|
+
matsnetAssets?: DropdownCryptoAsset<"mbtc" | "musd">[]
|
|
28
|
+
} & Omit<StatefulPopoverProps, "children" | "content">
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Passport Dropdown component that displays user's wallet and assets information.
|
|
32
|
+
* @param {DropdownProps} props - Component props.
|
|
33
|
+
* @returns {JSX.Element}
|
|
34
|
+
*/
|
|
35
|
+
export function Dropdown(props: DropdownProps) {
|
|
36
|
+
const {
|
|
37
|
+
placement = "bottomRight",
|
|
38
|
+
animateOutTime = 120,
|
|
39
|
+
onSignIn,
|
|
40
|
+
onSignOut,
|
|
41
|
+
evmNativeAssets,
|
|
42
|
+
matsnetAssets,
|
|
43
|
+
overrides,
|
|
44
|
+
...restProps
|
|
45
|
+
} = props
|
|
46
|
+
|
|
47
|
+
const [, theme] = useStyletron()
|
|
48
|
+
|
|
49
|
+
const dropdownData = useDropdownData({ evmNativeAssets, matsnetAssets })
|
|
50
|
+
|
|
51
|
+
const { openConnectModal } = useConnectModal()
|
|
52
|
+
|
|
53
|
+
const { isConnected } = useWalletAccount()
|
|
54
|
+
|
|
55
|
+
const { signInWithWalletAsync, isPending } = useSignInWithWallet()
|
|
56
|
+
|
|
57
|
+
const { disconnectAsync } = useDisconnect()
|
|
58
|
+
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
if (onSignIn) return
|
|
61
|
+
|
|
62
|
+
const handleSignIn = async () => {
|
|
63
|
+
if (!isConnected) return
|
|
64
|
+
|
|
65
|
+
try {
|
|
66
|
+
await signInWithWalletAsync()
|
|
67
|
+
} catch (error) {
|
|
68
|
+
await disconnectAsync()
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
handleSignIn()
|
|
73
|
+
}, [disconnectAsync, isConnected, onSignIn, signInWithWalletAsync])
|
|
74
|
+
|
|
75
|
+
if (!dropdownData || !isConnected) {
|
|
76
|
+
return (
|
|
77
|
+
<DisconnectedTrigger
|
|
78
|
+
// If connect wallet flow is not provided it fallbacks to RainbowKit's
|
|
79
|
+
// connect modal
|
|
80
|
+
onClick={onSignIn || openConnectModal}
|
|
81
|
+
isLoading={isPending}
|
|
82
|
+
>
|
|
83
|
+
Sign in
|
|
84
|
+
</DisconnectedTrigger>
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<StatefulPopover
|
|
90
|
+
content={<Content data={dropdownData} onSignOut={onSignOut} />}
|
|
91
|
+
placement={placement}
|
|
92
|
+
animateOutTime={animateOutTime}
|
|
93
|
+
overrides={{
|
|
94
|
+
...overrides,
|
|
95
|
+
Body: {
|
|
96
|
+
...overrides?.Body,
|
|
97
|
+
style: {
|
|
98
|
+
minWidth: "396px",
|
|
99
|
+
borderRadius: theme.borders.radius500,
|
|
100
|
+
boxShadow: theme.lighting.shadow500,
|
|
101
|
+
overflow: "hidden",
|
|
102
|
+
...overrides?.Body?.style,
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
}}
|
|
106
|
+
{...restProps}
|
|
107
|
+
>
|
|
108
|
+
<ConnectedTrigger avatar={<DefaultAvatar />} />
|
|
109
|
+
</StatefulPopover>
|
|
110
|
+
)
|
|
111
|
+
}
|