@xyo-network/react-wallet 2.56.1 → 2.56.2
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/index.js +1 -0
- package/dist/cjs/hooks/index.js.map +1 -1
- package/dist/cjs/hooks/useWrapperWallet.js +29 -0
- package/dist/cjs/hooks/useWrapperWallet.js.map +1 -0
- package/dist/docs.json +202 -143
- package/dist/esm/hooks/index.js +1 -0
- package/dist/esm/hooks/index.js.map +1 -1
- package/dist/esm/hooks/useWrapperWallet.js +24 -0
- package/dist/esm/hooks/useWrapperWallet.js.map +1 -0
- package/dist/types/hooks/index.d.ts +1 -0
- package/dist/types/hooks/index.d.ts.map +1 -1
- package/dist/types/hooks/useWrapperWallet.d.ts +3 -0
- package/dist/types/hooks/useWrapperWallet.d.ts.map +1 -0
- package/package.json +9 -8
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useWrapperWallet.tsx +25 -0
package/dist/esm/hooks/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,oBAAoB,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { usePromise } from '@xylabs/react-promise';
|
|
2
|
+
import { HDWallet } from '@xyo-network/account';
|
|
3
|
+
import { Mutex } from 'async-mutex';
|
|
4
|
+
let globalWrapperWallet = undefined;
|
|
5
|
+
const globalWrapperWalletMutex = new Mutex();
|
|
6
|
+
export const useWrapperWallet = () => {
|
|
7
|
+
const [wallet] = usePromise(async () => {
|
|
8
|
+
return await globalWrapperWalletMutex.runExclusive(async () => {
|
|
9
|
+
if (globalWrapperWallet) {
|
|
10
|
+
return globalWrapperWallet;
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
globalWrapperWallet = await HDWallet.random();
|
|
14
|
+
}
|
|
15
|
+
catch (ex) {
|
|
16
|
+
const error = ex;
|
|
17
|
+
console.error(`Wrapper Wallet Creation Failed: ${error.message}`);
|
|
18
|
+
}
|
|
19
|
+
return globalWrapperWallet;
|
|
20
|
+
});
|
|
21
|
+
}, []);
|
|
22
|
+
return wallet;
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=useWrapperWallet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useWrapperWallet.js","sourceRoot":"","sources":["../../../src/hooks/useWrapperWallet.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAE/C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAEnC,IAAI,mBAAmB,GAA+B,SAAS,CAAA;AAC/D,MAAM,wBAAwB,GAAG,IAAI,KAAK,EAAE,CAAA;AAE5C,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAA+B,EAAE;IAC/D,MAAM,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC,KAAK,IAAI,EAAE;QACrC,OAAO,MAAM,wBAAwB,CAAC,YAAY,CAAC,KAAK,IAAI,EAAE;YAC5D,IAAI,mBAAmB,EAAE;gBACvB,OAAO,mBAAmB,CAAA;aAC3B;YACD,IAAI;gBACF,mBAAmB,GAAG,MAAM,QAAQ,CAAC,MAAM,EAAE,CAAA;aAC9C;YAAC,OAAO,EAAE,EAAE;gBACX,MAAM,KAAK,GAAG,EAAW,CAAA;gBACzB,OAAO,CAAC,KAAK,CAAC,mCAAmC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;aAClE;YACD,OAAO,mBAAmB,CAAA;QAC5B,CAAC,CAAC,CAAA;IACJ,CAAC,EAAE,EAAE,CAAC,CAAA;IACN,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,oBAAoB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useWrapperWallet.d.ts","sourceRoot":"","sources":["../../../src/hooks/useWrapperWallet.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAM1D,eAAO,MAAM,gBAAgB,QAAO,cAAc,GAAG,SAgBpD,CAAA"}
|
package/package.json
CHANGED
|
@@ -24,10 +24,11 @@
|
|
|
24
24
|
"@xyo-network/account-model": "^2.64.1",
|
|
25
25
|
"@xyo-network/bip39": "^2.64.1",
|
|
26
26
|
"@xyo-network/core": "^2.64.1",
|
|
27
|
-
"@xyo-network/react-address-render": "^2.56.
|
|
28
|
-
"@xyo-network/react-network": "^2.56.
|
|
29
|
-
"@xyo-network/react-shared": "^2.56.
|
|
30
|
-
"@xyo-network/wallet-model": "^2.64.1"
|
|
27
|
+
"@xyo-network/react-address-render": "^2.56.2",
|
|
28
|
+
"@xyo-network/react-network": "^2.56.2",
|
|
29
|
+
"@xyo-network/react-shared": "^2.56.2",
|
|
30
|
+
"@xyo-network/wallet-model": "^2.64.1",
|
|
31
|
+
"async-mutex": "^0.4.0"
|
|
31
32
|
},
|
|
32
33
|
"peerDependencies": {
|
|
33
34
|
"@mui/icons-material": "^5",
|
|
@@ -41,9 +42,9 @@
|
|
|
41
42
|
"description": "Common React library for all XYO projects that use React",
|
|
42
43
|
"devDependencies": {
|
|
43
44
|
"@storybook/react": "^7.0.24",
|
|
44
|
-
"@xylabs/ts-scripts-yarn3": "^2.
|
|
45
|
-
"@xylabs/tsconfig-react": "^2.
|
|
46
|
-
"@xyo-network/react-storybook": "^2.56.
|
|
45
|
+
"@xylabs/ts-scripts-yarn3": "^2.18.2",
|
|
46
|
+
"@xylabs/tsconfig-react": "^2.18.2",
|
|
47
|
+
"@xyo-network/react-storybook": "^2.56.2",
|
|
47
48
|
"typescript": "^5.1.6"
|
|
48
49
|
},
|
|
49
50
|
"browser": "dist/esm/index.js",
|
|
@@ -88,5 +89,5 @@
|
|
|
88
89
|
},
|
|
89
90
|
"sideEffects": false,
|
|
90
91
|
"types": "dist/types/index.d.ts",
|
|
91
|
-
"version": "2.56.
|
|
92
|
+
"version": "2.56.2"
|
|
92
93
|
}
|
package/src/hooks/index.ts
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { usePromise } from '@xylabs/react-promise'
|
|
2
|
+
import { HDWallet } from '@xyo-network/account'
|
|
3
|
+
import { WalletInstance } from '@xyo-network/wallet-model'
|
|
4
|
+
import { Mutex } from 'async-mutex'
|
|
5
|
+
|
|
6
|
+
let globalWrapperWallet: WalletInstance | undefined = undefined
|
|
7
|
+
const globalWrapperWalletMutex = new Mutex()
|
|
8
|
+
|
|
9
|
+
export const useWrapperWallet = (): WalletInstance | undefined => {
|
|
10
|
+
const [wallet] = usePromise(async () => {
|
|
11
|
+
return await globalWrapperWalletMutex.runExclusive(async () => {
|
|
12
|
+
if (globalWrapperWallet) {
|
|
13
|
+
return globalWrapperWallet
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
globalWrapperWallet = await HDWallet.random()
|
|
17
|
+
} catch (ex) {
|
|
18
|
+
const error = ex as Error
|
|
19
|
+
console.error(`Wrapper Wallet Creation Failed: ${error.message}`)
|
|
20
|
+
}
|
|
21
|
+
return globalWrapperWallet
|
|
22
|
+
})
|
|
23
|
+
}, [])
|
|
24
|
+
return wallet
|
|
25
|
+
}
|