react-web3-storage 1.0.7 → 1.0.9

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/package.json CHANGED
@@ -1,16 +1,17 @@
1
1
  {
2
2
  "name": "react-web3-storage",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "Simple web3 storage for react dapp",
5
5
  "main": "src/index.js",
6
6
  "author": "Stas Prohetamine",
7
7
  "license": "ISC",
8
8
  "dependencies": {
9
- "promise-queue": "^2.2.5",
10
- "sleep-promise": "^9.1.0",
11
9
  "@reown/appkit": "^1.8.16",
12
10
  "@reown/appkit-adapter-ethers": "^1.8.16",
13
- "ethers": "^6.16.0"
11
+ "ethers": "^6.16.0",
12
+ "md5": "^2.3.0",
13
+ "promise-queue": "^2.2.5",
14
+ "sleep-promise": "^9.1.0"
14
15
  },
15
16
  "peerDependencies": {
16
17
  "@reown/appkit": "^1.8.16",
@@ -20,11 +21,11 @@
20
21
  "react-dom": "^18.0.0 || ^19.0.0"
21
22
  },
22
23
  "devDependencies": {
23
- "react": "^18.0.0 || ^19.0.0",
24
- "react-dom": "^18.0.0 || ^19.0.0",
25
- "tsup": "^8.5.1",
26
24
  "@reown/appkit": "^1.8.16",
27
25
  "@reown/appkit-adapter-ethers": "^1.8.16",
28
- "ethers": "^6.16.0"
26
+ "ethers": "^6.16.0",
27
+ "react": "^18.0.0 || ^19.0.0",
28
+ "react-dom": "^18.0.0 || ^19.0.0",
29
+ "tsup": "^8.5.1"
29
30
  }
30
31
  }
package/src/provider.js CHANGED
@@ -1,11 +1,12 @@
1
1
  import { createAppKit, AppKitProvider } from '@reown/appkit/react'
2
2
  import { EthersAdapter } from '@reown/appkit-adapter-ethers'
3
+ import md5 from 'md5'
3
4
 
4
5
  import _config from '../config.js'
5
6
 
6
7
  const Provider = ({ children, config }) => {
7
- if (!window.GOBAL_REACT_WEB3_STORAGE_createdAppKit) {
8
- window.GOBAL_REACT_WEB3_STORAGE_createdAppKit = true
8
+ if (!window.GOBAL_REACT_WEB3_createdAppKit) {
9
+ window.GOBAL_REACT_WEB3_createdAppKit = true
9
10
  createAppKit({
10
11
  projectId: config.projectId,
11
12
  adapters: [new EthersAdapter()],
@@ -14,8 +15,12 @@ const Provider = ({ children, config }) => {
14
15
  })
15
16
  }
16
17
 
18
+ if (config.host) {
19
+ window.GOBAL_REACT_WEB3_hostHash = md5(config.host) || md5(window.location.host)
20
+ }
21
+
17
22
  if (config.defaultNetwork) {
18
- window.GOBAL_REACT_WEB3_STORAGE_networkIndex = _config.blockChainsData.findIndex(({ name }) => config.defaultNetwork === name)
23
+ window.GOBAL_REACT_WEB3_networkIndex = _config.blockChainsData.findIndex(({ name }) => config.defaultNetwork === name)
19
24
  }
20
25
 
21
26
  return AppKitProvider({ children, ...config })
@@ -19,7 +19,7 @@ const usePrivateStorage = (_id, value = '') => {
19
19
  msg: null
20
20
  })
21
21
 
22
- let id = `${location.host}-${_id}`
22
+ let id = `${window.GOBAL_REACT_WEB3_hostHash}-${_id}`
23
23
 
24
24
  const createSignerPrivate = async () => {
25
25
  try {
@@ -19,7 +19,7 @@ const useReadStorage = (_id, _address, value = '') => {
19
19
  msg: null
20
20
  })
21
21
 
22
- let id = `${location.host}-${_id}`
22
+ let id = `${window.GOBAL_REACT_WEB3_hostHash}-${_id}`
23
23
 
24
24
  const createSignerPrivate = async () => {
25
25
  try {
@@ -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[window.GOBAL_REACT_WEB3_STORAGE_networkIndex || 0]
57
+ const { receiver: receiverAddress, publicRpc } = config.blockChainsData[window.GOBAL_REACT_WEB3_networkIndex || 0]
58
58
 
59
59
  const provider = new JsonRpcProvider(publicRpc);
60
60
  const wallet = new Wallet(_wallet.privateKey, provider);
@@ -19,7 +19,7 @@ const useStorage = (_id, value = '') => {
19
19
  msg: null
20
20
  })
21
21
 
22
- let id = `${location.host}-${_id}`
22
+ let id = `${window.GOBAL_REACT_WEB3_hostHash}-${_id}`
23
23
 
24
24
  const createSignerPrivate = async () => {
25
25
  try {
@@ -23,7 +23,7 @@ const useTableStorage = (_id, _address) => {
23
23
  msg: null
24
24
  })
25
25
 
26
- let id = `${location.host}-${_id}`
26
+ let id = `${window.GOBAL_REACT_WEB3_hostHash}-${_id}`
27
27
 
28
28
  const createSignerPrivate = async () => {
29
29
  if (!walletProvider || !address) {
@@ -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[window.GOBAL_REACT_WEB3_STORAGE_networkIndex || 0]
115
+ const { receiver: receiverAddress, publicRpc } = config.blockChainsData[window.GOBAL_REACT_WEB3_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[window.GOBAL_REACT_WEB3_STORAGE_networkIndex || 0]
162
+ const { receiver: receiverAddress, publicRpc } = config.blockChainsData[window.GOBAL_REACT_WEB3_networkIndex || 0]
163
163
 
164
164
  const provider = new JsonRpcProvider(publicRpc);
165
165
  const wallet = new Wallet(_wallet.privateKey, provider);