@w3ux/react-connect-kit 3.2.24-alpha.5 → 3.2.24-alpha.7
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/HardwareAccounts/index.js +18 -10
- package/HardwareAccounts/index.js.map +1 -1
- package/package.json +2 -2
- package/HardwareAccounts/utils.d.ts +0 -2
- package/HardwareAccounts/utils.js +0 -10
- package/HardwareAccounts/utils.js.map +0 -1
- package/consts.d.ts +0 -1
- package/consts.js +0 -5
- package/consts.js.map +0 -1
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { createSafeContext } from '@w3ux/hooks';
|
|
3
|
+
import { getHardwareAccounts as getAllHardwareAccounts, hardwareAccounts$, setHardwareAccounts, } from '@w3ux/observables-connect';
|
|
4
|
+
import { hardwareAccountsKey } from '@w3ux/observables-connect/consts';
|
|
5
|
+
import { getHardwareAccountsLocal } from '@w3ux/observables-connect/local';
|
|
3
6
|
import { ellipsisFn } from '@w3ux/utils';
|
|
4
|
-
import { useState } from 'react';
|
|
5
|
-
import { hardwareAccountsKey } from '../consts';
|
|
6
|
-
import { getLocalHardwareAccounts } from './utils';
|
|
7
|
+
import { useEffect, useState } from 'react';
|
|
7
8
|
export const [HardwareAccountsContext, useHardwareAccounts] = createSafeContext();
|
|
8
9
|
export const HardwareAccountsProvider = ({ children, }) => {
|
|
9
|
-
const [hardwareAccounts,
|
|
10
|
-
const hardwareAccountExists = (source, network, address) => !!
|
|
10
|
+
const [hardwareAccounts, setHardwareAccountsState] = useState(getHardwareAccountsLocal());
|
|
11
|
+
const hardwareAccountExists = (source, network, address) => !!getAllHardwareAccounts().find((a) => a.source === source && a.address === address && a.network === network);
|
|
11
12
|
const addHardwareAccount = (source, network, address, index, callback) => {
|
|
12
|
-
|
|
13
|
-
if (!exists) {
|
|
13
|
+
if (!hardwareAccountExists(source, network, address)) {
|
|
14
14
|
const newAccount = {
|
|
15
15
|
address,
|
|
16
16
|
network,
|
|
@@ -18,7 +18,7 @@ export const HardwareAccountsProvider = ({ children, }) => {
|
|
|
18
18
|
source,
|
|
19
19
|
index,
|
|
20
20
|
};
|
|
21
|
-
const newHardwareAccounts = [...
|
|
21
|
+
const newHardwareAccounts = [...getAllHardwareAccounts()].concat(newAccount);
|
|
22
22
|
localStorage.setItem(hardwareAccountsKey, JSON.stringify(newHardwareAccounts));
|
|
23
23
|
setHardwareAccounts(newHardwareAccounts);
|
|
24
24
|
if (typeof callback === 'function') {
|
|
@@ -29,7 +29,7 @@ export const HardwareAccountsProvider = ({ children, }) => {
|
|
|
29
29
|
return null;
|
|
30
30
|
};
|
|
31
31
|
const removeHardwareAccount = (source, network, address, callback) => {
|
|
32
|
-
const newHardwareAccounts = [...
|
|
32
|
+
const newHardwareAccounts = [...getAllHardwareAccounts()].filter((a) => !(a.source === source && a.address === address && a.network === network));
|
|
33
33
|
if (!newHardwareAccounts.length) {
|
|
34
34
|
localStorage.removeItem(hardwareAccountsKey);
|
|
35
35
|
}
|
|
@@ -42,7 +42,7 @@ export const HardwareAccountsProvider = ({ children, }) => {
|
|
|
42
42
|
}
|
|
43
43
|
};
|
|
44
44
|
const renameHardwareAccount = (source, network, address, newName) => {
|
|
45
|
-
const newHardwareAccounts = [...
|
|
45
|
+
const newHardwareAccounts = [...getAllHardwareAccounts()].map((a) => a.source === source && a.network === network && a.address === address
|
|
46
46
|
? {
|
|
47
47
|
...a,
|
|
48
48
|
name: newName,
|
|
@@ -53,6 +53,14 @@ export const HardwareAccountsProvider = ({ children, }) => {
|
|
|
53
53
|
};
|
|
54
54
|
const getHardwareAccount = (source, network, address) => hardwareAccounts.find((a) => a.source === source && a.network === network && a.address === address) || null;
|
|
55
55
|
const getHardwareAccounts = (source, network) => hardwareAccounts.filter((a) => a.source === source && a.network === network);
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
const sub = hardwareAccounts$.subscribe((accounts) => {
|
|
58
|
+
setHardwareAccountsState(accounts);
|
|
59
|
+
});
|
|
60
|
+
return () => {
|
|
61
|
+
sub.unsubscribe();
|
|
62
|
+
};
|
|
63
|
+
}, []);
|
|
56
64
|
return (_jsx(HardwareAccountsContext.Provider, { value: {
|
|
57
65
|
hardwareAccountExists,
|
|
58
66
|
getHardwareAccount,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/HardwareAccounts/index.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"sources":["../src/HardwareAccounts/index.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EACL,mBAAmB,IAAI,sBAAsB,EAC7C,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAA;AACtE,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAA;AAE1E,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAG3C,MAAM,CAAC,MAAM,CAAC,uBAAuB,EAAE,mBAAmB,CAAC,GACzD,iBAAiB,EAAoC,CAAA;AAEvD,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,EACvC,QAAQ,GAGT,EAAE,EAAE;IAEH,MAAM,CAAC,gBAAgB,EAAE,wBAAwB,CAAC,GAAG,QAAQ,CAE3D,wBAAwB,EAAE,CAAC,CAAA;IAG7B,MAAM,qBAAqB,GAAG,CAC5B,MAA6B,EAC7B,OAAe,EACf,OAAe,EACf,EAAE,CACF,CAAC,CAAC,sBAAsB,EAAE,CAAC,IAAI,CAC7B,CAAC,CAAC,EAAE,EAAE,CACJ,CAAC,CAAC,MAAM,KAAK,MAAM,IAAI,CAAC,CAAC,OAAO,KAAK,OA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;IAG9E,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,GAAG,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,EAAE;YACnD,wBAAwB,CAAC,QAAQ,CAAC,CAAA;QACpC,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,uBAAuB,CAAC,QAAQ,IAC/B,KAAK,EAAE;YACL,qBAAqB;YACrB,kBAAkB;YAClB,kBAAkB;YAClB,qBAAqB;YACrB,qBAAqB;YACrB,mBAAmB;SACpB,YAEA,QAAQ,GACwB,CACpC,CAAA;AACH,CAAC,CAAA","file":"index.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport { createSafeContext } from '@w3ux/hooks'\nimport {\n getHardwareAccounts as getAllHardwareAccounts,\n hardwareAccounts$,\n setHardwareAccounts,\n} from '@w3ux/observables-connect'\nimport { hardwareAccountsKey } from '@w3ux/observables-connect/consts'\nimport { getHardwareAccountsLocal } from '@w3ux/observables-connect/local'\nimport type { HardwareAccount, HardwareAccountSource } from '@w3ux/types'\nimport { ellipsisFn } from '@w3ux/utils'\nimport type { ReactNode } from 'react'\nimport { useEffect, useState } from 'react'\nimport type { HardwareAccountsContextInterface } from './types'\n\nexport const [HardwareAccountsContext, useHardwareAccounts] =\n createSafeContext<HardwareAccountsContextInterface>()\n\nexport const HardwareAccountsProvider = ({\n children,\n}: {\n children: ReactNode\n}) => {\n // Store imported hardware accounts\n const [hardwareAccounts, setHardwareAccountsState] = useState<\n HardwareAccount[]\n >(getHardwareAccountsLocal())\n\n // Check if an account exists\n const hardwareAccountExists = (\n source: HardwareAccountSource,\n network: string,\n address: string\n ) =>\n !!getAllHardwareAccounts().find(\n (a) =>\n a.source === source && a.address === address && a.network === network\n )\n\n // Adds an account\n const addHardwareAccount = (\n source: HardwareAccountSource,\n network: string,\n address: string,\n index: number,\n callback?: () => void\n ) => {\n if (!hardwareAccountExists(source, network, address)) {\n const newAccount: HardwareAccount = {\n address,\n network,\n name: ellipsisFn(address),\n source,\n index,\n }\n const newHardwareAccounts = [...getAllHardwareAccounts()].concat(\n newAccount\n )\n localStorage.setItem(\n hardwareAccountsKey,\n JSON.stringify(newHardwareAccounts)\n )\n setHardwareAccounts(newHardwareAccounts)\n // Handle optional callback function\n if (typeof callback === 'function') {\n callback()\n }\n return newAccount\n }\n return null\n }\n\n // Removes an account\n const removeHardwareAccount = (\n source: HardwareAccountSource,\n network: string,\n address: string,\n callback?: () => void\n ) => {\n const newHardwareAccounts = [...getAllHardwareAccounts()].filter(\n (a) =>\n !(a.source === source && a.address === address && a.network === network)\n )\n\n if (!newHardwareAccounts.length) {\n localStorage.removeItem(hardwareAccountsKey)\n } else {\n localStorage.setItem(\n hardwareAccountsKey,\n JSON.stringify(newHardwareAccounts)\n )\n }\n setHardwareAccounts(newHardwareAccounts)\n // Handle optional callback function\n if (typeof callback === 'function') {\n callback()\n }\n }\n\n // Renames an imported account\n const renameHardwareAccount = (\n source: HardwareAccountSource,\n network: string,\n address: string,\n newName: string\n ) => {\n const newHardwareAccounts = [...getAllHardwareAccounts()].map((a) =>\n a.source === source && a.network === network && a.address === address\n ? {\n ...a,\n name: newName,\n }\n : a\n )\n localStorage.setItem(\n hardwareAccountsKey,\n JSON.stringify(newHardwareAccounts)\n )\n setHardwareAccounts(newHardwareAccounts)\n }\n\n // Gets an imported account\n const getHardwareAccount = (\n source: HardwareAccountSource,\n network: string,\n address: string\n ) =>\n hardwareAccounts.find(\n (a) =>\n a.source === source && a.network === network && a.address === address\n ) || null\n\n // Gets all accounts for a network and source\n const getHardwareAccounts = (\n source: HardwareAccountSource,\n network: string\n ) =>\n hardwareAccounts.filter((a) => a.source === source && a.network === network)\n\n // Subscribes to observables and updates state\n useEffect(() => {\n const sub = hardwareAccounts$.subscribe((accounts) => {\n setHardwareAccountsState(accounts)\n })\n return () => {\n sub.unsubscribe()\n }\n }, [])\n\n return (\n <HardwareAccountsContext.Provider\n value={{\n hardwareAccountExists,\n getHardwareAccount,\n addHardwareAccount,\n removeHardwareAccount,\n renameHardwareAccount,\n getHardwareAccounts,\n }}\n >\n {children}\n </HardwareAccountsContext.Provider>\n )\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@w3ux/react-connect-kit",
|
|
3
|
-
"version": "3.2.24-alpha.
|
|
3
|
+
"version": "3.2.24-alpha.7",
|
|
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.
|
|
8
|
+
"@w3ux/observables-connect": "0.9.32-alpha.3",
|
|
9
9
|
"@w3ux/utils": "^2.0.9"
|
|
10
10
|
},
|
|
11
11
|
"type": "module",
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { localStorageOrDefault } from '@w3ux/utils';
|
|
2
|
-
import { hardwareAccountsKey } from '../consts';
|
|
3
|
-
export const getLocalHardwareAccounts = () => {
|
|
4
|
-
const accounts = localStorageOrDefault(hardwareAccountsKey, [], true);
|
|
5
|
-
return accounts;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
//# sourceMappingURL=utils.js.map
|
|
9
|
-
|
|
10
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/HardwareAccounts/utils.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAA;AAG/C,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAsB,EAAE;IAC9D,MAAM,QAAQ,GAAG,qBAAqB,CACpC,mBAAmB,EACnB,EAAE,EACF,IAAI,CACgB,CAAA;IAEtB,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA","file":"utils.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport type { HardwareAccount } from '@w3ux/types'\nimport { localStorageOrDefault } from '@w3ux/utils'\nimport { hardwareAccountsKey } from '../consts'\n\n// Gets imported Ledger accounts from local storage\nexport const getLocalHardwareAccounts = (): HardwareAccount[] => {\n const accounts = localStorageOrDefault(\n hardwareAccountsKey,\n [],\n true\n ) as HardwareAccount[]\n\n return accounts\n}\n"]}
|
package/consts.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const hardwareAccountsKey = "hardware_accounts";
|
package/consts.js
DELETED
package/consts.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/consts.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,mBAAmB,GAAG,mBAAmB,CAAA","file":"consts.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\n// Local storage hardware accounts key\nexport const hardwareAccountsKey = 'hardware_accounts'\n"]}
|