@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.
- package/dist/browser/components/MaxAccounts/MaxAccountsTableRow.js +41 -11
- package/dist/browser/components/MaxAccounts/MaxAccountsTableRow.js.map +1 -1
- package/dist/browser/components/MaxAccounts/OutOfBoundsSnackBar.js +3 -2
- package/dist/browser/components/MaxAccounts/OutOfBoundsSnackBar.js.map +1 -1
- package/dist/browser/components/MaxAccounts/index.js +88 -1
- package/dist/browser/components/MaxAccounts/index.js.map +1 -1
- package/dist/browser/components/SeedPhrase/DefaultSeedPhrase.js +3 -2
- package/dist/browser/components/SeedPhrase/DefaultSeedPhrase.js.map +1 -1
- package/dist/browser/components/SeedPhrase/_shared/SeedPhraseIconButton.js +3 -2
- package/dist/browser/components/SeedPhrase/_shared/SeedPhraseIconButton.js.map +1 -1
- package/dist/browser/components/SeedPhrase/_shared/index.js +45 -1
- package/dist/browser/components/SeedPhrase/_shared/index.js.map +1 -1
- package/dist/browser/components/SeedPhrase/dialog/SeedPhraseDialog.js +295 -16
- package/dist/browser/components/SeedPhrase/dialog/SeedPhraseDialog.js.map +1 -1
- package/dist/browser/components/SeedPhrase/dialog/components/DialogActionButtons.js +13 -3
- package/dist/browser/components/SeedPhrase/dialog/components/DialogActionButtons.js.map +1 -1
- package/dist/browser/components/SeedPhrase/dialog/components/OverwriteWarning.js +13 -3
- package/dist/browser/components/SeedPhrase/dialog/components/OverwriteWarning.js.map +1 -1
- package/dist/browser/components/SeedPhrase/dialog/components/fields/NewPhraseTextField.js +74 -12
- package/dist/browser/components/SeedPhrase/dialog/components/fields/NewPhraseTextField.js.map +1 -1
- package/dist/browser/components/SeedPhrase/dialog/components/fields/SavedPhraseTextField.js +60 -10
- package/dist/browser/components/SeedPhrase/dialog/components/fields/SavedPhraseTextField.js.map +1 -1
- package/dist/browser/components/SeedPhrase/dialog/components/fields/index.js +125 -2
- package/dist/browser/components/SeedPhrase/dialog/components/fields/index.js.map +1 -1
- package/dist/browser/components/SeedPhrase/dialog/components/fields/validation-messages/InvalidPhrase.js +3 -2
- package/dist/browser/components/SeedPhrase/dialog/components/fields/validation-messages/InvalidPhrase.js.map +1 -1
- package/dist/browser/components/SeedPhrase/dialog/components/fields/validation-messages/PhraseHeaderBox.js +3 -2
- package/dist/browser/components/SeedPhrase/dialog/components/fields/validation-messages/PhraseHeaderBox.js.map +1 -1
- package/dist/browser/components/SeedPhrase/dialog/components/fields/validation-messages/colorParser.js +2 -1
- package/dist/browser/components/SeedPhrase/dialog/components/fields/validation-messages/colorParser.js.map +1 -1
- package/dist/browser/components/SeedPhrase/dialog/components/fields/validation-messages/index.js +57 -3
- package/dist/browser/components/SeedPhrase/dialog/components/fields/validation-messages/index.js.map +1 -1
- package/dist/browser/components/SeedPhrase/dialog/components/index.js +164 -3
- package/dist/browser/components/SeedPhrase/dialog/components/index.js.map +1 -1
- package/dist/browser/components/SeedPhrase/dialog/index.js +315 -1
- package/dist/browser/components/SeedPhrase/dialog/index.js.map +1 -1
- package/dist/browser/components/SeedPhrase/index.js +373 -4
- package/dist/browser/components/SeedPhrase/index.js.map +1 -1
- package/dist/browser/components/SeedPhrase/settings/SeedPhraseTableRow.js +325 -12
- package/dist/browser/components/SeedPhrase/settings/SeedPhraseTableRow.js.map +1 -1
- package/dist/browser/components/SeedPhrase/settings/index.js +339 -1
- package/dist/browser/components/SeedPhrase/settings/index.js.map +1 -1
- package/dist/browser/components/WalletAccountDetails/WalletAccountDetails.js +62 -3
- package/dist/browser/components/WalletAccountDetails/WalletAccountDetails.js.map +1 -1
- package/dist/browser/components/WalletAccountDetails/index.js +83 -1
- package/dist/browser/components/WalletAccountDetails/index.js.map +1 -1
- package/dist/browser/components/WalletAccountSelect/Select.js +70 -5
- package/dist/browser/components/WalletAccountSelect/Select.js.map +1 -1
- package/dist/browser/components/WalletAccountSelect/SelectBar.js +150 -4
- package/dist/browser/components/WalletAccountSelect/SelectBar.js.map +1 -1
- package/dist/browser/components/WalletAccountSelect/WalletInfo.js +116 -10
- package/dist/browser/components/WalletAccountSelect/WalletInfo.js.map +1 -1
- package/dist/browser/components/WalletAccountSelect/index.js +175 -2
- package/dist/browser/components/WalletAccountSelect/index.js.map +1 -1
- package/dist/browser/components/index.js +694 -4
- package/dist/browser/components/index.js.map +1 -1
- package/dist/browser/contexts/SeedPhrase/Context.js +2 -1
- package/dist/browser/contexts/SeedPhrase/Context.js.map +1 -1
- package/dist/browser/contexts/SeedPhrase/Provider.js +9 -3
- package/dist/browser/contexts/SeedPhrase/Provider.js.map +1 -1
- package/dist/browser/contexts/SeedPhrase/index.js +91 -4
- package/dist/browser/contexts/SeedPhrase/index.js.map +1 -1
- package/dist/browser/contexts/SeedPhrase/use.js +8 -2
- package/dist/browser/contexts/SeedPhrase/use.js.map +1 -1
- package/dist/browser/contexts/Wallet/Context.js +2 -1
- package/dist/browser/contexts/Wallet/Context.js.map +1 -1
- package/dist/browser/contexts/Wallet/Provider.js +90 -7
- package/dist/browser/contexts/Wallet/Provider.js.map +1 -1
- package/dist/browser/contexts/Wallet/index.js +183 -5
- package/dist/browser/contexts/Wallet/index.js.map +1 -1
- package/dist/browser/contexts/Wallet/lib/WalletPath.js +4 -3
- package/dist/browser/contexts/Wallet/lib/WalletPath.js.map +1 -1
- package/dist/browser/contexts/Wallet/lib/index.js +21 -1
- package/dist/browser/contexts/Wallet/lib/index.js.map +1 -1
- package/dist/browser/contexts/Wallet/use.js +13 -7
- package/dist/browser/contexts/Wallet/use.js.map +1 -1
- package/dist/browser/contexts/Wallet/usePromise.js +2 -1
- package/dist/browser/contexts/Wallet/usePromise.js.map +1 -1
- package/dist/browser/contexts/index.js +273 -2
- package/dist/browser/contexts/index.js.map +1 -1
- package/dist/browser/hooks/index.js +147 -4
- package/dist/browser/hooks/index.js.map +1 -1
- package/dist/browser/hooks/useAccount.js +24 -4
- package/dist/browser/hooks/useAccount.js.map +1 -1
- package/dist/browser/hooks/useWallet.js +38 -4
- package/dist/browser/hooks/useWallet.js.map +1 -1
- package/dist/browser/hooks/useWallets.js +69 -4
- package/dist/browser/hooks/useWallets.js.map +1 -1
- package/dist/browser/hooks/useWrapperAccount.js +4 -3
- package/dist/browser/hooks/useWrapperAccount.js.map +1 -1
- package/dist/browser/index.js +890 -3
- package/dist/browser/index.js.map +1 -1
- package/dist/docs.json +147 -147
- package/package.json +22 -22
package/dist/browser/index.js
CHANGED
|
@@ -1,4 +1,891 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
// src/components/MaxAccounts/MaxAccountsTableRow.tsx
|
|
2
|
+
import { ButtonGroup, TableCell, TableRow, Typography } from "@mui/material";
|
|
3
|
+
import { ButtonEx } from "@xylabs/react-button";
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
|
|
6
|
+
// src/components/MaxAccounts/OutOfBoundsSnackBar.tsx
|
|
7
|
+
import { Alert, AlertTitle, Snackbar } from "@mui/material";
|
|
8
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
var OutOfBoundsSnackBar = ({
|
|
10
|
+
activeAccountIndex,
|
|
11
|
+
desiredMaximumAccounts,
|
|
12
|
+
setShowSnackBar,
|
|
13
|
+
showSnackBar
|
|
14
|
+
}) => {
|
|
15
|
+
return /* @__PURE__ */ jsx(
|
|
16
|
+
Snackbar,
|
|
17
|
+
{
|
|
18
|
+
anchorOrigin: { horizontal: "center", vertical: "top" },
|
|
19
|
+
autoHideDuration: 5e3,
|
|
20
|
+
onClose: () => setShowSnackBar?.(false),
|
|
21
|
+
open: showSnackBar,
|
|
22
|
+
children: /* @__PURE__ */ jsxs(Alert, { severity: "error", onClose: () => setShowSnackBar?.(false), children: [
|
|
23
|
+
/* @__PURE__ */ jsx(AlertTitle, { children: "Maximum Accounts Error" }),
|
|
24
|
+
"Your currently selected account number (",
|
|
25
|
+
activeAccountIndex !== void 0 ? activeAccountIndex + 1 : "",
|
|
26
|
+
") cannot be greater than the desired Maximum Accounts (",
|
|
27
|
+
desiredMaximumAccounts,
|
|
28
|
+
")."
|
|
29
|
+
] })
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// src/components/MaxAccounts/MaxAccountsTableRow.tsx
|
|
35
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
36
|
+
var MaxAccountsTableRow = ({ activeAccountIndex, changeMaxAccounts, maxAccounts }) => {
|
|
37
|
+
const [desiredMaximumAccounts, setDesiredMaximumAccounts] = useState();
|
|
38
|
+
const [showSnackBar, setShowSnackBar] = useState(false);
|
|
39
|
+
const handleChangeMaxAccounts = (change) => {
|
|
40
|
+
if (maxAccounts !== void 0 && activeAccountIndex !== void 0) {
|
|
41
|
+
switch (change) {
|
|
42
|
+
case "decrease": {
|
|
43
|
+
const desiredMaximumAccounts2 = maxAccounts - 1;
|
|
44
|
+
const validMaximumAccounts = desiredMaximumAccounts2 > 0;
|
|
45
|
+
const maxAccountsWithinRange = activeAccountIndex + 1 <= desiredMaximumAccounts2;
|
|
46
|
+
if (validMaximumAccounts && maxAccountsWithinRange) {
|
|
47
|
+
changeMaxAccounts?.(desiredMaximumAccounts2);
|
|
48
|
+
}
|
|
49
|
+
if (!maxAccountsWithinRange)
|
|
50
|
+
setShowSnackBar(true);
|
|
51
|
+
setDesiredMaximumAccounts(desiredMaximumAccounts2);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
case "increase": {
|
|
55
|
+
changeMaxAccounts?.(maxAccounts + 1);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
default: {
|
|
59
|
+
console.error(change, "is not a recognized value");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
} else {
|
|
63
|
+
throw new Error("Max Accounts is unset and needs a default");
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
return /* @__PURE__ */ jsxs2(TableRow, { children: [
|
|
67
|
+
/* @__PURE__ */ jsx2(TableCell, { children: "Maximum Accounts" }),
|
|
68
|
+
/* @__PURE__ */ jsx2(TableCell, { align: "center", children: /* @__PURE__ */ jsx2(Typography, { variant: "caption", children: maxAccounts }) }),
|
|
69
|
+
/* @__PURE__ */ jsxs2(TableCell, { align: "center", children: [
|
|
70
|
+
/* @__PURE__ */ jsxs2(ButtonGroup, { children: [
|
|
71
|
+
/* @__PURE__ */ jsx2(ButtonEx, { onClick: () => handleChangeMaxAccounts("decrease"), variant: "contained", size: "small", children: "-" }),
|
|
72
|
+
/* @__PURE__ */ jsx2(ButtonEx, { onClick: () => handleChangeMaxAccounts("increase"), variant: "contained", size: "small", children: "+" })
|
|
73
|
+
] }),
|
|
74
|
+
/* @__PURE__ */ jsx2(
|
|
75
|
+
OutOfBoundsSnackBar,
|
|
76
|
+
{
|
|
77
|
+
desiredMaximumAccounts,
|
|
78
|
+
activeAccountIndex,
|
|
79
|
+
setShowSnackBar,
|
|
80
|
+
showSnackBar
|
|
81
|
+
}
|
|
82
|
+
)
|
|
83
|
+
] })
|
|
84
|
+
] });
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// src/components/SeedPhrase/_shared/SeedPhraseIconButton.tsx
|
|
88
|
+
import { HelpOutline as HelpOutlineIcon } from "@mui/icons-material";
|
|
89
|
+
import {
|
|
90
|
+
Button,
|
|
91
|
+
Dialog,
|
|
92
|
+
DialogActions,
|
|
93
|
+
DialogContent,
|
|
94
|
+
DialogTitle,
|
|
95
|
+
IconButton,
|
|
96
|
+
Link,
|
|
97
|
+
List,
|
|
98
|
+
ListItem,
|
|
99
|
+
Typography as Typography2
|
|
100
|
+
} from "@mui/material";
|
|
101
|
+
import { useState as useState2 } from "react";
|
|
102
|
+
import { Fragment, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
103
|
+
var SeedPhraseIconButton = (props) => {
|
|
104
|
+
const [open, setOpen] = useState2(false);
|
|
105
|
+
const onClose = () => setOpen(false);
|
|
106
|
+
return /* @__PURE__ */ jsxs3(Fragment, { children: [
|
|
107
|
+
/* @__PURE__ */ jsx3(IconButton, { onClick: () => setOpen(true), ...props, children: /* @__PURE__ */ jsx3(HelpOutlineIcon, { fontSize: "small" }) }),
|
|
108
|
+
/* @__PURE__ */ jsxs3(Dialog, { open, children: [
|
|
109
|
+
/* @__PURE__ */ jsx3(DialogTitle, { children: "Understanding your Seed Phrase" }),
|
|
110
|
+
/* @__PURE__ */ jsxs3(DialogContent, { children: [
|
|
111
|
+
/* @__PURE__ */ jsxs3(Typography2, { children: [
|
|
112
|
+
"Your Seed Phrase should adhere to the",
|
|
113
|
+
" ",
|
|
114
|
+
/* @__PURE__ */ jsx3(Link, { target: "_blank", href: "https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki", children: "bip39 specification" }),
|
|
115
|
+
" ",
|
|
116
|
+
"and is used to generate accounts which identify your data on the XYO Network."
|
|
117
|
+
] }),
|
|
118
|
+
/* @__PURE__ */ jsxs3(List, { children: [
|
|
119
|
+
/* @__PURE__ */ jsx3(ListItem, { children: "Do not share this phrase with anyone." }),
|
|
120
|
+
/* @__PURE__ */ jsx3(ListItem, { children: "Do not save it to a public computer." }),
|
|
121
|
+
/* @__PURE__ */ jsx3(ListItem, { children: "Do not use a existing phrase from another wallet (i.e. Metamask)." }),
|
|
122
|
+
/* @__PURE__ */ jsx3(ListItem, { children: "Do not use before copying it down somewhere safe." })
|
|
123
|
+
] })
|
|
124
|
+
] }),
|
|
125
|
+
/* @__PURE__ */ jsx3(DialogActions, { children: /* @__PURE__ */ jsx3(Button, { onClick: onClose, variant: "outlined", children: "OK" }) })
|
|
126
|
+
] })
|
|
127
|
+
] });
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// src/components/SeedPhrase/DefaultSeedPhrase.tsx
|
|
131
|
+
import { Alert as Alert2, AlertTitle as AlertTitle2, Snackbar as Snackbar2 } from "@mui/material";
|
|
132
|
+
import { generateMnemonic, wordlists } from "@xyo-network/bip39";
|
|
133
|
+
import { useEffect, useState as useState3 } from "react";
|
|
134
|
+
import { Fragment as Fragment2, jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
135
|
+
var DefaultSeedPhrase = ({ changeSeedPhrase, children, hideDefaultSeedPhraseMessage, seedPhrase }) => {
|
|
136
|
+
const [showSnackBar, setShowSnackBar] = useState3(false);
|
|
137
|
+
useEffect(() => {
|
|
138
|
+
if (!seedPhrase) {
|
|
139
|
+
const mnemonic = generateMnemonic(wordlists.english, 256);
|
|
140
|
+
changeSeedPhrase?.(mnemonic);
|
|
141
|
+
setShowSnackBar(true);
|
|
142
|
+
}
|
|
143
|
+
}, [changeSeedPhrase, seedPhrase]);
|
|
144
|
+
return /* @__PURE__ */ jsxs4(Fragment2, { children: [
|
|
145
|
+
hideDefaultSeedPhraseMessage ? null : /* @__PURE__ */ jsx4(
|
|
146
|
+
Snackbar2,
|
|
147
|
+
{
|
|
148
|
+
open: showSnackBar,
|
|
149
|
+
autoHideDuration: 5e3,
|
|
150
|
+
onClose: () => setShowSnackBar(false),
|
|
151
|
+
anchorOrigin: { horizontal: "center", vertical: "top" },
|
|
152
|
+
children: /* @__PURE__ */ jsxs4(Alert2, { severity: "success", children: [
|
|
153
|
+
/* @__PURE__ */ jsx4(AlertTitle2, { children: "Default Seed Phrase Generated" }),
|
|
154
|
+
"Go to application settings to save it."
|
|
155
|
+
] })
|
|
156
|
+
}
|
|
157
|
+
),
|
|
158
|
+
children
|
|
159
|
+
] });
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
// src/components/SeedPhrase/dialog/SeedPhraseDialog.tsx
|
|
163
|
+
import { Dialog as Dialog2, DialogContent as DialogContent2, DialogTitle as DialogTitle2 } from "@mui/material";
|
|
164
|
+
|
|
165
|
+
// src/contexts/SeedPhrase/Context.ts
|
|
166
|
+
import { createContextEx } from "@xyo-network/react-shared";
|
|
167
|
+
var SeedPhraseContext = createContextEx();
|
|
168
|
+
|
|
169
|
+
// src/contexts/SeedPhrase/Provider.tsx
|
|
170
|
+
import { generateMnemonic as generateMnemonic2, validateMnemonic, wordlists as wordlists2 } from "@xyo-network/bip39";
|
|
171
|
+
import { useEffect as useEffect2, useMemo, useState as useState4 } from "react";
|
|
172
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
173
|
+
var SeedPhraseProvider = ({
|
|
174
|
+
children,
|
|
175
|
+
defaultPhrase,
|
|
176
|
+
handleChangeSeedPhrase,
|
|
177
|
+
saveCallback,
|
|
178
|
+
seedPhrase,
|
|
179
|
+
open
|
|
180
|
+
}) => {
|
|
181
|
+
const [phrase, setPhrase] = useState4();
|
|
182
|
+
const [overwriteWarning, setOverwriteWarning] = useState4(false);
|
|
183
|
+
useEffect2(() => {
|
|
184
|
+
setPhrase(defaultPhrase);
|
|
185
|
+
}, [defaultPhrase]);
|
|
186
|
+
useEffect2(() => {
|
|
187
|
+
if (!open) {
|
|
188
|
+
handleCancelOverwrite();
|
|
189
|
+
}
|
|
190
|
+
}, [open]);
|
|
191
|
+
useEffect2(() => {
|
|
192
|
+
if (seedPhrase || open) {
|
|
193
|
+
setPhrase?.(seedPhrase ?? "");
|
|
194
|
+
}
|
|
195
|
+
}, [seedPhrase, open, setPhrase]);
|
|
196
|
+
const handleGenerate = () => {
|
|
197
|
+
const mnemonic = generateMnemonic2(wordlists2.english, 256);
|
|
198
|
+
setPhrase?.(mnemonic);
|
|
199
|
+
setOverwriteWarning?.(false);
|
|
200
|
+
};
|
|
201
|
+
const handleCancelOverwrite = () => {
|
|
202
|
+
setOverwriteWarning?.(false);
|
|
203
|
+
};
|
|
204
|
+
const handleClear = () => {
|
|
205
|
+
setPhrase?.("");
|
|
206
|
+
setOverwriteWarning?.(false);
|
|
207
|
+
};
|
|
208
|
+
const handleSave = () => {
|
|
209
|
+
if (!overwriteWarning && seedPhrase && seedPhrase !== phrase) {
|
|
210
|
+
setOverwriteWarning?.(true);
|
|
211
|
+
} else {
|
|
212
|
+
handleChangeSeedPhrase?.(phrase ?? "");
|
|
213
|
+
saveCallback?.();
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
const validate = (passedPhrase) => {
|
|
217
|
+
if (!passedPhrase) {
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
return validateMnemonic(passedPhrase, wordlists2.english);
|
|
221
|
+
};
|
|
222
|
+
const validSeedPhrase = useMemo(() => validate?.(seedPhrase), [seedPhrase]);
|
|
223
|
+
const validPhrase = useMemo(() => validate?.(phrase), [phrase]);
|
|
224
|
+
return /* @__PURE__ */ jsx5(
|
|
225
|
+
SeedPhraseContext.Provider,
|
|
226
|
+
{
|
|
227
|
+
value: {
|
|
228
|
+
handleCancelOverwrite,
|
|
229
|
+
handleChangeSeedPhrase,
|
|
230
|
+
handleClear,
|
|
231
|
+
handleGenerate,
|
|
232
|
+
handleSave,
|
|
233
|
+
overwriteWarning,
|
|
234
|
+
phrase,
|
|
235
|
+
provided: true,
|
|
236
|
+
seedPhrase,
|
|
237
|
+
setOverwriteWarning,
|
|
238
|
+
setPhrase,
|
|
239
|
+
validPhrase,
|
|
240
|
+
validSeedPhrase,
|
|
241
|
+
validate
|
|
242
|
+
},
|
|
243
|
+
children
|
|
244
|
+
}
|
|
245
|
+
);
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
// src/contexts/SeedPhrase/use.tsx
|
|
249
|
+
import { useContextEx } from "@xyo-network/react-shared";
|
|
250
|
+
var useSeedPhrase = () => useContextEx(SeedPhraseContext, "SeedPhrase", true);
|
|
251
|
+
|
|
252
|
+
// src/contexts/Wallet/Context.ts
|
|
253
|
+
import { createContextEx as createContextEx2 } from "@xyo-network/react-shared";
|
|
254
|
+
var WalletContext = createContextEx2();
|
|
255
|
+
|
|
256
|
+
// src/contexts/Wallet/lib/WalletPath.ts
|
|
257
|
+
var Bip44 = {
|
|
258
|
+
base: "m",
|
|
259
|
+
coin_type: {
|
|
260
|
+
/* https://github.com/satoshilabs/slips/blob/master/slip-0044.md */
|
|
261
|
+
bitcoin: "0'",
|
|
262
|
+
bitcoinTestnet: "1'",
|
|
263
|
+
ether: "60'",
|
|
264
|
+
etherClassic: "61'"
|
|
265
|
+
},
|
|
266
|
+
purpose: "44'"
|
|
267
|
+
};
|
|
268
|
+
var WalletRootPath = `${Bip44.base}/${Bip44.purpose}/${Bip44.coin_type.ether}`;
|
|
269
|
+
var ethereumAccountPath = (index, hardened = true) => {
|
|
270
|
+
return `${WalletRootPath}/${index}${hardened ? "'" : ""}/0`;
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
// src/contexts/Wallet/Provider.tsx
|
|
274
|
+
import { useEffect as useEffect4, useState as useState6 } from "react";
|
|
275
|
+
|
|
276
|
+
// src/contexts/Wallet/usePromise.ts
|
|
277
|
+
import { Mutex } from "async-mutex";
|
|
278
|
+
import { useEffect as useEffect3, useMemo as useMemo2, useState as useState5 } from "react";
|
|
279
|
+
var usePromise = (promise, dependencies, debug = void 0) => {
|
|
280
|
+
const [result, setResult] = useState5();
|
|
281
|
+
const [error, setError] = useState5();
|
|
282
|
+
const [state, setState] = useState5("pending" /* pending */);
|
|
283
|
+
const mutex = useMemo2(() => {
|
|
284
|
+
return new Mutex();
|
|
285
|
+
}, []);
|
|
286
|
+
if (debug)
|
|
287
|
+
console.log(`usePromise [${debug}]: started [${typeof promise}]`);
|
|
288
|
+
const promiseMemo = useMemo2(() => {
|
|
289
|
+
try {
|
|
290
|
+
if (debug)
|
|
291
|
+
console.log(`usePromise [${debug}]: re-memo [${typeof promise}]`);
|
|
292
|
+
setState("pending" /* pending */);
|
|
293
|
+
return promise?.();
|
|
294
|
+
} catch (e) {
|
|
295
|
+
if (debug)
|
|
296
|
+
console.log(`usePromise [${debug}]: useMemo rejection [${typeof promise}]`);
|
|
297
|
+
setResult(void 0);
|
|
298
|
+
setError(e);
|
|
299
|
+
setState("rejected" /* rejected */);
|
|
300
|
+
}
|
|
301
|
+
}, dependencies);
|
|
302
|
+
if (debug)
|
|
303
|
+
console.log(`usePromise [${debug}] Main Function`);
|
|
304
|
+
useEffect3(() => {
|
|
305
|
+
if (debug)
|
|
306
|
+
console.log(`usePromise [${debug}] useEffect`);
|
|
307
|
+
mutex?.acquire().then(() => {
|
|
308
|
+
promiseMemo?.then((payload) => {
|
|
309
|
+
if (debug)
|
|
310
|
+
console.log(`usePromise [${debug}] then`);
|
|
311
|
+
setResult(payload);
|
|
312
|
+
setError(void 0);
|
|
313
|
+
setState("resolved" /* resolved */);
|
|
314
|
+
mutex?.release();
|
|
315
|
+
}).catch((e) => {
|
|
316
|
+
const error2 = e;
|
|
317
|
+
console.error(`usePromise: ${error2.message}`);
|
|
318
|
+
setResult(void 0);
|
|
319
|
+
setError(error2);
|
|
320
|
+
setState("rejected" /* rejected */);
|
|
321
|
+
mutex?.release();
|
|
322
|
+
});
|
|
323
|
+
}).catch((e) => {
|
|
324
|
+
const error2 = e;
|
|
325
|
+
console.error(`usePromise: ${error2.message}`);
|
|
326
|
+
setResult(void 0);
|
|
327
|
+
setError(error2);
|
|
328
|
+
setState("rejected" /* rejected */);
|
|
329
|
+
mutex?.release();
|
|
330
|
+
});
|
|
331
|
+
return () => {
|
|
332
|
+
if (debug)
|
|
333
|
+
console.log(`usePromise [${debug}] useEffect callback`);
|
|
334
|
+
};
|
|
335
|
+
}, [...dependencies, promiseMemo]);
|
|
336
|
+
if (debug)
|
|
337
|
+
console.log(`usePromise [${debug}] returning ${JSON.stringify([result, error, state], null, 2)}`);
|
|
338
|
+
return [result, error, state];
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
// src/contexts/Wallet/Provider.tsx
|
|
342
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
343
|
+
var WalletProvider = ({
|
|
344
|
+
basePath = WalletRootPath,
|
|
345
|
+
children,
|
|
346
|
+
defaultActiveAccountIndex = 0,
|
|
347
|
+
rootWallet = null,
|
|
348
|
+
...props
|
|
349
|
+
}) => {
|
|
350
|
+
const [activeAccountIndex, setActiveAccountIndex] = useState6(defaultActiveAccountIndex);
|
|
351
|
+
useEffect4(() => {
|
|
352
|
+
if (defaultActiveAccountIndex !== void 0) {
|
|
353
|
+
setActiveAccountIndex(defaultActiveAccountIndex);
|
|
354
|
+
}
|
|
355
|
+
}, [defaultActiveAccountIndex]);
|
|
356
|
+
const [coinTypeWallet = null] = usePromise(async () => {
|
|
357
|
+
if (rootWallet) {
|
|
358
|
+
if (!rootWallet?.path.includes(basePath)) {
|
|
359
|
+
try {
|
|
360
|
+
return await rootWallet?.derivePath(basePath);
|
|
361
|
+
} catch (e) {
|
|
362
|
+
console.error("Error setting proper wallet base path", e);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
} else {
|
|
366
|
+
return void 0;
|
|
367
|
+
}
|
|
368
|
+
}, [basePath, rootWallet]);
|
|
369
|
+
const [activeAccount = null] = usePromise(
|
|
370
|
+
async () => await coinTypeWallet?.derivePath(activeAccountIndex.toString()),
|
|
371
|
+
[coinTypeWallet, activeAccountIndex]
|
|
372
|
+
);
|
|
373
|
+
return /* @__PURE__ */ jsx6(
|
|
374
|
+
WalletContext.Provider,
|
|
375
|
+
{
|
|
376
|
+
value: {
|
|
377
|
+
activeAccount,
|
|
378
|
+
activeAccountIndex,
|
|
379
|
+
basePath,
|
|
380
|
+
coinTypeWallet,
|
|
381
|
+
provided: true,
|
|
382
|
+
rootWallet,
|
|
383
|
+
setActiveAccountIndex
|
|
384
|
+
},
|
|
385
|
+
...props,
|
|
386
|
+
children
|
|
387
|
+
}
|
|
388
|
+
);
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
// src/contexts/Wallet/use.ts
|
|
392
|
+
import { usePromise as usePromise2 } from "@xylabs/react-promise";
|
|
393
|
+
import { useContextEx as useContextEx2, useProvided } from "@xyo-network/react-shared";
|
|
394
|
+
var useWalletContext = (required = true) => {
|
|
395
|
+
return useContextEx2(WalletContext, "Wallet", required);
|
|
396
|
+
};
|
|
397
|
+
var useWalletProvided = () => {
|
|
398
|
+
return useProvided(WalletContext);
|
|
399
|
+
};
|
|
400
|
+
var useCoinTypeWallet = (required = true) => {
|
|
401
|
+
const { coinTypeWallet } = useWalletContext(required);
|
|
402
|
+
return [coinTypeWallet, void 0];
|
|
403
|
+
};
|
|
404
|
+
var useRootWallet = (required = true) => {
|
|
405
|
+
const { rootWallet } = useWalletContext(required);
|
|
406
|
+
return [rootWallet, void 0];
|
|
407
|
+
};
|
|
408
|
+
var useIndexedWalletFromContext = (index, required = true) => {
|
|
409
|
+
const [coinTypeWallet] = useCoinTypeWallet(required);
|
|
410
|
+
const [wallet] = usePromise2(async () => await coinTypeWallet?.derivePath(index.toString()) ?? coinTypeWallet, [coinTypeWallet, index]);
|
|
411
|
+
return [wallet, void 0];
|
|
412
|
+
};
|
|
413
|
+
var useSelectedWalletAccount = (required = true) => {
|
|
414
|
+
const { activeAccountIndex } = useWalletContext(required);
|
|
415
|
+
const [account] = useIndexedWalletFromContext(activeAccountIndex ?? 0, required);
|
|
416
|
+
if (activeAccountIndex === void 0 && account === null) {
|
|
417
|
+
return [null, void 0];
|
|
418
|
+
} else {
|
|
419
|
+
return [account, void 0];
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
// src/components/SeedPhrase/dialog/components/DialogActionButtons.tsx
|
|
424
|
+
import { Button as Button2, DialogActions as DialogActions2 } from "@mui/material";
|
|
425
|
+
import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
426
|
+
var DialogActionButtons = ({ onClose, ...props }) => {
|
|
427
|
+
const { handleSave, setPhrase } = useSeedPhrase();
|
|
428
|
+
const wrappedOnClose = (e) => {
|
|
429
|
+
setPhrase?.("");
|
|
430
|
+
onClose?.(e, "escapeKeyDown");
|
|
431
|
+
};
|
|
432
|
+
return /* @__PURE__ */ jsxs5(DialogActions2, { ...props, children: [
|
|
433
|
+
/* @__PURE__ */ jsx7(Button2, { variant: "outlined", onClick: wrappedOnClose, children: "Cancel" }),
|
|
434
|
+
/* @__PURE__ */ jsx7(Button2, { variant: "outlined", onClick: handleSave, children: "Save" })
|
|
435
|
+
] });
|
|
436
|
+
};
|
|
437
|
+
|
|
438
|
+
// src/components/SeedPhrase/dialog/components/fields/NewPhraseTextField.tsx
|
|
439
|
+
import { Button as Button3, DialogActions as DialogActions3, FormControl, FormLabel, TextField } from "@mui/material";
|
|
440
|
+
|
|
441
|
+
// src/components/SeedPhrase/dialog/components/fields/validation-messages/colorParser.ts
|
|
442
|
+
var colorParser = (conditional) => {
|
|
443
|
+
switch (conditional) {
|
|
444
|
+
case true:
|
|
445
|
+
return "success";
|
|
446
|
+
case false:
|
|
447
|
+
return "error";
|
|
448
|
+
default:
|
|
449
|
+
return void 0;
|
|
450
|
+
}
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
// src/components/SeedPhrase/dialog/components/fields/validation-messages/InvalidPhrase.tsx
|
|
454
|
+
import { Link as Link2, Typography as Typography3 } from "@mui/material";
|
|
455
|
+
import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
456
|
+
var InvalidPhraseTypography = (props) => /* @__PURE__ */ jsxs6(Typography3, { variant: "caption", color: "error", ...props, children: [
|
|
457
|
+
"Invalid seed phrase. See -",
|
|
458
|
+
" ",
|
|
459
|
+
/* @__PURE__ */ jsx8(Link2, { target: "_blank", href: "https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki", children: "bip39 Proposal" })
|
|
460
|
+
] });
|
|
461
|
+
|
|
462
|
+
// src/components/SeedPhrase/dialog/components/fields/validation-messages/PhraseHeaderBox.tsx
|
|
463
|
+
import { CheckCircleOutline as CheckCircleOutlineIcon, HighlightOff as HighlightOffIcon } from "@mui/icons-material";
|
|
464
|
+
import { FlexRow } from "@xylabs/react-flexbox";
|
|
465
|
+
import { useMemo as useMemo3 } from "react";
|
|
466
|
+
import { jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
467
|
+
var PhraseHeaderBox = ({ children, conditional, ...props }) => {
|
|
468
|
+
const state = useMemo3(() => {
|
|
469
|
+
switch (conditional) {
|
|
470
|
+
case true:
|
|
471
|
+
return "success";
|
|
472
|
+
case false:
|
|
473
|
+
return "error";
|
|
474
|
+
default:
|
|
475
|
+
return null;
|
|
476
|
+
}
|
|
477
|
+
}, [conditional]);
|
|
478
|
+
const Icon = useMemo3(() => {
|
|
479
|
+
switch (state) {
|
|
480
|
+
case "success":
|
|
481
|
+
return /* @__PURE__ */ jsx9(CheckCircleOutlineIcon, { fontSize: "small", color: "success" });
|
|
482
|
+
case "error":
|
|
483
|
+
return /* @__PURE__ */ jsx9(HighlightOffIcon, { fontSize: "small", color: "error" });
|
|
484
|
+
default:
|
|
485
|
+
return null;
|
|
486
|
+
}
|
|
487
|
+
}, [state]);
|
|
488
|
+
return /* @__PURE__ */ jsxs7(FlexRow, { justifyContent: "start", columnGap: 1, ...props, children: [
|
|
489
|
+
Icon,
|
|
490
|
+
children
|
|
491
|
+
] });
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
// src/components/SeedPhrase/dialog/components/fields/NewPhraseTextField.tsx
|
|
495
|
+
import { Fragment as Fragment3, jsx as jsx10, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
496
|
+
var NewPhraseTextField = (props) => {
|
|
497
|
+
const { handleClear, handleGenerate, overwriteWarning, phrase, setPhrase, validPhrase } = useSeedPhrase();
|
|
498
|
+
return /* @__PURE__ */ jsxs8(Fragment3, { children: [
|
|
499
|
+
/* @__PURE__ */ jsxs8(FormControl, { fullWidth: true, size: "small", sx: { display: "flex", flexDirection: "column", rowGap: 1 }, children: [
|
|
500
|
+
/* @__PURE__ */ jsx10(FormLabel, { children: /* @__PURE__ */ jsx10(PhraseHeaderBox, { conditional: validPhrase, children: "New Seed Phrase" }) }),
|
|
501
|
+
/* @__PURE__ */ jsx10(
|
|
502
|
+
TextField,
|
|
503
|
+
{
|
|
504
|
+
focused: true,
|
|
505
|
+
color: colorParser(validPhrase),
|
|
506
|
+
error: validPhrase === false,
|
|
507
|
+
helperText: validPhrase === false ? /* @__PURE__ */ jsx10(InvalidPhraseTypography, {}) : null,
|
|
508
|
+
fullWidth: true,
|
|
509
|
+
maxRows: Infinity,
|
|
510
|
+
multiline: true,
|
|
511
|
+
onChange: (e) => setPhrase?.(e.target.value),
|
|
512
|
+
value: phrase,
|
|
513
|
+
...props
|
|
514
|
+
}
|
|
515
|
+
)
|
|
516
|
+
] }),
|
|
517
|
+
/* @__PURE__ */ jsxs8(DialogActions3, { sx: { justifyContent: "center" }, children: [
|
|
518
|
+
/* @__PURE__ */ jsx10(Button3, { disabled: overwriteWarning, variant: "outlined", onClick: handleGenerate, children: "Generate" }),
|
|
519
|
+
/* @__PURE__ */ jsx10(Button3, { variant: "outlined", onClick: handleClear, children: "Clear" })
|
|
520
|
+
] })
|
|
521
|
+
] });
|
|
522
|
+
};
|
|
523
|
+
|
|
524
|
+
// src/components/SeedPhrase/dialog/components/fields/SavedPhraseTextField.tsx
|
|
525
|
+
import { Chip, FormControl as FormControl2, FormLabel as FormLabel2, TextField as TextField2 } from "@mui/material";
|
|
526
|
+
import { useState as useState7 } from "react";
|
|
527
|
+
import { Fragment as Fragment4, jsx as jsx11, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
528
|
+
var SavedPhraseTextField = (props) => {
|
|
529
|
+
const { validSeedPhrase, seedPhrase } = useSeedPhrase();
|
|
530
|
+
const [visible, setVisible] = useState7(false);
|
|
531
|
+
return /* @__PURE__ */ jsxs9(FormControl2, { fullWidth: true, size: "small", sx: { display: "flex", flexDirection: "column", rowGap: 1 }, children: [
|
|
532
|
+
/* @__PURE__ */ jsx11(Chip, { label: visible ? "Hide Saved Seed Phrase" : "Reveal Saved Seed Phrase", onClick: () => setVisible(!visible) }),
|
|
533
|
+
visible ? /* @__PURE__ */ jsxs9(Fragment4, { children: [
|
|
534
|
+
/* @__PURE__ */ jsx11(FormLabel2, { children: /* @__PURE__ */ jsx11(PhraseHeaderBox, { conditional: validSeedPhrase, children: "Saved Seed Phrase" }) }),
|
|
535
|
+
/* @__PURE__ */ jsx11(
|
|
536
|
+
TextField2,
|
|
537
|
+
{
|
|
538
|
+
defaultValue: seedPhrase,
|
|
539
|
+
disabled: true,
|
|
540
|
+
error: validSeedPhrase === false,
|
|
541
|
+
helperText: validSeedPhrase === false ? /* @__PURE__ */ jsx11(InvalidPhraseTypography, {}) : null,
|
|
542
|
+
fullWidth: true,
|
|
543
|
+
maxRows: Infinity,
|
|
544
|
+
multiline: true,
|
|
545
|
+
...props
|
|
546
|
+
}
|
|
547
|
+
)
|
|
548
|
+
] }) : null
|
|
549
|
+
] });
|
|
550
|
+
};
|
|
551
|
+
|
|
552
|
+
// src/components/SeedPhrase/dialog/components/OverwriteWarning.tsx
|
|
553
|
+
import { Alert as Alert3, Button as Button4 } from "@mui/material";
|
|
554
|
+
import { FlexRow as FlexRow2 } from "@xylabs/react-flexbox";
|
|
555
|
+
import { jsx as jsx12, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
556
|
+
var OverwriteWarning = () => {
|
|
557
|
+
const { handleCancelOverwrite, handleSave } = useSeedPhrase();
|
|
558
|
+
return /* @__PURE__ */ jsx12(
|
|
559
|
+
Alert3,
|
|
560
|
+
{
|
|
561
|
+
variant: "outlined",
|
|
562
|
+
severity: "warning",
|
|
563
|
+
action: /* @__PURE__ */ jsxs10(FlexRow2, { sx: { columnGap: 1 }, children: [
|
|
564
|
+
/* @__PURE__ */ jsx12(Button4, { variant: "outlined", color: "inherit", size: "small", onClick: handleSave, children: "Overwrite" }),
|
|
565
|
+
/* @__PURE__ */ jsx12(Button4, { variant: "outlined", color: "inherit", size: "small", onClick: handleCancelOverwrite, children: "Cancel" })
|
|
566
|
+
] }),
|
|
567
|
+
children: "Are you sure you want to overwrite existing seed phrase? This action cannot be undone."
|
|
568
|
+
}
|
|
569
|
+
);
|
|
570
|
+
};
|
|
571
|
+
|
|
572
|
+
// src/components/SeedPhrase/dialog/SeedPhraseDialog.tsx
|
|
573
|
+
import { jsx as jsx13, jsxs as jsxs11 } from "react/jsx-runtime";
|
|
574
|
+
var SeedPhraseDialog = ({ changeSeedPhrase, seedPhrase, ...props }) => {
|
|
575
|
+
return /* @__PURE__ */ jsx13(
|
|
576
|
+
SeedPhraseProvider,
|
|
577
|
+
{
|
|
578
|
+
seedPhrase,
|
|
579
|
+
handleChangeSeedPhrase: changeSeedPhrase,
|
|
580
|
+
open: props.open,
|
|
581
|
+
saveCallback: () => props.onClose?.({}, "escapeKeyDown"),
|
|
582
|
+
children: /* @__PURE__ */ jsx13(SeedPhraseDialogInner, { ...props })
|
|
583
|
+
}
|
|
584
|
+
);
|
|
585
|
+
};
|
|
586
|
+
var SeedPhraseDialogInner = (props) => {
|
|
587
|
+
const { overwriteWarning, seedPhrase } = useSeedPhrase();
|
|
588
|
+
return /* @__PURE__ */ jsxs11(Dialog2, { "aria-labelledby": "alert-dialog-title", "aria-describedby": "alert-dialog-description", fullWidth: true, maxWidth: "sm", ...props, children: [
|
|
589
|
+
/* @__PURE__ */ jsxs11(DialogTitle2, { id: "alert-dialog-title", children: [
|
|
590
|
+
"Update Your Seed Phrase ",
|
|
591
|
+
/* @__PURE__ */ jsx13(SeedPhraseIconButton, {})
|
|
592
|
+
] }),
|
|
593
|
+
/* @__PURE__ */ jsxs11(DialogContent2, { sx: { display: "flex", flexDirection: "column", rowGap: 2 }, children: [
|
|
594
|
+
/* @__PURE__ */ jsx13(NewPhraseTextField, {}),
|
|
595
|
+
seedPhrase ? /* @__PURE__ */ jsx13(SavedPhraseTextField, {}) : null,
|
|
596
|
+
overwriteWarning ? /* @__PURE__ */ jsx13(OverwriteWarning, {}) : null
|
|
597
|
+
] }),
|
|
598
|
+
/* @__PURE__ */ jsx13(DialogActionButtons, { onClose: props.onClose })
|
|
599
|
+
] });
|
|
600
|
+
};
|
|
601
|
+
|
|
602
|
+
// src/components/SeedPhrase/settings/SeedPhraseTableRow.tsx
|
|
603
|
+
import { Cancel as CancelIcon, RadioButtonChecked as RadioButtonCheckedIcon } from "@mui/icons-material";
|
|
604
|
+
import { Button as Button5, ButtonGroup as ButtonGroup2, TableCell as TableCell2, TableRow as TableRow2 } from "@mui/material";
|
|
605
|
+
import { useState as useState8 } from "react";
|
|
606
|
+
import { jsx as jsx14, jsxs as jsxs12 } from "react/jsx-runtime";
|
|
607
|
+
var SeedPhraseTableRow = ({ changeSeedPhrase, seedPhrase, ...props }) => {
|
|
608
|
+
const [open, setOpen] = useState8(false);
|
|
609
|
+
const handleOpen = () => {
|
|
610
|
+
setOpen(true);
|
|
611
|
+
};
|
|
612
|
+
return /* @__PURE__ */ jsxs12(TableRow2, { ...props, children: [
|
|
613
|
+
/* @__PURE__ */ jsxs12(TableCell2, { children: [
|
|
614
|
+
"Seed Phrase ",
|
|
615
|
+
/* @__PURE__ */ jsx14(SeedPhraseIconButton, {})
|
|
616
|
+
] }),
|
|
617
|
+
/* @__PURE__ */ jsx14(TableCell2, { align: "center", children: seedPhrase ? /* @__PURE__ */ jsx14(RadioButtonCheckedIcon, { color: "success" }) : /* @__PURE__ */ jsx14(CancelIcon, { color: "error" }) }),
|
|
618
|
+
/* @__PURE__ */ jsxs12(TableCell2, { children: [
|
|
619
|
+
/* @__PURE__ */ jsx14(SeedPhraseDialog, { changeSeedPhrase, open, onClose: () => setOpen(false), seedPhrase }),
|
|
620
|
+
/* @__PURE__ */ jsx14(ButtonGroup2, { fullWidth: true, children: /* @__PURE__ */ jsx14(Button5, { variant: "contained", size: "small", onClick: handleOpen, children: "Update" }) })
|
|
621
|
+
] })
|
|
622
|
+
] });
|
|
623
|
+
};
|
|
624
|
+
|
|
625
|
+
// src/components/WalletAccountDetails/WalletAccountDetails.tsx
|
|
626
|
+
import { EthAddress } from "@xylabs/eth-address";
|
|
627
|
+
import { EthAccountButton } from "@xylabs/react-crypto";
|
|
628
|
+
import { FlexCol, FlexRow as FlexRow3 } from "@xylabs/react-flexbox";
|
|
629
|
+
import { NumberStatus } from "@xylabs/react-number-status";
|
|
630
|
+
import { useNetwork } from "@xyo-network/react-network";
|
|
631
|
+
|
|
632
|
+
// src/hooks/useAccount.ts
|
|
633
|
+
import { usePromise as usePromise3 } from "@xylabs/react-promise";
|
|
634
|
+
import { useState as useState9 } from "react";
|
|
635
|
+
var useAccount = ({ wallet, account, index, required = false } = {}) => {
|
|
636
|
+
const walletContextProvided = useWalletProvided();
|
|
637
|
+
const [validationError, setValidationError] = useState9();
|
|
638
|
+
if (wallet && account && !validationError) {
|
|
639
|
+
setValidationError(Error("useAccount can not have both a wallet and an account in the parameters"));
|
|
640
|
+
}
|
|
641
|
+
if (index && account && !validationError) {
|
|
642
|
+
setValidationError(Error("useAccount can not have both a index and an account in the parameters"));
|
|
643
|
+
}
|
|
644
|
+
const [error, setError] = useState9();
|
|
645
|
+
const [coinTypeWallet] = useCoinTypeWallet(!wallet && required);
|
|
646
|
+
const { activeAccountIndex } = useWalletContext(false);
|
|
647
|
+
const [activeAccount] = usePromise3(async () => {
|
|
648
|
+
try {
|
|
649
|
+
if (!validationError) {
|
|
650
|
+
if (wallet) {
|
|
651
|
+
return await wallet?.derivePath?.(`${index ?? 0}'\0`);
|
|
652
|
+
} else if (coinTypeWallet) {
|
|
653
|
+
return await coinTypeWallet?.derivePath?.(`${index ?? activeAccountIndex ?? 0}'\0`);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
} catch (ex) {
|
|
657
|
+
const error2 = ex;
|
|
658
|
+
console.error(error2.message);
|
|
659
|
+
setError(error2);
|
|
660
|
+
}
|
|
661
|
+
}, [index, wallet, coinTypeWallet, activeAccountIndex, validationError]);
|
|
662
|
+
if (validationError && !error) {
|
|
663
|
+
console.error(validationError.message);
|
|
664
|
+
setError(validationError);
|
|
665
|
+
}
|
|
666
|
+
return [error ? void 0 : account ?? activeAccount ?? walletContextProvided ? null : void 0, error];
|
|
667
|
+
};
|
|
668
|
+
|
|
669
|
+
// src/hooks/useWallet.ts
|
|
670
|
+
import { usePromise as usePromise4 } from "@xylabs/react-promise";
|
|
671
|
+
import { HDWallet } from "@xyo-network/account";
|
|
672
|
+
import { useState as useState10 } from "react";
|
|
673
|
+
var useWallet = ({ mnemonic, wallet, path, required = false, seed } = {}) => {
|
|
674
|
+
const walletContextProvided = useWalletProvided();
|
|
675
|
+
const [error, setError] = useState10();
|
|
676
|
+
const [contextAccount] = useSelectedWalletAccount(!wallet && required);
|
|
677
|
+
const [activeAccount] = usePromise4(async () => {
|
|
678
|
+
try {
|
|
679
|
+
const newAccount = await (() => {
|
|
680
|
+
if (wallet) {
|
|
681
|
+
return wallet;
|
|
682
|
+
} else if (mnemonic) {
|
|
683
|
+
return HDWallet.fromMnemonic(mnemonic);
|
|
684
|
+
} else if (seed) {
|
|
685
|
+
return HDWallet.fromSeed(seed);
|
|
686
|
+
}
|
|
687
|
+
return contextAccount;
|
|
688
|
+
})();
|
|
689
|
+
if (path) {
|
|
690
|
+
return newAccount?.derivePath?.(path);
|
|
691
|
+
} else {
|
|
692
|
+
return newAccount ?? wallet;
|
|
693
|
+
}
|
|
694
|
+
} catch (ex) {
|
|
695
|
+
setError(ex);
|
|
696
|
+
}
|
|
697
|
+
}, [mnemonic, contextAccount, seed, path, wallet]);
|
|
698
|
+
return [activeAccount ?? (walletContextProvided ? null : activeAccount), error];
|
|
699
|
+
};
|
|
700
|
+
|
|
701
|
+
// src/hooks/useWallets.ts
|
|
702
|
+
import { usePromise as usePromise5 } from "@xylabs/react-promise";
|
|
703
|
+
var useWallets = ({ wallet, paths }) => {
|
|
704
|
+
const walletContextProvided = useWalletProvided();
|
|
705
|
+
const [foundWallet] = useWallet({ wallet });
|
|
706
|
+
const [wallets, error] = usePromise5(
|
|
707
|
+
async () => foundWallet ? await Promise.all(paths.map((path) => foundWallet.derivePath(path))) : void 0,
|
|
708
|
+
[foundWallet, paths]
|
|
709
|
+
);
|
|
710
|
+
return [wallets ?? (walletContextProvided ? null : wallets), error];
|
|
711
|
+
};
|
|
712
|
+
|
|
713
|
+
// src/hooks/useWrapperAccount.ts
|
|
714
|
+
import { usePromise as usePromise6 } from "@xylabs/react-promise";
|
|
715
|
+
import { HDWallet as HDWallet2 } from "@xyo-network/account";
|
|
716
|
+
import { Mutex as Mutex2 } from "async-mutex";
|
|
717
|
+
var globalWrapperWallet = void 0;
|
|
718
|
+
var globalWrapperWalletMutex = new Mutex2();
|
|
719
|
+
var useWrapperAccount = (account) => {
|
|
720
|
+
return usePromise6(async () => {
|
|
721
|
+
return await globalWrapperWalletMutex.runExclusive(async () => {
|
|
722
|
+
if (account !== void 0) {
|
|
723
|
+
return account;
|
|
724
|
+
}
|
|
725
|
+
if (globalWrapperWallet) {
|
|
726
|
+
return globalWrapperWallet;
|
|
727
|
+
}
|
|
728
|
+
try {
|
|
729
|
+
globalWrapperWallet = await HDWallet2.random();
|
|
730
|
+
console.log(`Global Wrapper Wallet Creation Success: ${globalWrapperWallet.address}`);
|
|
731
|
+
} catch (ex) {
|
|
732
|
+
const error = ex;
|
|
733
|
+
console.error(`Global Wrapper Wallet Creation Failed: ${error.message}`);
|
|
734
|
+
}
|
|
735
|
+
return globalWrapperWallet;
|
|
736
|
+
});
|
|
737
|
+
}, [account]);
|
|
738
|
+
};
|
|
739
|
+
|
|
740
|
+
// src/components/WalletAccountDetails/WalletAccountDetails.tsx
|
|
741
|
+
import { jsx as jsx15, jsxs as jsxs13 } from "react/jsx-runtime";
|
|
742
|
+
var WalletAccountDetails = ({ exploreUrl = "https://explore.xyo.network", account, ...props }) => {
|
|
743
|
+
const [accountToUse] = useAccount({ account });
|
|
744
|
+
const { network } = useNetwork();
|
|
745
|
+
const exploreAddressUrl = `${exploreUrl}/recent?account=${accountToUse?.address}&network=${network?.name ?? "main"}`;
|
|
746
|
+
return /* @__PURE__ */ jsxs13(FlexCol, { ...props, children: [
|
|
747
|
+
/* @__PURE__ */ jsx15(EthAccountButton, { address: EthAddress.fromString(accountToUse?.address) }),
|
|
748
|
+
/* @__PURE__ */ jsxs13(FlexRow3, { gap: 1, children: [
|
|
749
|
+
/* @__PURE__ */ jsx15(NumberStatus, { rounded: true, title: "Tokens", value: 0, to: `${exploreAddressUrl}&schema=network.xyo.account.tokens`, target: "_blank" }),
|
|
750
|
+
/* @__PURE__ */ jsx15(NumberStatus, { rounded: true, title: "NFTs", value: 0, to: `${exploreAddressUrl}&schema=network.xyo.account.nfts`, target: "_blank" }),
|
|
751
|
+
/* @__PURE__ */ jsx15(NumberStatus, { rounded: true, title: "Signatures", value: 0, to: `${exploreAddressUrl}&schema=network.xyo.account.signatures`, target: "_blank" }),
|
|
752
|
+
/* @__PURE__ */ jsx15(NumberStatus, { rounded: true, title: "Signins", value: 0, to: `${exploreAddressUrl}&schema=network.xyo.account.signins`, target: "_blank" })
|
|
753
|
+
] })
|
|
754
|
+
] });
|
|
755
|
+
};
|
|
756
|
+
|
|
757
|
+
// src/components/WalletAccountSelect/Select.tsx
|
|
758
|
+
import { CircularProgress, MenuItem } from "@mui/material";
|
|
759
|
+
import { SelectEx } from "@xylabs/react-select";
|
|
760
|
+
import { AddressRenderRowBox } from "@xyo-network/react-address-render";
|
|
761
|
+
import { Fragment as Fragment5, jsx as jsx16 } from "react/jsx-runtime";
|
|
762
|
+
var arrayRange = (length, start = 0) => {
|
|
763
|
+
return Array.from(Array(length).keys()).map((x) => x + start);
|
|
764
|
+
};
|
|
765
|
+
var WalletAccountSelect = ({
|
|
766
|
+
addressNames = {},
|
|
767
|
+
iconOnly,
|
|
768
|
+
iconSize = 24,
|
|
769
|
+
icons,
|
|
770
|
+
maxAccounts = 1,
|
|
771
|
+
showFavorite = false,
|
|
772
|
+
size,
|
|
773
|
+
...props
|
|
774
|
+
}) => {
|
|
775
|
+
const { activeAccountIndex = 0, setActiveAccountIndex, coinTypeWallet } = useWalletContext();
|
|
776
|
+
const disabled = !coinTypeWallet || activeAccountIndex === void 0;
|
|
777
|
+
return /* @__PURE__ */ jsx16(Fragment5, { children: coinTypeWallet ? /* @__PURE__ */ jsx16(
|
|
778
|
+
SelectEx,
|
|
779
|
+
{
|
|
780
|
+
margin: "dense",
|
|
781
|
+
disabled,
|
|
782
|
+
renderValue: (selectedAccountIndex) => {
|
|
783
|
+
const Item = () => {
|
|
784
|
+
const [selectedAccount] = useWallet({ path: selectedAccountIndex.toString(), wallet: coinTypeWallet });
|
|
785
|
+
const customName = selectedAccount ? addressNames[selectedAccount.address] : void 0;
|
|
786
|
+
const favorite = !!selectedAccount && selectedAccount.address in addressNames;
|
|
787
|
+
return /* @__PURE__ */ jsx16(MenuItem, { value: selectedAccountIndex, sx: { minHeight: 0, paddingBottom: 0, paddingTop: 0 }, children: /* @__PURE__ */ jsx16(
|
|
788
|
+
AddressRenderRowBox,
|
|
789
|
+
{
|
|
790
|
+
disableSharedRef: true,
|
|
791
|
+
flexGrow: 1,
|
|
792
|
+
address: selectedAccount?.address,
|
|
793
|
+
iconOnly,
|
|
794
|
+
iconSize,
|
|
795
|
+
icons,
|
|
796
|
+
name: customName,
|
|
797
|
+
favorite,
|
|
798
|
+
showFavorite
|
|
799
|
+
}
|
|
800
|
+
) });
|
|
801
|
+
};
|
|
802
|
+
return /* @__PURE__ */ jsx16(Item, {});
|
|
803
|
+
},
|
|
804
|
+
value: activeAccountIndex,
|
|
805
|
+
onChange: (event) => setActiveAccountIndex?.(parseInt(`${event.target.value}`)),
|
|
806
|
+
size,
|
|
807
|
+
variant: "outlined",
|
|
808
|
+
...props,
|
|
809
|
+
children: arrayRange(maxAccounts).map((index) => {
|
|
810
|
+
const Item = () => {
|
|
811
|
+
const [account] = useWallet({ path: index.toString(), wallet: coinTypeWallet });
|
|
812
|
+
const customName = account ? addressNames[account.address] : void 0;
|
|
813
|
+
const favorite = !!account && account.address in addressNames;
|
|
814
|
+
return /* @__PURE__ */ jsx16(MenuItem, { value: index, sx: { minHeight: 0, paddingBottom: 0, paddingTop: 0 }, children: /* @__PURE__ */ jsx16(
|
|
815
|
+
AddressRenderRowBox,
|
|
816
|
+
{
|
|
817
|
+
disableSharedRef: true,
|
|
818
|
+
flexGrow: 1,
|
|
819
|
+
address: account?.address,
|
|
820
|
+
favorite,
|
|
821
|
+
iconOnly,
|
|
822
|
+
iconSize,
|
|
823
|
+
icons,
|
|
824
|
+
name: customName,
|
|
825
|
+
showFavorite
|
|
826
|
+
}
|
|
827
|
+
) }, account?.address);
|
|
828
|
+
};
|
|
829
|
+
return /* @__PURE__ */ jsx16(Item, {}, index);
|
|
830
|
+
})
|
|
831
|
+
}
|
|
832
|
+
) : /* @__PURE__ */ jsx16(CircularProgress, { size: 24 }) });
|
|
833
|
+
};
|
|
834
|
+
|
|
835
|
+
// src/components/WalletAccountSelect/SelectBar.tsx
|
|
836
|
+
import { FlexCol as FlexCol2 } from "@xylabs/react-flexbox";
|
|
837
|
+
import { jsx as jsx17 } from "react/jsx-runtime";
|
|
838
|
+
var WalletAccountSelectBar = ({
|
|
839
|
+
addressNames = {},
|
|
840
|
+
iconOnly,
|
|
841
|
+
iconSize,
|
|
842
|
+
icons,
|
|
843
|
+
maxAccounts = 1,
|
|
844
|
+
showFavorite = false,
|
|
845
|
+
size = "small",
|
|
846
|
+
...props
|
|
847
|
+
}) => {
|
|
848
|
+
return /* @__PURE__ */ jsx17(FlexCol2, { alignItems: "stretch", ...props, children: /* @__PURE__ */ jsx17(
|
|
849
|
+
WalletAccountSelect,
|
|
850
|
+
{
|
|
851
|
+
addressNames,
|
|
852
|
+
fullWidth: true,
|
|
853
|
+
showFavorite,
|
|
854
|
+
iconSize,
|
|
855
|
+
iconOnly,
|
|
856
|
+
icons,
|
|
857
|
+
maxAccounts,
|
|
858
|
+
size: size ?? "small"
|
|
859
|
+
}
|
|
860
|
+
) });
|
|
861
|
+
};
|
|
862
|
+
export {
|
|
863
|
+
Bip44,
|
|
864
|
+
DefaultSeedPhrase,
|
|
865
|
+
MaxAccountsTableRow,
|
|
866
|
+
SeedPhraseContext,
|
|
867
|
+
SeedPhraseDialog,
|
|
868
|
+
SeedPhraseDialogInner,
|
|
869
|
+
SeedPhraseIconButton,
|
|
870
|
+
SeedPhraseProvider,
|
|
871
|
+
SeedPhraseTableRow,
|
|
872
|
+
WalletAccountDetails,
|
|
873
|
+
WalletAccountSelect,
|
|
874
|
+
WalletAccountSelectBar,
|
|
875
|
+
WalletContext,
|
|
876
|
+
WalletProvider,
|
|
877
|
+
WalletRootPath,
|
|
878
|
+
ethereumAccountPath,
|
|
879
|
+
useAccount,
|
|
880
|
+
useCoinTypeWallet,
|
|
881
|
+
useIndexedWalletFromContext,
|
|
882
|
+
useRootWallet,
|
|
883
|
+
useSeedPhrase,
|
|
884
|
+
useSelectedWalletAccount,
|
|
885
|
+
useWallet,
|
|
886
|
+
useWalletContext,
|
|
887
|
+
useWalletProvided,
|
|
888
|
+
useWallets,
|
|
889
|
+
useWrapperAccount
|
|
890
|
+
};
|
|
4
891
|
//# sourceMappingURL=index.js.map
|