@w3ux/react-connect-kit 3.2.24-alpha.4 → 3.2.24-alpha.6

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 (42) hide show
  1. package/HardwareAccounts/index.js +18 -10
  2. package/HardwareAccounts/index.js.map +1 -1
  3. package/index.d.ts +0 -3
  4. package/index.js +0 -3
  5. package/index.js.map +1 -1
  6. package/package.json +2 -2
  7. package/types.d.ts +0 -2
  8. package/types.js +0 -2
  9. package/types.js.map +1 -1
  10. package/HardwareAccounts/utils.d.ts +0 -2
  11. package/HardwareAccounts/utils.js +0 -10
  12. package/HardwareAccounts/utils.js.map +0 -1
  13. package/LedgerAccounts/index.d.ts +0 -6
  14. package/LedgerAccounts/index.js +0 -67
  15. package/LedgerAccounts/index.js.map +0 -1
  16. package/LedgerAccounts/types.d.ts +0 -9
  17. package/LedgerAccounts/types.js +0 -5
  18. package/LedgerAccounts/types.js.map +0 -1
  19. package/LedgerAccounts/utils.d.ts +0 -2
  20. package/LedgerAccounts/utils.js +0 -9
  21. package/LedgerAccounts/utils.js.map +0 -1
  22. package/VaultAccounts/index.d.ts +0 -6
  23. package/VaultAccounts/index.js +0 -83
  24. package/VaultAccounts/index.js.map +0 -1
  25. package/VaultAccounts/types.d.ts +0 -9
  26. package/VaultAccounts/types.js +0 -5
  27. package/VaultAccounts/types.js.map +0 -1
  28. package/VaultAccounts/utils.d.ts +0 -6
  29. package/VaultAccounts/utils.js +0 -12
  30. package/VaultAccounts/utils.js.map +0 -1
  31. package/WCAccounts/index.d.ts +0 -6
  32. package/WCAccounts/index.js +0 -76
  33. package/WCAccounts/index.js.map +0 -1
  34. package/WCAccounts/types.d.ts +0 -9
  35. package/WCAccounts/types.js +0 -5
  36. package/WCAccounts/types.js.map +0 -1
  37. package/WCAccounts/utils.d.ts +0 -6
  38. package/WCAccounts/utils.js +0 -12
  39. package/WCAccounts/utils.js.map +0 -1
  40. package/consts.d.ts +0 -1
  41. package/consts.js +0 -5
  42. package/consts.js.map +0 -1
@@ -1,16 +1,16 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { createSafeContext } from '@w3ux/hooks';
3
+ import { getHardwareAccounts as getAllHardwareAccounts, hardwareAccounts$, setHardwareAccounts, } from '@w3ux/observables-connect';
4
+ import { hardwareAccountsKey } from '@w3ux/observables-connect/consts';
5
+ import { getHardwareAccountsLocal } from '@w3ux/observables-connect/local';
3
6
  import { ellipsisFn } from '@w3ux/utils';
4
- import { hardwareAccountsKey } from 'consts';
5
- import { useState } from 'react';
6
- import { getLocalHardwareAccounts } from './utils';
7
+ import { useEffect, useState } from 'react';
7
8
  export const [HardwareAccountsContext, useHardwareAccounts] = createSafeContext();
