@xyo-network/react-wallet 2.55.3 → 2.55.4
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 +12 -1
- package/dist/cjs/hooks/useAccount.js.map +1 -1
- package/dist/docs.json +136 -136
- package/dist/esm/hooks/useAccount.js +12 -1
- package/dist/esm/hooks/useAccount.js.map +1 -1
- package/dist/types/hooks/useAccount.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/hooks/useAccount.tsx +10 -4
|
@@ -3,7 +3,18 @@ import { usePromise } from '@xyo-network/react-shared';
|
|
|
3
3
|
import { useAccountFromContext } from '../contexts';
|
|
4
4
|
export const useAccount = ({ mnemonic, account, path, required, seed } = {}) => {
|
|
5
5
|
const [contextAccount] = useAccountFromContext(!account && required);
|
|
6
|
-
const [activeAccount] = usePromise(async () =>
|
|
6
|
+
const [activeAccount] = usePromise(async () => {
|
|
7
|
+
if (account) {
|
|
8
|
+
return account;
|
|
9
|
+
}
|
|
10
|
+
else if (mnemonic) {
|
|
11
|
+
return await HDWallet.fromMnemonic(mnemonic);
|
|
12
|
+
}
|
|
13
|
+
else if (seed) {
|
|
14
|
+
return await HDWallet.fromSeed(seed);
|
|
15
|
+
}
|
|
16
|
+
return contextAccount;
|
|
17
|
+
}, [account, mnemonic, contextAccount, seed]);
|
|
7
18
|
return usePromise(async () => (path ? await activeAccount?.derivePath?.(path) : activeAccount));
|
|
8
19
|
};
|
|
9
20
|
//# sourceMappingURL=useAccount.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAccount.js","sourceRoot":"","sources":["../../../src/hooks/useAccount.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAE/C,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAGtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAUnD,MAAM,CAA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IAAI,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAA;AACjG,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAccount.d.ts","sourceRoot":"","sources":["../../../src/hooks/useAccount.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAE5C,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAI1D,MAAM,WAAW,iBAAiB;IAChC,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,IAAI,CAAC,EAAE,QAAQ,CAAA;CAChB;AAED,eAAO,MAAM,UAAU,iDAAiD,iBAAiB,
|
|
1
|
+
{"version":3,"file":"useAccount.d.ts","sourceRoot":"","sources":["../../../src/hooks/useAccount.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAE5C,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAI1D,MAAM,WAAW,iBAAiB;IAChC,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,IAAI,CAAC,EAAE,QAAQ,CAAA;CAChB;AAED,eAAO,MAAM,UAAU,iDAAiD,iBAAiB,2GAaxF,CAAA"}
|
package/package.json
CHANGED
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"@xylabs/react-shared": "^2.17.3",
|
|
22
22
|
"@xyo-network/account": "^2.63.2",
|
|
23
23
|
"@xyo-network/core": "^2.63.2",
|
|
24
|
-
"@xyo-network/react-address-render": "^2.55.
|
|
25
|
-
"@xyo-network/react-network": "^2.55.
|
|
26
|
-
"@xyo-network/react-shared": "^2.55.
|
|
24
|
+
"@xyo-network/react-address-render": "^2.55.4",
|
|
25
|
+
"@xyo-network/react-network": "^2.55.4",
|
|
26
|
+
"@xyo-network/react-shared": "^2.55.4",
|
|
27
27
|
"@xyo-network/wallet-model": "^2.63.2"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@storybook/react": "^7.0.23",
|
|
41
41
|
"@xylabs/ts-scripts-yarn3": "^2.17.17",
|
|
42
42
|
"@xylabs/tsconfig-react": "^2.17.17",
|
|
43
|
-
"@xyo-network/react-storybook": "^2.55.
|
|
43
|
+
"@xyo-network/react-storybook": "^2.55.4",
|
|
44
44
|
"typescript": "^5.1.3"
|
|
45
45
|
},
|
|
46
46
|
"browser": "dist/esm/index.js",
|
|
@@ -85,5 +85,5 @@
|
|
|
85
85
|
},
|
|
86
86
|
"sideEffects": false,
|
|
87
87
|
"types": "dist/types/index.d.ts",
|
|
88
|
-
"version": "2.55.
|
|
88
|
+
"version": "2.55.4"
|
|
89
89
|
}
|
package/src/hooks/useAccount.tsx
CHANGED
|
@@ -15,9 +15,15 @@ export interface AccountHookParams {
|
|
|
15
15
|
|
|
16
16
|
export const useAccount = ({ mnemonic, account, path, required, seed }: AccountHookParams = {}) => {
|
|
17
17
|
const [contextAccount] = useAccountFromContext(!account && required)
|
|
18
|
-
const [activeAccount] = usePromise(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
const [activeAccount] = usePromise(async () => {
|
|
19
|
+
if (account) {
|
|
20
|
+
return account
|
|
21
|
+
} else if (mnemonic) {
|
|
22
|
+
return await HDWallet.fromMnemonic(mnemonic as string)
|
|
23
|
+
} else if (seed) {
|
|
24
|
+
return await HDWallet.fromSeed(seed)
|
|
25
|
+
}
|
|
26
|
+
return contextAccount
|
|
27
|
+
}, [account, mnemonic, contextAccount, seed])
|
|
22
28
|
return usePromise(async () => (path ? await activeAccount?.derivePath?.(path) : activeAccount))
|
|
23
29
|
}
|