@mezo-org/passport 0.4.0-dev.8 → 0.4.0-dev.81
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/README.md +18 -22
- package/dist/src/api/auth.d.ts +7 -3
- package/dist/src/api/auth.d.ts.map +1 -1
- package/dist/src/api/auth.js +3 -1
- package/dist/src/api/auth.js.map +1 -1
- package/dist/src/api/client.d.ts +4 -1
- package/dist/src/api/client.d.ts.map +1 -1
- package/dist/src/api/client.js +9 -2
- package/dist/src/api/client.js.map +1 -1
- package/dist/src/api/portal.d.ts +3 -9
- package/dist/src/api/portal.d.ts.map +1 -1
- package/dist/src/api/portal.js +8 -5
- package/dist/src/api/portal.js.map +1 -1
- package/dist/src/components/Dropdown/ConnectedTrigger.d.ts +2 -1
- package/dist/src/components/Dropdown/ConnectedTrigger.d.ts.map +1 -1
- package/dist/src/components/Dropdown/ConnectedTrigger.js +29 -20
- package/dist/src/components/Dropdown/ConnectedTrigger.js.map +1 -1
- package/dist/src/components/Dropdown/Content.d.ts +19 -5
- package/dist/src/components/Dropdown/Content.d.ts.map +1 -1
- package/dist/src/components/Dropdown/Content.js +19 -61
- package/dist/src/components/Dropdown/Content.js.map +1 -1
- package/dist/src/components/Dropdown/DisconnectedTrigger.d.ts.map +1 -1
- package/dist/src/components/Dropdown/DisconnectedTrigger.js +2 -2
- package/dist/src/components/Dropdown/DisconnectedTrigger.js.map +1 -1
- package/dist/src/components/Dropdown/Dropdown.d.ts +13 -6
- package/dist/src/components/Dropdown/Dropdown.d.ts.map +1 -1
- package/dist/src/components/Dropdown/Dropdown.js +32 -9
- package/dist/src/components/Dropdown/Dropdown.js.map +1 -1
- package/dist/src/components/Dropdown/ListingItem.d.ts +13 -0
- package/dist/src/components/Dropdown/ListingItem.d.ts.map +1 -0
- package/dist/src/components/Dropdown/ListingItem.js +34 -0
- package/dist/src/components/Dropdown/ListingItem.js.map +1 -0
- package/dist/src/components/Dropdown/NestedViewLayout.d.ts +7 -0
- package/dist/src/components/Dropdown/NestedViewLayout.d.ts.map +1 -0
- package/dist/src/components/Dropdown/NestedViewLayout.js +34 -0
- package/dist/src/components/Dropdown/NestedViewLayout.js.map +1 -0
- package/dist/src/components/Dropdown/Receive/Receive.d.ts +7 -0
- package/dist/src/components/Dropdown/Receive/Receive.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Receive/Receive.js +53 -0
- package/dist/src/components/Dropdown/Receive/Receive.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts +7 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.js +48 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountAssetItem.d.ts +11 -0
- package/dist/src/components/Dropdown/Root/AccountAssetItem.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountAssetItem.js +9 -0
- package/dist/src/components/Dropdown/Root/AccountAssetItem.js.map +1 -0
- package/dist/src/components/Dropdown/{AccountBalance.d.ts → Root/AccountBalance.d.ts} +2 -1
- package/dist/src/components/Dropdown/Root/AccountBalance.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountBalance.js +15 -0
- package/dist/src/components/Dropdown/Root/AccountBalance.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts +9 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.js +48 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.js.map +1 -0
- package/dist/src/components/Dropdown/Root/Root.d.ts +23 -0
- package/dist/src/components/Dropdown/Root/Root.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/Root.js +57 -0
- package/dist/src/components/Dropdown/Root/Root.js.map +1 -0
- package/dist/src/components/Dropdown/Root/WalletAddress.d.ts +8 -0
- package/dist/src/components/Dropdown/Root/WalletAddress.d.ts.map +1 -0
- package/dist/src/components/Dropdown/{AccountAddress.js → Root/WalletAddress.js} +21 -15
- package/dist/src/components/Dropdown/Root/WalletAddress.js.map +1 -0
- package/dist/src/components/Dropdown/{WelcomeBlock.d.ts → Root/WelcomeBlock.d.ts} +1 -1
- package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts.map +1 -0
- package/dist/src/components/Dropdown/{WelcomeBlock.js → Root/WelcomeBlock.js} +5 -5
- package/dist/src/components/Dropdown/Root/WelcomeBlock.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/config.d.ts +29 -6
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +88 -15
- package/dist/src/config.js.map +1 -1
- package/dist/src/constants.d.ts +13 -3
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +14 -4
- package/dist/src/constants.js.map +1 -1
- package/dist/src/hooks/index.d.ts +4 -0
- package/dist/src/hooks/index.d.ts.map +1 -1
- package/dist/src/hooks/index.js +4 -0
- package/dist/src/hooks/index.js.map +1 -1
- package/dist/src/hooks/useAssetsConversionRates.d.ts +23 -0
- package/dist/src/hooks/useAssetsConversionRates.d.ts.map +1 -0
- package/dist/src/hooks/useAssetsConversionRates.js +90 -0
- package/dist/src/hooks/useAssetsConversionRates.js.map +1 -0
- package/dist/src/hooks/useAuthenticateWithWallet.d.ts +13 -13
- package/dist/src/hooks/useAuthenticateWithWallet.d.ts.map +1 -1
- package/dist/src/hooks/useAuthenticateWithWallet.js +8 -7
- package/dist/src/hooks/useAuthenticateWithWallet.js.map +1 -1
- package/dist/src/hooks/useBorrowData.d.ts +82 -0
- package/dist/src/hooks/useBorrowData.d.ts.map +1 -0
- package/dist/src/hooks/useBorrowData.js +159 -0
- package/dist/src/hooks/useBorrowData.js.map +1 -0
- package/dist/src/hooks/useCreateAccount.d.ts.map +1 -1
- package/dist/src/hooks/useCreateAccount.js +22 -1
- package/dist/src/hooks/useCreateAccount.js.map +1 -1
- package/dist/src/hooks/useDropdownData.d.ts +37 -34
- package/dist/src/hooks/useDropdownData.d.ts.map +1 -1
- package/dist/src/hooks/useDropdownData.js +85 -61
- package/dist/src/hooks/useDropdownData.js.map +1 -1
- package/dist/src/hooks/useLinkAccount.d.ts +19 -13
- package/dist/src/hooks/useLinkAccount.d.ts.map +1 -1
- package/dist/src/hooks/useLinkAccount.js +20 -1
- package/dist/src/hooks/useLinkAccount.js.map +1 -1
- package/dist/src/hooks/useRefreshPassport.d.ts +19 -0
- package/dist/src/hooks/useRefreshPassport.d.ts.map +1 -0
- package/dist/src/hooks/useRefreshPassport.js +44 -0
- package/dist/src/hooks/useRefreshPassport.js.map +1 -0
- package/dist/src/hooks/useSignInWithWallet.d.ts +13 -13
- package/dist/src/hooks/useSignInWithWallet.d.ts.map +1 -1
- package/dist/src/hooks/useSignUpWithWallet.d.ts +13 -13
- package/dist/src/hooks/useSignUpWithWallet.d.ts.map +1 -1
- package/dist/src/hooks/useTokensBalances.d.ts +74 -0
- package/dist/src/hooks/useTokensBalances.d.ts.map +1 -0
- package/dist/src/hooks/useTokensBalances.js +140 -0
- package/dist/src/hooks/useTokensBalances.js.map +1 -0
- package/dist/src/hooks/useValidateMezoId.d.ts +8 -0
- package/dist/src/hooks/useValidateMezoId.d.ts.map +1 -0
- package/dist/src/hooks/useValidateMezoId.js +24 -0
- package/dist/src/hooks/useValidateMezoId.js.map +1 -0
- package/dist/src/hooks/useWalletAccount.d.ts +2 -1
- package/dist/src/hooks/useWalletAccount.d.ts.map +1 -1
- package/dist/src/hooks/useWalletAccount.js +19 -15
- package/dist/src/hooks/useWalletAccount.js.map +1 -1
- package/dist/src/hooks/useWatchTransferEvents.d.ts +5 -0
- package/dist/src/hooks/useWatchTransferEvents.d.ts.map +1 -0
- package/dist/src/hooks/useWatchTransferEvents.js +63 -0
- package/dist/src/hooks/useWatchTransferEvents.js.map +1 -0
- 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/index.d.ts +13 -0
- package/dist/src/lib/contracts/index.d.ts.map +1 -0
- package/dist/src/lib/contracts/index.js +62 -0
- package/dist/src/lib/contracts/index.js.map +1 -0
- package/dist/src/lib/contracts/priceOracle.d.ts +43 -0
- package/dist/src/lib/contracts/priceOracle.d.ts.map +1 -0
- package/dist/src/lib/contracts/priceOracle.js +52 -0
- package/dist/src/lib/contracts/priceOracle.js.map +1 -0
- package/dist/src/provider.js +1 -1
- package/dist/src/provider.js.map +1 -1
- package/dist/src/stores/dropdownStore.d.ts +12 -0
- package/dist/src/stores/dropdownStore.d.ts.map +1 -0
- package/dist/src/stores/dropdownStore.js +13 -0
- package/dist/src/stores/dropdownStore.js.map +1 -0
- package/dist/src/utils/address.d.ts +1 -1
- package/dist/src/utils/address.d.ts.map +1 -1
- package/dist/src/utils/address.js +2 -0
- package/dist/src/utils/address.js.map +1 -1
- package/dist/src/utils/address.test.js +8 -5
- package/dist/src/utils/address.test.js.map +1 -1
- package/dist/src/utils/cryptoAssets.d.ts +17 -1
- package/dist/src/utils/cryptoAssets.d.ts.map +1 -1
- package/dist/src/utils/cryptoAssets.js +87 -31
- package/dist/src/utils/cryptoAssets.js.map +1 -1
- package/dist/src/utils/cryptoAssets.test.js +51 -33
- package/dist/src/utils/cryptoAssets.test.js.map +1 -1
- package/dist/src/utils/currency.d.ts +8 -0
- package/dist/src/utils/currency.d.ts.map +1 -1
- package/dist/src/utils/currency.js +11 -0
- package/dist/src/utils/currency.js.map +1 -1
- package/dist/src/utils/currency.test.js +1 -0
- package/dist/src/utils/currency.test.js.map +1 -1
- package/dist/src/utils/mezoId.d.ts +7 -0
- package/dist/src/utils/mezoId.d.ts.map +1 -0
- package/dist/src/utils/mezoId.js +41 -0
- package/dist/src/utils/mezoId.js.map +1 -0
- package/dist/src/utils/numbers.d.ts +39 -17
- package/dist/src/utils/numbers.d.ts.map +1 -1
- package/dist/src/utils/numbers.js +91 -33
- package/dist/src/utils/numbers.js.map +1 -1
- package/dist/src/utils/numbers.test.js +144 -22
- package/dist/src/utils/numbers.test.js.map +1 -1
- package/dist/src/utils/siww.d.ts +1 -0
- package/dist/src/utils/siww.d.ts.map +1 -1
- package/dist/src/utils/siww.js +50 -12
- package/dist/src/utils/siww.js.map +1 -1
- package/dist/src/utils/wagmi.d.ts +3 -0
- package/dist/src/utils/wagmi.d.ts.map +1 -0
- package/dist/src/utils/wagmi.js +7 -0
- package/dist/src/utils/wagmi.js.map +1 -0
- package/dist/src/wallet/index.d.ts +1 -1
- package/dist/src/wallet/index.d.ts.map +1 -1
- package/dist/src/wallet/index.js +1 -1
- package/dist/src/wallet/index.js.map +1 -1
- package/package.json +10 -8
- package/src/api/auth.ts +8 -4
- package/src/api/client.ts +11 -2
- package/src/api/portal.ts +11 -14
- package/src/components/Dropdown/ConnectedTrigger.tsx +52 -32
- package/src/components/Dropdown/Content.tsx +67 -117
- package/src/components/Dropdown/DisconnectedTrigger.tsx +2 -1
- package/src/components/Dropdown/Dropdown.tsx +75 -15
- package/src/components/Dropdown/ListingItem.tsx +80 -0
- package/src/components/Dropdown/NestedViewLayout.tsx +75 -0
- package/src/components/Dropdown/README.md +10 -18
- package/src/components/Dropdown/Receive/Receive.tsx +119 -0
- package/src/components/Dropdown/Root/AccountAddressActions.tsx +101 -0
- package/src/components/Dropdown/Root/AccountAssetItem.tsx +26 -0
- package/src/components/Dropdown/Root/AccountBalance.tsx +30 -0
- package/src/components/Dropdown/Root/AccountOtherAssets.tsx +68 -0
- package/src/components/Dropdown/Root/Root.tsx +147 -0
- package/src/components/Dropdown/Root/WalletAddress.tsx +128 -0
- package/src/components/Dropdown/{WelcomeBlock.tsx → Root/WelcomeBlock.tsx} +5 -6
- package/src/components/Dropdown/TestnetTopBanner.tsx +32 -0
- package/src/config.ts +135 -21
- package/src/constants.ts +18 -4
- package/src/hooks/index.ts +7 -0
- package/src/hooks/useAssetsConversionRates.ts +97 -0
- package/src/hooks/useAuthenticateWithWallet.ts +33 -12
- package/src/hooks/useBorrowData.ts +187 -0
- package/src/hooks/useCreateAccount.ts +28 -2
- package/src/hooks/useDropdownData.ts +119 -97
- package/src/hooks/useLinkAccount.ts +36 -4
- package/src/hooks/useRefreshPassport.ts +56 -0
- package/src/hooks/useSignInWithWallet.ts +2 -2
- package/src/hooks/useSignUpWithWallet.ts +2 -2
- package/src/hooks/useTokensBalances.ts +187 -0
- package/src/hooks/useValidateMezoId.ts +31 -0
- package/src/hooks/useWalletAccount.ts +29 -19
- package/src/hooks/useWatchTransferEvents.ts +74 -0
- package/src/index.ts +13 -1
- package/src/lib/contracts/index.ts +92 -0
- package/src/lib/contracts/priceOracle.ts +53 -0
- package/src/provider.ts +1 -1
- package/src/stores/dropdownStore.ts +20 -0
- package/src/utils/address.test.ts +10 -6
- package/src/utils/address.ts +5 -3
- package/src/utils/cryptoAssets.test.ts +57 -37
- package/src/utils/cryptoAssets.ts +113 -35
- package/src/utils/currency.test.ts +2 -0
- package/src/utils/currency.ts +21 -0
- package/src/utils/mezoId.ts +51 -0
- package/src/utils/numbers.test.ts +181 -23
- package/src/utils/numbers.ts +121 -34
- package/src/utils/siww.ts +71 -16
- package/src/utils/wagmi.ts +12 -0
- package/src/wallet/index.ts +3 -2
- package/dist/src/components/Dropdown/AccountAddress.d.ts +0 -8
- package/dist/src/components/Dropdown/AccountAddress.d.ts.map +0 -1
- package/dist/src/components/Dropdown/AccountAddress.js.map +0 -1
- package/dist/src/components/Dropdown/AccountAssets.d.ts +0 -14
- package/dist/src/components/Dropdown/AccountAssets.d.ts.map +0 -1
- package/dist/src/components/Dropdown/AccountAssets.js +0 -44
- package/dist/src/components/Dropdown/AccountAssets.js.map +0 -1
- package/dist/src/components/Dropdown/AccountBalance.d.ts.map +0 -1
- package/dist/src/components/Dropdown/AccountBalance.js +0 -18
- package/dist/src/components/Dropdown/AccountBalance.js.map +0 -1
- package/dist/src/components/Dropdown/WelcomeBlock.d.ts.map +0 -1
- package/dist/src/components/Dropdown/WelcomeBlock.js.map +0 -1
- package/dist/src/hooks/useAssetsUSDConversion.d.ts +0 -8
- package/dist/src/hooks/useAssetsUSDConversion.d.ts.map +0 -1
- package/dist/src/hooks/useAssetsUSDConversion.js +0 -21
- package/dist/src/hooks/useAssetsUSDConversion.js.map +0 -1
- package/src/components/Dropdown/AccountAddress.tsx +0 -111
- package/src/components/Dropdown/AccountAssets.tsx +0 -110
- package/src/components/Dropdown/AccountBalance.tsx +0 -38
- package/src/hooks/useAssetsUSDConversion.ts +0 -31
|
@@ -0,0 +1,128 @@
|
|
|
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 WalletAddressProps = {
|
|
15
|
+
address: string
|
|
16
|
+
type: "bitcoin" | "evm"
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default function WalletAddress(props: WalletAddressProps) {
|
|
20
|
+
const { address, type } = props
|
|
21
|
+
|
|
22
|
+
const { environment } = usePassportContext()
|
|
23
|
+
const blockExplorerUrl = getAddressExplorerUrl(
|
|
24
|
+
address,
|
|
25
|
+
type,
|
|
26
|
+
environment === "testnet",
|
|
27
|
+
)
|
|
28
|
+
const trimmedAddress = trimAddress(address)
|
|
29
|
+
const { icon: accountIcon } = getCryptoAsset(
|
|
30
|
+
type === "bitcoin" ? "BTC" : "ETH",
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
const [, theme] = useStyletron()
|
|
34
|
+
|
|
35
|
+
const [, copy] = useCopyToClipboard()
|
|
36
|
+
const [isCopiedMessageVisible, setIsCopiedMessageVisible] = useState(false)
|
|
37
|
+
const handleCopyAddress = useCallback(() => {
|
|
38
|
+
copy(address)
|
|
39
|
+
setIsCopiedMessageVisible(true)
|
|
40
|
+
|
|
41
|
+
setTimeout(() => {
|
|
42
|
+
setIsCopiedMessageVisible(false)
|
|
43
|
+
}, 2000)
|
|
44
|
+
}, [copy, address])
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<Block
|
|
48
|
+
as="button"
|
|
49
|
+
onClick={handleCopyAddress}
|
|
50
|
+
display="flex"
|
|
51
|
+
alignItems="center"
|
|
52
|
+
backgroundColor="transparent"
|
|
53
|
+
padding={`${theme.sizing.scale600} ${theme.sizing.scale500}`}
|
|
54
|
+
overrides={{
|
|
55
|
+
Block: {
|
|
56
|
+
style: {
|
|
57
|
+
borderWidth: 0,
|
|
58
|
+
cursor: "pointer",
|
|
59
|
+
":hover": {
|
|
60
|
+
backgroundColor: theme.colors.backgroundTertiary,
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
}}
|
|
65
|
+
>
|
|
66
|
+
<Block as={accountIcon} size={theme.sizing.scale600} />
|
|
67
|
+
{isCopiedMessageVisible ? (
|
|
68
|
+
<ParagraphSmall
|
|
69
|
+
margin={0}
|
|
70
|
+
marginLeft={theme.sizing.scale500}
|
|
71
|
+
color={theme.colors.contentPrimary}
|
|
72
|
+
>
|
|
73
|
+
Copied address to clipboard
|
|
74
|
+
</ParagraphSmall>
|
|
75
|
+
) : (
|
|
76
|
+
<Block
|
|
77
|
+
as="a"
|
|
78
|
+
marginLeft={theme.sizing.scale500}
|
|
79
|
+
href={blockExplorerUrl}
|
|
80
|
+
target="_blank"
|
|
81
|
+
overrides={{
|
|
82
|
+
Block: {
|
|
83
|
+
style: {
|
|
84
|
+
color: "inherit",
|
|
85
|
+
textDecoration: "none",
|
|
86
|
+
":hover": {
|
|
87
|
+
textDecoration: "underline",
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
}}
|
|
92
|
+
>
|
|
93
|
+
<ParagraphSmall
|
|
94
|
+
display="flex"
|
|
95
|
+
alignItems="center"
|
|
96
|
+
margin={0}
|
|
97
|
+
color={theme.colors.contentPrimary}
|
|
98
|
+
>
|
|
99
|
+
{trimmedAddress}
|
|
100
|
+
<LinkIcon
|
|
101
|
+
display="inline"
|
|
102
|
+
size={theme.sizing.scale550}
|
|
103
|
+
overrides={{
|
|
104
|
+
Svg: {
|
|
105
|
+
style: {
|
|
106
|
+
stroke: "currentColor",
|
|
107
|
+
marginLeft: theme.sizing.scale300,
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
}}
|
|
111
|
+
/>
|
|
112
|
+
</ParagraphSmall>
|
|
113
|
+
</Block>
|
|
114
|
+
)}
|
|
115
|
+
<CopyIcon
|
|
116
|
+
size={theme.sizing.scale550}
|
|
117
|
+
color={theme.colors.contentPrimary}
|
|
118
|
+
overrides={{
|
|
119
|
+
Svg: {
|
|
120
|
+
style: {
|
|
121
|
+
marginLeft: "auto",
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
}}
|
|
125
|
+
/>
|
|
126
|
+
</Block>
|
|
127
|
+
)
|
|
128
|
+
}
|
|
@@ -6,14 +6,13 @@ import {
|
|
|
6
6
|
useStyletron,
|
|
7
7
|
} from "@mezo-org/mezo-clay"
|
|
8
8
|
import React from "react"
|
|
9
|
-
import DefaultAvatar from "
|
|
10
|
-
import { formatHumanReadableNumber } from "../../utils/numbers"
|
|
9
|
+
import DefaultAvatar from "../../../assets/DefaultAvatar"
|
|
11
10
|
|
|
12
11
|
const DOT_DELIMITER_REGEX = /(?=\.)/
|
|
13
12
|
|
|
14
13
|
type WelcomeBlockProps = {
|
|
15
14
|
mezoId: string
|
|
16
|
-
matsBalance:
|
|
15
|
+
matsBalance: string
|
|
17
16
|
}
|
|
18
17
|
|
|
19
18
|
export default function WelcomeBlock(props: WelcomeBlockProps) {
|
|
@@ -75,16 +74,16 @@ export default function WelcomeBlock(props: WelcomeBlockProps) {
|
|
|
75
74
|
overrides={{
|
|
76
75
|
Block: {
|
|
77
76
|
style: {
|
|
78
|
-
gap: theme.sizing.
|
|
77
|
+
gap: theme.sizing.scale400,
|
|
79
78
|
},
|
|
80
79
|
},
|
|
81
80
|
}}
|
|
82
81
|
>
|
|
83
82
|
<Mats
|
|
84
83
|
color={theme.colors.contentPrimary}
|
|
85
|
-
size={theme.sizing.
|
|
84
|
+
size={theme.sizing.scale500}
|
|
86
85
|
/>
|
|
87
|
-
{
|
|
86
|
+
{matsBalance} mats
|
|
88
87
|
</LabelSmall>
|
|
89
88
|
</Block>
|
|
90
89
|
</Block>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React from "react"
|
|
2
|
+
import {
|
|
3
|
+
Block,
|
|
4
|
+
InfoCircle,
|
|
5
|
+
LabelSmall,
|
|
6
|
+
useStyletron,
|
|
7
|
+
} from "@mezo-org/mezo-clay"
|
|
8
|
+
import { usePassportContext } from "../../hooks/usePassportContext"
|
|
9
|
+
|
|
10
|
+
export default function TestnetTopBanner() {
|
|
11
|
+
const [, theme] = useStyletron()
|
|
12
|
+
|
|
13
|
+
const { environment } = usePassportContext()
|
|
14
|
+
|
|
15
|
+
if (environment !== "testnet") {
|
|
16
|
+
return null
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<Block
|
|
21
|
+
display="flex"
|
|
22
|
+
alignItems="center"
|
|
23
|
+
padding={`${theme.sizing.scale700} ${theme.sizing.scale600}`}
|
|
24
|
+
backgroundColor={theme.colors.warning}
|
|
25
|
+
>
|
|
26
|
+
<InfoCircle size={theme.sizing.scale550} />
|
|
27
|
+
<LabelSmall marginLeft={theme.sizing.scale500}>
|
|
28
|
+
You are using testnet funds.
|
|
29
|
+
</LabelSmall>
|
|
30
|
+
</Block>
|
|
31
|
+
)
|
|
32
|
+
}
|
package/src/config.ts
CHANGED
|
@@ -1,7 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import {
|
|
2
|
+
Chain,
|
|
3
|
+
getDefaultConfig,
|
|
4
|
+
RainbowKitWalletConnectParameters,
|
|
5
|
+
WalletList,
|
|
6
|
+
} from "@rainbow-me/rainbowkit"
|
|
7
|
+
import {
|
|
8
|
+
Config,
|
|
9
|
+
createConfig,
|
|
10
|
+
CreateConfigParameters,
|
|
11
|
+
http,
|
|
12
|
+
webSocket,
|
|
13
|
+
} from "wagmi"
|
|
14
|
+
import { walletConnectWallet } from "@rainbow-me/rainbowkit/wallets"
|
|
15
|
+
import {
|
|
16
|
+
CHAIN_ID,
|
|
17
|
+
MEZO_LOGO,
|
|
18
|
+
mezoMainnet,
|
|
19
|
+
mezoTestnet,
|
|
20
|
+
RPC_BY_NETWORK,
|
|
21
|
+
WALLET_CONNECT_SAFE_WALLET_ID,
|
|
22
|
+
} from "./constants"
|
|
5
23
|
import { getOKXWallet, getUnisatWallet, getXverseWallet } from "./wallet"
|
|
6
24
|
|
|
7
25
|
type WagmiConfigParameters = Omit<
|
|
@@ -10,6 +28,7 @@ type WagmiConfigParameters = Omit<
|
|
|
10
28
|
>
|
|
11
29
|
type GetDefaultConfigParameters = WagmiConfigParameters & {
|
|
12
30
|
appName: string
|
|
31
|
+
mezoNetwork?: "mainnet" | "testnet"
|
|
13
32
|
appDescription?: string
|
|
14
33
|
appUrl?: string
|
|
15
34
|
appIcon?: string
|
|
@@ -20,7 +39,8 @@ type GetDefaultConfigParameters = WagmiConfigParameters & {
|
|
|
20
39
|
}
|
|
21
40
|
|
|
22
41
|
const transports = {
|
|
23
|
-
[CHAIN_ID.
|
|
42
|
+
[CHAIN_ID.mainnet]: http(RPC_BY_NETWORK.mainnet.http),
|
|
43
|
+
[CHAIN_ID.testnet]: http(RPC_BY_NETWORK.testnet.http),
|
|
24
44
|
} as Pick<CreateConfigParameters, "transports">
|
|
25
45
|
|
|
26
46
|
export const defaultConfig: Required<
|
|
@@ -34,39 +54,133 @@ export const defaultConfig: Required<
|
|
|
34
54
|
> = {
|
|
35
55
|
transports,
|
|
36
56
|
walletConnectProjectId: "",
|
|
37
|
-
chains: [
|
|
57
|
+
chains: [mezoMainnet, mezoTestnet],
|
|
38
58
|
multiInjectedProviderDiscovery: true,
|
|
39
59
|
}
|
|
40
60
|
|
|
41
|
-
const
|
|
42
|
-
rpcUrl: RPC_BY_NETWORK.testnet,
|
|
61
|
+
const bitcoinWalletTestnetConfig = {
|
|
62
|
+
rpcUrl: RPC_BY_NETWORK.testnet.http,
|
|
43
63
|
chainId: CHAIN_ID.testnet,
|
|
44
64
|
}
|
|
45
65
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
66
|
+
const bitcoinWalletMainnetConfig = {
|
|
67
|
+
rpcUrl: RPC_BY_NETWORK.mainnet.http,
|
|
68
|
+
chainId: CHAIN_ID.mainnet,
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export const unisatWalletMezoTestnet = getUnisatWallet(
|
|
72
|
+
bitcoinWalletTestnetConfig,
|
|
73
|
+
)
|
|
74
|
+
export const okxWalletMezoTestnet = getOKXWallet(bitcoinWalletTestnetConfig)
|
|
75
|
+
export const xverseWalletMezoTestnet = getXverseWallet(
|
|
76
|
+
bitcoinWalletTestnetConfig,
|
|
77
|
+
)
|
|
49
78
|
|
|
50
|
-
export
|
|
79
|
+
export const unisatWalletMezoMainnet = getUnisatWallet(
|
|
80
|
+
bitcoinWalletMainnetConfig,
|
|
81
|
+
)
|
|
82
|
+
export const okxWalletMezoMainnet = getOKXWallet(bitcoinWalletMainnetConfig)
|
|
83
|
+
export const xverseWalletMezoMainnet = getXverseWallet(
|
|
84
|
+
bitcoinWalletMainnetConfig,
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
type WalletConnectWalletOptions = {
|
|
88
|
+
projectId: string
|
|
89
|
+
options?: RainbowKitWalletConnectParameters
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Creates a RainbowKit's WalletConnect wallet with Safe Wallets (Ethereum and Mezo). It has disabled Explorer.
|
|
94
|
+
* @param opts - Options for the WalletConnect wallet.
|
|
95
|
+
* @returns A WalletConnect wallet configured for Safe Wallets.
|
|
96
|
+
*/
|
|
97
|
+
export const safeWalletConnectWallet = (opts: WalletConnectWalletOptions) => {
|
|
98
|
+
const { projectId, options } = opts
|
|
99
|
+
|
|
100
|
+
return walletConnectWallet({
|
|
101
|
+
projectId,
|
|
102
|
+
options: {
|
|
103
|
+
...options,
|
|
104
|
+
qrModalOptions: {
|
|
105
|
+
...options?.qrModalOptions,
|
|
106
|
+
desktopWallets: [
|
|
107
|
+
...(options?.qrModalOptions?.desktopWallets || []),
|
|
108
|
+
{
|
|
109
|
+
id: "mezo",
|
|
110
|
+
name: "Mezo Safe",
|
|
111
|
+
links: {
|
|
112
|
+
native: "",
|
|
113
|
+
universal: "https://safe.mezo.org/",
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
walletImages: {
|
|
118
|
+
...options?.qrModalOptions?.walletImages,
|
|
119
|
+
mezo: MEZO_LOGO,
|
|
120
|
+
},
|
|
121
|
+
explorerExcludedWalletIds: "ALL",
|
|
122
|
+
explorerRecommendedWalletIds: [
|
|
123
|
+
...(options?.qrModalOptions?.explorerRecommendedWalletIds || []),
|
|
124
|
+
WALLET_CONNECT_SAFE_WALLET_ID,
|
|
125
|
+
],
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function getDefaultWallets(
|
|
132
|
+
network: "mainnet" | "testnet" = "mainnet",
|
|
133
|
+
): WalletList {
|
|
51
134
|
return [
|
|
52
135
|
{
|
|
53
136
|
groupName: "Bitcoin",
|
|
54
|
-
wallets:
|
|
137
|
+
wallets:
|
|
138
|
+
network === "mainnet"
|
|
139
|
+
? [
|
|
140
|
+
unisatWalletMezoMainnet,
|
|
141
|
+
okxWalletMezoMainnet,
|
|
142
|
+
xverseWalletMezoMainnet,
|
|
143
|
+
]
|
|
144
|
+
: [
|
|
145
|
+
unisatWalletMezoTestnet,
|
|
146
|
+
okxWalletMezoTestnet,
|
|
147
|
+
xverseWalletMezoTestnet,
|
|
148
|
+
],
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
groupName: "Ethereum",
|
|
152
|
+
wallets: [safeWalletConnectWallet],
|
|
55
153
|
},
|
|
56
154
|
]
|
|
57
155
|
}
|
|
58
156
|
|
|
59
|
-
export function getConfig({
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
157
|
+
export function getConfig(config: GetDefaultConfigParameters): Config {
|
|
158
|
+
const {
|
|
159
|
+
appName,
|
|
160
|
+
mezoNetwork = "mainnet",
|
|
161
|
+
walletConnectProjectId = defaultConfig.walletConnectProjectId,
|
|
162
|
+
...restParameters
|
|
163
|
+
} = config
|
|
164
|
+
|
|
165
|
+
const wallets = config.bitcoinWallets ?? [...getDefaultWallets(mezoNetwork)]
|
|
166
|
+
|
|
65
167
|
return getDefaultConfig({
|
|
66
168
|
...defaultConfig,
|
|
67
169
|
appName,
|
|
68
|
-
wallets
|
|
69
|
-
projectId: walletConnectProjectId
|
|
170
|
+
wallets,
|
|
171
|
+
projectId: walletConnectProjectId,
|
|
70
172
|
...restParameters,
|
|
71
173
|
})
|
|
72
174
|
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* This config is only used to listen for Transfer events on mezo chain.
|
|
178
|
+
* Should not be exported in index for public use.
|
|
179
|
+
*/
|
|
180
|
+
export const simpleWssMezoConfig = createConfig({
|
|
181
|
+
chains: [mezoMainnet, mezoTestnet],
|
|
182
|
+
transports: {
|
|
183
|
+
[mezoMainnet.id]: webSocket(RPC_BY_NETWORK.mainnet.webSocket),
|
|
184
|
+
[mezoTestnet.id]: webSocket(RPC_BY_NETWORK.testnet.webSocket),
|
|
185
|
+
},
|
|
186
|
+
})
|
package/src/constants.ts
CHANGED
|
@@ -1,11 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { mezoMainnet, mezoTestnet } from "@mezo-org/orangekit"
|
|
2
2
|
|
|
3
|
-
export {
|
|
3
|
+
export { mezoMainnet, mezoTestnet } from "@mezo-org/orangekit"
|
|
4
4
|
|
|
5
5
|
export const CHAIN_ID = {
|
|
6
|
-
testnet:
|
|
6
|
+
testnet: mezoTestnet.id,
|
|
7
|
+
mainnet: mezoMainnet.id,
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
export const RPC_BY_NETWORK = {
|
|
10
|
-
|
|
11
|
+
mainnet: {
|
|
12
|
+
http: mezoMainnet.rpcUrls.default.http[0],
|
|
13
|
+
webSocket: mezoMainnet.rpcUrls.default.webSocket?.[0],
|
|
14
|
+
},
|
|
15
|
+
testnet: {
|
|
16
|
+
http: mezoTestnet.rpcUrls.default.http[0],
|
|
17
|
+
webSocket: mezoTestnet.rpcUrls.default.webSocket?.[0],
|
|
18
|
+
},
|
|
11
19
|
}
|
|
20
|
+
|
|
21
|
+
export const MEZO_LOGO =
|
|
22
|
+
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAAAAXNSR0IB2cksfwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAQ5QTFRF9TlR9TpS9kRa91Zr92d6+HCC+G+B9klf9TtT9UBX9lJn92V4915x9k9k9T5V+6ax/dLY//b3//7+//////j5/drf+7C6+HSF+pmm/MrQ/vDx//39//n6/urs/MPK+YKR9UJZ92F0/eDk+HiI/LfA/vHz+Y6c+qGt/vP0+6+59kdd9TxU+HqK/uzu/czS9k1j+pik+7S9+YeW/dfc9kVb+YWU//z8/L3F91lt/cvS/MLJ9lRp+Yya/dbb/L/H/d3h/uHl91xw//T2/MbN/uPm+HKD+pCe+pWi/d/j/ufq/ujq9kth/MfO91tv/c7U+7O89lVq+6mz92N19kpg+G1/+p2p+6Ov+pKf+6y3+Gt92yHguQAAAx9JREFUeJzt1tlPE0EcB/CdUtouRxuKQItgCyVNpG3SKoWKqOHBxKQGCf6Z4hGNT8Yjno00UAERJcoCEWuIIgj0iHUtuwWW3ZlpSYq8fOelM/Pb3fnsHL8tEU64EAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgKPfoZSCmWTpcZGQvGAlZPOYAPXm3fEVRoYyRmN9MZDdVRAiHQOgK5s/aDjIZ/3wbdnMfsNJVjJC2XIkgN1N1rRtsZHMaZoBQla1YVszeVdVgL17Rd91JqcRnFs06cKF/E4VAQHLsrHTS5J71ahhRYqrJC9WD2BppS1pT7Y0zbHlHCXsSJeZg8oBYs8qtd//TVJ+Bz9Swyb/qyoBhj4wAr1vd1+9K8/IC46lQnUA7jwrEtgorkIrc5jgBG8VKgZ4/7APdaEnKQ7MMMMh8rQKgFo7J2hpWolyjjxvJ1YM8P/gRcNfWFtAKZHEVuWAq0te5Xe96VD3/DYPIISmua/S3i6rD53VL6TxtmsTvCdF0q4pXrx/a44XHiAPywKuv+E8IFr7oKuBng/U4t/x8M59dF4qC7jxkn2/N1U8bKPTG+wrLt+NE84bhB/re4wAD3O/CJHXym4eSzEFNvOS0NvMXoXadHlA4+k1Q59avJ9+q5WLy6xjFWq+LQh9jhQj7Ou4Ux5AWhg5Ldh0b6/a0MqYg05l6HgNYx8UcoZsRjk8dU5qzotsJQ4aYwvUnej8qk5NPC3RwrZfxrNMO71DEkWwP/8lpYsyB2JsvFTrc1F2os9zy9hJA9i7LYa/Fpr5V8uwbEj+4oVxea9OWQW5LSNVBhBsI/rTEq3RJxBhdH1Wd1fguSYdmzr00x2YoC0tI4H6Nv9qL7o0JRmv6dtekzVNU/jR4fGCkz81zf7vk9SRWBn8pvmJtQRucUin3tOuEdt3zpa+gT5n6rwhydbVm7Pq8+WY9T7jbLE/IfYr6c2IIDyTXdMy6xoyuNGb8Dhe+DsnJVo8nnRbLTPDFtNCkhbmA/5TAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAODEAf8AjIbLgSYY+/AAAAAASUVORK5CYII="
|
|
23
|
+
|
|
24
|
+
export const WALLET_CONNECT_SAFE_WALLET_ID =
|
|
25
|
+
"225affb176778569276e484e1b92637ad061b01e13a048b35a9d280c3b58970f"
|
package/src/hooks/index.ts
CHANGED
|
@@ -6,13 +6,20 @@ export {
|
|
|
6
6
|
useSubscribeToConnectorEvent,
|
|
7
7
|
useSubscribeToWalletNetworkDoesNotMatchProviderChain,
|
|
8
8
|
} from "@mezo-org/orangekit"
|
|
9
|
+
export { useInvalidateBorrowData, useResetBorrowData } from "./useBorrowData"
|
|
9
10
|
export * from "./useGetAccountByAddress"
|
|
10
11
|
export * from "./useGetAccountByMezoId"
|
|
11
12
|
export * from "./useGetCurrentAccount"
|
|
12
13
|
export * from "./useGetSession"
|
|
13
14
|
export * from "./useLinkAccount"
|
|
15
|
+
export * from "./useRefreshPassport"
|
|
14
16
|
export * from "./useSignInWithDiscord"
|
|
15
17
|
export * from "./useSignInWithWallet"
|
|
16
18
|
export * from "./useSignOut"
|
|
17
19
|
export * from "./useSignUpWithWallet"
|
|
20
|
+
export {
|
|
21
|
+
useInvalidateTokensBalances,
|
|
22
|
+
useResetTokensBalances,
|
|
23
|
+
} from "./useTokensBalances"
|
|
18
24
|
export * from "./useUpdateMezoId"
|
|
25
|
+
export * from "./useValidateMezoId"
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { useQuery } from "@tanstack/react-query"
|
|
2
|
+
import { useReadContract } from "wagmi"
|
|
3
|
+
import { ONE_SECOND_MS } from "../utils/time"
|
|
4
|
+
import { QUERY_KEYS } from "./constants"
|
|
5
|
+
import { usePortalApiClient } from "./usePortalApiClient"
|
|
6
|
+
import { priceOracleContract } from "../lib/contracts"
|
|
7
|
+
import { fromFloatToBigInt } from "../utils/numbers"
|
|
8
|
+
import { getCryptoAsset } from "../utils/cryptoAssets"
|
|
9
|
+
import { CHAIN_ID } from "../constants"
|
|
10
|
+
import { usePassportContext } from "./usePassportContext"
|
|
11
|
+
|
|
12
|
+
const BTC_TARGET_DIGITS = getCryptoAsset("BTC").decimals
|
|
13
|
+
const T_TARGET_DIGITS = getCryptoAsset("mT").decimals
|
|
14
|
+
// If the oracle has not been updated in at least 60 seconds, it is stale.
|
|
15
|
+
const MAX_PRICE_DELAY = 60 * ONE_SECOND_MS
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Scales the price by the number of digits.
|
|
19
|
+
* @dev Oracles returns prices with variable number of digits. This function
|
|
20
|
+
* scales the price to a fixed number of digits ensuring consistency.
|
|
21
|
+
* @param price - The price to scale.
|
|
22
|
+
* @param priceDigits - The number of digits in the price.
|
|
23
|
+
* @returns The scaled price.
|
|
24
|
+
*/
|
|
25
|
+
function scalePriceByDigits(price: bigint, priceDigits: number): bigint {
|
|
26
|
+
if (priceDigits > BTC_TARGET_DIGITS) {
|
|
27
|
+
return price / 10n ** BigInt(priceDigits - BTC_TARGET_DIGITS)
|
|
28
|
+
}
|
|
29
|
+
if (priceDigits < BTC_TARGET_DIGITS) {
|
|
30
|
+
return price * 10n ** BigInt(BTC_TARGET_DIGITS - priceDigits)
|
|
31
|
+
}
|
|
32
|
+
return price
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Hook to fetch assets conversion rates.
|
|
37
|
+
* @see https://github.com/mezo-org/musd/blob/f0b2030315f0d8b0fc11a9fc778856fe4673051f/solidity/contracts/PriceFeed.sol
|
|
38
|
+
* @returns {}.data.{}.price - The latest asset price.
|
|
39
|
+
* @returns {}.data.{}.digits - The latest asset price digits.
|
|
40
|
+
* @returns {}.isPending - Whether the request is pending.
|
|
41
|
+
* @returns {}.isError - Whether there was an error fetching the price.
|
|
42
|
+
*/
|
|
43
|
+
export function useAssetsConversionRates() {
|
|
44
|
+
const portalApiClient = usePortalApiClient()
|
|
45
|
+
const { environment = "mainnet" } = usePassportContext()
|
|
46
|
+
|
|
47
|
+
const btcPrice = useReadContract({
|
|
48
|
+
...priceOracleContract,
|
|
49
|
+
functionName: "latestRoundData",
|
|
50
|
+
query: {
|
|
51
|
+
refetchInterval: ({ state }) => {
|
|
52
|
+
if (!state.data) return MAX_PRICE_DELAY
|
|
53
|
+
|
|
54
|
+
const [, , , updatedAt] = state.data ?? []
|
|
55
|
+
if (!updatedAt) return MAX_PRICE_DELAY
|
|
56
|
+
|
|
57
|
+
const age = Date.now() - Number(updatedAt) * 1000
|
|
58
|
+
|
|
59
|
+
return age > MAX_PRICE_DELAY
|
|
60
|
+
? // If the data is stale, we want to refetch as soon as possible, but
|
|
61
|
+
// not faster than once per second, to avoid excessive requests.
|
|
62
|
+
// Math.max ensures the interval is at least 1 second.
|
|
63
|
+
Math.max(ONE_SECOND_MS, MAX_PRICE_DELAY - age)
|
|
64
|
+
: MAX_PRICE_DELAY - age
|
|
65
|
+
},
|
|
66
|
+
select: (data) => {
|
|
67
|
+
const [, answer] = data
|
|
68
|
+
return scalePriceByDigits(answer, BTC_TARGET_DIGITS)
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
chainId: CHAIN_ID[environment],
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
const tPrice = useQuery({
|
|
75
|
+
queryKey: [QUERY_KEYS.ASSETS_USD_CONVERSION],
|
|
76
|
+
queryFn: () => portalApiClient.getPortalStatistics(),
|
|
77
|
+
select: (data) =>
|
|
78
|
+
fromFloatToBigInt(data.currentUsdPerTToken, T_TARGET_DIGITS),
|
|
79
|
+
refetchInterval: MAX_PRICE_DELAY,
|
|
80
|
+
throwOnError: true,
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
data: {
|
|
85
|
+
t: {
|
|
86
|
+
price: tPrice.data ?? 0n,
|
|
87
|
+
decimals: T_TARGET_DIGITS,
|
|
88
|
+
},
|
|
89
|
+
btc: {
|
|
90
|
+
price: btcPrice.data ?? 0n,
|
|
91
|
+
decimals: BTC_TARGET_DIGITS,
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
isPending: tPrice.isPending || btcPrice.isPending,
|
|
95
|
+
isError: tPrice.isError || btcPrice.isError,
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { useSignMessage } from "wagmi"
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
DefaultError,
|
|
4
|
+
MutationOptions,
|
|
5
|
+
useMutation,
|
|
6
|
+
} from "@tanstack/react-query"
|
|
3
7
|
import { useCreateAccount } from "./useCreateAccount"
|
|
4
8
|
import { useCreateSession } from "./useCreateSession"
|
|
5
9
|
import { useEnsureNoSessionAndFetchNonce } from "./useEnsureNoSessionAndFetchNonce"
|
|
6
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
createSignInWithWalletMessage,
|
|
12
|
+
verifyDomainInSignInWithWalletMessage,
|
|
13
|
+
} from "../utils/siww"
|
|
7
14
|
import { useGetAccountByAddress } from "./useGetAccountByAddress"
|
|
8
15
|
import type { Session } from "../api"
|
|
9
16
|
import useWalletAccount from "./useWalletAccount"
|
|
@@ -11,40 +18,54 @@ import useWalletAccount from "./useWalletAccount"
|
|
|
11
18
|
function useAuthenticateWithWallet(
|
|
12
19
|
shouldCreateAccount = false,
|
|
13
20
|
mutationOptions: Omit<
|
|
14
|
-
MutationOptions<Session>,
|
|
21
|
+
MutationOptions<Session, DefaultError, number | void>,
|
|
15
22
|
"mutationFn" | "mutationKey"
|
|
16
23
|
> = {},
|
|
17
24
|
) {
|
|
18
|
-
const {
|
|
25
|
+
const {
|
|
26
|
+
walletAddress,
|
|
27
|
+
chainId: walletChainId,
|
|
28
|
+
connector,
|
|
29
|
+
networkFamily,
|
|
30
|
+
} = useWalletAccount()
|
|
19
31
|
const { ensureNoSessionAndFetchNonce } = useEnsureNoSessionAndFetchNonce()
|
|
20
32
|
const { createSessionAsync } = useCreateSession()
|
|
21
33
|
const { createAccountAsync } = useCreateAccount()
|
|
22
34
|
const { signMessageAsync } = useSignMessage()
|
|
23
35
|
|
|
24
|
-
const { refetch: getAccountByAddress } = useGetAccountByAddress(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
36
|
+
const { refetch: getAccountByAddress } = useGetAccountByAddress(
|
|
37
|
+
walletAddress,
|
|
38
|
+
{
|
|
39
|
+
enabled: false,
|
|
40
|
+
retry: false,
|
|
41
|
+
},
|
|
42
|
+
)
|
|
28
43
|
|
|
29
44
|
const { mutate, mutateAsync, ...signInMutationRestParameters } = useMutation({
|
|
30
|
-
mutationFn: async () => {
|
|
31
|
-
if (!
|
|
45
|
+
mutationFn: async (chainId?: number | void) => {
|
|
46
|
+
if (!walletAddress) {
|
|
32
47
|
throw new Error("Sign in error: Wallet not connected!")
|
|
33
48
|
}
|
|
34
49
|
|
|
35
50
|
const nonce = await ensureNoSessionAndFetchNonce()
|
|
36
51
|
|
|
37
52
|
const messageResult = createSignInWithWalletMessage(
|
|
38
|
-
|
|
53
|
+
walletAddress,
|
|
39
54
|
nonce,
|
|
40
55
|
networkFamily,
|
|
41
|
-
chainId,
|
|
56
|
+
chainId ?? walletChainId,
|
|
42
57
|
)
|
|
43
58
|
const signatureResult = await signMessageAsync({
|
|
44
59
|
message: messageResult,
|
|
45
60
|
connector,
|
|
46
61
|
})
|
|
47
62
|
|
|
63
|
+
await verifyDomainInSignInWithWalletMessage(
|
|
64
|
+
messageResult,
|
|
65
|
+
signatureResult,
|
|
66
|
+
nonce,
|
|
67
|
+
)
|
|
68
|
+
|
|
48
69
|
if (shouldCreateAccount) {
|
|
49
70
|
const getAccountByAddressResult = await getAccountByAddress()
|
|
50
71
|
|