@w3ux/react-connect-kit 3.2.24-alpha.2 → 3.2.24-alpha.4

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.
@@ -0,0 +1,6 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { HardwareAccountsContextInterface } from './types';
3
+ export declare const HardwareAccountsContext: import("react").Context<HardwareAccountsContextInterface>, useHardwareAccounts: () => HardwareAccountsContextInterface;
4
+ export declare const HardwareAccountsProvider: ({ children, }: {
5
+ children: ReactNode;
6
+ }) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,68 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createSafeContext } from '@w3ux/hooks';
3
+ import { ellipsisFn } from '@w3ux/utils';
4
+ import { hardwareAccountsKey } from 'consts';
5
+ import { useState } from 'react';
6
+ import { getLocalHardwareAccounts } from './utils';
7
+ export const [HardwareAccountsContext, useHardwareAccounts] = createSafeContext();
8
+ export const HardwareAccountsProvider = ({ children, }) => {
9
+ const [hardwareAccounts, setHardwareAccounts] = useState(getLocalHardwareAccounts());
10
+ const hardwareAccountExists = (source, network, address) => !!hardwareAccounts.find((a) => a.source === source && a.address === address && a.network === network);
11
+ const addHardwareAccount = (source, network, address, index, callback) => {
12
+ const exists = !!hardwareAccounts.find((a) => a.source === source && a.address === address && a.network === network);
13
+ if (!exists) {
14
+ const newAccount = {
15
+ address,
16
+ network,
17
+ name: ellipsisFn(address),
18
+ source,
19
+ index,
20
+ };
21
+ const newHardwareAccounts = [...hardwareAccounts].concat(newAccount);
22
+ localStorage.setItem(hardwareAccountsKey, JSON.stringify(newHardwareAccounts));
23
+ setHardwareAccounts(newHardwareAccounts);
24
+ if (typeof callback === 'function') {
25
+ callback();
26
+ }
27
+ return newAccount;
28
+ }
29
+ return null;
30
+ };
31
+ const removeHardwareAccount = (source, network, address, callback) => {
32
+ const newHardwareAccounts = [...hardwareAccounts].filter((a) => !(a.source === source && a.address === address && a.network === network));
33
+ if (!newHardwareAccounts.length) {
34
+ localStorage.removeItem(hardwareAccountsKey);
35
+ }
36
+ else {
37
+ localStorage.setItem(hardwareAccountsKey, JSON.stringify(newHardwareAccounts));
38
+ }
39
+ setHardwareAccounts(newHardwareAccounts);
40
+ if (typeof callback === 'function') {
41
+ callback();
42
+ }
43
+ };
44
+ const renameHardwareAccount = (source, network, address, newName) => {
45
+ const newHardwareAccounts = [...hardwareAccounts].map((a) => a.source === source && a.network === network && a.address === address
46
+ ? {
47
+ ...a,
48
+ name: newName,
49
+ }
50
+ : a);
51
+ localStorage.setItem(hardwareAccountsKey, JSON.stringify(newHardwareAccounts));
52
+ setHardwareAccounts(newHardwareAccounts);
53
+ };
54
+ const getHardwareAccount = (source, network, address) => hardwareAccounts.find((a) => a.source === source && a.network === network && a.address === address) || null;
55
+ const getHardwareAccounts = (source, network) => hardwareAccounts.filter((a) => a.source === source && a.network === network);
56
+ return (_jsx(HardwareAccountsContext.Provider, { value: {
57
+ hardwareAccountExists,
58
+ getHardwareAccount,
59
+ addHardwareAccount,
60
+ removeHardwareAccount,
61
+ renameHardwareAccount,
62
+ getHardwareAccounts,
63
+ }, children: children }));
64
+ };
65
+
66
+ //# sourceMappingURL=index.js.map
67
+
68
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/HardwareAccounts/index.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAE/C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAA;AAE5C,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhC,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAA;AAElD,MAAM,CAAC,MAAM,CAAC,uBAAuB,EAAE,mBAAmB,CAAC,GACzD,iBAAiB,EAAoC,CAAA;AAEvD,MAAM,CAAC,MAAM,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AmB,CAAC,CAAA;IAC1C,CAAC,CAAA;IAGD,MAAM,kBAAkB,GAAG,CACzB,MAA6B,EAC7B,OAAe,EACf,OAAe,EACf,EAAE,CACF,gBAAgB,CAAC,IAAI,CACnB,CAAC,CAAC,EAAE,EAAE,CACJ,CAAC,CAAC,MAAM,KAAK,MAAM,IAAI,CAAC,CAAC,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK,OAAO,CACxE,IAAI,IAAI,CAAA;IAGX,MAAM,mBAAmB,GAAG,CAC1B,MAA6B,EAC7B,OAAe,EACf,EAAE,CACF,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,IAAI,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC,CAAA;IAE9E,OAAO,CACL,KAAC,uBAAuB,CAAC,QAAQ,IAC/B,KAAK,EAAE;YACL,qBAAqB;YACrB,kBAAkB;YAClB,kBAAkB;YAClB,qBAAqB;YACrB,qBAAqB;YACrB,mBAAmB;SACpB,YAEA,QAAQ,GACwB,CACpC,CAAA;AACH,CAAC,CAAA","file":"index.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport { createSafeContext } from '@w3ux/hooks'\nimport type { HardwareAccount, HardwareAccountSource } from '@w3ux/types'\nimport { ellipsisFn } from '@w3ux/utils'\nimport { hardwareAccountsKey } from 'consts'\nimport type { ReactNode } from 'react'\nimport { useState } from 'react'\nimport type { HardwareAccountsContextInterface } from './types'\nimport { getLocalHardwareAccounts } from './utils'\n\nexport const [HardwareAccountsContext, useHardwareAccounts] =\n createSafeContext<HardwareAccountsContextInterface>()\n\nexport const HardwareAccountsProvider = ({\n children,\n}: {\n children: ReactNode\n}) => {\n // Store imported hardware accounts\n const [hardwareAccounts, setHardwareAccounts] = useState<HardwareAccount[]>(\n getLocalHardwareAccounts()\n )\n\n // Check if an account exists\n const hardwareAccountExists = (\n source: HardwareAccountSource,\n network: string,\n address: string\n ) =>\n !!hardwareAccounts.find(\n (a) =>\n a.source === source && a.address === address && a.network === network\n )\n\n // Adds an account\n const addHardwareAccount = (\n source: HardwareAccountSource,\n network: string,\n address: string,\n index: number,\n callback?: () => void\n ) => {\n const exists = !!hardwareAccounts.find(\n (a) =>\n a.source === source && a.address === address && a.network === network\n )\n\n if (!exists) {\n const newAccount: HardwareAccount = {\n address,\n network,\n name: ellipsisFn(address),\n source,\n index,\n }\n const newHardwareAccounts = [...hardwareAccounts].concat(newAccount)\n localStorage.setItem(\n hardwareAccountsKey,\n JSON.stringify(newHardwareAccounts)\n )\n setHardwareAccounts(newHardwareAccounts)\n // Handle optional callback function\n if (typeof callback === 'function') {\n callback()\n }\n return newAccount\n }\n return null\n }\n\n // Removes an account\n const removeHardwareAccount = (\n source: HardwareAccountSource,\n network: string,\n address: string,\n callback?: () => void\n ) => {\n const newHardwareAccounts = [...hardwareAccounts].filter(\n (a) =>\n !(a.source === source && a.address === address && a.network === network)\n )\n\n if (!newHardwareAccounts.length) {\n localStorage.removeItem(hardwareAccountsKey)\n } else {\n localStorage.setItem(\n hardwareAccountsKey,\n JSON.stringify(newHardwareAccounts)\n )\n }\n setHardwareAccounts(newHardwareAccounts)\n // Handle optional callback function\n if (typeof callback === 'function') {\n callback()\n }\n }\n\n // Renames an imported account\n const renameHardwareAccount = (\n source: HardwareAccountSource,\n network: string,\n address: string,\n newName: string\n ) => {\n const newHardwareAccounts = [...hardwareAccounts].map((a) =>\n a.source === source && a.network === network && a.address === address\n ? {\n ...a,\n name: newName,\n }\n : a\n )\n localStorage.setItem(\n hardwareAccountsKey,\n JSON.stringify(newHardwareAccounts)\n )\n setHardwareAccounts(newHardwareAccounts)\n }\n\n // Gets an imported account\n const getHardwareAccount = (\n source: HardwareAccountSource,\n network: string,\n address: string\n ) =>\n hardwareAccounts.find(\n (a) =>\n a.source === source && a.network === network && a.address === address\n ) || null\n\n // Gets all accounts for a network and source\n const getHardwareAccounts = (\n source: HardwareAccountSource,\n network: string\n ) =>\n hardwareAccounts.filter((a) => a.source === source && a.network === network)\n\n return (\n <HardwareAccountsContext.Provider\n value={{\n hardwareAccountExists,\n getHardwareAccount,\n addHardwareAccount,\n removeHardwareAccount,\n renameHardwareAccount,\n getHardwareAccounts,\n }}\n >\n {children}\n </HardwareAccountsContext.Provider>\n )\n}\n"]}
@@ -0,0 +1,9 @@
1
+ import type { HardwareAccount, HardwareAccountSource } from '@w3ux/types';
2
+ export interface HardwareAccountsContextInterface {
3
+ hardwareAccountExists: (source: HardwareAccountSource, network: string, a: string) => boolean;
4
+ addHardwareAccount: (source: HardwareAccountSource, network: string, address: string, index: number, callback?: () => void) => HardwareAccount | null;
5
+ removeHardwareAccount: (source: HardwareAccountSource, network: string, address: string, callback?: () => void) => void;
6
+ renameHardwareAccount: (source: HardwareAccountSource, network: string, address: string, name: string) => void;
7
+ getHardwareAccount: (source: HardwareAccountSource, network: string, address: string) => HardwareAccount | null;
8
+ getHardwareAccounts: (source: HardwareAccountSource, network: string) => HardwareAccount[];
9
+ }
@@ -0,0 +1,5 @@
1
+ export {};
2
+
3
+ //# sourceMappingURL=types.js.map
4
+
5
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/HardwareAccounts/types.ts"],"names":[],"mappings":"","file":"types.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport type { HardwareAccount, HardwareAccountSource } from '@w3ux/types'\n\nexport interface HardwareAccountsContextInterface {\n hardwareAccountExists: (\n source: HardwareAccountSource,\n network: string,\n a: string\n ) => boolean\n addHardwareAccount: (\n source: HardwareAccountSource,\n network: string,\n address: string,\n index: number,\n callback?: () => void\n ) => HardwareAccount | null\n removeHardwareAccount: (\n source: HardwareAccountSource,\n network: string,\n address: string,\n callback?: () => void\n ) => void\n renameHardwareAccount: (\n source: HardwareAccountSource,\n network: string,\n address: string,\n name: string\n ) => void\n getHardwareAccount: (\n source: HardwareAccountSource,\n network: string,\n address: string\n ) => HardwareAccount | null\n getHardwareAccounts: (\n source: HardwareAccountSource,\n network: string\n ) => HardwareAccount[]\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import type { HardwareAccount } from '@w3ux/types';
2
+ export declare const getLocalHardwareAccounts: () => HardwareAccount[];
@@ -0,0 +1,10 @@
1
+ import { localStorageOrDefault } from '@w3ux/utils';
2
+ import { hardwareAccountsKey } from 'consts';
3
+ export const getLocalHardwareAccounts = () => {
4
+ const accounts = localStorageOrDefault(hardwareAccountsKey, [], true);
5
+ return accounts;
6
+ };
7
+
8
+ //# sourceMappingURL=utils.js.map
9
+
10
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/HardwareAccounts/utils.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAA;AAG5C,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAsB,EAAE;IAC9D,MAAM,QAAQ,GAAG,qBAAqB,CACpC,mBAAmB,EACnB,EAAE,EACF,IAAI,CACgB,CAAA;IAEtB,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA","file":"utils.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport type { HardwareAccount } from '@w3ux/types'\nimport { localStorageOrDefault } from '@w3ux/utils'\nimport { hardwareAccountsKey } from 'consts'\n\n// Gets imported Ledger accounts from local storage\nexport const getLocalHardwareAccounts = (): HardwareAccount[] => {\n const accounts = localStorageOrDefault(\n hardwareAccountsKey,\n [],\n true\n ) as HardwareAccount[]\n\n return accounts\n}\n"]}
@@ -9,7 +9,6 @@ export const LedgerAccountsProvider = ({ children, }) => {
9
9
  const ledgerAccountExists = (network, address) => !!ledgerAccounts.find((a) => a.address === address && a.network === network);
10
10
  const addLedgerAccount = (network, address, index, callback) => {
11
11
  const exists = !!ledgerAccounts.find((a) => a.address === address && a.network === network);
12
- console.log('exists: ', exists);
13
12
  if (!exists) {
14
13
  const newAccount = {
15
14
  address,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/LedgerAccounts/index.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAE/C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhC,OAAO,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAA;AAEhD,MAAM,CAAC,MAAM,CAAC,qBAAqB,EAAE,iBAAiB,CAAC,GACrD,iBAAiB,EAAkC,CAAA;AAErD,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,EACrC,QAAQ,GAGT,EAAE,EAAE;IAEH,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,QAAQ,CAClD,sBAAsB,EAAE,CACzB,CAAA;IAGD,MAAM,mBAAmB,GAAG,CAAC,OAAe,EAAE,OAAe,EAAE,EAAE,CAC/D,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC,CAAA;IAG9E,MAAM,gBAAgB,GAAG,CACvB,OAAe,EACf,OAAe,EACf,KAAa,EACb,QAAqB,EACrB,EAAE;QACF,MAAM,MAAM,GAAG,CAAC,CAAC,cAAc,CAAC,IAAI,CAClC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK,OAAO,CACtD,CAAA;QAED,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,CAAA;QAC/B,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MA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EAAE;QACF,MAAM,iBAAiB,GAAG,CAAC,GAAG,cAAc,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CACtD,CAAC,CAAC,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK,OAAO;YAC5C,CAAC,CAAC;gBACE,GAAG,CAAC;gBACJ,IAAI,EAAE,OAAO;aACd;YACH,CAAC,CAAC,CAAC,CACN,CAAA;QACD,YAAY,CAAC,OAAO,CAAC,iBAAiB,EAAE,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC,CAAA;QAC1E,iBAAiB,CAAC,iBAAiB,CAAC,CAAA;IACtC,CAAC,CAAA;IAGD,MAAM,gBAAgB,GAAG,CAAC,OAAe,EAAE,OAAe,EAAE,EAAE,CAC5D,cAAc,CAAC,IAAI,CACjB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK,OAAO,CACtD,IAAI,IAAI,CAAA;IAGX,MAAM,iBAAiB,GAAG,CAAC,OAAe,EAAE,EAAE,CAC5C,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC,CAAA;IAErD,OAAO,CACL,KAAC,qBAAqB,CAAC,QAAQ,IAC7B,KAAK,EAAE;YACL,mBAAmB;YACnB,gBAAgB;YAChB,gBAAgB;YAChB,mBAAmB;YACnB,mBAAmB;YACnB,iBAAiB;SAClB,YAEA,QAAQ,GACsB,CAClC,CAAA;AACH,CAAC,CAAA","file":"index.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport { createSafeContext } from '@w3ux/hooks'\nimport type { HardwareAccount } from '@w3ux/types'\nimport { ellipsisFn } from '@w3ux/utils'\nimport type { ReactNode } from 'react'\nimport { useState } from 'react'\nimport type { LedgerAccountsContextInterface } from './types'\nimport { getLocalLedgerAccounts } from './utils'\n\nexport const [LedgerAccountsContext, useLedgerAccounts] =\n createSafeContext<LedgerAccountsContextInterface>()\n\nexport const LedgerAccountsProvider = ({\n children,\n}: {\n children: ReactNode\n}) => {\n // Store imported ledger accounts\n const [ledgerAccounts, setLedgerAccounts] = useState<HardwareAccount[]>(\n getLocalLedgerAccounts()\n )\n\n // Check if a Ledger account is imported\n const ledgerAccountExists = (network: string, address: string) =>\n !!ledgerAccounts.find((a) => a.address === address && a.network === network)\n\n // Adds a ledger account\n const addLedgerAccount = (\n network: string,\n address: string,\n index: number,\n callback?: () => void\n ) => {\n const exists = !!ledgerAccounts.find(\n (a) => a.address === address && a.network === network\n )\n\n console.log('exists: ', exists)\n if (!exists) {\n const newAccount = {\n address,\n network,\n name: ellipsisFn(address),\n source: 'ledger',\n index,\n }\n const newLedgerAccounts = [...ledgerAccounts].concat(newAccount)\n localStorage.setItem('ledger_accounts', JSON.stringify(newLedgerAccounts))\n setLedgerAccounts(newLedgerAccounts)\n\n // Handle optional callback function.\n if (typeof callback === 'function') {\n callback()\n }\n return newAccount\n }\n return null\n }\n\n // Removes a Ledger account\n const removeLedgerAccount = (\n network: string,\n address: string,\n callback?: () => void\n ) => {\n const newLedgerAccounts = [...ledgerAccounts].filter(\n (a) => !(a.address === address && a.network === network)\n )\n\n if (!newLedgerAccounts.length) {\n localStorage.removeItem('ledger_accounts')\n } else {\n localStorage.setItem('ledger_accounts', JSON.stringify(newLedgerAccounts))\n }\n\n setLedgerAccounts(newLedgerAccounts)\n // Handle optional callback function\n if (typeof callback === 'function') {\n callback()\n }\n }\n\n // Renames an imported ledger account\n const renameLedgerAccount = (\n network: string,\n address: string,\n newName: string\n ) => {\n const newLedgerAccounts = [...ledgerAccounts].map((a) =>\n a.network === network && a.address === address\n ? {\n ...a,\n name: newName,\n }\n : a\n )\n localStorage.setItem('ledger_accounts', JSON.stringify(newLedgerAccounts))\n setLedgerAccounts(newLedgerAccounts)\n }\n\n // Gets an imported ledger account\n const getLedgerAccount = (network: string, address: string) =>\n ledgerAccounts.find(\n (a) => a.network === network && a.address === address\n ) || null\n\n // Gets all Ledger accounts for a network\n const getLedgerAccounts = (network: string) =>\n ledgerAccounts.filter((a) => a.network === network)\n\n return (\n <LedgerAccountsContext.Provider\n value={{\n ledgerAccountExists,\n getLedgerAccount,\n addLedgerAccount,\n removeLedgerAccount,\n renameLedgerAccount,\n getLedgerAccounts,\n }}\n >\n {children}\n </LedgerAccountsContext.Provider>\n )\n}\n"]}
1
+ {"version":3,"sources":["../src/LedgerAccounts/index.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAE/C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhC,OAAO,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAA;AAEhD,MAAM,CAAC,MAAM,CAAC,qBAAqB,EAAE,iBAAiB,CAAC,GACrD,iBAAiB,EAAkC,CAAA;AAErD,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,EACrC,QAAQ,GAGT,EAAE,EAAE;IAEH,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,QAAQ,CAClD,sBAAsB,EAAE,CACzB,CAAA;IAGD,MAAM,mBAAmB,GAAG,CAAC,OAAe,EAAE,OAAe,EAAE,EAAE,CAC/D,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC,CAAA;IAG9E,MAAM,gBAAgB,GAAG,CACvB,OAAe,EACf,OAAe,EACf,KAAa,EACb,QAAqB,EACrB,EAAE;QACF,MAAM,MAAM,GAAG,CAAC,CAAC,cAAc,CAAC,IAAI,CAClC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAA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CAAA;QACZ,CAAC;IACH,CAAC,CAAA;IAGD,MAAM,mBAAmB,GAAG,CAC1B,OAAe,EACf,OAAe,EACf,OAAe,EACf,EAAE;QACF,MAAM,iBAAiB,GAAG,CAAC,GAAG,cAAc,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CACtD,CAAC,CAAC,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK,OAAO;YAC5C,CAAC,CAAC;gBACE,GAAG,CAAC;gBACJ,IAAI,EAAE,OAAO;aACd;YACH,CAAC,CAAC,CAAC,CACN,CAAA;QACD,YAAY,CAAC,OAAO,CAAC,iBAAiB,EAAE,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC,CAAA;QAC1E,iBAAiB,CAAC,iBAAiB,CAAC,CAAA;IACtC,CAAC,CAAA;IAGD,MAAM,gBAAgB,GAAG,CAAC,OAAe,EAAE,OAAe,EAAE,EAAE,CAC5D,cAAc,CAAC,IAAI,CACjB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK,OAAO,CACtD,IAAI,IAAI,CAAA;IAGX,MAAM,iBAAiB,GAAG,CAAC,OAAe,EAAE,EAAE,CAC5C,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC,CAAA;IAErD,OAAO,CACL,KAAC,qBAAqB,CAAC,QAAQ,IAC7B,KAAK,EAAE;YACL,mBAAmB;YACnB,gBAAgB;YAChB,gBAAgB;YAChB,mBAAmB;YACnB,mBAAmB;YACnB,iBAAiB;SAClB,YAEA,QAAQ,GACsB,CAClC,CAAA;AACH,CAAC,CAAA","file":"index.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport { createSafeContext } from '@w3ux/hooks'\nimport type { HardwareAccount } from '@w3ux/types'\nimport { ellipsisFn } from '@w3ux/utils'\nimport type { ReactNode } from 'react'\nimport { useState } from 'react'\nimport type { LedgerAccountsContextInterface } from './types'\nimport { getLocalLedgerAccounts } from './utils'\n\nexport const [LedgerAccountsContext, useLedgerAccounts] =\n createSafeContext<LedgerAccountsContextInterface>()\n\nexport const LedgerAccountsProvider = ({\n children,\n}: {\n children: ReactNode\n}) => {\n // Store imported ledger accounts\n const [ledgerAccounts, setLedgerAccounts] = useState<HardwareAccount[]>(\n getLocalLedgerAccounts()\n )\n\n // Check if a Ledger account is imported\n const ledgerAccountExists = (network: string, address: string) =>\n !!ledgerAccounts.find((a) => a.address === address && a.network === network)\n\n // Adds a ledger account\n const addLedgerAccount = (\n network: string,\n address: string,\n index: number,\n callback?: () => void\n ) => {\n const exists = !!ledgerAccounts.find(\n (a) => a.address === address && a.network === network\n )\n\n if (!exists) {\n const newAccount: HardwareAccount = {\n address,\n network,\n name: ellipsisFn(address),\n source: 'ledger',\n index,\n }\n const newLedgerAccounts = [...ledgerAccounts].concat(newAccount)\n localStorage.setItem('ledger_accounts', JSON.stringify(newLedgerAccounts))\n setLedgerAccounts(newLedgerAccounts)\n\n // Handle optional callback function.\n if (typeof callback === 'function') {\n callback()\n }\n return newAccount\n }\n return null\n }\n\n // Removes a Ledger account\n const removeLedgerAccount = (\n network: string,\n address: string,\n callback?: () => void\n ) => {\n const newLedgerAccounts = [...ledgerAccounts].filter(\n (a) => !(a.address === address && a.network === network)\n )\n\n if (!newLedgerAccounts.length) {\n localStorage.removeItem('ledger_accounts')\n } else {\n localStorage.setItem('ledger_accounts', JSON.stringify(newLedgerAccounts))\n }\n\n setLedgerAccounts(newLedgerAccounts)\n // Handle optional callback function\n if (typeof callback === 'function') {\n callback()\n }\n }\n\n // Renames an imported ledger account\n const renameLedgerAccount = (\n network: string,\n address: string,\n newName: string\n ) => {\n const newLedgerAccounts = [...ledgerAccounts].map((a) =>\n a.network === network && a.address === address\n ? {\n ...a,\n name: newName,\n }\n : a\n )\n localStorage.setItem('ledger_accounts', JSON.stringify(newLedgerAccounts))\n setLedgerAccounts(newLedgerAccounts)\n }\n\n // Gets an imported ledger account\n const getLedgerAccount = (network: string, address: string) =>\n ledgerAccounts.find(\n (a) => a.network === network && a.address === address\n ) || null\n\n // Gets all Ledger accounts for a network\n const getLedgerAccounts = (network: string) =>\n ledgerAccounts.filter((a) => a.network === network)\n\n return (\n <LedgerAccountsContext.Provider\n value={{\n ledgerAccountExists,\n getLedgerAccount,\n addLedgerAccount,\n removeLedgerAccount,\n renameLedgerAccount,\n getLedgerAccounts,\n }}\n >\n {children}\n </LedgerAccountsContext.Provider>\n )\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/VaultAccounts/index.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAE/C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhC,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAEtE,MAAM,CAAC,MAAM,CAAC,oBAAoB,EAAE,gBAAgB,CAAC,GACnD,iBAAiB,EAAiC,CAAA;AAEpD,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,EACpC,QAAQ,GAGT,EAAE,EAAE;IACH,MAAM,CAAC,aAAa,EAAE,eAAe,CAAC,GAAG,QAAQ,CAC/C,qBAAqB,EAAE,CACxB,CAAA;IAGD,MAAM,kBAAkB,GAAG,CAAC,OAAe,EAAE,OAAe,EAAE,EAAE,CAC9D,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC,CAAA;IAG7E,MAAM,eAAe,GAAG,CACtB,OAAe,EACf,OAAe,EACf,KAAa,EACb,QAAqB,EACrB,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,CAAC,OAAO,KAAK,OAAO,CAAC,CAAA;IAEpD,OAAO,CACL,KAAC,oBAAoB,CAAC,QAAQ,IAC5B,KAAK,EAAE;YACL,kBAAkB;YAClB,eAAe;YACf,kBAAkB;YAClB,kBAAkB;YAClB,eAAe;YACf,gBAAgB;SACjB,YAEA,QAAQ,GACqB,CACjC,CAAA;AACH,CAAC,CAAA","file":"index.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport { createSafeContext } from '@w3ux/hooks'\nimport type { HardwareAccount } from '@w3ux/types'\nimport { ellipsisFn } from '@w3ux/utils'\nimport type { ReactNode } from 'react'\nimport { useState } from 'react'\nimport type { VaultAccountsContextInterface } from './types'\nimport { getLocalVaultAccounts, isLocalNetworkAddress } from './utils'\n\nexport const [VaultAccountsContext, useVaultAccounts] =\n createSafeContext<VaultAccountsContextInterface>()\n\nexport const VaultAccountsProvider = ({\n children,\n}: {\n children: ReactNode\n}) => {\n const [vaultAccounts, seVaultAccounts] = useState<HardwareAccount[]>(\n getLocalVaultAccounts()\n )\n\n // Check if a Vault address exists in imported addresses.\n const vaultAccountExists = (network: string, address: string) =>\n !!vaultAccounts.find((a) => a.address === address && a.network === network)\n\n // Adds a vault account to state and local storage.\n const addVaultAccount = (\n network: string,\n address: string,\n index: number,\n callback?: () => void\n ) => {\n let newVaultAccounts = getLocalVaultAccounts()\n\n if (\n !newVaultAccounts.find((a) => isLocalNetworkAddress(network, a, address))\n ) {\n const account = {\n address,\n network,\n name: ellipsisFn(address),\n source: 'vault',\n index,\n }\n\n newVaultAccounts = [...newVaultAccounts].concat(account)\n localStorage.setItem(\n 'polkadot_vault_accounts',\n JSON.stringify(newVaultAccounts)\n )\n seVaultAccounts(newVaultAccounts)\n\n // Handle optional callback function.\n if (typeof callback === 'function') {\n callback()\n }\n return account\n }\n return null\n }\n\n const removeVaultAccount = (\n network: string,\n address: string,\n callback?: () => void\n ) => {\n let newVaultAccounts = getLocalVaultAccounts()\n\n newVaultAccounts = newVaultAccounts.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 (!newVaultAccounts.length) {\n localStorage.removeItem('polkadot_vault_accounts')\n } else {\n localStorage.setItem(\n 'polkadot_vault_accounts',\n JSON.stringify(newVaultAccounts)\n )\n }\n seVaultAccounts(newVaultAccounts)\n\n // Handle optional callback function.\n if (typeof callback === 'function') {\n callback()\n }\n }\n\n const getVaultAccount = (network: string, address: string) => {\n const localVaultAccounts = getLocalVaultAccounts()\n if (!localVaultAccounts) {\n return null\n }\n return (\n localVaultAccounts.find((a) =>\n isLocalNetworkAddress(network, a, address)\n ) ?? null\n )\n }\n\n const renameVaultAccount = (\n network: string,\n address: string,\n newName: string\n ) => {\n let newVaultAccounts = getLocalVaultAccounts()\n\n newVaultAccounts = newVaultAccounts.map((a) =>\n isLocalNetworkAddress(network, a, address)\n ? {\n ...a,\n name: newName,\n }\n : a\n )\n localStorage.setItem(\n 'polkadot_vault_accounts',\n JSON.stringify(newVaultAccounts)\n )\n seVaultAccounts(newVaultAccounts)\n }\n\n // Gets Vault accounts for a network.\n const getVaultAccounts = (network: string) =>\n vaultAccounts.filter((a) => a.network === network)\n\n return (\n <VaultAccountsContext.Provider\n value={{\n vaultAccountExists,\n addVaultAccount,\n removeVaultAccount,\n renameVaultAccount,\n getVaultAccount,\n getVaultAccounts,\n }}\n >\n {children}\n </VaultAccountsContext.Provider>\n )\n}\n"]}
1
+ {"version":3,"sources":["../src/VaultAccounts/index.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAE/C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhC,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAEtE,MAAM,CAAC,MAAM,CAAC,oBAAoB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,EAAE,CAAA;QAE9C,gBAAgB,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAC5C,qBAAqB,CAAC,OAAO,EAAE,CAAC,EAAE,OAAO,CAAC;YACxC,CAAC,CAAC;gBACE,GAAG,CAAC;gBACJ,IAAI,EAAE,OAAO;aACd;YACH,CAAC,CAAC,CAAC,CACN,CAAA;QACD,YAAY,CAAC,OAAO,CAClB,yBAAyB,EACzB,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,CACjC,CAAA;QACD,eAAe,CAAC,gBAAgB,CAAC,CAAA;IACnC,CAAC,CAAA;IAGD,MAAM,gBAAgB,GAAG,CAAC,OAAe,EAAE,EAAE,CAC3C,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC,CAAA;IAEpD,OAAO,CACL,KAAC,oBAAoB,CAAC,QAAQ,IAC5B,KAAK,EAAE;YACL,kBAAkB;YAClB,eAAe;YACf,kBAAkB;YAClB,kBAAkB;YAClB,eAAe;YACf,gBAAgB;SACjB,YAEA,QAAQ,GACqB,CACjC,CAAA;AACH,CAAC,CAAA","file":"index.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport { createSafeContext } from '@w3ux/hooks'\nimport type { HardwareAccount } from '@w3ux/types'\nimport { ellipsisFn } from '@w3ux/utils'\nimport type { ReactNode } from 'react'\nimport { useState } from 'react'\nimport type { VaultAccountsContextInterface } from './types'\nimport { getLocalVaultAccounts, isLocalNetworkAddress } from './utils'\n\nexport const [VaultAccountsContext, useVaultAccounts] =\n createSafeContext<VaultAccountsContextInterface>()\n\nexport const VaultAccountsProvider = ({\n children,\n}: {\n children: ReactNode\n}) => {\n const [vaultAccounts, seVaultAccounts] = useState<HardwareAccount[]>(\n getLocalVaultAccounts()\n )\n\n // Check if a Vault address exists in imported addresses.\n const vaultAccountExists = (network: string, address: string) =>\n !!vaultAccounts.find((a) => a.address === address && a.network === network)\n\n // Adds a vault account to state and local storage.\n const addVaultAccount = (\n network: string,\n address: string,\n index: number,\n callback?: () => void\n ) => {\n let newVaultAccounts = getLocalVaultAccounts()\n\n if (\n !newVaultAccounts.find((a) => isLocalNetworkAddress(network, a, address))\n ) {\n const account: HardwareAccount = {\n address,\n network,\n name: ellipsisFn(address),\n source: 'vault',\n index,\n }\n\n newVaultAccounts = [...newVaultAccounts].concat(account)\n localStorage.setItem(\n 'polkadot_vault_accounts',\n JSON.stringify(newVaultAccounts)\n )\n seVaultAccounts(newVaultAccounts)\n\n // Handle optional callback function.\n if (typeof callback === 'function') {\n callback()\n }\n return account\n }\n return null\n }\n\n const removeVaultAccount = (\n network: string,\n address: string,\n callback?: () => void\n ) => {\n let newVaultAccounts = getLocalVaultAccounts()\n\n newVaultAccounts = newVaultAccounts.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 (!newVaultAccounts.length) {\n localStorage.removeItem('polkadot_vault_accounts')\n } else {\n localStorage.setItem(\n 'polkadot_vault_accounts',\n JSON.stringify(newVaultAccounts)\n )\n }\n seVaultAccounts(newVaultAccounts)\n\n // Handle optional callback function.\n if (typeof callback === 'function') {\n callback()\n }\n }\n\n const getVaultAccount = (network: string, address: string) => {\n const localVaultAccounts = getLocalVaultAccounts()\n if (!localVaultAccounts) {\n return null\n }\n return (\n localVaultAccounts.find((a) =>\n isLocalNetworkAddress(network, a, address)\n ) ?? null\n )\n }\n\n const renameVaultAccount = (\n network: string,\n address: string,\n newName: string\n ) => {\n let newVaultAccounts = getLocalVaultAccounts()\n\n newVaultAccounts = newVaultAccounts.map((a) =>\n isLocalNetworkAddress(network, a, address)\n ? {\n ...a,\n name: newName,\n }\n : a\n )\n localStorage.setItem(\n 'polkadot_vault_accounts',\n JSON.stringify(newVaultAccounts)\n )\n seVaultAccounts(newVaultAccounts)\n }\n\n // Gets Vault accounts for a network.\n const getVaultAccounts = (network: string) =>\n vaultAccounts.filter((a) => a.network === network)\n\n return (\n <VaultAccountsContext.Provider\n value={{\n vaultAccountExists,\n addVaultAccount,\n removeVaultAccount,\n renameVaultAccount,\n getVaultAccount,\n getVaultAccounts,\n }}\n >\n {children}\n </VaultAccountsContext.Provider>\n )\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/WCAccounts/index.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAE/C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhC,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAEnE,MAAM,CAAC,MAAM,CAAC,iBAAiB,EAAE,aAAa,CAAC,GAC7C,iBAAiB,EAA8B,CAAA;AAEjD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,EAAE,QAAQ,EAA2B,EAAE,EAAE;IAC1E,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAC/B,QAAQ,CAAoB,kBAAkB,EAAE,CAAC,CAAA;IAGnD,MAAM,eAAe,GAAG,CAAC,OAAe,EAAE,OAAe,EAAE,EAAE,CAC3D,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC,CAAA;IAG1E,MAAM,YAAY,GAAG,CACnB,OAAe,EACf,OAAe,EACf,KAAa,EACb,QAAqB,EACrB,EAAE;QACF,IAAI,WAAW,GAAG,CAAC,GAAG,UAAU,CAAC,CAAA;QAEjC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,qBAAqB,CAAC,OAAO,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE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AAU,EAAE,CAAC;YACnC,QAAQ,EAAE,CAAA;QACZ,CAAC;IACH,CAAC,CAAA;IAED,MAAM,YAAY,GAAG,CAAC,OAAe,EAAE,OAAe,EAAE,EAAE,CACxD,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC,CAAA;IAExE,MAAM,eAAe,GAAG,CACtB,OAAe,EACf,OAAe,EACf,OAAe,EACf,EAAE;QACF,MAAM,WAAW,GAAG,CAAC,GAAG,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAC5C,qBAAqB,CAAC,OAAO,EAAE,CAAC,EAAE,OAAO,CAAC;YACxC,CAAC,CAAC;gBACE,GAAG,CAAC;gBACJ,IAAI,EAAE,OAAO;aACd;YACH,CAAC,CAAC,CAAC,CACN,CAAA;QACD,YAAY,CAAC,OAAO,CAAC,yBAAyB,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAA;QAE5E,aAAa,CAAC,WAAW,CAAC,CAAA;IAC5B,CAAC,CAAA;IAGD,MAAM,aAAa,GAAG,CAAC,OAAe,EAAE,EAAE,CACxC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC,CAAA;IAEjD,OAAO,CACL,KAAC,iBAAiB,CAAC,QAAQ,IACzB,KAAK,EAAE;YACL,eAAe;YACf,YAAY;YACZ,eAAe;YACf,eAAe;YACf,YAAY;YACZ,aAAa;SACd,YAEA,QAAQ,GACkB,CAC9B,CAAA;AACH,CAAC,CAAA","file":"index.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport { createSafeContext } from '@w3ux/hooks'\nimport type { HardwareAccount } from '@w3ux/types'\nimport { ellipsisFn } from '@w3ux/utils'\nimport type { ReactNode } from 'react'\nimport { useState } from 'react'\nimport type { WCAccountsContextInterface } from './types'\nimport { getLocalWcAccounts, isLocalNetworkAddress } from './utils'\n\nexport const [WCAccountsContext, useWcAccounts] =\n createSafeContext<WCAccountsContextInterface>()\n\nexport const WCAccountsProvider = ({ children }: { children: ReactNode }) => {\n const [wcAccounts, setWcAccounts] =\n useState<HardwareAccount[]>(getLocalWcAccounts())\n\n // Check if a Wallet Connect address exists in imported addresses.\n const wcAccountExists = (network: string, address: string) =>\n !!wcAccounts.find((a) => a.address === address && a.network === network)\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 = [...wcAccounts]\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 setWcAccounts(newAccounts)\n // Handle optional callback function\n if (typeof callback === 'function') {\n callback()\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 = [...wcAccounts]\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 setWcAccounts(newAccounts)\n\n // Handle optional callback function.\n if (typeof callback === 'function') {\n callback()\n }\n }\n\n const getWcAccount = (network: string, address: string) =>\n wcAccounts.find((a) => a.address === address && a.network === network)\n\n const renameWcAccount = (\n network: string,\n address: string,\n newName: string\n ) => {\n const newAccounts = [...wcAccounts].map((a) =>\n isLocalNetworkAddress(network, a, address)\n ? {\n ...a,\n name: newName,\n }\n : a\n )\n localStorage.setItem('wallet_connect_accounts', JSON.stringify(newAccounts))\n\n setWcAccounts(newAccounts)\n }\n\n // Gets Wallet Connect accounts for a network.\n const getWcAccounts = (network: string) =>\n wcAccounts.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 }}\n >\n {children}\n </WCAccountsContext.Provider>\n )\n}\n"]}
1
+ {"version":3,"sources":["../src/WCAccounts/index.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAE/C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhC,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAEnE,MAAM,CAAC,MAAM,CAAC,iBAAiB,EAAE,aAAa,CAAC,GAC7C,iBAAiB,EAA8B,CAAA;AAEjD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,EAAE,QAAQ,EAA2B,EAAE,EAAE;IAC1E,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAC/B,QAAQ,CAAoB,kBAAkB,EAAE,CAAC,CAAA;IAGnD,MAAM,eAAe,GAAG,CAAC,OAAe,EAAE,OAAe,EAAE,EAAE,CAC3D,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC,CAAA;IAG1E,MAAM,YAAY,GAAG,CACnB,OAAe,EACf,OAAe,EACf,KAAa,EACb,QAAqB,EACrB,EAAE;QACF,IAAI,WAAW,GAAG,CAAC,GAAG,UAAU,CAAC,CAAA;QAEjC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,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C;QACD,aAAa,CAAC,WAAW,CAAC,CAAA;QAG1B,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE,CAAC;YACnC,QAAQ,EAAE,CAAA;QACZ,CAAC;IACH,CAAC,CAAA;IAED,MAAM,YAAY,GAAG,CAAC,OAAe,EAAE,OAAe,EAAE,EAAE,CACxD,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC,CAAA;IAExE,MAAM,eAAe,GAAG,CACtB,OAAe,EACf,OAAe,EACf,OAAe,EACf,EAAE;QACF,MAAM,WAAW,GAAG,CAAC,GAAG,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAC5C,qBAAqB,CAAC,OAAO,EAAE,CAAC,EAAE,OAAO,CAAC;YACxC,CAAC,CAAC;gBACE,GAAG,CAAC;gBACJ,IAAI,EAAE,OAAO;aACd;YACH,CAAC,CAAC,CAAC,CACN,CAAA;QACD,YAAY,CAAC,OAAO,CAAC,yBAAyB,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAA;QAE5E,aAAa,CAAC,WAAW,CAAC,CAAA;IAC5B,CAAC,CAAA;IAGD,MAAM,aAAa,GAAG,CAAC,OAAe,EAAE,EAAE,CACxC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC,CAAA;IAEjD,OAAO,CACL,KAAC,iBAAiB,CAAC,QAAQ,IACzB,KAAK,EAAE;YACL,eAAe;YACf,YAAY;YACZ,eAAe;YACf,eAAe;YACf,YAAY;YACZ,aAAa;SACd,YAEA,QAAQ,GACkB,CAC9B,CAAA;AACH,CAAC,CAAA","file":"index.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport { createSafeContext } from '@w3ux/hooks'\nimport type { HardwareAccount } from '@w3ux/types'\nimport { ellipsisFn } from '@w3ux/utils'\nimport type { ReactNode } from 'react'\nimport { useState } from 'react'\nimport type { WCAccountsContextInterface } from './types'\nimport { getLocalWcAccounts, isLocalNetworkAddress } from './utils'\n\nexport const [WCAccountsContext, useWcAccounts] =\n createSafeContext<WCAccountsContextInterface>()\n\nexport const WCAccountsProvider = ({ children }: { children: ReactNode }) => {\n const [wcAccounts, setWcAccounts] =\n useState<HardwareAccount[]>(getLocalWcAccounts())\n\n // Check if a Wallet Connect address exists in imported addresses.\n const wcAccountExists = (network: string, address: string) =>\n !!wcAccounts.find((a) => a.address === address && a.network === network)\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 = [...wcAccounts]\n\n if (!newAccounts.find((a) => isLocalNetworkAddress(network, a, address))) {\n const account: HardwareAccount = {\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 setWcAccounts(newAccounts)\n // Handle optional callback function\n if (typeof callback === 'function') {\n callback()\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 = [...wcAccounts]\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 setWcAccounts(newAccounts)\n\n // Handle optional callback function.\n if (typeof callback === 'function') {\n callback()\n }\n }\n\n const getWcAccount = (network: string, address: string) =>\n wcAccounts.find((a) => a.address === address && a.network === network)\n\n const renameWcAccount = (\n network: string,\n address: string,\n newName: string\n ) => {\n const newAccounts = [...wcAccounts].map((a) =>\n isLocalNetworkAddress(network, a, address)\n ? {\n ...a,\n name: newName,\n }\n : a\n )\n localStorage.setItem('wallet_connect_accounts', JSON.stringify(newAccounts))\n\n setWcAccounts(newAccounts)\n }\n\n // Gets Wallet Connect accounts for a network.\n const getWcAccounts = (network: string) =>\n wcAccounts.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 }}\n >\n {children}\n </WCAccountsContext.Provider>\n )\n}\n"]}
package/consts.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const hardwareAccountsKey = "hardware_accounts";
package/consts.js ADDED
@@ -0,0 +1,5 @@
1
+ export const hardwareAccountsKey = 'hardware_accounts';
2
+
3
+ //# sourceMappingURL=consts.js.map
4
+
5
+ //# sourceMappingURL=consts.js.map
package/consts.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/consts.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,mBAAmB,GAAG,mBAAmB,CAAA","file":"consts.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\n// Local storage hardware accounts key\nexport const hardwareAccountsKey = 'hardware_accounts'\n"]}
package/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './ExtensionAccounts';
2
2
  export * from './Extensions';
3
+ export * from './HardwareAccounts';
3
4
  export * from './LedgerAccounts';
4
5
  export * from './VaultAccounts';
5
6
  export * from './WCAccounts';
package/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './ExtensionAccounts';
2
2
  export * from './Extensions';
3
+ export * from './HardwareAccounts';
3
4
  export * from './LedgerAccounts';
4
5
  export * from './VaultAccounts';
5
6
  export * from './WCAccounts';
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,qBAAqB,CAAA;AACnC,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA","file":"index.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nexport * from './ExtensionAccounts'\nexport * from './Extensions'\nexport * from './LedgerAccounts'\nexport * from './VaultAccounts'\nexport * from './WCAccounts'\n"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,qBAAqB,CAAA;AACnC,cAAc,cAAc,CAAA;AAC5B,cAAc,oBAAoB,CAAA;AAClC,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA","file":"index.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nexport * from './ExtensionAccounts'\nexport * from './Extensions'\nexport * from './HardwareAccounts'\nexport * from './LedgerAccounts'\nexport * from './VaultAccounts'\nexport * from './WCAccounts'\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@w3ux/react-connect-kit",
3
- "version": "3.2.24-alpha.2",
3
+ "version": "3.2.24-alpha.4",
4
4
  "license": "GPL-3.0-only",
5
5
  "dependencies": {
6
6
  "@w3ux/extension-assets": "^2.2.0",