@xyo-network/react-wallet 2.60.3 → 2.60.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,8 +1,8 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { usePromise } from '@xylabs/react-promise';
3
2
  import { useEffect, useState } from 'react';
4
3
  import { WalletContext } from './Context';
5
4
  import { WalletRootPath } from './lib';
5
+ import { usePromise } from './usePromise';
6
6
  export const WalletProvider = ({ basePath = WalletRootPath, children, defaultActiveAccountIndex = 0, rootWallet = null, ...props }) => {
7
7
  const [activeAccountIndex, setActiveAccountIndex] = useState(defaultActiveAccountIndex);
8
8
  useEffect(() => {
@@ -26,7 +26,7 @@ export const WalletProvider = ({ basePath = WalletRootPath, children, defaultAct
26
26
  return undefined;
27
27
  }
28
28
  }, [basePath, rootWallet]);
29
- const [activeAccount = null] = usePromise(() => coinTypeWallet?.derivePath(activeAccountIndex.toString()), [coinTypeWallet, activeAccountIndex]);
29
+ const [activeAccount = null] = usePromise(async () => await coinTypeWallet?.derivePath(activeAccountIndex.toString()), [coinTypeWallet, activeAccountIndex]);
30
30
  return (_jsx(WalletContext.Provider, { value: {
31
31
  activeAccount,
32
32
  activeAccountIndex,
@@ -1 +1 @@
1
- {"version":3,"file":"Provider.js","sourceRoot":"","sources":["../../../../src/contexts/Wallet/Provider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAGlD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAE3C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AAQtC,MAAM,CAAC,MAAM,cAAc,GAAgD,CAAC,EAC1E,QAAQ,GAAG,cAAc,EACzB,QAAQ,EACR,yBAAyB,GAAG,CAAC,EAC7B,UAAU,GAAG,IAAI,EACjB,GAA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,kBAAkB,CAAC,QAAQ,EAAE,CAAC,EAC3E,CAAC,cAAc,EAAE,kBAAkB,CAAC,CACrC,CAAA;IAED,OAAO,CACL,KAAC,aAAa,CAAC,QAAQ,IACrB,KAAK,EAAE;YACL,aAAa;YACb,kBAAkB;YAClB,QAAQ;YACR,cAAc;YACd,QAAQ,EAAE,IAAI;YACd,UAAU;YACV,qBAAqB;SACtB,KACG,KAAK,YAER,QAAQ,GACc,CAC1B,CAAA;AACH,CAAC,CAAA"}
@@ -0,0 +1,80 @@
1
+ // Inspired from https://github.com/bsonntag/react-use-promise
2
+ import { Mutex } from 'async-mutex';
3
+ import { useEffect, useMemo, useState } from 'react';
4
+ export var State;
5
+ (function (State) {
6
+ State["pending"] = "pending";
7
+ State["rejected"] = "rejected";
8
+ State["resolved"] = "resolved";
9
+ })(State || (State = {}));
10
+ /**
11
+ * usePromise -
12
+ */
13
+ export const usePromise = (promise, dependencies, debug = undefined) => {
14
+ const [result, setResult] = useState();
15
+ const [error, setError] = useState();
16
+ const [state, setState] = useState(State.pending);
17
+ const mutex = useMemo(() => {
18
+ return new Mutex();
19
+ }, []);
20
+ if (debug)
21
+ console.log(`usePromise [${debug}]: started [${typeof promise}]`);
22
+ const promiseMemo = useMemo(() => {
23
+ try {
24
+ if (debug)
25
+ console.log(`usePromise [${debug}]: re-memo [${typeof promise}]`);
26
+ setState(State.pending);
27
+ return promise?.();
28
+ }
29
+ catch (e) {
30
+ if (debug)
31
+ console.log(`usePromise [${debug}]: useMemo rejection [${typeof promise}]`);
32
+ setResult(undefined);
33
+ setError(e);
34
+ setState(State.rejected);
35
+ }
36
+ }, dependencies);
37
+ if (debug)
38
+ console.log(`usePromise [${debug}] Main Function`);
39
+ useEffect(() => {
40
+ if (debug)
41
+ console.log(`usePromise [${debug}] useEffect`);
42
+ mutex
43
+ ?.acquire()
44
+ .then(() => {
45
+ promiseMemo
46
+ ?.then((payload) => {
47
+ if (debug)
48
+ console.log(`usePromise [${debug}] then`);
49
+ setResult(payload);
50
+ setError(undefined);
51
+ setState(State.resolved);
52
+ mutex?.release();
53
+ })
54
+ .catch((e) => {
55
+ const error = e;
56
+ console.error(`usePromise: ${error.message}`);
57
+ setResult(undefined);
58
+ setError(error);
59
+ setState(State.rejected);
60
+ mutex?.release();
61
+ });
62
+ })
63
+ .catch((e) => {
64
+ const error = e;
65
+ console.error(`usePromise: ${error.message}`);
66
+ setResult(undefined);
67
+ setError(error);
68
+ setState(State.rejected);
69
+ mutex?.release();
70
+ });
71
+ return () => {
72
+ if (debug)
73
+ console.log(`usePromise [${debug}] useEffect callback`);
74
+ };
75
+ }, [...dependencies, promiseMemo]);
76
+ if (debug)
77
+ console.log(`usePromise [${debug}] returning ${JSON.stringify([result, error, state], null, 2)}`);
78
+ return [result, error, state];
79
+ };
80
+ //# sourceMappingURL=usePromise.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePromise.js","sourceRoot":"","sources":["../../../../src/contexts/Wallet/usePromise.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAE9D,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACnC,OAAO,EAAkB,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEpE,MAAM,CAAN,IAAY,KAIX;AAJD,WAAY,KAAK;IACf,4BAAmB,CAAA;IACnB,8BAAqB,CAAA;IACrB,8BAAqB,CAAA;AACvB,CAAC,EAJW,KAAK,KAAL,KAAK,QAIhB;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,OAA2C,EAC3C,YAA4B,EAC5B,QAA4B,SAAS,EACwB,EAAE;IAC/D,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,EAAW,CAAA;IAC/C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,EAAS,CAAA;IAC3C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAQ,KAAK,CAAC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,CAAA;AAC/B,CAAC,CAAA"}
@@ -4,7 +4,7 @@ import { useWallet } from './useWallet';
4
4
  export const useWallets = ({ wallet, paths }) => {
5
5
  const walletContextProvided = useWalletProvided();
6
6
  const [foundWallet] = useWallet({ wallet });
7
- const [wallets, error] = usePromise(() => (foundWallet ? Promise.all(paths.map((path) => foundWallet.derivePath(path))) : undefined), [foundWallet, paths]);
7
+ const [wallets, error] = usePromise(async () => (foundWallet ? await Promise.all(paths.map((path) => foundWallet.derivePath(path))) : undefined), [foundWallet, paths]);
8
8
  return [wallets ?? (walletContextProvided ? null : wallets), error];
9
9
  };
10
10
  //# sourceMappingURL=useWallets.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useWallets.js","sourceRoot":"","sources":["../../../src/hooks/useWallets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAGlD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAOvC,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,EAAE,MAAM,EAAE,KAAK,EAAqB,EAA4D,EAAE;IAC3H,MAAM,qBAAqB,GAAG,iBAAiB,EAAE,CAAA;IACjD,MAAM,CAAC,WAAW,CAAC,GAAG,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC,CAAA;IAC3C,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,GAAG,UAAU,CACjC,GAAG,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,EAChG,CAAC,WAAW,EAAE,KAAK,CAAC,CACrB,CAAA;IACD,OAAO,CAAC,OAAO,IAAI,CAAC,qBAAqB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,CAAA;AACrE,CAAC,CAAA"}
1
+ {"version":3,"file":"useWallets.js","sourceRoot":"","sources":["../../../src/hooks/useWallets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAGlD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAOvC,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,EAAE,MAAM,EAAE,KAAK,EAAqB,EAA4D,EAAE;IAC3H,MAAM,qBAAqB,GAAG,iBAAiB,EAAE,CAAA;IACjD,MAAM,CAAC,WAAW,CAAC,GAAG,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC,CAAA;IAC3C,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,GAAG,UAAU,CACjC,KAAK,IAAI,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,EAC5G,CAAC,WAAW,EAAE,KAAK,CAAC,CACrB,CAAA;IACD,OAAO,CAAC,OAAO,IAAI,CAAC,qBAAqB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,CAAA;AACrE,CAAC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["../../../../src/contexts/Wallet/Provider.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAM1D,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,yBAAyB,CAAC,EAAE,MAAM,CAAA;IAClC,UAAU,CAAC,EAAE,cAAc,GAAG,IAAI,CAAA;CACnC;AAED,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,mBAAmB,CAAC,CAgDtE,CAAA"}
1
+ {"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["../../../../src/contexts/Wallet/Provider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAO1D,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,yBAAyB,CAAC,EAAE,MAAM,CAAA;IAClC,UAAU,CAAC,EAAE,cAAc,GAAG,IAAI,CAAA;CACnC;AAED,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,mBAAmB,CAAC,CAmDtE,CAAA"}
@@ -0,0 +1,11 @@
1
+ import { DependencyList } from 'react';
2
+ export declare enum State {
3
+ pending = "pending",
4
+ rejected = "rejected",
5
+ resolved = "resolved"
6
+ }
7
+ /**
8
+ * usePromise -
9
+ */
10
+ export declare const usePromise: <TResult>(promise: () => Promise<TResult | undefined>, dependencies: DependencyList, debug?: string | undefined) => [TResult | undefined, Error | undefined, State | undefined];
11
+ //# sourceMappingURL=usePromise.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePromise.d.ts","sourceRoot":"","sources":["../../../../src/contexts/Wallet/usePromise.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAgC,MAAM,OAAO,CAAA;AAEpE,oBAAY,KAAK;IACf,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,QAAQ,aAAa;CACtB;AAED;;GAEG;AACH,eAAO,MAAM,UAAU,+FAGd,MAAM,GAAG,SAAS,gEA8D1B,CAAA"}
package/package.json CHANGED
@@ -11,23 +11,23 @@
11
11
  },
12
12
  "dependencies": {
13
13
  "@xylabs/eth-address": "^2.9.3",
14
- "@xylabs/react-button": "~2.17.8",
15
- "@xylabs/react-crypto": "~2.17.8",
16
- "@xylabs/react-flexbox": "~2.17.8",
17
- "@xylabs/react-identicon": "~2.17.8",
18
- "@xylabs/react-number-status": "~2.17.8",
19
- "@xylabs/react-promise": "~2.17.8",
20
- "@xylabs/react-quick-tip-button": "~2.17.8",
21
- "@xylabs/react-select": "~2.17.8",
22
- "@xylabs/react-shared": "~2.17.8",
23
- "@xyo-network/account": "^2.70.6",
24
- "@xyo-network/account-model": "^2.70.6",
25
- "@xyo-network/bip39": "^2.70.6",
26
- "@xyo-network/core": "^2.70.6",
27
- "@xyo-network/react-address-render": "~2.60.3",
28
- "@xyo-network/react-network": "~2.60.3",
29
- "@xyo-network/react-shared": "~2.60.3",
30
- "@xyo-network/wallet-model": "^2.70.6",
14
+ "@xylabs/react-button": "~2.17.11",
15
+ "@xylabs/react-crypto": "~2.17.11",
16
+ "@xylabs/react-flexbox": "~2.17.11",
17
+ "@xylabs/react-identicon": "~2.17.11",
18
+ "@xylabs/react-number-status": "~2.17.11",
19
+ "@xylabs/react-promise": "~2.17.11",
20
+ "@xylabs/react-quick-tip-button": "~2.17.11",
21
+ "@xylabs/react-select": "~2.17.11",
22
+ "@xylabs/react-shared": "~2.17.11",
23
+ "@xyo-network/account": "^2.70.11",
24
+ "@xyo-network/account-model": "^2.70.11",
25
+ "@xyo-network/bip39": "^2.70.11",
26
+ "@xyo-network/core": "^2.70.11",
27
+ "@xyo-network/react-address-render": "~2.60.5",
28
+ "@xyo-network/react-network": "~2.60.5",
29
+ "@xyo-network/react-shared": "~2.60.5",
30
+ "@xyo-network/wallet-model": "^2.70.11",
31
31
  "async-mutex": "^0.4.0"
32
32
  },
33
33
  "peerDependencies": {
@@ -41,10 +41,10 @@
41
41
  },
42
42
  "description": "Common React library for all XYO projects that use React",
43
43
  "devDependencies": {
44
- "@storybook/react": "^7.2.0",
44
+ "@storybook/react": "^7.2.1",
45
45
  "@xylabs/ts-scripts-yarn3": "^2.19.0",
46
46
  "@xylabs/tsconfig-react": "^2.19.0",
47
- "@xyo-network/react-storybook": "~2.60.3",
47
+ "@xyo-network/react-storybook": "~2.60.5",
48
48
  "typescript": "^5.1.6"
49
49
  },
50
50
  "browser": "dist/esm/index.js",
@@ -89,5 +89,5 @@
89
89
  },
90
90
  "sideEffects": false,
91
91
  "types": "dist/types/index.d.ts",
92
- "version": "2.60.3"
92
+ "version": "2.60.5"
93
93
  }
@@ -1,10 +1,10 @@
1
- import { usePromise } from '@xylabs/react-promise'
2
1
  import { WithChildren } from '@xylabs/react-shared'
3
2
  import { WalletInstance } from '@xyo-network/wallet-model'
4
3
  import { useEffect, useState } from 'react'
5
4
 
6
5
  import { WalletContext } from './Context'
7
6
  import { WalletRootPath } from './lib'
7
+ import { usePromise } from './usePromise'
8
8
 
9
9
  export interface WalletProviderProps {
10
10
  basePath?: string
@@ -42,7 +42,10 @@ export const WalletProvider: React.FC<WithChildren<WalletProviderProps>> = ({
42
42
  }
43
43
  }, [basePath, rootWallet])
44
44
 
45
- const [activeAccount = null] = usePromise(() => coinTypeWallet?.derivePath(activeAccountIndex.toString()), [coinTypeWallet, activeAccountIndex])
45
+ const [activeAccount = null] = usePromise(
46
+ async () => await coinTypeWallet?.derivePath(activeAccountIndex.toString()),
47
+ [coinTypeWallet, activeAccountIndex],
48
+ )
46
49
 
47
50
  return (
48
51
  <WalletContext.Provider
@@ -0,0 +1,80 @@
1
+ // Inspired from https://github.com/bsonntag/react-use-promise
2
+
3
+ import { Mutex } from 'async-mutex'
4
+ import { DependencyList, useEffect, useMemo, useState } from 'react'
5
+
6
+ export enum State {
7
+ pending = 'pending',
8
+ rejected = 'rejected',
9
+ resolved = 'resolved',
10
+ }
11
+
12
+ /**
13
+ * usePromise -
14
+ */
15
+ export const usePromise = <TResult>(
16
+ promise: () => Promise<TResult | undefined>,
17
+ dependencies: DependencyList,
18
+ debug: string | undefined = undefined,
19
+ ): [TResult | undefined, Error | undefined, State | undefined] => {
20
+ const [result, setResult] = useState<TResult>()
21
+ const [error, setError] = useState<Error>()
22
+ const [state, setState] = useState<State>(State.pending)
23
+ const mutex = useMemo(() => {
24
+ return new Mutex()
25
+ }, [])
26
+
27
+ if (debug) console.log(`usePromise [${debug}]: started [${typeof promise}]`)
28
+
29
+ const promiseMemo: Promise<TResult | undefined> | undefined = useMemo(() => {
30
+ try {
31
+ if (debug) console.log(`usePromise [${debug}]: re-memo [${typeof promise}]`)
32
+ setState(State.pending)
33
+ return promise?.()
34
+ } catch (e) {
35
+ if (debug) console.log(`usePromise [${debug}]: useMemo rejection [${typeof promise}]`)
36
+ setResult(undefined)
37
+ setError(e as Error)
38
+ setState(State.rejected)
39
+ }
40
+ }, dependencies)
41
+
42
+ if (debug) console.log(`usePromise [${debug}] Main Function`)
43
+
44
+ useEffect(() => {
45
+ if (debug) console.log(`usePromise [${debug}] useEffect`)
46
+ mutex
47
+ ?.acquire()
48
+ .then(() => {
49
+ promiseMemo
50
+ ?.then((payload) => {
51
+ if (debug) console.log(`usePromise [${debug}] then`)
52
+ setResult(payload)
53
+ setError(undefined)
54
+ setState(State.resolved)
55
+ mutex?.release()
56
+ })
57
+ .catch((e) => {
58
+ const error = e as Error
59
+ console.error(`usePromise: ${error.message}`)
60
+ setResult(undefined)
61
+ setError(error)
62
+ setState(State.rejected)
63
+ mutex?.release()
64
+ })
65
+ })
66
+ .catch((e) => {
67
+ const error = e as Error
68
+ console.error(`usePromise: ${error.message}`)
69
+ setResult(undefined)
70
+ setError(error)
71
+ setState(State.rejected)
72
+ mutex?.release()
73
+ })
74
+ return () => {
75
+ if (debug) console.log(`usePromise [${debug}] useEffect callback`)
76
+ }
77
+ }, [...dependencies, promiseMemo])
78
+ if (debug) console.log(`usePromise [${debug}] returning ${JSON.stringify([result, error, state], null, 2)}`)
79
+ return [result, error, state]
80
+ }
@@ -13,7 +13,7 @@ export const useWallets = ({ wallet, paths }: WalletsHookParams): [WalletInstanc
13
13
  const walletContextProvided = useWalletProvided()
14
14
  const [foundWallet] = useWallet({ wallet })
15
15
  const [wallets, error] = usePromise(
16
- () => (foundWallet ? Promise.all(paths.map((path) => foundWallet.derivePath(path))) : undefined),
16
+ async () => (foundWallet ? await Promise.all(paths.map((path) => foundWallet.derivePath(path))) : undefined),
17
17
  [foundWallet, paths],
18
18
  )
19
19
  return [wallets ?? (walletContextProvided ? null : wallets), error]