@w3ux/react-connect-kit 0.1.12 → 0.1.13
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/VaultAccountsProvider/defaults.js +1 -0
- package/VaultAccountsProvider/defaults.js.map +1 -1
- package/VaultAccountsProvider/index.js +6 -5
- package/VaultAccountsProvider/index.js.map +1 -1
- package/VaultAccountsProvider/types.d.ts +1 -0
- package/VaultAccountsProvider/types.js.map +1 -1
- package/package.json +1 -1
|
@@ -4,6 +4,7 @@ export var defaultVaultAccountsContext = {
|
|
|
4
4
|
removeVaultAccount: function (address, callback) { },
|
|
5
5
|
renameVaultAccount: function (address, newName) { },
|
|
6
6
|
getVaultAccount: function (address) { return null; },
|
|
7
|
+
getVaultAccounts: function (network) { return []; },
|
|
7
8
|
vaultAccounts: [],
|
|
8
9
|
};
|
|
9
10
|
|
|
@@ -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;IACtC,eAAe,EAAE,UAAC,OAAO,EAAE,KAAK,EAAE,QAAQ,IAAK,OAAA,IAAI,EAAJ,CAAI;IACnD,kBAAkB,EAAE,UAAC,OAAO,EAAE,QAAQ,IAAM,CAAC;IAC7C,kBAAkB,EAAE,UAAC,OAAO,EAAE,OAAO,IAAM,CAAC;IAC5C,eAAe,EAAE,UAAC,OAAO,IAAK,OAAA,IAAI,EAAJ,CAAI;IAClC,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: (address) => false,\n addVaultAccount: (address, index, callback) => null,\n removeVaultAccount: (address, callback) => {},\n renameVaultAccount: (address, newName) => {},\n getVaultAccount: (address) => null,\n vaultAccounts: [],\n};\n"]}
|
|
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;IACtC,eAAe,EAAE,UAAC,OAAO,EAAE,KAAK,EAAE,QAAQ,IAAK,OAAA,IAAI,EAAJ,CAAI;IACnD,kBAAkB,EAAE,UAAC,OAAO,EAAE,QAAQ,IAAM,CAAC;IAC7C,kBAAkB,EAAE,UAAC,OAAO,EAAE,OAAO,IAAM,CAAC;IAC5C,eAAe,EAAE,UAAC,OAAO,IAAK,OAAA,IAAI,EAAJ,CAAI;IAClC,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: (address) => false,\n addVaultAccount: (address, index, callback) => null,\n removeVaultAccount: (address, callback) => {},\n renameVaultAccount: (address, newName) => {},\n getVaultAccount: (address) => null,\n getVaultAccounts: (network) => [],\n vaultAccounts: [],\n};\n"]}
|
|
@@ -20,14 +20,14 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
20
20
|
};
|
|
21
21
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
22
22
|
import { ellipsisFn, setStateWithRef } from "@w3ux/utils";
|
|
23
|
-
import { createContext, useContext,
|
|
23
|
+
import { createContext, useContext, useRef, useState } from "react";
|
|
24
24
|
import { getLocalVaultAccounts, isLocalNetworkAddress } from "./utils";
|
|
25
25
|
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
29
|
var network = _a.network, children = _a.children;
|
|
30
|
-
var _b = useState(getLocalVaultAccounts(
|
|
30
|
+
var _b = useState(getLocalVaultAccounts()), vaultAccounts = _b[0], seVaultAccountsState = _b[1];
|
|
31
31
|
var vaultAccountsRef = useRef(vaultAccounts);
|
|
32
32
|
var vaultAccountExists = function (address) {
|
|
33
33
|
return !!getLocalVaultAccounts().find(function (a) {
|
|
@@ -95,15 +95,16 @@ export var VaultAccountsProvider = function (_a) {
|
|
|
95
95
|
localStorage.setItem("polkadot_vault_accounts", JSON.stringify(newVaultAccounts));
|
|
96
96
|
setStateWithRef(newVaultAccounts.filter(function (a) { return a.network === network; }), seVaultAccountsState, vaultAccountsRef);
|
|
97
97
|
};
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
98
|
+
var getVaultAccounts = function (network) {
|
|
99
|
+
return vaultAccountsRef.current.filter(function (a) { return a.network === network; });
|
|
100
|
+
};
|
|
101
101
|
return (_jsx(VaultAccountsContext.Provider, { value: {
|
|
102
102
|
vaultAccountExists: vaultAccountExists,
|
|
103
103
|
addVaultAccount: addVaultAccount,
|
|
104
104
|
removeVaultAccount: removeVaultAccount,
|
|
105
105
|
renameVaultAccount: renameVaultAccount,
|
|
106
106
|
getVaultAccount: getVaultAccount,
|
|
107
|
+
getVaultAccounts: getVaultAccounts,
|
|
107
108
|
vaultAccounts: vaultAccountsRef.current,
|
|
108
109
|
}, children: children }));
|
|
109
110
|
};
|
|
@@ -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,
|
|
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,CAAC;AAGzD,MAAM,CAAC,IAAM,oBAAoB,GAC/B,aAAa,CAAgC,2BAA2B,CAAC,CAAC;AAE5E,MAAM,CAAC,IAAM,gBAAgB,GAAG,cAAM,OAAA,UAAU,CAAC,oBAAoB,CAAC,EAAhC,CAAgC,CAAC;AAEvE,MAAM,CAAC,IAAM,qBAAqB,GAAG,UAAC,EAGT;QAF3B,OAAO,aAAA,EACP,QAAQ,cAAA;IAEF,IAAA,KAAwC,QAAQ,CACpD,qBAAqB,EAAE,CACxB,EAFM,aAAa,QAAA,EAAE,oBAAoB,QAEzC,CAAC;IACF,IAAM,gBAAgB,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC;IAE/C,yDAAyD;IACzD,IAAM,kBAAkB,GAAG,UAAC,OAAe;QACzC,OAAA,CAAC,CAAC,qBAAqB,EAAE,CAAC,IAAI,CAAC,UAAC,CAAC;YAC/B,OAAA,qBAAqB,CAAC,OAAO,EAAE,CAAC,EAAE,OAAO,CAAC;QAA1C,CAA0C,CAC3C;IA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AO,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 network,\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 = (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 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 = (address: string, callback?: () => void) => {\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 = (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 = (address: string, newName: string) => {\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"]}
|
|
@@ -10,5 +10,6 @@ export interface VaultAccountsContextInterface {
|
|
|
10
10
|
removeVaultAccount: (address: string, callback?: () => void) => void;
|
|
11
11
|
renameVaultAccount: (address: string, newName: string) => void;
|
|
12
12
|
getVaultAccount: (address: string) => VaultAccount | null;
|
|
13
|
+
getVaultAccounts: (network: string) => VaultAccount[];
|
|
13
14
|
vaultAccounts: VaultAccount[];
|
|
14
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, callback?: () => void) => void;\n renameVaultAccount: (address: string, newName: string) => void;\n getVaultAccount: (address: string) => VaultAccount | null;\n vaultAccounts: VaultAccount[];\n}\n"]}
|
|
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, callback?: () => void) => void;\n renameVaultAccount: (address: string, newName: string) => void;\n getVaultAccount: (address: string) => VaultAccount | null;\n getVaultAccounts: (network: string) => VaultAccount[];\n vaultAccounts: VaultAccount[];\n}\n"]}
|