@mezo-org/passport 0.4.0-dev.8 → 0.4.0-dev.80
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 +18 -5
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +45 -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 +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 +73 -20
- package/src/constants.ts +12 -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 +12 -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,187 @@
|
|
|
1
|
+
import { useReadContracts } from "wagmi"
|
|
2
|
+
import { useCallback, useMemo } from "react"
|
|
3
|
+
import { Abi } from "viem"
|
|
4
|
+
import { useQueryClient } from "@tanstack/react-query"
|
|
5
|
+
import { usePassportContext } from "./usePassportContext"
|
|
6
|
+
import {
|
|
7
|
+
mainnetTokenContracts,
|
|
8
|
+
testnetTokenContracts,
|
|
9
|
+
MezoChainToken,
|
|
10
|
+
} from "../lib/contracts"
|
|
11
|
+
import useWalletAccount from "./useWalletAccount"
|
|
12
|
+
import { CHAIN_ID } from "../constants"
|
|
13
|
+
|
|
14
|
+
// Wagmi handles typesafety with ABI const assertions. TypeScript doesn't
|
|
15
|
+
// support importing JSON as const yet so types cannot be inferred from the
|
|
16
|
+
// imported contract. As a workaround there is minimal ABI definition that can
|
|
17
|
+
// be asserted types from.
|
|
18
|
+
// Ref: https://wagmi.sh/core/typescript#const-assert-abis-typed-data
|
|
19
|
+
|
|
20
|
+
const BALANCE_OF_ABI = [
|
|
21
|
+
{
|
|
22
|
+
inputs: [
|
|
23
|
+
{
|
|
24
|
+
internalType: "address",
|
|
25
|
+
name: "account",
|
|
26
|
+
type: "address",
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
name: "balanceOf",
|
|
30
|
+
outputs: [
|
|
31
|
+
{
|
|
32
|
+
internalType: "uint256",
|
|
33
|
+
name: "",
|
|
34
|
+
type: "uint256",
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
stateMutability: "view",
|
|
38
|
+
type: "function",
|
|
39
|
+
},
|
|
40
|
+
] as const satisfies Abi
|
|
41
|
+
|
|
42
|
+
const BALANCE_TOKENS: MezoChainToken[] = [
|
|
43
|
+
"mcbBTC",
|
|
44
|
+
"mDAI",
|
|
45
|
+
"mFBTC",
|
|
46
|
+
"mSolvBTC",
|
|
47
|
+
"mswBTC",
|
|
48
|
+
"mT",
|
|
49
|
+
"mUSDC",
|
|
50
|
+
"mUSDe",
|
|
51
|
+
"mUSDT",
|
|
52
|
+
"mxSolvBTC",
|
|
53
|
+
"MUSD",
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
type UseMezoChainTokensBalancesOptions<T> = {
|
|
57
|
+
tokens?: T
|
|
58
|
+
queryOptions?: object
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Hook to get the balance of a list of tokens for the current account
|
|
63
|
+
* @param options.tokens The list of tokens to get the balance for. It will
|
|
64
|
+
* fallback to all tokens if not provided.
|
|
65
|
+
* @param options.queryOptions The query options to pass to the
|
|
66
|
+
* `useReadContracts`
|
|
67
|
+
* @returns Tanstack's `useQuery` returnings with balance of tokens for the
|
|
68
|
+
* current account in form of typesafe object with token names as keys
|
|
69
|
+
* and balances as values.
|
|
70
|
+
* @dev In case of error data fallbacks to `0n`. To determine if an error
|
|
71
|
+
* occurred, check the `isError` property.
|
|
72
|
+
* @example
|
|
73
|
+
* const mezoTokensBalance = useTokensBalances({
|
|
74
|
+
* tokens: ["mT", "mxSolvBTC"],
|
|
75
|
+
* })
|
|
76
|
+
* console.log(mezoTokensBalance?.data.mT) // Eg. 0n
|
|
77
|
+
* console.log(Object.keys(mezoTokensBalance?.data)) // ["mT", "mxSolvBTC"]
|
|
78
|
+
*/
|
|
79
|
+
export function useTokensBalances<T extends MezoChainToken[]>(
|
|
80
|
+
options: UseMezoChainTokensBalancesOptions<T> = {},
|
|
81
|
+
) {
|
|
82
|
+
const { environment = "mainnet" } = usePassportContext()
|
|
83
|
+
|
|
84
|
+
const { accountAddress } = useWalletAccount()
|
|
85
|
+
|
|
86
|
+
const contractsMap = useMemo(() => {
|
|
87
|
+
const contracts =
|
|
88
|
+
environment === "mainnet" ? mainnetTokenContracts : testnetTokenContracts
|
|
89
|
+
|
|
90
|
+
const tokenContracts = Object.fromEntries(
|
|
91
|
+
Object.entries(contracts).filter(([key]) =>
|
|
92
|
+
BALANCE_TOKENS.includes(key as MezoChainToken),
|
|
93
|
+
),
|
|
94
|
+
) as typeof contracts
|
|
95
|
+
|
|
96
|
+
return tokenContracts
|
|
97
|
+
}, [environment])
|
|
98
|
+
|
|
99
|
+
const { tokens = Object.keys(contractsMap) as T, queryOptions = {} } = options
|
|
100
|
+
|
|
101
|
+
const contracts = useMemo(() => {
|
|
102
|
+
if (!accountAddress) return []
|
|
103
|
+
|
|
104
|
+
return tokens.map((token) => {
|
|
105
|
+
const { address } = contractsMap[token]
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
address,
|
|
109
|
+
abi: BALANCE_OF_ABI,
|
|
110
|
+
functionName: "balanceOf",
|
|
111
|
+
args: [accountAddress],
|
|
112
|
+
chainId: CHAIN_ID[environment],
|
|
113
|
+
}
|
|
114
|
+
})
|
|
115
|
+
}, [accountAddress, tokens, contractsMap, environment])
|
|
116
|
+
|
|
117
|
+
return useReadContracts({
|
|
118
|
+
contracts,
|
|
119
|
+
query: {
|
|
120
|
+
select: (data) =>
|
|
121
|
+
data.reduce(
|
|
122
|
+
(acc, item) => {
|
|
123
|
+
const token = tokens[data.indexOf(item)]
|
|
124
|
+
|
|
125
|
+
return {
|
|
126
|
+
...acc,
|
|
127
|
+
[token]: item.result ?? 0n,
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
{} as Record<T[number], bigint>,
|
|
131
|
+
),
|
|
132
|
+
...queryOptions,
|
|
133
|
+
},
|
|
134
|
+
})
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Hook for invalidating current user's token balances. Can be used to
|
|
139
|
+
* invalidate the balances manually, which forces the data to be re-fetched.
|
|
140
|
+
* @param tokens The list of tokens (as string arrays) for which we want to
|
|
141
|
+
* invalidate query for.
|
|
142
|
+
* @returns Function `invalidateTokenBalances` that invalidates token balances
|
|
143
|
+
* @example
|
|
144
|
+
* const { invalidateTokenBalances } = useInvalidateTokensBalances(["mT", "mUSD"])
|
|
145
|
+
* (...)
|
|
146
|
+
* await invalidateTokenBalances()
|
|
147
|
+
*/
|
|
148
|
+
export function useInvalidateTokensBalances(tokens?: MezoChainToken[]) {
|
|
149
|
+
const queryClient = useQueryClient()
|
|
150
|
+
|
|
151
|
+
const { queryKey } = useTokensBalances({ tokens })
|
|
152
|
+
|
|
153
|
+
const invalidateTokensBalancesHandler = useCallback(
|
|
154
|
+
() => queryClient.invalidateQueries({ queryKey }),
|
|
155
|
+
[queryClient, queryKey],
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
return {
|
|
159
|
+
invalidateTokensBalances: invalidateTokensBalancesHandler,
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Hook for resetting current user's token balances. Can be used to reset the
|
|
165
|
+
* balances manually, which forces the data to be re-fetched.
|
|
166
|
+
* @param tokens The list of tokens (as string arrays) for which we want to
|
|
167
|
+
* reset query for.
|
|
168
|
+
* @returns Function `resetTokenBalances` that invalidates token balances
|
|
169
|
+
* @example
|
|
170
|
+
* const { resetTokenBalances } = useResetTokensBalances(["mT", "mUSD"])
|
|
171
|
+
* (...)
|
|
172
|
+
* await resetTokenBalances()
|
|
173
|
+
*/
|
|
174
|
+
export function useResetTokensBalances(tokens?: MezoChainToken[]) {
|
|
175
|
+
const queryClient = useQueryClient()
|
|
176
|
+
|
|
177
|
+
const { queryKey } = useTokensBalances({ tokens })
|
|
178
|
+
|
|
179
|
+
const resetTokenBalancesHandler = useCallback(
|
|
180
|
+
() => queryClient.resetQueries({ queryKey }),
|
|
181
|
+
[queryClient, queryKey],
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
return {
|
|
185
|
+
resetTokenBalances: resetTokenBalancesHandler,
|
|
186
|
+
}
|
|
187
|
+
}
|
|
@@ -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,10 +1,12 @@
|
|
|
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
|
|
@@ -13,27 +15,35 @@ type UseWalletAccountReturn = {
|
|
|
13
15
|
|
|
14
16
|
export default function useWalletAccount(): UseWalletAccountReturn {
|
|
15
17
|
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
18
|
|
|
29
19
|
const networkFamily = useMemo(
|
|
30
|
-
() => (
|
|
31
|
-
[
|
|
20
|
+
() => (connector?.type !== "orangekit" ? "evm" : "bitcoin"),
|
|
21
|
+
[connector],
|
|
32
22
|
)
|
|
33
23
|
|
|
24
|
+
const { data: btcData } = useQuery({
|
|
25
|
+
queryKey: [connector?.id],
|
|
26
|
+
queryFn: async () => {
|
|
27
|
+
const bitcoinProvider = (
|
|
28
|
+
connector as unknown as OrangeKitConnector
|
|
29
|
+
).getBitcoinProvider()
|
|
30
|
+
|
|
31
|
+
const address = await bitcoinProvider.getAddress()
|
|
32
|
+
const balance = await bitcoinProvider.getBalance()
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
address,
|
|
36
|
+
balance,
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
const { address: btcAddress } = btcData || {}
|
|
42
|
+
|
|
34
43
|
return {
|
|
35
|
-
|
|
36
|
-
|
|
44
|
+
accountAddress: evmAddress,
|
|
45
|
+
walletAddress: btcAddress ?? evmAddress,
|
|
46
|
+
isConnected: networkFamily === "bitcoin" ? !!btcAddress : !!evmAddress,
|
|
37
47
|
networkFamily,
|
|
38
48
|
connector,
|
|
39
49
|
chainId,
|
|
@@ -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,92 @@
|
|
|
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
|
+
|
|
29
|
+
import { Abi, Address } from "viem"
|
|
30
|
+
|
|
31
|
+
export type MezoChainToken =
|
|
32
|
+
| "mcbBTC"
|
|
33
|
+
| "mDAI"
|
|
34
|
+
| "mFBTC"
|
|
35
|
+
| "mSolvBTC"
|
|
36
|
+
| "mswBTC"
|
|
37
|
+
| "mT"
|
|
38
|
+
| "mUSDC"
|
|
39
|
+
| "mUSDe"
|
|
40
|
+
| "mUSDT"
|
|
41
|
+
| "mxSolvBTC"
|
|
42
|
+
| "MUSD"
|
|
43
|
+
|
|
44
|
+
export type MezoBorrowContract = "TroveManager" | "BorrowerOperations"
|
|
45
|
+
|
|
46
|
+
type ContractsMap<K extends string> = Record<
|
|
47
|
+
K,
|
|
48
|
+
{
|
|
49
|
+
address: Address
|
|
50
|
+
abi: Abi
|
|
51
|
+
}
|
|
52
|
+
>
|
|
53
|
+
|
|
54
|
+
export const testnetTokenContracts = {
|
|
55
|
+
mcbBTC: cbbtcTestnet,
|
|
56
|
+
mDAI: daiTestnet,
|
|
57
|
+
mFBTC: fbtcTestnet,
|
|
58
|
+
mSolvBTC: solvbtcTestnet,
|
|
59
|
+
mswBTC: swbtcTestnet,
|
|
60
|
+
mT: tTestnet,
|
|
61
|
+
mUSDC: usdcTestnet,
|
|
62
|
+
mUSDe: usdeTestnet,
|
|
63
|
+
mUSDT: usdtTestnet,
|
|
64
|
+
mxSolvBTC: xsolvbtcTestnet,
|
|
65
|
+
MUSD: musdTestnet,
|
|
66
|
+
} as unknown as ContractsMap<MezoChainToken>
|
|
67
|
+
|
|
68
|
+
export const mainnetTokenContracts = {
|
|
69
|
+
mcbBTC: cbbtcMainnet,
|
|
70
|
+
mDAI: daiMainnet,
|
|
71
|
+
mFBTC: fbtcMainnet,
|
|
72
|
+
mSolvBTC: solvbtcMainnet,
|
|
73
|
+
mswBTC: swbtcMainnet,
|
|
74
|
+
mT: tMainnet,
|
|
75
|
+
mUSDC: usdcMainnet,
|
|
76
|
+
mUSDe: usdeMainnet,
|
|
77
|
+
mUSDT: usdtMainnet,
|
|
78
|
+
mxSolvBTC: xsolvbtcMainnet,
|
|
79
|
+
MUSD: musdMainnet,
|
|
80
|
+
} as unknown as ContractsMap<MezoChainToken>
|
|
81
|
+
|
|
82
|
+
export const mainnetBorrowContracts = {
|
|
83
|
+
TroveManager: troveManagerMainnet,
|
|
84
|
+
BorrowerOperations: borrowerOperationsMainnet,
|
|
85
|
+
} as unknown as ContractsMap<MezoBorrowContract>
|
|
86
|
+
|
|
87
|
+
export const testnetBorrowContracts = {
|
|
88
|
+
TroveManager: troveManagerTestnet,
|
|
89
|
+
BorrowerOperations: borrowerOperationsTestnet,
|
|
90
|
+
} as unknown as ContractsMap<MezoBorrowContract>
|
|
91
|
+
|
|
92
|
+
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
|
@@ -29,7 +29,7 @@ export function PassportProvider({
|
|
|
29
29
|
portalApiUrl,
|
|
30
30
|
children,
|
|
31
31
|
}: PassportProviderProps) {
|
|
32
|
-
if (environment
|
|
32
|
+
if (environment && !["mainnet", "testnet"].includes(environment)) {
|
|
33
33
|
throw new Error("Wrong environment passed to PassportProvider.")
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -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
|
|
@@ -10,12 +10,6 @@ describe("trimAddress", () => {
|
|
|
10
10
|
const expected = "0x123...bcdef"
|
|
11
11
|
expect(trimAddress(input)).toBe(expected)
|
|
12
12
|
})
|
|
13
|
-
|
|
14
|
-
it("returns lowercase result", () => {
|
|
15
|
-
const input = "0xABCDEF1234567890"
|
|
16
|
-
const expected = "0xabc...67890"
|
|
17
|
-
expect(trimAddress(input)).toBe(expected)
|
|
18
|
-
})
|
|
19
13
|
})
|
|
20
14
|
|
|
21
15
|
describe("getAddressExplorerUrl", () => {
|
|
@@ -41,4 +35,14 @@ describe("getAddressExplorerUrl", () => {
|
|
|
41
35
|
const url = getAddressExplorerUrl(evmAddress, "evm", true)
|
|
42
36
|
expect(url).toBe(`https://sepolia.etherscan.io/address/${evmAddress}`)
|
|
43
37
|
})
|
|
38
|
+
|
|
39
|
+
it("returns correct mainnet Mezo explorer URL", () => {
|
|
40
|
+
const url = getAddressExplorerUrl(evmAddress, "mezo", false)
|
|
41
|
+
expect(url).toBe(`https://explorer.mezo.org/address/${evmAddress}`)
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it("returns correct testnet Mezo explorer URL", () => {
|
|
45
|
+
const url = getAddressExplorerUrl(evmAddress, "mezo", true)
|
|
46
|
+
expect(url).toBe(`https://explorer.test.mezo.org/address/${evmAddress}`)
|
|
47
|
+
})
|
|
44
48
|
})
|
package/src/utils/address.ts
CHANGED
|
@@ -11,14 +11,16 @@ export function trimAddress(address: string): string {
|
|
|
11
11
|
return trimmedAddress
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
const MAINNET_EXPLORER_URLS: Record<"bitcoin" | "evm", string> = {
|
|
14
|
+
const MAINNET_EXPLORER_URLS: Record<"bitcoin" | "evm" | "mezo", string> = {
|
|
15
15
|
bitcoin: "https://mempool.space",
|
|
16
16
|
evm: "https://etherscan.io",
|
|
17
|
+
mezo: "https://explorer.mezo.org",
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
const TESTNET_EXPLORER_URLS: Record<"bitcoin" | "evm", string> = {
|
|
20
|
+
const TESTNET_EXPLORER_URLS: Record<"bitcoin" | "evm" | "mezo", string> = {
|
|
20
21
|
bitcoin: "https://mempool.space/testnet",
|
|
21
22
|
evm: "https://sepolia.etherscan.io",
|
|
23
|
+
mezo: "https://explorer.test.mezo.org",
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
/**
|
|
@@ -30,7 +32,7 @@ const TESTNET_EXPLORER_URLS: Record<"bitcoin" | "evm", string> = {
|
|
|
30
32
|
*/
|
|
31
33
|
export function getAddressExplorerUrl(
|
|
32
34
|
address: string,
|
|
33
|
-
chainType: "bitcoin" | "evm",
|
|
35
|
+
chainType: "bitcoin" | "evm" | "mezo",
|
|
34
36
|
isTestnet: boolean,
|
|
35
37
|
) {
|
|
36
38
|
const EXPLORER_URLS = isTestnet
|