@xyo-network/react-wallet 2.64.0 → 2.64.3

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 (94) hide show
  1. package/dist/browser/components/MaxAccounts/MaxAccountsTableRow.js +41 -11
  2. package/dist/browser/components/MaxAccounts/MaxAccountsTableRow.js.map +1 -1
  3. package/dist/browser/components/MaxAccounts/OutOfBoundsSnackBar.js +3 -2
  4. package/dist/browser/components/MaxAccounts/OutOfBoundsSnackBar.js.map +1 -1
  5. package/dist/browser/components/MaxAccounts/index.js +88 -1
  6. package/dist/browser/components/MaxAccounts/index.js.map +1 -1
  7. package/dist/browser/components/SeedPhrase/DefaultSeedPhrase.js +3 -2
  8. package/dist/browser/components/SeedPhrase/DefaultSeedPhrase.js.map +1 -1
  9. package/dist/browser/components/SeedPhrase/_shared/SeedPhraseIconButton.js +3 -2
  10. package/dist/browser/components/SeedPhrase/_shared/SeedPhraseIconButton.js.map +1 -1
  11. package/dist/browser/components/SeedPhrase/_shared/index.js +45 -1
  12. package/dist/browser/components/SeedPhrase/_shared/index.js.map +1 -1
  13. package/dist/browser/components/SeedPhrase/dialog/SeedPhraseDialog.js +295 -16
  14. package/dist/browser/components/SeedPhrase/dialog/SeedPhraseDialog.js.map +1 -1
  15. package/dist/browser/components/SeedPhrase/dialog/components/DialogActionButtons.js +13 -3
  16. package/dist/browser/components/SeedPhrase/dialog/components/DialogActionButtons.js.map +1 -1
  17. package/dist/browser/components/SeedPhrase/dialog/components/OverwriteWarning.js +13 -3
  18. package/dist/browser/components/SeedPhrase/dialog/components/OverwriteWarning.js.map +1 -1
  19. package/dist/browser/components/SeedPhrase/dialog/components/fields/NewPhraseTextField.js +74 -12
  20. package/dist/browser/components/SeedPhrase/dialog/components/fields/NewPhraseTextField.js.map +1 -1
  21. package/dist/browser/components/SeedPhrase/dialog/components/fields/SavedPhraseTextField.js +60 -10
  22. package/dist/browser/components/SeedPhrase/dialog/components/fields/SavedPhraseTextField.js.map +1 -1
  23. package/dist/browser/components/SeedPhrase/dialog/components/fields/index.js +125 -2
  24. package/dist/browser/components/SeedPhrase/dialog/components/fields/index.js.map +1 -1
  25. package/dist/browser/components/SeedPhrase/dialog/components/fields/validation-messages/InvalidPhrase.js +3 -2
  26. package/dist/browser/components/SeedPhrase/dialog/components/fields/validation-messages/InvalidPhrase.js.map +1 -1
  27. package/dist/browser/components/SeedPhrase/dialog/components/fields/validation-messages/PhraseHeaderBox.js +3 -2
  28. package/dist/browser/components/SeedPhrase/dialog/components/fields/validation-messages/PhraseHeaderBox.js.map +1 -1
  29. package/dist/browser/components/SeedPhrase/dialog/components/fields/validation-messages/colorParser.js +2 -1
  30. package/dist/browser/components/SeedPhrase/dialog/components/fields/validation-messages/colorParser.js.map +1 -1
  31. package/dist/browser/components/SeedPhrase/dialog/components/fields/validation-messages/index.js +57 -3
  32. package/dist/browser/components/SeedPhrase/dialog/components/fields/validation-messages/index.js.map +1 -1
  33. package/dist/browser/components/SeedPhrase/dialog/components/index.js +164 -3
  34. package/dist/browser/components/SeedPhrase/dialog/components/index.js.map +1 -1
  35. package/dist/browser/components/SeedPhrase/dialog/index.js +315 -1
  36. package/dist/browser/components/SeedPhrase/dialog/index.js.map +1 -1
  37. package/dist/browser/components/SeedPhrase/index.js +373 -4
  38. package/dist/browser/components/SeedPhrase/index.js.map +1 -1
  39. package/dist/browser/components/SeedPhrase/settings/SeedPhraseTableRow.js +325 -12
  40. package/dist/browser/components/SeedPhrase/settings/SeedPhraseTableRow.js.map +1 -1
  41. package/dist/browser/components/SeedPhrase/settings/index.js +339 -1
  42. package/dist/browser/components/SeedPhrase/settings/index.js.map +1 -1
  43. package/dist/browser/components/WalletAccountDetails/WalletAccountDetails.js +62 -3
  44. package/dist/browser/components/WalletAccountDetails/WalletAccountDetails.js.map +1 -1
  45. package/dist/browser/components/WalletAccountDetails/index.js +83 -1
  46. package/dist/browser/components/WalletAccountDetails/index.js.map +1 -1
  47. package/dist/browser/components/WalletAccountSelect/Select.js +70 -5
  48. package/dist/browser/components/WalletAccountSelect/Select.js.map +1 -1
  49. package/dist/browser/components/WalletAccountSelect/SelectBar.js +150 -4
  50. package/dist/browser/components/WalletAccountSelect/SelectBar.js.map +1 -1
  51. package/dist/browser/components/WalletAccountSelect/WalletInfo.js +116 -10
  52. package/dist/browser/components/WalletAccountSelect/WalletInfo.js.map +1 -1
  53. package/dist/browser/components/WalletAccountSelect/index.js +175 -2
  54. package/dist/browser/components/WalletAccountSelect/index.js.map +1 -1
  55. package/dist/browser/components/index.js +694 -4
  56. package/dist/browser/components/index.js.map +1 -1
  57. package/dist/browser/contexts/SeedPhrase/Context.js +2 -1
  58. package/dist/browser/contexts/SeedPhrase/Context.js.map +1 -1
  59. package/dist/browser/contexts/SeedPhrase/Provider.js +9 -3
  60. package/dist/browser/contexts/SeedPhrase/Provider.js.map +1 -1
  61. package/dist/browser/contexts/SeedPhrase/index.js +91 -4
  62. package/dist/browser/contexts/SeedPhrase/index.js.map +1 -1
  63. package/dist/browser/contexts/SeedPhrase/use.js +8 -2
  64. package/dist/browser/contexts/SeedPhrase/use.js.map +1 -1
  65. package/dist/browser/contexts/Wallet/Context.js +2 -1
  66. package/dist/browser/contexts/Wallet/Context.js.map +1 -1
  67. package/dist/browser/contexts/Wallet/Provider.js +90 -7
  68. package/dist/browser/contexts/Wallet/Provider.js.map +1 -1
  69. package/dist/browser/contexts/Wallet/index.js +183 -5
  70. package/dist/browser/contexts/Wallet/index.js.map +1 -1
  71. package/dist/browser/contexts/Wallet/lib/WalletPath.js +4 -3
  72. package/dist/browser/contexts/Wallet/lib/WalletPath.js.map +1 -1
  73. package/dist/browser/contexts/Wallet/lib/index.js +21 -1
  74. package/dist/browser/contexts/Wallet/lib/index.js.map +1 -1
  75. package/dist/browser/contexts/Wallet/use.js +13 -7
  76. package/dist/browser/contexts/Wallet/use.js.map +1 -1
  77. package/dist/browser/contexts/Wallet/usePromise.js +2 -1
  78. package/dist/browser/contexts/Wallet/usePromise.js.map +1 -1
  79. package/dist/browser/contexts/index.js +273 -2
  80. package/dist/browser/contexts/index.js.map +1 -1
  81. package/dist/browser/hooks/index.js +147 -4
  82. package/dist/browser/hooks/index.js.map +1 -1
  83. package/dist/browser/hooks/useAccount.js +24 -4
  84. package/dist/browser/hooks/useAccount.js.map +1 -1
  85. package/dist/browser/hooks/useWallet.js +38 -4
  86. package/dist/browser/hooks/useWallet.js.map +1 -1
  87. package/dist/browser/hooks/useWallets.js +69 -4
  88. package/dist/browser/hooks/useWallets.js.map +1 -1
  89. package/dist/browser/hooks/useWrapperAccount.js +4 -3
  90. package/dist/browser/hooks/useWrapperAccount.js.map +1 -1
  91. package/dist/browser/index.js +890 -3
  92. package/dist/browser/index.js.map +1 -1
  93. package/dist/docs.json +147 -147
  94. package/package.json +22 -22
