@w3ux/react-connect-kit 3.2.22 → 3.2.24-alpha.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.
- package/ExtensionAccounts/defaults.js.map +1 -0
- package/{ExtensionAccountsProvider → ExtensionAccounts}/index.js +1 -1
- package/ExtensionAccounts/index.js.map +1 -0
- package/ExtensionAccounts/types.js.map +1 -0
- package/{ExtensionsProvider → Extensions}/index.js +0 -6
- package/Extensions/index.js.map +1 -0
- package/{ExtensionsProvider → Extensions}/types.d.ts +0 -1
- package/Extensions/types.js.map +1 -0
- package/LedgerAccounts/index.d.ts +6 -0
- package/LedgerAccounts/index.js +66 -0
- package/LedgerAccounts/index.js.map +1 -0
- package/LedgerAccounts/types.d.ts +9 -0
- package/LedgerAccounts/types.js.map +1 -0
- package/LedgerAccounts/utils.d.ts +2 -0
- package/LedgerAccounts/utils.js +11 -0
- package/LedgerAccounts/utils.js.map +1 -0
- package/VaultAccounts/index.d.ts +6 -0
- package/{VaultAccountsProvider → VaultAccounts}/index.js +8 -10
- package/VaultAccounts/index.js.map +1 -0
- package/VaultAccounts/types.d.ts +9 -0
- package/VaultAccounts/types.js.map +1 -0
- package/{VaultAccountsProvider → VaultAccounts}/utils.d.ts +2 -2
- package/VaultAccounts/utils.js.map +1 -0
- package/WCAccounts/index.d.ts +6 -0
- package/{WCAccountsProvider → WCAccounts}/index.js +12 -14
- package/WCAccounts/index.js.map +1 -0
- package/WCAccounts/types.d.ts +9 -0
- package/WCAccounts/types.js.map +1 -0
- package/{WCAccountsProvider → WCAccounts}/utils.d.ts +2 -2
- package/WCAccounts/utils.js.map +1 -0
- package/index.d.ts +5 -5
- package/index.js +5 -5
- package/index.js.map +1 -1
- package/package.json +3 -3
- package/types.d.ts +4 -4
- package/types.js +4 -4
- package/types.js.map +1 -1
- package/ExtensionAccountsProvider/defaults.js.map +0 -1
- package/ExtensionAccountsProvider/index.js.map +0 -1
- package/ExtensionAccountsProvider/types.js.map +0 -1
- package/ExtensionsProvider/index.js.map +0 -1
- package/ExtensionsProvider/types.js.map +0 -1
- package/LedgerAccountsProvider/index.d.ts +0 -3
- package/LedgerAccountsProvider/index.js +0 -86
- package/LedgerAccountsProvider/index.js.map +0 -1
- package/LedgerAccountsProvider/types.d.ts +0 -21
- package/LedgerAccountsProvider/types.js.map +0 -1
- package/LedgerAccountsProvider/utils.d.ts +0 -9
- package/LedgerAccountsProvider/utils.js +0 -29
- package/LedgerAccountsProvider/utils.js.map +0 -1
- package/VaultAccountsProvider/index.d.ts +0 -3
- package/VaultAccountsProvider/index.js.map +0 -1
- package/VaultAccountsProvider/types.d.ts +0 -15
- package/VaultAccountsProvider/types.js.map +0 -1
- package/VaultAccountsProvider/utils.js.map +0 -1
- package/WCAccountsProvider/index.d.ts +0 -3
- package/WCAccountsProvider/index.js.map +0 -1
- package/WCAccountsProvider/types.d.ts +0 -15
- package/WCAccountsProvider/types.js.map +0 -1
- package/WCAccountsProvider/utils.js.map +0 -1
- /package/{ExtensionAccountsProvider → ExtensionAccounts}/defaults.d.ts +0 -0
- /package/{ExtensionAccountsProvider → ExtensionAccounts}/defaults.js +0 -0
- /package/{ExtensionAccountsProvider → ExtensionAccounts}/index.d.ts +0 -0
- /package/{ExtensionAccountsProvider → ExtensionAccounts}/types.d.ts +0 -0
- /package/{ExtensionAccountsProvider → ExtensionAccounts}/types.js +0 -0
- /package/{ExtensionsProvider → Extensions}/index.d.ts +0 -0
- /package/{ExtensionsProvider → Extensions}/types.js +0 -0
- /package/{LedgerAccountsProvider → LedgerAccounts}/types.js +0 -0
- /package/{VaultAccountsProvider → VaultAccounts}/types.js +0 -0
- /package/{VaultAccountsProvider → VaultAccounts}/utils.js +0 -0
- /package/{WCAccountsProvider → WCAccounts}/types.js +0 -0
- /package/{WCAccountsProvider → WCAccounts}/utils.js +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/ExtensionAccounts/defaults.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,MAAM,6BAA6B,GAAmC;IAC3E,WAAW,EAAE,EAAE;IACf,eAAe,EAAE,EAAE;CACpB,CAAA","file":"defaults.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport type { ProcessExtensionAccountsResult } from '@w3ux/types'\n\nexport const defaultProcessExtensionResult: ProcessExtensionAccountsResult = {\n newAccounts: [],\n removedAccounts: [],\n}\n"]}
|
|
@@ -6,7 +6,7 @@ import { connectExtension as doConnectExtension, reconnectExtensions, } from '@w
|
|
|
6
6
|
import { formatAccountSs58 } from '@w3ux/utils';
|
|
7
7
|
import { useEffect, useState } from 'react';
|
|
8
8
|
import { combineLatest } from 'rxjs';
|
|
9
|
-
import { useExtensions } from '../
|
|
9
|
+
import { useExtensions } from '../Extensions';
|
|
10
10
|
export const [ExtensionAccountsContext, useExtensionAccounts] = createSafeContext();
|
|
11
11
|
export const ExtensionAccountsProvider = ({ children, ss58, dappName, }) => {
|
|
12
12
|
const { gettingExtensions } = useExtensions();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/ExtensionAccounts/index.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,sBAAsB,EACtB,cAAc,EACd,aAAa,GACd,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAA;AAC7D,OAAO,EACL,gBAAgB,IAAI,kBAAkB,EACtC,mBAAmB,GACpB,MAAM,sCAAsC,CAAA;AAE7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,MAAM,CAAA;AACpC,OAAO,EAAE,aAAa,EAAE,MA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,CAAC;SACD,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,KAAK,IAAI,CAAC,CAAA;IAG1C,SAAS,CAAC,GAAG,EAAE;QACb,oBAAoB,EAAE,CAAA;QACtB,OAAO,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAA;IACzB,CAAC,EAAE,CAAC,iBAAiB,CAAC,CAAC,CAAA;IAGvB,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,GAAG,GAAG,aAAa,CAAC;YACxB,sBAAsB;YACtB,kBAAkB;YAClB,cAAc;SACf,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE;YAC7C,wBAAwB,CAAC,WAAW,CAAC,CAAA;YACrC,oBAAoB,CAAC,QAAQ,CAAC,CAAA;YAC9B,mBAAmB,CAAC,IAAI,CAAC,CAAA;QAC3B,CAAC,CAAC,CAAA;QACF,OAAO,GAAG,EAAE;YACV,GAAG,CAAC,WAAW,EAAE,CAAA;QACnB,CAAC,CAAA;IACH,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO,CACL,KAAC,wBAAwB,CAAC,QAAQ,IAChC,KAAK,EAAE;YACL,qBAAqB;YACrB,gBAAgB;YAChB,gBAAgB;YAChB,oBAAoB;SACrB,YAEA,QAAQ,GACyB,CACrC,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 {\n extensionAccounts$,\n getReconnectSync,\n initialisedExtensions$,\n reconnectSync$,\n resetAccounts,\n} from '@w3ux/observables-connect'\nimport { unsubAll } from '@w3ux/observables-connect/accounts'\nimport {\n connectExtension as doConnectExtension,\n reconnectExtensions,\n} from '@w3ux/observables-connect/extensions'\nimport type { ImportedAccount, Sync } from '@w3ux/types'\nimport { formatAccountSs58 } from '@w3ux/utils'\nimport { useEffect, useState } from 'react'\nimport { combineLatest } from 'rxjs'\nimport { useExtensions } from '../Extensions'\nimport type {\n ExtensionAccountsContextInterface,\n ExtensionAccountsProviderProps,\n} from './types'\n\nexport const [ExtensionAccountsContext, useExtensionAccounts] =\n createSafeContext<ExtensionAccountsContextInterface>()\n\nexport const ExtensionAccountsProvider = ({\n children,\n ss58,\n dappName,\n}: ExtensionAccountsProviderProps) => {\n const { gettingExtensions } = useExtensions()\n\n // Store connected extension accounts\n const [extensionAccounts, setExtensionAccounts] = useState<ImportedAccount[]>(\n []\n )\n // Stores initialised extensions\n const [extensionsInitialised, setExtensionsInitialised] = useState<string[]>(\n []\n )\n // Store whether previously enabled extensions have been re-connected\n const [extensionsSynced, setExtensionsSynced] = useState<Sync>('unsynced')\n\n // Handle initial connection to previously enabled extensions\n const handleInitialConnect = async () => {\n if (!gettingExtensions && getReconnectSync() === 'unsynced') {\n // Defensive: unsubscribe from all accounts and reset state\n unsubAll()\n resetAccounts()\n await reconnectExtensions(dappName, ss58)\n }\n }\n\n // Connects to a single extension and processes its accounts\n const connectExtension = async (id: string): Promise<boolean> =>\n await doConnectExtension(dappName, ss58, id)\n\n // Get extension accounts, formatted by a provided ss58 prefix\n const getExtensionAccounts = (ss58Prefix: number): ImportedAccount[] =>\n extensionAccounts\n .map((account) => {\n const formattedAddress = formatAccountSs58(account.address, ss58Prefix)\n if (!formattedAddress) {\n return null\n }\n return {\n ...account,\n address: formattedAddress,\n }\n })\n .filter((account) => account !== null)\n\n // Initialise extension accounts sync\n useEffect(() => {\n handleInitialConnect()\n return () => unsubAll()\n }, [gettingExtensions])\n\n // Subscribes to observables and updates state\n useEffect(() => {\n const sub = combineLatest([\n initialisedExtensions$,\n extensionAccounts$,\n reconnectSync$,\n ]).subscribe(([initialised, accounts, sync]) => {\n setExtensionsInitialised(initialised)\n setExtensionAccounts(accounts)\n setExtensionsSynced(sync)\n })\n return () => {\n sub.unsubscribe()\n }\n }, [])\n\n return (\n <ExtensionAccountsContext.Provider\n value={{\n extensionsInitialised,\n connectExtension,\n extensionsSynced,\n getExtensionAccounts,\n }}\n >\n {children}\n </ExtensionAccountsContext.Provider>\n )\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/ExtensionAccounts/types.ts"],"names":[],"mappings":"","file":"types.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport type { ImportedAccount, Sync } from '@w3ux/types'\nimport type { ReactNode } from 'react'\n\nexport interface ExtensionAccountsContextInterface {\n extensionsInitialised: string[]\n connectExtension: (id: string) => Promise<boolean>\n extensionsSynced: Sync\n getExtensionAccounts: (ss58: number) => ImportedAccount[]\n}\n\nexport interface ExtensionAccountsProviderProps {\n children: ReactNode\n ss58: number\n dappName: string\n}\n"]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import extensions from '@w3ux/extension-assets';
|
|
3
2
|
import { createSafeContext } from '@w3ux/hooks';
|
|
4
3
|
import { canConnect, extensionsStatus$, getStatus, gettingExtensions$, removeStatus, setStatus, } from '@w3ux/observables-connect';
|
|
5
4
|
import { getExtensions } from '@w3ux/observables-connect/extensions';
|
|
@@ -17,10 +16,6 @@ export const ExtensionsProvider = ({ children }) => {
|
|
|
17
16
|
};
|
|
18
17
|
const extensionInstalled = (id) => getStatus(id) !== undefined;
|
|
19
18
|
const extensionCanConnect = (id) => canConnect(id);
|
|
20
|
-
const extensionHasFeature = (id, feature) => {
|
|
21
|
-
const features = extensions[id]?.features || [];
|
|
22
|
-
return features === '*' || features.includes(feature);
|
|
23
|
-
};
|
|
24
19
|
useEffect(() => {
|
|
25
20
|
getExtensions();
|
|
26
21
|
const sub = combineLatest([
|
|
@@ -41,7 +36,6 @@ export const ExtensionsProvider = ({ children }) => {
|
|
|
41
36
|
removeExtensionStatus,
|
|
42
37
|
extensionInstalled,
|
|
43
38
|
extensionCanCon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CAAC,CAAA;IAGnE,SAAS,CAAC,GAAG,EAAE;QACb,aAAa,EAAE,CAAA;QACf,MAAM,GAAG,GAAG,aAAa,CAAC;YACxB,kBAAkB;YAClB,iBAAiB;SAClB,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,EAAE;YACjC,oBAAoB,CAAC,OAAO,CAAC,CAAA;YAC7B,mBAAmB,CAAC,MAAM,CAAC,CAAA;QAC7B,CAAC,CAAC,CAAA;QACF,OAAO,GAAG,EAAE;YACV,GAAG,CAAC,WAAW,EAAE,CAAA;QACnB,CAAC,CAAA;IACH,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO,CACL,KAAC,iBAAiB,CAAC,QAAQ,IACzB,KAAK,EAAE;YACL,gBAAgB;YAChB,iBAAiB;YACjB,kBAAkB;YAClB,qBAAqB;YACrB,kBAAkB;YAClB,mBAAmB;SACpB,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 {\n canConnect,\n extensionsStatus$,\n getStatus,\n gettingExtensions$,\n removeStatus,\n setStatus,\n} from '@w3ux/observables-connect'\nimport { getExtensions } from '@w3ux/observables-connect/extensions'\nimport type { ExtensionsStatus, ExtensionStatus } from '@w3ux/types'\nimport { type ReactNode, useEffect, useState } from 'react'\nimport { combineLatest } from 'rxjs'\nimport type { ExtensionsContextInterface } from './types'\n\nexport const [ExtensionsContext, useExtensions] =\n createSafeContext<ExtensionsContextInterface>()\n\nexport const ExtensionsProvider = ({ children }: { children: ReactNode }) => {\n // Store whether extensions are being fetched\n const [gettingExtensions, setGettingExtensions] = useState<boolean>(true)\n\n // Store discovered extensions along with their status\n const [extensionsStatus, setExtensionsStatus] = useState<ExtensionsStatus>({})\n\n // Setter for an extension status\n const setExtensionStatus = (id: string, status: ExtensionStatus) => {\n setStatus(id, status)\n }\n\n // Removes an extension status\n const removeExtensionStatus = (id: string) => {\n removeStatus(id)\n }\n\n // Checks if an extension has been installed\n const extensionInstalled = (id: string): boolean =>\n getStatus(id) !== undefined\n\n // Checks whether an extension can be connected to\n const extensionCanConnect = (id: string): boolean => canConnect(id)\n\n // Subscribes to observables and updates state\n useEffect(() => {\n getExtensions()\n const sub = combineLatest([\n gettingExtensions$,\n extensionsStatus$,\n ]).subscribe(([getting, status]) => {\n setGettingExtensions(getting)\n setExtensionsStatus(status)\n })\n return () => {\n sub.unsubscribe()\n }\n }, [])\n\n return (\n <ExtensionsContext.Provider\n value={{\n extensionsStatus,\n gettingExtensions,\n setExtensionStatus,\n removeExtensionStatus,\n extensionInstalled,\n extensionCanConnect,\n }}\n >\n {children}\n </ExtensionsContext.Provider>\n )\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/Extensions/types.ts"],"names":[],"mappings":"","file":"types.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport type { ExtensionStatus } from '@w3ux/types'\n\n// Extensions context interface.\nexport interface ExtensionsContextInterface {\n gettingExtensions: boolean\n extensionsStatus: Record<string, ExtensionStatus>\n setExtensionStatus: (id: string, status: ExtensionStatus) => void\n removeExtensionStatus: (id: string) => void\n extensionInstalled: (id: string) => boolean\n extensionCanConnect: (id: string) => boolean\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { LedgerAccountsContextInterface } from './types';
|
|
3
|
+
export declare const LedgerAccountsContext: import("react").Context<LedgerAccountsContextInterface>, useLedgerAccounts: () => LedgerAccountsContextInterface;
|
|
4
|
+
export declare const LedgerAccountsProvider: ({ children, }: {
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createSafeContext } from '@w3ux/hooks';
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { getLocalLedgerAccounts } from './utils';
|
|
5
|
+
export const [LedgerAccountsContext, useLedgerAccounts] = createSafeContext();
|
|
6
|
+
export const LedgerAccountsProvider = ({ children, }) => {
|
|
7
|
+
const [ledgerAccounts, setLedgerAccounts] = useState(getLocalLedgerAccounts());
|
|
8
|
+
const ledgerAccountExists = (network, address) => !!ledgerAccounts.find((a) => a.address === address && a.network === network);
|
|
9
|
+
const addLedgerAccount = (network, address, index, callback) => {
|
|
10
|
+
const exists = ledgerAccounts.find((a) => a.address === address);
|
|
11
|
+
if (!exists) {
|
|
12
|
+
const newAccount = {
|
|
13
|
+
address,
|
|
14
|
+
network,
|
|
15
|
+
name: `Ledger ${index + 1}`,
|
|
16
|
+
source: 'ledger',
|
|
17
|
+
index,
|
|
18
|
+
};
|
|
19
|
+
const newLedgerAccounts = [...ledgerAccounts].concat(newAccount);
|
|
20
|
+
localStorage.setItem('ledger_accounts', JSON.stringify(newLedgerAccounts));
|
|
21
|
+
setLedgerAccounts(newLedgerAccounts);
|
|
22
|
+
if (typeof callback === 'function') {
|
|
23
|
+
callback();
|
|
24
|
+
}
|
|
25
|
+
return newAccount;
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
};
|
|
29
|
+
const removeLedgerAccount = (network, address, callback) => {
|
|
30
|
+
const newLedgerAccounts = [...ledgerAccounts].filter((a) => !(a.address === address && a.network === network));
|
|
31
|
+
if (!newLedgerAccounts.length) {
|
|
32
|
+
localStorage.removeItem('ledger_accounts');
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
localStorage.setItem('ledger_accounts', JSON.stringify(newLedgerAccounts));
|
|
36
|
+
}
|
|
37
|
+
setLedgerAccounts(newLedgerAccounts);
|
|
38
|
+
if (typeof callback === 'function') {
|
|
39
|
+
callback();
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const renameLedgerAccount = (network, address, newName) => {
|
|
43
|
+
const newLedgerAccounts = [...ledgerAccounts].map((a) => a.network === network && a.address === address
|
|
44
|
+
? {
|
|
45
|
+
...a,
|
|
46
|
+
name: newName,
|
|
47
|
+
}
|
|
48
|
+
: a);
|
|
49
|
+
localStorage.setItem('ledger_accounts', JSON.stringify(newLedgerAccounts));
|
|
50
|
+
setLedgerAccounts(newLedgerAccounts);
|
|
51
|
+
};
|
|
52
|
+
const getLedgerAccount = (network, address) => ledgerAccounts.find((a) => a.network === network && a.address === address) || null;
|
|
53
|
+
const getLedgerAccounts = (network) => ledgerAccounts.filter((a) => a.network === network);
|
|
54
|
+
return (_jsx(LedgerAccountsContext.Provider, { value: {
|
|
55
|
+
ledgerAccountExists,
|
|
56
|
+
getLedgerAccount,
|
|
57
|
+
addLedgerAccount,
|
|
58
|
+
removeLedgerAccount,
|
|
59
|
+
renameLedgerAccount,
|
|
60
|
+
getLedgerAccounts,
|
|
61
|
+
}, children: children }));
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
//# sourceMappingURL=index.js.map
|
|
65
|
+
|
|
66
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/LedgerAccounts/index.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAG/C,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,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C,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 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((a) => a.address === address)\n\n if (!exists) {\n const newAccount = {\n address,\n network,\n name: `Ledger ${index + 1}`,\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"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { HardwareAccount } from '@w3ux/types';
|
|
2
|
+
export interface LedgerAccountsContextInterface {
|
|
3
|
+
ledgerAccountExists: (network: string, a: string) => boolean;
|
|
4
|
+
addLedgerAccount: (network: string, address: string, index: number, callback?: () => void) => HardwareAccount | null;
|
|
5
|
+
removeLedgerAccount: (network: string, address: string, callback?: () => void) => void;
|
|
6
|
+
renameLedgerAccount: (network: string, address: string, name: string) => void;
|
|
7
|
+
getLedgerAccount: (network: string, address: string) => HardwareAccount | null;
|
|
8
|
+
getLedgerAccounts: (network: string) => HardwareAccount[];
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/LedgerAccounts/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 } from '@w3ux/types'\n\nexport interface LedgerAccountsContextInterface {\n ledgerAccountExists: (network: string, a: string) => boolean\n addLedgerAccount: (\n network: string,\n address: string,\n index: number,\n callback?: () => void\n ) => HardwareAccount | null\n removeLedgerAccount: (\n network: string,\n address: string,\n callback?: () => void\n ) => void\n renameLedgerAccount: (network: string, address: string, name: string) => void\n getLedgerAccount: (network: string, address: string) => HardwareAccount | null\n getLedgerAccounts: (network: string) => HardwareAccount[]\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { localStorageOrDefault } from '@w3ux/utils';
|
|
2
|
+
export const getLocalLedgerAccounts = (network) => {
|
|
3
|
+
const localAddresses = localStorageOrDefault('ledger_accounts', [], true);
|
|
4
|
+
return network
|
|
5
|
+
? localAddresses.filter((a) => a.network === network)
|
|
6
|
+
: localAddresses;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=utils.js.map
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/LedgerAccounts/utils.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAGnD,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,OAAgB,EAAqB,EAAE;IAC5E,MAAM,cAAc,GAAG,qBAAqB,CAC1C,iBAAiB,EACjB,EAAE,EACF,IAAI,CACgB,CAAA;IAEtB,OAAO,OAAO;QACZ,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC;QACrD,CAAC,CAAC,cAAc,CAAA;AACpB,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'\n\n// Gets imported Ledger accounts from local storage\nexport const getLocalLedgerAccounts = (network?: string): HardwareAccount[] => {\n const localAddresses = localStorageOrDefault(\n 'ledger_accounts',\n [],\n true\n ) as HardwareAccount[]\n\n return network\n ? localAddresses.filter((a) => a.network === network)\n : localAddresses\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { VaultAccountsContextInterface } from './types';
|
|
3
|
+
export declare const VaultAccountsContext: import("react").Context<VaultAccountsContextInterface>, useVaultAccounts: () => VaultAccountsContextInterface;
|
|
4
|
+
export declare const VaultAccountsProvider: ({ children, }: {
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { createSafeContext } from '@w3ux/hooks';
|
|
3
|
-
import { ellipsisFn
|
|
4
|
-
import {
|
|
3
|
+
import { ellipsisFn } from '@w3ux/utils';
|
|
4
|
+
import { useState } from 'react';
|
|
5
5
|
import { getLocalVaultAccounts, isLocalNetworkAddress } from './utils';
|
|
6
6
|
export const [VaultAccountsContext, useVaultAccounts] = createSafeContext();
|
|
7
7
|
export const VaultAccountsProvider = ({ children, }) => {
|
|
8
|
-
const [vaultAccounts,
|
|
9
|
-
const
|
|
10
|
-
const vaultAccountExists = (network, address) => !!getLocalVaultAccounts().find((a) => isLocalNetworkAddress(network, a, address));
|
|
8
|
+
const [vaultAccounts, seVaultAccounts] = useState(getLocalVaultAccounts());
|
|
9
|
+
const vaultAccountExists = (network, address) => !!vaultAccounts.find((a) => a.address === address && a.network === network);
|
|
11
10
|
const addVaultAccount = (network, address, index, callback) => {
|
|
12
11
|
let newVaultAccounts = getLocalVaultAccounts();
|
|
13
12
|
if (!newVaultAccounts.find((a) => isLocalNetworkAddress(network, a, address))) {
|
|
@@ -20,7 +19,7 @@ export const VaultAccountsProvider = ({ children, }) => {
|
|
|
20
19
|
};
|
|
21
20
|
newVaultAccounts = [...newVaultAccounts].concat(account);
|
|
22
21
|
localStorage.setItem('polkadot_vault_accounts', JSON.stringify(newVaultAccounts));
|
|
23
|
-
|
|
22
|
+
seVaultAccounts(newVaultAccounts);
|
|
24
23
|
if (typeof callback === 'function') {
|
|
25
24
|
callback();
|
|
26
25
|
}
|
|
@@ -45,7 +44,7 @@ export const VaultAccountsProvider = ({ children, }) => {
|
|
|
45
44
|
else {
|
|
46
45
|
localStorage.setItem('polkadot_vault_accounts', JSON.stringify(newVaultAccounts));
|
|
47
46
|
}
|
|
48
|
-
|
|
47
|
+
seVaultAccounts(newVaultAccounts);
|
|
49
48
|
if (typeof callback === 'function') {
|
|
50
49
|
callback();
|
|
51
50
|
}
|
|
@@ -66,9 +65,9 @@ export const VaultAccountsProvider = ({ children, }) => {
|
|
|
66
65
|
}
|
|
67
66
|
: a);
|
|
68
67
|
localStorage.setItem('polkadot_vault_accounts', JSON.stringify(newVaultAccounts));
|
|
69
|
-
|
|
68
|
+
seVaultAccounts(newVaultAccounts);
|
|
70
69
|
};
|
|
71
|
-
const getVaultAccounts = (network) =>
|
|
70
|
+
const getVaultAccounts = (network) => vaultAccounts.filter((a) => a.network === network);
|
|
72
71
|
return (_jsx(VaultAccountsContext.Provider, { value: {
|
|
73
72
|
vaultAccountExists,
|
|
74
73
|
addVaultAccount,
|
|
@@ -76,7 +75,6 @@ export const VaultAccountsProvider = ({ children, }) => {
|
|
|
76
75
|
renameVaultAccount,
|
|
77
76
|
getVaultAccount,
|
|
78
77
|
getVaultAccounts,
|
|
79
|
-
vaultAccounts: vaultAccountsRef.current,
|
|
80
78
|
}, children: children }));
|
|
81
79
|
};
|
|
82
80
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/VaultAccounts/index.tsx"],"names":[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,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAC5B,qBAAqB,CAAC,OAAO,EAAE,CAAC,EAAE,OAAO,CAAC,CAC3C,IAAI,IAAI,CACV,CAAA;IACH,CAAC,CAAA;IAED,MAAM,kBAAkB,GAAG,CACzB,OAAe,EACf,OAAe,EACf,OAAe,EACf,EAAE;QACF,IAAI,gBAAgB,GAAG,qBAAqB,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 = {\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"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { HardwareAccount } from '@w3ux/types';
|
|
2
|
+
export interface VaultAccountsContextInterface {
|
|
3
|
+
vaultAccountExists: (network: string, address: string) => boolean;
|
|
4
|
+
addVaultAccount: (network: string, address: string, index: number, callback?: () => void) => HardwareAccount | null;
|
|
5
|
+
removeVaultAccount: (network: string, address: string, callback?: () => void) => void;
|
|
6
|
+
renameVaultAccount: (network: string, address: string, newName: string) => void;
|
|
7
|
+
getVaultAccount: (network: string, address: string) => HardwareAccount | null;
|
|
8
|
+
getVaultAccounts: (network: string) => HardwareAccount[];
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/VaultAccounts/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 } from '@w3ux/types'\n\nexport interface VaultAccountsContextInterface {\n vaultAccountExists: (network: string, address: string) => boolean\n addVaultAccount: (\n network: string,\n address: string,\n index: number,\n callback?: () => void\n ) => HardwareAccount | null\n removeVaultAccount: (\n network: string,\n address: string,\n callback?: () => void\n ) => void\n renameVaultAccount: (\n network: string,\n address: string,\n newName: string\n ) => void\n getVaultAccount: (network: string, address: string) => HardwareAccount | null\n getVaultAccounts: (network: string) => HardwareAccount[]\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const getLocalVaultAccounts: (network?: string) =>
|
|
1
|
+
import type { HardwareAccount } from '@w3ux/types';
|
|
2
|
+
export declare const getLocalVaultAccounts: (network?: string) => HardwareAccount[];
|
|
3
3
|
export declare const isLocalNetworkAddress: (chain: string, a: {
|
|
4
4
|
address: string | undefined;
|
|
5
5
|
network: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/VaultAccounts/utils.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAGnD,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,OAAgB,EAAE,EAAE;IACxD,MAAM,cAAc,GAAG,qBAAqB,CAC1C,yBAAyB,EACzB,EAAE,EACF,IAAI,CACgB,CAAA;IAEtB,OAAO,OAAO;QACZ,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC;QACrD,CAAC,CAAC,cAAc,CAAA;AACpB,CAAC,CAAA;AAGD,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,KAAa,EACb,CAAmD,EACnD,OAAe,EACf,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK,KAAK,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'\n\n// Gets imported Vault accounts from local storage.\nexport const getLocalVaultAccounts = (network?: string) => {\n const localAddresses = localStorageOrDefault(\n 'polkadot_vault_accounts',\n [],\n true\n ) as HardwareAccount[]\n\n return network\n ? localAddresses.filter((a) => a.network === network)\n : localAddresses\n}\n\n// Gets whether an address is a local network address.\nexport const isLocalNetworkAddress = (\n chain: string,\n a: { address: string | undefined; network: string },\n address: string\n) => a.address === address && a.network === chain\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { WCAccountsContextInterface } from './types';
|
|
3
|
+
export declare const WCAccountsContext: import("react").Context<WCAccountsContextInterface>, useWcAccounts: () => WCAccountsContextInterface;
|
|
4
|
+
export declare const WCAccountsProvider: ({ children }: {
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { createSafeContext } from '@w3ux/hooks';
|
|
3
|
-
import { ellipsisFn
|
|
4
|
-
import {
|
|
3
|
+
import { ellipsisFn } from '@w3ux/utils';
|
|
4
|
+
import { useState } from 'react';
|
|
5
5
|
import { getLocalWcAccounts, isLocalNetworkAddress } from './utils';
|
|
6
6
|
export const [WCAccountsContext, useWcAccounts] = createSafeContext();
|
|
7
7
|
export const WCAccountsProvider = ({ children }) => {
|
|
8
|
-
const [wcAccounts,
|
|
9
|
-
const
|
|
10
|
-
const wcAccountExists = (network, address) => !!wcAccountsRef.current.find((a) => isLocalNetworkAddress(network, a, address));
|
|
8
|
+
const [wcAccounts, setWcAccounts] = useState(getLocalWcAccounts());
|
|
9
|
+
const wcAccountExists = (network, address) => !!wcAccounts.find((a) => a.address === address && a.network === network);
|
|
11
10
|
const addWcAccount = (network, address, index, callback) => {
|
|
12
|
-
let newAccounts = [...
|
|
11
|
+
let newAccounts = [...wcAccounts];
|
|
13
12
|
if (!newAccounts.find((a) => isLocalNetworkAddress(network, a, address))) {
|
|
14
13
|
const account = {
|
|
15
14
|
address,
|
|
@@ -20,7 +19,7 @@ export const WCAccountsProvider = ({ children }) => {
|
|
|
20
19
|
};
|
|
21
20
|
newAccounts = [...newAccounts].concat(account);
|
|
22
21
|
localStorage.setItem('wallet_connect_accounts', JSON.stringify(newAccounts));
|
|
23
|
-
|
|
22
|
+
setWcAccounts(newAccounts);
|
|
24
23
|
if (typeof callback === 'function') {
|
|
25
24
|
callback();
|
|
26
25
|
}
|
|
@@ -29,7 +28,7 @@ export const WCAccountsProvider = ({ children }) => {
|
|
|
29
28
|
return null;
|
|
30
29
|
};
|
|
31
30
|
const removeWcAccount = (network, address, callback) => {
|
|
32
|
-
let newAccounts = [...
|
|
31
|
+
let newAccounts = [...wcAccounts];
|
|
33
32
|
newAccounts = newAccounts.filter((a) => {
|
|
34
33
|
if (a.address !== address) {
|
|
35
34
|
return true;
|
|
@@ -45,23 +44,23 @@ export const WCAccountsProvider = ({ children }) => {
|
|
|
45
44
|
else {
|
|
46
45
|
localStorage.setItem('wallet_connect_accounts', JSON.stringify(newAccounts));
|
|
47
46
|
}
|
|
48
|
-
|
|
47
|
+
setWcAccounts(newAccounts);
|
|
49
48
|
if (typeof callback === 'function') {
|
|
50
49
|
callback();
|
|
51
50
|
}
|
|
52
51
|
};
|
|
53
|
-
const getWcAccount = (network, address) =>
|
|
52
|
+
const getWcAccount = (network, address) => wcAccounts.find((a) => a.address === address && a.network === network);
|
|
54
53
|
const renameWcAccount = (network, address, newName) => {
|
|
55
|
-
const newAccounts =
|
|
54
|
+
const newAccounts = [...wcAccounts].map((a) => isLocalNetworkAddress(network, a, address)
|
|
56
55
|
? {
|
|
57
56
|
...a,
|
|
58
57
|
name: newName,
|
|
59
58
|
}
|
|
60
59
|
: a);
|
|
61
60
|
localStorage.setItem('wallet_connect_accounts', JSON.stringify(newAccounts));
|
|
62
|
-
|
|
61
|
+
setWcAccounts(newAccounts);
|
|
63
62
|
};
|
|
64
|
-
const getWcAccounts = (network) =>
|
|
63
|
+
const getWcAccounts = (network) => wcAccounts.filter((a) => a.network === network);
|
|
65
64
|
return (_jsx(WCAccountsContext.Provider, { value: {
|
|
66
65
|
wcAccountExists,
|
|
67
66
|
addWcAccount,
|
|
@@ -69,7 +68,6 @@ export const WCAccountsProvider = ({ children }) => {
|
|
|
69
68
|
renameWcAccount,
|
|
70
69
|
getWcAccount,
|
|
71
70
|
getWcAccounts,
|
|
72
|
-
wcAccounts: wcAccountsRef.current,
|
|
73
71
|
}, children: children }));
|
|
74
72
|
};
|
|
75
73
|
|
|
@@ -0,0 +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,CAA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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 = {\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"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { HardwareAccount } from '@w3ux/types';
|
|
2
|
+
export interface WCAccountsContextInterface {
|
|
3
|
+
wcAccountExists: (network: string, address: string) => boolean;
|
|
4
|
+
addWcAccount: (network: string, address: string, index: number, callback?: () => void) => HardwareAccount | null;
|
|
5
|
+
removeWcAccount: (network: string, address: string, callback?: () => void) => void;
|
|
6
|
+
renameWcAccount: (network: string, address: string, newName: string) => void;
|
|
7
|
+
getWcAccount: (network: string, address: string) => HardwareAccount | null;
|
|
8
|
+
getWcAccounts: (network: string) => HardwareAccount[];
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/WCAccounts/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 } from '@w3ux/types'\n\nexport interface WCAccountsContextInterface {\n wcAccountExists: (network: string, address: string) => boolean\n addWcAccount: (\n network: string,\n address: string,\n index: number,\n callback?: () => void\n ) => HardwareAccount | null\n removeWcAccount: (\n network: string,\n address: string,\n callback?: () => void\n ) => void\n renameWcAccount: (network: string, address: string, newName: string) => void\n getWcAccount: (network: string, address: string) => HardwareAccount | null\n getWcAccounts: (network: string) => HardwareAccount[]\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const getLocalWcAccounts: (network?: string) =>
|
|
1
|
+
import type { HardwareAccount } from '@w3ux/types';
|
|
2
|
+
export declare const getLocalWcAccounts: (network?: string) => HardwareAccount[];
|
|
3
3
|
export declare const isLocalNetworkAddress: (chain: string, a: {
|
|
4
4
|
address: string | undefined;
|
|
5
5
|
network: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/WCAccounts/utils.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAGnD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,OAAgB,EAAE,EAAE;IACrD,MAAM,cAAc,GAAG,qBAAqB,CAC1C,yBAAyB,EACzB,EAAE,EACF,IAAI,CACgB,CAAA;IAEtB,OAAO,OAAO;QACZ,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC;QACrD,CAAC,CAAC,cAAc,CAAA;AACpB,CAAC,CAAA;AAGD,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,KAAa,EACb,CAAmD,EACnD,OAAe,EACf,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK,KAAK,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'\n\n// Gets imported Wallet Connect accounts from local storage.\nexport const getLocalWcAccounts = (network?: string) => {\n const localAddresses = localStorageOrDefault(\n 'wallet_connect_accounts',\n [],\n true\n ) as HardwareAccount[]\n\n return network\n ? localAddresses.filter((a) => a.network === network)\n : localAddresses\n}\n\n// Gets whether an address is a local network address.\nexport const isLocalNetworkAddress = (\n chain: string,\n a: { address: string | undefined; network: string },\n address: string\n) => a.address === address && a.network === chain\n"]}
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
1
|
+
export * from './ExtensionAccounts';
|
|
2
|
+
export * from './Extensions';
|
|
3
|
+
export * from './LedgerAccounts';
|
|
4
|
+
export * from './VaultAccounts';
|
|
5
|
+
export * from './WCAccounts';
|
package/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
1
|
+
export * from './ExtensionAccounts';
|
|
2
|
+
export * from './Extensions';
|
|
3
|
+
export * from './LedgerAccounts';
|
|
4
|
+
export * from './VaultAccounts';
|
|
5
|
+
export * from './WCAccounts';
|
|
6
6
|
|
|
7
7
|
//# sourceMappingURL=index.js.map
|
|
8
8
|
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,
|
|
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"]}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@w3ux/react-connect-kit",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.24-alpha.1",
|
|
4
4
|
"license": "GPL-3.0-only",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@w3ux/extension-assets": "^2.2.0",
|
|
7
7
|
"@w3ux/hooks": "^2.1.0",
|
|
8
|
-
"@w3ux/observables-connect": "0.9.
|
|
9
|
-
"@w3ux/utils": "^2.0.
|
|
8
|
+
"@w3ux/observables-connect": "0.9.31",
|
|
9
|
+
"@w3ux/utils": "^2.0.9"
|
|
10
10
|
},
|
|
11
11
|
"type": "module",
|
|
12
12
|
"peerDependencies": {
|
package/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
1
|
+
export * from './ExtensionAccounts/types';
|
|
2
|
+
export * from './Extensions/types';
|
|
3
|
+
export * from './LedgerAccounts/types';
|
|
4
|
+
export * from './VaultAccounts/types';
|
package/types.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
1
|
+
export * from './ExtensionAccounts/types';
|
|
2
|
+
export * from './Extensions/types';
|
|
3
|
+
export * from './LedgerAccounts/types';
|
|
4
|
+
export * from './VaultAccounts/types';
|
|
5
5
|
|
|
6
6
|
//# sourceMappingURL=types.js.map
|
|
7
7
|
|
package/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"names":[],"mappings":"AAGA,cAAc,
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"names":[],"mappings":"AAGA,cAAc,2BAA2B,CAAA;AACzC,cAAc,oBAAoB,CAAA;AAClC,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA","file":"types.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nexport * from './ExtensionAccounts/types'\nexport * from './Extensions/types'\nexport * from './LedgerAccounts/types'\nexport * from './VaultAccounts/types'\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ExtensionAccountsProvider/defaults.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,MAAM,6BAA6B,GAAmC;IAC3E,WAAW,EAAE,EAAE;IACf,eAAe,EAAE,EAAE;CACpB,CAAA","file":"defaults.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport type { ProcessExtensionAccountsResult } from '@w3ux/types'\n\nexport const defaultProcessExtensionResult: ProcessExtensionAccountsResult = {\n newAccounts: [],\n removedAccounts: [],\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ExtensionAccountsProvider/index.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,sBAAsB,EACtB,cAAc,EACd,aAAa,GACd,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAA;AAC7D,OAAO,EACL,gBAAgB,IAAI,kBAAkB,EACtC,mBAAmB,GACpB,MAAM,sCAAsC,CAAA;AAE7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,MAAM,CAAA;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAMrD,MAAM,CAAC,MAAM,CAAC,wBAAwB,EAAE,oBAAoB,CAAC,GAC3D,iBAAiB,EAAqC,CAAA;AAExD,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,EACxC,QAAQ,EACR,IAAI,EACJ,QAAQ,GACuB,EAAE,EAAE;IACnC,MAAM,EAAE,iBAAiB,EAAE,GAAG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AGvB,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,GAAG,GAAG,aAAa,CAAC;YACxB,sBAAsB;YACtB,kBAAkB;YAClB,cAAc;SACf,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE;YAC7C,wBAAwB,CAAC,WAAW,CAAC,CAAA;YACrC,oBAAoB,CAAC,QAAQ,CAAC,CAAA;YAC9B,mBAAmB,CAAC,IAAI,CAAC,CAAA;QAC3B,CAAC,CAAC,CAAA;QACF,OAAO,GAAG,EAAE;YACV,GAAG,CAAC,WAAW,EAAE,CAAA;QACnB,CAAC,CAAA;IACH,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO,CACL,KAAC,wBAAwB,CAAC,QAAQ,IAChC,KAAK,EAAE;YACL,qBAAqB;YACrB,gBAAgB;YAChB,gBAAgB;YAChB,oBAAoB;SACrB,YAEA,QAAQ,GACyB,CACrC,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 {\n extensionAccounts$,\n getReconnectSync,\n initialisedExtensions$,\n reconnectSync$,\n resetAccounts,\n} from '@w3ux/observables-connect'\nimport { unsubAll } from '@w3ux/observables-connect/accounts'\nimport {\n connectExtension as doConnectExtension,\n reconnectExtensions,\n} from '@w3ux/observables-connect/extensions'\nimport type { ImportedAccount, Sync } from '@w3ux/types'\nimport { formatAccountSs58 } from '@w3ux/utils'\nimport { useEffect, useState } from 'react'\nimport { combineLatest } from 'rxjs'\nimport { useExtensions } from '../ExtensionsProvider'\nimport type {\n ExtensionAccountsContextInterface,\n ExtensionAccountsProviderProps,\n} from './types'\n\nexport const [ExtensionAccountsContext, useExtensionAccounts] =\n createSafeContext<ExtensionAccountsContextInterface>()\n\nexport const ExtensionAccountsProvider = ({\n children,\n ss58,\n dappName,\n}: ExtensionAccountsProviderProps) => {\n const { gettingExtensions } = useExtensions()\n\n // Store connected extension accounts\n const [extensionAccounts, setExtensionAccounts] = useState<ImportedAccount[]>(\n []\n )\n // Stores initialised extensions\n const [extensionsInitialised, setExtensionsInitialised] = useState<string[]>(\n []\n )\n // Store whether previously enabled extensions have been re-connected\n const [extensionsSynced, setExtensionsSynced] = useState<Sync>('unsynced')\n\n // Handle initial connection to previously enabled extensions\n const handleInitialConnect = async () => {\n if (!gettingExtensions && getReconnectSync() === 'unsynced') {\n // Defensive: unsubscribe from all accounts and reset state\n unsubAll()\n resetAccounts()\n await reconnectExtensions(dappName, ss58)\n }\n }\n\n // Connects to a single extension and processes its accounts\n const connectExtension = async (id: string): Promise<boolean> =>\n await doConnectExtension(dappName, ss58, id)\n\n // Get extension accounts, formatted by a provided ss58 prefix\n const getExtensionAccounts = (ss58Prefix: number): ImportedAccount[] =>\n extensionAccounts\n .map((account) => {\n const formattedAddress = formatAccountSs58(account.address, ss58Prefix)\n if (!formattedAddress) {\n return null\n }\n return {\n ...account,\n address: formattedAddress,\n }\n })\n .filter((account) => account !== null)\n\n // Initialise extension accounts sync\n useEffect(() => {\n handleInitialConnect()\n return () => unsubAll()\n }, [gettingExtensions])\n\n // Subscribes to observables and updates state\n useEffect(() => {\n const sub = combineLatest([\n initialisedExtensions$,\n extensionAccounts$,\n reconnectSync$,\n ]).subscribe(([initialised, accounts, sync]) => {\n setExtensionsInitialised(initialised)\n setExtensionAccounts(accounts)\n setExtensionsSynced(sync)\n })\n return () => {\n sub.unsubscribe()\n }\n }, [])\n\n return (\n <ExtensionAccountsContext.Provider\n value={{\n extensionsInitialised,\n connectExtension,\n extensionsSynced,\n getExtensionAccounts,\n }}\n >\n {children}\n </ExtensionAccountsContext.Provider>\n )\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ExtensionAccountsProvider/types.ts"],"names":[],"mappings":"","file":"types.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport type { ImportedAccount, Sync } from '@w3ux/types'\nimport type { ReactNode } from 'react'\n\nexport interface ExtensionAccountsContextInterface {\n extensionsInitialised: string[]\n connectExtension: (id: string) => Promise<boolean>\n extensionsSynced: Sync\n getExtensionAccounts: (ss58: number) => ImportedAccount[]\n}\n\nexport interface ExtensionAccountsProviderProps {\n children: ReactNode\n ss58: number\n dappName: string\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ExtensionsProvider/index.tsx"],"names":[],"mappings":";AAGA,OAAO,UAAU,MAAM,wBAAwB,CAAA;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,SAAS,EACT,kBAAkB,EAClB,YAAY,EACZ,SAAS,GACV,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAA;AAEpE,OAAO,EAAkB,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,MAAM,CAAA;AAGpC,MAAM,CAAC,MAAM,CAAC,iBAAiB,EAAE,aAAa,CAAC,GAC7C,iBAAiB,EAA8B,CAAA;AAEjD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,EAAE,QAAQ,EAA2B,EAAE,EAAE;IAE1E,MAAM,CAAC,iBAAiB,EAAE,oBAAoB,CAAC,GAAG,QAAQ,CAAU,IAAI,CAAC,CAAA;IAGzE,MAAM,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,GAAG,QAAQ,CAAmB,EAAE,CAAC,CAAA;IAG9E,MAAM,kBAAkB,GAAG,CAAC,EAAU,EAAE,MAAuB,EAAE,EAAE;QACjE,SAAS,CAAC,EAAE,EAAE,MAAM,CAAC,CAAA;IACvB,CAAC,CAAA;IAGD,MAAM,qBAAqB,GAAG,CAAC,EAAU,EAAE,EAAE;QAC3C,YAAY,CAAC,EAAE,CAAC,CAAA;IAClB,CAAC,CAAA;IAGD,MAAM,kBAAkB,GAAG,CAAC,EAAU,EAAW,EAAE,CACjD,SAAS,CAAC,EAAE,CAAC,KAAK,SAAS,CAAA;IAG7B,MAAM,mBAAmB,GAAG,CAAC,EAAU,EAAW,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,CAAA;IAGnE,MAAM,mBAAmB,GAAG,CAAC,EAAU,EAAE,OAAe,EAAW,EAAE;QACnE,MAAM,QAAQ,GAAG,UAAU,CAAC,EAAE,CAAC,EAAE,QAAQ,IAAI,EAAE,CAAA;QAC/C,OAAO,QAAQ,KAAK,GAAG,IAAI,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;IACvD,CAAC,CAAA;IAGD,SAAS,CAAC,GAAG,EAAE;QACb,aAAa,EAAE,CAAA;QACf,MAAM,GAAG,GAAG,aAAa,CAAC;YACxB,kBAAkB;YAClB,iBAAiB;SAClB,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,EAAE;YACjC,oBAAoB,CAAC,OAAO,CAAC,CAAA;YAC7B,mBAAmB,CAAC,MAAM,CAAC,CAAA;QAC7B,CAAC,CAAC,CAAA;QACF,OAAO,GAAG,EAAE;YACV,GAAG,CAAC,WAAW,EAAE,CAAA;QACnB,CAAC,CAAA;IACH,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO,CACL,KAAC,iBAAiB,CAAC,QAAQ,IACzB,KAAK,EAAE;YACL,gBAAgB;YAChB,iBAAiB;YACjB,kBAAkB;YAClB,qBAAqB;YACrB,kBAAkB;YAClB,mBAAmB;YACnB,mBAAmB;SACpB,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 extensions from '@w3ux/extension-assets'\nimport { createSafeContext } from '@w3ux/hooks'\nimport {\n canConnect,\n extensionsStatus$,\n getStatus,\n gettingExtensions$,\n removeStatus,\n setStatus,\n} from '@w3ux/observables-connect'\nimport { getExtensions } from '@w3ux/observables-connect/extensions'\nimport type { ExtensionsStatus, ExtensionStatus } from '@w3ux/types'\nimport { type ReactNode, useEffect, useState } from 'react'\nimport { combineLatest } from 'rxjs'\nimport type { ExtensionsContextInterface } from './types'\n\nexport const [ExtensionsContext, useExtensions] =\n createSafeContext<ExtensionsContextInterface>()\n\nexport const ExtensionsProvider = ({ children }: { children: ReactNode }) => {\n // Store whether extensions are being fetched\n const [gettingExtensions, setGettingExtensions] = useState<boolean>(true)\n\n // Store discovered extensions along with their status\n const [extensionsStatus, setExtensionsStatus] = useState<ExtensionsStatus>({})\n\n // Setter for an extension status\n const setExtensionStatus = (id: string, status: ExtensionStatus) => {\n setStatus(id, status)\n }\n\n // Removes an extension status\n const removeExtensionStatus = (id: string) => {\n removeStatus(id)\n }\n\n // Checks if an extension has been installed\n const extensionInstalled = (id: string): boolean =>\n getStatus(id) !== undefined\n\n // Checks whether an extension can be connected to\n const extensionCanConnect = (id: string): boolean => canConnect(id)\n\n // Checks whether an extension supports a feature\n const extensionHasFeature = (id: string, feature: string): boolean => {\n const features = extensions[id]?.features || []\n return features === '*' || features.includes(feature)\n }\n\n // Subscribes to observables and updates state\n useEffect(() => {\n getExtensions()\n const sub = combineLatest([\n gettingExtensions$,\n extensionsStatus$,\n ]).subscribe(([getting, status]) => {\n setGettingExtensions(getting)\n setExtensionsStatus(status)\n })\n return () => {\n sub.unsubscribe()\n }\n }, [])\n\n return (\n <ExtensionsContext.Provider\n value={{\n extensionsStatus,\n gettingExtensions,\n setExtensionStatus,\n removeExtensionStatus,\n extensionInstalled,\n extensionCanConnect,\n extensionHasFeature,\n }}\n >\n {children}\n </ExtensionsContext.Provider>\n )\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ExtensionsProvider/types.ts"],"names":[],"mappings":"","file":"types.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport type { ExtensionStatus } from '@w3ux/types'\n\n// Extensions context interface.\nexport interface ExtensionsContextInterface {\n gettingExtensions: boolean\n extensionsStatus: Record<string, ExtensionStatus>\n setExtensionStatus: (id: string, status: ExtensionStatus) => void\n removeExtensionStatus: (id: string) => void\n extensionInstalled: (id: string) => boolean\n extensionCanConnect: (id: string) => boolean\n extensionHasFeature: (id: string, feature: string) => boolean\n}\n"]}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { LedgerAccountsContextInterface, LedgerAccountsProviderProps } from './types';
|
|
2
|
-
export declare const LedgerAccountsContext: import("react").Context<LedgerAccountsContextInterface>, useLedgerAccounts: () => LedgerAccountsContextInterface;
|
|
3
|
-
export declare const LedgerAccountsProvider: ({ children, }: LedgerAccountsProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { createSafeContext } from '@w3ux/hooks';
|
|
3
|
-
import { setStateWithRef } from '@w3ux/utils';
|
|
4
|
-
import { useRef, useState } from 'react';
|
|
5
|
-
import { getLocalLedgerAccounts, getLocalLedgerAddresses, isLocalLedgerAccount, renameLocalLedgerAddress, } from './utils';
|
|
6
|
-
export const [LedgerAccountsContext, useLedgerAccounts] = createSafeContext();
|
|
7
|
-
export const LedgerAccountsProvider = ({ children, }) => {
|
|
8
|
-
const [ledgerAccounts, setLedgerAccountsState] = useState(getLocalLedgerAccounts());
|
|
9
|
-
const ledgerAccountsRef = useRef(ledgerAccounts);
|
|
10
|
-
const ledgerAccountExists = (network, address) => !!getLocalLedgerAccounts().find((account) => isLocalLedgerAccount(network, account, address));
|
|
11
|
-
const addLedgerAccount = (network, address, index, callback) => {
|
|
12
|
-
let newLedgerAccounts = getLocalLedgerAccounts();
|
|
13
|
-
const ledgerAddress = getLocalLedgerAddresses().find((a) => isLocalLedgerAccount(network, a, address));
|
|
14
|
-
if (ledgerAddress &&
|
|
15
|
-
!newLedgerAccounts.find((account) => isLocalLedgerAccount(network, account, address))) {
|
|
16
|
-
const newAccount = {
|
|
17
|
-
address,
|
|
18
|
-
network,
|
|
19
|
-
name: ledgerAddress.name,
|
|
20
|
-
source: 'ledger',
|
|
21
|
-
index,
|
|
22
|
-
};
|
|
23
|
-
newLedgerAccounts = [...newLedgerAccounts].concat(newAccount);
|
|
24
|
-
localStorage.setItem('ledger_accounts', JSON.stringify(newLedgerAccounts));
|
|
25
|
-
setStateWithRef(newLedgerAccounts.filter((account) => account.network === network), setLedgerAccountsState, ledgerAccountsRef);
|
|
26
|
-
if (typeof callback === 'function') {
|
|
27
|
-
callback();
|
|
28
|
-
}
|
|
29
|
-
return newAccount;
|
|
30
|
-
}
|
|
31
|
-
return null;
|
|
32
|
-
};
|
|
33
|
-
const removeLedgerAccount = (network, address, callback) => {
|
|
34
|
-
const newLedgerAccounts = getLocalLedgerAccounts().filter((account) => {
|
|
35
|
-
if (account.address !== address) {
|
|
36
|
-
return true;
|
|
37
|
-
}
|
|
38
|
-
if (account.network !== network) {
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
return false;
|
|
42
|
-
});
|
|
43
|
-
if (!newLedgerAccounts.length) {
|
|
44
|
-
localStorage.removeItem('ledger_accounts');
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
localStorage.setItem('ledger_accounts', JSON.stringify(newLedgerAccounts));
|
|
48
|
-
}
|
|
49
|
-
setStateWithRef(newLedgerAccounts.filter((account) => account.network === network), setLedgerAccountsState, ledgerAccountsRef);
|
|
50
|
-
if (typeof callback === 'function') {
|
|
51
|
-
callback();
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
const renameLedgerAccount = (network, address, newName) => {
|
|
55
|
-
const newLedgerAccounts = getLocalLedgerAccounts().map((account) => isLocalLedgerAccount(network, account, address)
|
|
56
|
-
? {
|
|
57
|
-
...account,
|
|
58
|
-
name: newName,
|
|
59
|
-
}
|
|
60
|
-
: account);
|
|
61
|
-
renameLocalLedgerAddress(address, newName, network);
|
|
62
|
-
localStorage.setItem('ledger_accounts', JSON.stringify(newLedgerAccounts));
|
|
63
|
-
setStateWithRef(newLedgerAccounts.filter((account) => account.network === network), setLedgerAccountsState, ledgerAccountsRef);
|
|
64
|
-
};
|
|
65
|
-
const getLedgerAccount = (network, address) => {
|
|
66
|
-
const localLedgerAccounts = getLocalLedgerAccounts();
|
|
67
|
-
if (!localLedgerAccounts) {
|
|
68
|
-
return null;
|
|
69
|
-
}
|
|
70
|
-
return (localLedgerAccounts.find((account) => isLocalLedgerAccount(network, account, address)) || null);
|
|
71
|
-
};
|
|
72
|
-
const getLedgerAccounts = (network) => ledgerAccountsRef.current.filter((a) => a.network === network);
|
|
73
|
-
return (_jsx(LedgerAccountsContext.Provider, { value: {
|
|
74
|
-
ledgerAccountExists,
|
|
75
|
-
getLedgerAccount,
|
|
76
|
-
addLedgerAccount,
|
|
77
|
-
removeLedgerAccount,
|
|
78
|
-
renameLedgerAccount,
|
|
79
|
-
getLedgerAccounts,
|
|
80
|
-
ledgerAccounts: ledgerAccountsRef.current,
|
|
81
|
-
}, children: children }));
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
//# sourceMappingURL=index.js.map
|
|
85
|
-
|
|
86
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/LedgerAccountsProvider/index.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAE/C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAKxC,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,oBAAoB,EAC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,KAAK,EAAE;YACL,mBAAmB;YACnB,gBAAgB;YAChB,gBAAgB;YAChB,mBAAmB;YACnB,mBAAmB;YACnB,iBAAiB;YACjB,cAAc,EAAE,iBAAiB,CAAC,OAAO;SAC1C,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 { LedgerAccount } from '@w3ux/types'\nimport { setStateWithRef } from '@w3ux/utils'\nimport { useRef, useState } from 'react'\nimport type {\n LedgerAccountsContextInterface,\n LedgerAccountsProviderProps,\n} from './types'\nimport {\n getLocalLedgerAccounts,\n getLocalLedgerAddresses,\n isLocalLedgerAccount,\n renameLocalLedgerAddress,\n} from './utils'\n\nexport const [LedgerAccountsContext, useLedgerAccounts] =\n createSafeContext<LedgerAccountsContextInterface>()\n\nexport const LedgerAccountsProvider = ({\n children,\n}: LedgerAccountsProviderProps) => {\n // Store the fetched ledger accounts.\n const [ledgerAccounts, setLedgerAccountsState] = useState<LedgerAccount[]>(\n getLocalLedgerAccounts()\n )\n const ledgerAccountsRef = useRef(ledgerAccounts)\n\n // Check if a Ledger address exists in imported addresses.\n const ledgerAccountExists = (network: string, address: string) =>\n !!getLocalLedgerAccounts().find((account) =>\n isLocalLedgerAccount(network, account, address)\n )\n\n // Adds a ledger address to the list of fetched addresses.\n const addLedgerAccount = (\n network: string,\n address: string,\n index: number,\n callback?: () => void\n ) => {\n let newLedgerAccounts = getLocalLedgerAccounts()\n\n const ledgerAddress = getLocalLedgerAddresses().find((a) =>\n isLocalLedgerAccount(network, a, address)\n )\n\n if (\n ledgerAddress &&\n !newLedgerAccounts.find((account) =>\n isLocalLedgerAccount(network, account, address)\n )\n ) {\n const newAccount = {\n address,\n network,\n name: ledgerAddress.name,\n source: 'ledger',\n index,\n }\n\n // Update the full list of local ledger accounts with new entry.\n newLedgerAccounts = [...newLedgerAccounts].concat(newAccount)\n localStorage.setItem('ledger_accounts', JSON.stringify(newLedgerAccounts))\n\n // Store only those accounts on the current network in state.\n setStateWithRef(\n newLedgerAccounts.filter((account) => account.network === network),\n setLedgerAccountsState,\n ledgerAccountsRef\n )\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 from state and local storage.\n const removeLedgerAccount = (\n network: string,\n address: string,\n callback?: () => void\n ) => {\n // Remove th account from local storage records\n const newLedgerAccounts = getLocalLedgerAccounts().filter((account) => {\n if (account.address !== address) {\n return true\n }\n if (account.network !== network) {\n return true\n }\n return false\n })\n if (!newLedgerAccounts.length) {\n localStorage.removeItem('ledger_accounts')\n } else {\n localStorage.setItem('ledger_accounts', JSON.stringify(newLedgerAccounts))\n }\n\n // Update state with the new list of accounts.\n setStateWithRef(\n newLedgerAccounts.filter((account) => account.network === network),\n setLedgerAccountsState,\n ledgerAccountsRef\n )\n\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 // Update the local storage records.\n const newLedgerAccounts = getLocalLedgerAccounts().map((account) =>\n isLocalLedgerAccount(network, account, address)\n ? {\n ...account,\n name: newName,\n }\n : account\n )\n renameLocalLedgerAddress(address, newName, network)\n localStorage.setItem('ledger_accounts', JSON.stringify(newLedgerAccounts))\n\n // Update state with the new list of accounts.\n setStateWithRef(\n newLedgerAccounts.filter((account) => account.network === network),\n setLedgerAccountsState,\n ledgerAccountsRef\n )\n }\n\n // Gets an imported address along with its Ledger metadata.\n const getLedgerAccount = (network: string, address: string) => {\n const localLedgerAccounts = getLocalLedgerAccounts()\n if (!localLedgerAccounts) {\n return null\n }\n return (\n localLedgerAccounts.find((account) =>\n isLocalLedgerAccount(network, account, address)\n ) || null\n )\n }\n\n // Gets Ledger accounts for a network.\n const getLedgerAccounts = (network: string) =>\n ledgerAccountsRef.current.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 ledgerAccounts: ledgerAccountsRef.current,\n }}\n >\n {children}\n </LedgerAccountsContext.Provider>\n )\n}\n"]}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { LedgerAccount } from '@w3ux/types';
|
|
2
|
-
import type { ReactNode } from 'react';
|
|
3
|
-
export interface LedgerAccountsContextInterface {
|
|
4
|
-
ledgerAccountExists: (network: string, a: string) => boolean;
|
|
5
|
-
addLedgerAccount: (network: string, address: string, index: number, callback?: () => void) => LedgerAccount | null;
|
|
6
|
-
removeLedgerAccount: (network: string, address: string, callback?: () => void) => void;
|
|
7
|
-
renameLedgerAccount: (network: string, address: string, name: string) => void;
|
|
8
|
-
getLedgerAccount: (network: string, address: string) => LedgerAccount | null;
|
|
9
|
-
getLedgerAccounts: (network: string) => LedgerAccount[];
|
|
10
|
-
ledgerAccounts: LedgerAccount[];
|
|
11
|
-
}
|
|
12
|
-
export interface LedgerAccountsProviderProps {
|
|
13
|
-
children: ReactNode;
|
|
14
|
-
}
|
|
15
|
-
export interface LedgerAddress {
|
|
16
|
-
address: string;
|
|
17
|
-
index: number;
|
|
18
|
-
name: string;
|
|
19
|
-
network: string;
|
|
20
|
-
pubKey: string;
|
|
21
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/LedgerAccountsProvider/types.ts"],"names":[],"mappings":"","file":"types.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport type { LedgerAccount } from '@w3ux/types'\nimport type { ReactNode } from 'react'\n\nexport interface LedgerAccountsContextInterface {\n ledgerAccountExists: (network: string, a: string) => boolean\n addLedgerAccount: (\n network: string,\n address: string,\n index: number,\n callback?: () => void\n ) => LedgerAccount | null\n removeLedgerAccount: (\n network: string,\n address: string,\n callback?: () => void\n ) => void\n renameLedgerAccount: (network: string, address: string, name: string) => void\n getLedgerAccount: (network: string, address: string) => LedgerAccount | null\n getLedgerAccounts: (network: string) => LedgerAccount[]\n ledgerAccounts: LedgerAccount[]\n}\n\nexport interface LedgerAccountsProviderProps {\n children: ReactNode\n}\n\nexport interface LedgerAddress {\n address: string\n index: number\n name: string\n network: string\n pubKey: string\n}\n"]}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { LedgerAccount } from '@w3ux/types';
|
|
2
|
-
import type { LedgerAddress } from './types';
|
|
3
|
-
export declare const getLocalLedgerAccounts: (network?: string) => LedgerAccount[];
|
|
4
|
-
export declare const isLocalLedgerAccount: (network: string, account: {
|
|
5
|
-
address: string | null;
|
|
6
|
-
network: string;
|
|
7
|
-
}, address: string) => boolean;
|
|
8
|
-
export declare const getLocalLedgerAddresses: (network?: string) => LedgerAddress[];
|
|
9
|
-
export declare const renameLocalLedgerAddress: (address: string, name: string, network: string) => void;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { localStorageOrDefault } from '@w3ux/utils';
|
|
2
|
-
export const getLocalLedgerAccounts = (network) => {
|
|
3
|
-
const localAddresses = localStorageOrDefault('ledger_accounts', [], true);
|
|
4
|
-
return network
|
|
5
|
-
? localAddresses.filter((a) => a.network === network)
|
|
6
|
-
: localAddresses;
|
|
7
|
-
};
|
|
8
|
-
export const isLocalLedgerAccount = (network, account, address) => account.address === address && account.network === network;
|
|
9
|
-
export const getLocalLedgerAddresses = (network) => {
|
|
10
|
-
const localAddresses = localStorageOrDefault('ledger_addresses', [], true);
|
|
11
|
-
return network
|
|
12
|
-
? localAddresses.filter((a) => a.network === network)
|
|
13
|
-
: localAddresses;
|
|
14
|
-
};
|
|
15
|
-
export const renameLocalLedgerAddress = (address, name, network) => {
|
|
16
|
-
const localLedger = localStorageOrDefault('ledger_addresses', [], true)?.map((i) => !(i.address === address && i.network === network)
|
|
17
|
-
? i
|
|
18
|
-
: {
|
|
19
|
-
...i,
|
|
20
|
-
name,
|
|
21
|
-
});
|
|
22
|
-
if (localLedger) {
|
|
23
|
-
localStorage.setItem('ledger_addresses', JSON.stringify(localLedger));
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
//# sourceMappingURL=utils.js.map
|
|
28
|
-
|
|
29
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/LedgerAccountsProvider/utils.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAInD,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,OAAgB,EAAmB,EAAE;IAC1E,MAAM,cAAc,GAAG,qBAAqB,CAC1C,iBAAiB,EACjB,EAAE,EACF,IAAI,CACc,CAAA;IAEpB,OAAO,OAAO;QACZ,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC;QACrD,CAAC,CAAC,cAAc,CAAA;AACpB,CAAC,CAAA;AAGD,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,OAAe,EACf,OAAoD,EACpD,OAAe,EACf,EAAE,CAAC,OAAO,CAAC,OAAO,KAAK,OAAO,IAAI,OAAO,CAAC,OAAO,KAAK,OAAO,CAAA;AAG/D,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,OAAgB,EAAE,EAAE;IAC1D,MAAM,cAAc,GAAG,qBAAqB,CAC1C,kBAAkB,EAClB,EAAE,EACF,IAAI,CACc,CAAA;IAEpB,OAAO,OAAO;QACZ,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC;QACrD,CAAC,CAAC,cAAc,CAAA;AACpB,CAAC,CAAA;AAGD,MAAM,CAAC,MAAM,wBAAwB,GAAG,CACtC,OAAe,EACf,IAAY,EACZ,OAAe,EACf,EAAE;IACF,MAAM,WAAW,GACf,qBAAqB,CAAC,kBAAkB,EAAE,EAAE,EAAE,IAAI,CACnD,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CACX,CAAC,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC;QAC/C,CAAC,CAAC,CAAC;QACH,CAAC,CAAC;YACE,GAAG,CAAC;YACJ,IAAI;SACL,CACN,CAAA;IACD,IAAI,WAAW,EAAE,CAAC;QAChB,YAAY,CAAC,OAAO,CAAC,kBAAkB,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAA;IACvE,CAAC;AACH,CAAC,CAAA","file":"utils.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport type { LedgerAccount } from '@w3ux/types'\nimport { localStorageOrDefault } from '@w3ux/utils'\nimport type { LedgerAddress } from './types'\n\n// Gets imported Ledger accounts from local storage.\nexport const getLocalLedgerAccounts = (network?: string): LedgerAccount[] => {\n const localAddresses = localStorageOrDefault(\n 'ledger_accounts',\n [],\n true\n ) as LedgerAccount[]\n\n return network\n ? localAddresses.filter((a) => a.network === network)\n : localAddresses\n}\n\n// Gets whether an address is a local Ledger account.\nexport const isLocalLedgerAccount = (\n network: string,\n account: { address: string | null; network: string },\n address: string\n) => account.address === address && account.network === network\n\n// Gets saved ledger addresses from local storage.\nexport const getLocalLedgerAddresses = (network?: string) => {\n const localAddresses = localStorageOrDefault(\n 'ledger_addresses',\n [],\n true\n ) as LedgerAddress[]\n\n return network\n ? localAddresses.filter((a) => a.network === network)\n : localAddresses\n}\n\n// Renames a record from local ledger addresses.\nexport const renameLocalLedgerAddress = (\n address: string,\n name: string,\n network: string\n) => {\n const localLedger = (\n localStorageOrDefault('ledger_addresses', [], true) as LedgerAddress[]\n )?.map((i) =>\n !(i.address === address && i.network === network)\n ? i\n : {\n ...i,\n name,\n }\n )\n if (localLedger) {\n localStorage.setItem('ledger_addresses', JSON.stringify(localLedger))\n }\n}\n"]}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { VaultAccountsContextInterface, VaultAccountsProviderProps } from './types';
|
|
2
|
-
export declare const VaultAccountsContext: import("react").Context<VaultAccountsContextInterface>, useVaultAccounts: () => VaultAccountsContextInterface;
|
|
3
|
-
export declare const VaultAccountsProvider: ({ children, }: VaultAccountsProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/VaultAccountsProvider/index.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAE/C,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AACzD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAKxC,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,GACmB,EAAE,EAAE;IAC/B,MAAM,CAAC,aAAa,EAAE,oBAAoB,CAAC,GAAG,QAAQ,CACpD,qBAAqB,EAAE,CACxB,CAAA;IACD,MAAM,gBAAgB,GAAG,MAAM,CAAC,aAAa,CAAC,CAAA;IAG9C,MAAM,kBAAkB,GAAG,CAAC,OAAe,EAAE,OAAe,EAAE,EAAE,CAC9D,CAAC,CAAC,qBAAqB,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CACnC,qBAAqB,CAAC,OAAO,EAAE,CAAC,EAAE,OAAO,CAAC,CAC3C,CAAA;IAGH,MAAM,eAA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CAAC,CACN,CAAA;QACD,YAAY,CAAC,OAAO,CAClB,yBAAyB,EACzB,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,CACjC,CAAA;QACD,eAAe,CACb,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC,EACrD,oBAAoB,EACpB,gBAAgB,CACjB,CAAA;IACH,CAAC,CAAA;IAGD,MAAM,gBAAgB,GAAG,CAAC,OAAe,EAAE,EAAE,CAC3C,gBAAgB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC,CAAA;IAE/D,OAAO,CACL,KAAC,oBAAoB,CAAC,QAAQ,IAC5B,KAAK,EAAE;YACL,kBAAkB;YAClB,eAAe;YACf,kBAAkB;YAClB,kBAAkB;YAClB,eAAe;YACf,gBAAgB;YAChB,aAAa,EAAE,gBAAgB,CAAC,OAAO;SACxC,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 { VaultAccount } from '@w3ux/types'\nimport { ellipsisFn, setStateWithRef } from '@w3ux/utils'\nimport { useRef, useState } from 'react'\nimport type {\n VaultAccountsContextInterface,\n VaultAccountsProviderProps,\n} from './types'\nimport { getLocalVaultAccounts, isLocalNetworkAddress } from './utils'\n\nexport const [VaultAccountsContext, useVaultAccounts] =\n createSafeContext<VaultAccountsContextInterface>()\n\nexport const VaultAccountsProvider = ({\n children,\n}: VaultAccountsProviderProps) => {\n const [vaultAccounts, seVaultAccountsState] = useState<VaultAccount[]>(\n getLocalVaultAccounts()\n )\n const vaultAccountsRef = useRef(vaultAccounts)\n\n // Check if a Vault address exists in imported addresses.\n const vaultAccountExists = (network: string, address: string) =>\n !!getLocalVaultAccounts().find((a) =>\n isLocalNetworkAddress(network, a, address)\n )\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\n // store only those accounts on the current network in state.\n setStateWithRef(\n newVaultAccounts.filter((a) => a.network === network),\n seVaultAccountsState,\n vaultAccountsRef\n )\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 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 setStateWithRef(\n newVaultAccounts.filter((a) => a.network === network),\n seVaultAccountsState,\n vaultAccountsRef\n )\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 setStateWithRef(\n newVaultAccounts.filter((a) => a.network === network),\n seVaultAccountsState,\n vaultAccountsRef\n )\n }\n\n // Gets Vault accounts for a network.\n const getVaultAccounts = (network: string) =>\n vaultAccountsRef.current.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 vaultAccounts: vaultAccountsRef.current,\n }}\n >\n {children}\n </VaultAccountsContext.Provider>\n )\n}\n"]}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { VaultAccount } from '@w3ux/types';
|
|
2
|
-
import type { ReactNode } from 'react';
|
|
3
|
-
export interface VaultAccountsProviderProps {
|
|
4
|
-
children: ReactNode;
|
|
5
|
-
network: string;
|
|
6
|
-
}
|
|
7
|
-
export interface VaultAccountsContextInterface {
|
|
8
|
-
vaultAccountExists: (network: string, address: string) => boolean;
|
|
9
|
-
addVaultAccount: (network: string, address: string, index: number, callback?: () => void) => VaultAccount | null;
|
|
10
|
-
removeVaultAccount: (network: string, address: string, callback?: () => void) => void;
|
|
11
|
-
renameVaultAccount: (network: string, address: string, newName: string) => void;
|
|
12
|
-
getVaultAccount: (network: string, address: string) => VaultAccount | null;
|
|
13
|
-
getVaultAccounts: (network: string) => VaultAccount[];
|
|
14
|
-
vaultAccounts: VaultAccount[];
|
|
15
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/VaultAccountsProvider/types.ts"],"names":[],"mappings":"","file":"types.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport type { VaultAccount } from '@w3ux/types'\nimport type { ReactNode } from 'react'\n\nexport interface VaultAccountsProviderProps {\n children: ReactNode\n network: string\n}\n\nexport interface VaultAccountsContextInterface {\n vaultAccountExists: (network: string, address: string) => boolean\n addVaultAccount: (\n network: string,\n address: string,\n index: number,\n callback?: () => void\n ) => VaultAccount | null\n removeVaultAccount: (\n network: string,\n address: string,\n callback?: () => void\n ) => void\n renameVaultAccount: (\n network: string,\n address: string,\n newName: string\n ) => void\n getVaultAccount: (network: string, address: string) => VaultAccount | null\n getVaultAccounts: (network: string) => VaultAccount[]\n vaultAccounts: VaultAccount[]\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/VaultAccountsProvider/utils.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAGnD,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,OAAgB,EAAE,EAAE;IACxD,MAAM,cAAc,GAAG,qBAAqB,CAC1C,yBAAyB,EACzB,EAAE,EACF,IAAI,CACa,CAAA;IAEnB,OAAO,OAAO;QACZ,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC;QACrD,CAAC,CAAC,cAAc,CAAA;AACpB,CAAC,CAAA;AAGD,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,KAAa,EACb,CAAmD,EACnD,OAAe,EACf,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK,KAAK,CAAA","file":"utils.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport type { VaultAccount } from '@w3ux/types'\nimport { localStorageOrDefault } from '@w3ux/utils'\n\n// Gets imported Vault accounts from local storage.\nexport const getLocalVaultAccounts = (network?: string) => {\n const localAddresses = localStorageOrDefault(\n 'polkadot_vault_accounts',\n [],\n true\n ) as VaultAccount[]\n\n return network\n ? localAddresses.filter((a) => a.network === network)\n : localAddresses\n}\n\n// Gets whether an address is a local network address.\nexport const isLocalNetworkAddress = (\n chain: string,\n a: { address: string | undefined; network: string },\n address: string\n) => a.address === address && a.network === chain\n"]}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { WCAccountsContextInterface, WCAccountsProviderProps } from './types';
|
|
2
|
-
export declare const WCAccountsContext: import("react").Context<WCAccountsContextInterface>, useWcAccounts: () => WCAccountsContextInterface;
|
|
3
|
-
export declare const WCAccountsProvider: ({ children }: WCAccountsProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/WCAccountsProvider/index.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAE/C,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AACzD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAKxC,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,kBAAkB,CAAC,GACpC,QAAQ,CAAc,kBAAkB,EAAE,CAAC,CAAA;IAC7C,MAAM,aAAa,GAAG,MAAM,CAAC,UAAU,CAAC,CAAA;IAGxC,MAAM,eAAe,GAAG,CAAC,OAAe,EAAE,OAAe,EAAE,EAAE,CAC3D,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CACjC,qBAAqB,CAAC,OAAO,EAAE,CAAC,EAAE,OAAO,CAAC,CAC3C,CAAA;IAGH,MAAM,YAAY,GAAG,CACnB,OAAe,EACf,OAAe,EACf,KAAa,EACb,QAAqB,EACrB,EAAE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Q,IACzB,KAAK,EAAE;YACL,eAAe;YACf,YAAY;YACZ,eAAe;YACf,eAAe;YACf,YAAY;YACZ,aAAa;YACb,UAAU,EAAE,aAAa,CAAC,OAAO;SAClC,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 { WCAccount } from '@w3ux/types'\nimport { ellipsisFn, setStateWithRef } from '@w3ux/utils'\nimport { useRef, useState } from 'react'\nimport type {\n WCAccountsContextInterface,\n WCAccountsProviderProps,\n} from './types'\nimport { getLocalWcAccounts, isLocalNetworkAddress } from './utils'\n\nexport const [WCAccountsContext, useWcAccounts] =\n createSafeContext<WCAccountsContextInterface>()\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('wallet_connect_accounts', JSON.stringify(newAccounts))\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"]}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { WCAccount } from '@w3ux/types';
|
|
2
|
-
import type { ReactNode } from 'react';
|
|
3
|
-
export interface WCAccountsProviderProps {
|
|
4
|
-
children: ReactNode;
|
|
5
|
-
network: string;
|
|
6
|
-
}
|
|
7
|
-
export interface WCAccountsContextInterface {
|
|
8
|
-
wcAccountExists: (network: string, address: string) => boolean;
|
|
9
|
-
addWcAccount: (network: string, address: string, index: number, callback?: () => void) => WCAccount | null;
|
|
10
|
-
removeWcAccount: (network: string, address: string, callback?: () => void) => void;
|
|
11
|
-
renameWcAccount: (network: string, address: string, newName: string) => void;
|
|
12
|
-
getWcAccount: (network: string, address: string) => WCAccount | null;
|
|
13
|
-
getWcAccounts: (network: string) => WCAccount[];
|
|
14
|
-
wcAccounts: WCAccount[];
|
|
15
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/WCAccountsProvider/types.ts"],"names":[],"mappings":"","file":"types.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport type { WCAccount } from '@w3ux/types'\nimport type { ReactNode } from 'react'\n\nexport interface WCAccountsProviderProps {\n children: ReactNode\n network: string\n}\n\nexport interface WCAccountsContextInterface {\n wcAccountExists: (network: string, address: string) => boolean\n addWcAccount: (\n network: string,\n address: string,\n index: number,\n callback?: () => void\n ) => WCAccount | null\n removeWcAccount: (\n network: string,\n address: string,\n callback?: () => void\n ) => void\n renameWcAccount: (network: string, address: string, newName: string) => void\n getWcAccount: (network: string, address: string) => WCAccount | null\n getWcAccounts: (network: string) => WCAccount[]\n wcAccounts: WCAccount[]\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/WCAccountsProvider/utils.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAGnD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,OAAgB,EAAE,EAAE;IACrD,MAAM,cAAc,GAAG,qBAAqB,CAC1C,yBAAyB,EACzB,EAAE,EACF,IAAI,CACU,CAAA;IAEhB,OAAO,OAAO;QACZ,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC;QACrD,CAAC,CAAC,cAAc,CAAA;AACpB,CAAC,CAAA;AAGD,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,KAAa,EACb,CAAmD,EACnD,OAAe,EACf,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK,KAAK,CAAA","file":"utils.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport type { WCAccount } from '@w3ux/types'\nimport { localStorageOrDefault } from '@w3ux/utils'\n\n// Gets imported Wallet Connect accounts from local storage.\nexport const getLocalWcAccounts = (network?: string) => {\n const localAddresses = localStorageOrDefault(\n 'wallet_connect_accounts',\n [],\n true\n ) as WCAccount[]\n\n return network\n ? localAddresses.filter((a) => a.network === network)\n : localAddresses\n}\n\n// Gets whether an address is a local network address.\nexport const isLocalNetworkAddress = (\n chain: string,\n a: { address: string | undefined; network: string },\n address: string\n) => a.address === address && a.network === chain\n"]}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|