@mezo-org/passport 0.4.0-dev.4 → 0.4.0-dev.6
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 +36 -59
- package/dist/src/api/auth.d.ts.map +1 -1
- package/dist/src/api/auth.js +21 -49
- 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 +58 -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 +8 -0
- package/dist/src/components/Dropdown/Content.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Content.js +65 -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 +18 -0
- package/dist/src/components/Dropdown/Dropdown.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Dropdown.js +42 -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 +1 -0
- package/dist/src/hooks/constants.d.ts.map +1 -1
- package/dist/src/hooks/constants.js +1 -0
- package/dist/src/hooks/constants.js.map +1 -1
- package/dist/src/hooks/index.d.ts +1 -1
- package/dist/src/hooks/index.d.ts.map +1 -1
- package/dist/src/hooks/index.js +1 -1
- 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 +70 -0
- package/dist/src/hooks/useAuthenticateWithWallet.js.map +1 -0
- package/dist/src/hooks/useCreateAccount.d.ts +23 -173
- package/dist/src/hooks/useCreateAccount.d.ts.map +1 -1
- package/dist/src/hooks/useCreateAccount.js +7 -4
- package/dist/src/hooks/useCreateAccount.js.map +1 -1
- package/dist/src/hooks/useCreateSession.d.ts +12 -101
- package/dist/src/hooks/useCreateSession.d.ts.map +1 -1
- package/dist/src/hooks/useCreateSession.js +10 -8
- package/dist/src/hooks/useCreateSession.js.map +1 -1
- package/dist/src/hooks/useDropdownData.d.ts +44 -0
- package/dist/src/hooks/useDropdownData.d.ts.map +1 -0
- package/dist/src/hooks/useDropdownData.js +73 -0
- package/dist/src/hooks/useDropdownData.js.map +1 -0
- package/dist/src/hooks/useEnsureNoSessionAndFetchNonce.d.ts.map +1 -1
- package/dist/src/hooks/useEnsureNoSessionAndFetchNonce.js +1 -0
- package/dist/src/hooks/useEnsureNoSessionAndFetchNonce.js.map +1 -1
- package/dist/src/hooks/useGetAccountByAddress.d.ts +2 -2
- package/dist/src/hooks/useGetAccountByAddress.d.ts.map +1 -1
- package/dist/src/hooks/useGetAccountByMezoId.d.ts +2 -2
- package/dist/src/hooks/useGetAccountByMezoId.d.ts.map +1 -1
- package/dist/src/hooks/useGetCurrentAccount.d.ts +16 -2
- package/dist/src/hooks/useGetCurrentAccount.d.ts.map +1 -1
- package/dist/src/hooks/useGetCurrentAccount.js +25 -3
- package/dist/src/hooks/useGetCurrentAccount.js.map +1 -1
- package/dist/src/hooks/useGetSession.d.ts +1 -1
- package/dist/src/hooks/useGetSession.d.ts.map +1 -1
- package/dist/src/hooks/useLinkAccount.d.ts +15 -175
- package/dist/src/hooks/useLinkAccount.d.ts.map +1 -1
- package/dist/src/hooks/useLinkAccount.js +7 -4
- 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 -100
- package/dist/src/hooks/useSignInWithDiscord.d.ts.map +1 -1
- package/dist/src/hooks/useSignInWithDiscord.js +6 -3
- package/dist/src/hooks/useSignInWithDiscord.js.map +1 -1
- package/dist/src/hooks/useSignInWithWallet.d.ts +12 -100
- package/dist/src/hooks/useSignInWithWallet.d.ts.map +1 -1
- package/dist/src/hooks/useSignInWithWallet.js +6 -34
- 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 +7 -4
- 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 -136
- package/dist/src/hooks/useUpdateMezoId.d.ts.map +1 -1
- package/dist/src/hooks/useUpdateMezoId.js +7 -4
- 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 +25 -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 +37 -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 +49 -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 +43 -0
- package/dist/src/utils/numbers.d.ts.map +1 -0
- package/dist/src/utils/numbers.js +81 -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 +68 -0
- package/dist/src/utils/numbers.test.js.map +1 -0
- package/package.json +9 -3
- package/src/api/auth.ts +72 -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 +111 -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 +142 -0
- package/src/components/Dropdown/DisconnectedTrigger.tsx +35 -0
- package/src/components/Dropdown/Dropdown.tsx +81 -0
- package/src/components/Dropdown/README.md +46 -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 +1 -0
- package/src/hooks/index.ts +1 -1
- package/src/hooks/useAssetsUSDConversion.ts +31 -0
- package/src/hooks/useAuthenticateWithWallet.ts +105 -0
- package/src/hooks/useCreateAccount.ts +19 -5
- package/src/hooks/useCreateSession.ts +22 -9
- package/src/hooks/useDropdownData.ts +130 -0
- package/src/hooks/useEnsureNoSessionAndFetchNonce.ts +1 -0
- package/src/hooks/useGetAccountByAddress.ts +2 -2
- package/src/hooks/useGetAccountByMezoId.ts +2 -2
- package/src/hooks/useGetCurrentAccount.ts +46 -6
- package/src/hooks/useGetSession.ts +1 -1
- package/src/hooks/useLinkAccount.ts +18 -5
- package/src/hooks/usePortalApiClient.ts +6 -0
- package/src/hooks/useSignInWithDiscord.ts +14 -5
- package/src/hooks/useSignInWithWallet.ts +14 -42
- package/src/hooks/useSignOut.ts +18 -4
- package/src/hooks/useSignUpWithWallet.ts +21 -0
- package/src/hooks/useUpdateMezoId.ts +19 -4
- package/src/hooks/useWalletAccount.ts +41 -0
- package/src/index.ts +1 -0
- package/src/provider.ts +30 -37
- package/src/utils/address.test.ts +44 -0
- package/src/utils/address.ts +43 -0
- package/src/utils/cryptoAssets.test.ts +59 -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 +89 -0
- package/src/utils/numbers.ts +110 -0
|
@@ -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,142 @@
|
|
|
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
|
+
}
|
|
41
|
+
|
|
42
|
+
export default function DropdownContent(props: DropdownContentProps) {
|
|
43
|
+
const { data } = props
|
|
44
|
+
|
|
45
|
+
const [, theme] = useStyletron()
|
|
46
|
+
|
|
47
|
+
const {
|
|
48
|
+
mezoId,
|
|
49
|
+
address,
|
|
50
|
+
walletType,
|
|
51
|
+
totalBalanceInUsd,
|
|
52
|
+
formattedNativeAssets,
|
|
53
|
+
matsnet,
|
|
54
|
+
} = data
|
|
55
|
+
|
|
56
|
+
const { disconnect } = useDisconnect()
|
|
57
|
+
const { signOut } = useSignOut()
|
|
58
|
+
|
|
59
|
+
const handleLogOut = useCallback(() => {
|
|
60
|
+
signOut()
|
|
61
|
+
disconnect()
|
|
62
|
+
}, [signOut, disconnect])
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<Block
|
|
66
|
+
display="inline-flex"
|
|
67
|
+
flexDirection="column"
|
|
68
|
+
backgroundColor={theme.colors.backgroundPrimary}
|
|
69
|
+
padding={theme.sizing.scale500}
|
|
70
|
+
width="100%"
|
|
71
|
+
overrides={{
|
|
72
|
+
Block: {
|
|
73
|
+
style: {
|
|
74
|
+
boxSizing: "border-box",
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
}}
|
|
78
|
+
>
|
|
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} />
|
|
93
|
+
|
|
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>
|
|
111
|
+
)}
|
|
112
|
+
|
|
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>
|
|
140
|
+
</Block>
|
|
141
|
+
)
|
|
142
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
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, ...restProps },
|
|
24
|
+
},
|
|
25
|
+
}}
|
|
26
|
+
size="small"
|
|
27
|
+
shape="pill"
|
|
28
|
+
onClick={onClick}
|
|
29
|
+
>
|
|
30
|
+
{children}
|
|
31
|
+
</Button>
|
|
32
|
+
)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
export default DisconnectedTrigger
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {
|
|
2
|
+
StatefulPopover,
|
|
3
|
+
StatefulPopoverProps,
|
|
4
|
+
useStyletron,
|
|
5
|
+
} from "@mezo-org/mezo-clay"
|
|
6
|
+
import { useConnectModal } from "@rainbow-me/rainbowkit"
|
|
7
|
+
import React from "react"
|
|
8
|
+
import DefaultAvatar from "../../assets/DefaultAvatar"
|
|
9
|
+
import useDropdownData, {
|
|
10
|
+
DropdownCryptoAsset,
|
|
11
|
+
} from "../../hooks/useDropdownData"
|
|
12
|
+
import useWalletAccount from "../../hooks/useWalletAccount"
|
|
13
|
+
import ConnectedTrigger from "./ConnectedTrigger"
|
|
14
|
+
import Content from "./Content"
|
|
15
|
+
import DisconnectedTrigger from "./DisconnectedTrigger"
|
|
16
|
+
|
|
17
|
+
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">[]
|
|
24
|
+
} & Omit<StatefulPopoverProps, "children" | "content">
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Passport Dropdown component that displays user's wallet and assets information.
|
|
28
|
+
* @param {DropdownProps} props - Component props.
|
|
29
|
+
* @returns {JSX.Element}
|
|
30
|
+
*/
|
|
31
|
+
export function Dropdown(props: DropdownProps) {
|
|
32
|
+
const {
|
|
33
|
+
placement = "bottomRight",
|
|
34
|
+
animateOutTime = 120,
|
|
35
|
+
onSignInClick,
|
|
36
|
+
evmNativeAssets,
|
|
37
|
+
matsnetAssets,
|
|
38
|
+
...restProps
|
|
39
|
+
} = props
|
|
40
|
+
|
|
41
|
+
const [, theme] = useStyletron()
|
|
42
|
+
|
|
43
|
+
const dropdownData = useDropdownData({ evmNativeAssets, matsnetAssets })
|
|
44
|
+
|
|
45
|
+
const { openConnectModal } = useConnectModal()
|
|
46
|
+
|
|
47
|
+
const { isConnected } = useWalletAccount()
|
|
48
|
+
|
|
49
|
+
if (!dropdownData || !isConnected) {
|
|
50
|
+
return (
|
|
51
|
+
<DisconnectedTrigger
|
|
52
|
+
// If connect wallet flow is not provided it fallbacks to RainbowKit's
|
|
53
|
+
// connect modal
|
|
54
|
+
onClick={onSignInClick || openConnectModal}
|
|
55
|
+
>
|
|
56
|
+
Sign in
|
|
57
|
+
</DisconnectedTrigger>
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<StatefulPopover
|
|
63
|
+
content={<Content data={dropdownData} />}
|
|
64
|
+
placement={placement}
|
|
65
|
+
animateOutTime={animateOutTime}
|
|
66
|
+
overrides={{
|
|
67
|
+
Body: {
|
|
68
|
+
style: {
|
|
69
|
+
minWidth: "378px",
|
|
70
|
+
borderRadius: theme.borders.radius500,
|
|
71
|
+
boxShadow: theme.lighting.shadow500,
|
|
72
|
+
overflow: "hidden",
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
}}
|
|
76
|
+
{...restProps}
|
|
77
|
+
>
|
|
78
|
+
<ConnectedTrigger avatar={<DefaultAvatar />} />
|
|
79
|
+
</StatefulPopover>
|
|
80
|
+
)
|
|
81
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Passport Dropdown component
|
|
2
|
+
|
|
3
|
+
This component is a layer of interaction with Passport API in form of Dropdown
|
|
4
|
+
component. It allows to establish the session and interact with the API.
|
|
5
|
+
|
|
6
|
+
## Props
|
|
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
|
+
```
|
|
26
|
+
|
|
27
|
+
Besides that, component allows
|
|
28
|
+
[Clay's `StatefulPopover` props](https://baseweb.design/components/popover/)
|
|
29
|
+
excluding the `children` and `content`.
|
|
30
|
+
|
|
31
|
+
## Overview
|
|
32
|
+
|
|
33
|
+
The component has two distinguishable states - disconnected and connected. In
|
|
34
|
+
disconnected state the component offers the trigger to initiate the connection
|
|
35
|
+
flow. It can be fully customizable by providing your own one. As long as it's
|
|
36
|
+
compliant with Wagmi/RainbowKit it will work. Component will automatically
|
|
37
|
+
detect connected connector and change the state of component displaying the
|
|
38
|
+
avatar thumbnail instead of button.
|
|
39
|
+
|
|
40
|
+
Component has the following features:
|
|
41
|
+
|
|
42
|
+
- displays wallet address that can be copied,
|
|
43
|
+
- displays total balance in USD,
|
|
44
|
+
- displays partial balances per asset with token amounts and USD conversions,
|
|
45
|
+
- serves _Log out_ button which disconnects the wallet connector and closes
|
|
46
|
+
Passport API session.
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Block,
|
|
3
|
+
HeadingSmall,
|
|
4
|
+
LabelSmall,
|
|
5
|
+
Mats,
|
|
6
|
+
useStyletron,
|
|
7
|
+
} from "@mezo-org/mezo-clay"
|
|
8
|
+
import React from "react"
|
|
9
|
+
import DefaultAvatar from "../../assets/DefaultAvatar"
|
|
10
|
+
import { formatHumanReadableNumber } from "../../utils/numbers"
|
|
11
|
+
|
|
12
|
+
const DOT_DELIMITER_REGEX = /(?=\.)/
|
|
13
|
+
|
|
14
|
+
type WelcomeBlockProps = {
|
|
15
|
+
mezoId: string
|
|
16
|
+
matsBalance: number
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default function WelcomeBlock(props: WelcomeBlockProps) {
|
|
20
|
+
const { mezoId, matsBalance } = props
|
|
21
|
+
|
|
22
|
+
const [name, nameSuffix] = mezoId.split(DOT_DELIMITER_REGEX)
|
|
23
|
+
const [, theme] = useStyletron()
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<Block
|
|
27
|
+
display="flex"
|
|
28
|
+
alignItems="center"
|
|
29
|
+
padding={`${theme.sizing.scale600} 0`}
|
|
30
|
+
marginBottom={theme.sizing.scale300}
|
|
31
|
+
overrides={{
|
|
32
|
+
Block: {
|
|
33
|
+
style: {
|
|
34
|
+
gap: theme.sizing.scale600,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
}}
|
|
38
|
+
>
|
|
39
|
+
<Block
|
|
40
|
+
as={DefaultAvatar}
|
|
41
|
+
width={theme.sizing.scale1200}
|
|
42
|
+
height={theme.sizing.scale1200}
|
|
43
|
+
overrides={{
|
|
44
|
+
Block: {
|
|
45
|
+
style: {
|
|
46
|
+
borderRadius: "100%",
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
}}
|
|
50
|
+
/>
|
|
51
|
+
|
|
52
|
+
<Block
|
|
53
|
+
display="flex"
|
|
54
|
+
flexDirection="column"
|
|
55
|
+
overrides={{
|
|
56
|
+
Block: {
|
|
57
|
+
style: {
|
|
58
|
+
gap: theme.sizing.scale100,
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
}}
|
|
62
|
+
>
|
|
63
|
+
<HeadingSmall as="span">
|
|
64
|
+
<Block as="span">{name}</Block>
|
|
65
|
+
<Block as="span" color={theme.colors.gray500}>
|
|
66
|
+
{nameSuffix}
|
|
67
|
+
</Block>
|
|
68
|
+
</HeadingSmall>
|
|
69
|
+
|
|
70
|
+
<LabelSmall
|
|
71
|
+
display="flex"
|
|
72
|
+
alignItems="center"
|
|
73
|
+
margin={0}
|
|
74
|
+
color={theme.colors.contentTertiary}
|
|
75
|
+
overrides={{
|
|
76
|
+
Block: {
|
|
77
|
+
style: {
|
|
78
|
+
gap: theme.sizing.scale300,
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
}}
|
|
82
|
+
>
|
|
83
|
+
<Mats
|
|
84
|
+
color={theme.colors.contentPrimary}
|
|
85
|
+
size={theme.sizing.scale600}
|
|
86
|
+
/>
|
|
87
|
+
{formatHumanReadableNumber(matsBalance, 0)}
|
|
88
|
+
</LabelSmall>
|
|
89
|
+
</Block>
|
|
90
|
+
</Block>
|
|
91
|
+
)
|
|
92
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Dropdown, DropdownProps } from "./Dropdown"
|
package/src/hooks/constants.ts
CHANGED
package/src/hooks/index.ts
CHANGED
|
@@ -6,7 +6,6 @@ export {
|
|
|
6
6
|
useSubscribeToConnectorEvent,
|
|
7
7
|
useSubscribeToWalletNetworkDoesNotMatchProviderChain,
|
|
8
8
|
} from "@mezo-org/orangekit"
|
|
9
|
-
export * from "./useCreateAccount"
|
|
10
9
|
export * from "./useGetAccountByAddress"
|
|
11
10
|
export * from "./useGetAccountByMezoId"
|
|
12
11
|
export * from "./useGetCurrentAccount"
|
|
@@ -15,4 +14,5 @@ export * from "./useLinkAccount"
|
|
|
15
14
|
export * from "./useSignInWithDiscord"
|
|
16
15
|
export * from "./useSignInWithWallet"
|
|
17
16
|
export * from "./useSignOut"
|
|
17
|
+
export * from "./useSignUpWithWallet"
|
|
18
18
|
export * from "./useUpdateMezoId"
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { UseBaseQueryOptions, useQuery } from "@tanstack/react-query"
|
|
2
|
+
import { ONE_MINUTE_MS } from "../utils/time"
|
|
3
|
+
import { QUERY_KEYS } from "./constants"
|
|
4
|
+
import { usePortalApiClient } from "./usePortalApiClient"
|
|
5
|
+
|
|
6
|
+
type AssetsUsdConversion = {
|
|
7
|
+
btcUsd: string
|
|
8
|
+
ethUsd: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function useAssetsUsdConversion(
|
|
12
|
+
useQueryOptions: Partial<UseBaseQueryOptions<AssetsUsdConversion>> = {},
|
|
13
|
+
) {
|
|
14
|
+
const portalApiClient = usePortalApiClient()
|
|
15
|
+
|
|
16
|
+
return useQuery({
|
|
17
|
+
queryKey: [QUERY_KEYS.ASSETS_USD_CONVERSION],
|
|
18
|
+
queryFn: async () => {
|
|
19
|
+
const { currentUsdPerBtc, currentUsdPerEth } =
|
|
20
|
+
await portalApiClient.getPortalStatistics()
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
btcUsd: currentUsdPerBtc,
|
|
24
|
+
ethUsd: currentUsdPerEth,
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
staleTime: 30 * ONE_MINUTE_MS,
|
|
28
|
+
retry: 1,
|
|
29
|
+
...useQueryOptions,
|
|
30
|
+
})
|
|
31
|
+
}
|