@@ -1,6 +1,184 @@
1
- export * from "./Context";
2
- export * from "./lib";
3
- export * from "./Provider";
4
- export * from "./State";
5
- export * from "./use";
1
+ // src/contexts/Wallet/Context.ts
2
+ import { createContextEx } from "@xyo-network/react-shared";
3
+ var WalletContext = createContextEx();
4
+
5
+ // src/contexts/Wallet/lib/WalletPath.ts
6
+ var Bip44 = {
7
+ base: "m",
8
+ coin_type: {
9
+ /* https://github.com/satoshilabs/slips/blob/master/slip-0044.md */
10
+ bitcoin: "0'",
11
+ bitcoinTestnet: "1'",
12
+ ether: "60'",
13
+ etherClassic: "61'"
14
+ },
15
+ purpose: "44'"
16
+ };
17
+ var WalletRootPath = `${Bip44.base}/${Bip44.purpose}/${Bip44.coin_type.ether}`;
18
+ var ethereumAccountPath = (index, hardened = true) => {
19
+ return `${WalletRootPath}/${index}${hardened ? "'" : ""}/0`;
20
+ };
21
+
22
+ // src/contexts/Wallet/Provider.tsx
23
+ import { useEffect as useEffect2, useState as useState2 } from "react";
24
+
25
+ // src/contexts/Wallet/usePromise.ts
26
+ import { Mutex } from "async-mutex";
27
+ import { useEffect, useMemo, useState } from "react";
28
+ var usePromise = (promise, dependencies, debug = void 0) => {
29
+ const [result, setResult] = useState();
30
+ const [error, setError] = useState();
31
+ const [state, setState] = useState("pending" /* pending */);
32
+ const mutex = useMemo(() => {
33
+ return new Mutex();
34
+ }, []);
35
+ if (debug)
36
+ console.log(`usePromise [${debug}]: started [${typeof promise}]`);
37
+ const promiseMemo = useMemo(() => {
38
+ try {
39
+ if (debug)
40
+ console.log(`usePromise [${debug}]: re-memo [${typeof promise}]`);
41
+ setState("pending" /* pending */);
42
+ return promise?.();
43
+ } catch (e) {
44
+ if (debug)
45
+ console.log(`usePromise [${debug}]: useMemo rejection [${typeof promise}]`);
46
+ setResult(void 0);
47
+ setError(e);
48
+ setState("rejected" /* rejected */);
49
+ }
50
+ }, dependencies);
51
+ if (debug)
52
+ console.log(`usePromise [${debug}] Main Function`);
53
+ useEffect(() => {
54
+ if (debug)
55
+ console.log(`usePromise [${debug}] useEffect`);
56
+ mutex?.acquire().then(() => {
57
+ promiseMemo?.then((payload) => {
58
+ if (debug)
59
+ console.log(`usePromise [${debug}] then`);
60
+ setResult(payload);
61
+ setError(void 0);
62
+ setState("resolved" /* resolved */);
63
+ mutex?.release();
64
+ }).catch((e) => {
65
+ const error2 = e;
66
+ console.error(`usePromise: ${error2.message}`);
67
+ setResult(void 0);
68
+ setError(error2);
69
+ setState("rejected" /* rejected */);
70
+ mutex?.release();
71
+ });
72
+ }).catch((e) => {
73
+ const error2 = e;
74
+ console.error(`usePromise: ${error2.message}`);
75
+ setResult(void 0);
76
+ setError(error2);
77
+ setState("rejected" /* rejected */);
78
+ mutex?.release();
79
+ });
80
+ return () => {
81
+ if (debug)
82
+ console.log(`usePromise [${debug}] useEffect callback`);
83
+ };
84
+ }, [...dependencies, promiseMemo]);
85
+ if (debug)
86
+ console.log(`usePromise [${debug}] returning ${JSON.stringify([result, error, state], null, 2)}`);
87
+ return [result, error, state];
88
+ };
89
+
90
+ // src/contexts/Wallet/Provider.tsx
91
+ import { jsx } from "react/jsx-runtime";
92
+ var WalletProvider = ({
93
+ basePath = WalletRootPath,
94
+ children,
95
+ defaultActiveAccountIndex = 0,
96
+ rootWallet = null,
97
+ ...props
98
+ }) => {
99
+ const [activeAccountIndex, setActiveAccountIndex] = useState2(defaultActiveAccountIndex);
100
+ useEffect2(() => {
101
+ if (defaultActiveAccountIndex !== void 0) {
102
+ setActiveAccountIndex(defaultActiveAccountIndex);
103
+ }
104
+ }, [defaultActiveAccountIndex]);
105
+ const [coinTypeWallet = null] = usePromise(async () => {
106
+ if (rootWallet) {
107
+ if (!rootWallet?.path.includes(basePath)) {
108
+ try {
109
+ return await rootWallet?.derivePath(basePath);
110
+ } catch (e) {
111
+ console.error("Error setting proper wallet base path", e);
112
+ }
113
+ }
114
+ } else {
115
+ return void 0;
116
+ }
117
+ }, [basePath, rootWallet]);
118
+ const [activeAccount = null] = usePromise(
119
+ async () => await coinTypeWallet?.derivePath(activeAccountIndex.toString()),
120
+ [coinTypeWallet, activeAccountIndex]
121
+ );
122
+ return /* @__PURE__ */ jsx(
123
+ WalletContext.Provider,
124
+ {
125
+ value: {
126
+ activeAccount,
127
+ activeAccountIndex,
128
+ basePath,
129
+ coinTypeWallet,
130
+ provided: true,
131
+ rootWallet,
132
+ setActiveAccountIndex
133
+ },
134
+ ...props,
135
+ children
136
+ }
137
+ );
138
+ };
139
+
140
+ // src/contexts/Wallet/use.ts
141
+ import { usePromise as usePromise2 } from "@xylabs/react-promise";
142
+ import { useContextEx, useProvided } from "@xyo-network/react-shared";
143
+ var useWalletContext = (required = true) => {
144
+ return useContextEx(WalletContext, "Wallet", required);
145
+ };
146
+ var useWalletProvided = () => {
147
+ return useProvided(WalletContext);
148
+ };
149
+ var useCoinTypeWallet = (required = true) => {
150
+ const { coinTypeWallet } = useWalletContext(required);
151
+ return [coinTypeWallet, void 0];
152
+ };
153
+ var useRootWallet = (required = true) => {
154
+ const { rootWallet } = useWalletContext(required);
155
+ return [rootWallet, void 0];
156
+ };
157
+ var useIndexedWalletFromContext = (index, required = true) => {
158
+ const [coinTypeWallet] = useCoinTypeWallet(required);
159
+ const [wallet] = usePromise2(async () => await coinTypeWallet?.derivePath(index.toString()) ?? coinTypeWallet, [coinTypeWallet, index]);
160
+ return [wallet, void 0];
161
+ };
162
+ var useSelectedWalletAccount = (required = true) => {
163
+ const { activeAccountIndex } = useWalletContext(required);
164
+ const [account] = useIndexedWalletFromContext(activeAccountIndex ?? 0, required);
165
+ if (activeAccountIndex === void 0 && account === null) {
166
+ return [null, void 0];
167
+ } else {
168
+ return [account, void 0];
169
+ }
170
+ };
171
+ export {
172
+ Bip44,
173
+ WalletContext,
174
+ WalletProvider,
175
+ WalletRootPath,
176
+ ethereumAccountPath,
177
+ useCoinTypeWallet,
178
+ useIndexedWalletFromContext,
179
+ useRootWallet,
180
+ useSelectedWalletAccount,
181
+ useWalletContext,
182
+ useWalletProvided
183
+ };
6
184
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/contexts/Wallet/index.ts"],"sourcesContent":["export * from './Context'\nexport * from './lib'\nexport * from './Provider'\nexport * from './State'\nexport * from './use'\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
1
+ {"version":3,"sources":["../../../../src/contexts/Wallet/Context.ts","../../../../src/contexts/Wallet/lib/WalletPath.ts","../../../../src/contexts/Wallet/Provider.tsx","../../../../src/contexts/Wallet/usePromise.ts","../../../../src/contexts/Wallet/use.ts"],"sourcesContent":["import { createContextEx } from '@xyo-network/react-shared'\n\nimport { WalletContextState } from './State'\n\nexport const WalletContext = createContextEx<WalletContextState>()\n","export const Bip44 = {\n base: 'm',\n coin_type: {\n /* https://github.com/satoshilabs/slips/blob/master/slip-0044.md */\n bitcoin: \"0'\",\n bitcoinTestnet: \"1'\",\n ether: \"60'\",\n etherClassic: \"61'\",\n },\n purpose: \"44'\",\n}\n\nexport const WalletRootPath = `${Bip44.base}/${Bip44.purpose}/${Bip44.coin_type.ether}`\n\nexport const ethereumAccountPath = (index: number, hardened = true) => {\n return `${WalletRootPath}/${index}${hardened ? \"'\" : ''}/0`\n}\n","import { WithChildren } from '@xylabs/react-shared'\nimport { WalletInstance } from '@xyo-network/wallet-model'\nimport { useEffect, useState } from 'react'\n\nimport { WalletContext } from './Context'\nimport { WalletRootPath } from './lib'\nimport { usePromise } from './usePromise'\n\nexport interface WalletProviderProps {\n basePath?: string\n defaultActiveAccountIndex?: number\n rootWallet?: WalletInstance | null\n}\n\nexport const WalletProvider: React.FC<WithChildren<WalletProviderProps>> = ({\n basePath = WalletRootPath,\n children,\n defaultActiveAccountIndex = 0,\n rootWallet = null,\n ...props\n}) => {\n const [activeAccountIndex, setActiveAccountIndex] = useState(defaultActiveAccountIndex)\n\n useEffect(() => {\n if (defaultActiveAccountIndex !== undefined) {\n setActiveAccountIndex(defaultActiveAccountIndex)\n }\n }, [defaultActiveAccountIndex])\n\n const [coinTypeWallet = null] = usePromise(async () => {\n // ensure the wallet has the proper base\n if (rootWallet) {\n if (!rootWallet?.path.includes(basePath)) {\n try {\n return await rootWallet?.derivePath(basePath)\n } catch (e) {\n console.error('Error setting proper wallet base path', e)\n }\n }\n } else {\n return undefined\n }\n }, [basePath, rootWallet])\n\n const [activeAccount = null] = usePromise(\n async () => await coinTypeWallet?.derivePath(activeAccountIndex.toString()),\n [coinTypeWallet, activeAccountIndex],\n )\n\n return (\n <WalletContext.Provider\n value={{\n activeAccount,\n activeAccountIndex,\n basePath,\n coinTypeWallet,\n provided: true,\n rootWallet,\n setActiveAccountIndex,\n }}\n {...props}\n >\n {children}\n </WalletContext.Provider>\n )\n}\n","// Inspired from https://github.com/bsonntag/react-use-promise\n\nimport { Mutex } from 'async-mutex'\nimport { DependencyList, useEffect, useMemo, useState } from 'react'\n\nexport enum State {\n pending = 'pending',\n rejected = 'rejected',\n resolved = 'resolved',\n}\n\n/**\n * usePromise -\n */\nexport const usePromise = <TResult>(\n promise: () => Promise<TResult | undefined>,\n dependencies: DependencyList,\n debug: string | undefined = undefined,\n): [TResult | undefined, Error | undefined, State | undefined] => {\n const [result, setResult] = useState<TResult>()\n const [error, setError] = useState<Error>()\n const [state, setState] = useState<State>(State.pending)\n const mutex = useMemo(() => {\n return new Mutex()\n }, [])\n\n if (debug) console.log(`usePromise [${debug}]: started [${typeof promise}]`)\n\n const promiseMemo: Promise<TResult | undefined> | undefined = useMemo(() => {\n try {\n if (debug) console.log(`usePromise [${debug}]: re-memo [${typeof promise}]`)\n setState(State.pending)\n return promise?.()\n } catch (e) {\n if (debug) console.log(`usePromise [${debug}]: useMemo rejection [${typeof promise}]`)\n setResult(undefined)\n setError(e as Error)\n setState(State.rejected)\n }\n }, dependencies)\n\n if (debug) console.log(`usePromise [${debug}] Main Function`)\n\n useEffect(() => {\n if (debug) console.log(`usePromise [${debug}] useEffect`)\n mutex\n ?.acquire()\n .then(() => {\n promiseMemo\n ?.then((payload) => {\n if (debug) console.log(`usePromise [${debug}] then`)\n setResult(payload)\n setError(undefined)\n setState(State.resolved)\n mutex?.release()\n })\n .catch((e) => {\n const error = e as Error\n console.error(`usePromise: ${error.message}`)\n setResult(undefined)\n setError(error)\n setState(State.rejected)\n mutex?.release()\n })\n })\n .catch((e) => {\n const error = e as Error\n console.error(`usePromise: ${error.message}`)\n setResult(undefined)\n setError(error)\n setState(State.rejected)\n mutex?.release()\n })\n return () => {\n if (debug) console.log(`usePromise [${debug}] useEffect callback`)\n }\n }, [...dependencies, promiseMemo])\n if (debug) console.log(`usePromise [${debug}] returning ${JSON.stringify([result, error, state], null, 2)}`)\n return [result, error, state]\n}\n","import { usePromise } from '@xylabs/react-promise'\nimport { useContextEx, useProvided } from '@xyo-network/react-shared'\nimport { WalletInstance } from '@xyo-network/wallet-model'\n\nimport { WalletContext } from './Context'\n\nexport const useWalletContext = (required = true) => {\n return useContextEx(WalletContext, 'Wallet', required)\n}\n\nexport const useWalletProvided = () => {\n return useProvided(WalletContext)\n}\n\nexport const useCoinTypeWallet = (required = true): [WalletInstance | null | undefined, Error | undefined] => {\n const { coinTypeWallet } = useWalletContext(required)\n return [coinTypeWallet, undefined]\n}\n\nexport const useRootWallet = (required = true): [WalletInstance | null | undefined, Error | undefined] => {\n const { rootWallet } = useWalletContext(required)\n return [rootWallet, undefined]\n}\n\nexport const useIndexedWalletFromContext = (index: number, required = true): [WalletInstance | null | undefined, Error | undefined] => {\n const [coinTypeWallet] = useCoinTypeWallet(required)\n const [wallet] = usePromise(async () => (await coinTypeWallet?.derivePath(index.toString())) ?? coinTypeWallet, [coinTypeWallet, index])\n return [wallet, undefined]\n}\n\nexport const useSelectedWalletAccount = (required = true): [WalletInstance | null | undefined, Error | undefined] => {\n const { activeAccountIndex } = useWalletContext(required)\n //we pass in 0 as default since we can not call the hook optionally,\n //we resolve this false result by checking whether activeAccountIndex is defined before returning it\n const [account] = useIndexedWalletFromContext(activeAccountIndex ?? 0, required)\n if (activeAccountIndex === undefined && account === null) {\n return [null, undefined]\n } else {\n return [account, undefined]\n }\n}\n"],"mappings":";AAAA,SAAS,uBAAuB;AAIzB,IAAM,gBAAgB,gBAAoC;;;ACJ1D,IAAM,QAAQ;AAAA,EACnB,MAAM;AAAA,EACN,WAAW;AAAA;AAAA,IAET,SAAS;AAAA,IACT,gBAAgB;AAAA,IAChB,OAAO;AAAA,IACP,cAAc;AAAA,EAChB;AAAA,EACA,SAAS;AACX;AAEO,IAAM,iBAAiB,GAAG,MAAM,IAAI,IAAI,MAAM,OAAO,IAAI,MAAM,UAAU,KAAK;AAE9E,IAAM,sBAAsB,CAAC,OAAe,WAAW,SAAS;AACrE,SAAO,GAAG,cAAc,IAAI,KAAK,GAAG,WAAW,MAAM,EAAE;AACzD;;;ACdA,SAAS,aAAAA,YAAW,YAAAC,iBAAgB;;;ACApC,SAAS,aAAa;AACtB,SAAyB,WAAW,SAAS,gBAAgB;AAWtD,IAAM,aAAa,CACxB,SACA,cACA,QAA4B,WACoC;AAChE,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAkB;AAC9C,QAAM,CAAC,O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A;AAAA,QACA,UAAU;AAAA,QACV;AAAA,QACA;AAAA,MACF;AAAA,MACC,GAAG;AAAA,MAEH;AAAA;AAAA,EACH;AAEJ;;;AEjEA,SAAS,cAAAC,mBAAkB;AAC3B,SAAS,cAAc,mBAAmB;AAKnC,IAAM,mBAAmB,CAAC,WAAW,SAAS;AACnD,SAAO,aAAa,eAAe,UAAU,QAAQ;AACvD;AAEO,IAAM,oBAAoB,MAAM;AACrC,SAAO,YAAY,aAAa;AAClC;AAEO,IAAM,oBAAoB,CAAC,WAAW,SAAiE;AAC5G,QAAM,EAAE,eAAe,IAAI,iBAAiB,QAAQ;AACpD,SAAO,CAAC,gBAAgB,MAAS;AACnC;AAEO,IAAM,gBAAgB,CAAC,WAAW,SAAiE;AACxG,QAAM,EAAE,WAAW,IAAI,iBAAiB,QAAQ;AAChD,SAAO,CAAC,YAAY,MAAS;AAC/B;AAEO,IAAM,8BAA8B,CAAC,OAAe,WAAW,SAAiE;AACrI,QAAM,CAAC,cAAc,IAAI,kBAAkB,QAAQ;AACnD,QAAM,CAAC,MAAM,IAAIC,YAAW,YAAa,MAAM,gBAAgB,WAAW,MAAM,SAAS,CAAC,KAAM,gBAAgB,CAAC,gBAAgB,KAAK,CAAC;AACvI,SAAO,CAAC,QAAQ,MAAS;AAC3B;AAEO,IAAM,2BAA2B,CAAC,WAAW,SAAiE;AACnH,QAAM,EAAE,mBAAmB,IAAI,iBAAiB,QAAQ;AAGxD,QAAM,CAAC,OAAO,IAAI,4BAA4B,sBAAsB,GAAG,QAAQ;AAC/E,MAAI,uBAAuB,UAAa,YAAY,MAAM;AACxD,WAAO,CAAC,MAAM,MAAS;AAAA,EACzB,OAAO;AACL,WAAO,CAAC,SAAS,MAAS;AAAA,EAC5B;AACF;","names":["useEffect","useState","error","useState","useEffect","usePromise","usePromise"]}
@@ -1,4 +1,5 @@
1
- const Bip44 = {
1
+ // src/contexts/Wallet/lib/WalletPath.ts
2
+ var Bip44 = {
2
3
  base: "m",
3
4
  coin_type: {
4
5
  /* https://github.com/satoshilabs/slips/blob/master/slip-0044.md */
@@ -9,8 +10,8 @@ const Bip44 = {
9
10
  },
10
11
  purpose: "44'"
11
12
  };
12
- const WalletRootPath = `${Bip44.base}/${Bip44.purpose}/${Bip44.coin_type.ether}`;
13
- const ethereumAccountPath = (index, hardened = true) => {
13
+ var WalletRootPath = `${Bip44.base}/${Bip44.purpose}/${Bip44.coin_type.ether}`;
14
+ var ethereumAccountPath = (index, hardened = true) => {
14
15
  return `${WalletRootPath}/${index}${hardened ? "'" : ""}/0`;
15
16
  };
16
17
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/contexts/Wallet/lib/WalletPath.ts"],"sourcesContent":["export const Bip44 = {\n base: 'm',\n coin_type: {\n /* https://github.com/satoshilabs/slips/blob/master/slip-0044.md */\n bitcoin: \"0'\",\n bitcoinTestnet: \"1'\",\n ether: \"60'\",\n etherClassic: \"61'\",\n },\n purpose: \"44'\",\n}\n\nexport const WalletRootPath = `${Bip44.base}/${Bip44.purpose}/${Bip44.coin_type.ether}`\n\nexport const ethereumAccountPath = (index: number, hardened = true) => {\n return `${WalletRootPath}/${index}${hardened ? \"'\" : ''}/0`\n}\n"],"mappings":"AAAO,MAAM,QAAQ;AAAA,EACnB,MAAM;AAAA,EACN,WAAW;AAAA;AAAA,IAET,SAAS;AAAA,IACT,gBAAgB;AAAA,IAChB,OAAO;AAAA,IACP,cAAc;AAAA,EAChB;AAAA,EACA,SAAS;AACX;AAEO,MAAM,iBAAiB,GAAG,MAAM,IAAI,IAAI,MAAM,OAAO,IAAI,MAAM,UAAU,KAAK;AAE9E,MAAM,sBAAsB,CAAC,OAAe,WAAW,SAAS;AACrE,SAAO,GAAG,cAAc,IAAI,KAAK,GAAG,WAAW,MAAM,EAAE;AACzD;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/contexts/Wallet/lib/WalletPath.ts"],"sourcesContent":["export const Bip44 = {\n base: 'm',\n coin_type: {\n /* https://github.com/satoshilabs/slips/blob/master/slip-0044.md */\n bitcoin: \"0'\",\n bitcoinTestnet: \"1'\",\n ether: \"60'\",\n etherClassic: \"61'\",\n },\n purpose: \"44'\",\n}\n\nexport const WalletRootPath = `${Bip44.base}/${Bip44.purpose}/${Bip44.coin_type.ether}`\n\nexport const ethereumAccountPath = (index: number, hardened = true) => {\n return `${WalletRootPath}/${index}${hardened ? \"'\" : ''}/0`\n}\n"],"mappings":";AAAO,IAAM,QAAQ;AAAA,EACnB,MAAM;AAAA,EACN,WAAW;AAAA;AAAA,IAET,SAAS;AAAA,IACT,gBAAgB;AAAA,IAChB,OAAO;AAAA,IACP,cAAc;AAAA,EAChB;AAAA,EACA,SAAS;AACX;AAEO,IAAM,iBAAiB,GAAG,MAAM,IAAI,IAAI,MAAM,OAAO,IAAI,MAAM,UAAU,KAAK;AAE9E,IAAM,sBAAsB,CAAC,OAAe,WAAW,SAAS;AACrE,SAAO,GAAG,cAAc,IAAI,KAAK,GAAG,WAAW,MAAM,EAAE;AACzD;","names":[]}
@@ -1,2 +1,22 @@
1
- export * from "./WalletPath";
1
+ // src/contexts/Wallet/lib/WalletPath.ts
2
+ var Bip44 = {
3
+ base: "m",
4
+ coin_type: {
5
+ /* https://github.com/satoshilabs/slips/blob/master/slip-0044.md */
6
+ bitcoin: "0'",
7
+ bitcoinTestnet: "1'",
8
+ ether: "60'",
9
+ etherClassic: "61'"
10
+ },
11
+ purpose: "44'"
12
+ };
13
+ var WalletRootPath = `${Bip44.base}/${Bip44.purpose}/${Bip44.coin_type.ether}`;
14
+ var ethereumAccountPath = (index, hardened = true) => {
15
+ return `${WalletRootPath}/${index}${hardened ? "'" : ""}/0`;
16
+ };
17
+ export {
18
+ Bip44,
19
+ WalletRootPath,
20
+ ethereumAccountPath
21
+ };
2
22
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/contexts/Wallet/lib/index.ts"],"sourcesContent":["export * from './WalletPath'\n"],"mappings":"AAAA,cAAc;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/contexts/Wallet/lib/WalletPath.ts"],"sourcesContent":["export const Bip44 = {\n base: 'm',\n coin_type: {\n /* https://github.com/satoshilabs/slips/blob/master/slip-0044.md */\n bitcoin: \"0'\",\n bitcoinTestnet: \"1'\",\n ether: \"60'\",\n etherClassic: \"61'\",\n },\n purpose: \"44'\",\n}\n\nexport const WalletRootPath = `${Bip44.base}/${Bip44.purpose}/${Bip44.coin_type.ether}`\n\nexport const ethereumAccountPath = (index: number, hardened = true) => {\n return `${WalletRootPath}/${index}${hardened ? \"'\" : ''}/0`\n}\n"],"mappings":";AAAO,IAAM,QAAQ;AAAA,EACnB,MAAM;AAAA,EACN,WAAW;AAAA;AAAA,IAET,SAAS;AAAA,IACT,gBAAgB;AAAA,IAChB,OAAO;AAAA,IACP,cAAc;AAAA,EAChB;AAAA,EACA,SAAS;AACX;AAEO,IAAM,iBAAiB,GAAG,MAAM,IAAI,IAAI,MAAM,OAAO,IAAI,MAAM,UAAU,KAAK;AAE9E,IAAM,sBAAsB,CAAC,OAAe,WAAW,SAAS;AACrE,SAAO,GAAG,cAAc,IAAI,KAAK,GAAG,WAAW,MAAM,EAAE;AACzD;","names":[]}
@@ -1,26 +1,32 @@
1
+ // src/contexts/Wallet/use.ts
1
2
  import { usePromise } from "@xylabs/react-promise";
2
3
  import { useContextEx, useProvided } from "@xyo-network/react-shared";
3
- import { WalletContext } from "./Context";
4
- const useWalletContext = (required = true) => {
4
+
5
+ // src/contexts/Wallet/Context.ts
6
+ import { createContextEx } from "@xyo-network/react-shared";
7
+ var WalletContext = createContextEx();
8
+
9
+ // src/contexts/Wallet/use.ts
10
+ var useWalletContext = (required = true) => {
5
11
  return useContextEx(WalletContext, "Wallet", required);
6
12
  };
7
- const useWalletProvided = () => {
13
+ var useWalletProvided = () => {
8
14
  return useProvided(WalletContext);
9
15
  };
10
- const useCoinTypeWallet = (required = true) => {
16
+ var useCoinTypeWallet = (required = true) => {
11
17
  const { coinTypeWallet } = useWalletContext(required);
12
18
  return [coinTypeWallet, void 0];
13
19
  };
14
- const useRootWallet = (required = true) => {
20
+ var useRootWallet = (required = true) => {
15
21
  const { rootWallet } = useWalletContext(required);
16
22
  return [rootWallet, void 0];
17
23
  };
18
- const useIndexedWalletFromContext = (index, required = true) => {
24
+ var useIndexedWalletFromContext = (index, required = true) => {
19
25
  const [coinTypeWallet] = useCoinTypeWallet(required);
20
26
  const [wallet] = usePromise(async () => await coinTypeWallet?.derivePath(index.toString()) ?? coinTypeWallet, [coinTypeWallet, index]);
21
27
  return [wallet, void 0];
22
28
  };
23
- const useSelectedWalletAccount = (required = true) => {
29
+ var useSelectedWalletAccount = (required = true) => {
24
30
  const { activeAccountIndex } = useWalletContext(required);
25
31
  const [account] = useIndexedWalletFromContext(activeAccountIndex ?? 0, required);
26
32
  if (activeAccountIndex === void 0 && account === null) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/contexts/Wallet/use.ts"],"sourcesContent":["import { usePromise } from '@xylabs/react-promise'\nimport { useContextEx, useProvided } from '@xyo-network/react-shared'\nimport { WalletInstance } from '@xyo-network/wallet-model'\n\nimport { WalletContext } from './Context'\n\nexport const useWalletContext = (required = true) => {\n return useContextEx(WalletContext, 'Wallet', required)\n}\n\nexport const useWalletProvided = () => {\n return useProvided(WalletContext)\n}\n\nexport const useCoinTypeWallet = (required = true): [WalletInstance | null | undefined, Error | undefined] => {\n const { coinTypeWallet } = useWalletContext(required)\n return [coinTypeWallet, undefined]\n}\n\nexport const useRootWallet = (required = true): [WalletInstance | null | undefined, Error | undefined] => {\n const { rootWallet } = useWalletContext(required)\n return [rootWallet, undefined]\n}\n\nexport const useIndexedWalletFromContext = (index: number, required = true): [WalletInstance | null | undefined, Error | undefined] => {\n const [coinTypeWallet] = useCoinTypeWallet(required)\n const [wallet] = usePromise(async () => (await coinTypeWallet?.derivePath(index.toString())) ?? coinTypeWallet, [coinTypeWallet, index])\n return [wallet, undefined]\n}\n\nexport const useSelectedWalletAccount = (required = true): [WalletInstance | null | undefined, Error | undefined] => {\n const { activeAccountIndex } = useWalletContext(required)\n //we pass in 0 as default since we can not call the hook optionally,\n //we resolve this false result by checking whether activeAccountIndex is defined before returning it\n const [account] = useIndexedWalletFromContext(activeAccountIndex ?? 0, required)\n if (activeAccountIndex === undefined && account === null) {\n return [null, undefined]\n } else {\n return [account, undefined]\n }\n}\n"],"mappings":"AAAA,SAAS,kBAAkB;AAC3B,SAAS,cAAc,mBAAmB;AAG1C,SAAS,qBAAqB;AAEvB,MAAM,mBAAmB,CAAC,WAAW,SAAS;AACnD,SAAO,aAAa,eAAe,UAAU,QAAQ;AACvD;AAEO,MAAM,oBAAoB,MAAM;AACrC,SAAO,YAAY,aAAa;AAClC;AAEO,MAAM,oBAAoB,CAAC,WAAW,SAAiE;AAC5G,QAAM,EAAE,eAAe,IAAI,iBAAiB,QAAQ;AACpD,SAAO,CAAC,gBAAgB,MAAS;AACnC;AAEO,MAAM,gBAAgB,CAAC,WAAW,SAAiE;AACxG,QAAM,EAAE,WAAW,IAAI,iBAAiB,QAAQ;AAChD,SAAO,CAAC,YAAY,MAAS;AAC/B;AAEO,MAAM,8BAA8B,CAAC,OAAe,WAAW,SAAiE;AACrI,QAAM,CAAC,cAAc,IAAI,kBAAkB,QAAQ;AACnD,QAAM,CAAC,MAAM,IAAI,WAAW,YAAa,MAAM,gBAAgB,WAAW,MAAM,SAAS,CAAC,KAAM,gBAAgB,CAAC,gBAAgB,KAAK,CAAC;AACvI,SAAO,CAAC,QAAQ,MAAS;AAC3B;AAEO,MAAM,2BAA2B,CAAC,WAAW,SAAiE;AACnH,QAAM,EAAE,mBAAmB,IAAI,iBAAiB,QAAQ;AAGxD,QAAM,CAAC,OAAO,IAAI,4BAA4B,sBAAsB,GAAG,QAAQ;AAC/E,MAAI,uBAAuB,UAAa,YAAY,MAAM;AACxD,WAAO,CAAC,MAAM,MAAS;AAAA,EACzB,OAAO;AACL,WAAO,CAAC,SAAS,MAAS;AAAA,EAC5B;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/contexts/Wallet/use.ts","../../../../src/contexts/Wallet/Context.ts"],"sourcesContent":["import { usePromise } from '@xylabs/react-promise'\nimport { useContextEx, useProvided } from '@xyo-network/react-shared'\nimport { WalletInstance } from '@xyo-network/wallet-model'\n\nimport { WalletContext } from './Context'\n\nexport const useWalletContext = (required = true) => {\n return useContextEx(WalletContext, 'Wallet', required)\n}\n\nexport const useWalletProvided = () => {\n return useProvided(WalletContext)\n}\n\nexport const useCoinTypeWallet = (required = true): [WalletInstance | null | undefined, Error | undefined] => {\n const { coinTypeWallet } = useWalletContext(required)\n return [coinTypeWallet, undefined]\n}\n\nexport const useRootWallet = (required = true): [WalletInstance | null | undefined, Error | undefined] => {\n const { rootWallet } = useWalletContext(required)\n return [rootWallet, undefined]\n}\n\nexport const useIndexedWalletFromContext = (index: number, required = true): [WalletInstance | null | undefined, Error | undefined] => {\n const [coinTypeWallet] = useCoinTypeWallet(required)\n const [wallet] = usePromise(async () => (await coinTypeWallet?.derivePath(index.toString())) ?? coinTypeWallet, [coinTypeWallet, index])\n return [wallet, undefined]\n}\n\nexport const useSelectedWalletAccount = (required = true): [WalletInstance | null | undefined, Error | undefined] => {\n const { activeAccountIndex } = useWalletContext(required)\n //we pass in 0 as default since we can not call the hook optionally,\n //we resolve this false result by checking whether activeAccountIndex is defined before returning it\n const [account] = useIndexedWalletFromContext(activeAccountIndex ?? 0, required)\n if (activeAccountIndex === undefined && account === null) {\n return [null, undefined]\n } else {\n return [account, undefined]\n }\n}\n","import { createContextEx } from '@xyo-network/react-shared'\n\nimport { WalletContextState } from './State'\n\nexport const WalletContext = createContextEx<WalletContextState>()\n"],"mappings":";AAAA,SAAS,kBAAkB;AAC3B,SAAS,cAAc,mBAAmB;;;ACD1C,SAAS,uBAAuB;AAIzB,IAAM,gBAAgB,gBAAoC;;;ADE1D,IAAM,mBAAmB,CAAC,WAAW,SAAS;AACnD,SAAO,aAAa,eAAe,UAAU,QAAQ;AACvD;AAEO,IAAM,oBAAoB,MAAM;AACrC,SAAO,YAAY,aAAa;AAClC;AAEO,IAAM,oBAAoB,CAAC,WAAW,SAAiE;AAC5G,QAAM,EAAE,eAAe,IAAI,iBAAiB,QAAQ;AACpD,SAAO,CAAC,gBAAgB,MAAS;AACnC;AAEO,IAAM,gBAAgB,CAAC,WAAW,SAAiE;AACxG,QAAM,EAAE,WAAW,IAAI,iBAAiB,QAAQ;AAChD,SAAO,CAAC,YAAY,MAAS;AAC/B;AAEO,IAAM,8BAA8B,CAAC,OAAe,WAAW,SAAiE;AACrI,QAAM,CAAC,cAAc,IAAI,kBAAkB,QAAQ;AACnD,QAAM,CAAC,MAAM,IAAI,WAAW,YAAa,MAAM,gBAAgB,WAAW,MAAM,SAAS,CAAC,KAAM,gBAAgB,CAAC,gBAAgB,KAAK,CAAC;AACvI,SAAO,CAAC,QAAQ,MAAS;AAC3B;AAEO,IAAM,2BAA2B,CAAC,WAAW,SAAiE;AACnH,QAAM,EAAE,mBAAmB,IAAI,iBAAiB,QAAQ;AAGxD,QAAM,CAAC,OAAO,IAAI,4BAA4B,sBAAsB,GAAG,QAAQ;AAC/E,MAAI,uBAAuB,UAAa,YAAY,MAAM;AACxD,WAAO,CAAC,MAAM,MAAS;AAAA,EACzB,OAAO;AACL,WAAO,CAAC,SAAS,MAAS;AAAA,EAC5B;AACF;","names":[]}
@@ -1,3 +1,4 @@
1
+ // src/contexts/Wallet/usePromise.ts
1
2
  import { Mutex } from "async-mutex";
2
3
  import { useEffect, useMemo, useState } from "react";
3
4
  var State = /* @__PURE__ */ ((State2) => {
@@ -6,7 +7,7 @@ var State = /* @__PURE__ */ ((State2) => {
6
7
  State2["resolved"] = "resolved";
7
8
  return State2;
8
9
  })(State || {});
9
- const usePromise = (promise, dependencies, debug = void 0) => {
10
+ var usePromise = (promise, dependencies, debug = void 0) => {
10
11
  const [result, setResult] = useState();
11
12
  const [error, setError] = useState();
12
13
  const [state, setState] = useState("pending" /* pending */);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/contexts/Wallet/usePromise.ts"],"sourcesContent":["// Inspired from https://github.com/bsonntag/react-use-promise\n\nimport { Mutex } from 'async-mutex'\nimport { DependencyList, useEffect, useMemo, useState } from 'react'\n\nexport enum State {\n pending = 'pending',\n rejected = 'rejected',\n resolved = 'resolved',\n}\n\n/**\n * usePromise -\n */\nexport const usePromise = <TResult>(\n promise: () => Promise<TResult | undefined>,\n dependencies: DependencyList,\n debug: string | undefined = undefined,\n): [TResult | undefined, Error | undefined, State | undefined] => {\n const [result, setResult] = useState<TResult>()\n const [error, setError] = useState<Error>()\n const [state, setState] = useState<State>(State.pending)\n const mutex = useMemo(() => {\n return new Mutex()\n }, [])\n\n if (debug) console.log(`usePromise [${debug}]: started [${typeof promise}]`)\n\n const promiseMemo: Promise<TResult | undefined> | undefined = useMemo(() => {\n try {\n if (debug) console.log(`usePromise [${debug}]: re-memo [${typeof promise}]`)\n setState(State.pending)\n return promise?.()\n } catch (e) {\n if (debug) console.log(`usePromise [${debug}]: useMemo rejection [${typeof promise}]`)\n setResult(undefined)\n setError(e as Error)\n setState(State.rejected)\n }\n }, dependencies)\n\n if (debug) console.log(`usePromise [${debug}] Main Function`)\n\n useEffect(() => {\n if (debug) console.log(`usePromise [${debug}] useEffect`)\n mutex\n ?.acquire()\n .then(() => {\n promiseMemo\n ?.then((payload) => {\n if (debug) console.log(`usePromise [${debug}] then`)\n setResult(payload)\n setError(undefined)\n setState(State.resolved)\n mutex?.release()\n })\n .catch((e) => {\n const error = e as Error\n console.error(`usePromise: ${error.message}`)\n setResult(undefined)\n setError(error)\n setState(State.rejected)\n mutex?.release()\n })\n })\n .catch((e) => {\n const error = e as Error\n console.error(`usePromise: ${error.message}`)\n setResult(undefined)\n setError(error)\n setState(State.rejected)\n mutex?.release()\n })\n return () => {\n if (debug) console.log(`usePromise [${debug}] useEffect callback`)\n }\n }, [...dependencies, promiseMemo])\n if (debug) console.log(`usePromise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AAO,QAAQ;AAAA,MACjB,CAAC,EACA,MAAM,CAAC,MAAM;AACZ,cAAMC,SAAQ;AACd,gBAAQ,MAAM,eAAeA,OAAM,OAAO,EAAE;AAC5C,kBAAU,MAAS;AACnB,iBAASA,MAAK;AACd,iBAAS,yBAAc;AACvB,eAAO,QAAQ;AAAA,MACjB,CAAC;AAAA,IACL,CAAC,EACA,MAAM,CAAC,MAAM;AACZ,YAAMA,SAAQ;AACd,cAAQ,MAAM,eAAeA,OAAM,OAAO,EAAE;AAC5C,gBAAU,MAAS;AACnB,eAASA,MAAK;AACd,eAAS,yBAAc;AACvB,aAAO,QAAQ;AAAA,IACjB,CAAC;AACH,WAAO,MAAM;AACX,UAAI;AAAO,gBAAQ,IAAI,eAAe,KAAK,sBAAsB;AAAA,IACnE;AAAA,EACF,GAAG,CAAC,GAAG,cAAc,WAAW,CAAC;AACjC,MAAI;AAAO,YAAQ,IAAI,eAAe,KAAK,eAAe,KAAK,UAAU,CAAC,QAAQ,OAAO,KAAK,GAAG,MAAM,CAAC,CAAC,EAAE;AAC3G,SAAO,CAAC,QAAQ,OAAO,KAAK;AAC9B;","names":["State","error"]}
1
+ {"version":3,"sources":["../../../../src/contexts/Wallet/usePromise.ts"],"sourcesContent":["// Inspired from https://github.com/bsonntag/react-use-promise\n\nimport { Mutex } from 'async-mutex'\nimport { DependencyList, useEffect, useMemo, useState } from 'react'\n\nexport enum State {\n pending = 'pending',\n rejected = 'rejected',\n resolved = 'resolved',\n}\n\n/**\n * usePromise -\n */\nexport const usePromise = <TResult>(\n promise: () => Promise<TResult | undefined>,\n dependencies: DependencyList,\n debug: string | undefined = undefined,\n): [TResult | undefined, Error | undefined, State | undefined] => {\n const [result, setResult] = useState<TResult>()\n const [error, setError] = useState<Error>()\n const [state, setState] = useState<State>(State.pending)\n const mutex = useMemo(() => {\n return new Mutex()\n }, [])\n\n if (debug) console.log(`usePromise [${debug}]: started [${typeof promise}]`)\n\n const promiseMemo: Promise<TResult | undefined> | undefined = useMemo(() => {\n try {\n if (debug) console.log(`usePromise [${debug}]: re-memo [${typeof promise}]`)\n setState(State.pending)\n return promise?.()\n } catch (e) {\n if (debug) console.log(`usePromise [${debug}]: useMemo rejection [${typeof promise}]`)\n setResult(undefined)\n setError(e as Error)\n setState(State.rejected)\n }\n }, dependencies)\n\n if (debug) console.log(`usePromise [${debug}] Main Function`)\n\n useEffect(() => {\n if (debug) console.log(`usePromise [${debug}] useEffect`)\n mutex\n ?.acquire()\n .then(() => {\n promiseMemo\n ?.then((payload) => {\n if (debug) console.log(`usePromise [${debug}] then`)\n setResult(payload)\n setError(undefined)\n setState(State.resolved)\n mutex?.release()\n })\n .catch((e) => {\n const error = e as Error\n console.error(`usePromise: ${error.message}`)\n setResult(undefined)\n setError(error)\n setState(State.rejected)\n mutex?.release()\n })\n })\n .catch((e) => {\n const error = e as Error\n console.error(`usePromise: ${error.message}`)\n setResult(undefined)\n setError(error)\n setState(State.rejected)\n mutex?.release()\n })\n return () => {\n if (debug) console.log(`usePromise [${debug}] useEffect callback`)\n }\n }, [...dependencies, promiseMemo])\n if (debug) console.log(`usePromise [${debug}] returning ${JSON.stringify([result, error, state], null, 2)}`)\n return [result, error, state]\n}\n"],"mappings":";AAEA,SAAS,aAAa;AACtB,SAAyB,WAAW,SAAS,gBAAgB;AAEtD,IAAK,QAAL,kBAAKA,WAAL;AACL,EAAAA,OAAA,aAAU;AACV,EAAAA,OAAA,cAAW;AACX,EAAAA,OAAA,cAAW;AAHD,SAAAA;AAAA,GAAA;AASL,IAAM,aAAa,CACxB,SACA,cACA,QAA4B,WACoC;AAChE,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAkB;AAC9C,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAgB;AAC1C,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAgB,uBAAa;AACvD,QAAM,QAAQ,QAAQ,MAAM;AAC1B,WAAO,IAAI,MAAM;AAAA,EACnB,GAAG,CAAC,CAAC;AAEL,MAAI;AAAO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C,MAAI;AAAO,YAAQ,IAAI,eAAe,KAAK,eAAe,KAAK,UAAU,CAAC,QAAQ,OAAO,KAAK,GAAG,MAAM,CAAC,CAAC,EAAE;AAC3G,SAAO,CAAC,QAAQ,OAAO,KAAK;AAC9B;","names":["State","error"]}
@@ -1,3 +1,274 @@
1
- export * from "./SeedPhrase";
2
- export * from "./Wallet";
1
+ // src/contexts/SeedPhrase/Context.ts
2
+ import { createContextEx } from "@xyo-network/react-shared";
3
+ var SeedPhraseContext = createContextEx();
4
+
5
+ // src/contexts/SeedPhrase/Provider.tsx
6
+ import { generateMnemonic, validateMnemonic, wordlists } from "@xyo-network/bip39";
7
+ import { useEffect, useMemo, useState } from "react";
8
+ import { jsx } from "react/jsx-runtime";
9
+ var SeedPhraseProvider = ({
10
+ children,
11
+ defaultPhrase,
12
+ handleChangeSeedPhrase,
13
+ saveCallback,
14
+ seedPhrase,
15
+ open
16
+ }) => {
17
+ const [phrase, setPhrase] = useState();
18
+ const [overwriteWarning, setOverwriteWarning] = useState(false);
19
+ useEffect(() => {
20
+ setPhrase(defaultPhrase);
21
+ }, [defaultPhrase]);
22
+ useEffect(() => {
23
+ if (!open) {
24
+ handleCancelOverwrite();
25
+ }
26
+ }, [open]);
27
+ useEffect(() => {
28
+ if (seedPhrase || open) {
29
+ setPhrase?.(seedPhrase ?? "");
30
+ }
31
+ }, [seedPhrase, open, setPhrase]);
32
+ const handleGenerate = () => {
33
+ const mnemonic = generateMnemonic(wordlists.english, 256);
34
+ setPhrase?.(mnemonic);
35
+ setOverwriteWarning?.(false);
36
+ };
37
+ const handleCancelOverwrite = () => {
38
+ setOverwriteWarning?.(false);
39
+ };
40
+ const handleClear = () => {
41
+ setPhrase?.("");
42
+ setOverwriteWarning?.(false);
43
+ };
44
+ const handleSave = () => {
45
+ if (!overwriteWarning && seedPhrase && seedPhrase !== phrase) {
46
+ setOverwriteWarning?.(true);
47
+ } else {
48
+ handleChangeSeedPhrase?.(phrase ?? "");
49
+ saveCallback?.();
50
+ }
51
+ };
52
+ const validate = (passedPhrase) => {
53
+ if (!passedPhrase) {
54
+ return null;
55
+ }
56
+ return validateMnemonic(passedPhrase, wordlists.english);
57
+ };
58
+ const validSeedPhrase = useMemo(() => validate?.(seedPhrase), [seedPhrase]);
59
+ const validPhrase = useMemo(() => validate?.(phrase), [phrase]);
60
+ return /* @__PURE__ */ jsx(
61
+ SeedPhraseContext.Provider,
62
+ {
63
+ value: {
64
+ handleCancelOverwrite,
65
+ handleChangeSeedPhrase,
66
+ handleClear,
67
+ handleGenerate,
68
+ handleSave,
69
+ overwriteWarning,
70
+ phrase,
71
+ provided: true,
72
+ seedPhrase,
73
+ setOverwriteWarning,
74
+ setPhrase,
75
+ validPhrase,
76
+ validSeedPhrase,
77
+ validate
78
+ },
79
+ children
80
+ }
81
+ );
82
+ };
83
+
84
+ // src/contexts/SeedPhrase/use.tsx
85
+ import { useContextEx } from "@xyo-network/react-shared";
86
+ var useSeedPhrase = () => useContextEx(SeedPhraseContext, "SeedPhrase", true);
87
+
88
+ // src/contexts/Wallet/Context.ts
89
+ import { createContextEx as createContextEx2 } from "@xyo-network/react-shared";
90
+ var WalletContext = createContextEx2();
91
+
92
+ // src/contexts/Wallet/lib/WalletPath.ts
93
+ var Bip44 = {
94
+ base: "m",
95
+ coin_type: {
96
+ /* https://github.com/satoshilabs/slips/blob/master/slip-0044.md */
97
+ bitcoin: "0'",
98
+ bitcoinTestnet: "1'",
99
+ ether: "60'",
100
+ etherClassic: "61'"
101
+ },
102
+ purpose: "44'"
103
+ };
104
+ var WalletRootPath = `${Bip44.base}/${Bip44.purpose}/${Bip44.coin_type.ether}`;
105
+ var ethereumAccountPath = (index, hardened = true) => {
106
+ return `${WalletRootPath}/${index}${hardened ? "'" : ""}/0`;
107
+ };
108
+
109
+ // src/contexts/Wallet/Provider.tsx
110
+ import { useEffect as useEffect3, useState as useState3 } from "react";
111
+
112
+ // src/contexts/Wallet/usePromise.ts
113
+ import { Mutex } from "async-mutex";
114
+ import { useEffect as useEffect2, useMemo as useMemo2, useState as useState2 } from "react";
115
+ var usePromise = (promise, dependencies, debug = void 0) => {
116
+ const [result, setResult] = useState2();
117
+ const [error, setError] = useState2();
118
+ const [state, setState] = useState2("pending" /* pending */);
119
+ const mutex = useMemo2(() => {
120
+ return new Mutex();
121
+ }, []);
122
+ if (debug)
123
+ console.log(`usePromise [${debug}]: started [${typeof promise}]`);
124
+ const promiseMemo = useMemo2(() => {
125
+ try {
126
+ if (debug)
127
+ console.log(`usePromise [${debug}]: re-memo [${typeof promise}]`);
128
+ setState("pending" /* pending */);
129
+ return promise?.();
130
+ } catch (e) {
131
+ if (debug)
132
+ console.log(`usePromise [${debug}]: useMemo rejection [${typeof promise}]`);
133
+ setResult(void 0);
134
+ setError(e);
135
+ setState("rejected" /* rejected */);
136
+ }
137
+ }, dependencies);
138
+ if (debug)
139
+ console.log(`usePromise [${debug}] Main Function`);
140
+ useEffect2(() => {
141
+ if (debug)
142
+ console.log(`usePromise [${debug}] useEffect`);
143
+ mutex?.acquire().then(() => {
144
+ promiseMemo?.then((payload) => {
145
+ if (debug)
146
+ console.log(`usePromise [${debug}] then`);
147
+ setResult(payload);
148
+ setError(void 0);
149
+ setState("resolved" /* resolved */);
150
+ mutex?.release();
151
+ }).catch((e) => {
152
+ const error2 = e;
153
+ console.error(`usePromise: ${error2.message}`);
154
+ setResult(void 0);
155
+ setError(error2);
156
+ setState("rejected" /* rejected */);
157
+ mutex?.release();
158
+ });
159
+ }).catch((e) => {
160
+ const error2 = e;
161
+ console.error(`usePromise: ${error2.message}`);
162
+ setResult(void 0);
163
+ setError(error2);
164
+ setState("rejected" /* rejected */);
165
+ mutex?.release();
166
+ });
167
+ return () => {
168
+ if (debug)
169
+ console.log(`usePromise [${debug}] useEffect callback`);
170
+ };
171
+ }, [...dependencies, promiseMemo]);
172
+ if (debug)
173
+ console.log(`usePromise [${debug}] returning ${JSON.stringify([result, error, state], null, 2)}`);
174
+ return [result, error, state];
175
+ };
176
+
177
+ // src/contexts/Wallet/Provider.tsx
178
+ import { jsx as jsx2 } from "react/jsx-runtime";
179
+ var WalletProvider = ({
180
+ basePath = WalletRootPath,
181
+ children,
182
+ defaultActiveAccountIndex = 0,
183
+ rootWallet = null,
184
+ ...props
185
+ }) => {
186
+ const [activeAccountIndex, setActiveAccountIndex] = useState3(defaultActiveAccountIndex);
187
+ useEffect3(() => {
188
+ if (defaultActiveAccountIndex !== void 0) {
189
+ setActiveAccountIndex(defaultActiveAccountIndex);
190
+ }
191
+ }, [defaultActiveAccountIndex]);
192
+ const [coinTypeWallet = null] = usePromise(async () => {
193
+ if (rootWallet) {
194
+ if (!rootWallet?.path.includes(basePath)) {
195
+ try {
196
+ return await rootWallet?.derivePath(basePath);
197
+ } catch (e) {
198
+ console.error("Error setting proper wallet base path", e);
199
+ }
200
+ }
201
+ } else {
202
+ return void 0;
203
+ }
204
+ }, [basePath, rootWallet]);
205
+ const [activeAccount = null] = usePromise(
206
+ async () => await coinTypeWallet?.derivePath(activeAccountIndex.toString()),
207
+ [coinTypeWallet, activeAccountIndex]
208
+ );
209
+ return /* @__PURE__ */ jsx2(
210
+ WalletContext.Provider,
211
+ {
212
+ value: {
213
+ activeAccount,
214
+ activeAccountIndex,
215
+ basePath,
216
+ coinTypeWallet,
217
+ provided: true,
218
+ rootWallet,
219
+ setActiveAccountIndex
220
+ },
221
+ ...props,
222
+ children
223
+ }
224
+ );
225
+ };
226
+
227
+ // src/contexts/Wallet/use.ts
228
+ import { usePromise as usePromise2 } from "@xylabs/react-promise";
229
+ import { useContextEx as useContextEx2, useProvided } from "@xyo-network/react-shared";
230
+ var useWalletContext = (required = true) => {
231
+ return useContextEx2(WalletContext, "Wallet", required);
232
+ };
233
+ var useWalletProvided = () => {
234
+ return useProvided(WalletContext);
235
+ };
236
+ var useCoinTypeWallet = (required = true) => {
237
+ const { coinTypeWallet } = useWalletContext(required);
238
+ return [coinTypeWallet, void 0];
239
+ };
240
+ var useRootWallet = (required = true) => {
241
+ const { rootWallet } = useWalletContext(required);
242
+ return [rootWallet, void 0];
243
+ };
244
+ var useIndexedWalletFromContext = (index, required = true) => {
245
+ const [coinTypeWallet] = useCoinTypeWallet(required);
246
+ const [wallet] = usePromise2(async () => await coinTypeWallet?.derivePath(index.toString()) ?? coinTypeWallet, [coinTypeWallet, index]);
247
+ return [wallet, void 0];
248
+ };
249
+ var useSelectedWalletAccount = (required = true) => {
250
+ const { activeAccountIndex } = useWalletContext(required);
251
+ const [account] = useIndexedWalletFromContext(activeAccountIndex ?? 0, required);
252
+ if (activeAccountIndex === void 0 && account === null) {
253
+ return [null, void 0];
254
+ } else {
255
+ return [account, void 0];
256
+ }
257
+ };
258
+ export {
259
+ Bip44,
260
+ SeedPhraseContext,
261
+ SeedPhraseProvider,
262
+ WalletContext,
263
+ WalletProvider,
264
+ WalletRootPath,
265
+ ethereumAccountPath,
266
+ useCoinTypeWallet,
267
+ useIndexedWalletFromContext,
268
+ useRootWallet,
269
+ useSeedPhrase,
270
+ useSelectedWalletAccount,
271
+ useWalletContext,
272
+ useWalletProvided
273
+ };
3
274
  //# sourceMappingURL=index.js.map