react-web3-storage 1.0.63 → 1.1.0
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/PhArrowCircleDown-BR-zH4LC.js +14 -0
- package/dist/PhArrowCircleDown-Sb38khBy.mjs +73 -0
- package/dist/PhArrowClockwise-BE5j9P0Z.mjs +73 -0
- package/dist/PhArrowClockwise-BRaehQGe.js +14 -0
- package/dist/PhArrowDown-B_WmmmY9.js +14 -0
- package/dist/PhArrowDown-CFEyR2dR.mjs +73 -0
- package/dist/PhArrowLeft-CYfU7NZj.mjs +73 -0
- package/dist/PhArrowLeft-CkEd70hm.js +14 -0
- package/dist/PhArrowRight-C07Qkx86.js +14 -0
- package/dist/PhArrowRight-EermNu0V.mjs +73 -0
- package/dist/PhArrowSquareOut-BjTBfzOP.js +14 -0
- package/dist/PhArrowSquareOut-DZwTtw54.mjs +73 -0
- package/dist/PhArrowUp-DB4CCSss.js +14 -0
- package/dist/PhArrowUp-xTpLFQkg.mjs +73 -0
- package/dist/PhArrowUpRight-CQbvn6NO.mjs +73 -0
- package/dist/PhArrowUpRight-GpCIMsAh.js +14 -0
- package/dist/PhArrowsClockwise-BgcIUg-Z.js +14 -0
- package/dist/PhArrowsClockwise-DnUYZTVx.mjs +73 -0
- package/dist/PhArrowsDownUp-C8KXUqtu.js +14 -0
- package/dist/PhArrowsDownUp-DgoprEe2.mjs +73 -0
- package/dist/PhArrowsLeftRight-CahChzCj.js +14 -0
- package/dist/PhArrowsLeftRight-FD4AZiLh.mjs +73 -0
- package/dist/PhBank-DIqIL4x_.js +14 -0
- package/dist/PhBank-DbQOQ9zJ.mjs +73 -0
- package/dist/PhBrowser-BCBXK2IM.mjs +73 -0
- package/dist/PhBrowser-laCKtn7T.js +14 -0
- package/dist/PhCaretDown-CnjP-QjZ.mjs +73 -0
- package/dist/PhCaretDown-DDe42xDU.js +14 -0
- package/dist/PhCaretLeft-Cskc5OY9.js +14 -0
- package/dist/PhCaretLeft-DkuXxjf_.mjs +73 -0
- package/dist/PhCaretRight-CBWpghxt.mjs +73 -0
- package/dist/PhCaretRight-DNgI5w_B.js +14 -0
- package/dist/PhCaretUp-CQ-OztBV.mjs +73 -0
- package/dist/PhCaretUp-CUZ4g_Me.js +14 -0
- package/dist/PhCheck-BVV_Dwfo.js +14 -0
- package/dist/PhCheck-t515emYS.mjs +73 -0
- package/dist/PhCircleHalf-BuQTmrKW.mjs +73 -0
- package/dist/PhCircleHalf-DDC7rige.js +14 -0
- package/dist/PhClock-BqynEKWl.js +14 -0
- package/dist/PhClock-D6XkTmM_.mjs +73 -0
- package/dist/PhCompass-2QeeX5Ad.mjs +73 -0
- package/dist/PhCompass-BsuJwXAE.js +14 -0
- package/dist/PhCopy-CO34-_xD.mjs +73 -0
- package/dist/PhCopy-MVqtRS6X.js +14 -0
- package/dist/PhCreditCard-Dq4kdjCw.js +14 -0
- package/dist/PhCreditCard-bfnqYflD.mjs +73 -0
- package/dist/PhCurrencyDollar-6k8UWxal.js +14 -0
- package/dist/PhCurrencyDollar-BekVYPtC.mjs +73 -0
- package/dist/PhDesktop-BkNzf3rT.mjs +73 -0
- package/dist/PhDesktop-CfsXQ0vC.js +14 -0
- package/dist/PhDeviceMobile-BT3Mg_b0.mjs +73 -0
- package/dist/PhDeviceMobile-BnrrDrwf.js +14 -0
- package/dist/PhDotsThree-6LRvhAcL.js +14 -0
- package/dist/PhDotsThree-kpf2OKxJ.mjs +73 -0
- package/dist/PhEnvelope-CHsfC2e0.js +14 -0
- package/dist/PhEnvelope-UFKpKtwf.mjs +73 -0
- package/dist/PhFunnelSimple-CdAqSIhK.mjs +73 -0
- package/dist/PhFunnelSimple-JAk7X9Wo.js +14 -0
- package/dist/PhGlobe-B3RYXl8h.mjs +73 -0
- package/dist/PhGlobe-Tfs4MfpG.js +14 -0
- package/dist/PhIdentificationCard-Dqmd6eY1.js +14 -0
- package/dist/PhIdentificationCard-rSq59Czm.mjs +73 -0
- package/dist/PhImage-aEryzfCi.js +14 -0
- package/dist/PhImage-ynsEnFd_.mjs +73 -0
- package/dist/PhInfo-B7lsWl6m.mjs +73 -0
- package/dist/PhInfo-D6oUrWpA.js +14 -0
- package/dist/PhLightbulb-FQDaMMqu.mjs +73 -0
- package/dist/PhLightbulb-qbEduhPa.js +14 -0
- package/dist/PhMagnifyingGlass-COdRH2k5.js +14 -0
- package/dist/PhMagnifyingGlass-_NXk13-0.mjs +73 -0
- package/dist/PhPaperPlaneRight-BYi7SorW.mjs +73 -0
- package/dist/PhPaperPlaneRight-DrpVAQOZ.js +14 -0
- package/dist/PhPlus-25KQTPHG.mjs +73 -0
- package/dist/PhPlus-BhUXef08.js +14 -0
- package/dist/PhPower-BKl7gzsB.mjs +73 -0
- package/dist/PhPower-BNJf1AGQ.js +14 -0
- package/dist/PhPuzzlePiece-BkZeF8CX.js +14 -0
- package/dist/PhPuzzlePiece-BqUI4GRs.mjs +73 -0
- package/dist/PhQrCode-C-tqZKPP.mjs +73 -0
- package/dist/PhQrCode-C0v0iXQN.js +14 -0
- package/dist/PhQuestion-BBAiRWgt.js +14 -0
- package/dist/PhQuestion-CtYvffyD.mjs +73 -0
- package/dist/PhQuestionMark-BNbtL2yx.mjs +73 -0
- package/dist/PhQuestionMark-BvGUBZ1h.js +14 -0
- package/dist/PhSealCheck-B0TEqWpq.mjs +73 -0
- package/dist/PhSealCheck-BwNkuF7G.js +14 -0
- package/dist/PhSignOut-C1rMSNaS.js +14 -0
- package/dist/PhSignOut-HX2_BVsD.mjs +73 -0
- package/dist/PhSpinner-CoDYLYOX.mjs +73 -0
- package/dist/PhSpinner-nmsGWDQl.js +14 -0
- package/dist/PhTrash-CALlKx3e.js +14 -0
- package/dist/PhTrash-DeQHS8ZP.mjs +73 -0
- package/dist/PhUser-CA0e5OPI.js +14 -0
- package/dist/PhUser-Cy5EY3vX.mjs +73 -0
- package/dist/PhVault-DdXjVOO9.mjs +73 -0
- package/dist/PhVault-DqxV75cz.js +14 -0
- package/dist/PhWallet-CeQrfGYc.mjs +73 -0
- package/dist/PhWallet-CyCuEs2U.js +14 -0
- package/dist/PhWarning-BKaHv_wT.mjs +73 -0
- package/dist/PhWarning-C7oj86bY.js +14 -0
- package/dist/PhWarningCircle-8MWw-QgE.mjs +73 -0
- package/dist/PhWarningCircle-CrNPXGj4.js +14 -0
- package/dist/PhX-9lsrXjyl.js +14 -0
- package/dist/PhX-DgXr_Fb0.mjs +73 -0
- package/dist/ReownAuthentication-CAiTtWE5.js +5 -0
- package/dist/ReownAuthentication-CE26uZpr.mjs +274 -0
- package/dist/SwapController-IE-9UN8T.js +1 -0
- package/dist/SwapController-sJUkOlKM.mjs +462 -0
- package/dist/ccip-DtOTIGBy.js +1 -0
- package/dist/ccip-DwIyS7_y.mjs +150 -0
- package/dist/data-capture-BRFlaLGs.js +242 -0
- package/dist/data-capture-CA5JJz0T.mjs +489 -0
- package/dist/email-BqnUUnkE.js +90 -0
- package/dist/email-C8Wfg0DW.mjs +338 -0
- package/dist/embedded-wallet-C3_Wuw8u.js +410 -0
- package/dist/embedded-wallet-DkhXdUnx.mjs +808 -0
- package/dist/features-BZoggdON.mjs +5 -0
- package/dist/features-I8DYEMV3.js +1 -0
- package/dist/index-BEd4u0iw.js +1 -0
- package/dist/index-BPYAlSd6.js +132 -0
- package/dist/index-BPZW2omQ.js +7203 -0
- package/dist/index-ByqXOARw.mjs +8792 -0
- package/dist/index-C9SAkqXG.js +1062 -0
- package/dist/index-CUlQi2EX.mjs +196 -0
- package/dist/index-CeLUBlqr.mjs +68752 -0
- package/dist/index-CkXotluz.mjs +151 -0
- package/dist/index-D0UfsSF5.mjs +2685 -0
- package/dist/index-DHltz-x1.mjs +215 -0
- package/dist/index-DRVHsNBA.mjs +352 -0
- package/dist/index-DRatSA2B.mjs +267 -0
- package/dist/index-DU5uzJkT.js +17 -0
- package/dist/index-DpGkNMqj.js +1 -0
- package/dist/index-cmRavC33.js +1 -0
- package/dist/index-lZ8cTWip.js +138 -0
- package/dist/index-uhM-Uk4v.js +78 -0
- package/dist/index-wms889HG.mjs +35 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.es.js +10 -0
- package/dist/onramp-De_bA1w6.mjs +842 -0
- package/dist/onramp-EIHCZ9g_.js +422 -0
- package/dist/parseSignature-BvqB8KFD.js +16 -0
- package/dist/parseSignature-D375GU0u.mjs +8465 -0
- package/dist/pay-with-exchange-Cgpar9Ud.mjs +512 -0
- package/dist/pay-with-exchange-DGovmrR0.js +280 -0
- package/dist/property-Bd8U3_QP.mjs +618 -0
- package/dist/property-DissjCbZ.js +27 -0
- package/dist/receive-C9PzbXJR.mjs +228 -0
- package/dist/receive-CGS-CjH9.js +131 -0
- package/dist/send-CSXHNfF5.js +554 -0
- package/dist/send-HSo8sShU.mjs +1155 -0
- package/dist/socials-R83S9ZJf.js +250 -0
- package/dist/socials-fJrgkZ_3.mjs +611 -0
- package/dist/swaps-CrrgExrc.mjs +1752 -0
- package/dist/swaps-DV5-oRwn.js +1050 -0
- package/dist/transactions-BQeUJzm6.mjs +35 -0
- package/dist/transactions-DrhN3k8s.js +16 -0
- package/dist/w3m-modal-CgAulf1i.mjs +1759 -0
- package/dist/w3m-modal-CrAjjbwi.js +891 -0
- package/package.json +27 -15
- package/config.js +0 -39
- package/src/index.js +0 -17
- package/src/network-test.js +0 -14
- package/src/provider.js +0 -24
- package/src/use-app.js +0 -10
- package/src/use-private-storage.js +0 -104
- package/src/use-read-storage.js +0 -97
- package/src/use-storage.js +0 -104
- package/src/use-table-storage.js +0 -247
- package/src/web3-storage.sol +0 -198
package/src/use-table-storage.js
DELETED
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
import { useAppKit, useAppKitAccount, useAppKitProvider } from '@reown/appkit/react'
|
|
2
|
-
import { BrowserProvider, Contract, Wallet, JsonRpcProvider } from 'ethers'
|
|
3
|
-
import config from '../config.js'
|
|
4
|
-
import { useEffect, useState } from 'react'
|
|
5
|
-
import sleep from 'sleep-promise'
|
|
6
|
-
import Queue from 'promise-queue'
|
|
7
|
-
|
|
8
|
-
if (!window.GOBAL_PROMISE_QUEUE_WEB3_STORAGE) {
|
|
9
|
-
window.GOBAL_PROMISE_QUEUE_WEB3_STORAGE = new Queue(1, Infinity)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const useTableStorage = (_id, _address) => {
|
|
13
|
-
const { open } = useAppKit()
|
|
14
|
-
, { address, isConnected } = useAppKitAccount({ namespace: 'eip155' })
|
|
15
|
-
, { walletProvider } = useAppKitProvider('eip155')
|
|
16
|
-
|
|
17
|
-
const [isFullLoad, setFullLoad] = useState(false)
|
|
18
|
-
const [updateItemIndex, setUpdateItemIndex] = useState(0)
|
|
19
|
-
const [lastIndex, setLastIndex] = useState(0)
|
|
20
|
-
const [items, setItems] = useState([])
|
|
21
|
-
const [outcome, setOutcome] = useState({
|
|
22
|
-
type: 'load',
|
|
23
|
-
msg: null
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
let id = `${location.host}-${_id}`
|
|
27
|
-
|
|
28
|
-
const createSignerPrivate = async () => {
|
|
29
|
-
if (!walletProvider || !address) {
|
|
30
|
-
open()
|
|
31
|
-
return
|
|
32
|
-
}
|
|
33
|
-
const provider = new BrowserProvider(walletProvider)
|
|
34
|
-
const network = await provider.getNetwork()
|
|
35
|
-
const signer = await provider.getSigner()
|
|
36
|
-
return [signer, network.name]
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const addItem = async text => {
|
|
40
|
-
try {
|
|
41
|
-
setOutcome({ type: 'upload', msg: null })
|
|
42
|
-
const [signer, network] = await createSignerPrivate()
|
|
43
|
-
const _address = config.address[network]
|
|
44
|
-
|
|
45
|
-
const token = new Contract(_address.token, config.ABI.token, signer)
|
|
46
|
-
, receiver = new Contract(_address.receiver, config.ABI.receiver, signer)
|
|
47
|
-
|
|
48
|
-
const allowance = await token.allowance(address, _address.receiver)
|
|
49
|
-
const amount = 1
|
|
50
|
-
|
|
51
|
-
if (allowance < amount) {
|
|
52
|
-
const approveTx = await token.approve(_address.receiver, amount)
|
|
53
|
-
await approveTx.wait()
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const calcTx = await receiver.tableRowWrite(_address.token, amount, id, text)
|
|
57
|
-
const { status } = await calcTx.wait()
|
|
58
|
-
if (status === 1) {
|
|
59
|
-
setOutcome({ type: 'uploaded', msg: null })
|
|
60
|
-
await readRowsCount()
|
|
61
|
-
} else {
|
|
62
|
-
setOutcome({ type: 'error', msg: null })
|
|
63
|
-
}
|
|
64
|
-
} catch (err) {
|
|
65
|
-
setOutcome({ type: 'error', msg: err })
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const updateItem = async (index, text) => {
|
|
70
|
-
try {
|
|
71
|
-
setOutcome({ type: 'upload', msg: null })
|
|
72
|
-
const [signer, network] = await createSignerPrivate()
|
|
73
|
-
const _address = config.address[network]
|
|
74
|
-
|
|
75
|
-
const token = new Contract(_address.token, config.ABI.token, signer)
|
|
76
|
-
, receiver = new Contract(_address.receiver, config.ABI.receiver, signer)
|
|
77
|
-
|
|
78
|
-
const allowance = await token.allowance(address, _address.receiver)
|
|
79
|
-
const amount = 1
|
|
80
|
-
|
|
81
|
-
if (allowance < amount) {
|
|
82
|
-
const approveTx = await token.approve(_address.receiver, amount)
|
|
83
|
-
await approveTx.wait()
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const calcTx = await receiver.tableRowUpdate(_address.token, amount, id, index, text)
|
|
87
|
-
const { status } = await calcTx.wait()
|
|
88
|
-
if (status === 1) {
|
|
89
|
-
setOutcome({ type: 'uploaded', msg: null })
|
|
90
|
-
window.GOBAL_PROMISE_QUEUE_WEB3_STORAGE.add(readRowsCount)
|
|
91
|
-
setUpdateItemIndex(index)
|
|
92
|
-
} else {
|
|
93
|
-
setOutcome({ type: 'error', msg: null })
|
|
94
|
-
}
|
|
95
|
-
} catch (err) {
|
|
96
|
-
setOutcome({ type: 'error', msg: err })
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const _readRowsCount = async () => {
|
|
101
|
-
try {
|
|
102
|
-
const [signer, network] = await createSignerPrivate()
|
|
103
|
-
const _address = config.address[network]
|
|
104
|
-
|
|
105
|
-
const receiver = new Contract(_address.receiver, config.ABI.receiver, signer)
|
|
106
|
-
const text = await receiver.tableRowsCount(id)
|
|
107
|
-
setLastIndex(parseInt(text.toString()))
|
|
108
|
-
return true
|
|
109
|
-
} catch (err) {}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const _readRowsCountPublic = async () => {
|
|
113
|
-
try {
|
|
114
|
-
const _wallet = Wallet.createRandom();
|
|
115
|
-
const { receiver: receiverAddress, publicRpc } = config.blockChainsData[window.GOBAL_REACT_WEB3_STORAGE_networkIndex || 0]
|
|
116
|
-
|
|
117
|
-
const provider = new JsonRpcProvider(publicRpc);
|
|
118
|
-
const wallet = new Wallet(_wallet.privateKey, provider);
|
|
119
|
-
|
|
120
|
-
const receiver = new Contract(receiverAddress, config.ABI.receiver, wallet)
|
|
121
|
-
const text = await receiver.tableRowsCount(id)
|
|
122
|
-
setLastIndex(parseInt(text.toString()))
|
|
123
|
-
return true
|
|
124
|
-
} catch (err) {}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const readRowsCount = async () => {
|
|
128
|
-
if (isConnected) {
|
|
129
|
-
await _readRowsCount()
|
|
130
|
-
} else {
|
|
131
|
-
await _readRowsCountPublic()
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const _tableRowRead = async x => {
|
|
136
|
-
for (let r = 0; r < 100; r++) {
|
|
137
|
-
try {
|
|
138
|
-
const [signer, network] = await createSignerPrivate()
|
|
139
|
-
const _address = config.address[network]
|
|
140
|
-
const receiver = new Contract(_address.receiver, config.ABI.receiver, signer)
|
|
141
|
-
const text = await receiver.tableRowRead(id, x.toString())
|
|
142
|
-
|
|
143
|
-
let item = null
|
|
144
|
-
|
|
145
|
-
try {
|
|
146
|
-
item = JSON.parse(text.toString())
|
|
147
|
-
} catch (e) {}
|
|
148
|
-
|
|
149
|
-
if (item) {
|
|
150
|
-
setItems(items => [...items.filter(_item => _item.index !== item.index), { ...item, isDelete: item.text === '', hasEdit: address.toLowerCase() === item.address }].sort((a, b) => a.index - b.index))
|
|
151
|
-
await sleep(1)
|
|
152
|
-
}
|
|
153
|
-
return
|
|
154
|
-
} catch (e) {}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const _publicTableRowRead = async x => {
|
|
159
|
-
for (let r = 0; r < 100; r++) {
|
|
160
|
-
try {
|
|
161
|
-
const _wallet = Wallet.createRandom();
|
|
162
|
-
const { receiver: receiverAddress, publicRpc } = config.blockChainsData[window.GOBAL_REACT_WEB3_STORAGE_networkIndex || 0]
|
|
163
|
-
|
|
164
|
-
const provider = new JsonRpcProvider(publicRpc);
|
|
165
|
-
const wallet = new Wallet(_wallet.privateKey, provider);
|
|
166
|
-
|
|
167
|
-
const receiver = new Contract(receiverAddress, config.ABI.receiver, wallet)
|
|
168
|
-
const text = await receiver.tableRowRead(id, x.toString())
|
|
169
|
-
|
|
170
|
-
let item = null
|
|
171
|
-
|
|
172
|
-
try {
|
|
173
|
-
item = JSON.parse(text.toString())
|
|
174
|
-
} catch (e) {}
|
|
175
|
-
|
|
176
|
-
if (item) {
|
|
177
|
-
setItems(items => [...items.filter(_item => _item.index !== item.index), { ...item, isDelete: item.text === '', hasEdit: false }].sort((a, b) => a.index - b.index))
|
|
178
|
-
await sleep(1)
|
|
179
|
-
}
|
|
180
|
-
return
|
|
181
|
-
} catch (e) {}
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
const tableRowRead = async x => {
|
|
186
|
-
if (isConnected) {
|
|
187
|
-
await _tableRowRead(x)
|
|
188
|
-
} else {
|
|
189
|
-
await _publicTableRowRead(x)
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
useEffect(() => {
|
|
194
|
-
const timeId = setInterval(() =>
|
|
195
|
-
window.GOBAL_PROMISE_QUEUE_WEB3_STORAGE.add(readRowsCount)
|
|
196
|
-
, 1000)
|
|
197
|
-
return () => clearTimeout(timeId)
|
|
198
|
-
}, [isConnected])
|
|
199
|
-
|
|
200
|
-
useEffect(() => {
|
|
201
|
-
if (lastIndex !== 0) {
|
|
202
|
-
const timeId = setTimeout(async () => {
|
|
203
|
-
const loadCount = isFullLoad ? lastIndex - 5 : -1
|
|
204
|
-
|
|
205
|
-
window.GOBAL_PROMISE_QUEUE_WEB3_STORAGE.add(() => tableRowRead(updateItemIndex))
|
|
206
|
-
|
|
207
|
-
for (let x = lastIndex; x > loadCount; x--) {
|
|
208
|
-
window.GOBAL_PROMISE_QUEUE_WEB3_STORAGE.add(() => tableRowRead(x))
|
|
209
|
-
await sleep(1)
|
|
210
|
-
}
|
|
211
|
-
}, 1000)
|
|
212
|
-
|
|
213
|
-
const intervalId = setInterval(() => {
|
|
214
|
-
if (isFullLoad && window.GOBAL_PROMISE_QUEUE_WEB3_STORAGE.queue.length === 0) {
|
|
215
|
-
const randomItemIndex = parseInt(lastIndex * Math.random())
|
|
216
|
-
window.GOBAL_PROMISE_QUEUE_WEB3_STORAGE.add(() => tableRowRead(randomItemIndex))
|
|
217
|
-
}
|
|
218
|
-
}, 5000)
|
|
219
|
-
|
|
220
|
-
return () => {
|
|
221
|
-
clearTimeout(timeId)
|
|
222
|
-
clearInterval(intervalId)
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
}, [isConnected, id, lastIndex, updateItemIndex, address, isFullLoad])
|
|
226
|
-
|
|
227
|
-
useEffect(() => {
|
|
228
|
-
if (items.length === lastIndex && lastIndex !== 0) {
|
|
229
|
-
setOutcome({ type: 'loaded', msg: null })
|
|
230
|
-
setFullLoad(true)
|
|
231
|
-
}
|
|
232
|
-
}, [items])
|
|
233
|
-
|
|
234
|
-
useEffect(() => {
|
|
235
|
-
const timeId = setTimeout(() => {
|
|
236
|
-
if (lastIndex === 0 && outcome.type !== 'error') {
|
|
237
|
-
setOutcome({ type: 'loaded', msg: null })
|
|
238
|
-
}
|
|
239
|
-
}, 5000)
|
|
240
|
-
|
|
241
|
-
return () => clearTimeout(timeId)
|
|
242
|
-
}, [lastIndex, updateItemIndex, outcome])
|
|
243
|
-
|
|
244
|
-
return [items, addItem, updateItem, outcome]
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
export default useTableStorage
|
package/src/web3-storage.sol
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity ^0.8.20;
|
|
3
|
-
import "@openzeppelin/contracts/utils/Strings.sol";
|
|
4
|
-
|
|
5
|
-
interface IERC20 {
|
|
6
|
-
function transferFrom(address from, address to, uint256 amount) external returns (bool);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
contract Fun {
|
|
10
|
-
using Strings for address;
|
|
11
|
-
using Strings for uint256;
|
|
12
|
-
|
|
13
|
-
function makeAddressString(address user, string memory id) internal pure returns (string memory) {
|
|
14
|
-
return string(
|
|
15
|
-
abi.encodePacked(
|
|
16
|
-
user.toHexString(),
|
|
17
|
-
"_",
|
|
18
|
-
id
|
|
19
|
-
)
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function makeString(string memory index, string memory id) internal pure returns (string memory) {
|
|
24
|
-
return string(
|
|
25
|
-
abi.encodePacked(
|
|
26
|
-
index,
|
|
27
|
-
"_",
|
|
28
|
-
id
|
|
29
|
-
)
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function toJson(address user, string memory index, string memory text) internal pure returns (string memory) {
|
|
34
|
-
return string(
|
|
35
|
-
abi.encodePacked(
|
|
36
|
-
'{',
|
|
37
|
-
"\"index\":\"",index,"\",",
|
|
38
|
-
"\"address\":\"",user.toHexString(),"\",",
|
|
39
|
-
"\"text\":\"",text,"\"",
|
|
40
|
-
'}'
|
|
41
|
-
)
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function uintToString(uint256 value) internal pure returns (string memory) {
|
|
46
|
-
return value.toString();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function mathPrice(uint256 _priceRatio, string memory text) public pure returns (uint256) {
|
|
50
|
-
uint256 length = bytes(text).length;
|
|
51
|
-
uint256 units = (length + 9) / 10;
|
|
52
|
-
return _priceRatio * units;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
contract Storage is Fun {
|
|
57
|
-
address internal owner;
|
|
58
|
-
address internal allowedToken;
|
|
59
|
-
uint256 internal priceRatio = 0;
|
|
60
|
-
|
|
61
|
-
mapping(string => string) internal privateFields;
|
|
62
|
-
mapping(string => string) internal publicFields;
|
|
63
|
-
mapping(string => string) internal tableFields;
|
|
64
|
-
mapping(string => uint256) internal tableIndexs;
|
|
65
|
-
|
|
66
|
-
constructor(address _allowedToken, uint256 _priceRatio) {
|
|
67
|
-
owner = msg.sender;
|
|
68
|
-
allowedToken = _allowedToken;
|
|
69
|
-
priceRatio = _priceRatio; // default 0
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function tableRowWrite(
|
|
73
|
-
address token,
|
|
74
|
-
uint256 amount,
|
|
75
|
-
string memory id,
|
|
76
|
-
string memory text
|
|
77
|
-
) public {
|
|
78
|
-
require(bytes(text).length <= 10000, "text value too much");
|
|
79
|
-
|
|
80
|
-
uint256 price = mathPrice(priceRatio, text);
|
|
81
|
-
|
|
82
|
-
if (priceRatio > 0) {
|
|
83
|
-
require(amount == price, "You can't pay with a larger amount");
|
|
84
|
-
require(token == allowedToken, "Accepts payment in official token only");
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
string memory index = uintToString(tableIndexs[id]);
|
|
88
|
-
tableFields[makeString(index, id)] = toJson(msg.sender, index, text);
|
|
89
|
-
tableIndexs[id] += 1;
|
|
90
|
-
|
|
91
|
-
if (priceRatio == 0) return;
|
|
92
|
-
|
|
93
|
-
IERC20(token).transferFrom(
|
|
94
|
-
msg.sender,
|
|
95
|
-
owner,
|
|
96
|
-
amount
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function tableRowUpdate(
|
|
101
|
-
address token,
|
|
102
|
-
uint256 amount,
|
|
103
|
-
string memory id,
|
|
104
|
-
string memory index,
|
|
105
|
-
string memory text
|
|
106
|
-
) public {
|
|
107
|
-
require(bytes(text).length <= 10000, "text value too much");
|
|
108
|
-
|
|
109
|
-
uint256 price = mathPrice(priceRatio, text);
|
|
110
|
-
|
|
111
|
-
if (priceRatio > 0) {
|
|
112
|
-
require(amount == price, "You can't pay with a larger amount");
|
|
113
|
-
require(token == allowedToken, "Accepts payment in official token only");
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
tableFields[makeString(index, id)] = toJson(msg.sender, index, text);
|
|
117
|
-
|
|
118
|
-
if (priceRatio == 0) return;
|
|
119
|
-
|
|
120
|
-
IERC20(token).transferFrom(
|
|
121
|
-
msg.sender,
|
|
122
|
-
owner,
|
|
123
|
-
amount
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function privateWrite(
|
|
128
|
-
address token,
|
|
129
|
-
uint256 amount,
|
|
130
|
-
string memory id,
|
|
131
|
-
string memory text
|
|
132
|
-
) public {
|
|
133
|
-
require(bytes(text).length <= 10000, "text value too much");
|
|
134
|
-
|
|
135
|
-
uint256 price = mathPrice(priceRatio, text);
|
|
136
|
-
|
|
137
|
-
if (priceRatio > 0) {
|
|
138
|
-
require(amount == price, "You can't pay with a larger amount");
|
|
139
|
-
require(token == allowedToken, "Accepts payment in official token only");
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
privateFields[makeAddressString(msg.sender, id)] = text;
|
|
143
|
-
|
|
144
|
-
if (priceRatio == 0) return;
|
|
145
|
-
|
|
146
|
-
IERC20(token).transferFrom(
|
|
147
|
-
msg.sender,
|
|
148
|
-
owner,
|
|
149
|
-
amount
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function publicWrite(
|
|
154
|
-
address token,
|
|
155
|
-
uint256 amount,
|
|
156
|
-
string memory id,
|
|
157
|
-
string memory text
|
|
158
|
-
) public {
|
|
159
|
-
require(bytes(text).length <= 10000, "text value too much");
|
|
160
|
-
|
|
161
|
-
uint256 price = mathPrice(priceRatio, text);
|
|
162
|
-
|
|
163
|
-
if (priceRatio > 0) {
|
|
164
|
-
require(amount == price, "You can't pay with a larger amount");
|
|
165
|
-
require(token == allowedToken, "Accepts payment in official token only");
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
publicFields[makeAddressString(msg.sender, id)] = text;
|
|
169
|
-
|
|
170
|
-
if (priceRatio == 0) return;
|
|
171
|
-
|
|
172
|
-
IERC20(token).transferFrom(
|
|
173
|
-
msg.sender,
|
|
174
|
-
owner,
|
|
175
|
-
amount
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
function tableRowRead(string memory id, string memory index) view public returns (string memory) {
|
|
180
|
-
return tableFields[makeString(index, id)];
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
function tableRowsCount(string memory id) view public returns (uint256) {
|
|
184
|
-
return tableIndexs[id];
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
function privateRead(string memory id) view public returns (string memory) {
|
|
188
|
-
return privateFields[makeAddressString(msg.sender, id)];
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
function publicRead(string memory id, address _address) view public returns (string memory) {
|
|
192
|
-
address sender = msg.sender;
|
|
193
|
-
if (_address != address(0)) {
|
|
194
|
-
sender = _address;
|
|
195
|
-
}
|
|
196
|
-
return publicFields[makeAddressString(sender, id)];
|
|
197
|
-
}
|
|
198
|
-
}
|