@w3ux/react-connect-kit 0.1.11 → 0.1.12
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.d.ts +2 -0
- package/VaultAccountsProvider/defaults.js +10 -0
- package/VaultAccountsProvider/defaults.js.map +1 -0
- package/VaultAccountsProvider/index.d.ts +5 -0
- package/VaultAccountsProvider/index.js +111 -0
- package/VaultAccountsProvider/index.js.map +1 -0
- package/VaultAccountsProvider/types.d.ts +14 -0
- package/VaultAccountsProvider/types.js +3 -0
- package/VaultAccountsProvider/types.js.map +1 -0
- package/VaultAccountsProvider/utils.d.ts +6 -0
- package/VaultAccountsProvider/utils.js +10 -0
- package/VaultAccountsProvider/utils.js.map +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/types.d.ts +1 -0
- package/types.js +1 -0
- package/types.js.map +1 -1
|
@@ -0,0 +1,10 @@
|
|
|
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; },
|
|
7
|
+
vaultAccounts: [],
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
|
|
@@ -0,0 +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"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { VaultAccountsContextInterface, VaultAccountsProviderProps } from "./types";
|
|
3
|
+
export declare const VaultAccountsContext: import("react").Context<VaultAccountsContextInterface>;
|
|
4
|
+
export declare const useVaultAccounts: () => VaultAccountsContextInterface;
|
|
5
|
+
export declare const VaultAccountsProvider: ({ network, children, }: VaultAccountsProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
13
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
14
|
+
if (ar || !(i in from)) {
|
|
15
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
16
|
+
ar[i] = from[i];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
20
|
+
};
|
|
21
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
22
|
+
import { ellipsisFn, setStateWithRef } from "@w3ux/utils";
|
|
23
|
+
import { createContext, useContext, useEffect, useRef, useState } from "react";
|
|
24
|
+
import { getLocalVaultAccounts, isLocalNetworkAddress } from "./utils";
|
|
25
|
+
import { defaultVaultAccountsContext } from "./defaults";
|
|
26
|
+
export var VaultAccountsContext = createContext(defaultVaultAccountsContext);
|
|
27
|
+
export var useVaultAccounts = function () { return useContext(VaultAccountsContext); };
|
|
28
|
+
export var VaultAccountsProvider = function (_a) {
|
|
29
|
+
var network = _a.network, children = _a.children;
|
|
30
|
+
var _b = useState(getLocalVaultAccounts(network)), vaultAccounts = _b[0], seVaultAccountsState = _b[1];
|
|
31
|
+
var vaultAccountsRef = useRef(vaultAccounts);
|
|
32
|
+
var vaultAccountExists = function (address) {
|
|
33
|
+
return !!getLocalVaultAccounts().find(function (a) {
|
|
34
|
+
return isLocalNetworkAddress(network, a, address);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
var addVaultAccount = function (address, index, callback) {
|
|
38
|
+
var newVaultAccounts = getLocalVaultAccounts();
|
|
39
|
+
if (!newVaultAccounts.find(function (a) { return isLocalNetworkAddress(network, a, address); })) {
|
|
40
|
+
var account = {
|
|
41
|
+
address: address,
|
|
42
|
+
network: network,
|
|
43
|
+
name: ellipsisFn(address),
|
|
44
|
+
source: "vault",
|
|
45
|
+
index: index,
|
|
46
|
+
};
|
|
47
|
+
newVaultAccounts = __spreadArray([], newVaultAccounts, true).concat(account);
|
|
48
|
+
localStorage.setItem("polkadot_vault_accounts", JSON.stringify(newVaultAccounts));
|
|
49
|
+
setStateWithRef(newVaultAccounts.filter(function (a) { return a.network === network; }), seVaultAccountsState, vaultAccountsRef);
|
|
50
|
+
if (typeof callback === "function") {
|
|
51
|
+
callback();
|
|
52
|
+
}
|
|
53
|
+
return account;
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
};
|
|
57
|
+
var removeVaultAccount = function (address, callback) {
|
|
58
|
+
var newVaultAccounts = getLocalVaultAccounts();
|
|
59
|
+
newVaultAccounts = newVaultAccounts.filter(function (a) {
|
|
60
|
+
if (a.address !== address) {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
if (a.network !== network) {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
});
|
|
68
|
+
if (!newVaultAccounts.length) {
|
|
69
|
+
localStorage.removeItem("polkadot_vault_accounts");
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
localStorage.setItem("polkadot_vault_accounts", JSON.stringify(newVaultAccounts));
|
|
73
|
+
}
|
|
74
|
+
setStateWithRef(newVaultAccounts.filter(function (a) { return a.network === network; }), seVaultAccountsState, vaultAccountsRef);
|
|
75
|
+
if (typeof callback === "function") {
|
|
76
|
+
callback();
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
var getVaultAccount = function (address) {
|
|
80
|
+
var _a;
|
|
81
|
+
var localVaultAccounts = getLocalVaultAccounts();
|
|
82
|
+
if (!localVaultAccounts) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
return ((_a = localVaultAccounts.find(function (a) {
|
|
86
|
+
return isLocalNetworkAddress(network, a, address);
|
|
87
|
+
})) !== null && _a !== void 0 ? _a : null);
|
|
88
|
+
};
|
|
89
|
+
var renameVaultAccount = function (address, newName) {
|
|
90
|
+
var newVaultAccounts = getLocalVaultAccounts();
|
|
91
|
+
newVaultAccounts = newVaultAccounts.map(function (a) {
|
|
92
|
+
return isLocalNetworkAddress(network, a, address)
|
|
93
|
+
? __assign(__assign({}, a), { name: newName }) : a;
|
|
94
|
+
});
|
|
95
|
+
localStorage.setItem("polkadot_vault_accounts", JSON.stringify(newVaultAccounts));
|
|
96
|
+
setStateWithRef(newVaultAccounts.filter(function (a) { return a.network === network; }), seVaultAccountsState, vaultAccountsRef);
|
|
97
|
+
};
|
|
98
|
+
useEffect(function () {
|
|
99
|
+
setStateWithRef(getLocalVaultAccounts(network), seVaultAccountsState, vaultAccountsRef);
|
|
100
|
+
}, [network]);
|
|
101
|
+
return (_jsx(VaultAccountsContext.Provider, { value: {
|
|
102
|
+
vaultAccountExists: vaultAccountExists,
|
|
103
|
+
addVaultAccount: addVaultAccount,
|
|
104
|
+
removeVaultAccount: removeVaultAccount,
|
|
105
|
+
renameVaultAccount: renameVaultAccount,
|
|
106
|
+
getVaultAccount: getVaultAccount,
|
|
107
|
+
vaultAccounts: vaultAccountsRef.current,
|
|
108
|
+
}, children: children }));
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
|
|
@@ -0,0 +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,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC/E,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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PL-3.0-only */\n\nimport { ellipsisFn, setStateWithRef } from \"@w3ux/utils\";\nimport { createContext, useContext, useEffect, 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(network)\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 // Refresh imported vault accounts on network change.\n useEffect(() => {\n setStateWithRef(\n getLocalVaultAccounts(network),\n seVaultAccountsState,\n vaultAccountsRef\n );\n }, [network]);\n\n return (\n <VaultAccountsContext.Provider\n value={{\n vaultAccountExists,\n addVaultAccount,\n removeVaultAccount,\n renameVaultAccount,\n getVaultAccount,\n vaultAccounts: vaultAccountsRef.current,\n }}\n >\n {children}\n </VaultAccountsContext.Provider>\n );\n};\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
import { VaultAccount } from "../types";
|
|
3
|
+
export interface VaultAccountsProviderProps {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
network: string;
|
|
6
|
+
}
|
|
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;
|
|
13
|
+
vaultAccounts: VaultAccount[];
|
|
14
|
+
}
|
|
@@ -0,0 +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"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { VaultAccount } from "../types";
|
|
2
|
+
export declare const getLocalVaultAccounts: (network?: string) => VaultAccount[];
|
|
3
|
+
export declare const isLocalNetworkAddress: (chain: string, a: {
|
|
4
|
+
address: string | undefined;
|
|
5
|
+
network: string;
|
|
6
|
+
}, address: string) => boolean;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { localStorageOrDefault } from "@w3ux/utils";
|
|
2
|
+
export var getLocalVaultAccounts = function (network) {
|
|
3
|
+
var localAddresses = localStorageOrDefault("polkadot_vault_accounts", [], true);
|
|
4
|
+
return network
|
|
5
|
+
? localAddresses.filter(function (a) { return a.network === network; })
|
|
6
|
+
: localAddresses;
|
|
7
|
+
};
|
|
8
|
+
export var isLocalNetworkAddress = function (chain, a, address) { return a.address === address && a.network === chain; };
|
|
9
|
+
|
|
10
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/VaultAccountsProvider/utils.ts"],"names":[],"mappings":"AAAA;wCACwC;AAExC,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAGpD,mDAAmD;AACnD,MAAM,CAAC,IAAM,qBAAqB,GAAG,UAAC,OAAgB;IACpD,IAAM,cAAc,GAAG,qBAAqB,CAC1C,yBAAyB,EACzB,EAAE,EACF,IAAI,CACa,CAAC;IAEpB,OAAO,OAAO;QACZ,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,OAAO,KAAK,OAAO,EAArB,CAAqB,CAAC;QACrD,CAAC,CAAC,cAAc,CAAC;AACrB,CAAC,CAAC;AAEF,sDAAsD;AACtD,MAAM,CAAC,IAAM,qBAAqB,GAAG,UACnC,KAAa,EACb,CAAmD,EACnD,OAAe,IACZ,OAAA,CAAC,CAAC,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK,KAAK,EAA5C,CAA4C,CAAC","file":"utils.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport { localStorageOrDefault } from \"@w3ux/utils\";\nimport { VaultAccount } from \"../types\";\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"]}
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"AAAA;wCACwC;AAExC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mCAAmC,CAAC;AAClD,cAAc,gCAAgC,CAAC","file":"index.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nexport * from \"./ExtensionsProvider/index\";\nexport * from \"./ExtensionAccountsProvider/index\";\nexport * from \"./LedgerAccountsProvider/index\";\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"AAAA;wCACwC;AAExC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mCAAmC,CAAC;AAClD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC","file":"index.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nexport * from \"./ExtensionsProvider/index\";\nexport * from \"./ExtensionAccountsProvider/index\";\nexport * from \"./LedgerAccountsProvider/index\";\nexport * from \"./VaultAccountsProvider/index\";\n"]}
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { ExtensionAccount, ExtensionInterface } from "./ExtensionsProvider/types
|
|
|
2
2
|
export * from "./ExtensionsProvider/types";
|
|
3
3
|
export * from "./ExtensionAccountsProvider/types";
|
|
4
4
|
export * from "./LedgerAccountsProvider/types";
|
|
5
|
+
export * from "./VaultAccountsProvider/types";
|
|
5
6
|
export type MaybeAddress = string | null;
|
|
6
7
|
export type AccountSource = "extension" | "external" | "ledger" | "vault";
|
|
7
8
|
export type ExternalAccountAddedBy = "system" | "user";
|
package/types.js
CHANGED
package/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"names":[],"mappings":"AAAA;wCACwC;AAOxC;;+DAE+D;AAE/D,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mCAAmC,CAAC;AAClD,cAAc,gCAAgC,CAAC","file":"types.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport {\n ExtensionAccount,\n ExtensionInterface,\n} from \"./ExtensionsProvider/types\";\n\n/*------------------------------------------------------------\n Re-export package inner types.\n ------------------------------------------------------------*/\n\nexport * from \"./ExtensionsProvider/types\";\nexport * from \"./ExtensionAccountsProvider/types\";\nexport * from \"./LedgerAccountsProvider/types\";\n\n/*------------------------------------------------------------\n Imported account types.\n ------------------------------------------------------------*/\nexport type MaybeAddress = string | null;\n\nexport type AccountSource = \"extension\" | \"external\" | \"ledger\" | \"vault\";\n\nexport type ExternalAccountAddedBy = \"system\" | \"user\";\n\nexport type ImportedAccount =\n | ExtensionAccount\n | ExternalAccount\n | LedgerAccount\n | VaultAccount;\n\nexport interface ExternalAccount {\n address: string;\n network: string;\n name: string;\n source: string;\n addedBy: ExternalAccountAddedBy;\n}\n\nexport interface LedgerAccount {\n address: string;\n network: string;\n name: string;\n source: string;\n index: number;\n}\n\nexport interface VaultAccount {\n address: string;\n network: string;\n name: string;\n source: string;\n index: number;\n}\n\n/*------------------------------------------------------------\n Extension import process types.\n ------------------------------------------------------------*/\n\nexport type RawExtensions = Map<string, RawExtensionEnable>;\n\nexport type RawExtensionEnable = (name?: string) => Promise<ExtensionInterface>;\n\nexport type ExtensionEnableStatus =\n | \"valid\"\n | \"extension_not_found\"\n | \"enable_invalid\";\n\nexport type ExtensionEnableResults = Map<string, ExtensionEnableResult>;\n\nexport interface ExtensionEnableResult {\n extension?: ExtensionInterface;\n connected: boolean;\n error?: string;\n}\n\n/*------------------------------------------------------------\n Miscellaneous types.\n ------------------------------------------------------------*/\n\nexport type VoidFn = () => void;\n\nexport type Sync = \"synced\" | \"unsynced\" | \"syncing\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyFunction = any;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyJson = any;\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"names":[],"mappings":"AAAA;wCACwC;AAOxC;;+DAE+D;AAE/D,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mCAAmC,CAAC;AAClD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC","file":"types.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport {\n ExtensionAccount,\n ExtensionInterface,\n} from \"./ExtensionsProvider/types\";\n\n/*------------------------------------------------------------\n Re-export package inner types.\n ------------------------------------------------------------*/\n\nexport * from \"./ExtensionsProvider/types\";\nexport * from \"./ExtensionAccountsProvider/types\";\nexport * from \"./LedgerAccountsProvider/types\";\nexport * from \"./VaultAccountsProvider/types\";\n\n/*------------------------------------------------------------\n Imported account types.\n ------------------------------------------------------------*/\nexport type MaybeAddress = string | null;\n\nexport type AccountSource = \"extension\" | \"external\" | \"ledger\" | \"vault\";\n\nexport type ExternalAccountAddedBy = \"system\" | \"user\";\n\nexport type ImportedAccount =\n | ExtensionAccount\n | ExternalAccount\n | LedgerAccount\n | VaultAccount;\n\nexport interface ExternalAccount {\n address: string;\n network: string;\n name: string;\n source: string;\n addedBy: ExternalAccountAddedBy;\n}\n\nexport interface LedgerAccount {\n address: string;\n network: string;\n name: string;\n source: string;\n index: number;\n}\n\nexport interface VaultAccount {\n address: string;\n network: string;\n name: string;\n source: string;\n index: number;\n}\n\n/*------------------------------------------------------------\n Extension import process types.\n ------------------------------------------------------------*/\n\nexport type RawExtensions = Map<string, RawExtensionEnable>;\n\nexport type RawExtensionEnable = (name?: string) => Promise<ExtensionInterface>;\n\nexport type ExtensionEnableStatus =\n | \"valid\"\n | \"extension_not_found\"\n | \"enable_invalid\";\n\nexport type ExtensionEnableResults = Map<string, ExtensionEnableResult>;\n\nexport interface ExtensionEnableResult {\n extension?: ExtensionInterface;\n connected: boolean;\n error?: string;\n}\n\n/*------------------------------------------------------------\n Miscellaneous types.\n ------------------------------------------------------------*/\n\nexport type VoidFn = () => void;\n\nexport type Sync = \"synced\" | \"unsynced\" | \"syncing\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyFunction = any;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyJson = any;\n"]}
|