8
9
  export const HardwareAccountsProvider = ({ children, }) => {
9
- const [hardwareAccounts, setHardwareAccounts] = useState(getLocalHardwareAccounts());
10
- const hardwareAccountExists = (source, network, address) => !!hardwareAccounts.find((a) => a.source === source && a.address === address && a.network === network);
10
+ const [hardwareAccounts, setHardwareAccountsState] = useState(getHardwareAccountsLocal());
11
+ const hardwareAccountExists = (source, network, address) => !!getAllHardwareAccounts().find((a) => a.source === source && a.address === address && a.network === network);
11
12
  const addHardwareAccount = (source, network, address, index, callback) => {
12
- const exists = !!hardwareAccounts.find((a) => a.source === source && a.address === address && a.network === network);
13
- if (!exists) {
13
+ if (!hardwareAccountExists(source, network, address)) {
14
14
  const newAccount = {
15
15
  address,
16
16
  network,
@@ -18,7 +18,7 @@ export const HardwareAccountsProvider = ({ children, }) => {
18
18
  source,
19
19
  index,
20
20
  };
21
- const newHardwareAccounts = [...hardwareAccounts].concat(newAccount);
21
+ const newHardwareAccounts = [...getAllHardwareAccounts()].concat(newAccount);
22
22
  localStorage.setItem(hardwareAccountsKey, JSON.stringify(newHardwareAccounts));
23
23
  setHardwareAccounts(newHardwareAccounts);
24
24
  if (typeof callback === 'function') {
@@ -29,7 +29,7 @@ export const HardwareAccountsProvider = ({ children, }) => {
29
29
  return null;
30
30
  };
31
31
  const removeHardwareAccount = (source, network, address, callback) => {
32
- const newHardwareAccounts = [...hardwareAccounts].filter((a) => !(a.source === source && a.address === address && a.network === network));
32
+ const newHardwareAccounts = [...getAllHardwareAccounts()].filter((a) => !(a.source === source && a.address === address && a.network === network));
33
33
  if (!newHardwareAccounts.length) {
34
34
  localStorage.removeItem(hardwareAccountsKey);
35
35
  }
@@ -42,7 +42,7 @@ export const HardwareAccountsProvider = ({ children, }) => {
42
42
  }
43
43
  };
44
44
  const renameHardwareAccount = (source, network, address, newName) => {
45
- const newHardwareAccounts = [...hardwareAccounts].map((a) => a.source === source && a.network === network && a.address === address
45
+ const newHardwareAccounts = [...getAllHardwareAccounts()].map((a) => a.source === source && a.network === network && a.address === address
46
46
  ? {
47
47
  ...a,
48
48
  name: newName,
@@ -53,6 +53,14 @@ export const HardwareAccountsProvider = ({ children, }) => {
53
53
  };
54
54
  const getHardwareAccount = (source, network, address) => hardwareAccounts.find((a) => a.source === source && a.network === network && a.address === address) || null;
55
55
  const getHardwareAccounts = (source, network) => hardwareAccounts.filter((a) => a.source === source && a.network === network);
56
+ useEffect(() => {
57
+ const sub = hardwareAccounts$.subscribe((accounts) => {
58
+ setHardwareAccountsState(accounts);
59
+ });
60
+ return () => {
61
+ sub.unsubscribe();
62
+ };
63
+ }, []);
56
64
  return (_jsx(HardwareAccountsContext.Provider, { value: {
57
65
  hardwareAccountExists,
58
66
  getHardwareAccount,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/HardwareAccounts/index.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAE/C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAA;AAE5C,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhC,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAA;AAElD,MAAM,CAAC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,CAClB,mBAAmB,EACnB,IAAI,CAAC,SAAS,CAAC,mBAAmB,CAAC,CACpC,CAAA;QACD,mBAAmB,CAAC,mBAAmB,CAAC,CAAA;IAC1C,CAAC,CAAA;IAGD,MAAM,kBAAkB,GAAG,CACzB,MAA6B,EAC7B,OAAe,EACf,OAAe,EACf,EAAE,CACF,gBAAgB,CAAC,IAAI,CACnB,CAAC,CAAC,EAAE,EAAE,CACJ,CAAC,CAAC,MAAM,KAAK,MAAM,IAAI,CAAC,CAAC,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK,OAAO,CACxE,IAAI,IAAI,CAAA;IAGX,MAAM,mBAAmB,GAAG,CAC1B,MAA6B,EAC7B,OAAe,EACf,EAAE,CACF,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,IAAI,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC,CAAA;IAE9E,OAAO,CACL,KAAC,uBAAuB,CAAC,QAAQ,IAC/B,KAAK,EAAE;YACL,qBAAqB;YACrB,kBAAkB;YAClB,kBAAkB;YAClB,qBAAqB;YACrB,qBAAqB;YACrB,mBAAmB;SACpB,YAEA,QAAQ,GACwB,CACpC,CAAA;AACH,CAAC,CAAA","file":"index.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport { createSafeContext } from '@w3ux/hooks'\nimport type { HardwareAccount, HardwareAccountSource } from '@w3ux/types'\nimport { ellipsisFn } from '@w3ux/utils'\nimport { hardwareAccountsKey } from 'consts'\nimport type { ReactNode } from 'react'\nimport { useState } from 'react'\nimport type { HardwareAccountsContextInterface } from './types'\nimport { getLocalHardwareAccounts } from './utils'\n\nexport const [HardwareAccountsContext, useHardwareAccounts] =\n createSafeContext<HardwareAccountsContextInterface>()\n\nexport const HardwareAccountsProvider = ({\n children,\n}: {\n children: ReactNode\n}) => {\n // Store imported hardware accounts\n const [hardwareAccounts, setHardwareAccounts] = useState<HardwareAccount[]>(\n getLocalHardwareAccounts()\n )\n\n // Check if an account exists\n const hardwareAccountExists = (\n source: HardwareAccountSource,\n network: string,\n address: string\n ) =>\n !!hardwareAccounts.find(\n (a) =>\n a.source === source && a.address === address && a.network === network\n )\n\n // Adds an account\n const addHardwareAccount = (\n source: HardwareAccountSource,\n network: string,\n address: string,\n index: number,\n callback?: () => void\n ) => {\n const exists = !!hardwareAccounts.find(\n (a) =>\n a.source === source && a.address === address && a.network === network\n )\n\n if (!exists) {\n const newAccount: HardwareAccount = {\n address,\n network,\n name: ellipsisFn(address),\n source,\n index,\n }\n const newHardwareAccounts = [...hardwareAccounts].concat(newAccount)\n localStorage.setItem(\n hardwareAccountsKey,\n JSON.stringify(newHardwareAccounts)\n )\n setHardwareAccounts(newHardwareAccounts)\n // Handle optional callback function\n if (typeof callback === 'function') {\n callback()\n }\n return newAccount\n }\n return null\n }\n\n // Removes an account\n const removeHardwareAccount = (\n source: HardwareAccountSource,\n network: string,\n address: string,\n callback?: () => void\n ) => {\n const newHardwareAccounts = [...hardwareAccounts].filter(\n (a) =>\n !(a.source === source && a.address === address && a.network === network)\n )\n\n if (!newHardwareAccounts.length) {\n localStorage.removeItem(hardwareAccountsKey)\n } else {\n localStorage.setItem(\n hardwareAccountsKey,\n JSON.stringify(newHardwareAccounts)\n )\n }\n setHardwareAccounts(newHardwareAccounts)\n // Handle optional callback function\n if (typeof callback === 'function') {\n callback()\n }\n }\n\n // Renames an imported account\n const renameHardwareAccount = (\n source: HardwareAccountSource,\n network: string,\n address: string,\n newName: string\n ) => {\n const newHardwareAccounts = [...hardwareAccounts].map((a) =>\n a.source === source && a.network === network && a.address === address\n ? {\n ...a,\n name: newName,\n }\n : a\n )\n localStorage.setItem(\n hardwareAccountsKey,\n JSON.stringify(newHardwareAccounts)\n )\n setHardwareAccounts(newHardwareAccounts)\n }\n\n // Gets an imported account\n const getHardwareAccount = (\n source: HardwareAccountSource,\n network: string,\n address: string\n ) =>\n hardwareAccounts.find(\n (a) =>\n a.source === source && a.network === network && a.address === address\n ) || null\n\n // Gets all accounts for a network and source\n const getHardwareAccounts = (\n source: HardwareAccountSource,\n network: string\n ) =>\n hardwareAccounts.filter((a) => a.source === source && a.network === network)\n\n return (\n <HardwareAccountsContext.Provider\n value={{\n hardwareAccountExists,\n getHardwareAccount,\n addHardwareAccount,\n removeHardwareAccount,\n renameHardwareAccount,\n getHardwareAccounts,\n }}\n >\n {children}\n </HardwareAccountsContext.Provider>\n )\n}\n"]}
1
+ {"version":3,"sources":["../src/HardwareAccounts/index.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EACL,mBAAmB,IAAI,sBAAsB,EAC7C,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAA;AACtE,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAA;AAE1E,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAG3C,MAAM,CAAC,MAAM,CAAC,uBAAuB,EAAE,mBAAmB,CAAC,GACzD,iBAAiB,EAAoC,CAAA;AAEvD,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,EACvC,QAAQ,GAGT,EAAE,EAAE;IAEH,MAAM,CAAC,gBAAgB,EAAE,wBAAwB,CAAC,GAAG,QAAQ,CAE3D,wBAAwB,EAAE,CAAC,CAAA;IAG7B,MAAM,qBAAqB,GAAG,CAC5B,MAA6B,EAC7B,OAAe,EACf,OAAe,EACf,EAAE,CACF,CAAC,CAAC,sBAAsB,EAAE,CAAC,IAAI,CAC7B,CAAC,CAAC,EAAE,EAAE,CACJ,CAAC,CAAC,MAAM,KAAK,MAAM,IAAI,CAAC,CAAC,OAAO,KA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,CAAA;IAG9E,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,GAAG,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,EAAE;YACnD,wBAAwB,CAAC,QAAQ,CAAC,CAAA;QACpC,CAAC,CAAC,CAAA;QACF,OAAO,GAAG,EAAE;YACV,GAAG,CAAC,WAAW,EAAE,CAAA;QACnB,CAAC,CAAA;IACH,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO,CACL,KAAC,uBAAuB,CAAC,QAAQ,IAC/B,KAAK,EAAE;YACL,qBAAqB;YACrB,kBAAkB;YAClB,kBAAkB;YAClB,qBAAqB;YACrB,qBAAqB;YACrB,mBAAmB;SACpB,YAEA,QAAQ,GACwB,CACpC,CAAA;AACH,CAAC,CAAA","file":"index.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport { createSafeContext } from '@w3ux/hooks'\nimport {\n getHardwareAccounts as getAllHardwareAccounts,\n hardwareAccounts$,\n setHardwareAccounts,\n} from '@w3ux/observables-connect'\nimport { hardwareAccountsKey } from '@w3ux/observables-connect/consts'\nimport { getHardwareAccountsLocal } from '@w3ux/observables-connect/local'\nimport type { HardwareAccount, HardwareAccountSource } from '@w3ux/types'\nimport { ellipsisFn } from '@w3ux/utils'\nimport type { ReactNode } from 'react'\nimport { useEffect, useState } from 'react'\nimport type { HardwareAccountsContextInterface } from './types'\n\nexport const [HardwareAccountsContext, useHardwareAccounts] =\n createSafeContext<HardwareAccountsContextInterface>()\n\nexport const HardwareAccountsProvider = ({\n children,\n}: {\n children: ReactNode\n}) => {\n // Store imported hardware accounts\n const [hardwareAccounts, setHardwareAccountsState] = useState<\n HardwareAccount[]\n >(getHardwareAccountsLocal())\n\n // Check if an account exists\n const hardwareAccountExists = (\n source: HardwareAccountSource,\n network: string,\n address: string\n ) =>\n !!getAllHardwareAccounts().find(\n (a) =>\n a.source === source && a.address === address && a.network === network\n )\n\n // Adds an account\n const addHardwareAccount = (\n source: HardwareAccountSource,\n network: string,\n address: string,\n index: number,\n callback?: () => void\n ) => {\n if (!hardwareAccountExists(source, network, address)) {\n const newAccount: HardwareAccount = {\n address,\n network,\n name: ellipsisFn(address),\n source,\n index,\n }\n const newHardwareAccounts = [...getAllHardwareAccounts()].concat(\n newAccount\n )\n localStorage.setItem(\n hardwareAccountsKey,\n JSON.stringify(newHardwareAccounts)\n )\n setHardwareAccounts(newHardwareAccounts)\n // Handle optional callback function\n if (typeof callback === 'function') {\n callback()\n }\n return newAccount\n }\n return null\n }\n\n // Removes an account\n const removeHardwareAccount = (\n source: HardwareAccountSource,\n network: string,\n address: string,\n callback?: () => void\n ) => {\n const newHardwareAccounts = [...getAllHardwareAccounts()].filter(\n (a) =>\n !(a.source === source && a.address === address && a.network === network)\n )\n\n if (!newHardwareAccounts.length) {\n localStorage.removeItem(hardwareAccountsKey)\n } else {\n localStorage.setItem(\n hardwareAccountsKey,\n JSON.stringify(newHardwareAccounts)\n )\n }\n setHardwareAccounts(newHardwareAccounts)\n // Handle optional callback function\n if (typeof callback === 'function') {\n callback()\n }\n }\n\n // Renames an imported account\n const renameHardwareAccount = (\n source: HardwareAccountSource,\n network: string,\n address: string,\n newName: string\n ) => {\n const newHardwareAccounts = [...getAllHardwareAccounts()].map((a) =>\n a.source === source && a.network === network && a.address === address\n ? {\n ...a,\n name: newName,\n }\n : a\n )\n localStorage.setItem(\n hardwareAccountsKey,\n JSON.stringify(newHardwareAccounts)\n )\n setHardwareAccounts(newHardwareAccounts)\n }\n\n // Gets an imported account\n const getHardwareAccount = (\n source: HardwareAccountSource,\n network: string,\n address: string\n ) =>\n hardwareAccounts.find(\n (a) =>\n a.source === source && a.network === network && a.address === address\n ) || null\n\n // Gets all accounts for a network and source\n const getHardwareAccounts = (\n source: HardwareAccountSource,\n network: string\n ) =>\n hardwareAccounts.filter((a) => a.source === source && a.network === network)\n\n // Subscribes to observables and updates state\n useEffect(() => {\n const sub = hardwareAccounts$.subscribe((accounts) => {\n setHardwareAccountsState(accounts)\n })\n return () => {\n sub.unsubscribe()\n }\n }, [])\n\n return (\n <HardwareAccountsContext.Provider\n value={{\n hardwareAccountExists,\n getHardwareAccount,\n addHardwareAccount,\n removeHardwareAccount,\n renameHardwareAccount,\n getHardwareAccounts,\n }}\n >\n {children}\n </HardwareAccountsContext.Provider>\n )\n}\n"]}
package/index.d.ts CHANGED
@@ -1,6 +1,3 @@
1
1
  export * from './ExtensionAccounts';
2
2
  export * from './Extensions';
3
3
  export * from './HardwareAccounts';
4
- export * from './LedgerAccounts';
5
- export * from './VaultAccounts';
6
- export * from './WCAccounts';
package/index.js CHANGED
@@ -1,9 +1,6 @@
1
1
  export * from './ExtensionAccounts';
2
2
  export * from './Extensions';
3
3
  export * from './HardwareAccounts';
4
- export * from './LedgerAccounts';
5
- export * from './VaultAccounts';
6
- export * from './WCAccounts';
7
4
 
8
5
  //# sourceMappingURL=index.js.map
9
6
 
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,qBAAqB,CAAA;AACnC,cAAc,cAAc,CAAA;AAC5B,cAAc,oBAAoB,CAAA;AAClC,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA","file":"index.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nexport * from './ExtensionAccounts'\nexport * from './Extensions'\nexport * from './HardwareAccounts'\nexport * from './LedgerAccounts'\nexport * from './VaultAccounts'\nexport * from './WCAccounts'\n"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,qBAAqB,CAAA;AACnC,cAAc,cAAc,CAAA;AAC5B,cAAc,oBAAoB,CAAA","file":"index.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nexport * from './ExtensionAccounts'\nexport * from './Extensions'\nexport * from './HardwareAccounts'\n"]}
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@w3ux/react-connect-kit",
3
- "version": "3.2.24-alpha.4",
3
+ "version": "3.2.24-alpha.6",
4
4
  "license": "GPL-3.0-only",
5
5
  "dependencies": {
6
6
  "@w3ux/extension-assets": "^2.2.0",
7
7
  "@w3ux/hooks": "^2.1.0",
8
- "@w3ux/observables-connect": "0.9.31",
8
+ "@w3ux/observables-connect": "0.9.32-alpha.3",
9
9
  "@w3ux/utils": "^2.0.9"
10
10
  },
11
11
  "type": "module",
package/types.d.ts CHANGED
@@ -1,4 +1,2 @@
1
1
  export * from './ExtensionAccounts/types';
2
2
  export * from './Extensions/types';
3
- export * from './LedgerAccounts/types';
4
- export * from './VaultAccounts/types';
package/types.js CHANGED
@@ -1,7 +1,5 @@
1
1
  export * from './ExtensionAccounts/types';
2
2
  export * from './Extensions/types';
3
- export * from './LedgerAccounts/types';
4
- export * from './VaultAccounts/types';
5
3
 
6
4
  //# sourceMappingURL=types.js.map
7
5
 
package/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types.ts"],"names":[],"mappings":"AAGA,cAAc,2BAA2B,CAAA;AACzC,cAAc,oBAAoB,CAAA;AAClC,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA","file":"types.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nexport * from './ExtensionAccounts/types'\nexport * from './Extensions/types'\nexport * from './LedgerAccounts/types'\nexport * from './VaultAccounts/types'\n"]}
1
+ {"version":3,"sources":["../src/types.ts"],"names":[],"mappings":"AAGA,cAAc,2BAA2B,CAAA;AACzC,cAAc,oBAAoB,CAAA","file":"types.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nexport * from './ExtensionAccounts/types'\nexport * from './Extensions/types'\n"]}
@@ -1,2 +0,0 @@
1
- import type { HardwareAccount } from '@w3ux/types';
2
- export declare const getLocalHardwareAccounts: () => HardwareAccount[];
@@ -1,10 +0,0 @@
1
- import { localStorageOrDefault } from '@w3ux/utils';
2
- import { hardwareAccountsKey } from 'consts';
3
- export const getLocalHardwareAccounts = () => {
4
- const accounts = localStorageOrDefault(hardwareAccountsKey, [], true);
5
- return accounts;
6
- };
7
-
8
- //# sourceMappingURL=utils.js.map
9
-
10
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/HardwareAccounts/utils.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAA;AAG5C,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAsB,EAAE;IAC9D,MAAM,QAAQ,GAAG,qBAAqB,CACpC,mBAAmB,EACnB,EAAE,EACF,IAAI,CACgB,CAAA;IAEtB,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA","file":"utils.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport type { HardwareAccount } from '@w3ux/types'\nimport { localStorageOrDefault } from '@w3ux/utils'\nimport { hardwareAccountsKey } from 'consts'\n\n// Gets imported Ledger accounts from local storage\nexport const getLocalHardwareAccounts = (): HardwareAccount[] => {\n const accounts = localStorageOrDefault(\n hardwareAccountsKey,\n [],\n true\n ) as HardwareAccount[]\n\n return accounts\n}\n"]}
@@ -1,6 +0,0 @@
1
- import type { ReactNode } from 'react';
2
- import type { LedgerAccountsContextInterface } from './types';
3
- export declare const LedgerAccountsContext: import("react").Context<LedgerAccountsContextInterface>, useLedgerAccounts: () => LedgerAccountsContextInterface;
4
- export declare const LedgerAccountsProvider: ({ children, }: {
5
- children: ReactNode;
6
- }) => import("react/jsx-runtime").JSX.Element;
@@ -1,67 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { createSafeContext } from '@w3ux/hooks';
3
- import { ellipsisFn } from '@w3ux/utils';
4
- import { useState } from 'react';
5
- import { getLocalLedgerAccounts } from './utils';
6
- export const [LedgerAccountsContext, useLedgerAccounts] = createSafeContext();
7
- export const LedgerAccountsProvider = ({ children, }) => {
8
- const [ledgerAccounts, setLedgerAccounts] = useState(getLocalLedgerAccounts());
9
- const ledgerAccountExists = (network, address) => !!ledgerAccounts.find((a) => a.address === address && a.network === network);
10
- const addLedgerAccount = (network, address, index, callback) => {
11
- const exists = !!ledgerAccounts.find((a) => a.address === address && a.network === network);
12
- if (!exists) {
13
- const newAccount = {
14
- address,
15
- network,
16
- name: ellipsisFn(address),
17
- source: 'ledger',
18
- index,
19
- };
20
- const newLedgerAccounts = [...ledgerAccounts].concat(newAccount);
21
- localStorage.setItem('ledger_accounts', JSON.stringify(newLedgerAccounts));
22
- setLedgerAccounts(newLedgerAccounts);
23
- if (typeof callback === 'function') {
24
- callback();
25
- }
26
- return newAccount;
27
- }
28
- return null;
29
- };
30
- const removeLedgerAccount = (network, address, callback) => {
31
- const newLedgerAccounts = [...ledgerAccounts].filter((a) => !(a.address === address && a.network === network));
32
- if (!newLedgerAccounts.length) {
33
- localStorage.removeItem('ledger_accounts');
34
- }
35
- else {
36
- localStorage.setItem('ledger_accounts', JSON.stringify(newLedgerAccounts));
37
- }
38
- setLedgerAccounts(newLedgerAccounts);
39
- if (typeof callback === 'function') {
40
- callback();
41
- }
42
- };
43
- const renameLedgerAccount = (network, address, newName) => {
44
- const newLedgerAccounts = [...ledgerAccounts].map((a) => a.network === network && a.address === address
45
- ? {
46
- ...a,
47
- name: newName,
48
- }
49
- : a);
50
- localStorage.setItem('ledger_accounts', JSON.stringify(newLedgerAccounts));
51
- setLedgerAccounts(newLedgerAccounts);
52
- };
53
- const getLedgerAccount = (network, address) => ledgerAccounts.find((a) => a.network === network && a.address === address) || null;
54
- const getLedgerAccounts = (network) => ledgerAccounts.filter((a) => a.network === network);
55
- return (_jsx(LedgerAccountsContext.Provider, { value: {
56
- ledgerAccountExists,
57
- getLedgerAccount,
58
- addLedgerAccount,
59
- removeLedgerAccount,
60
- renameLedgerAccount,
61
- getLedgerAccounts,
62
- }, children: children }));
63
- };
64
-
65
- //# sourceMappingURL=index.js.map
66
-
67
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/LedgerAccounts/index.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAE/C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhC,OAAO,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAA;AAEhD,MAAM,CAAC,MAAM,CAAC,qBAAqB,EAAE,iBAAiB,CAAC,GACrD,iBAAiB,EAAkC,CAAA;AAErD,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,EACrC,QAAQ,GAGT,EAAE,EAAE;IAEH,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,QAAQ,CAClD,sBAAsB,EAAE,CACzB,CAAA;IAGD,MAAM,mBAAmB,GAAG,CAAC,OAAe,EAAE,OAAe,EAAE,EAAE,CAC/D,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC,CAAA;IAG9E,MAAM,gBAAgB,GAAG,CACvB,OAAe,EACf,OAAe,EACf,KAAa,EACb,QAAqB,EACrB,EAAE;QACF,MAAM,MAAM,GAAG,CAAC,CAAC,cAAc,CAAC,IAAI,CAClC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK,OAAO,CACtD,CAAA;QAED,IAAI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B,OAAe,EACf,OAAe,EACf,OAAe,EACf,EAAE;QACF,MAAM,iBAAiB,GAAG,CAAC,GAAG,cAAc,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CACtD,CAAC,CAAC,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK,OAAO;YAC5C,CAAC,CAAC;gBACE,GAAG,CAAC;gBACJ,IAAI,EAAE,OAAO;aACd;YACH,CAAC,CAAC,CAAC,CACN,CAAA;QACD,YAAY,CAAC,OAAO,CAAC,iBAAiB,EAAE,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC,CAAA;QAC1E,iBAAiB,CAAC,iBAAiB,CAAC,CAAA;IACtC,CAAC,CAAA;IAGD,MAAM,gBAAgB,GAAG,CAAC,OAAe,EAAE,OAAe,EAAE,EAAE,CAC5D,cAAc,CAAC,IAAI,CACjB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK,OAAO,CACtD,IAAI,IAAI,CAAA;IAGX,MAAM,iBAAiB,GAAG,CAAC,OAAe,EAAE,EAAE,CAC5C,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC,CAAA;IAErD,OAAO,CACL,KAAC,qBAAqB,CAAC,QAAQ,IAC7B,KAAK,EAAE;YACL,mBAAmB;YACnB,gBAAgB;YAChB,gBAAgB;YAChB,mBAAmB;YACnB,mBAAmB;YACnB,iBAAiB;SAClB,YAEA,QAAQ,GACsB,CAClC,CAAA;AACH,CAAC,CAAA","file":"index.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport { createSafeContext } from '@w3ux/hooks'\nimport type { HardwareAccount } from '@w3ux/types'\nimport { ellipsisFn } from '@w3ux/utils'\nimport type { ReactNode } from 'react'\nimport { useState } from 'react'\nimport type { LedgerAccountsContextInterface } from './types'\nimport { getLocalLedgerAccounts } from './utils'\n\nexport const [LedgerAccountsContext, useLedgerAccounts] =\n createSafeContext<LedgerAccountsContextInterface>()\n\nexport const LedgerAccountsProvider = ({\n children,\n}: {\n children: ReactNode\n}) => {\n // Store imported ledger accounts\n const [ledgerAccounts, setLedgerAccounts] = useState<HardwareAccount[]>(\n getLocalLedgerAccounts()\n )\n\n // Check if a Ledger account is imported\n const ledgerAccountExists = (network: string, address: string) =>\n !!ledgerAccounts.find((a) => a.address === address && a.network === network)\n\n // Adds a ledger account\n const addLedgerAccount = (\n network: string,\n address: string,\n index: number,\n callback?: () => void\n ) => {\n const exists = !!ledgerAccounts.find(\n (a) => a.address === address && a.network === network\n )\n\n if (!exists) {\n const newAccount: HardwareAccount = {\n address,\n network,\n name: ellipsisFn(address),\n source: 'ledger',\n index,\n }\n const newLedgerAccounts = [...ledgerAccounts].concat(newAccount)\n localStorage.setItem('ledger_accounts', JSON.stringify(newLedgerAccounts))\n setLedgerAccounts(newLedgerAccounts)\n\n // Handle optional callback function.\n if (typeof callback === 'function') {\n callback()\n }\n return newAccount\n }\n return null\n }\n\n // Removes a Ledger account\n const removeLedgerAccount = (\n network: string,\n address: string,\n callback?: () => void\n ) => {\n const newLedgerAccounts = [...ledgerAccounts].filter(\n (a) => !(a.address === address && a.network === network)\n )\n\n if (!newLedgerAccounts.length) {\n localStorage.removeItem('ledger_accounts')\n } else {\n localStorage.setItem('ledger_accounts', JSON.stringify(newLedgerAccounts))\n }\n\n setLedgerAccounts(newLedgerAccounts)\n // Handle optional callback function\n if (typeof callback === 'function') {\n callback()\n }\n }\n\n // Renames an imported ledger account\n const renameLedgerAccount = (\n network: string,\n address: string,\n newName: string\n ) => {\n const newLedgerAccounts = [...ledgerAccounts].map((a) =>\n a.network === network && a.address === address\n ? {\n ...a,\n name: newName,\n }\n : a\n )\n localStorage.setItem('ledger_accounts', JSON.stringify(newLedgerAccounts))\n setLedgerAccounts(newLedgerAccounts)\n }\n\n // Gets an imported ledger account\n const getLedgerAccount = (network: string, address: string) =>\n ledgerAccounts.find(\n (a) => a.network === network && a.address === address\n ) || null\n\n // Gets all Ledger accounts for a network\n const getLedgerAccounts = (network: string) =>\n ledgerAccounts.filter((a) => a.network === network)\n\n return (\n <LedgerAccountsContext.Provider\n value={{\n ledgerAccountExists,\n getLedgerAccount,\n addLedgerAccount,\n removeLedgerAccount,\n renameLedgerAccount,\n getLedgerAccounts,\n }}\n >\n {children}\n </LedgerAccountsContext.Provider>\n )\n}\n"]}
@@ -1,9 +0,0 @@
1
- import type { HardwareAccount } from '@w3ux/types';
2
- export interface LedgerAccountsContextInterface {
3
- ledgerAccountExists: (network: string, a: string) => boolean;
4
- addLedgerAccount: (network: string, address: string, index: number, callback?: () => void) => HardwareAccount | null;
5
- removeLedgerAccount: (network: string, address: string, callback?: () => void) => void;
6
- renameLedgerAccount: (network: string, address: string, name: string) => void;
7
- getLedgerAccount: (network: string, address: string) => HardwareAccount | null;
8
- getLedgerAccounts: (network: string) => HardwareAccount[];
9
- }
@@ -1,5 +0,0 @@
1
- export {};
2
-
3
- //# sourceMappingURL=types.js.map
4
-
5
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/LedgerAccounts/types.ts"],"names":[],"mappings":"","file":"types.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport type { HardwareAccount } from '@w3ux/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 ) => HardwareAccount | 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) => HardwareAccount | null\n getLedgerAccounts: (network: string) => HardwareAccount[]\n}\n"]}
@@ -1,2 +0,0 @@
1
- import type { HardwareAccount } from '@w3ux/types';
2
- export declare const getLocalLedgerAccounts: () => HardwareAccount[];
@@ -1,9 +0,0 @@
1
- import { localStorageOrDefault } from '@w3ux/utils';
2
- export const getLocalLedgerAccounts = () => {
3
- const localAddresses = localStorageOrDefault('ledger_accounts', [], true);
4
- return localAddresses;
5
- };
6
-
7
- //# sourceMappingURL=utils.js.map
8
-
9
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/LedgerAccounts/utils.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAGnD,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAsB,EAAE;IAC5D,MAAM,cAAc,GAAG,qBAAqB,CAC1C,iBAAiB,EACjB,EAAE,EACF,IAAI,CACgB,CAAA;IAEtB,OAAO,cAAc,CAAA;AACvB,CAAC,CAAA","file":"utils.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport type { HardwareAccount } from '@w3ux/types'\nimport { localStorageOrDefault } from '@w3ux/utils'\n\n// Gets imported Ledger accounts from local storage\nexport const getLocalLedgerAccounts = (): HardwareAccount[] => {\n const localAddresses = localStorageOrDefault(\n 'ledger_accounts',\n [],\n true\n ) as HardwareAccount[]\n\n return localAddresses\n}\n"]}
@@ -1,6 +0,0 @@
1
- import type { ReactNode } from 'react';
2
- import type { VaultAccountsContextInterface } from './types';
3
- export declare const VaultAccountsContext: import("react").Context<VaultAccountsContextInterface>, useVaultAccounts: () => VaultAccountsContextInterface;
4
- export declare const VaultAccountsProvider: ({ children, }: {
5
- children: ReactNode;
6
- }) => import("react/jsx-runtime").JSX.Element;
@@ -1,83 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { createSafeContext } from '@w3ux/hooks';
3
- import { ellipsisFn } from '@w3ux/utils';
4
- import { useState } from 'react';
5
- import { getLocalVaultAccounts, isLocalNetworkAddress } from './utils';
6
- export const [VaultAccountsContext, useVaultAccounts] = createSafeContext();
7
- export const VaultAccountsProvider = ({ children, }) => {
8
- const [vaultAccounts, seVaultAccounts] = useState(getLocalVaultAccounts());
9
- const vaultAccountExists = (network, address) => !!vaultAccounts.find((a) => a.address === address && a.network === network);
10
- const addVaultAccount = (network, address, index, callback) => {
11
- let newVaultAccounts = getLocalVaultAccounts();
12
- if (!newVaultAccounts.find((a) => isLocalNetworkAddress(network, a, address))) {
13
- const account = {
14
- address,
15
- network,
16
- name: ellipsisFn(address),
17
- source: 'vault',
18
- index,
19
- };
20
- newVaultAccounts = [...newVaultAccounts].concat(account);
21
- localStorage.setItem('polkadot_vault_accounts', JSON.stringify(newVaultAccounts));
22
- seVaultAccounts(newVaultAccounts);
23
- if (typeof callback === 'function') {
24
- callback();
25
- }
26
- return account;
27
- }
28
- return null;
29
- };
30
- const removeVaultAccount = (network, address, callback) => {
31
- let newVaultAccounts = getLocalVaultAccounts();
32
- newVaultAccounts = newVaultAccounts.filter((a) => {
33
- if (a.address !== address) {
34
- return true;
35
- }
36
- if (a.network !== network) {
37
- return true;
38
- }
39
- return false;
40
- });
41
- if (!newVaultAccounts.length) {
42
- localStorage.removeItem('polkadot_vault_accounts');
43
- }
44
- else {
45
- localStorage.setItem('polkadot_vault_accounts', JSON.stringify(newVaultAccounts));
46
- }
47
- seVaultAccounts(newVaultAccounts);
48
- if (typeof callback === 'function') {
49
- callback();
50
- }
51
- };
52
- const getVaultAccount = (network, address) => {
53
- const localVaultAccounts = getLocalVaultAccounts();
54
- if (!localVaultAccounts) {
55
- return null;
56
- }
57
- return (localVaultAccounts.find((a) => isLocalNetworkAddress(network, a, address)) ?? null);
58
- };
59
- const renameVaultAccount = (network, address, newName) => {
60
- let newVaultAccounts = getLocalVaultAccounts();
61
- newVaultAccounts = newVaultAccounts.map((a) => isLocalNetworkAddress(network, a, address)
62
- ? {
63
- ...a,
64
- name: newName,
65
- }
66
- : a);
67
- localStorage.setItem('polkadot_vault_accounts', JSON.stringify(newVaultAccounts));
68
- seVaultAccounts(newVaultAccounts);
69
- };
70
- const getVaultAccounts = (network) => vaultAccounts.filter((a) => a.network === network);
71
- return (_jsx(VaultAccountsContext.Provider, { value: {
72
- vaultAccountExists,
73
- addVaultAccount,
74
- removeVaultAccount,
75
- renameVaultAccount,
76
- getVaultAccount,
77
- getVaultAccounts,
78
- }, children: children }));
79
- };
80
-
81
- //# sourceMappingURL=index.js.map
82
-
83
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/VaultAccounts/index.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAE/C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhC,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAEtE,MAAM,CAAC,MAAM,CAAC,oBAAoB,EAAE,gBAAgB,CAAC,GACnD,iBAAiB,EAAiC,CAAA;AAEpD,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,EACpC,QAAQ,GAGT,EAAE,EAAE;IACH,MAAM,CAAC,aAAa,EAAE,eAAe,CAAC,GAAG,QAAQ,CAC/C,qBAAqB,EAAE,CACxB,CAAA;IAGD,MAAM,kBAAkB,GAAG,CAAC,OAAe,EAAE,OAAe,EAAE,EAAE,CAC9D,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC,CAAA;IAG7E,MAAM,eAAe,GAAG,CACtB,OAAe,EACf,OAAe,EACf,KAAa,EACb,QAAqB,EACrB,EAAE;QACF,IAAI,gBAAgB,GAAG,qBAAqB,EAAE,CAAA;QAE9C,IACE,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAA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EAAE;YACL,kBAAkB;YAClB,eAAe;YACf,kBAAkB;YAClB,kBAAkB;YAClB,eAAe;YACf,gBAAgB;SACjB,YAEA,QAAQ,GACqB,CACjC,CAAA;AACH,CAAC,CAAA","file":"index.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport { createSafeContext } from '@w3ux/hooks'\nimport type { HardwareAccount } from '@w3ux/types'\nimport { ellipsisFn } from '@w3ux/utils'\nimport type { ReactNode } from 'react'\nimport { useState } from 'react'\nimport type { VaultAccountsContextInterface } from './types'\nimport { getLocalVaultAccounts, isLocalNetworkAddress } from './utils'\n\nexport const [VaultAccountsContext, useVaultAccounts] =\n createSafeContext<VaultAccountsContextInterface>()\n\nexport const VaultAccountsProvider = ({\n children,\n}: {\n children: ReactNode\n}) => {\n const [vaultAccounts, seVaultAccounts] = useState<HardwareAccount[]>(\n getLocalVaultAccounts()\n )\n\n // Check if a Vault address exists in imported addresses.\n const vaultAccountExists = (network: string, address: string) =>\n !!vaultAccounts.find((a) => a.address === address && a.network === network)\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: HardwareAccount = {\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 seVaultAccounts(newVaultAccounts)\n\n // Handle optional callback function.\n if (typeof callback === 'function') {\n callback()\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 seVaultAccounts(newVaultAccounts)\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 seVaultAccounts(newVaultAccounts)\n }\n\n // Gets Vault accounts for a network.\n const getVaultAccounts = (network: string) =>\n vaultAccounts.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 }}\n >\n {children}\n </VaultAccountsContext.Provider>\n )\n}\n"]}
@@ -1,9 +0,0 @@
1
- import type { HardwareAccount } from '@w3ux/types';
2
- export interface VaultAccountsContextInterface {
3
- vaultAccountExists: (network: string, address: string) => boolean;
4
- addVaultAccount: (network: string, address: string, index: number, callback?: () => void) => HardwareAccount | null;
5
- removeVaultAccount: (network: string, address: string, callback?: () => void) => void;
6
- renameVaultAccount: (network: string, address: string, newName: string) => void;
7
- getVaultAccount: (network: string, address: string) => HardwareAccount | null;
8
- getVaultAccounts: (network: string) => HardwareAccount[];
9
- }
@@ -1,5 +0,0 @@
1
- export {};
2
-
3
- //# sourceMappingURL=types.js.map
4
-
5
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/VaultAccounts/types.ts"],"names":[],"mappings":"","file":"types.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport type { HardwareAccount } from '@w3ux/types'\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 ) => HardwareAccount | 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) => HardwareAccount | null\n getVaultAccounts: (network: string) => HardwareAccount[]\n}\n"]}
@@ -1,6 +0,0 @@
1
- import type { HardwareAccount } from '@w3ux/types';
2
- export declare const getLocalVaultAccounts: (network?: string) => HardwareAccount[];
3
- export declare const isLocalNetworkAddress: (chain: string, a: {
4
- address: string | undefined;
5
- network: string;
6
- }, address: string) => boolean;
@@ -1,12 +0,0 @@
1
- import { localStorageOrDefault } from '@w3ux/utils';
2
- export const getLocalVaultAccounts = (network) => {
3
- const localAddresses = localStorageOrDefault('polkadot_vault_accounts', [], true);
4
- return network
5
- ? localAddresses.filter((a) => a.network === network)
6
- : localAddresses;
7
- };
8
- export const isLocalNetworkAddress = (chain, a, address) => a.address === address && a.network === chain;
9
-
10
- //# sourceMappingURL=utils.js.map
11
-
12
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/VaultAccounts/utils.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAGnD,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,OAAgB,EAAE,EAAE;IACxD,MAAM,cAAc,GAAG,qBAAqB,CAC1C,yBAAyB,EACzB,EAAE,EACF,IAAI,CACgB,CAAA;IAEtB,OAAO,OAAO;QACZ,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC;QACrD,CAAC,CAAC,cAAc,CAAA;AACpB,CAAC,CAAA;AAGD,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,KAAa,EACb,CAAmD,EACnD,OAAe,EACf,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK,KAAK,CAAA","file":"utils.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport type { HardwareAccount } from '@w3ux/types'\nimport { localStorageOrDefault } from '@w3ux/utils'\n\n// Gets imported Vault accounts from local storage.\nexport const getLocalVaultAccounts = (network?: string) => {\n const localAddresses = localStorageOrDefault(\n 'polkadot_vault_accounts',\n [],\n true\n ) as HardwareAccount[]\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"]}
@@ -1,6 +0,0 @@
1
- import type { ReactNode } from 'react';
2
- import type { WCAccountsContextInterface } from './types';
3
- export declare const WCAccountsContext: import("react").Context<WCAccountsContextInterface>, useWcAccounts: () => WCAccountsContextInterface;
4
- export declare const WCAccountsProvider: ({ children }: {
5
- children: ReactNode;
6
- }) => import("react/jsx-runtime").JSX.Element;
@@ -1,76 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { createSafeContext } from '@w3ux/hooks';
3
- import { ellipsisFn } from '@w3ux/utils';
4
- import { useState } from 'react';
5
- import { getLocalWcAccounts, isLocalNetworkAddress } from './utils';
6
- export const [WCAccountsContext, useWcAccounts] = createSafeContext();
7
- export const WCAccountsProvider = ({ children }) => {
8
- const [wcAccounts, setWcAccounts] = useState(getLocalWcAccounts());
9
- const wcAccountExists = (network, address) => !!wcAccounts.find((a) => a.address === address && a.network === network);
10
- const addWcAccount = (network, address, index, callback) => {
11
- let newAccounts = [...wcAccounts];
12
- if (!newAccounts.find((a) => isLocalNetworkAddress(network, a, address))) {
13
- const account = {
14
- address,
15
- network,
16
- name: ellipsisFn(address),
17
- source: 'wallet_connect',
18
- index,
19
- };
20
- newAccounts = [...newAccounts].concat(account);
21
- localStorage.setItem('wallet_connect_accounts', JSON.stringify(newAccounts));
22
- setWcAccounts(newAccounts);
23
- if (typeof callback === 'function') {
24
- callback();
25
- }
26
- return account;
27
- }
28
- return null;
29
- };
30
- const removeWcAccount = (network, address, callback) => {
31
- let newAccounts = [...wcAccounts];
32
- newAccounts = newAccounts.filter((a) => {
33
- if (a.address !== address) {
34
- return true;
35
- }
36
- if (a.network !== network) {
37
- return true;
38
- }
39
- return false;
40
- });
41
- if (!newAccounts.length) {
42
- localStorage.removeItem('wallet_connect_accounts');
43
- }
44
- else {
45
- localStorage.setItem('wallet_connect_accounts', JSON.stringify(newAccounts));
46
- }
47
- setWcAccounts(newAccounts);
48
- if (typeof callback === 'function') {
49
- callback();
50
- }
51
- };
52
- const getWcAccount = (network, address) => wcAccounts.find((a) => a.address === address && a.network === network);
53
- const renameWcAccount = (network, address, newName) => {
54
- const newAccounts = [...wcAccounts].map((a) => isLocalNetworkAddress(network, a, address)
55
- ? {
56
- ...a,
57
- name: newName,
58
- }
59
- : a);
60
- localStorage.setItem('wallet_connect_accounts', JSON.stringify(newAccounts));
61
- setWcAccounts(newAccounts);
62
- };
63
- const getWcAccounts = (network) => wcAccounts.filter((a) => a.network === network);
64
- return (_jsx(WCAccountsContext.Provider, { value: {
65
- wcAccountExists,
66
- addWcAccount,
67
- removeWcAccount,
68
- renameWcAccount,
69
- getWcAccount,
70
- getWcAccounts,
71
- }, children: children }));
72
- };
73
-
74
- //# sourceMappingURL=index.js.map
75
-
76
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/WCAccounts/index.tsx"],"names":[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AA;IAExE,MAAM,eAAe,GAAG,CACtB,OAAe,EACf,OAAe,EACf,OAAe,EACf,EAAE;QACF,MAAM,WAAW,GAAG,CAAC,GAAG,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAC5C,qBAAqB,CAAC,OAAO,EAAE,CAAC,EAAE,OAAO,CAAC;YACxC,CAAC,CAAC;gBACE,GAAG,CAAC;gBACJ,IAAI,EAAE,OAAO;aACd;YACH,CAAC,CAAC,CAAC,CACN,CAAA;QACD,YAAY,CAAC,OAAO,CAAC,yBAAyB,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAA;QAE5E,aAAa,CAAC,WAAW,CAAC,CAAA;IAC5B,CAAC,CAAA;IAGD,MAAM,aAAa,GAAG,CAAC,OAAe,EAAE,EAAE,CACxC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC,CAAA;IAEjD,OAAO,CACL,KAAC,iBAAiB,CAAC,QAAQ,IACzB,KAAK,EAAE;YACL,eAAe;YACf,YAAY;YACZ,eAAe;YACf,eAAe;YACf,YAAY;YACZ,aAAa;SACd,YAEA,QAAQ,GACkB,CAC9B,CAAA;AACH,CAAC,CAAA","file":"index.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport { createSafeContext } from '@w3ux/hooks'\nimport type { HardwareAccount } from '@w3ux/types'\nimport { ellipsisFn } from '@w3ux/utils'\nimport type { ReactNode } from 'react'\nimport { useState } from 'react'\nimport type { WCAccountsContextInterface } from './types'\nimport { getLocalWcAccounts, isLocalNetworkAddress } from './utils'\n\nexport const [WCAccountsContext, useWcAccounts] =\n createSafeContext<WCAccountsContextInterface>()\n\nexport const WCAccountsProvider = ({ children }: { children: ReactNode }) => {\n const [wcAccounts, setWcAccounts] =\n useState<HardwareAccount[]>(getLocalWcAccounts())\n\n // Check if a Wallet Connect address exists in imported addresses.\n const wcAccountExists = (network: string, address: string) =>\n !!wcAccounts.find((a) => a.address === address && a.network === network)\n\n // Adds a wallet connect account to state and local storage.\n const addWcAccount = (\n network: string,\n address: string,\n index: number,\n callback?: () => void\n ) => {\n let newAccounts = [...wcAccounts]\n\n if (!newAccounts.find((a) => isLocalNetworkAddress(network, a, address))) {\n const account: HardwareAccount = {\n address,\n network,\n name: ellipsisFn(address),\n source: 'wallet_connect',\n index,\n }\n\n newAccounts = [...newAccounts].concat(account)\n localStorage.setItem(\n 'wallet_connect_accounts',\n JSON.stringify(newAccounts)\n )\n setWcAccounts(newAccounts)\n // Handle optional callback function\n if (typeof callback === 'function') {\n callback()\n }\n return account\n }\n return null\n }\n\n const removeWcAccount = (\n network: string,\n address: string,\n callback?: () => void\n ) => {\n let newAccounts = [...wcAccounts]\n\n newAccounts = newAccounts.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 (!newAccounts.length) {\n localStorage.removeItem('wallet_connect_accounts')\n } else {\n localStorage.setItem(\n 'wallet_connect_accounts',\n JSON.stringify(newAccounts)\n )\n }\n setWcAccounts(newAccounts)\n\n // Handle optional callback function.\n if (typeof callback === 'function') {\n callback()\n }\n }\n\n const getWcAccount = (network: string, address: string) =>\n wcAccounts.find((a) => a.address === address && a.network === network)\n\n const renameWcAccount = (\n network: string,\n address: string,\n newName: string\n ) => {\n const newAccounts = [...wcAccounts].map((a) =>\n isLocalNetworkAddress(network, a, address)\n ? {\n ...a,\n name: newName,\n }\n : a\n )\n localStorage.setItem('wallet_connect_accounts', JSON.stringify(newAccounts))\n\n setWcAccounts(newAccounts)\n }\n\n // Gets Wallet Connect accounts for a network.\n const getWcAccounts = (network: string) =>\n wcAccounts.filter((a) => a.network === network)\n\n return (\n <WCAccountsContext.Provider\n value={{\n wcAccountExists,\n addWcAccount,\n removeWcAccount,\n renameWcAccount,\n getWcAccount,\n getWcAccounts,\n }}\n >\n {children}\n </WCAccountsContext.Provider>\n )\n}\n"]}
@@ -1,9 +0,0 @@
1
- import type { HardwareAccount } from '@w3ux/types';
2
- export interface WCAccountsContextInterface {
3
- wcAccountExists: (network: string, address: string) => boolean;
4
- addWcAccount: (network: string, address: string, index: number, callback?: () => void) => HardwareAccount | null;
5
- removeWcAccount: (network: string, address: string, callback?: () => void) => void;
6
- renameWcAccount: (network: string, address: string, newName: string) => void;
7
- getWcAccount: (network: string, address: string) => HardwareAccount | null;
8
- getWcAccounts: (network: string) => HardwareAccount[];
9
- }
@@ -1,5 +0,0 @@
1
- export {};
2
-
3
- //# sourceMappingURL=types.js.map
4
-
5
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/WCAccounts/types.ts"],"names":[],"mappings":"","file":"types.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport type { HardwareAccount } from '@w3ux/types'\n\nexport interface WCAccountsContextInterface {\n wcAccountExists: (network: string, address: string) => boolean\n addWcAccount: (\n network: string,\n address: string,\n index: number,\n callback?: () => void\n ) => HardwareAccount | null\n removeWcAccount: (\n network: string,\n address: string,\n callback?: () => void\n ) => void\n renameWcAccount: (network: string, address: string, newName: string) => void\n getWcAccount: (network: string, address: string) => HardwareAccount | null\n getWcAccounts: (network: string) => HardwareAccount[]\n}\n"]}
@@ -1,6 +0,0 @@
1
- import type { HardwareAccount } from '@w3ux/types';
2
- export declare const getLocalWcAccounts: (network?: string) => HardwareAccount[];
3
- export declare const isLocalNetworkAddress: (chain: string, a: {
4
- address: string | undefined;
5
- network: string;
6
- }, address: string) => boolean;
@@ -1,12 +0,0 @@
1
- import { localStorageOrDefault } from '@w3ux/utils';
2
- export const getLocalWcAccounts = (network) => {
3
- const localAddresses = localStorageOrDefault('wallet_connect_accounts', [], true);
4
- return network
5
- ? localAddresses.filter((a) => a.network === network)
6
- : localAddresses;
7
- };
8
- export const isLocalNetworkAddress = (chain, a, address) => a.address === address && a.network === chain;
9
-
10
- //# sourceMappingURL=utils.js.map
11
-
12
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/WCAccounts/utils.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAGnD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,OAAgB,EAAE,EAAE;IACrD,MAAM,cAAc,GAAG,qBAAqB,CAC1C,yBAAyB,EACzB,EAAE,EACF,IAAI,CACgB,CAAA;IAEtB,OAAO,OAAO;QACZ,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC;QACrD,CAAC,CAAC,cAAc,CAAA;AACpB,CAAC,CAAA;AAGD,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,KAAa,EACb,CAAmD,EACnD,OAAe,EACf,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK,KAAK,CAAA","file":"utils.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport type { HardwareAccount } from '@w3ux/types'\nimport { localStorageOrDefault } from '@w3ux/utils'\n\n// Gets imported Wallet Connect accounts from local storage.\nexport const getLocalWcAccounts = (network?: string) => {\n const localAddresses = localStorageOrDefault(\n 'wallet_connect_accounts',\n [],\n true\n ) as HardwareAccount[]\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/consts.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare const hardwareAccountsKey = "hardware_accounts";
package/consts.js DELETED
@@ -1,5 +0,0 @@
1
- export const hardwareAccountsKey = 'hardware_accounts';
2
-
3
- //# sourceMappingURL=consts.js.map
4
-
5
- //# sourceMappingURL=consts.js.map
package/consts.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/consts.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,mBAAmB,GAAG,mBAAmB,CAAA","file":"consts.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\n// Local storage hardware accounts key\nexport const hardwareAccountsKey = 'hardware_accounts'\n"]}