@w3ux/react-connect-kit 0.0.1

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.
Files changed (49) hide show
  1. package/ExtensionAccountsProvider/Extensions.d.ts +13 -0
  2. package/ExtensionAccountsProvider/Extensions.js +205 -0
  3. package/ExtensionAccountsProvider/Extensions.js.map +1 -0
  4. package/ExtensionAccountsProvider/defaults.d.ts +9 -0
  5. package/ExtensionAccountsProvider/defaults.js +14 -0
  6. package/ExtensionAccountsProvider/defaults.js.map +1 -0
  7. package/ExtensionAccountsProvider/index.d.ts +5 -0
  8. package/ExtensionAccountsProvider/index.js +327 -0
  9. package/ExtensionAccountsProvider/index.js.map +1 -0
  10. package/ExtensionAccountsProvider/snap.d.ts +2 -0
  11. package/ExtensionAccountsProvider/snap.js +129 -0
  12. package/ExtensionAccountsProvider/snap.js.map +1 -0
  13. package/ExtensionAccountsProvider/types.d.ts +28 -0
  14. package/ExtensionAccountsProvider/types.js +3 -0
  15. package/ExtensionAccountsProvider/types.js.map +1 -0
  16. package/ExtensionAccountsProvider/useImportExtension.d.ts +6 -0
  17. package/ExtensionAccountsProvider/useImportExtension.js +66 -0
  18. package/ExtensionAccountsProvider/useImportExtension.js.map +1 -0
  19. package/ExtensionAccountsProvider/utils.d.ts +8 -0
  20. package/ExtensionAccountsProvider/utils.js +37 -0
  21. package/ExtensionAccountsProvider/utils.js.map +1 -0
  22. package/ExtensionsProvider/defaults.d.ts +2 -0
  23. package/ExtensionsProvider/defaults.js +11 -0
  24. package/ExtensionsProvider/defaults.js.map +1 -0
  25. package/ExtensionsProvider/index.d.ts +7 -0
  26. package/ExtensionsProvider/index.js +156 -0
  27. package/ExtensionsProvider/index.js.map +1 -0
  28. package/ExtensionsProvider/types.d.ts +43 -0
  29. package/ExtensionsProvider/types.js +3 -0
  30. package/ExtensionsProvider/types.js.map +1 -0
  31. package/ExtensionsProvider/utils.d.ts +20 -0
  32. package/ExtensionsProvider/utils.js +78 -0
  33. package/ExtensionsProvider/utils.js.map +1 -0
  34. package/LedgerAccountsProvider/defaults.d.ts +2 -0
  35. package/LedgerAccountsProvider/defaults.js +10 -0
  36. package/LedgerAccountsProvider/defaults.js.map +1 -0
  37. package/LedgerAccountsProvider/index.d.ts +5 -0
  38. package/LedgerAccountsProvider/index.js +116 -0
  39. package/LedgerAccountsProvider/index.js.map +1 -0
  40. package/LedgerAccountsProvider/types.d.ts +21 -0
  41. package/LedgerAccountsProvider/types.js +3 -0
  42. package/LedgerAccountsProvider/types.js.map +1 -0
  43. package/LedgerAccountsProvider/utils.d.ts +9 -0
  44. package/LedgerAccountsProvider/utils.js +38 -0
  45. package/LedgerAccountsProvider/utils.js.map +1 -0
  46. package/package.json +6 -0
  47. package/types.d.ts +39 -0
  48. package/types.js +3 -0
  49. package/types.js.map +1 -0
