UNPKG

@coin-voyage/paykit

Version:

Seamless crypto payments. Onboard users from any chain, any coin into your app with one click.

75 lines 3.19 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { useCombinedWallets } from "@coin-voyage/crypto/hooks"; import usePayContext from "../components/contexts/pay"; import { walletConfigs } from "../lib/config/wallet"; import { isInjectedConnector } from "../utils"; export const useWallets = () => { const { paymentState } = usePayContext(); const { installedWallets } = useCombinedWallets(paymentState.connectorChainType); const context = usePayContext(); const wallets = installedWallets.map((wallet) => { // use overrides const walletId = Object.keys(walletConfigs).find( // where id is comma seperated list (id) => id .split(",") .map((i) => i.trim()) .indexOf(wallet.id) !== -1); const c = { id: wallet.id, name: wallet.name ?? wallet.id, icon: (_jsx("img", { src: wallet.icon, alt: wallet.name, width: "100%", height: "100%" })), connectors: wallet.connectors, iconShape: "squircle", isInstalled: true, }; if (walletId) { const walletConfig = walletConfigs[walletId]; return { ...c, iconConnector: wallet.icon ? (_jsx("img", { src: wallet.icon.toString(), alt: wallet.name, width: "100%", height: "100%" })) : undefined, ...walletConfig, }; } return c; }); return (wallets // remove duplicate ids .filter((wallet, index, self) => self.findIndex((w) => w.id === wallet.id) === index) // // Replace walletConnect's name with the one from options .map((wallet) => { if (wallet.id === "walletConnect") { return { ...wallet, name: context.options?.walletConnectName || wallet.name, shortName: context.options?.walletConnectName || wallet.shortName, }; } return wallet; }) // remove wallet with id coinbaseWalletSDK if wallet with id 'com.coinbase.wallet' exists .filter((wallet, _, self) => !(wallet.id === "coinbaseWalletSDK" && self.find((w) => w.id === "com.coinbase.wallet"))) // remove wallet with id io.metamask if wallet with id 'metaMask' exists .filter((wallet, _, self) => !((wallet.id === "metaMaskSDK" || wallet.id === "metaMask") && self.find((w) => w.id === "io.metamask" || w.id === "io.metamask.mobile"))) // order by isInstalled injected connectors first .sort((a, b) => { const AisInstalled = a.isInstalled && isInjectedConnector(a.connectors[0].connector.id); const BisInstalled = b.isInstalled && isInjectedConnector(b.connectors[0].connector.id); if (AisInstalled && !BisInstalled) return -1; if (!AisInstalled && BisInstalled) return 1; return 0; }) // move walletConnect to the end .sort((a, b) => { if (a.id === "walletConnect") return 1; if (b.id === "walletConnect") return -1; return 0; })); }; //# sourceMappingURL=useWallets.js.map