UNPKG

@lifi/wallet-management

Version:

LI.FI Wallet Management solution.

58 lines 2.66 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { connect, disconnect, getAccount } from '@bigmi/client'; import { useConfig } from '@bigmi/react'; import { ChainId, ChainType } from '@lifi/sdk'; 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 { getConnectorIcon } from '../utils/getConnectorIcon.js'; import { isWalletInstalled } from '../utils/isWalletInstalled.js'; import { CardListItemButton } from './CardListItemButton.js'; export const UTXOListItemButton = ({ ecosystemSelection, connector, tagType, onNotInstalled, onConnected, onConnecting, onError, }) => { const emitter = useWalletManagementEvents(); const config = useConfig(); const { setLastConnectedAccount } = useLastConnectedAccount(); const connectorName = connector.name; const connectorDisplayName = ecosystemSelection ? 'Bitcoin' : connectorName; const handleUTXOConnect = async () => { if (tagType === WalletTagType.Connected) { onConnected?.(); return; } try { const identityCheckPassed = isWalletInstalled(connector.id); if (!identityCheckPassed) { onNotInstalled?.(connector); return; } const connectedAccount = getAccount(config); onConnecting?.(); const data = await connect(config, { connector }); if (connectedAccount.connector) { await disconnect(config, { connector: connectedAccount.connector }); } setLastConnectedAccount(connector); emitter.emit(WalletManagementEvent.WalletConnected, { address: data.accounts[0].address, chainId: ChainId.BTC, chainType: ChainType.UTXO, connectorId: connector.id, connectorName: connectorName, }); onConnected?.(); } catch (error) { onError?.(error); } }; return (_jsx(CardListItemButton, { icon: ecosystemSelection ? getChainTypeIcon(ChainType.UTXO) : (getConnectorIcon(connector) ?? ''), onClick: handleUTXOConnect, title: connectorDisplayName, tagType: ecosystemSelection && tagType !== WalletTagType.Connected ? undefined : tagType }, connector.id)); }; //# sourceMappingURL=UTXOListItemButton.js.map