@particle-network/connectkit
Version:
8 lines (7 loc) • 5.25 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../src/hooks/useWalletsProps.tsx"],
"sourcesContent": ["import type { Connector } from '@particle-network/connector-core';\nimport Injected from '../assets/wallets/Injected';\nimport { walletConfigs, type WalletConfigProps } from '../config/wallet';\nimport { useConnectors } from './useConnectors';\n\ntype GetConnectorType = {\n getConnector: <properties extends Record<string, unknown> = Record<string, unknown>>() => Connector & properties;\n};\n\nexport type WalletProps = {\n id: string;\n groupId?: string;\n connector: Connector;\n isInstalled?: boolean;\n} & WalletConfigProps &\n GetConnectorType;\n\nconst useWalletsProps = () => {\n const connectors = useConnectors();\n\n const wallets = connectors.map((connector): WalletProps => {\n const rawId = connector.id.replace('solana_', '');\n const groupId = Object.keys(walletConfigs).find(\n (id) =>\n id\n .split(',')\n .map((i) => i.trim())\n .indexOf(rawId) !== -1\n );\n\n const props: WalletProps = {\n id: connector.id,\n name: connector.name ?? connector.id ?? connector.type,\n icon: <img src={connector.icon} alt={connector.name} width={'100%'} height={'100%'} />,\n connector,\n iconShape: 'squircle',\n isInstalled: connector.isInstalled?.(),\n getConnector: <properties extends Record<string, unknown> = Record<string, unknown>>() => {\n return connector as Connector & properties;\n },\n };\n\n if (groupId) {\n const wallet = walletConfigs[groupId];\n return {\n ...props,\n ...wallet,\n groupId,\n };\n } else {\n if (!connector.icon) {\n props.icon = <Injected />;\n }\n }\n return props;\n });\n\n const result = wallets\n // remove duplicate ids\n .filter(\n (wallet, index, self) =>\n self.findIndex((w) => w.id === wallet.id && w.connector.chainType === wallet.connector.chainType) === index\n )\n // remove wallet when eip-6963 provider discovery\n .filter((wallet, index, self) => {\n if (wallet.connector.chainType === 'solana') {\n // solana not support eip-6963.\n return true;\n }\n const groupId = wallet.groupId;\n if (groupId && groupId.includes(',')) {\n const isMipd = wallet.connector.id.includes('.');\n if (isMipd) {\n return true;\n }\n\n const mipdIds = groupId\n .split(',')\n .map((id) => id.trim())\n .filter((id) => id.includes('.'));\n\n const hasMipd = self.find((w) => mipdIds.includes(w.connector.id));\n return Boolean(!hasMipd);\n }\n\n return true;\n })\n // order by isInstalled\n .sort((a, b) => {\n if (a.isInstalled && !b.isInstalled) return -1;\n if (!a.isInstalled && b.isInstalled) return 1;\n return 0;\n })\n // move walletConnect to the end\n .sort((a, b) => {\n if (a.id === 'walletConnect') return 1;\n if (b.id === 'walletConnect') return -1;\n return 0;\n });\n\n return result;\n};\n\nexport default useWalletsProps;\n\nexport const useWalletProps = (id: string): WalletProps | null => {\n const wallets = useWalletsProps();\n const wallet = wallets.find((c) => c.id === id);\n if (!wallet) return null;\n return wallet;\n};\n"],
"mappings": ";;;;;;;;;;;;;;;;;;AAiCY;AAjCZ,IAiBM,iBAsFC,yBAEM;AAzGb;AAAA;AAAA;AACA;AACA;AACA;AAcA,IAAM,kBAAkB,MAAM;AAC5B,YAAM,aAAa,cAAc;AAEjC,YAAM,UAAU,WAAW,IAAI,CAAC,cAA2B;AACzD,cAAM,QAAQ,UAAU,GAAG,QAAQ,WAAW,EAAE;AAChD,cAAM,UAAU,OAAO,KAAK,aAAa,EAAE;AAAA,UACzC,CAAC,OACC,GACG,MAAM,GAAG,EACT,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,EACnB,QAAQ,KAAK,MAAM;AAAA,QAC1B;AAEA,cAAM,QAAqB;AAAA,UACzB,IAAI,UAAU;AAAA,UACd,MAAM,UAAU,QAAQ,UAAU,MAAM,UAAU;AAAA,UAClD,MAAM,oBAAC,SAAI,KAAK,UAAU,MAAM,KAAK,UAAU,MAAM,OAAO,QAAQ,QAAQ,QAAQ;AAAA,UACpF;AAAA,UACA,WAAW;AAAA,UACX,aAAa,UAAU,cAAc;AAAA,UACrC,cAAc,MAA4E;AACxF,mBAAO;AAAA,UACT;AAAA,QACF;AAEA,YAAI,SAAS;AACX,gBAAM,SAAS,cAAc;AAC7B,iBAAO;AAAA,YACL,GAAG;AAAA,YACH,GAAG;AAAA,YACH;AAAA,UACF;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