@xyo-network/react-wallet 2.55.3 → 2.55.5
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/cjs/hooks/useAccount.js +29 -2
- package/dist/cjs/hooks/useAccount.js.map +1 -1
- package/dist/docs.json +144 -162
- package/dist/esm/hooks/useAccount.js +28 -2
- package/dist/esm/hooks/useAccount.js.map +1 -1
- package/dist/types/hooks/useAccount.d.ts +1 -1
- package/dist/types/hooks/useAccount.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/hooks/useAccount.tsx +25 -6
|
@@ -4,11 +4,38 @@ exports.useAccount = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const account_1 = require("@xyo-network/account");
|
|
6
6
|
const react_shared_1 = require("@xyo-network/react-shared");
|
|
7
|
+
const react_1 = require("react");
|
|
7
8
|
const contexts_1 = require("../contexts");
|
|
8
9
|
const useAccount = ({ mnemonic, account, path, required, seed } = {}) => {
|
|
10
|
+
const [error, setError] = (0, react_1.useState)();
|
|
9
11
|
const [contextAccount] = (0, contexts_1.useAccountFromContext)(!account && required);
|
|
10
|
-
const [activeAccount] = (0, react_shared_1.usePromise)(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
11
|
-
|
|
12
|
+
const [activeAccount] = (0, react_shared_1.usePromise)(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
13
|
+
var _a;
|
|
14
|
+
try {
|
|
15
|
+
const newAccount = yield (() => {
|
|
16
|
+
if (account) {
|
|
17
|
+
return account;
|
|
18
|
+
}
|
|
19
|
+
else if (mnemonic) {
|
|
20
|
+
return account_1.HDWallet.fromMnemonic(mnemonic);
|
|
21
|
+
}
|
|
22
|
+
else if (seed) {
|
|
23
|
+
return account_1.HDWallet.fromSeed(seed);
|
|
24
|
+
}
|
|
25
|
+
return contextAccount;
|
|
26
|
+
})();
|
|
27
|
+
if (path) {
|
|
28
|
+
return (_a = newAccount === null || newAccount === void 0 ? void 0 : newAccount.derivePath) === null || _a === void 0 ? void 0 : _a.call(newAccount, path);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
return newAccount;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
catch (ex) {
|
|
35
|
+
setError(ex);
|
|
36
|
+
}
|
|
37
|
+
}), [account, mnemonic, contextAccount, seed, path]);
|
|
38
|
+
return [activeAccount, error];
|
|
12
39
|
};
|
|
13
40
|
exports.useAccount = useAccount;
|
|
14
41
|
//# sourceMappingURL=useAccount.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAccount.js","sourceRoot":"","sources":["../../../src/hooks/useAccount.tsx"],"names":[],"mappings":";;;;AAAA,kDAA+C;AAE/C,4DAAsD;
|
|
1
|
+
{"version":3,"file":"useAccount.js","sourceRoot":"","sources":["../../../src/hooks/useAccount.tsx"],"names":[],"mappings":";;;;AAAA,kDAA+C;AAE/C,4DAAsD;AAEtD,iCAAgC;AAEhC,0CAAmD;AAU5C,MAAM,UAAU,GAAG,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,KAAwB,EAAE,EAAmD,EAAE;IACjJ,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,IAAA,gBAAQ,GAAS,CAAA;IAC3C,MAAM,CAAC,cAAc,CAAC,GAAG,IAAA,gCAAqB,EAAC,CAAC,OAAO,IAAI,QAAQ,CAAC,CAAA;IACpE,MAAM,CAAC,aAAa,CAAC,GAAG,IAAA,yBAAU,EAAC,GAAS,EAAE;;QAC5C,IAAI;YACF,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,EAAE;gBAC7B,IAAI,OAAO,EAAE;oBACX,OAAO,OAAO,CAAA;iBACf;qBAAM,IAAI,QAAQ,EAAE;oBACnB,OAAO,kBAAQ,CAAC,YAAY,CAAC,QAAkB,CAAC,CAAA;iBACjD;qBAAM,IAAI,IAAI,EA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