@xyo-network/react-wallet 2.55.4 → 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.
@@ -1,20 +1,35 @@
1
1
  import { HDWallet } from '@xyo-network/account';
2
2
  import { usePromise } from '@xyo-network/react-shared';
3
+ import { useState } from 'react';
3
4
  import { useAccountFromContext } from '../contexts';
4
5
  export const useAccount = ({ mnemonic, account, path, required, seed } = {}) => {
6
+ const [error, setError] = useState();
5
7
  const [contextAccount] = useAccountFromContext(!account && required);
6
8
  const [activeAccount] = usePromise(async () => {
7
- if (account) {
8
- return account;
9
+ try {
10
+ const newAccount = await (() => {
11
+ if (account) {
12
+ return account;
13
+ }
14
+ else if (mnemonic) {
15
+ return HDWallet.fromMnemonic(mnemonic);
16
+ }
17
+ else if (seed) {
18
+ return HDWallet.fromSeed(seed);
19
+ }
20
+ return contextAccount;
21
+ })();
22
+ if (path) {
23
+ return newAccount?.derivePath?.(path);
24
+ }
25
+ else {
26
+ return newAccount;
27
+ }
9
28
  }
10
- else if (mnemonic) {
11
- return await HDWallet.fromMnemonic(mnemonic);
29
+ catch (ex) {
30
+ setError(ex);
12
31
  }
13
- else if (seed) {
14
- return await HDWallet.fromSeed(seed);
15
- }
16
- return contextAccount;
17
- }, [account, mnemonic, contextAccount, seed]);
18
- return usePromise(async () => (path ? await activeAccount?.derivePath?.(path) : activeAccount));
32
+ }, [account, mnemonic, contextAccount, seed, path]);
33
+ return [activeAccount, error];
19
34
  };
20
35
  //# 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,CAAC,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AAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,EAAS,CAAA;IAC3C,MAAM,CAAC,cAAc,CAAC,GAAG,qBAAqB,CAAC,CAAC,OAAO,IAAI,QAAQ,CAAC,CAAA;IACpE,MAAM,CAAC,aAAa,CAAC,GAAG,UAAU,CAAC,KAAK,IAAI,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,QAAQ,CAAC,YAAY,CAAC,QAAkB,CAAC,CAAA;iBACjD;qBAAM,IAAI,IAAI,EAAE;oBACf,OAAO,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;iBAC/B;gBACD,OAAO,cAAc,CAAA;YACvB,CAAC,CAAC,EAAE,CAAA;YACJ,IAAI,IAAI,EAAE;gBACR,OAAO,UAAU,EAAE,UAAU,EAAE,CAAC,IAAI,CAAC,CAAA;aACtC;iBAAM;gBACL,OAAO,UAAU,CAAA;aAClB;SACF;QAAC,OAAO,EAAE,EAAE;YACX,QAAQ,CAAC,EAAW,CAAC,CAAA;SACtB;IACH,CAAC,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;IACnD,OAAO,CAAC,aAAa,EAAE,KAAK,CAAC,CAAA;AAC/B,CAAC,CAAA"}
@@ -7,5 +7,5 @@ export interface AccountHookParams {
7
7
  required?: boolean;
8
8
  seed?: DataLike;
9
9
  }
10
- export declare const useAccount: ({ mnemonic, account, path, required, seed }?: AccountHookParams) => [WalletInstance | undefined, Error | undefined, import("@xyo-network/react-shared").State | undefined];
10
+ export declare const useAccount: ({ mnemonic, account, path, required, seed }?: AccountHookParams) => [WalletInstance | undefined, Error | undefined];
11
11
  //# sourceMappingURL=useAccount.d.ts.map
@@ -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,2GAaxF,CAAA"}
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;AAK1D,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,KAAQ,CAAC,cAAc,GAAG,SAAS,EAAE,KAAK,GAAG,SAAS,CAyB9I,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.4",
25
- "@xyo-network/react-network": "^2.55.4",
26
- "@xyo-network/react-shared": "^2.55.4",
24
+ "@xyo-network/react-address-render": "^2.55.5",
25
+ "@xyo-network/react-network": "^2.55.5",
26
+ "@xyo-network/react-shared": "^2.55.5",
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.4",
43
+ "@xyo-network/react-storybook": "^2.55.5",
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.4"
88
+ "version": "2.55.5"
89
89
  }
@@ -2,6 +2,7 @@ import { HDWallet } from '@xyo-network/account'
2
2
  import { DataLike } from '@xyo-network/core'
3
3
  import { usePromise } from '@xyo-network/react-shared'
4
4
  import { WalletInstance } from '@xyo-network/wallet-model'
5
+ import { useState } from 'react'
5
6
 
6
7
  import { useAccountFromContext } from '../contexts'
7
8
 
@@ -13,17 +14,29 @@ export interface AccountHookParams {
13
14
  seed?: DataLike
14
15
  }
15
16
 
16
- export const useAccount = ({ mnemonic, account, path, required, seed }: AccountHookParams = {}) => {
17
+ export const useAccount = ({ mnemonic, account, path, required, seed }: AccountHookParams = {}): [WalletInstance | undefined, Error | undefined] => {
18
+ const [error, setError] = useState<Error>()
17
19
  const [contextAccount] = useAccountFromContext(!account && required)
18
20
  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)
21
+ try {
22
+ const newAccount = await (() => {
23
+ if (account) {
24
+ return account
25
+ } else if (mnemonic) {
26
+ return HDWallet.fromMnemonic(mnemonic as string)
27
+ } else if (seed) {
28
+ return HDWallet.fromSeed(seed)
29
+ }
30
+ return contextAccount
31
+ })()
32
+ if (path) {
33
+ return newAccount?.derivePath?.(path)
34
+ } else {
35
+ return newAccount
36
+ }
37
+ } catch (ex) {
38
+ setError(ex as Error)
25
39
  }
26
- return contextAccount
27
- }, [account, mnemonic, contextAccount, seed])
28
- return usePromise(async () => (path ? await activeAccount?.derivePath?.(path) : activeAccount))
40
+ }, [account, mnemonic, contextAccount, seed, path])
41
+ return [activeAccount, error]
29
42
  }