@dynamic-labs/sdk-react-core
Version:
A React SDK for implementing wallet web3 authentication and authorization to your website.
35 lines (32 loc) • 1.65 kB
JavaScript
'use client'
import { VerifiedCredentialNameToChainEnum } from '../../constants/values.js';
import { compareChains } from '../compareChains/compareChains.js';
const findWalletOptionFor = (account, walletOptions) => {
const { walletName } = account;
if (walletName === 'turnkeyhd' || walletName === 'dynamicwaas') {
const chain = account.chain
? VerifiedCredentialNameToChainEnum[account.chain]
: undefined;
return walletOptions.find((wallet) => walletName === wallet.key &&
wallet.walletConnector.connectedChain === chain);
}
// Wallets with name "unknown" are legacy wallets that were created when wallet name was still
// set to "unknown" if not found in wallet book. We need to use fallback connector for these wallets.
// The "unknown" wallet connector is also legacy and should never be used.
if (walletName !== 'unknown') {
const wallet = walletOptions.find((wallet) => wallet.key === walletName);
if (wallet)
return wallet;
}
// If we cannot find the correct connector for the wallet, we default to the fallback
// this way the wallet will appear in user wallets, but will not be able to be interacted with
const fallbackOptions = walletOptions.filter((wallet) => wallet.key === 'fallbackconnector');
const { chain } = account;
if (chain) {
const unknownWallet = fallbackOptions.find(({ walletConnector }) => compareChains(walletConnector.connectedChain, chain));
if (unknownWallet)
return unknownWallet;
}
return fallbackOptions[0];
};
export { findWalletOptionFor };