@@ -0,0 +1,43 @@
1
+ import type { FunctionComponent, SVGProps } from "react";
2
+ import { AnyJson, ExternalAccountAddedBy, VoidFn } from "../types";
3
+ export interface ExtensionsContextInterface {
4
+ checkingInjectedWeb3: boolean;
5
+ extensionsStatus: Record<string, ExtensionStatus>;
6
+ setExtensionStatus: (id: string, status: ExtensionStatus) => void;
7
+ removeExtensionStatus: (id: string) => void;
8
+ extensionInstalled: (id: string) => boolean;
9
+ extensionCanConnect: (id: string) => boolean;
10
+ extensionHasFeature: (id: string, feature: string) => boolean;
11
+ }
12
+ export interface ExtensionInjected extends ExtensionConfig {
13
+ id: string;
14
+ enable: (n: string) => Promise<ExtensionInterface>;
15
+ }
16
+ export interface ExtensionInterface {
17
+ accounts: {
18
+ subscribe: (a: (b: ExtensionAccount[]) => void) => VoidFn;
19
+ get: () => Promise<ExtensionAccount[]>;
20
+ };
21
+ provider: AnyJson;
22
+ metadata: AnyJson;
23
+ signer: AnyJson;
24
+ }
25
+ export interface ExtensionAccount extends ExtensionMetadata {
26
+ address: string;
27
+ meta?: AnyJson;
28
+ name: string;
29
+ signer?: AnyJson;
30
+ }
31
+ export interface ExtensionConfig {
32
+ id: string;
33
+ title: string;
34
+ icon: FunctionComponent<SVGProps<SVGSVGElement> & {
35
+ title?: string | undefined;
36
+ }>;
37
+ url: string;
38
+ }
39
+ export interface ExtensionMetadata {
40
+ addedBy?: ExternalAccountAddedBy;
41
+ source: string;
42
+ }
43
+ export type ExtensionStatus = "installed" | "not_authenticated" | "connected";
@@ -0,0 +1,3 @@
1
+ export {};
2
+
3
+
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/ExtensionsProvider/types.ts"],"names":[],"mappings":"AAAA;yCACyC","file":"types.js","sourcesContent":["/* @license Copyright 2024 @polkadot-cloud/library authors & contributors\",\n\"SPDX-License-Identifier: GPL-3.0-only */\n\nimport type { FunctionComponent, SVGProps } from \"react\";\nimport { AnyJson, ExternalAccountAddedBy, VoidFn } from \"../types\";\n\n// Extensions context interface.\nexport interface ExtensionsContextInterface {\n checkingInjectedWeb3: boolean;\n extensionsStatus: Record<string, ExtensionStatus>;\n setExtensionStatus: (id: string, status: ExtensionStatus) => void;\n removeExtensionStatus: (id: string) => void;\n extensionInstalled: (id: string) => boolean;\n extensionCanConnect: (id: string) => boolean;\n extensionHasFeature: (id: string, feature: string) => boolean;\n}\n\n// Top level required properties the extension must expose via their `injectedWeb3` entry.\nexport interface ExtensionInjected extends ExtensionConfig {\n id: string;\n enable: (n: string) => Promise<ExtensionInterface>;\n}\n\n// Required properties `enable` must provide after resolution.\nexport interface ExtensionInterface {\n accounts: {\n subscribe: (a: (b: ExtensionAccount[]) => void) => VoidFn;\n get: () => Promise<ExtensionAccount[]>;\n };\n provider: AnyJson;\n metadata: AnyJson;\n signer: AnyJson;\n}\n\n// Required properties returned after subscribing to accounts.\nexport interface ExtensionAccount extends ExtensionMetadata {\n address: string;\n meta?: AnyJson;\n name: string;\n signer?: AnyJson;\n}\n\n// Configuration item of an extension.\nexport interface ExtensionConfig {\n id: string;\n title: string;\n icon: FunctionComponent<\n SVGProps<SVGSVGElement> & { title?: string | undefined }\n >;\n url: string;\n}\n\n// Miscellaneous metadata added to an extension.\nexport interface ExtensionMetadata {\n addedBy?: ExternalAccountAddedBy;\n source: string;\n}\n\nexport type ExtensionStatus = \"installed\" | \"not_authenticated\" | \"connected\";\n"]}
@@ -0,0 +1,20 @@
1
+ import { SnapRpcMethodRequest } from "@chainsafe/metamask-polkadot-types";
2
+ import { AnyJson } from "../types";
3
+ declare global {
4
+ interface Window {
5
+ injectedWeb3?: AnyJson;
6
+ ethereum: {
7
+ isMetaMask: boolean;
8
+ send: (request: SnapRpcMethodRequest | {
9
+ method: string;
10
+ params?: never[];
11
+ }) => Promise<unknown>;
12
+ on: (eventName: unknown, callback: unknown) => unknown;
13
+ request: <T>(request: SnapRpcMethodRequest | {
14
+ method: string;
15
+ params?: AnyJson;
16
+ }) => Promise<T>;
17
+ };
18
+ }
19
+ }
20
+ export declare const polkadotSnapAvailable: () => Promise<boolean>;
@@ -0,0 +1,78 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import { hasMetaMask, } from "@chainsafe/metamask-polkadot-adapter/src/utils";
38
+ import { withTimeout } from "@w3ux/utils";
39
+ var getWalletSnaps = function () { return __awaiter(void 0, void 0, void 0, function () {
40
+ var ethRequest, response;
41
+ var _a;
42
+ return __generator(this, function (_b) {
43
+ switch (_b.label) {
44
+ case 0:
45
+ ethRequest = ((_a = window === null || window === void 0 ? void 0 : window.ethereum) === null || _a === void 0 ? void 0 : _a.request) ? true : false;
46
+ if (!ethRequest) return [3 , 2];
47
+ return [4 , withTimeout(200, window.ethereum.request({ method: "wallet_getSnaps" }))];
48
+ case 1:
49
+ response = _b.sent();
50
+ return [2 , response];
51
+ case 2: return [2 ];
52
+ }
53
+ });
54
+ }); };
55
+ export var polkadotSnapAvailable = function () { return __awaiter(void 0, void 0, void 0, function () {
56
+ var e_1;
57
+ return __generator(this, function (_a) {
58
+ switch (_a.label) {
59
+ case 0:
60
+ if (!hasMetaMask()) {
61
+ return [2 , false];
62
+ }
63
+ _a.label = 1;
64
+ case 1:
65
+ _a.trys.push([1, 3, , 4]);
66
+ return [4 , getWalletSnaps()];
67
+ case 2:
68
+ _a.sent();
69
+ return [2 , true];
70
+ case 3:
71
+ e_1 = _a.sent();
72
+ return [2 , false];
73
+ case 4: return [2 ];
74
+ }
75
+ });
76
+ }); };
77
+
78
+
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/ExtensionsProvider/utils.ts"],"names":[],"mappings":"AAAA;yCACyC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEzC,OAAO,EAEL,WAAW,GACZ,MAAM,gDAAgD,CAAC;AAExD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAsB1C,oGAAoG;AACpG,8FAA8F;AAC9F,qBAAqB;AACrB,IAAM,cAAc,GAAG;;;;;;gBACf,UAAU,GAAG,CAAA,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,QAAQ,0CAAE,OAAO,EAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;qBACxD,UAAU,EAAV,wBAAU;gBACK,qBAAM,WAAW,CAChC,GAAG,EACH,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,iBAAiB,EAAE,CAAC,CACvD,EAAA;;gBAHK,QAAQ,GAAG,SAGhB;gBACD,sBAAO,QAAqC,EAAC;oBAE/C,sBAAO;;;KACR,CAAC;AAEF,mEAAmE;AACnE,MAAM,CAAC,IAAM,qBAAqB,GAAG;;;;;gBACnC,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;oBACnB,sBAAO,KAAK,EAAC;gBACf,CAAC;;;;gBAGC,qBAAM,cAAc,EAAE,EAAA;;gBAAtB,SAAsB,CAAC;gBACvB,sBAAO,IAAI,EAAC;;;gBAEZ,sBAAO,KAAK,EAAC;;;;KAEhB,CAAC","file":"utils.js","sourcesContent":["/* @license Copyright 2024 @polkadot-cloud/library authors & contributors\",\n\"SPDX-License-Identifier: GPL-3.0-only */\n\nimport {\n GetSnapsResponse,\n hasMetaMask,\n} from \"@chainsafe/metamask-polkadot-adapter/src/utils\";\nimport { SnapRpcMethodRequest } from \"@chainsafe/metamask-polkadot-types\";\nimport { withTimeout } from \"@w3ux/utils\";\nimport { AnyJson } from \"../types\";\n\n// Workaround for current `ethereum` snap types. See\n// https://github.com/ChainSafe/metamask-snap-polkadot/blob/e0f3d4fc0be7366c62211e29d3a276e4fab5669e/packages/adapter/src/types.ts#L40\n// for full type.\ndeclare global {\n interface Window {\n injectedWeb3?: AnyJson;\n ethereum: {\n isMetaMask: boolean;\n send: (\n request: SnapRpcMethodRequest | { method: string; params?: never[] }\n ) => Promise<unknown>;\n on: (eventName: unknown, callback: unknown) => unknown;\n request: <T>(\n request: SnapRpcMethodRequest | { method: string; params?: AnyJson }\n ) => Promise<T>;\n };\n }\n}\n\n// Checks if snaps are supported. Note that other extensions may inject `window.ethereum`, which may\n// break the request. We wrap the request in a timeout to ensure it doesn't hang the extension\n// discovery process.\nconst getWalletSnaps = async (): Promise<GetSnapsResponse> => {\n const ethRequest = window?.ethereum?.request ? true : false;\n if (ethRequest) {\n const response = await withTimeout(\n 200,\n window.ethereum.request({ method: \"wallet_getSnaps\" })\n );\n return response as Promise<GetSnapsResponse>;\n }\n return;\n};\n\n// Determines if Metamask Polkadot Snap is available and supported.\nexport const polkadotSnapAvailable = async (): Promise<boolean> => {\n if (!hasMetaMask()) {\n return false;\n }\n\n try {\n await getWalletSnaps();\n return true;\n } catch (e) {\n return false;\n }\n};\n"]}
@@ -0,0 +1,2 @@
1
+ import { LedgerAccountsContextInterface } from "./types";
2
+ export declare const defaultLedgerAccountsContext: LedgerAccountsContextInterface;
@@ -0,0 +1,10 @@
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; },
7
+ ledgerAccounts: [],
8
+ };
9
+
10
+
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/LedgerAccountsProvider/defaults.ts"],"names":[],"mappings":"AAAA;yCACyC;AACzC,6GAA6G;AAI7G,MAAM,CAAC,IAAM,4BAA4B,GAAmC;IAC1E,mBAAmB,EAAE,UAAC,OAAO,IAAK,OAAA,KAAK,EAAL,CAAK;IACvC,gBAAgB,EAAE,UAAC,OAAO,EAAE,KAAK,EAAE,QAAQ,IAAK,OAAA,IAAI,EAAJ,CAAI;IACpD,mBAAmB,EAAE,UAAC,OAAO,EAAE,QAAQ,IAAM,CAAC;IAC9C,mBAAmB,EAAE,UAAC,OAAO,EAAE,OAAO,IAAM,CAAC;IAC7C,gBAAgB,EAAE,UAAC,OAAO,IAAK,OAAA,IAAI,EAAJ,CAAI;IACnC,cAAc,EAAE,EAAE;CACnB,CAAC","file":"defaults.js","sourcesContent":["/* @license Copyright 2024 @polkadot-cloud/library authors & contributors\",\n\"SPDX-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: (address) => false,\n addLedgerAccount: (address, index, callback) => null,\n removeLedgerAccount: (address, callback) => {},\n renameLedgerAccount: (address, newName) => {},\n getLedgerAccount: (address) => null,\n ledgerAccounts: [],\n};\n"]}
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import { LedgerAccountsContextInterface, LedgerAccountsProviderProps } from "./types";
3
+ export declare const LedgerAccountsContext: import("react").Context<LedgerAccountsContextInterface>;
4
+ export declare const useLedgerAccounts: () => LedgerAccountsContextInterface;
5
+ export declare const LedgerAccountsProvider: ({ children, network, }: LedgerAccountsProviderProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,116 @@
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 { createContext, useContext, useRef, useState } from "react";
23
+ import { defaultLedgerAccountsContext } from "./defaults";
24
+ import { getLocalLedgerAccounts, getLocalLedgerAddresses, isLocalLedgerAccount, renameLocalLedgerAddress, } from "./utils";
25
+ import { setStateWithRef } from "@w3ux/utils";
26
+ import { useEffectIgnoreInitial } from "@w3ux/hooks";
27
+ export var LedgerAccountsContext = createContext(defaultLedgerAccountsContext);
28
+ export var useLedgerAccounts = function () { return useContext(LedgerAccountsContext); };
29
+ export var LedgerAccountsProvider = function (_a) {
30
+ var children = _a.children, network = _a.network;
31
+ var _b = useState(getLocalLedgerAccounts(network)), ledgerAccounts = _b[0], setLedgerAccountsState = _b[1];
32
+ var ledgerAccountsRef = useRef(ledgerAccounts);
33
+ var ledgerAccountExists = function (address) {
34
+ return !!getLocalLedgerAccounts().find(function (account) {
35
+ return isLocalLedgerAccount(network, account, address);
36
+ });
37
+ };
38
+ var addLedgerAccount = function (address, index, callback) {
39
+ var newLedgerAccounts = getLocalLedgerAccounts();
40
+ var ledgerAddress = getLocalLedgerAddresses().find(function (a) {
41
+ return isLocalLedgerAccount(network, a, address);
42
+ });
43
+ if (ledgerAddress &&
44
+ !newLedgerAccounts.find(function (account) {
45
+ return isLocalLedgerAccount(network, account, address);
46
+ })) {
47
+ var newAccount = {
48
+ address: address,
49
+ network: network,
50
+ name: ledgerAddress.name,
51
+ source: "ledger",
52
+ index: index,
53
+ };
54
+ newLedgerAccounts = __spreadArray([], newLedgerAccounts, true).concat(newAccount);
55
+ localStorage.setItem("ledger_accounts", JSON.stringify(newLedgerAccounts));
56
+ setStateWithRef(newLedgerAccounts.filter(function (account) { return account.network === network; }), setLedgerAccountsState, ledgerAccountsRef);
57
+ if (typeof callback === "function") {
58
+ callback();
59
+ }
60
+ return newAccount;
61
+ }
62
+ return null;
63
+ };
64
+ var removeLedgerAccount = function (address, callback) {
65
+ var newLedgerAccounts = getLocalLedgerAccounts().filter(function (account) {
66
+ if (account.address !== address) {
67
+ return true;
68
+ }
69
+ if (account.network !== network) {
70
+ return true;
71
+ }
72
+ return false;
73
+ });
74
+ if (!newLedgerAccounts.length) {
75
+ localStorage.removeItem("ledger_accounts");
76
+ }
77
+ else {
78
+ localStorage.setItem("ledger_accounts", JSON.stringify(newLedgerAccounts));
79
+ }
80
+ setStateWithRef(newLedgerAccounts.filter(function (account) { return account.network === network; }), setLedgerAccountsState, ledgerAccountsRef);
81
+ if (typeof callback === "function") {
82
+ callback();
83
+ }
84
+ };
85
+ var renameLedgerAccount = function (address, newName) {
86
+ var newLedgerAccounts = getLocalLedgerAccounts().map(function (account) {
87
+ return isLocalLedgerAccount(network, account, address)
88
+ ? __assign(__assign({}, account), { name: newName }) : account;
89
+ });
90
+ renameLocalLedgerAddress(address, newName, network);
91
+ localStorage.setItem("ledger_accounts", JSON.stringify(newLedgerAccounts));
92
+ setStateWithRef(newLedgerAccounts.filter(function (account) { return account.network === network; }), setLedgerAccountsState, ledgerAccountsRef);
93
+ };
94
+ var getLedgerAccount = function (address) {
95
+ var localLedgerAccounts = getLocalLedgerAccounts();
96
+ if (!localLedgerAccounts) {
97
+ return null;
98
+ }
99
+ return (localLedgerAccounts.find(function (account) {
100
+ return isLocalLedgerAccount(network, account, address);
101
+ }) || null);
102
+ };
103
+ useEffectIgnoreInitial(function () {
104
+ setStateWithRef(getLocalLedgerAccounts(network), setLedgerAccountsState, ledgerAccountsRef);
105
+ }, [network]);
106
+ return (_jsx(LedgerAccountsContext.Provider, { value: {
107
+ ledgerAccountExists: ledgerAccountExists,
108
+ getLedgerAccount: getLedgerAccount,
109
+ addLedgerAccount: addLedgerAccount,
110
+ removeLedgerAccount: removeLedgerAccount,
111
+ renameLedgerAccount: renameLedgerAccount,
112
+ ledgerAccounts: ledgerAccountsRef.current,
113
+ }, children: children }));
114
+ };
115
+
116
+
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/LedgerAccountsProvider/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;yCACyC;AAEzC,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;AAC9C,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAErD,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,EAGT;QAF5B,QAAQ,cAAA,EACR,OAAO,aAAA;IAEP,qCAAqC;IAC/B,IAAA,KAA2C,QAAQ,CACvD,sBA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BAAA;YAChB,mBAAmB,qBAAA;YACnB,mBAAmB,qBAAA;YACnB,cAAc,EAAE,iBAAiB,CAAC,OAAO;SAC1C,YAEA,QAAQ,GACsB,CAClC,CAAC;AACJ,CAAC,CAAC","file":"index.js","sourcesContent":["/* @license Copyright 2024 @polkadot-cloud/library authors & contributors\",\n\"SPDX-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\";\nimport { useEffectIgnoreInitial } from \"@w3ux/hooks\";\n\nexport const LedgerAccountsContext =\n createContext<LedgerAccountsContextInterface>(defaultLedgerAccountsContext);\n\nexport const useLedgerAccounts = () => useContext(LedgerAccountsContext);\n\nexport const LedgerAccountsProvider = ({\n children,\n network,\n}: LedgerAccountsProviderProps) => {\n // Store the fetched ledger accounts.\n const [ledgerAccounts, setLedgerAccountsState] = useState<LedgerAccount[]>(\n getLocalLedgerAccounts(network)\n );\n const ledgerAccountsRef = useRef(ledgerAccounts);\n\n // Check if a Ledger address exists in imported addresses.\n const ledgerAccountExists = (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 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 = (address: string, callback?: () => void) => {\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 = (address: string, newName: string) => {\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 = (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 // Refresh imported ledger accounts on network change.\n useEffectIgnoreInitial(() => {\n setStateWithRef(\n getLocalLedgerAccounts(network),\n setLedgerAccountsState,\n ledgerAccountsRef\n );\n }, [network]);\n\n return (\n <LedgerAccountsContext.Provider\n value={{\n ledgerAccountExists,\n getLedgerAccount,\n addLedgerAccount,\n removeLedgerAccount,\n renameLedgerAccount,\n ledgerAccounts: ledgerAccountsRef.current,\n }}\n >\n {children}\n </LedgerAccountsContext.Provider>\n );\n};\n"]}
@@ -0,0 +1,21 @@
1
+ import { ReactNode } from "react";
2
+ import { LedgerAccount } from "../types";
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;
9
+ ledgerAccounts: LedgerAccount[];
10
+ }
11
+ export interface LedgerAccountsProviderProps {
12
+ children: ReactNode;
13
+ network: string;
14
+ }
15
+ export interface LedgerAddress {
16
+ address: string;
17
+ index: number;
18
+ name: string;
19
+ network: string;
20
+ pubKey: string;
21
+ }
@@ -0,0 +1,3 @@
1
+ export {};
2
+
3
+
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/LedgerAccountsProvider/types.ts"],"names":[],"mappings":"AAAA;yCACyC","file":"types.js","sourcesContent":["/* @license Copyright 2024 @polkadot-cloud/library authors & contributors\",\n\"SPDX-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, callback?: () => void) => void;\n renameLedgerAccount: (address: string, name: string) => void;\n getLedgerAccount: (address: string) => LedgerAccount | null;\n ledgerAccounts: LedgerAccount[];\n}\n\nexport interface LedgerAccountsProviderProps {\n children: ReactNode;\n network: string;\n}\n\nexport interface LedgerAddress {\n address: string;\n index: number;\n name: string;\n network: string;\n pubKey: string;\n}\n"]}
@@ -0,0 +1,9 @@
1
+ import { LedgerAccount } from "../types";
2
+ import { LedgerAddress } from "./types";
3
+ export declare const getLocalLedgerAccounts: (network?: string) => LedgerAccount[];
4
+ export declare const isLocalLedgerAccount: (network: string, account: {
5
+ address: string | null;
6
+ network: string;
7
+ }, address: string) => boolean;
8
+ export declare const getLocalLedgerAddresses: (network?: string) => LedgerAddress[];
9
+ export declare const renameLocalLedgerAddress: (address: string, name: string, network: string) => void;
@@ -0,0 +1,38 @@
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
+ import { localStorageOrDefault } from "@w3ux/utils";
13
+ export var getLocalLedgerAccounts = function (network) {
14
+ var localAddresses = localStorageOrDefault("ledger_accounts", [], true);
15
+ return network
16
+ ? localAddresses.filter(function (a) { return a.network === network; })
17
+ : localAddresses;
18
+ };
19
+ export var isLocalLedgerAccount = function (network, account, address) { return account.address === address && account.network === network; };
20
+ export var getLocalLedgerAddresses = function (network) {
21
+ var localAddresses = localStorageOrDefault("ledger_addresses", [], true);
22
+ return network
23
+ ? localAddresses.filter(function (a) { return a.network === network; })
24
+ : localAddresses;
25
+ };
26
+ export var renameLocalLedgerAddress = function (address, name, network) {
27
+ var _a;
28
+ var localLedger = (_a = localStorageOrDefault("ledger_addresses", [], true)) === null || _a === void 0 ? void 0 : _a.map(function (i) {
29
+ return !(i.address === address && i.network === network)
30
+ ? i
31
+ : __assign(__assign({}, i), { name: name });
32
+ });
33
+ if (localLedger) {
34
+ localStorage.setItem("ledger_addresses", JSON.stringify(localLedger));
35
+ }
36
+ };
37
+
38
+
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/LedgerAccountsProvider/utils.ts"],"names":[],"mappings":"AAAA;yCACyC;;;;;;;;;;;;AAEzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAIpD,oDAAoD;AACpD,MAAM,CAAC,IAAM,sBAAsB,GAAG,UAAC,OAAgB;IACrD,IAAM,cAAc,GAAG,qBAAqB,CAC1C,iBAAiB,EACjB,EAAE,EACF,IAAI,CACc,CAAC;IAErB,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,qDAAqD;AACrD,MAAM,CAAC,IAAM,oBAAoB,GAAG,UAClC,OAAe,EACf,OAAoD,EACpD,OAAe,IACZ,OAAA,OAAO,CAAC,OAAO,KAAK,OAAO,IAAI,OAAO,CAAC,OAAO,KAAK,OAAO,EAA1D,CAA0D,CAAC;AAEhE,kDAAkD;AAClD,MAAM,CAAC,IAAM,uBAAuB,GAAG,UAAC,OAAgB;IACtD,IAAM,cAAc,GAAG,qBAAqB,CAC1C,kBAAkB,EAClB,EAAE,EACF,IAAI,CACc,CAAC;IAErB,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,gDAAgD;AAChD,MAAM,CAAC,IAAM,wBAAwB,GAAG,UACtC,OAAe,EACf,IAAY,EACZ,OAAe;;IAEf,IAAM,WAAW,GAAG,MAClB,qBAAqB,CAAC,kBAAkB,EAAE,EAAE,EAAE,IAAI,CACnD,0CAAE,GAAG,CAAC,UAAC,CAAC;QACP,OAAA,CAAC,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC;YAC/C,CAAC,CAAC,CAAC;YACH,CAAC,uBACM,CAAC,KACJ,IAAI,MAAA,GACL;IALL,CAKK,CACN,CAAC;IACF,IAAI,WAAW,EAAE,CAAC;QAChB,YAAY,CAAC,OAAO,CAAC,kBAAkB,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC;IACxE,CAAC;AACH,CAAC,CAAC","file":"utils.js","sourcesContent":["/* @license Copyright 2024 @polkadot-cloud/library authors & contributors\",\n\"SPDX-License-Identifier: GPL-3.0-only */\n\nimport { localStorageOrDefault } from \"@w3ux/utils\";\nimport { LedgerAccount } from \"../types\";\nimport { LedgerAddress } from \"./types\";\n\n// Gets imported Ledger accounts from local storage.\nexport const getLocalLedgerAccounts = (network?: string): LedgerAccount[] => {\n const localAddresses = localStorageOrDefault(\n \"ledger_accounts\",\n [],\n true\n ) as LedgerAccount[];\n\n return network\n ? localAddresses.filter((a) => a.network === network)\n : localAddresses;\n};\n\n// Gets whether an address is a local Ledger account.\nexport const isLocalLedgerAccount = (\n network: string,\n account: { address: string | null; network: string },\n address: string\n) => account.address === address && account.network === network;\n\n// Gets saved ledger addresses from local storage.\nexport const getLocalLedgerAddresses = (network?: string) => {\n const localAddresses = localStorageOrDefault(\n \"ledger_addresses\",\n [],\n true\n ) as LedgerAddress[];\n\n return network\n ? localAddresses.filter((a) => a.network === network)\n : localAddresses;\n};\n\n// Renames a record from local ledger addresses.\nexport const renameLocalLedgerAddress = (\n address: string,\n name: string,\n network: string\n) => {\n const localLedger = (\n localStorageOrDefault(\"ledger_addresses\", [], true) as LedgerAddress[]\n )?.map((i) =>\n !(i.address === address && i.network === network)\n ? i\n : {\n ...i,\n name,\n }\n );\n if (localLedger) {\n localStorage.setItem(\"ledger_addresses\", JSON.stringify(localLedger));\n }\n};\n"]}
package/package.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "@w3ux/react-connect-kit",
3
+ "version": "0.0.1",
4
+ "license": "GPL-3.0-only",
5
+ "type": "module"
6
+ }
package/types.d.ts ADDED
@@ -0,0 +1,39 @@
1
+ import { ExtensionAccount, ExtensionInterface } from "./ExtensionsProvider/types";
2
+ export type MaybeAddress = string | null;
3
+ export type AccountSource = "extension" | "external" | "ledger" | "vault";
4
+ export type ExternalAccountAddedBy = "system" | "user";
5
+ export type ImportedAccount = ExtensionAccount | ExternalAccount | LedgerAccount | VaultAccount;
6
+ export interface ExternalAccount {
7
+ address: string;
8
+ network: string;
9
+ name: string;
10
+ source: string;
11
+ addedBy: ExternalAccountAddedBy;
12
+ }
13
+ export interface LedgerAccount {
14
+ address: string;
15
+ network: string;
16
+ name: string;
17
+ source: string;
18
+ index: number;
19
+ }
20
+ export interface VaultAccount {
21
+ address: string;
22
+ network: string;
23
+ name: string;
24
+ source: string;
25
+ index: number;
26
+ }
27
+ export type RawExtensions = Map<string, RawExtensionEnable>;
28
+ export type RawExtensionEnable = (name?: string) => Promise<ExtensionInterface>;
29
+ export type ExtensionEnableStatus = "valid" | "extension_not_found" | "enable_invalid";
30
+ export type ExtensionEnableResults = Map<string, ExtensionEnableResult>;
31
+ export interface ExtensionEnableResult {
32
+ extension?: ExtensionInterface;
33
+ connected: boolean;
34
+ error?: string;
35
+ }
36
+ export type VoidFn = () => void;
37
+ export type Sync = "synced" | "unsynced" | "syncing";
38
+ export type AnyFunction = any;
39
+ export type AnyJson = any;
package/types.js ADDED
@@ -0,0 +1,3 @@
1
+ export {};
2
+
3
+
package/types.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types.ts"],"names":[],"mappings":"AAAA;yCACyC","file":"types.js","sourcesContent":["/* @license Copyright 2024 @polkadot-cloud/library authors & contributors\",\n\"SPDX-License-Identifier: GPL-3.0-only */\n\nimport {\n ExtensionAccount,\n ExtensionInterface,\n} from \"./ExtensionsProvider/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"]}