@w3ux/react-connect-kit 1.5.1-alpha.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -9,7 +9,6 @@ export const WCAccountsProvider = ({ children }) => {
|
|
|
9
9
|
const [wcAccounts, setWcAccountsState] = useState(getLocalWcAccounts());
|
|
10
10
|
const wcAccountsRef = useRef(wcAccounts);
|
|
11
11
|
const wcAccountExists = (network, address) => !!wcAccountsRef.current.find((a) => isLocalNetworkAddress(network, a, address));
|
|
12
|
-
console.log(wcAccountsRef.current);
|
|
13
12
|
const addWcAccount = (network, address, index, callback) => {
|
|
14
13
|
let newAccounts = [...wcAccountsRef.current];
|
|
15
14
|
if (!newAccounts.find((a) => isLocalNetworkAddress(network, a, address))) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/WCAccountsProvider/index.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAKpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAGtD,MAAM,CAAC,MAAM,iBAAiB,GAAG,aAAa,CAC5C,wBAAwB,CACzB,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,EAAE,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC;AAEjE,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,EAAE,QAAQ,EAA2B,EAAE,EAAE;IAC1E,MAAM,CAAC,UAAU,EAAE,kBAAkB,CAAC,GACpC,QAAQ,CAAc,kBAAkB,EAAE,CAAC,CAAC;IAC9C,MAAM,aAAa,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;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K,EAAE;YACL,eAAe;YACf,YAAY;YACZ,eAAe;YACf,eAAe;YACf,YAAY;YACZ,aAAa;YACb,UAAU,EAAE,aAAa,CAAC,OAAO;SAClC,YAEA,QAAQ,GACkB,CAC9B,CAAC;AACJ,CAAC,CAAC","file":"index.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport { ellipsisFn, setStateWithRef } from \"@w3ux/utils\";\nimport { createContext, useContext, useRef, useState } from \"react\";\nimport { getLocalWcAccounts, isLocalNetworkAddress } from \"./utils\";\nimport type {\n WCAccountsContextInterface,\n WCAccountsProviderProps,\n} from \"./types\";\nimport { defaultWcAccountsContext } from \"./defaults\";\nimport { WCAccount } from \"../types\";\n\nexport const WCAccountsContext = createContext<WCAccountsContextInterface>(\n defaultWcAccountsContext\n);\n\nexport const useWcAccounts = () => useContext(WCAccountsContext);\n\nexport const WCAccountsProvider = ({ children }: WCAccountsProviderProps) => {\n const [wcAccounts, setWcAccountsState] =\n useState<WCAccount[]>(getLocalWcAccounts());\n const wcAccountsRef = useRef(wcAccounts);\n\n // Check if a Wallet Connect address exists in imported addresses.\n const wcAccountExists = (network: string, address: string) =>\n !!wcAccountsRef.current.find((a) =>\n isLocalNetworkAddress(network, a, address)\n );\n\n // Adds a wallet connect account to state and local storage.\n const addWcAccount = (\n network: string,\n address: string,\n index: number,\n callback?: () => void\n ) => {\n let newAccounts = [...wcAccountsRef.current];\n\n if (!newAccounts.find((a) => isLocalNetworkAddress(network, a, address))) {\n const account = {\n address,\n network,\n name: ellipsisFn(address),\n source: \"wallet_connect\",\n index,\n };\n\n newAccounts = [...newAccounts].concat(account);\n localStorage.setItem(\n \"wallet_connect_accounts\",\n JSON.stringify(newAccounts)\n );\n\n // Persist the new accounts to state.\n setStateWithRef(newAccounts, setWcAccountsState, wcAccountsRef);\n\n // Handle optional callback function.\n if (typeof callback === \"function\") {\n callback();\n }\n\n return account;\n }\n return null;\n };\n\n const removeWcAccount = (\n network: string,\n address: string,\n callback?: () => void\n ) => {\n let newAccounts = [...wcAccountsRef.current];\n\n newAccounts = newAccounts.filter((a) => {\n if (a.address !== address) {\n return true;\n }\n if (a.network !== network) {\n return true;\n }\n return false;\n });\n\n if (!newAccounts.length) {\n localStorage.removeItem(\"wallet_connect_accounts\");\n } else {\n localStorage.setItem(\n \"wallet_connect_accounts\",\n JSON.stringify(newAccounts)\n );\n }\n setStateWithRef(newAccounts, setWcAccountsState, wcAccountsRef);\n\n // Handle optional callback function.\n if (typeof callback === \"function\") {\n callback();\n }\n };\n\n const getWcAccount = (network: string, address: string) =>\n wcAccountsRef.current.find((a) =>\n isLocalNetworkAddress(network, a, address)\n ) ?? null;\n\n const renameWcAccount = (\n network: string,\n address: string,\n newName: string\n ) => {\n const newAccounts = wcAccountsRef.current.map((a) =>\n isLocalNetworkAddress(network, a, address)\n ? {\n ...a,\n name: newName,\n }\n : a\n );\n localStorage.setItem(\n \"wallet_connect_accounts\",\n JSON.stringify(newAccounts)\n );\n\n setStateWithRef(newAccounts, setWcAccountsState, wcAccountsRef);\n };\n\n // Gets Wallet Connect accounts for a network.\n const getWcAccounts = (network: string) =>\n wcAccountsRef.current.filter((a) => a.network === network);\n\n return (\n <WCAccountsContext.Provider\n value={{\n wcAccountExists,\n addWcAccount,\n removeWcAccount,\n renameWcAccount,\n getWcAccount,\n getWcAccounts,\n wcAccounts: wcAccountsRef.current,\n }}\n >\n {children}\n </WCAccountsContext.Provider>\n );\n};\n"]}
|