UNPKG

@particle-network/connectkit

Version:
8 lines (7 loc) 4.8 kB
{ "version": 3, "sources": ["../../src/hooks/useChains.ts", "../../src/hooks/useWalletConnections.tsx"], "sourcesContent": ["import { useMemo } from 'react';\nimport { useContext } from '../context';\nimport { useAccount } from './useAccount';\n\nexport const useChains = () => {\n const { config } = useContext();\n const { connector } = useAccount();\n\n const chains = useMemo(() => {\n const walletConnectorType = connector?.walletConnectorType;\n if (walletConnectorType) {\n const walletConnector = config.getWalletConnector(walletConnectorType);\n if (walletConnector) {\n return walletConnector.chains;\n }\n }\n return config.chains;\n }, [connector, config]);\n\n return chains;\n};\n", "import { useMemo } from 'react';\nimport SocialIcon from '../components/socialLogin/Icons';\nimport { useContext } from '../context';\nimport type { AuthWalletConnectorProperties } from '../types/properties';\nimport { useConnections } from './useConnections';\nimport { useLastConnectorId } from './useLastConnectorId';\nimport useWalletsProps, { type WalletProps } from './useWalletsProps';\n\nexport type WalletConnection = {\n accounts: readonly [string, ...string[]];\n chainId: number;\n walletProps: WalletProps;\n};\n\nexport const useWalletConnections = (): WalletConnection[] => {\n const connections = useConnections();\n const wallets = useWalletsProps();\n const { config } = useContext();\n const { lastConnectorId } = useLastConnectorId();\n\n const walletConnections = useMemo(() => {\n const props: WalletConnection[] = [];\n for (const connection of connections) {\n const id = connection.connector.id;\n const wallet = wallets.find(\n (wallet) =>\n wallet.id === id ||\n wallet.groupId\n ?.split(',')\n .map((item) => item.trim())\n .includes(id)\n );\n if (!wallet) {\n continue;\n }\n\n if (connection.connector.type === 'particleAuth') {\n const authType = config\n .getWalletConnector<AuthWalletConnectorProperties>('particleAuth')\n ?.auth.getLatestAuthType();\n if (authType) {\n wallet.icon = <SocialIcon authType={authType} />;\n }\n } else {\n // \u79FB\u52A8\u7AEFwallet\u90FD\u662F\u901A\u8FC7WalletConnect\u94FE\u63A5\u7684\uFF0C\u4F46\u662Ficon\u9700\u8981\u663E\u793A\u5177\u4F53\u70B9\u51FB\u7684wallet\n if (wallet.connector.id === 'walletConnect' && lastConnectorId && lastConnectorId !== wallet.connector.id) {\n const lastWallet = wallets.find(\n (wallet) =>\n wallet.id === lastConnectorId ||\n wallet.groupId\n ?.split(',')\n .map((item) => item.trim())\n .includes(lastConnectorId)\n );\n if (lastWallet?.icon) {\n wallet.icon = lastWallet.icon;\n }\n }\n }\n\n props.push({\n accounts: connection.accounts,\n chainId: connection.chainId,\n walletProps: wallet,\n });\n }\n\n return props;\n }, [connections, wallets, config, lastConnectorId]);\n\n return walletConnections;\n};\n"], "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,eAAe;AAAxB,IAIa;AAJb;AAAA;AAAA;AACA;AACA;AAEO,IAAM,YAAY,MAAM;AAC7B,YAAM,EAAE,OAAO,IAAI,WAAW;AAC9B,YAAM,EAAE,UAAU,IAAI,WAAW;AAEjC,YAAM,SAAS,QAAQ,MAAM;AAC3B,cAAM,sBAAsB,WAAW;AACvC,YAAI,qBAAqB;AACvB,gBAAM,kBAAkB,OAAO,mBAAmB,mBAAmB;AACrE,cAAI,iBAAiB;AACnB,mBAAO,gBAAgB;AAAA,UACzB;AAAA,QACF;AACA,eAAO,OAAO;AAAA,MAChB,GAAG,CAAC,WAAW,MAAM,CAAC;AAEtB,aAAO;AAAA,IACT;AAAA;AAAA;;;ACpBA,SAAS,WAAAA,gBAAe;AAyCA;AAzCxB,IAca;AAdb;AAAA;AAAA;AACA;AACA;AAEA;AACA;AACA;AAQO,IAAM,uBAAuB,MAA0B;AAC5D,YAAM,cAAc,eAAe;AACnC,YAAM,UAAU,wBAAgB;AAChC,YAAM,EAAE,OAAO,IAAI,WAAW;AAC9B,YAAM,EAAE,gBAAgB,IAAI,mBAAmB;AAE/C,YAAM,oBAAoBA,SAAQ,MAAM;AACtC,cAAM,QAA4B,CAAC;AACnC,mBAAW,cAAc,aAAa;AACpC,gBAAM,KAAK,WAAW,UAAU;AAChC,gBAAM,SAAS,QAAQ;AAAA,YACrB,CAACC,YACCA,QAAO,OAAO,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