@w3ux/react-connect-kit 0.1.13 → 0.1.15
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/LedgerAccountsProvider/defaults.js +6 -5
- package/LedgerAccountsProvider/defaults.js.map +1 -1
- package/LedgerAccountsProvider/index.d.ts +1 -1
- package/LedgerAccountsProvider/index.js +11 -11
- package/LedgerAccountsProvider/index.js.map +1 -1
- package/LedgerAccountsProvider/types.d.ts +6 -6
- package/LedgerAccountsProvider/types.js.map +1 -1
- package/VaultAccountsProvider/defaults.js +5 -5
- package/VaultAccountsProvider/defaults.js.map +1 -1
- package/VaultAccountsProvider/index.d.ts +1 -1
- package/VaultAccountsProvider/index.js +6 -6
- package/VaultAccountsProvider/index.js.map +1 -1
- package/VaultAccountsProvider/types.d.ts +5 -5
- package/VaultAccountsProvider/types.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export var defaultLedgerAccountsContext = {
|
|
2
|
-
ledgerAccountExists: function (address) { return false; },
|
|
3
|
-
addLedgerAccount: function (address, index, callback) { return null; },
|
|
4
|
-
removeLedgerAccount: function (address, callback) { },
|
|
5
|
-
renameLedgerAccount: function (address, newName) { },
|
|
6
|
-
getLedgerAccount: function (address) { return null; },
|
|
2
|
+
ledgerAccountExists: function (network, address) { return false; },
|
|
3
|
+
addLedgerAccount: function (network, address, index, callback) { return null; },
|
|
4
|
+
removeLedgerAccount: function (network, address, callback) { },
|
|
5
|
+
renameLedgerAccount: function (network, address, newName) { },
|
|
6
|
+
getLedgerAccount: function (network, address) { return null; },
|
|
7
|
+
getLedgerAccounts: function (network) { return []; },
|
|
7
8
|
ledgerAccounts: [],
|
|
8
9
|
};
|
|
9
10
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/LedgerAccountsProvider/defaults.ts"],"names":[],"mappings":"AAAA;wCACwC;AACxC,6GAA6G;AAI7G,MAAM,CAAC,IAAM,4BAA4B,GAAmC;IAC1E,mBAAmB,EAAE,UAAC,OAAO,IAAK,OAAA,KAAK,EAAL,CAAK;
|
|
1
|
+
{"version":3,"sources":["../src/LedgerAccountsProvider/defaults.ts"],"names":[],"mappings":"AAAA;wCACwC;AACxC,6GAA6G;AAI7G,MAAM,CAAC,IAAM,4BAA4B,GAAmC;IAC1E,mBAAmB,EAAE,UAAC,OAAO,EAAE,OAAO,IAAK,OAAA,KAAK,EAAL,CAAK;IAChD,gBAAgB,EAAE,UAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,IAAK,OAAA,IAAI,EAAJ,CAAI;IAC7D,mBAAmB,EAAE,UAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,IAAM,CAAC;IACvD,mBAAmB,EAAE,UAAC,OAAO,EAAE,OAAO,EAAE,OAAO,IAAM,CAAC;IACtD,gBAAgB,EAAE,UAAC,OAAO,EAAE,OAAO,IAAK,OAAA,IAAI,EAAJ,CAAI;IAC5C,iBAAiB,EAAE,UAAC,OAAO,IAAK,OAAA,EAAE,EAAF,CAAE;IAClC,cAAc,EAAE,EAAE;CACnB,CAAC","file":"defaults.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function, no-unused-vars */\n\nimport { LedgerAccountsContextInterface } from \"./types\";\n\nexport const defaultLedgerAccountsContext: LedgerAccountsContextInterface = {\n ledgerAccountExists: (network, address) => false,\n addLedgerAccount: (network, address, index, callback) => null,\n removeLedgerAccount: (network, address, callback) => {},\n renameLedgerAccount: (network, address, newName) => {},\n getLedgerAccount: (network, address) => null,\n getLedgerAccounts: (network) => [],\n ledgerAccounts: [],\n};\n"]}
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
import { LedgerAccountsContextInterface, LedgerAccountsProviderProps } from "./types";
|
|
3
3
|
export declare const LedgerAccountsContext: import("react").Context<LedgerAccountsContextInterface>;
|
|
4
4
|
export declare const useLedgerAccounts: () => LedgerAccountsContextInterface;
|
|
5
|
-
export declare const LedgerAccountsProvider: ({ children,
|
|
5
|
+
export declare const LedgerAccountsProvider: ({ children, }: LedgerAccountsProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -23,19 +23,18 @@ import { createContext, useContext, useRef, useState } from "react";
|
|
|
23
23
|
import { defaultLedgerAccountsContext } from "./defaults";
|
|
24
24
|
import { getLocalLedgerAccounts, getLocalLedgerAddresses, isLocalLedgerAccount, renameLocalLedgerAddress, } from "./utils";
|
|
25
25
|
import { setStateWithRef } from "@w3ux/utils";
|
|
26
|
-
import { useEffectIgnoreInitial } from "@w3ux/hooks";
|
|
27
26
|
export var LedgerAccountsContext = createContext(defaultLedgerAccountsContext);
|
|
28
27
|
export var useLedgerAccounts = function () { return useContext(LedgerAccountsContext); };
|
|
29
28
|
export var LedgerAccountsProvider = function (_a) {
|
|
30
|
-
var children = _a.children
|
|
31
|
-
var _b = useState(getLocalLedgerAccounts(
|
|
29
|
+
var children = _a.children;
|
|
30
|
+
var _b = useState(getLocalLedgerAccounts()), ledgerAccounts = _b[0], setLedgerAccountsState = _b[1];
|
|
32
31
|
var ledgerAccountsRef = useRef(ledgerAccounts);
|
|
33
|
-
var ledgerAccountExists = function (address) {
|
|
32
|
+
var ledgerAccountExists = function (network, address) {
|
|
34
33
|
return !!getLocalLedgerAccounts().find(function (account) {
|
|
35
34
|
return isLocalLedgerAccount(network, account, address);
|
|
36
35
|
});
|
|
37
36
|
};
|
|
38
|
-
var addLedgerAccount = function (address, index, callback) {
|
|
37
|
+
var addLedgerAccount = function (network, address, index, callback) {
|
|
39
38
|
var newLedgerAccounts = getLocalLedgerAccounts();
|
|
40
39
|
var ledgerAddress = getLocalLedgerAddresses().find(function (a) {
|
|
41
40
|
return isLocalLedgerAccount(network, a, address);
|
|
@@ -61,7 +60,7 @@ export var LedgerAccountsProvider = function (_a) {
|
|
|
61
60
|
}
|
|
62
61
|
return null;
|
|
63
62
|
};
|
|
64
|
-
var removeLedgerAccount = function (address, callback) {
|
|
63
|
+
var removeLedgerAccount = function (network, address, callback) {
|
|
65
64
|
var newLedgerAccounts = getLocalLedgerAccounts().filter(function (account) {
|
|
66
65
|
if (account.address !== address) {
|
|
67
66
|
return true;
|
|
@@ -82,7 +81,7 @@ export var LedgerAccountsProvider = function (_a) {
|
|
|
82
81
|
callback();
|
|
83
82
|
}
|
|
84
83
|
};
|
|
85
|
-
var renameLedgerAccount = function (address, newName) {
|
|
84
|
+
var renameLedgerAccount = function (network, address, newName) {
|
|
86
85
|
var newLedgerAccounts = getLocalLedgerAccounts().map(function (account) {
|
|
87
86
|
return isLocalLedgerAccount(network, account, address)
|
|
88
87
|
? __assign(__assign({}, account), { name: newName }) : account;
|
|
@@ -91,7 +90,7 @@ export var LedgerAccountsProvider = function (_a) {
|
|
|
91
90
|
localStorage.setItem("ledger_accounts", JSON.stringify(newLedgerAccounts));
|
|
92
91
|
setStateWithRef(newLedgerAccounts.filter(function (account) { return account.network === network; }), setLedgerAccountsState, ledgerAccountsRef);
|
|
93
92
|
};
|
|
94
|
-
var getLedgerAccount = function (address) {
|
|
93
|
+
var getLedgerAccount = function (network, address) {
|
|
95
94
|
var localLedgerAccounts = getLocalLedgerAccounts();
|
|
96
95
|
if (!localLedgerAccounts) {
|
|
97
96
|
return null;
|
|
@@ -100,15 +99,16 @@ export var LedgerAccountsProvider = function (_a) {
|
|
|
100
99
|
return isLocalLedgerAccount(network, account, address);
|
|
101
100
|
}) || null);
|
|
102
101
|
};
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
102
|
+
var getLedgerAccounts = function (network) {
|
|
103
|
+
return ledgerAccountsRef.current.filter(function (a) { return a.network === network; });
|
|
104
|
+
};
|
|
106
105
|
return (_jsx(LedgerAccountsContext.Provider, { value: {
|
|
107
106
|
ledgerAccountExists: ledgerAccountExists,
|
|
108
107
|
getLedgerAccount: getLedgerAccount,
|
|
109
108
|
addLedgerAccount: addLedgerAccount,
|
|
110
109
|
removeLedgerAccount: removeLedgerAccount,
|
|
111
110
|
renameLedgerAccount: renameLedgerAccount,
|
|
111
|
+
getLedgerAccounts: getLedgerAccounts,
|
|
112
112
|
ledgerAccounts: ledgerAccountsRef.current,
|
|
113
113
|
}, children: children }));
|
|
114
114
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/LedgerAccountsProvider/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;wCACwC;AAExC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACpE,OAAO,EAAE,4BAA4B,EAAE,MAAM,YAAY,CAAC;AAM1D,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,oBAAoB,EACpB,wBAAwB,GACzB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"sources":["../src/LedgerAccountsProvider/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;wCACwC;AAExC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACpE,OAAO,EAAE,4BAA4B,EAAE,MAAM,YAAY,CAAC;AAM1D,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,oBAAoB,EACpB,wBAAwB,GACzB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,CAAC,IAAM,qBAAqB,GAChC,aAAa,CAAiC,4BAA4B,CAAC,CAAC;AAE9E,MAAM,CAAC,IAAM,iBAAiB,GAAG,cAAM,OAAA,UAAU,CAAC,qBAAqB,CAAC,EAAjC,CAAiC,CAAC;AAEzE,MAAM,CAAC,IAAM,sBAAsB,GAAG,UAAC,EAET;QAD5B,QAAQ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D,CAAC;IAEjE,OAAO,CACL,KAAC,qBAAqB,CAAC,QAAQ,IAC7B,KAAK,EAAE;YACL,mBAAmB,qBAAA;YACnB,gBAAgB,kBAAA;YAChB,gBAAgB,kBAAA;YAChB,mBAAmB,qBAAA;YACnB,mBAAmB,qBAAA;YACnB,iBAAiB,mBAAA;YACjB,cAAc,EAAE,iBAAiB,CAAC,OAAO;SAC1C,YAEA,QAAQ,GACsB,CAClC,CAAC;AACJ,CAAC,CAAC","file":"index.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport { createContext, useContext, useRef, useState } from \"react\";\nimport { defaultLedgerAccountsContext } from \"./defaults\";\nimport {\n LedgerAccountsContextInterface,\n LedgerAccountsProviderProps,\n} from \"./types\";\nimport { LedgerAccount } from \"../types\";\nimport {\n getLocalLedgerAccounts,\n getLocalLedgerAddresses,\n isLocalLedgerAccount,\n renameLocalLedgerAddress,\n} from \"./utils\";\nimport { setStateWithRef } from \"@w3ux/utils\";\n\nexport const LedgerAccountsContext =\n createContext<LedgerAccountsContextInterface>(defaultLedgerAccountsContext);\n\nexport const useLedgerAccounts = () => useContext(LedgerAccountsContext);\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(\n \"ledger_accounts\",\n JSON.stringify(newLedgerAccounts)\n );\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(\n \"ledger_accounts\",\n JSON.stringify(newLedgerAccounts)\n );\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,16 +1,16 @@
|
|
|
1
1
|
import { ReactNode } from "react";
|
|
2
2
|
import { LedgerAccount } from "../types";
|
|
3
3
|
export interface LedgerAccountsContextInterface {
|
|
4
|
-
ledgerAccountExists: (a: string) => boolean;
|
|
5
|
-
addLedgerAccount: (address: string, index: number, callback?: () => void) => LedgerAccount | null;
|
|
6
|
-
removeLedgerAccount: (address: string, callback?: () => void) => void;
|
|
7
|
-
renameLedgerAccount: (address: string, name: string) => void;
|
|
8
|
-
getLedgerAccount: (address: string) => LedgerAccount | null;
|
|
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[];
|
|
9
10
|
ledgerAccounts: LedgerAccount[];
|
|
10
11
|
}
|
|
11
12
|
export interface LedgerAccountsProviderProps {
|
|
12
13
|
children: ReactNode;
|
|
13
|
-
network: string;
|
|
14
14
|
}
|
|
15
15
|
export interface LedgerAddress {
|
|
16
16
|
address: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/LedgerAccountsProvider/types.ts"],"names":[],"mappings":"AAAA;wCACwC","file":"types.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport { ReactNode } from \"react\";\nimport { LedgerAccount } from \"../types\";\n\nexport interface LedgerAccountsContextInterface {\n ledgerAccountExists: (a: string) => boolean;\n addLedgerAccount: (\n address: string,\n index: number,\n callback?: () => void\n ) => LedgerAccount | null;\n removeLedgerAccount: (address: string
|
|
1
|
+
{"version":3,"sources":["../src/LedgerAccountsProvider/types.ts"],"names":[],"mappings":"AAAA;wCACwC","file":"types.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport { ReactNode } from \"react\";\nimport { LedgerAccount } from \"../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 ) => 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 +1,9 @@
|
|
|
1
1
|
export var defaultVaultAccountsContext = {
|
|
2
|
-
vaultAccountExists: function (address) { return false; },
|
|
3
|
-
addVaultAccount: function (address, index, callback) { return null; },
|
|
4
|
-
removeVaultAccount: function (address, callback) { },
|
|
5
|
-
renameVaultAccount: function (address, newName) { },
|
|
6
|
-
getVaultAccount: function (address) { return null; },
|
|
2
|
+
vaultAccountExists: function (network, address) { return false; },
|
|
3
|
+
addVaultAccount: function (network, address, index, callback) { return null; },
|
|
4
|
+
removeVaultAccount: function (network, address, callback) { },
|
|
5
|
+
renameVaultAccount: function (network, address, newName) { },
|
|
6
|
+
getVaultAccount: function (network, address) { return null; },
|
|
7
7
|
getVaultAccounts: function (network) { return []; },
|
|
8
8
|
vaultAccounts: [],
|
|
9
9
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/VaultAccountsProvider/defaults.ts"],"names":[],"mappings":"AAAA;wCACwC;AACxC,6GAA6G;AAI7G,MAAM,CAAC,IAAM,2BAA2B,GAAkC;IACxE,kBAAkB,EAAE,UAAC,OAAO,IAAK,OAAA,KAAK,EAAL,CAAK;
|
|
1
|
+
{"version":3,"sources":["../src/VaultAccountsProvider/defaults.ts"],"names":[],"mappings":"AAAA;wCACwC;AACxC,6GAA6G;AAI7G,MAAM,CAAC,IAAM,2BAA2B,GAAkC;IACxE,kBAAkB,EAAE,UAAC,OAAO,EAAE,OAAO,IAAK,OAAA,KAAK,EAAL,CAAK;IAC/C,eAAe,EAAE,UAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,IAAK,OAAA,IAAI,EAAJ,CAAI;IAC5D,kBAAkB,EAAE,UAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,IAAM,CAAC;IACtD,kBAAkB,EAAE,UAAC,OAAO,EAAE,OAAO,EAAE,OAAO,IAAM,CAAC;IACrD,eAAe,EAAE,UAAC,OAAO,EAAE,OAAO,IAAK,OAAA,IAAI,EAAJ,CAAI;IAC3C,gBAAgB,EAAE,UAAC,OAAO,IAAK,OAAA,EAAE,EAAF,CAAE;IACjC,aAAa,EAAE,EAAE;CAClB,CAAC","file":"defaults.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function, no-unused-vars */\n\nimport type { VaultAccountsContextInterface } from \"./types\";\n\nexport const defaultVaultAccountsContext: VaultAccountsContextInterface = {\n vaultAccountExists: (network, address) => false,\n addVaultAccount: (network, address, index, callback) => null,\n removeVaultAccount: (network, address, callback) => {},\n renameVaultAccount: (network, address, newName) => {},\n getVaultAccount: (network, address) => null,\n getVaultAccounts: (network) => [],\n vaultAccounts: [],\n};\n"]}
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
import type { VaultAccountsContextInterface, VaultAccountsProviderProps } from "./types";
|
|
3
3
|
export declare const VaultAccountsContext: import("react").Context<VaultAccountsContextInterface>;
|
|
4
4
|
export declare const useVaultAccounts: () => VaultAccountsContextInterface;
|
|
5
|
-
export declare const VaultAccountsProvider: ({
|
|
5
|
+
export declare const VaultAccountsProvider: ({ children, }: VaultAccountsProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -26,15 +26,15 @@ import { defaultVaultAccountsContext } from "./defaults";
|
|
|
26
26
|
export var VaultAccountsContext = createContext(defaultVaultAccountsContext);
|
|
27
27
|
export var useVaultAccounts = function () { return useContext(VaultAccountsContext); };
|
|
28
28
|
export var VaultAccountsProvider = function (_a) {
|
|
29
|
-
var
|
|
29
|
+
var children = _a.children;
|
|
30
30
|
var _b = useState(getLocalVaultAccounts()), vaultAccounts = _b[0], seVaultAccountsState = _b[1];
|
|
31
31
|
var vaultAccountsRef = useRef(vaultAccounts);
|
|
32
|
-
var vaultAccountExists = function (address) {
|
|
32
|
+
var vaultAccountExists = function (network, address) {
|
|
33
33
|
return !!getLocalVaultAccounts().find(function (a) {
|
|
34
34
|
return isLocalNetworkAddress(network, a, address);
|
|
35
35
|
});
|
|
36
36
|
};
|
|
37
|
-
var addVaultAccount = function (address, index, callback) {
|
|
37
|
+
var addVaultAccount = function (network, address, index, callback) {
|
|
38
38
|
var newVaultAccounts = getLocalVaultAccounts();
|
|
39
39
|
if (!newVaultAccounts.find(function (a) { return isLocalNetworkAddress(network, a, address); })) {
|
|
40
40
|
var account = {
|
|
@@ -54,7 +54,7 @@ export var VaultAccountsProvider = function (_a) {
|
|
|
54
54
|
}
|
|
55
55
|
return null;
|
|
56
56
|
};
|
|
57
|
-
var removeVaultAccount = function (address, callback) {
|
|
57
|
+
var removeVaultAccount = function (network, address, callback) {
|
|
58
58
|
var newVaultAccounts = getLocalVaultAccounts();
|
|
59
59
|
newVaultAccounts = newVaultAccounts.filter(function (a) {
|
|
60
60
|
if (a.address !== address) {
|
|
@@ -76,7 +76,7 @@ export var VaultAccountsProvider = function (_a) {
|
|
|
76
76
|
callback();
|
|
77
77
|
}
|
|
78
78
|
};
|
|
79
|
-
var getVaultAccount = function (address) {
|
|
79
|
+
var getVaultAccount = function (network, address) {
|
|
80
80
|
var _a;
|
|
81
81
|
var localVaultAccounts = getLocalVaultAccounts();
|
|
82
82
|
if (!localVaultAccounts) {
|
|
@@ -86,7 +86,7 @@ export var VaultAccountsProvider = function (_a) {
|
|
|
86
86
|
return isLocalNetworkAddress(network, a, address);
|
|
87
87
|
})) !== null && _a !== void 0 ? _a : null);
|
|
88
88
|
};
|
|
89
|
-
var renameVaultAccount = function (address, newName) {
|
|
89
|
+
var renameVaultAccount = function (network, address, newName) {
|
|
90
90
|
var newVaultAccounts = getLocalVaultAccounts();
|
|
91
91
|
newVaultAccounts = newVaultAccounts.map(function (a) {
|
|
92
92
|
return isLocalNetworkAddress(network, a, address)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/VaultAccountsProvider/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;wCACwC;AAExC,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACpE,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAKvE,OAAO,EAAE,2BAA2B,EAAE,MAAM,YAAY,C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KACJ,IAAI,EAAE,OAAO,IAEjB,CAAC,CAAC,CAAC;QALL,CAKK,CACN,CAAC;QACF,YAAY,CAAC,OAAO,CAClB,yBAAyB,EACzB,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,CACjC,CAAC;QACF,eAAe,CACb,gBAAgB,CAAC,MAAM,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,OAAO,KAAK,OAAO,EAArB,CAAqB,CAAC,EACrD,oBAAoB,EACpB,gBAAgB,CACjB,CAAC;IACJ,CAAC,CAAC;IAEF,qCAAqC;IACrC,IAAM,gBAAgB,GAAG,UAAC,OAAe;QACvC,OAAA,gBAAgB,CAAC,OAAO,CAAC,MAAM,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,OAAO,KAAK,OAAO,EAArB,CAAqB,CAAC;IAA7D,CAA6D,CAAC;IAEhE,OAAO,CACL,KAAC,oBAAoB,CAAC,QAAQ,IAC5B,KAAK,EAAE;YACL,kBAAkB,oBAAA;YAClB,eAAe,iBAAA;YACf,kBAAkB,oBAAA;YAClB,kBAAkB,oBAAA;YAClB,eAAe,iBAAA;YACf,gBAAgB,kBAAA;YAChB,aAAa,EAAE,gBAAgB,CAAC,OAAO;SACxC,YAEA,QAAQ,GACqB,CACjC,CAAC;AACJ,CAAC,CAAC","file":"index.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport { ellipsisFn, setStateWithRef } from \"@w3ux/utils\";\nimport { createContext, useContext, useRef, useState } from \"react\";\nimport { getLocalVaultAccounts, isLocalNetworkAddress } from \"./utils\";\nimport type {\n VaultAccountsContextInterface,\n VaultAccountsProviderProps,\n} from \"./types\";\nimport { defaultVaultAccountsContext } from \"./defaults\";\nimport { VaultAccount } from \"../types\";\n\nexport const VaultAccountsContext =\n createContext<VaultAccountsContextInterface>(defaultVaultAccountsContext);\n\nexport const useVaultAccounts = () => useContext(VaultAccountsContext);\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"]}
|
|
@@ -5,11 +5,11 @@ export interface VaultAccountsProviderProps {
|
|
|
5
5
|
network: string;
|
|
6
6
|
}
|
|
7
7
|
export interface VaultAccountsContextInterface {
|
|
8
|
-
vaultAccountExists: (address: string) => boolean;
|
|
9
|
-
addVaultAccount: (address: string, index: number, callback?: () => void) => VaultAccount | null;
|
|
10
|
-
removeVaultAccount: (address: string, callback?: () => void) => void;
|
|
11
|
-
renameVaultAccount: (address: string, newName: string) => void;
|
|
12
|
-
getVaultAccount: (address: string) => VaultAccount | null;
|
|
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
13
|
getVaultAccounts: (network: string) => VaultAccount[];
|
|
14
14
|
vaultAccounts: VaultAccount[];
|
|
15
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/VaultAccountsProvider/types.ts"],"names":[],"mappings":"AAAA;wCACwC","file":"types.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport { ReactNode } from \"react\";\nimport { VaultAccount } from \"../types\";\n\nexport interface VaultAccountsProviderProps {\n children: ReactNode;\n network: string;\n}\n\nexport interface VaultAccountsContextInterface {\n vaultAccountExists: (address: string) => boolean;\n addVaultAccount: (\n address: string,\n index: number,\n callback?: () => void\n ) => VaultAccount | null;\n removeVaultAccount: (address: string
|
|
1
|
+
{"version":3,"sources":["../src/VaultAccountsProvider/types.ts"],"names":[],"mappings":"AAAA;wCACwC","file":"types.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport { ReactNode } from \"react\";\nimport { VaultAccount } from \"../types\";\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"]}
|