@mezo-org/passport 0.4.0-dev.4 → 0.4.0-dev.41
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 +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 +33 -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/ConnectedTrigger.d.ts +8 -0
- package/dist/src/components/Dropdown/ConnectedTrigger.d.ts.map +1 -0
- package/dist/src/components/Dropdown/ConnectedTrigger.js +39 -0
- package/dist/src/components/Dropdown/ConnectedTrigger.js.map +1 -0
- package/dist/src/components/Dropdown/Content.d.ts +23 -0
- package/dist/src/components/Dropdown/Content.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Content.js +27 -0
- package/dist/src/components/Dropdown/Content.js.map +1 -0
- package/dist/src/components/Dropdown/DisconnectedTrigger.d.ts +7 -0
- package/dist/src/components/Dropdown/DisconnectedTrigger.d.ts.map +1 -0
- package/dist/src/components/Dropdown/DisconnectedTrigger.js +13 -0
- package/dist/src/components/Dropdown/DisconnectedTrigger.js.map +1 -0
- package/dist/src/components/Dropdown/Dropdown.d.ts +27 -0
- package/dist/src/components/Dropdown/Dropdown.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Dropdown.js +68 -0
- package/dist/src/components/Dropdown/Dropdown.js.map +1 -0
- 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/Root/AccountBalance.d.ts +8 -0
- 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/Root/WalletAddress.js +64 -0
- package/dist/src/components/Dropdown/Root/WalletAddress.js.map +1 -0
- package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts +8 -0
- package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/WelcomeBlock.js +44 -0
- 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/components/Dropdown/index.d.ts +3 -0
- package/dist/src/components/Dropdown/index.d.ts.map +1 -0
- package/dist/src/components/Dropdown/index.js +2 -0
- package/dist/src/components/Dropdown/index.js.map +1 -0
- package/dist/src/components/index.d.ts +2 -0
- package/dist/src/components/index.d.ts.map +1 -0
- package/dist/src/components/index.js +2 -0
- package/dist/src/components/index.js.map +1 -0
- package/dist/src/config.d.ts +41 -0
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +20 -5
- package/dist/src/config.js.map +1 -1
- package/dist/src/constants.d.ts +6 -2
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +8 -4
- package/dist/src/constants.js.map +1 -1
- 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 +4 -1
- package/dist/src/hooks/index.d.ts.map +1 -1
- package/dist/src/hooks/index.js +4 -1
- package/dist/src/hooks/index.js.map +1 -1
- package/dist/src/hooks/useAssetsConversionRates.d.ts +7 -0
- package/dist/src/hooks/useAssetsConversionRates.d.ts.map +1 -0
- package/dist/src/hooks/useAssetsConversionRates.js +24 -0
- package/dist/src/hooks/useAssetsConversionRates.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/useBorrowData.d.ts +60 -0
- package/dist/src/hooks/useBorrowData.d.ts.map +1 -0
- package/dist/src/hooks/useBorrowData.js +122 -0
- package/dist/src/hooks/useBorrowData.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 +47 -0
- package/dist/src/hooks/useDropdownData.d.ts.map +1 -0
- package/dist/src/hooks/useDropdownData.js +95 -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/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/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/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/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 +13 -0
- package/dist/src/hooks/useWalletAccount.d.ts.map +1 -0
- package/dist/src/hooks/useWalletAccount.js +29 -0
- package/dist/src/hooks/useWalletAccount.js.map +1 -0
- 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 +57 -0
- package/dist/src/lib/contracts/index.js.map +1 -0
- 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/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 +15 -0
- package/dist/src/utils/address.d.ts.map +1 -0
- package/dist/src/utils/address.js +37 -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 +40 -0
- package/dist/src/utils/address.test.js.map +1 -0
- package/dist/src/utils/cryptoAssets.d.ts +44 -0
- package/dist/src/utils/cryptoAssets.d.ts.map +1 -0
- package/dist/src/utils/cryptoAssets.js +131 -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 +67 -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 +58 -0
- package/dist/src/utils/numbers.d.ts.map +1 -0
- package/dist/src/utils/numbers.js +132 -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 +170 -0
- package/dist/src/utils/numbers.test.js.map +1 -0
- package/package.json +13 -5
- 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 +57 -0
- package/src/assets/DefaultAvatar.tsx +74 -0
- package/src/components/Dropdown/ConnectedTrigger.tsx +76 -0
- package/src/components/Dropdown/Content.tsx +98 -0
- package/src/components/Dropdown/DisconnectedTrigger.tsx +36 -0
- package/src/components/Dropdown/Dropdown.tsx +148 -0
- package/src/components/Dropdown/ListingItem.tsx +80 -0
- package/src/components/Dropdown/NestedViewLayout.tsx +75 -0
- package/src/components/Dropdown/README.md +41 -0
- 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/Root/WelcomeBlock.tsx +91 -0
- package/src/components/Dropdown/TestnetTopBanner.tsx +32 -0
- package/src/components/Dropdown/index.ts +2 -0
- package/src/components/index.ts +1 -0
- package/src/config.ts +27 -6
- package/src/constants.ts +8 -4
- package/src/hooks/constants.ts +1 -0
- package/src/hooks/index.ts +7 -1
- package/src/hooks/useAssetsConversionRates.ts +32 -0
- package/src/hooks/useAuthenticateWithWallet.ts +102 -0
- package/src/hooks/useBorrowData.ts +143 -0
- package/src/hooks/useCreateAccount.ts +19 -5
- package/src/hooks/useCreateSession.ts +22 -9
- package/src/hooks/useDropdownData.ts +139 -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/useRefreshPassport.ts +56 -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/useTokensBalances.ts +187 -0
- package/src/hooks/useUpdateMezoId.ts +19 -4
- package/src/hooks/useWalletAccount.ts +55 -0
- package/src/hooks/useWatchTransferEvents.ts +74 -0
- package/src/index.ts +9 -1
- package/src/lib/contracts/index.ts +88 -0
- package/src/provider.ts +30 -37
- package/src/stores/dropdownStore.ts +20 -0
- package/src/utils/address.test.ts +48 -0
- package/src/utils/address.ts +45 -0
- package/src/utils/cryptoAssets.test.ts +79 -0
- package/src/utils/cryptoAssets.ts +173 -0
- package/src/utils/currency.test.ts +38 -0
- package/src/utils/currency.ts +32 -0
- package/src/utils/numbers.test.ts +220 -0
- package/src/utils/numbers.ts +188 -0
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
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
|
+
|
|
11
|
+
const DOT_DELIMITER_REGEX = /(?=\.)/
|
|
12
|
+
|
|
13
|
+
type WelcomeBlockProps = {
|
|
14
|
+
mezoId: string
|
|
15
|
+
matsBalance: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default function WelcomeBlock(props: WelcomeBlockProps) {
|
|
19
|
+
const { mezoId, matsBalance } = props
|
|
20
|
+
|
|
21
|
+
const [name, nameSuffix] = mezoId.split(DOT_DELIMITER_REGEX)
|
|
22
|
+
const [, theme] = useStyletron()
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<Block
|
|
26
|
+
display="flex"
|
|
27
|
+
alignItems="center"
|
|
28
|
+
padding={`${theme.sizing.scale600} 0`}
|
|
29
|
+
marginBottom={theme.sizing.scale300}
|
|
30
|
+
overrides={{
|
|
31
|
+
Block: {
|
|
32
|
+
style: {
|
|
33
|
+
gap: theme.sizing.scale600,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
}}
|
|
37
|
+
>
|
|
38
|
+
<Block
|
|
39
|
+
as={DefaultAvatar}
|
|
40
|
+
width={theme.sizing.scale1200}
|
|
41
|
+
height={theme.sizing.scale1200}
|
|
42
|
+
overrides={{
|
|
43
|
+
Block: {
|
|
44
|
+
style: {
|
|
45
|
+
borderRadius: "100%",
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
}}
|
|
49
|
+
/>
|
|
50
|
+
|
|
51
|
+
<Block
|
|
52
|
+
display="flex"
|
|
53
|
+
flexDirection="column"
|
|
54
|
+
overrides={{
|
|
55
|
+
Block: {
|
|
56
|
+
style: {
|
|
57
|
+
gap: theme.sizing.scale100,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
}}
|
|
61
|
+
>
|
|
62
|
+
<HeadingSmall as="span">
|
|
63
|
+
<Block as="span">{name}</Block>
|
|
64
|
+
<Block as="span" color={theme.colors.gray500}>
|
|
65
|
+
{nameSuffix}
|
|
66
|
+
</Block>
|
|
67
|
+
</HeadingSmall>
|
|
68
|
+
|
|
69
|
+
<LabelSmall
|
|
70
|
+
display="flex"
|
|
71
|
+
alignItems="center"
|
|
72
|
+
margin={0}
|
|
73
|
+
color={theme.colors.contentTertiary}
|
|
74
|
+
overrides={{
|
|
75
|
+
Block: {
|
|
76
|
+
style: {
|
|
77
|
+
gap: theme.sizing.scale400,
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
}}
|
|
81
|
+
>
|
|
82
|
+
<Mats
|
|
83
|
+
color={theme.colors.contentPrimary}
|
|
84
|
+
size={theme.sizing.scale500}
|
|
85
|
+
/>
|
|
86
|
+
{matsBalance} mats
|
|
87
|
+
</LabelSmall>
|
|
88
|
+
</Block>
|
|
89
|
+
</Block>
|
|
90
|
+
)
|
|
91
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Dropdown, DropdownProps } from "./Dropdown"
|
package/src/config.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import { http } from "viem"
|
|
2
1
|
import { Chain, getDefaultConfig, WalletList } from "@rainbow-me/rainbowkit"
|
|
3
|
-
import {
|
|
4
|
-
|
|
2
|
+
import {
|
|
3
|
+
Config,
|
|
4
|
+
createConfig,
|
|
5
|
+
CreateConfigParameters,
|
|
6
|
+
http,
|
|
7
|
+
webSocket,
|
|
8
|
+
} from "wagmi"
|
|
9
|
+
import { mainnet, sepolia } from "wagmi/chains"
|
|
10
|
+
import { CHAIN_ID, mezoTestnet, RPC_BY_NETWORK } from "./constants"
|
|
5
11
|
import { getOKXWallet, getUnisatWallet, getXverseWallet } from "./wallet"
|
|
6
12
|
|
|
7
13
|
type WagmiConfigParameters = Omit<
|
|
@@ -20,7 +26,10 @@ type GetDefaultConfigParameters = WagmiConfigParameters & {
|
|
|
20
26
|
}
|
|
21
27
|
|
|
22
28
|
const transports = {
|
|
23
|
-
[
|
|
29
|
+
[mainnet.id]: http(mainnet.rpcUrls.default.http[0]),
|
|
30
|
+
[sepolia.id]: http(sepolia.rpcUrls.default.http[0]),
|
|
31
|
+
// TODO: Add chain for mezo mainnet
|
|
32
|
+
[CHAIN_ID.testnet]: http(RPC_BY_NETWORK.testnet.http),
|
|
24
33
|
} as Pick<CreateConfigParameters, "transports">
|
|
25
34
|
|
|
26
35
|
export const defaultConfig: Required<
|
|
@@ -34,12 +43,13 @@ export const defaultConfig: Required<
|
|
|
34
43
|
> = {
|
|
35
44
|
transports,
|
|
36
45
|
walletConnectProjectId: "",
|
|
37
|
-
chains: [
|
|
46
|
+
chains: [mainnet, sepolia, mezoTestnet],
|
|
38
47
|
multiInjectedProviderDiscovery: true,
|
|
39
48
|
}
|
|
40
49
|
|
|
41
50
|
const bitcoinWalletConfig = {
|
|
42
|
-
|
|
51
|
+
// TODO: Add config for mezo mainnet
|
|
52
|
+
rpcUrl: RPC_BY_NETWORK.testnet.http,
|
|
43
53
|
chainId: CHAIN_ID.testnet,
|
|
44
54
|
}
|
|
45
55
|
|
|
@@ -70,3 +80,14 @@ export function getConfig({
|
|
|
70
80
|
...restParameters,
|
|
71
81
|
})
|
|
72
82
|
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* This config is only used to listen for Transfer events on mezo chain.
|
|
86
|
+
* Should not be exported in index for public use.
|
|
87
|
+
*/
|
|
88
|
+
export const simpleWssMezoConfig = createConfig({
|
|
89
|
+
chains: [mezoTestnet],
|
|
90
|
+
transports: {
|
|
91
|
+
[mezoTestnet.id]: webSocket(RPC_BY_NETWORK.testnet.wss),
|
|
92
|
+
},
|
|
93
|
+
})
|
package/src/constants.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { mezoTestnet } from "@mezo-org/orangekit"
|
|
2
2
|
|
|
3
|
-
export {
|
|
3
|
+
export { mezoTestnet } from "@mezo-org/orangekit"
|
|
4
4
|
|
|
5
5
|
export const CHAIN_ID = {
|
|
6
|
-
testnet:
|
|
6
|
+
testnet: mezoTestnet.id,
|
|
7
|
+
mainnet: undefined,
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
export const RPC_BY_NETWORK = {
|
|
10
|
-
testnet:
|
|
11
|
+
testnet: {
|
|
12
|
+
http: mezoTestnet.rpcUrls.default.http[0],
|
|
13
|
+
wss: mezoTestnet.rpcUrls.default.wss[0],
|
|
14
|
+
},
|
|
11
15
|
}
|
package/src/hooks/constants.ts
CHANGED
package/src/hooks/index.ts
CHANGED
|
@@ -6,13 +6,19 @@ export {
|
|
|
6
6
|
useSubscribeToConnectorEvent,
|
|
7
7
|
useSubscribeToWalletNetworkDoesNotMatchProviderChain,
|
|
8
8
|
} from "@mezo-org/orangekit"
|
|
9
|
-
export
|
|
9
|
+
export { useInvalidateBorrowData, useResetBorrowData } from "./useBorrowData"
|
|
10
10
|
export * from "./useGetAccountByAddress"
|
|
11
11
|
export * from "./useGetAccountByMezoId"
|
|
12
12
|
export * from "./useGetCurrentAccount"
|
|
13
13
|
export * from "./useGetSession"
|
|
14
14
|
export * from "./useLinkAccount"
|
|
15
|
+
export * from "./useRefreshPassport"
|
|
15
16
|
export * from "./useSignInWithDiscord"
|
|
16
17
|
export * from "./useSignInWithWallet"
|
|
17
18
|
export * from "./useSignOut"
|
|
19
|
+
export * from "./useSignUpWithWallet"
|
|
20
|
+
export {
|
|
21
|
+
useInvalidateTokensBalances,
|
|
22
|
+
useResetTokensBalances,
|
|
23
|
+
} from "./useTokensBalances"
|
|
18
24
|
export * from "./useUpdateMezoId"
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
usd: Record<"btc" | "eth" | "t", number>
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default function useAssetsConversionRates(
|
|
11
|
+
useQueryOptions: Partial<UseBaseQueryOptions<AssetsUsdConversion>> = {},
|
|
12
|
+
) {
|
|
13
|
+
const portalApiClient = usePortalApiClient()
|
|
14
|
+
|
|
15
|
+
return useQuery({
|
|
16
|
+
queryKey: [QUERY_KEYS.ASSETS_USD_CONVERSION],
|
|
17
|
+
queryFn: async () => {
|
|
18
|
+
const { currentUsdPerBtc, currentUsdPerEth, currentUsdPerTToken } =
|
|
19
|
+
await portalApiClient.getPortalStatistics()
|
|
20
|
+
return {
|
|
21
|
+
usd: {
|
|
22
|
+
btc: Number(currentUsdPerBtc),
|
|
23
|
+
eth: Number(currentUsdPerEth),
|
|
24
|
+
t: Number(currentUsdPerTToken),
|
|
25
|
+
},
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
staleTime: 30 * ONE_MINUTE_MS,
|
|
29
|
+
retry: 1,
|
|
30
|
+
...useQueryOptions,
|
|
31
|
+
})
|
|
32
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { useSignMessage } from "wagmi"
|
|
2
|
+
import { MutationOptions, useMutation } from "@tanstack/react-query"
|
|
3
|
+
import { useCreateAccount } from "./useCreateAccount"
|
|
4
|
+
import { useCreateSession } from "./useCreateSession"
|
|
5
|
+
import { useEnsureNoSessionAndFetchNonce } from "./useEnsureNoSessionAndFetchNonce"
|
|
6
|
+
import { createSignInWithWalletMessage } from "../utils/siww"
|
|
7
|
+
import { useGetAccountByAddress } from "./useGetAccountByAddress"
|
|
8
|
+
import type { Session } from "../api"
|
|
9
|
+
import useWalletAccount from "./useWalletAccount"
|
|
10
|
+
|
|
11
|
+
function useAuthenticateWithWallet(
|
|
12
|
+
shouldCreateAccount = false,
|
|
13
|
+
mutationOptions: Omit<
|
|
14
|
+
MutationOptions<Session>,
|
|
15
|
+
"mutationFn" | "mutationKey"
|
|
16
|
+
> = {},
|
|
17
|
+
) {
|
|
18
|
+
const { walletAddress, chainId, connector, networkFamily } =
|
|
19
|
+
useWalletAccount()
|
|
20
|
+
const { ensureNoSessionAndFetchNonce } = useEnsureNoSessionAndFetchNonce()
|
|
21
|
+
const { createSessionAsync } = useCreateSession()
|
|
22
|
+
const { createAccountAsync } = useCreateAccount()
|
|
23
|
+
const { signMessageAsync } = useSignMessage()
|
|
24
|
+
|
|
25
|
+
const { refetch: getAccountByAddress } = useGetAccountByAddress(
|
|
26
|
+
walletAddress,
|
|
27
|
+
{
|
|
28
|
+
enabled: false,
|
|
29
|
+
retry: false,
|
|
30
|
+
},
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
const { mutate, mutateAsync, ...signInMutationRestParameters } = useMutation({
|
|
34
|
+
mutationFn: async () => {
|
|
35
|
+
if (!walletAddress) {
|
|
36
|
+
throw new Error("Sign in error: Wallet not connected!")
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const nonce = await ensureNoSessionAndFetchNonce()
|
|
40
|
+
|
|
41
|
+
const messageResult = createSignInWithWalletMessage(
|
|
42
|
+
walletAddress,
|
|
43
|
+
nonce,
|
|
44
|
+
networkFamily,
|
|
45
|
+
chainId,
|
|
46
|
+
)
|
|
47
|
+
const signatureResult = await signMessageAsync({
|
|
48
|
+
message: messageResult,
|
|
49
|
+
connector,
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
if (shouldCreateAccount) {
|
|
53
|
+
const getAccountByAddressResult = await getAccountByAddress()
|
|
54
|
+
|
|
55
|
+
if (getAccountByAddressResult.data) {
|
|
56
|
+
throw new Error(
|
|
57
|
+
"Wallet authentication failed: Account creation failed. Account already exists.",
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (getAccountByAddressResult.error) {
|
|
62
|
+
throw new Error(
|
|
63
|
+
`Wallet authentication failed: Account creation failed. Could not verify if account already exists: ${getAccountByAddressResult.error}`,
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Fetch was successful, but no account was found
|
|
68
|
+
try {
|
|
69
|
+
const createAccountResult = await createAccountAsync({
|
|
70
|
+
type: "wallet",
|
|
71
|
+
message: messageResult,
|
|
72
|
+
signature: signatureResult,
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
if (!createAccountResult) {
|
|
76
|
+
throw new Error("Failed to create new account")
|
|
77
|
+
}
|
|
78
|
+
} catch (error) {
|
|
79
|
+
throw new Error(
|
|
80
|
+
`Wallet authentication failed: Account creation failed: ${error}`,
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return (await createSessionAsync({
|
|
86
|
+
type: "wallet",
|
|
87
|
+
message: messageResult,
|
|
88
|
+
signature: signatureResult,
|
|
89
|
+
})) as Session
|
|
90
|
+
// ^ By passing type: "wallet" we know for sure the return type is Session
|
|
91
|
+
},
|
|
92
|
+
...mutationOptions,
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
authenticateWithWallet: mutate,
|
|
97
|
+
authenticateWithWalletAsync: mutateAsync,
|
|
98
|
+
...signInMutationRestParameters,
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export { useAuthenticateWithWallet }
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { useAccount, useReadContract } from "wagmi"
|
|
2
|
+
import { useCallback, useMemo } from "react"
|
|
3
|
+
import { useQueryClient } from "@tanstack/react-query"
|
|
4
|
+
import { ONE_MINUTE_MS } from "../utils/time"
|
|
5
|
+
import {
|
|
6
|
+
mainnetBorrowContracts,
|
|
7
|
+
testnetBorrowContracts,
|
|
8
|
+
} from "../lib/contracts"
|
|
9
|
+
import { usePassportContext } from "./usePassportContext"
|
|
10
|
+
import { CHAIN_ID } from "../constants"
|
|
11
|
+
|
|
12
|
+
// Wagmi handles typesafety with ABI const assertions. TypeScript doesn't
|
|
13
|
+
// support importing JSON as const yet so types cannot be inferred from the
|
|
14
|
+
// imported contract. As a workaround there is minimal ABI definition that can
|
|
15
|
+
// be asserted types from.
|
|
16
|
+
// Ref: https://wagmi.sh/core/typescript#const-assert-abis-typed-data
|
|
17
|
+
|
|
18
|
+
const TROVE_MANAGER_ABI = [
|
|
19
|
+
{
|
|
20
|
+
inputs: [
|
|
21
|
+
{
|
|
22
|
+
internalType: "address",
|
|
23
|
+
name: "_borrower",
|
|
24
|
+
type: "address",
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
name: "getEntireDebtAndColl",
|
|
28
|
+
outputs: [
|
|
29
|
+
{
|
|
30
|
+
internalType: "uint256",
|
|
31
|
+
name: "coll",
|
|
32
|
+
type: "uint256",
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
internalType: "uint256",
|
|
36
|
+
name: "principal",
|
|
37
|
+
type: "uint256",
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
internalType: "uint256",
|
|
41
|
+
name: "interest",
|
|
42
|
+
type: "uint256",
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
internalType: "uint256",
|
|
46
|
+
name: "pendingCollateral",
|
|
47
|
+
type: "uint256",
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
internalType: "uint256",
|
|
51
|
+
name: "pendingPrincipal",
|
|
52
|
+
type: "uint256",
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
internalType: "uint256",
|
|
56
|
+
name: "pendingInterest",
|
|
57
|
+
type: "uint256",
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
stateMutability: "view",
|
|
61
|
+
type: "function",
|
|
62
|
+
},
|
|
63
|
+
] as const
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Query hook for getting borrow data. Returns collateral and trove debt for the
|
|
67
|
+
* connected account, based on it's evm address.
|
|
68
|
+
* @param queryOptions Query options passed to the underlying `useQuery` hook.
|
|
69
|
+
*/
|
|
70
|
+
export function useBorrowData(queryOptions = {}) {
|
|
71
|
+
const { environment = "mainnet" } = usePassportContext()
|
|
72
|
+
const { address } = useAccount()
|
|
73
|
+
|
|
74
|
+
const contractAddress = useMemo(() => {
|
|
75
|
+
if (environment === "mainnet") {
|
|
76
|
+
return mainnetBorrowContracts.TroveManager.address
|
|
77
|
+
}
|
|
78
|
+
return testnetBorrowContracts.TroveManager.address
|
|
79
|
+
}, [environment])
|
|
80
|
+
|
|
81
|
+
return useReadContract({
|
|
82
|
+
abi: TROVE_MANAGER_ABI,
|
|
83
|
+
address: contractAddress,
|
|
84
|
+
functionName: "getEntireDebtAndColl",
|
|
85
|
+
args: [address || "0x"],
|
|
86
|
+
query: {
|
|
87
|
+
enabled: !!address,
|
|
88
|
+
staleTime: 5 * ONE_MINUTE_MS,
|
|
89
|
+
retry: 1,
|
|
90
|
+
select: (data) => {
|
|
91
|
+
if (!data) return undefined
|
|
92
|
+
|
|
93
|
+
const [collateral, principal, interest] = data
|
|
94
|
+
return {
|
|
95
|
+
collateral,
|
|
96
|
+
troveDebt: principal + interest,
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
...queryOptions,
|
|
100
|
+
},
|
|
101
|
+
chainId: CHAIN_ID[environment],
|
|
102
|
+
})
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Hook for for invalidating current user's borrow data. Can be used to
|
|
107
|
+
* invalidate borrow data manually, which forces the data to be re-fetched.
|
|
108
|
+
* @returns Function `invalidateBorrowData` for invalidating the borrow data
|
|
109
|
+
*/
|
|
110
|
+
export function useInvalidateBorrowData() {
|
|
111
|
+
const queryClient = useQueryClient()
|
|
112
|
+
|
|
113
|
+
const { queryKey } = useBorrowData()
|
|
114
|
+
|
|
115
|
+
const invalidateBorrowDataHandler = useCallback(
|
|
116
|
+
() => queryClient.invalidateQueries({ queryKey }),
|
|
117
|
+
[queryClient, queryKey],
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
return {
|
|
121
|
+
invalidateBorrowData: invalidateBorrowDataHandler,
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Hook for for resetting current user's borrow data. Can be used to reset
|
|
127
|
+
* borrow data manually, which forces the data to be re-fetched.
|
|
128
|
+
* @returns Function `resetBorrowData` for resetting the borrow data
|
|
129
|
+
*/
|
|
130
|
+
export function useResetBorrowData() {
|
|
131
|
+
const queryClient = useQueryClient()
|
|
132
|
+
|
|
133
|
+
const { queryKey } = useBorrowData()
|
|
134
|
+
|
|
135
|
+
const resetBorrowDataHandler = useCallback(
|
|
136
|
+
() => queryClient.resetQueries({ queryKey }),
|
|
137
|
+
[queryClient, queryKey],
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
return {
|
|
141
|
+
resetBorrowData: resetBorrowDataHandler,
|
|
142
|
+
}
|
|
143
|
+
}
|
|
@@ -1,21 +1,35 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
useQueryClient,
|
|
3
|
+
useMutation,
|
|
4
|
+
MutationOptions,
|
|
5
|
+
DefaultError,
|
|
6
|
+
} from "@tanstack/react-query"
|
|
2
7
|
import { useAuthApiClient } from "./useAuthApiClient"
|
|
3
8
|
import { QUERY_KEYS } from "./constants"
|
|
4
|
-
import { CreateAccountRequest } from "../api
|
|
9
|
+
import type { CreateAccountRequest, CreateAccountResponse } from "../api"
|
|
5
10
|
|
|
6
|
-
export function useCreateAccount(
|
|
11
|
+
export function useCreateAccount(
|
|
12
|
+
mutationOptions: Omit<
|
|
13
|
+
MutationOptions<CreateAccountResponse, DefaultError, CreateAccountRequest>,
|
|
14
|
+
"mutationFn" | "mutationKey"
|
|
15
|
+
> = {},
|
|
16
|
+
) {
|
|
7
17
|
const queryClient = useQueryClient()
|
|
8
18
|
const authApiClient = useAuthApiClient()
|
|
9
19
|
|
|
20
|
+
const { onSuccess: customOnSuccess, ...restMutationOptions } = mutationOptions
|
|
21
|
+
|
|
10
22
|
const { mutate, mutateAsync, ...rest } = useMutation({
|
|
11
23
|
mutationFn: (createAccountRequest: CreateAccountRequest) =>
|
|
12
24
|
authApiClient.createAccount(createAccountRequest),
|
|
13
|
-
onSuccess: () => {
|
|
25
|
+
onSuccess: (data, variables, context) => {
|
|
14
26
|
queryClient.resetQueries({
|
|
15
27
|
queryKey: [QUERY_KEYS.ACCOUNT],
|
|
16
28
|
})
|
|
29
|
+
|
|
30
|
+
if (customOnSuccess) customOnSuccess(data, variables, context)
|
|
17
31
|
},
|
|
18
|
-
...
|
|
32
|
+
...restMutationOptions,
|
|
19
33
|
})
|
|
20
34
|
|
|
21
35
|
return { createAccount: mutate, createAccountAsync: mutateAsync, ...rest }
|