tempo.ts 0.1.5 → 0.2.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/README.md +33 -2
- package/dist/chains.d.ts +509 -115
- package/dist/chains.d.ts.map +1 -1
- package/dist/chains.js +18 -9
- package/dist/chains.js.map +1 -1
- package/dist/ox/Order.d.ts +92 -0
- package/dist/ox/Order.d.ts.map +1 -0
- package/dist/ox/Order.js +88 -0
- package/dist/ox/Order.js.map +1 -0
- package/dist/ox/OrdersFilters.d.ts +72 -0
- package/dist/ox/OrdersFilters.d.ts.map +1 -0
- package/dist/ox/OrdersFilters.js +100 -0
- package/dist/ox/OrdersFilters.js.map +1 -0
- package/dist/ox/Pagination.d.ts +128 -0
- package/dist/ox/Pagination.d.ts.map +1 -0
- package/dist/ox/Pagination.js +78 -0
- package/dist/ox/Pagination.js.map +1 -0
- package/dist/ox/PoolId.d.ts +18 -0
- package/dist/ox/PoolId.d.ts.map +1 -0
- package/dist/ox/PoolId.js +13 -0
- package/dist/ox/PoolId.js.map +1 -0
- package/dist/ox/RpcSchema.d.ts +32 -0
- package/dist/ox/RpcSchema.d.ts.map +1 -0
- package/dist/ox/RpcSchema.js +2 -0
- package/dist/ox/RpcSchema.js.map +1 -0
- package/dist/ox/SignatureEnvelope.d.ts +1 -1
- package/dist/ox/SignatureEnvelope.d.ts.map +1 -1
- package/dist/ox/SignatureEnvelope.js.map +1 -1
- package/dist/{viem → ox}/Tick.d.ts +4 -0
- package/dist/ox/Tick.d.ts.map +1 -0
- package/dist/ox/Tick.js.map +1 -0
- package/dist/ox/Transaction.d.ts.map +1 -1
- package/dist/ox/Transaction.js +2 -1
- package/dist/ox/Transaction.js.map +1 -1
- package/dist/ox/TransactionEnvelopeAA.d.ts +6 -6
- package/dist/ox/TransactionEnvelopeAA.d.ts.map +1 -1
- package/dist/ox/TransactionEnvelopeAA.js +4 -2
- package/dist/ox/TransactionEnvelopeAA.js.map +1 -1
- package/dist/ox/TransactionRequest.d.ts +4 -0
- package/dist/ox/TransactionRequest.d.ts.map +1 -1
- package/dist/ox/TransactionRequest.js.map +1 -1
- package/dist/ox/index.d.ts +6 -0
- package/dist/ox/index.d.ts.map +1 -1
- package/dist/ox/index.js +6 -0
- package/dist/ox/index.js.map +1 -1
- package/dist/prool/Instance.d.ts.map +1 -1
- package/dist/prool/Instance.js +20 -4
- package/dist/prool/Instance.js.map +1 -1
- package/dist/viem/Abis.d.ts +1469 -1082
- package/dist/viem/Abis.d.ts.map +1 -1
- package/dist/viem/Abis.js +932 -671
- package/dist/viem/Abis.js.map +1 -1
- package/dist/viem/Account.d.ts +150 -0
- package/dist/viem/Account.d.ts.map +1 -0
- package/dist/viem/Account.js +221 -0
- package/dist/viem/Account.js.map +1 -0
- package/dist/viem/Actions/amm.d.ts +80 -118
- package/dist/viem/Actions/amm.d.ts.map +1 -1
- package/dist/viem/Actions/amm.js +47 -116
- package/dist/viem/Actions/amm.js.map +1 -1
- package/dist/viem/Actions/dex.d.ts +889 -633
- package/dist/viem/Actions/dex.d.ts.map +1 -1
- package/dist/viem/Actions/dex.js +99 -0
- package/dist/viem/Actions/dex.js.map +1 -1
- package/dist/viem/Actions/fee.d.ts +3 -17
- package/dist/viem/Actions/fee.d.ts.map +1 -1
- package/dist/viem/Actions/fee.js.map +1 -1
- package/dist/viem/Actions/index.d.ts +1 -0
- package/dist/viem/Actions/index.d.ts.map +1 -1
- package/dist/viem/Actions/index.js +1 -0
- package/dist/viem/Actions/index.js.map +1 -1
- package/dist/viem/Actions/reward.d.ts +3236 -0
- package/dist/viem/Actions/reward.d.ts.map +1 -0
- package/dist/viem/Actions/reward.js +725 -0
- package/dist/viem/Actions/reward.js.map +1 -0
- package/dist/viem/Actions/token.d.ts +4295 -2646
- package/dist/viem/Actions/token.d.ts.map +1 -1
- package/dist/viem/Actions/token.js +214 -335
- package/dist/viem/Actions/token.js.map +1 -1
- package/dist/viem/Addresses.d.ts +1 -2
- package/dist/viem/Addresses.d.ts.map +1 -1
- package/dist/viem/Addresses.js +1 -2
- package/dist/viem/Addresses.js.map +1 -1
- package/dist/viem/Chain.d.ts +38 -12
- package/dist/viem/Chain.d.ts.map +1 -1
- package/dist/viem/Chain.js +27 -18
- package/dist/viem/Chain.js.map +1 -1
- package/dist/viem/Decorator.d.ts +959 -405
- package/dist/viem/Decorator.d.ts.map +1 -1
- package/dist/viem/Decorator.js +13 -5
- package/dist/viem/Decorator.js.map +1 -1
- package/dist/viem/Formatters.d.ts +8 -1
- package/dist/viem/Formatters.d.ts.map +1 -1
- package/dist/viem/Formatters.js +17 -0
- package/dist/viem/Formatters.js.map +1 -1
- package/dist/viem/P256.d.ts +2 -0
- package/dist/viem/P256.d.ts.map +1 -0
- package/dist/viem/P256.js +2 -0
- package/dist/viem/P256.js.map +1 -0
- package/dist/viem/Secp256k1.d.ts +2 -0
- package/dist/viem/Secp256k1.d.ts.map +1 -0
- package/dist/viem/Secp256k1.js +2 -0
- package/dist/viem/Secp256k1.js.map +1 -0
- package/dist/viem/TokenIds.d.ts +1 -2
- package/dist/viem/TokenIds.d.ts.map +1 -1
- package/dist/viem/TokenIds.js +1 -2
- package/dist/viem/TokenIds.js.map +1 -1
- package/dist/viem/Transaction.d.ts +1 -1
- package/dist/viem/Transaction.d.ts.map +1 -1
- package/dist/viem/Transaction.js +46 -5
- package/dist/viem/Transaction.js.map +1 -1
- package/dist/viem/WebAuthnP256.d.ts +79 -0
- package/dist/viem/WebAuthnP256.d.ts.map +1 -0
- package/dist/viem/WebAuthnP256.js +95 -0
- package/dist/viem/WebAuthnP256.js.map +1 -0
- package/dist/viem/WebCryptoP256.d.ts +2 -0
- package/dist/viem/WebCryptoP256.d.ts.map +1 -0
- package/dist/viem/WebCryptoP256.js +2 -0
- package/dist/viem/WebCryptoP256.js.map +1 -0
- package/dist/viem/index.d.ts +6 -3
- package/dist/viem/index.d.ts.map +1 -1
- package/dist/viem/index.js +6 -3
- package/dist/viem/index.js.map +1 -1
- package/dist/viem/internal/account.d.ts +24 -0
- package/dist/viem/internal/account.d.ts.map +1 -0
- package/dist/viem/internal/account.js +68 -0
- package/dist/viem/internal/account.js.map +1 -0
- package/dist/viem/internal/types.d.ts +10 -0
- package/dist/viem/internal/types.d.ts.map +1 -1
- package/dist/wagmi/Actions/amm.d.ts +428 -0
- package/dist/wagmi/Actions/amm.d.ts.map +1 -0
- package/dist/wagmi/Actions/amm.js +472 -0
- package/dist/wagmi/Actions/amm.js.map +1 -0
- package/dist/wagmi/Actions/dex.d.ts +908 -0
- package/dist/wagmi/Actions/dex.d.ts.map +1 -0
- package/dist/wagmi/Actions/dex.js +1023 -0
- package/dist/wagmi/Actions/dex.js.map +1 -0
- package/dist/wagmi/Actions/fee.d.ts +111 -0
- package/dist/wagmi/Actions/fee.d.ts.map +1 -0
- package/dist/wagmi/Actions/fee.js +126 -0
- package/dist/wagmi/Actions/fee.js.map +1 -0
- package/dist/wagmi/Actions/index.d.ts +6 -0
- package/dist/wagmi/Actions/index.d.ts.map +1 -0
- package/dist/wagmi/Actions/index.js +6 -0
- package/dist/wagmi/Actions/index.js.map +1 -0
- package/dist/wagmi/Actions/reward.d.ts +348 -0
- package/dist/wagmi/Actions/reward.d.ts.map +1 -0
- package/dist/wagmi/Actions/reward.js +388 -0
- package/dist/wagmi/Actions/reward.js.map +1 -0
- package/dist/wagmi/Actions/token.d.ts +1546 -0
- package/dist/wagmi/Actions/token.d.ts.map +1 -0
- package/dist/wagmi/Actions/token.js +1712 -0
- package/dist/wagmi/Actions/token.js.map +1 -0
- package/dist/wagmi/Connector.d.ts +73 -0
- package/dist/wagmi/Connector.d.ts.map +1 -0
- package/dist/wagmi/Connector.js +249 -0
- package/dist/wagmi/Connector.js.map +1 -0
- package/dist/wagmi/Hooks/amm.d.ts +421 -0
- package/dist/wagmi/Hooks/amm.d.ts.map +1 -0
- package/dist/wagmi/Hooks/amm.js +504 -0
- package/dist/wagmi/Hooks/amm.js.map +1 -0
- package/dist/wagmi/Hooks/dex.d.ts +816 -0
- package/dist/wagmi/Hooks/dex.d.ts.map +1 -0
- package/dist/wagmi/Hooks/dex.js +973 -0
- package/dist/wagmi/Hooks/dex.js.map +1 -0
- package/dist/wagmi/Hooks/fee.d.ts +97 -0
- package/dist/wagmi/Hooks/fee.d.ts.map +1 -0
- package/dist/wagmi/Hooks/fee.js +109 -0
- package/dist/wagmi/Hooks/fee.js.map +1 -0
- package/dist/wagmi/Hooks/index.d.ts +6 -0
- package/dist/wagmi/Hooks/index.d.ts.map +1 -0
- package/dist/wagmi/Hooks/index.js +6 -0
- package/dist/wagmi/Hooks/index.js.map +1 -0
- package/dist/wagmi/Hooks/reward.d.ts +307 -0
- package/dist/wagmi/Hooks/reward.d.ts.map +1 -0
- package/dist/wagmi/Hooks/reward.js +349 -0
- package/dist/wagmi/Hooks/reward.js.map +1 -0
- package/dist/wagmi/Hooks/token.d.ts +1388 -0
- package/dist/wagmi/Hooks/token.d.ts.map +1 -0
- package/dist/wagmi/Hooks/token.js +1657 -0
- package/dist/wagmi/Hooks/token.js.map +1 -0
- package/dist/wagmi/index.d.ts +4 -0
- package/dist/wagmi/index.d.ts.map +1 -0
- package/dist/wagmi/index.js +4 -0
- package/dist/wagmi/index.js.map +1 -0
- package/package.json +54 -10
- package/src/chains.ts +19 -9
- package/src/ox/Order.test.ts +78 -0
- package/src/ox/Order.ts +125 -0
- package/src/ox/OrdersFilters.test.ts +182 -0
- package/src/ox/OrdersFilters.ts +125 -0
- package/src/ox/Pagination.test.ts +162 -0
- package/src/ox/Pagination.ts +164 -0
- package/src/ox/PoolId.test.ts +33 -0
- package/src/ox/PoolId.ts +27 -0
- package/src/ox/RpcSchema.ts +35 -0
- package/src/ox/SignatureEnvelope.ts +3 -1
- package/src/{viem → ox}/Tick.test.ts +1 -1
- package/src/{viem → ox}/Tick.ts +5 -0
- package/src/ox/Transaction.test.ts +1 -1
- package/src/ox/Transaction.ts +2 -1
- package/src/ox/TransactionEnvelopeAA.test.ts +239 -96
- package/src/ox/TransactionEnvelopeAA.ts +9 -7
- package/src/ox/TransactionRequest.ts +4 -0
- package/src/ox/index.ts +6 -0
- package/src/prool/Instance.ts +51 -37
- package/src/prool/internal/chain.json +104 -52
- package/src/tsconfig.json +9 -0
- package/src/viem/Abis.ts +972 -710
- package/src/viem/Account.ts +279 -0
- package/src/viem/Actions/__snapshots__/dex.test.ts.snap +850 -0
- package/src/viem/Actions/amm.test.ts +98 -169
- package/src/viem/Actions/amm.ts +68 -155
- package/src/viem/Actions/dex.test.ts +563 -484
- package/src/viem/Actions/dex.ts +173 -0
- package/src/viem/Actions/fee.test.ts +23 -34
- package/src/viem/Actions/fee.ts +7 -0
- package/src/viem/Actions/index.ts +1 -0
- package/src/viem/Actions/policy.test.ts +19 -33
- package/src/viem/Actions/reward.test.ts +457 -0
- package/src/viem/Actions/reward.ts +999 -0
- package/src/viem/Actions/token.test.ts +453 -287
- package/src/viem/Actions/token.ts +452 -540
- package/src/viem/Addresses.ts +1 -2
- package/src/viem/Chain.ts +70 -20
- package/src/viem/Decorator.test.ts +2 -1
- package/src/viem/Decorator.ts +996 -421
- package/src/viem/Formatters.ts +31 -5
- package/src/viem/P256.ts +1 -0
- package/src/viem/Secp256k1.ts +1 -0
- package/src/viem/TokenIds.ts +1 -2
- package/src/viem/Transaction.ts +53 -7
- package/src/viem/WebAuthnP256.ts +140 -0
- package/src/viem/WebCryptoP256.ts +1 -0
- package/src/viem/e2e.test.ts +1126 -297
- package/src/viem/index.ts +6 -3
- package/src/viem/internal/account.ts +107 -0
- package/src/viem/internal/types.ts +9 -0
- package/src/wagmi/Actions/__snapshots__/dex.test.ts.snap +310 -0
- package/src/wagmi/Actions/amm.test.ts +198 -0
- package/src/wagmi/Actions/amm.ts +691 -0
- package/src/wagmi/Actions/dex.test.ts +1507 -0
- package/src/wagmi/Actions/dex.ts +1640 -0
- package/src/wagmi/Actions/fee.test.ts +63 -0
- package/src/wagmi/Actions/fee.ts +208 -0
- package/src/wagmi/Actions/index.ts +5 -0
- package/src/wagmi/Actions/reward.test.ts +210 -0
- package/src/wagmi/Actions/reward.ts +632 -0
- package/src/wagmi/Actions/token.test.ts +1308 -0
- package/src/wagmi/Actions/token.ts +2613 -0
- package/src/wagmi/Connector.test.ts +53 -0
- package/src/wagmi/Connector.ts +367 -0
- package/src/wagmi/Hooks/__snapshots__/dex.test.ts.snap +457 -0
- package/src/wagmi/Hooks/amm.test.ts +424 -0
- package/src/wagmi/Hooks/amm.ts +806 -0
- package/src/wagmi/Hooks/dex.test.ts +1017 -0
- package/src/wagmi/Hooks/dex.ts +1685 -0
- package/src/wagmi/Hooks/fee.test.ts +166 -0
- package/src/wagmi/Hooks/fee.ts +206 -0
- package/src/wagmi/Hooks/index.ts +5 -0
- package/src/wagmi/Hooks/reward.test.ts +219 -0
- package/src/wagmi/Hooks/reward.ts +672 -0
- package/src/wagmi/Hooks/token.test.ts +1670 -0
- package/src/wagmi/Hooks/token.ts +2906 -0
- package/src/wagmi/index.ts +3 -0
- package/src/wagmi/internal/types.ts +16 -0
- package/dist/viem/Client.d.ts +0 -27
- package/dist/viem/Client.d.ts.map +0 -1
- package/dist/viem/Client.js +0 -28
- package/dist/viem/Client.js.map +0 -1
- package/dist/viem/Tick.d.ts.map +0 -1
- package/dist/viem/Tick.js.map +0 -1
- package/src/viem/Client.bench-d.ts +0 -8
- package/src/viem/Client.test.ts +0 -178
- package/src/viem/Client.ts +0 -91
- /package/dist/{viem → ox}/Tick.js +0 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import type { Account } from 'viem'
|
|
2
|
+
import { describe, expect, test, vi } from 'vitest'
|
|
3
|
+
import { useConnect } from 'wagmi'
|
|
4
|
+
import { accounts } from '../../../test/viem/config.js'
|
|
5
|
+
import { config, renderHook } from '../../../test/wagmi/config.js'
|
|
6
|
+
import { useSetUserToken, useSetUserTokenSync, useUserToken } from './fee.js'
|
|
7
|
+
|
|
8
|
+
describe('useUserToken', () => {
|
|
9
|
+
test('default', async () => {
|
|
10
|
+
let account: Account | undefined
|
|
11
|
+
|
|
12
|
+
const { result, rerender } = await renderHook(() =>
|
|
13
|
+
useUserToken({ account }),
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
await vi.waitFor(() => result.current.fetchStatus === 'fetching')
|
|
17
|
+
|
|
18
|
+
expect(result.current).toMatchInlineSnapshot(`
|
|
19
|
+
{
|
|
20
|
+
"data": undefined,
|
|
21
|
+
"dataUpdatedAt": 0,
|
|
22
|
+
"error": null,
|
|
23
|
+
"errorUpdateCount": 0,
|
|
24
|
+
"errorUpdatedAt": 0,
|
|
25
|
+
"failureCount": 0,
|
|
26
|
+
"failureReason": null,
|
|
27
|
+
"fetchStatus": "idle",
|
|
28
|
+
"isEnabled": false,
|
|
29
|
+
"isError": false,
|
|
30
|
+
"isFetched": false,
|
|
31
|
+
"isFetchedAfterMount": false,
|
|
32
|
+
"isFetching": false,
|
|
33
|
+
"isInitialLoading": false,
|
|
34
|
+
"isLoading": false,
|
|
35
|
+
"isLoadingError": false,
|
|
36
|
+
"isPaused": false,
|
|
37
|
+
"isPending": true,
|
|
38
|
+
"isPlaceholderData": false,
|
|
39
|
+
"isRefetchError": false,
|
|
40
|
+
"isRefetching": false,
|
|
41
|
+
"isStale": false,
|
|
42
|
+
"isSuccess": false,
|
|
43
|
+
"promise": Promise {
|
|
44
|
+
"reason": [Error: experimental_prefetchInRender feature flag is not enabled],
|
|
45
|
+
"status": "rejected",
|
|
46
|
+
},
|
|
47
|
+
"queryKey": [
|
|
48
|
+
"getUserToken",
|
|
49
|
+
{
|
|
50
|
+
"account": undefined,
|
|
51
|
+
"chainId": 1337,
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
"refetch": [Function],
|
|
55
|
+
"status": "pending",
|
|
56
|
+
}
|
|
57
|
+
`)
|
|
58
|
+
|
|
59
|
+
account = accounts[0]
|
|
60
|
+
rerender()
|
|
61
|
+
|
|
62
|
+
await vi.waitFor(() => expect(result.current.isSuccess).toBeTruthy(), {
|
|
63
|
+
timeout: 5_000,
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
expect(result.current).toMatchInlineSnapshot(`
|
|
67
|
+
{
|
|
68
|
+
"data": {
|
|
69
|
+
"address": "0x20C0000000000000000000000000000000000001",
|
|
70
|
+
"id": 1n,
|
|
71
|
+
},
|
|
72
|
+
"dataUpdatedAt": 1675209600000,
|
|
73
|
+
"error": null,
|
|
74
|
+
"errorUpdateCount": 0,
|
|
75
|
+
"errorUpdatedAt": 0,
|
|
76
|
+
"failureCount": 0,
|
|
77
|
+
"failureReason": null,
|
|
78
|
+
"fetchStatus": "idle",
|
|
79
|
+
"isEnabled": true,
|
|
80
|
+
"isError": false,
|
|
81
|
+
"isFetched": true,
|
|
82
|
+
"isFetchedAfterMount": true,
|
|
83
|
+
"isFetching": false,
|
|
84
|
+
"isInitialLoading": false,
|
|
85
|
+
"isLoading": false,
|
|
86
|
+
"isLoadingError": false,
|
|
87
|
+
"isPaused": false,
|
|
88
|
+
"isPending": false,
|
|
89
|
+
"isPlaceholderData": false,
|
|
90
|
+
"isRefetchError": false,
|
|
91
|
+
"isRefetching": false,
|
|
92
|
+
"isStale": true,
|
|
93
|
+
"isSuccess": true,
|
|
94
|
+
"promise": Promise {
|
|
95
|
+
"reason": [Error: experimental_prefetchInRender feature flag is not enabled],
|
|
96
|
+
"status": "rejected",
|
|
97
|
+
},
|
|
98
|
+
"queryKey": [
|
|
99
|
+
"getUserToken",
|
|
100
|
+
{
|
|
101
|
+
"account": {
|
|
102
|
+
"address": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
103
|
+
"getHdKey": [Function],
|
|
104
|
+
"nonceManager": undefined,
|
|
105
|
+
"publicKey": "0x048318535b54105d4a7aae60c08fc45f9687181b4fdfc625bd1a753fa7397fed753547f11ca8696646f2f3acb08e31016afac23e630c5d11f59f61fef57b0d2aa5",
|
|
106
|
+
"sign": [Function],
|
|
107
|
+
"signAuthorization": [Function],
|
|
108
|
+
"signMessage": [Function],
|
|
109
|
+
"signTransaction": [Function],
|
|
110
|
+
"signTypedData": [Function],
|
|
111
|
+
"source": "hd",
|
|
112
|
+
"type": "local",
|
|
113
|
+
},
|
|
114
|
+
"chainId": 1337,
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
"refetch": [Function],
|
|
118
|
+
"status": "success",
|
|
119
|
+
}
|
|
120
|
+
`)
|
|
121
|
+
})
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
describe.skip('useSetUserToken', () => {
|
|
125
|
+
test('default', async () => {
|
|
126
|
+
const { result } = await renderHook(() => ({
|
|
127
|
+
connect: useConnect(),
|
|
128
|
+
setUserToken: useSetUserToken(),
|
|
129
|
+
}))
|
|
130
|
+
|
|
131
|
+
await result.current.connect.connectAsync({
|
|
132
|
+
connector: config.connectors[0]!,
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
const hash = await result.current.setUserToken.mutateAsync({
|
|
136
|
+
token: '0x20C0000000000000000000000000000000000001',
|
|
137
|
+
})
|
|
138
|
+
expect(hash).toBeDefined()
|
|
139
|
+
|
|
140
|
+
await vi.waitFor(() =>
|
|
141
|
+
expect(result.current.setUserToken.isSuccess).toBeTruthy(),
|
|
142
|
+
)
|
|
143
|
+
})
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
describe('useSetUserTokenSync', () => {
|
|
147
|
+
test('default', async () => {
|
|
148
|
+
const { result } = await renderHook(() => ({
|
|
149
|
+
connect: useConnect(),
|
|
150
|
+
setUserToken: useSetUserTokenSync(),
|
|
151
|
+
}))
|
|
152
|
+
|
|
153
|
+
await result.current.connect.connectAsync({
|
|
154
|
+
connector: config.connectors[0]!,
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
const data = await result.current.setUserToken.mutateAsync({
|
|
158
|
+
token: '0x20C0000000000000000000000000000000000001',
|
|
159
|
+
})
|
|
160
|
+
expect(data).toBeDefined()
|
|
161
|
+
|
|
162
|
+
await vi.waitFor(() =>
|
|
163
|
+
expect(result.current.setUserToken.isSuccess).toBeTruthy(),
|
|
164
|
+
)
|
|
165
|
+
})
|
|
166
|
+
})
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import type { DefaultError } from '@tanstack/query-core'
|
|
2
|
+
import type { UseMutationResult } from '@tanstack/react-query'
|
|
3
|
+
import type { Config, ResolvedRegister } from '@wagmi/core'
|
|
4
|
+
import { useChainId, useConfig } from 'wagmi'
|
|
5
|
+
import type { ConfigParameter, QueryParameter } from 'wagmi/internal'
|
|
6
|
+
import {
|
|
7
|
+
type UseMutationParameters,
|
|
8
|
+
type UseQueryReturnType,
|
|
9
|
+
useMutation,
|
|
10
|
+
useQuery,
|
|
11
|
+
} from 'wagmi/query'
|
|
12
|
+
|
|
13
|
+
import { getUserToken, setUserToken, setUserTokenSync } from '../Actions/fee.js'
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Hook for getting the user's default fee token.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* import { Hooks } from 'tempo.ts/wagmi'
|
|
21
|
+
*
|
|
22
|
+
* function App() {
|
|
23
|
+
* const { data, isLoading } = Hooks.fee.useUserToken({
|
|
24
|
+
* account: '0x20c...0055',
|
|
25
|
+
* })
|
|
26
|
+
*
|
|
27
|
+
* if (isLoading) return <div>Loading...</div>
|
|
28
|
+
* return <div>Token: {data?.address}</div>
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @param parameters - Parameters.
|
|
33
|
+
* @returns Query result with token address and ID.
|
|
34
|
+
*/
|
|
35
|
+
export function useUserToken<
|
|
36
|
+
config extends Config = ResolvedRegister['config'],
|
|
37
|
+
selectData = getUserToken.ReturnValue,
|
|
38
|
+
>(parameters: useUserToken.Parameters<config, selectData>) {
|
|
39
|
+
const { account, query = {} } = parameters
|
|
40
|
+
|
|
41
|
+
const config = useConfig(parameters)
|
|
42
|
+
const chainId = useChainId({ config })
|
|
43
|
+
|
|
44
|
+
const options = getUserToken.queryOptions(config, {
|
|
45
|
+
...parameters,
|
|
46
|
+
chainId: parameters.chainId ?? chainId,
|
|
47
|
+
query: undefined,
|
|
48
|
+
})
|
|
49
|
+
const enabled = Boolean(account && (query.enabled ?? true))
|
|
50
|
+
|
|
51
|
+
return useQuery({ ...query, ...options, enabled })
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export declare namespace useUserToken {
|
|
55
|
+
export type Parameters<
|
|
56
|
+
config extends Config = ResolvedRegister['config'],
|
|
57
|
+
selectData = getUserToken.ReturnValue,
|
|
58
|
+
> = ConfigParameter<config> &
|
|
59
|
+
QueryParameter<
|
|
60
|
+
getUserToken.ReturnValue,
|
|
61
|
+
DefaultError,
|
|
62
|
+
selectData,
|
|
63
|
+
getUserToken.QueryKey<config>
|
|
64
|
+
> &
|
|
65
|
+
Omit<getUserToken.queryOptions.Parameters<config, selectData>, 'query'>
|
|
66
|
+
|
|
67
|
+
export type ReturnValue<selectData = getUserToken.ReturnValue> =
|
|
68
|
+
UseQueryReturnType<selectData, Error>
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Hook for setting the user's default fee token.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```tsx
|
|
76
|
+
* import { Hooks } from 'tempo.ts/wagmi'
|
|
77
|
+
*
|
|
78
|
+
* function App() {
|
|
79
|
+
* const { mutate, isPending } = Hooks.fee.useSetUserToken()
|
|
80
|
+
*
|
|
81
|
+
* return (
|
|
82
|
+
* <button
|
|
83
|
+
* onClick={() => mutate({ token: '0x20c...0055' })}
|
|
84
|
+
* disabled={isPending}
|
|
85
|
+
* >
|
|
86
|
+
* Set Token
|
|
87
|
+
* </button>
|
|
88
|
+
* )
|
|
89
|
+
* }
|
|
90
|
+
* ```
|
|
91
|
+
*
|
|
92
|
+
* @param parameters - Parameters.
|
|
93
|
+
* @returns Mutation result.
|
|
94
|
+
*/
|
|
95
|
+
export function useSetUserToken<
|
|
96
|
+
config extends Config = ResolvedRegister['config'],
|
|
97
|
+
context = unknown,
|
|
98
|
+
>(
|
|
99
|
+
parameters: useSetUserToken.Parameters<config, context> = {},
|
|
100
|
+
): useSetUserToken.ReturnType<config, context> {
|
|
101
|
+
const { mutation } = parameters
|
|
102
|
+
const config = useConfig(parameters)
|
|
103
|
+
return useMutation({
|
|
104
|
+
...mutation,
|
|
105
|
+
async mutationFn(variables) {
|
|
106
|
+
return setUserToken(config, variables)
|
|
107
|
+
},
|
|
108
|
+
mutationKey: ['setUserTokenSync'],
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export declare namespace useSetUserToken {
|
|
113
|
+
type Parameters<
|
|
114
|
+
config extends Config = Config,
|
|
115
|
+
context = unknown,
|
|
116
|
+
> = ConfigParameter<config> & {
|
|
117
|
+
mutation?:
|
|
118
|
+
| UseMutationParameters<
|
|
119
|
+
setUserToken.ReturnValue,
|
|
120
|
+
setUserToken.ErrorType,
|
|
121
|
+
setUserToken.Parameters<config>,
|
|
122
|
+
context
|
|
123
|
+
>
|
|
124
|
+
| undefined
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
type ReturnType<
|
|
128
|
+
config extends Config = Config,
|
|
129
|
+
context = unknown,
|
|
130
|
+
> = UseMutationResult<
|
|
131
|
+
setUserToken.ReturnValue,
|
|
132
|
+
setUserToken.ErrorType,
|
|
133
|
+
setUserToken.Parameters<config>,
|
|
134
|
+
context
|
|
135
|
+
>
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Hook for setting the user's default fee token.
|
|
140
|
+
*
|
|
141
|
+
* Note: This is a synchronous hook that waits for the transaction
|
|
142
|
+
* to be included on a block before returning a response.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```tsx
|
|
146
|
+
* import { Hooks } from 'tempo.ts/wagmi'
|
|
147
|
+
*
|
|
148
|
+
* function App() {
|
|
149
|
+
* const { mutate, isPending } = Hooks.fee.useSetUserTokenSync()
|
|
150
|
+
*
|
|
151
|
+
* return (
|
|
152
|
+
* <button
|
|
153
|
+
* onClick={() => mutate({ token: '0x20c...0055' })}
|
|
154
|
+
* disabled={isPending}
|
|
155
|
+
* >
|
|
156
|
+
* Set Token
|
|
157
|
+
* </button>
|
|
158
|
+
* )
|
|
159
|
+
* }
|
|
160
|
+
* ```
|
|
161
|
+
*
|
|
162
|
+
* @param parameters - Parameters.
|
|
163
|
+
* @returns Mutation result.
|
|
164
|
+
*/
|
|
165
|
+
export function useSetUserTokenSync<
|
|
166
|
+
config extends Config = ResolvedRegister['config'],
|
|
167
|
+
context = unknown,
|
|
168
|
+
>(
|
|
169
|
+
parameters: useSetUserTokenSync.Parameters<config, context> = {},
|
|
170
|
+
): useSetUserTokenSync.ReturnType<config, context> {
|
|
171
|
+
const { mutation } = parameters
|
|
172
|
+
const config = useConfig(parameters)
|
|
173
|
+
return useMutation({
|
|
174
|
+
...mutation,
|
|
175
|
+
async mutationFn(variables) {
|
|
176
|
+
return setUserTokenSync(config, variables)
|
|
177
|
+
},
|
|
178
|
+
mutationKey: ['setUserTokenSync'],
|
|
179
|
+
})
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export declare namespace useSetUserTokenSync {
|
|
183
|
+
type Parameters<
|
|
184
|
+
config extends Config = Config,
|
|
185
|
+
context = unknown,
|
|
186
|
+
> = ConfigParameter<config> & {
|
|
187
|
+
mutation?:
|
|
188
|
+
| UseMutationParameters<
|
|
189
|
+
setUserTokenSync.ReturnValue,
|
|
190
|
+
setUserTokenSync.ErrorType,
|
|
191
|
+
setUserTokenSync.Parameters<config>,
|
|
192
|
+
context
|
|
193
|
+
>
|
|
194
|
+
| undefined
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
type ReturnType<
|
|
198
|
+
config extends Config = Config,
|
|
199
|
+
context = unknown,
|
|
200
|
+
> = UseMutationResult<
|
|
201
|
+
setUserTokenSync.ReturnValue,
|
|
202
|
+
setUserTokenSync.ErrorType,
|
|
203
|
+
setUserTokenSync.Parameters<config>,
|
|
204
|
+
context
|
|
205
|
+
>
|
|
206
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { type Address, parseUnits } from 'viem'
|
|
2
|
+
import { describe, expect, test, vi } from 'vitest'
|
|
3
|
+
import { useConnect } from 'wagmi'
|
|
4
|
+
import { config, renderHook, setupToken } from '../../../test/wagmi/config.js'
|
|
5
|
+
import * as hooks from './reward.js'
|
|
6
|
+
|
|
7
|
+
describe('useCancelSync', () => {
|
|
8
|
+
test('default', async () => {
|
|
9
|
+
const { result } = await renderHook(() => ({
|
|
10
|
+
cancel: hooks.useCancelSync(),
|
|
11
|
+
connect: useConnect(),
|
|
12
|
+
start: hooks.useStartSync(),
|
|
13
|
+
}))
|
|
14
|
+
|
|
15
|
+
await result.current.connect.connectAsync({
|
|
16
|
+
connector: config.connectors[0]!,
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
const { token } = await setupToken()
|
|
20
|
+
|
|
21
|
+
// Start a reward stream
|
|
22
|
+
const { id: streamId } = await result.current.start.mutateAsync({
|
|
23
|
+
amount: parseUnits('100', 6),
|
|
24
|
+
seconds: 3600,
|
|
25
|
+
token,
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
// Cancel the stream
|
|
29
|
+
await result.current.cancel.mutateAsync({
|
|
30
|
+
id: streamId,
|
|
31
|
+
token,
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
await vi.waitFor(() => expect(result.current.cancel.isSuccess).toBeTruthy())
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
describe('useGetStream', () => {
|
|
39
|
+
test('default', async () => {
|
|
40
|
+
const { result } = await renderHook(() => ({
|
|
41
|
+
connect: useConnect(),
|
|
42
|
+
getStream: hooks.useGetStream(),
|
|
43
|
+
startSync: hooks.useStartSync(),
|
|
44
|
+
}))
|
|
45
|
+
|
|
46
|
+
await result.current.connect.connectAsync({
|
|
47
|
+
connector: config.connectors[0]!,
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
const { token } = await setupToken()
|
|
51
|
+
|
|
52
|
+
const { id: streamId } = await result.current.startSync.mutateAsync({
|
|
53
|
+
amount: parseUnits('100', 6),
|
|
54
|
+
seconds: 10,
|
|
55
|
+
token,
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
// Update the hook to query the stream
|
|
59
|
+
const { result: streamResult } = await renderHook(() =>
|
|
60
|
+
hooks.useGetStream({
|
|
61
|
+
id: streamId,
|
|
62
|
+
token,
|
|
63
|
+
}),
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
await vi.waitFor(() => expect(streamResult.current.isSuccess).toBeTruthy())
|
|
67
|
+
|
|
68
|
+
expect(streamResult.current.data?.funder).toBeDefined()
|
|
69
|
+
expect(streamResult.current.data?.amountTotal).toBe(parseUnits('100', 6))
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
test('reactivity: id and token parameters', async () => {
|
|
73
|
+
const { result: setupResult } = await renderHook(() => ({
|
|
74
|
+
connect: useConnect(),
|
|
75
|
+
startSync: hooks.useStartSync(),
|
|
76
|
+
}))
|
|
77
|
+
|
|
78
|
+
await setupResult.current.connect.connectAsync({
|
|
79
|
+
connector: config.connectors[0]!,
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
const { token } = await setupToken()
|
|
83
|
+
|
|
84
|
+
const { id } = await setupResult.current.startSync.mutateAsync({
|
|
85
|
+
amount: parseUnits('100', 6),
|
|
86
|
+
seconds: 10,
|
|
87
|
+
token,
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
const { result, rerender } = await renderHook(
|
|
91
|
+
(props) =>
|
|
92
|
+
hooks.useGetStream({
|
|
93
|
+
id: props?.id,
|
|
94
|
+
token: props?.token,
|
|
95
|
+
}),
|
|
96
|
+
{
|
|
97
|
+
initialProps: {
|
|
98
|
+
id: undefined as bigint | undefined,
|
|
99
|
+
token: undefined as Address | undefined,
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
await vi.waitFor(() => result.current.fetchStatus === 'idle')
|
|
105
|
+
|
|
106
|
+
// Should be disabled when parameters are undefined
|
|
107
|
+
expect(result.current.data).toBeUndefined()
|
|
108
|
+
expect(result.current.isPending).toBe(true)
|
|
109
|
+
expect(result.current.isEnabled).toBe(false)
|
|
110
|
+
|
|
111
|
+
// Set parameters
|
|
112
|
+
rerender({ id, token })
|
|
113
|
+
|
|
114
|
+
await vi.waitFor(() => expect(result.current.isSuccess).toBeTruthy())
|
|
115
|
+
|
|
116
|
+
// Should now be enabled and have data
|
|
117
|
+
expect(result.current.isEnabled).toBe(true)
|
|
118
|
+
expect(result.current.data).toBeDefined()
|
|
119
|
+
expect(result.current.data?.amountTotal).toBe(parseUnits('100', 6))
|
|
120
|
+
})
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
describe('useGetTotalPerSecond', () => {
|
|
124
|
+
test('default', async () => {
|
|
125
|
+
const { token } = await setupToken()
|
|
126
|
+
|
|
127
|
+
const { result } = await renderHook(() =>
|
|
128
|
+
hooks.useGetTotalPerSecond({
|
|
129
|
+
token,
|
|
130
|
+
}),
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
await vi.waitFor(() => expect(result.current.isSuccess).toBeTruthy())
|
|
134
|
+
|
|
135
|
+
expect(result.current.data).toBe(0n)
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
test('reactivity: token parameter', async () => {
|
|
139
|
+
const { result, rerender } = await renderHook(
|
|
140
|
+
(props) =>
|
|
141
|
+
hooks.useGetTotalPerSecond({
|
|
142
|
+
token: props?.token,
|
|
143
|
+
}),
|
|
144
|
+
{
|
|
145
|
+
initialProps: {
|
|
146
|
+
token: undefined as Address | undefined,
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
await vi.waitFor(() => result.current.fetchStatus === 'idle')
|
|
152
|
+
|
|
153
|
+
// Should be disabled when token is undefined
|
|
154
|
+
expect(result.current.data).toBeUndefined()
|
|
155
|
+
expect(result.current.isPending).toBe(true)
|
|
156
|
+
expect(result.current.isEnabled).toBe(false)
|
|
157
|
+
|
|
158
|
+
// Setup token
|
|
159
|
+
const { token } = await setupToken()
|
|
160
|
+
|
|
161
|
+
// Set token
|
|
162
|
+
rerender({ token })
|
|
163
|
+
|
|
164
|
+
await vi.waitFor(() => expect(result.current.isSuccess).toBeTruthy())
|
|
165
|
+
|
|
166
|
+
// Should now be enabled and have data
|
|
167
|
+
expect(result.current.isEnabled).toBe(true)
|
|
168
|
+
expect(result.current.data).toBe(0n)
|
|
169
|
+
})
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
describe('useSetRecipientSync', () => {
|
|
173
|
+
test('default', async () => {
|
|
174
|
+
const { result } = await renderHook(() => ({
|
|
175
|
+
connect: useConnect(),
|
|
176
|
+
setRecipient: hooks.useSetRecipientSync(),
|
|
177
|
+
}))
|
|
178
|
+
|
|
179
|
+
await result.current.connect.connectAsync({
|
|
180
|
+
connector: config.connectors[0]!,
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
const { token } = await setupToken()
|
|
184
|
+
|
|
185
|
+
await result.current.setRecipient.mutateAsync({
|
|
186
|
+
recipient: '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
|
|
187
|
+
token,
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
await vi.waitFor(() =>
|
|
191
|
+
expect(result.current.setRecipient.isSuccess).toBeTruthy(),
|
|
192
|
+
)
|
|
193
|
+
})
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
describe('useStartSync', () => {
|
|
197
|
+
test('default', async () => {
|
|
198
|
+
const { result } = await renderHook(() => ({
|
|
199
|
+
connect: useConnect(),
|
|
200
|
+
start: hooks.useStartSync(),
|
|
201
|
+
}))
|
|
202
|
+
|
|
203
|
+
await result.current.connect.connectAsync({
|
|
204
|
+
connector: config.connectors[0]!,
|
|
205
|
+
})
|
|
206
|
+
|
|
207
|
+
const { token } = await setupToken()
|
|
208
|
+
|
|
209
|
+
const { id } = await result.current.start.mutateAsync({
|
|
210
|
+
amount: parseUnits('100', 6),
|
|
211
|
+
seconds: 10,
|
|
212
|
+
token,
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
expect(id).toBeGreaterThan(0n)
|
|
216
|
+
|
|
217
|
+
await vi.waitFor(() => expect(result.current.start.isSuccess).toBeTruthy())
|
|
218
|
+
})
|
|
219
|
+
})
|