react-web3-storage 1.0.6 → 1.0.7
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/config.js +1 -1
- package/package.json +1 -1
- package/src/provider.js +6 -2
- package/src/use-read-storage.js +11 -2
- package/src/use-table-storage.js +4 -4
package/config.js
CHANGED
|
@@ -7,7 +7,7 @@ const blockChainsData = [
|
|
|
7
7
|
name: 'unknown',
|
|
8
8
|
token: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
|
|
9
9
|
receiver: '0xcbEAF3BDe82155F56486Fb5a1072cb8baAf547cc',
|
|
10
|
-
publicRpc: 'http://
|
|
10
|
+
publicRpc: 'http://127.0.0.1:8545'
|
|
11
11
|
},
|
|
12
12
|
{
|
|
13
13
|
network: bsc,
|
package/package.json
CHANGED
package/src/provider.js
CHANGED
|
@@ -4,8 +4,8 @@ import { EthersAdapter } from '@reown/appkit-adapter-ethers'
|
|
|
4
4
|
import _config from '../config.js'
|
|
5
5
|
|
|
6
6
|
const Provider = ({ children, config }) => {
|
|
7
|
-
if (!window.
|
|
8
|
-
window.
|
|
7
|
+
if (!window.GOBAL_REACT_WEB3_STORAGE_createdAppKit) {
|
|
8
|
+
window.GOBAL_REACT_WEB3_STORAGE_createdAppKit = true
|
|
9
9
|
createAppKit({
|
|
10
10
|
projectId: config.projectId,
|
|
11
11
|
adapters: [new EthersAdapter()],
|
|
@@ -14,6 +14,10 @@ const Provider = ({ children, config }) => {
|
|
|
14
14
|
})
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
if (config.defaultNetwork) {
|
|
18
|
+
window.GOBAL_REACT_WEB3_STORAGE_networkIndex = _config.blockChainsData.findIndex(({ name }) => config.defaultNetwork === name)
|
|
19
|
+
}
|
|
20
|
+
|
|
17
21
|
return AppKitProvider({ children, ...config })
|
|
18
22
|
}
|
|
19
23
|
|
package/src/use-read-storage.js
CHANGED
|
@@ -54,7 +54,7 @@ const useReadStorage = (_id, _address, value = '') => {
|
|
|
54
54
|
try {
|
|
55
55
|
if (addr) {
|
|
56
56
|
const _wallet = Wallet.createRandom();
|
|
57
|
-
const { receiver: receiverAddress, publicRpc } = config.blockChainsData[0]
|
|
57
|
+
const { receiver: receiverAddress, publicRpc } = config.blockChainsData[window.GOBAL_REACT_WEB3_STORAGE_networkIndex || 0]
|
|
58
58
|
|
|
59
59
|
const provider = new JsonRpcProvider(publicRpc);
|
|
60
60
|
const wallet = new Wallet(_wallet.privateKey, provider);
|
|
@@ -88,7 +88,16 @@ const useReadStorage = (_id, _address, value = '') => {
|
|
|
88
88
|
window.GOBAL_PROMISE_QUEUE_WEB3_STORAGE.add(read)
|
|
89
89
|
, 1000)
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
const intervalId = setInterval(() => {
|
|
92
|
+
if (window.GOBAL_PROMISE_QUEUE_WEB3_STORAGE.queue.length === 0) {
|
|
93
|
+
window.GOBAL_PROMISE_QUEUE_WEB3_STORAGE.add(read)
|
|
94
|
+
}
|
|
95
|
+
}, 15000)
|
|
96
|
+
|
|
97
|
+
return () => {
|
|
98
|
+
clearTimeout(timeId)
|
|
99
|
+
clearInterval(intervalId)
|
|
100
|
+
}
|
|
92
101
|
}, [isConnected, _address])
|
|
93
102
|
|
|
94
103
|
return [data, outcome]
|
package/src/use-table-storage.js
CHANGED
|
@@ -112,7 +112,7 @@ const useTableStorage = (_id, _address) => {
|
|
|
112
112
|
const _readRowsCountPublic = async () => {
|
|
113
113
|
try {
|
|
114
114
|
const _wallet = Wallet.createRandom();
|
|
115
|
-
const { receiver: receiverAddress, publicRpc } = config.blockChainsData[0]
|
|
115
|
+
const { receiver: receiverAddress, publicRpc } = config.blockChainsData[window.GOBAL_REACT_WEB3_STORAGE_networkIndex || 0]
|
|
116
116
|
|
|
117
117
|
const provider = new JsonRpcProvider(publicRpc);
|
|
118
118
|
const wallet = new Wallet(_wallet.privateKey, provider);
|
|
@@ -159,7 +159,7 @@ const useTableStorage = (_id, _address) => {
|
|
|
159
159
|
for (let r = 0; r < 100; r++) {
|
|
160
160
|
try {
|
|
161
161
|
const _wallet = Wallet.createRandom();
|
|
162
|
-
const { receiver: receiverAddress, publicRpc } = config.blockChainsData[0]
|
|
162
|
+
const { receiver: receiverAddress, publicRpc } = config.blockChainsData[window.GOBAL_REACT_WEB3_STORAGE_networkIndex || 0]
|
|
163
163
|
|
|
164
164
|
const provider = new JsonRpcProvider(publicRpc);
|
|
165
165
|
const wallet = new Wallet(_wallet.privateKey, provider);
|
|
@@ -233,13 +233,13 @@ const useTableStorage = (_id, _address) => {
|
|
|
233
233
|
|
|
234
234
|
useEffect(() => {
|
|
235
235
|
const timeId = setTimeout(() => {
|
|
236
|
-
if (lastIndex === 0) {
|
|
236
|
+
if (lastIndex === 0 && outcome.type !== 'error') {
|
|
237
237
|
setOutcome({ type: 'loaded', msg: null })
|
|
238
238
|
}
|
|
239
239
|
}, 5000)
|
|
240
240
|
|
|
241
241
|
return () => clearTimeout(timeId)
|
|
242
|
-
}, [lastIndex, updateItemIndex])
|
|
242
|
+
}, [lastIndex, updateItemIndex, outcome])
|
|
243
243
|
|
|
244
244
|
return [items, addItem, updateItem, outcome]
|
|
245
245
|
}
|