@reservoir0x/relay-kit-ui
Version:
Relay is the Fastest and Cheapest Way to Bridge and Transact Across Chains.
40 lines • 1.89 kB
JavaScript
import { useMemo } from 'react';
import { NormalizedWalletName, WalletChainIncompatible, WalletChainRestricted } from '../constants/walletCompatibility.js';
import { isAddress } from 'viem';
import useIsAGW from './useIsAGW.js';
import useCexAddresses from './useCexAddresses.js';
export default (chainId, address, wallets, onAnalyticEvent) => {
const normalizedAddress = address && isAddress(address) ? address.toLowerCase() : address;
const linkedWallet = wallets?.find((wallet) => (wallet.vmType === 'evm'
? wallet.address.toLowerCase()
: wallet.address) === normalizedAddress);
const isRecipientAGW = useIsAGW(address, !linkedWallet, onAnalyticEvent);
const { data: cexAddresses } = useCexAddresses();
const isRecipientCEX = cexAddresses?.addresses.includes(normalizedAddress ?? '');
return useMemo(() => {
if (!chainId || !address) {
return true;
}
//Hyperliquid operates as a CEX, so there's no need to check for wallet compatibility
if (chainId === 1337) {
return true;
}
if (!linkedWallet) {
if (isRecipientCEX) {
return false;
}
return isRecipientAGW ? chainId === 2741 : true;
}
const normalizedWalletName = NormalizedWalletName[linkedWallet.connector] ?? linkedWallet.connector;
const incompatibleChains = WalletChainIncompatible[normalizedWalletName];
if (incompatibleChains && incompatibleChains.includes(chainId)) {
return false;
}
const restrictedChains = WalletChainRestricted[normalizedWalletName];
if (restrictedChains && !restrictedChains.includes(chainId)) {
return false;
}
return true;
}, [chainId, address, linkedWallet, isRecipientAGW, isRecipientCEX]);
};
//# sourceMappingURL=useIsWalletCompatible.js.map