UNPKG

@lifi/wallet-management

Version:

LI.FI Wallet Management solution.

53 lines 2.33 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { ChainId, ChainType } from '@lifi/sdk'; import { useWallet } from '@solana/wallet-adapter-react'; import { useLastConnectedAccount } from '../hooks/useAccount.js'; import { useWalletManagementEvents } from '../hooks/useWalletManagementEvents.js'; import { getChainTypeIcon } from '../icons.js'; import { WalletManagementEvent } from '../types/events.js'; import { WalletTagType } from '../types/walletTagType.js'; import { CardListItemButton } from './CardListItemButton.js'; export const SVMListItemButton = ({ ecosystemSelection, walletAdapter, tagType, onConnected, onConnecting, onError, }) => { const emitter = useWalletManagementEvents(); const { select, disconnect, connected } = useWallet(); const { setLastConnectedAccount } = useLastConnectedAccount(); const connectorName = walletAdapter.name; const connectorDisplayName = ecosystemSelection ? 'Solana' : walletAdapter.name; const connectWallet = async () => { if (tagType === WalletTagType.Connected) { onConnected?.(); return; } try { onConnecting?.(); if (connected) { await disconnect(); } select(walletAdapter.name); // We use autoConnect on wallet selection // await connect() walletAdapter.once('connect', (publicKey) => { setLastConnectedAccount(walletAdapter); emitter.emit(WalletManagementEvent.WalletConnected, { address: publicKey?.toString(), chainId: ChainId.SOL, chainType: ChainType.SVM, connectorId: connectorName, connectorName: connectorName, }); }); onConnected?.(); } catch (error) { onError?.(error); } }; return (_jsx(CardListItemButton, { icon: ecosystemSelection ? getChainTypeIcon(ChainType.SVM) : walletAdapter.icon, onClick: connectWallet, title: connectorDisplayName, tagType: ecosystemSelection && tagType !== WalletTagType.Connected ? undefined : tagType }, connectorDisplayName)); }; //# sourceMappingURL=SVMListItemButton.js.map