@mezo-org/passport 0.4.0-dev.9 → 0.5.1-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +4 -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 +9 -6
- package/dist/src/components/Dropdown/Dropdown.d.ts.map +1 -1
- package/dist/src/components/Dropdown/Dropdown.js +10 -10
- package/dist/src/components/Dropdown/Dropdown.js.map +1 -1
- package/dist/src/components/Dropdown/ListingItem.d.ts +14 -0
- package/dist/src/components/Dropdown/ListingItem.d.ts.map +1 -0
- package/dist/src/components/Dropdown/ListingItem.js +42 -0
- package/dist/src/components/Dropdown/ListingItem.js.map +1 -0
- package/dist/src/components/Dropdown/NestedViewLayout.d.ts +8 -0
- package/dist/src/components/Dropdown/NestedViewLayout.d.ts.map +1 -0
- package/dist/src/components/Dropdown/NestedViewLayout.js +32 -0
- package/dist/src/components/Dropdown/NestedViewLayout.js.map +1 -0
- package/dist/src/components/Dropdown/Receive/Receive.d.ts +4 -0
- package/dist/src/components/Dropdown/Receive/Receive.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Receive/Receive.js +64 -0
- package/dist/src/components/Dropdown/Receive/Receive.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts +4 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.js +49 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountBalance.d.ts +6 -0
- package/dist/src/components/Dropdown/Root/AccountBalance.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountBalance.js +35 -0
- package/dist/src/components/Dropdown/Root/AccountBalance.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountBtcListing.d.ts +6 -0
- package/dist/src/components/Dropdown/Root/AccountBtcListing.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountBtcListing.js +27 -0
- package/dist/src/components/Dropdown/Root/AccountBtcListing.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountError.d.ts +8 -0
- package/dist/src/components/Dropdown/Root/AccountError.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountError.js +17 -0
- package/dist/src/components/Dropdown/Root/AccountError.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountMusdListing.d.ts +4 -0
- package/dist/src/components/Dropdown/Root/AccountMusdListing.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountMusdListing.js +21 -0
- package/dist/src/components/Dropdown/Root/AccountMusdListing.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts +8 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.js +43 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.js.map +1 -0
- package/dist/src/components/Dropdown/Root/Root.d.ts +8 -0
- package/dist/src/components/Dropdown/Root/Root.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/Root.js +45 -0
- package/dist/src/components/Dropdown/Root/Root.js.map +1 -0
- package/dist/src/components/Dropdown/Root/WalletAddress.d.ts +4 -0
- package/dist/src/components/Dropdown/Root/WalletAddress.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/WalletAddress.js +66 -0
- package/dist/src/components/Dropdown/Root/WalletAddress.js.map +1 -0
- package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts +6 -0
- package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/WelcomeBlock.js +88 -0
- package/dist/src/components/Dropdown/Root/WelcomeBlock.js.map +1 -0
- package/dist/src/components/Dropdown/SlotNumber.d.ts +19 -0
- package/dist/src/components/Dropdown/SlotNumber.d.ts.map +1 -0
- package/dist/src/components/Dropdown/SlotNumber.js +67 -0
- package/dist/src/components/Dropdown/SlotNumber.js.map +1 -0
- package/dist/src/components/Dropdown/TestnetTopBanner.d.ts +3 -0
- package/dist/src/components/Dropdown/TestnetTopBanner.d.ts.map +1 -0
- package/dist/src/components/Dropdown/TestnetTopBanner.js +14 -0
- package/dist/src/components/Dropdown/TestnetTopBanner.js.map +1 -0
- package/dist/src/config.d.ts +19 -5
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +58 -14
- package/dist/src/config.js.map +1 -1
- package/dist/src/constants.d.ts +11 -3
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +12 -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 +18 -0
- package/dist/src/hooks/useAssetsConversionRates.d.ts.map +1 -0
- package/dist/src/hooks/useAssetsConversionRates.js +67 -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 +9 -8
- package/dist/src/hooks/useAuthenticateWithWallet.js.map +1 -1
- package/dist/src/hooks/useBorrowData.d.ts +108 -0
- package/dist/src/hooks/useBorrowData.d.ts.map +1 -0
- package/dist/src/hooks/useBorrowData.js +201 -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/useGetCurrentAccount.d.ts.map +1 -1
- package/dist/src/hooks/useGetCurrentAccount.js +4 -6
- package/dist/src/hooks/useGetCurrentAccount.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 +75 -0
- package/dist/src/hooks/useTokensBalances.d.ts.map +1 -0
- package/dist/src/hooks/useTokensBalances.js +181 -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 +20 -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 +66 -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.d.ts +7 -1
- package/dist/src/provider.d.ts.map +1 -1
- package/dist/src/provider.js +4 -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/assets.d.ts +145 -0
- package/dist/src/utils/assets.d.ts.map +1 -0
- package/dist/src/utils/assets.js +100 -0
- package/dist/src/utils/assets.js.map +1 -0
- package/dist/src/utils/assets.test.d.ts +2 -0
- package/dist/src/utils/assets.test.d.ts.map +1 -0
- package/dist/src/utils/assets.test.js +46 -0
- package/dist/src/utils/assets.test.js.map +1 -0
- package/dist/src/utils/currency.d.ts +13 -2
- package/dist/src/utils/currency.d.ts.map +1 -1
- package/dist/src/utils/currency.js +22 -8
- package/dist/src/utils/currency.js.map +1 -1
- package/dist/src/utils/currency.test.js +44 -1
- 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/number2.d.ts +106 -0
- package/dist/src/utils/number2.d.ts.map +1 -0
- package/dist/src/utils/number2.js +289 -0
- package/dist/src/utils/number2.js.map +1 -0
- package/dist/src/utils/numbers.d.ts +15 -33
- package/dist/src/utils/numbers.d.ts.map +1 -1
- package/dist/src/utils/numbers.js +26 -70
- package/dist/src/utils/numbers.js.map +1 -1
- package/dist/src/utils/numbers.test.js +46 -42
- 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 +11 -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 +26 -121
- package/src/components/Dropdown/DisconnectedTrigger.tsx +2 -1
- package/src/components/Dropdown/Dropdown.tsx +29 -17
- package/src/components/Dropdown/ListingItem.tsx +176 -0
- package/src/components/Dropdown/NestedViewLayout.tsx +87 -0
- package/src/components/Dropdown/README.md +10 -18
- package/src/components/Dropdown/Receive/Receive.tsx +144 -0
- package/src/components/Dropdown/Root/AccountAddressActions.tsx +99 -0
- package/src/components/Dropdown/Root/AccountBalance.tsx +75 -0
- package/src/components/Dropdown/Root/AccountBtcListing.tsx +52 -0
- package/src/components/Dropdown/Root/AccountError.tsx +34 -0
- package/src/components/Dropdown/Root/AccountMusdListing.tsx +45 -0
- package/src/components/Dropdown/Root/AccountOtherAssets.tsx +85 -0
- package/src/components/Dropdown/Root/Root.tsx +77 -0
- package/src/components/Dropdown/Root/WalletAddress.tsx +123 -0
- package/src/components/Dropdown/Root/WelcomeBlock.tsx +173 -0
- package/src/components/Dropdown/SlotNumber.tsx +131 -0
- package/src/components/Dropdown/TestnetTopBanner.tsx +32 -0
- package/src/config.ts +88 -20
- package/src/constants.ts +12 -4
- package/src/hooks/index.ts +7 -0
- package/src/hooks/useAssetsConversionRates.ts +79 -0
- package/src/hooks/useAuthenticateWithWallet.ts +30 -14
- package/src/hooks/useBorrowData.ts +246 -0
- package/src/hooks/useCreateAccount.ts +29 -2
- package/src/hooks/useGetCurrentAccount.ts +5 -7
- package/src/hooks/useLinkAccount.ts +37 -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 +265 -0
- package/src/hooks/useValidateMezoId.ts +31 -0
- package/src/hooks/useWalletAccount.ts +32 -20
- package/src/hooks/useWatchTransferEvents.ts +74 -0
- package/src/index.ts +12 -1
- package/src/lib/contracts/index.ts +99 -0
- package/src/lib/contracts/priceOracle.ts +53 -0
- package/src/provider.ts +11 -3
- 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/assets.test.ts +57 -0
- package/src/utils/assets.ts +103 -0
- package/src/utils/currency.test.ts +77 -1
- package/src/utils/currency.ts +35 -9
- package/src/utils/mezoId.ts +51 -0
- package/src/utils/number2.ts +419 -0
- package/src/utils/numbers.test.ts +49 -42
- package/src/utils/numbers.ts +33 -95
- 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 +0 -58
- 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 +0 -7
- 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 +0 -8
- package/dist/src/components/Dropdown/WelcomeBlock.d.ts.map +0 -1
- package/dist/src/components/Dropdown/WelcomeBlock.js +0 -44
- 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/dist/src/hooks/useDropdownData.d.ts +0 -44
- package/dist/src/hooks/useDropdownData.d.ts.map +0 -1
- package/dist/src/hooks/useDropdownData.js +0 -73
- package/dist/src/hooks/useDropdownData.js.map +0 -1
- package/dist/src/utils/cryptoAssets.d.ts +0 -28
- package/dist/src/utils/cryptoAssets.d.ts.map +0 -1
- package/dist/src/utils/cryptoAssets.js +0 -73
- package/dist/src/utils/cryptoAssets.js.map +0 -1
- package/dist/src/utils/cryptoAssets.test.d.ts +0 -2
- package/dist/src/utils/cryptoAssets.test.d.ts.map +0 -1
- package/dist/src/utils/cryptoAssets.test.js +0 -49
- package/dist/src/utils/cryptoAssets.test.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/components/Dropdown/WelcomeBlock.tsx +0 -92
- package/src/hooks/useAssetsUSDConversion.ts +0 -31
- package/src/hooks/useDropdownData.ts +0 -130
- package/src/utils/cryptoAssets.test.ts +0 -59
- package/src/utils/cryptoAssets.ts +0 -93
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { useConfig } from "wagmi"
|
|
2
|
+
import { Abi, formatUnits } from "viem"
|
|
3
|
+
import {
|
|
4
|
+
useQuery,
|
|
5
|
+
useQueryClient,
|
|
6
|
+
UseQueryOptions,
|
|
7
|
+
} from "@tanstack/react-query"
|
|
8
|
+
import { getBalance, readContracts } from "wagmi/actions"
|
|
9
|
+
import {
|
|
10
|
+
mainnetTokenContracts,
|
|
11
|
+
MezoChainToken,
|
|
12
|
+
testnetTokenContracts,
|
|
13
|
+
} from "../lib/contracts"
|
|
14
|
+
import useWalletAccount from "./useWalletAccount"
|
|
15
|
+
import {
|
|
16
|
+
getAsset,
|
|
17
|
+
isBitcoinLikeCryptoAsset,
|
|
18
|
+
isTTokenCryptoAsset,
|
|
19
|
+
} from "../utils/assets"
|
|
20
|
+
import { convertToUsd } from "../utils/currency"
|
|
21
|
+
import { CHAIN_ID } from "../constants"
|
|
22
|
+
import { useAssetsConversionRates } from "./useAssetsConversionRates"
|
|
23
|
+
import { normalizePrecision } from "../utils/numbers"
|
|
24
|
+
|
|
25
|
+
// Wagmi handles typesafety with ABI const assertions. TypeScript doesn't
|
|
26
|
+
// support importing JSON as const yet so types cannot be inferred from the
|
|
27
|
+
// imported contract. As a workaround there is minimal ABI definition that can
|
|
28
|
+
// be asserted types from.
|
|
29
|
+
// Ref: https://wagmi.sh/core/typescript#const-assert-abis-typed-data
|
|
30
|
+
|
|
31
|
+
export const BALANCE_OF_ABI = [
|
|
32
|
+
{
|
|
33
|
+
inputs: [
|
|
34
|
+
{
|
|
35
|
+
internalType: "address",
|
|
36
|
+
name: "account",
|
|
37
|
+
type: "address",
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
name: "balanceOf",
|
|
41
|
+
outputs: [
|
|
42
|
+
{
|
|
43
|
+
internalType: "uint256",
|
|
44
|
+
name: "",
|
|
45
|
+
type: "uint256",
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
stateMutability: "view",
|
|
49
|
+
type: "function",
|
|
50
|
+
},
|
|
51
|
+
] as const satisfies Abi
|
|
52
|
+
|
|
53
|
+
const BALANCE_TOKENS: MezoChainToken[] = [
|
|
54
|
+
"mcbBTC",
|
|
55
|
+
"mDAI",
|
|
56
|
+
"mFBTC",
|
|
57
|
+
"mSolvBTC",
|
|
58
|
+
"mswBTC",
|
|
59
|
+
"mT",
|
|
60
|
+
"mUSDC",
|
|
61
|
+
"mUSDe",
|
|
62
|
+
"mUSDT",
|
|
63
|
+
"mxSolvBTC",
|
|
64
|
+
"MUSD",
|
|
65
|
+
]
|
|
66
|
+
|
|
67
|
+
type UseMezoChainTokensBalancesOptions<T extends MezoChainToken[]> = {
|
|
68
|
+
tokens?: T
|
|
69
|
+
queryOptions?: Omit<
|
|
70
|
+
UseQueryOptions<Record<T[number], TokenBalance>>,
|
|
71
|
+
"queryKey" | "queryFn" | "select" | "enabled"
|
|
72
|
+
>
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export type TokenBalance = {
|
|
76
|
+
decimals: number
|
|
77
|
+
formatted: string
|
|
78
|
+
symbol: string
|
|
79
|
+
value: bigint
|
|
80
|
+
usd: {
|
|
81
|
+
value: bigint
|
|
82
|
+
formatted: string
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const TOKEN_BALANCES_QUERY_KEY = "passport.tokenBalances"
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Hook to get the balance of a list of tokens for the current account
|
|
90
|
+
* @param options.tokens The list of tokens to get the balance for. It will
|
|
91
|
+
* fallback to all tokens if not provided.
|
|
92
|
+
* @param options.queryOptions The query options to pass to the
|
|
93
|
+
* `useReadContracts`
|
|
94
|
+
* @returns Tanstack's `useQuery` returnings with balance of tokens for the
|
|
95
|
+
* current account in form of typesafe object with token names as keys
|
|
96
|
+
* and balances as values.
|
|
97
|
+
* @example
|
|
98
|
+
* const mezoTokensBalance = useTokensBalances({
|
|
99
|
+
* tokens: ["mT", "mxSolvBTC"],
|
|
100
|
+
* })
|
|
101
|
+
* // Assuming the status is "success"
|
|
102
|
+
* console.log(mezoTokensBalance.data.mT) // Eg. { value: 0n ... }
|
|
103
|
+
* console.log(Object.keys(mezoTokensBalance.data)) // ["mT", "mxSolvBTC"]
|
|
104
|
+
*/
|
|
105
|
+
export function useTokensBalances<T extends MezoChainToken[]>(
|
|
106
|
+
options: UseMezoChainTokensBalancesOptions<T> = {},
|
|
107
|
+
) {
|
|
108
|
+
const { tokens = BALANCE_TOKENS, ...restQueryOptions } = options
|
|
109
|
+
|
|
110
|
+
const walletAccount = useWalletAccount()
|
|
111
|
+
|
|
112
|
+
const config = useConfig()
|
|
113
|
+
|
|
114
|
+
const { data: conversionRatesData } = useAssetsConversionRates()
|
|
115
|
+
|
|
116
|
+
return useQuery({
|
|
117
|
+
queryKey: [
|
|
118
|
+
TOKEN_BALANCES_QUERY_KEY,
|
|
119
|
+
walletAccount?.accountAddress,
|
|
120
|
+
options.tokens,
|
|
121
|
+
],
|
|
122
|
+
enabled: !!walletAccount?.accountAddress && !!conversionRatesData,
|
|
123
|
+
queryFn: async () => {
|
|
124
|
+
const isMainnet = config.state.chainId === CHAIN_ID.mainnet
|
|
125
|
+
const contractsMap = isMainnet
|
|
126
|
+
? mainnetTokenContracts
|
|
127
|
+
: testnetTokenContracts
|
|
128
|
+
|
|
129
|
+
const accountAddress = walletAccount?.accountAddress
|
|
130
|
+
|
|
131
|
+
if (!accountAddress) {
|
|
132
|
+
throw new Error("Account address is not available.")
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const tokenContracts = tokens.map((token) => {
|
|
136
|
+
const { address } = contractsMap[token]
|
|
137
|
+
return {
|
|
138
|
+
address,
|
|
139
|
+
abi: BALANCE_OF_ABI,
|
|
140
|
+
functionName: "balanceOf" as const,
|
|
141
|
+
args: [accountAddress],
|
|
142
|
+
chainId: config.state.chainId,
|
|
143
|
+
}
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
return Promise.all([
|
|
147
|
+
getBalance(config, { address: accountAddress }),
|
|
148
|
+
readContracts(config, {
|
|
149
|
+
contracts: tokenContracts,
|
|
150
|
+
}),
|
|
151
|
+
])
|
|
152
|
+
},
|
|
153
|
+
select: (data) => {
|
|
154
|
+
const [btcBalance, tokensBalancesData] = data
|
|
155
|
+
if (!conversionRatesData) {
|
|
156
|
+
throw new Error("Conversion rates data is not available.")
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const parsedBtcBalance = {
|
|
160
|
+
...btcBalance,
|
|
161
|
+
symbol: getAsset("BTC").symbol,
|
|
162
|
+
usd: convertToUsd(
|
|
163
|
+
btcBalance.value,
|
|
164
|
+
btcBalance.decimals,
|
|
165
|
+
conversionRatesData.rates.BTC,
|
|
166
|
+
conversionRatesData.decimals,
|
|
167
|
+
),
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const parsedTokensBalances = tokensBalancesData.map((item, index) => {
|
|
171
|
+
const token = tokens[index]
|
|
172
|
+
const { decimals, symbol } = getAsset(token)
|
|
173
|
+
|
|
174
|
+
if (item.status === "failure") {
|
|
175
|
+
throw new Error(
|
|
176
|
+
`Failed to fetch balance of ${token} for ${walletAccount?.accountAddress}.`,
|
|
177
|
+
)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const tokenBalance: Omit<TokenBalance, "usd"> = {
|
|
181
|
+
value: item.result,
|
|
182
|
+
decimals,
|
|
183
|
+
symbol,
|
|
184
|
+
formatted: formatUnits(item.result, decimals),
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
let usd = {
|
|
188
|
+
value: normalizePrecision(
|
|
189
|
+
tokenBalance.value,
|
|
190
|
+
tokenBalance.decimals,
|
|
191
|
+
conversionRatesData.decimals,
|
|
192
|
+
),
|
|
193
|
+
formatted: formatUnits(tokenBalance.value, tokenBalance.decimals),
|
|
194
|
+
}
|
|
195
|
+
if (isBitcoinLikeCryptoAsset(tokenBalance.symbol)) {
|
|
196
|
+
usd = convertToUsd(
|
|
197
|
+
tokenBalance.value,
|
|
198
|
+
tokenBalance.decimals,
|
|
199
|
+
conversionRatesData.rates.BTC,
|
|
200
|
+
conversionRatesData.decimals,
|
|
201
|
+
)
|
|
202
|
+
}
|
|
203
|
+
if (isTTokenCryptoAsset(tokenBalance.symbol)) {
|
|
204
|
+
usd = convertToUsd(
|
|
205
|
+
tokenBalance.value,
|
|
206
|
+
tokenBalance.decimals,
|
|
207
|
+
conversionRatesData.rates.mT,
|
|
208
|
+
conversionRatesData.decimals,
|
|
209
|
+
)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return { ...tokenBalance, usd }
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
return [parsedBtcBalance, ...parsedTokensBalances].reduce(
|
|
216
|
+
(acc, token) => ({
|
|
217
|
+
...acc,
|
|
218
|
+
[token.symbol]: token,
|
|
219
|
+
}),
|
|
220
|
+
{} as Record<T[number] | "BTC", TokenBalance>,
|
|
221
|
+
)
|
|
222
|
+
},
|
|
223
|
+
...restQueryOptions,
|
|
224
|
+
})
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Hook for invalidating current user's token balances. Can be used to
|
|
229
|
+
* invalidate the balances manually, which forces the data to be re-fetched.
|
|
230
|
+
* @returns Function `invalidateTokenBalances` that invalidates token balances
|
|
231
|
+
* @example
|
|
232
|
+
* const { invalidateTokenBalances } = useInvalidateTokensBalances()
|
|
233
|
+
* (...)
|
|
234
|
+
* await invalidateTokenBalances()
|
|
235
|
+
*/
|
|
236
|
+
export function useInvalidateTokensBalances() {
|
|
237
|
+
const queryClient = useQueryClient()
|
|
238
|
+
|
|
239
|
+
const invalidateTokensBalancesHandler = () =>
|
|
240
|
+
queryClient.invalidateQueries({ queryKey: [TOKEN_BALANCES_QUERY_KEY] })
|
|
241
|
+
|
|
242
|
+
return {
|
|
243
|
+
invalidateTokensBalances: invalidateTokensBalancesHandler,
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Hook for resetting current user's token balances. Can be used to reset the
|
|
249
|
+
* balances manually, which forces the data to be re-fetched.
|
|
250
|
+
* @returns Function `resetTokenBalances` that invalidates token balances
|
|
251
|
+
* @example
|
|
252
|
+
* const { resetTokenBalances } = useResetTokensBalances()
|
|
253
|
+
* (...)
|
|
254
|
+
* await resetTokenBalances()
|
|
255
|
+
*/
|
|
256
|
+
export function useResetTokensBalances() {
|
|
257
|
+
const queryClient = useQueryClient()
|
|
258
|
+
|
|
259
|
+
const resetTokenBalancesHandler = () =>
|
|
260
|
+
queryClient.resetQueries({ queryKey: [TOKEN_BALANCES_QUERY_KEY] })
|
|
261
|
+
|
|
262
|
+
return {
|
|
263
|
+
resetTokenBalances: resetTokenBalancesHandler,
|
|
264
|
+
}
|
|
265
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { UseQueryResult } from "@tanstack/react-query"
|
|
2
|
+
import { validateMezoId, MezoId } from "../utils/mezoId"
|
|
3
|
+
import { useGetAccountByMezoId } from "./useGetAccountByMezoId"
|
|
4
|
+
|
|
5
|
+
export function useValidateMezoId(mezoId: MezoId) {
|
|
6
|
+
const validationErrors = validateMezoId(mezoId)
|
|
7
|
+
|
|
8
|
+
return useGetAccountByMezoId(mezoId, {
|
|
9
|
+
placeholderData: {
|
|
10
|
+
// @ts-expect-error TODO: Couldn't fix type for placeholderData which for
|
|
11
|
+
// some reason should return the same data as the data returned in
|
|
12
|
+
// queryFn.
|
|
13
|
+
isValid: validationErrors.length === 0,
|
|
14
|
+
isAvailable: validationErrors.length === 0,
|
|
15
|
+
errors: validationErrors,
|
|
16
|
+
},
|
|
17
|
+
enabled: validationErrors.length === 0,
|
|
18
|
+
// @ts-expect-error TODO: Couldn't fix type for select which for some reason
|
|
19
|
+
// should return the same data as the data returned in queryFn.
|
|
20
|
+
select: (data) => {
|
|
21
|
+
const isValid = validationErrors.length === 0
|
|
22
|
+
const isAvailable = isValid ? !data : false
|
|
23
|
+
|
|
24
|
+
return { isValid, isAvailable, errors: validationErrors }
|
|
25
|
+
},
|
|
26
|
+
}) as UseQueryResult<{
|
|
27
|
+
isValid: boolean
|
|
28
|
+
isAvailable: boolean
|
|
29
|
+
errors: string[]
|
|
30
|
+
}>
|
|
31
|
+
}
|
|
@@ -1,41 +1,53 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { OrangeKitConnector } from "@mezo-org/orangekit"
|
|
2
|
+
import { useQuery } from "@tanstack/react-query"
|
|
3
|
+
import { useMemo } from "react"
|
|
3
4
|
import { Address } from "viem"
|
|
4
5
|
import { Connector, useAccount } from "wagmi"
|
|
5
6
|
|
|
6
7
|
type UseWalletAccountReturn = {
|
|
7
|
-
|
|
8
|
+
accountAddress?: Address
|
|
9
|
+
walletAddress?: string
|
|
8
10
|
isConnected: boolean
|
|
9
11
|
networkFamily: "bitcoin" | "evm"
|
|
10
12
|
connector?: Connector
|
|
11
13
|
chainId?: number
|
|
12
14
|
}
|
|
13
15
|
|
|
16
|
+
// TODO: Invesitgate race conditions and refactor
|
|
17
|
+
|
|
14
18
|
export default function useWalletAccount(): UseWalletAccountReturn {
|
|
15
19
|
const { address: evmAddress, connector, chainId } = useAccount()
|
|
16
|
-
const { btcAddress } = useBitcoinAccount()
|
|
17
|
-
const [isConnected, setIsConnected] = useState(false)
|
|
18
|
-
|
|
19
|
-
useEffect(() => {
|
|
20
|
-
if (!connector) {
|
|
21
|
-
setIsConnected(false)
|
|
22
|
-
return
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const isBitcoinFlow = connector.type === "orangekit"
|
|
26
|
-
setIsConnected(isBitcoinFlow ? !!btcAddress : !!evmAddress)
|
|
27
|
-
}, [btcAddress, connector, evmAddress])
|
|
28
20
|
|
|
29
21
|
const networkFamily = useMemo(
|
|
30
|
-
() => (
|
|
31
|
-
[
|
|
22
|
+
() => (connector?.type !== "orangekit" ? "evm" : "bitcoin"),
|
|
23
|
+
[connector],
|
|
32
24
|
)
|
|
33
25
|
|
|
26
|
+
const { data: btcData } = useQuery({
|
|
27
|
+
queryKey: [connector?.id],
|
|
28
|
+
queryFn: async () => {
|
|
29
|
+
const bitcoinProvider = (
|
|
30
|
+
connector as unknown as OrangeKitConnector
|
|
31
|
+
).getBitcoinProvider()
|
|
32
|
+
|
|
33
|
+
const address = await bitcoinProvider.getAddress()
|
|
34
|
+
const balance = await bitcoinProvider.getBalance()
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
address,
|
|
38
|
+
balance,
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
const { address: btcAddress } = btcData || {}
|
|
44
|
+
|
|
34
45
|
return {
|
|
35
|
-
|
|
36
|
-
|
|
46
|
+
accountAddress: evmAddress,
|
|
47
|
+
walletAddress: btcAddress ?? evmAddress,
|
|
48
|
+
isConnected: networkFamily === "bitcoin" ? !!btcAddress : !!evmAddress,
|
|
37
49
|
networkFamily,
|
|
38
50
|
connector,
|
|
39
51
|
chainId,
|
|
40
|
-
}
|
|
52
|
+
}
|
|
41
53
|
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { useMemo } from "react"
|
|
2
|
+
import { useAccount, useWatchContractEvent } from "wagmi"
|
|
3
|
+
import {
|
|
4
|
+
mainnetTokenContracts,
|
|
5
|
+
MezoChainToken,
|
|
6
|
+
testnetTokenContracts,
|
|
7
|
+
} from "../lib/contracts"
|
|
8
|
+
import { usePassportContext } from "./usePassportContext"
|
|
9
|
+
import { CHAIN_ID } from "../constants"
|
|
10
|
+
import { useRefreshPassport } from "./useRefreshPassport"
|
|
11
|
+
import { simpleWssMezoConfig } from "../config"
|
|
12
|
+
|
|
13
|
+
function useWatchTransferEvents(token: MezoChainToken) {
|
|
14
|
+
const { address: userAddress } = useAccount()
|
|
15
|
+
const { environment = "mainnet" } = usePassportContext()
|
|
16
|
+
const { refreshTokensBalances, refreshBorrowData } = useRefreshPassport()
|
|
17
|
+
|
|
18
|
+
const contract = useMemo(() => {
|
|
19
|
+
const contracts =
|
|
20
|
+
environment === "mainnet" ? mainnetTokenContracts : testnetTokenContracts
|
|
21
|
+
|
|
22
|
+
return contracts[token]
|
|
23
|
+
}, [environment, token])
|
|
24
|
+
|
|
25
|
+
useWatchContractEvent({
|
|
26
|
+
address: contract.address,
|
|
27
|
+
abi: contract.abi,
|
|
28
|
+
eventName: "Transfer",
|
|
29
|
+
args: {
|
|
30
|
+
from: userAddress,
|
|
31
|
+
},
|
|
32
|
+
chainId: CHAIN_ID[environment],
|
|
33
|
+
enabled: !!userAddress,
|
|
34
|
+
config: simpleWssMezoConfig,
|
|
35
|
+
onLogs() {
|
|
36
|
+
console.log(`[${token}] Transfer from: ${userAddress}`)
|
|
37
|
+
refreshTokensBalances()
|
|
38
|
+
refreshBorrowData()
|
|
39
|
+
},
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
useWatchContractEvent({
|
|
43
|
+
address: contract.address,
|
|
44
|
+
abi: contract.abi,
|
|
45
|
+
eventName: "Transfer",
|
|
46
|
+
args: {
|
|
47
|
+
to: userAddress,
|
|
48
|
+
},
|
|
49
|
+
chainId: CHAIN_ID[environment],
|
|
50
|
+
enabled: !!userAddress,
|
|
51
|
+
config: simpleWssMezoConfig,
|
|
52
|
+
onLogs() {
|
|
53
|
+
console.log(`[${token}] Transfer to: ${userAddress}`)
|
|
54
|
+
refreshTokensBalances()
|
|
55
|
+
refreshBorrowData()
|
|
56
|
+
},
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function useWatchTransferEventsForAllTokens() {
|
|
61
|
+
useWatchTransferEvents("mcbBTC")
|
|
62
|
+
useWatchTransferEvents("mDAI")
|
|
63
|
+
useWatchTransferEvents("mFBTC")
|
|
64
|
+
useWatchTransferEvents("mSolvBTC")
|
|
65
|
+
useWatchTransferEvents("mswBTC")
|
|
66
|
+
useWatchTransferEvents("mT")
|
|
67
|
+
useWatchTransferEvents("mUSDC")
|
|
68
|
+
useWatchTransferEvents("mUSDe")
|
|
69
|
+
useWatchTransferEvents("mUSDT")
|
|
70
|
+
useWatchTransferEvents("mxSolvBTC")
|
|
71
|
+
useWatchTransferEvents("MUSD")
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export { useWatchTransferEvents, useWatchTransferEventsForAllTokens }
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
export * from "./components"
|
|
2
|
-
export
|
|
2
|
+
export {
|
|
3
|
+
defaultConfig,
|
|
4
|
+
unisatWalletMezoMainnet,
|
|
5
|
+
unisatWalletMezoTestnet,
|
|
6
|
+
okxWalletMezoMainnet,
|
|
7
|
+
okxWalletMezoTestnet,
|
|
8
|
+
xverseWalletMezoMainnet,
|
|
9
|
+
xverseWalletMezoTestnet,
|
|
10
|
+
getDefaultWallets,
|
|
11
|
+
getConfig,
|
|
12
|
+
} from "./config"
|
|
3
13
|
export * from "./constants"
|
|
4
14
|
export * from "./hooks"
|
|
5
15
|
export * from "./provider"
|
|
6
16
|
export * from "./wallet"
|
|
17
|
+
export { DISALLOWED_MEZO_ID_PATTERNS } from "./utils/mezoId"
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import cbbtcMainnet from "@mezo-org/mezod-contracts/deployments/mainnet/mcbBTC.json"
|
|
2
|
+
import daiMainnet from "@mezo-org/mezod-contracts/deployments/mainnet/mDAI.json"
|
|
3
|
+
import fbtcMainnet from "@mezo-org/mezod-contracts/deployments/mainnet/mFBTC.json"
|
|
4
|
+
import solvbtcMainnet from "@mezo-org/mezod-contracts/deployments/mainnet/mSolvBTC.json"
|
|
5
|
+
import swbtcMainnet from "@mezo-org/mezod-contracts/deployments/mainnet/mswBTC.json"
|
|
6
|
+
import tMainnet from "@mezo-org/mezod-contracts/deployments/mainnet/mT.json"
|
|
7
|
+
import usdcMainnet from "@mezo-org/mezod-contracts/deployments/mainnet/mUSDC.json"
|
|
8
|
+
import usdeMainnet from "@mezo-org/mezod-contracts/deployments/mainnet/mUSDe.json"
|
|
9
|
+
import usdtMainnet from "@mezo-org/mezod-contracts/deployments/mainnet/mUSDT.json"
|
|
10
|
+
import xsolvbtcMainnet from "@mezo-org/mezod-contracts/deployments/mainnet/mxSolvBTC.json"
|
|
11
|
+
import musdMainnet from "@mezo-org/musd-contracts/deployments/mainnet/MUSD.json"
|
|
12
|
+
import troveManagerMainnet from "@mezo-org/musd-contracts/deployments/mainnet/TroveManager.json"
|
|
13
|
+
import borrowerOperationsMainnet from "@mezo-org/musd-contracts/deployments/mainnet/BorrowerOperations.json"
|
|
14
|
+
|
|
15
|
+
import cbbtcTestnet from "@mezo-org/mezod-contracts/deployments/testnet/mcbBTC.json"
|
|
16
|
+
import daiTestnet from "@mezo-org/mezod-contracts/deployments/testnet/mDAI.json"
|
|
17
|
+
import fbtcTestnet from "@mezo-org/mezod-contracts/deployments/testnet/mFBTC.json"
|
|
18
|
+
import solvbtcTestnet from "@mezo-org/mezod-contracts/deployments/testnet/mSolvBTC.json"
|
|
19
|
+
import swbtcTestnet from "@mezo-org/mezod-contracts/deployments/testnet/mswBTC.json"
|
|
20
|
+
import tTestnet from "@mezo-org/mezod-contracts/deployments/testnet/mT.json"
|
|
21
|
+
import usdcTestnet from "@mezo-org/mezod-contracts/deployments/testnet/mUSDC.json"
|
|
22
|
+
import usdeTestnet from "@mezo-org/mezod-contracts/deployments/testnet/mUSDe.json"
|
|
23
|
+
import usdtTestnet from "@mezo-org/mezod-contracts/deployments/testnet/mUSDT.json"
|
|
24
|
+
import xsolvbtcTestnet from "@mezo-org/mezod-contracts/deployments/testnet/mxSolvBTC.json"
|
|
25
|
+
import musdTestnet from "@mezo-org/musd-contracts/deployments/matsnet/MUSD.json"
|
|
26
|
+
import troveManagerTestnet from "@mezo-org/musd-contracts/deployments/matsnet/TroveManager.json"
|
|
27
|
+
import borrowerOperationsTestnet from "@mezo-org/musd-contracts/deployments/matsnet/BorrowerOperations.json"
|
|
28
|
+
import priceFeed from "@mezo-org/musd-contracts/deployments/mainnet/PriceFeed.json"
|
|
29
|
+
import priceFeedTestnet from "@mezo-org/musd-contracts/deployments/matsnet/PriceFeed.json"
|
|
30
|
+
|
|
31
|
+
import { Abi, Address } from "viem"
|
|
32
|
+
|
|
33
|
+
export type MezoChainToken =
|
|
34
|
+
| "mcbBTC"
|
|
35
|
+
| "mDAI"
|
|
36
|
+
| "mFBTC"
|
|
37
|
+
| "mSolvBTC"
|
|
38
|
+
| "mswBTC"
|
|
39
|
+
| "mT"
|
|
40
|
+
| "mUSDC"
|
|
41
|
+
| "mUSDe"
|
|
42
|
+
| "mUSDT"
|
|
43
|
+
| "mxSolvBTC"
|
|
44
|
+
| "MUSD"
|
|
45
|
+
|
|
46
|
+
export type MezoBorrowContract =
|
|
47
|
+
| "TroveManager"
|
|
48
|
+
| "BorrowerOperations"
|
|
49
|
+
| "PriceFeed"
|
|
50
|
+
|
|
51
|
+
type ContractsMap<K extends string> = Record<
|
|
52
|
+
K,
|
|
53
|
+
{
|
|
54
|
+
address: Address
|
|
55
|
+
abi: Abi
|
|
56
|
+
}
|
|
57
|
+
>
|
|
58
|
+
|
|
59
|
+
export const testnetTokenContracts = {
|
|
60
|
+
mcbBTC: cbbtcTestnet,
|
|
61
|
+
mDAI: daiTestnet,
|
|
62
|
+
mFBTC: fbtcTestnet,
|
|
63
|
+
mSolvBTC: solvbtcTestnet,
|
|
64
|
+
mswBTC: swbtcTestnet,
|
|
65
|
+
mT: tTestnet,
|
|
66
|
+
mUSDC: usdcTestnet,
|
|
67
|
+
mUSDe: usdeTestnet,
|
|
68
|
+
mUSDT: usdtTestnet,
|
|
69
|
+
mxSolvBTC: xsolvbtcTestnet,
|
|
70
|
+
MUSD: musdTestnet,
|
|
71
|
+
} as unknown as ContractsMap<MezoChainToken>
|
|
72
|
+
|
|
73
|
+
export const mainnetTokenContracts = {
|
|
74
|
+
mcbBTC: cbbtcMainnet,
|
|
75
|
+
mDAI: daiMainnet,
|
|
76
|
+
mFBTC: fbtcMainnet,
|
|
77
|
+
mSolvBTC: solvbtcMainnet,
|
|
78
|
+
mswBTC: swbtcMainnet,
|
|
79
|
+
mT: tMainnet,
|
|
80
|
+
mUSDC: usdcMainnet,
|
|
81
|
+
mUSDe: usdeMainnet,
|
|
82
|
+
mUSDT: usdtMainnet,
|
|
83
|
+
mxSolvBTC: xsolvbtcMainnet,
|
|
84
|
+
MUSD: musdMainnet,
|
|
85
|
+
} as unknown as ContractsMap<MezoChainToken>
|
|
86
|
+
|
|
87
|
+
export const mainnetBorrowContracts = {
|
|
88
|
+
TroveManager: troveManagerMainnet,
|
|
89
|
+
BorrowerOperations: borrowerOperationsMainnet,
|
|
90
|
+
PriceFeed: priceFeed,
|
|
91
|
+
} as unknown as ContractsMap<MezoBorrowContract>
|
|
92
|
+
|
|
93
|
+
export const testnetBorrowContracts = {
|
|
94
|
+
TroveManager: troveManagerTestnet,
|
|
95
|
+
BorrowerOperations: borrowerOperationsTestnet,
|
|
96
|
+
PriceFeed: priceFeedTestnet,
|
|
97
|
+
} as unknown as ContractsMap<MezoBorrowContract>
|
|
98
|
+
|
|
99
|
+
export { default as priceOracleContract } from "./priceOracle"
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Address } from "viem"
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
address: "0x7b7c000000000000000000000000000000000015" as Address,
|
|
5
|
+
abi: [
|
|
6
|
+
{
|
|
7
|
+
inputs: [],
|
|
8
|
+
name: "decimals",
|
|
9
|
+
outputs: [
|
|
10
|
+
{
|
|
11
|
+
internalType: "uint8",
|
|
12
|
+
name: "",
|
|
13
|
+
type: "uint8",
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
stateMutability: "view",
|
|
17
|
+
type: "function",
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
inputs: [],
|
|
21
|
+
name: "latestRoundData",
|
|
22
|
+
outputs: [
|
|
23
|
+
{
|
|
24
|
+
internalType: "uint80",
|
|
25
|
+
name: "roundId",
|
|
26
|
+
type: "uint80",
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
internalType: "int256",
|
|
30
|
+
name: "answer",
|
|
31
|
+
type: "int256",
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
internalType: "uint256",
|
|
35
|
+
name: "startedAt",
|
|
36
|
+
type: "uint256",
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
internalType: "uint256",
|
|
40
|
+
name: "updatedAt",
|
|
41
|
+
type: "uint256",
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
internalType: "uint80",
|
|
45
|
+
name: "answeredInRound",
|
|
46
|
+
type: "uint80",
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
stateMutability: "view",
|
|
50
|
+
type: "function",
|
|
51
|
+
},
|
|
52
|
+
] as const,
|
|
53
|
+
}
|
package/src/provider.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { createContext, createElement } from "react"
|
|
2
2
|
import { AuthApiClient, PortalApiClient } from "./api"
|
|
3
|
+
import { ONE_SECOND_MS } from "./utils/time"
|
|
3
4
|
|
|
4
5
|
export interface PassportContextValue {
|
|
5
6
|
authApiClient: AuthApiClient
|
|
6
7
|
portalApiClient: PortalApiClient
|
|
7
8
|
environment?: Environment
|
|
9
|
+
accountDataRefetchInterval: number
|
|
10
|
+
nativeBalanceRefetchInterval: number
|
|
8
11
|
}
|
|
9
12
|
|
|
10
13
|
export const PassportContext = createContext<PassportContextValue | undefined>(
|
|
@@ -15,12 +18,13 @@ type Environment = "mainnet" | "testnet"
|
|
|
15
18
|
|
|
16
19
|
type PassportProviderProps = {
|
|
17
20
|
children: React.ReactNode
|
|
18
|
-
// eslint-disable-next-line react/require-default-props
|
|
19
21
|
environment?: Environment
|
|
20
|
-
// eslint-disable-next-line react/require-default-props
|
|
21
22
|
authApiUrl?: string
|
|
22
|
-
// eslint-disable-next-line react/require-default-props
|
|
23
23
|
portalApiUrl?: string
|
|
24
|
+
/** Time in milliseconds after which account data (like mats or mezo id) in dropdown should be re-fetched. Default is 90000 (90 secs) */
|
|
25
|
+
accountDataRefetchInterval?: number
|
|
26
|
+
/** Time in milliseconds after which native balance in dropdown should be re-fetched. Default is 90000 (90 secs) */
|
|
27
|
+
nativeBalanceRefetchInterval?: number
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
export function PassportProvider({
|
|
@@ -28,6 +32,8 @@ export function PassportProvider({
|
|
|
28
32
|
authApiUrl,
|
|
29
33
|
portalApiUrl,
|
|
30
34
|
children,
|
|
35
|
+
accountDataRefetchInterval = 90 * ONE_SECOND_MS,
|
|
36
|
+
nativeBalanceRefetchInterval = 90 * ONE_SECOND_MS,
|
|
31
37
|
}: PassportProviderProps) {
|
|
32
38
|
if (environment && !["mainnet", "testnet"].includes(environment)) {
|
|
33
39
|
throw new Error("Wrong environment passed to PassportProvider.")
|
|
@@ -43,6 +49,8 @@ export function PassportProvider({
|
|
|
43
49
|
portalApiUrl,
|
|
44
50
|
),
|
|
45
51
|
environment,
|
|
52
|
+
accountDataRefetchInterval,
|
|
53
|
+
nativeBalanceRefetchInterval,
|
|
46
54
|
},
|
|
47
55
|
},
|
|
48
56
|
children,
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { create } from "zustand"
|
|
2
|
+
|
|
3
|
+
export enum DropdownView {
|
|
4
|
+
ROOT = "ROOT",
|
|
5
|
+
RECEIVE = "RECEIVE",
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
interface DropdownStore {
|
|
9
|
+
view: DropdownView
|
|
10
|
+
setView: (view: DropdownView) => void
|
|
11
|
+
isNestedView: () => boolean
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const useDropdownStore = create<DropdownStore>((set, get) => ({
|
|
15
|
+
view: DropdownView.ROOT,
|
|
16
|
+
setView: (view: DropdownView) => set({ view }),
|
|
17
|
+
isNestedView: () => get().view !== DropdownView.ROOT,
|
|
18
|
+
}))
|
|
19
|
+
|
|
20
|
+
export default useDropdownStore
|