@w3ux/react-connect-kit 3.2.24-alpha.1 → 3.2.24-alpha.2
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/LedgerAccounts/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { createSafeContext } from '@w3ux/hooks';
|
|
3
|
+
import { ellipsisFn } from '@w3ux/utils';
|
|
3
4
|
import { useState } from 'react';
|
|
4
5
|
import { getLocalLedgerAccounts } from './utils';
|
|
5
6
|
export const [LedgerAccountsContext, useLedgerAccounts] = createSafeContext();
|
|
@@ -7,12 +8,13 @@ export const LedgerAccountsProvider = ({ children, }) => {
|
|
|
7
8
|
const [ledgerAccounts, setLedgerAccounts] = useState(getLocalLedgerAccounts());
|
|
8
9
|
const ledgerAccountExists = (network, address) => !!ledgerAccounts.find((a) => a.address === address && a.network === network);
|
|
9
10
|
const addLedgerAccount = (network, address, index, callback) => {
|
|
10
|
-
const exists = ledgerAccounts.find((a) => a.address === address);
|
|
11
|
+
const exists = !!ledgerAccounts.find((a) => a.address === address && a.network === network);
|
|
12
|
+
console.log('exists: ', exists);
|
|
11
13
|
if (!exists) {
|
|
12
14
|
const newAccount = {
|
|
13
15
|
address,
|
|
14
16
|
network,
|
|
15
|
-
name:
|
|
17
|
+
name: ellipsisFn(address),
|
|
16
18
|
source: 'ledger',
|
|
17
19
|
index,
|
|
18
20
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/LedgerAccounts/index.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"sources":["../src/LedgerAccounts/index.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAE/C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC,OAA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AAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC,CAAA;QAC1E,iBAAiB,CAAC,iBAAiB,CAAC,CAAA;IACtC,CAAC,CAAA;IAGD,MAAM,gBAAgB,GAAG,CAAC,OAAe,EAAE,OAAe,EAAE,EAAE,CAC5D,cAAc,CAAC,IAAI,CACjB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK,OAAO,CACtD,IAAI,IAAI,CAAA;IAGX,MAAM,iBAAiB,GAAG,CAAC,OAAe,EAAE,EAAE,CAC5C,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC,CAAA;IAErD,OAAO,CACL,KAAC,qBAAqB,CAAC,QAAQ,IAC7B,KAAK,EAAE;YACL,mBAAmB;YACnB,gBAAgB;YAChB,gBAAgB;YAChB,mBAAmB;YACnB,mBAAmB;YACnB,iBAAiB;SAClB,YAEA,QAAQ,GACsB,CAClC,CAAA;AACH,CAAC,CAAA","file":"index.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport { createSafeContext } from '@w3ux/hooks'\nimport type { HardwareAccount } from '@w3ux/types'\nimport { ellipsisFn } from '@w3ux/utils'\nimport type { ReactNode } from 'react'\nimport { useState } from 'react'\nimport type { LedgerAccountsContextInterface } from './types'\nimport { getLocalLedgerAccounts } from './utils'\n\nexport const [LedgerAccountsContext, useLedgerAccounts] =\n createSafeContext<LedgerAccountsContextInterface>()\n\nexport const LedgerAccountsProvider = ({\n children,\n}: {\n children: ReactNode\n}) => {\n // Store imported ledger accounts\n const [ledgerAccounts, setLedgerAccounts] = useState<HardwareAccount[]>(\n getLocalLedgerAccounts()\n )\n\n // Check if a Ledger account is imported\n const ledgerAccountExists = (network: string, address: string) =>\n !!ledgerAccounts.find((a) => a.address === address && a.network === network)\n\n // Adds a ledger account\n const addLedgerAccount = (\n network: string,\n address: string,\n index: number,\n callback?: () => void\n ) => {\n const exists = !!ledgerAccounts.find(\n (a) => a.address === address && a.network === network\n )\n\n console.log('exists: ', exists)\n if (!exists) {\n const newAccount = {\n address,\n network,\n name: ellipsisFn(address),\n source: 'ledger',\n index,\n }\n const newLedgerAccounts = [...ledgerAccounts].concat(newAccount)\n localStorage.setItem('ledger_accounts', JSON.stringify(newLedgerAccounts))\n setLedgerAccounts(newLedgerAccounts)\n\n // Handle optional callback function.\n if (typeof callback === 'function') {\n callback()\n }\n return newAccount\n }\n return null\n }\n\n // Removes a Ledger account\n const removeLedgerAccount = (\n network: string,\n address: string,\n callback?: () => void\n ) => {\n const newLedgerAccounts = [...ledgerAccounts].filter(\n (a) => !(a.address === address && a.network === network)\n )\n\n if (!newLedgerAccounts.length) {\n localStorage.removeItem('ledger_accounts')\n } else {\n localStorage.setItem('ledger_accounts', JSON.stringify(newLedgerAccounts))\n }\n\n setLedgerAccounts(newLedgerAccounts)\n // Handle optional callback function\n if (typeof callback === 'function') {\n callback()\n }\n }\n\n // Renames an imported ledger account\n const renameLedgerAccount = (\n network: string,\n address: string,\n newName: string\n ) => {\n const newLedgerAccounts = [...ledgerAccounts].map((a) =>\n a.network === network && a.address === address\n ? {\n ...a,\n name: newName,\n }\n : a\n )\n localStorage.setItem('ledger_accounts', JSON.stringify(newLedgerAccounts))\n setLedgerAccounts(newLedgerAccounts)\n }\n\n // Gets an imported ledger account\n const getLedgerAccount = (network: string, address: string) =>\n ledgerAccounts.find(\n (a) => a.network === network && a.address === address\n ) || null\n\n // Gets all Ledger accounts for a network\n const getLedgerAccounts = (network: string) =>\n ledgerAccounts.filter((a) => a.network === network)\n\n return (\n <LedgerAccountsContext.Provider\n value={{\n ledgerAccountExists,\n getLedgerAccount,\n addLedgerAccount,\n removeLedgerAccount,\n renameLedgerAccount,\n getLedgerAccounts,\n }}\n >\n {children}\n </LedgerAccountsContext.Provider>\n )\n}\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { HardwareAccount } from '@w3ux/types';
|
|
2
|
-
export declare const getLocalLedgerAccounts: (
|
|
2
|
+
export declare const getLocalLedgerAccounts: () => HardwareAccount[];
|
package/LedgerAccounts/utils.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { localStorageOrDefault } from '@w3ux/utils';
|
|
2
|
-
export const getLocalLedgerAccounts = (
|
|
2
|
+
export const getLocalLedgerAccounts = () => {
|
|
3
3
|
const localAddresses = localStorageOrDefault('ledger_accounts', [], true);
|
|
4
|
-
return
|
|
5
|
-
? localAddresses.filter((a) => a.network === network)
|
|
6
|
-
: localAddresses;
|
|
4
|
+
return localAddresses;
|
|
7
5
|
};
|
|
8
6
|
|
|
9
7
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +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,
|
|
1
|
+
{"version":3,"sources":["../src/LedgerAccounts/utils.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAGnD,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAsB,EAAE;IAC5D,MAAM,cAAc,GAAG,qBAAqB,CAC1C,iBAAiB,EACjB,EAAE,EACF,IAAI,CACgB,CAAA;IAEtB,OAAO,cAAc,CAAA;AACvB,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 = (): HardwareAccount[] => {\n const localAddresses = localStorageOrDefault(\n 'ledger_accounts',\n [],\n true\n ) as HardwareAccount[]\n\n return localAddresses\n}\n"]}
|