UNPKG

@reown/appkit-controllers

Version:

The full stack toolkit to build onchain app UX.

126 lines 4.87 kB
import { AssetUtil } from './AssetUtil.js'; import { ConnectorUtil } from './ConnectorUtil.js'; import { WalletUtil } from './WalletUtil.js'; export const ConnectUtil = { /** * Maps the initial connect view wallets into WalletItems. Includes WalletConnect wallet and injected wallets. If user doesn't have any injected wallets, it'll fill the list with most ranked WalletConnect wallets. * @returns The WalletItems for the initial connect view. */ getInitialWallets() { return ConnectorUtil.connectorList() .map(connector => { if (connector.kind === 'connector') { return this.mapConnectorToWalletItem(connector.connector, connector.subtype); } else if (connector.kind === 'wallet') { return this.mapWalletToWalletItem(connector.wallet); } return null; }) .filter(Boolean); }, /** * Maps the WalletGuide explorer wallets to WalletItems including search results. * @returns The WalletItems for the WalletGuide explorer wallets. */ getWalletConnectWallets(wcAllWallets, wcSearchWallets) { if (wcSearchWallets.length > 0) { return wcSearchWallets.map(w => this.mapWalletToWalletItem(w)); } return WalletUtil.getWalletConnectWallets(wcAllWallets).map(w => this.mapWalletToWalletItem(w)); }, /** * Serializes WcWallet properties into WalletItem format. * @param wallet - The WcWallet to serialize. * @returns The serialized walletInfo property. */ serializeWcWallet(wallet) { if (!wallet) { return { walletInfo: {} }; } return { walletInfo: { description: wallet.description, supportedChains: wallet.chains, website: wallet.homepage, installationLinks: { appStore: wallet.app_store, playStore: wallet.play_store, chromeStore: wallet.chrome_store, desktopLink: wallet.desktop_link }, deepLink: wallet.mobile_link, linkMode: wallet.link_mode, isCertified: wallet.badge_type === 'certified', supportsWcPay: wallet.supports_wcpay ?? false } }; }, /** * Maps the connector to a WalletItem. * @param connector - The connector to map to a WalletItem. * @param subType - The subtype of the connector. * @returns The WalletItem for the connector. */ mapConnectorToWalletItem(connector, subType) { const hasMultipleConnectors = connector.connectors?.length; const connectors = hasMultipleConnectors ? connector.connectors?.map(c => ({ id: c.id, chain: c.chain, chainImageUrl: AssetUtil.getChainNamespaceImageUrl(c.chain) })) || [] : [ { id: connector.id, chain: connector.chain, chainImageUrl: AssetUtil.getChainNamespaceImageUrl(connector.chain) } ]; return { id: connector.id, connectors: subType === 'walletConnect' ? [] : connectors, name: connector.name, imageUrl: connector.imageUrl || AssetUtil.getAssetImageUrl(connector.imageId), imageId: connector.imageId, isInjected: subType !== 'walletConnect', isRecent: false, ...this.serializeWcWallet(connector.explorerWallet) }; }, /** * Maps the WalletGuide explorer wallet to a WalletItem. * @param w - The WalletGuide explorer wallet. * @returns The WalletItem for the WalletGuide explorer wallet. */ mapWalletToWalletItem(w) { return { id: w.id, connectors: [], name: w.name, imageUrl: AssetUtil.getWalletImageUrl(w.image_id), imageId: w.image_id, isInjected: false, isRecent: false, ...this.serializeWcWallet(w) }; }, /** * Maps the WalletItem to a Wallet Guide Wallet. * @param wallet - The WalletItem to map to a Wallet Guide Wallet. * @returns The Wallet Guide Wallet for the WalletItem. */ mapWalletItemToWcWallet(wallet) { return { id: wallet.id, name: wallet.name, image_id: wallet.imageId, image_url: wallet.imageUrl, description: wallet.walletInfo.description, mobile_link: wallet.walletInfo.deepLink, link_mode: wallet.walletInfo.linkMode ?? null, chains: wallet.walletInfo.supportedChains }; } }; //# sourceMappingURL=ConnectUtil.js.map