@permissionless/wagmi 0.0.4 → 0.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/CHANGELOG.md +6 -0
- package/_cjs/context.js +14 -0
- package/_cjs/context.js.map +1 -0
- package/_cjs/hooks/useAvailableCapabilities.js +37 -0
- package/_cjs/hooks/useAvailableCapabilities.js.map +1 -0
- package/_cjs/hooks/useSendTransaction.js +42 -0
- package/_cjs/hooks/useSendTransaction.js.map +1 -0
- package/_cjs/hooks/useWaitForTransactionReceipt.js +168 -0
- package/_cjs/hooks/useWaitForTransactionReceipt.js.map +1 -0
- package/_cjs/index.js +7 -11
- package/_cjs/index.js.map +1 -1
- package/_cjs/utils/observe.js +43 -0
- package/_cjs/utils/observe.js.map +1 -0
- package/_esm/context.js +10 -0
- package/_esm/context.js.map +1 -0
- package/_esm/hooks/useAvailableCapabilities.js +33 -0
- package/_esm/hooks/useAvailableCapabilities.js.map +1 -0
- package/_esm/hooks/useSendTransaction.js +38 -0
- package/_esm/hooks/useSendTransaction.js.map +1 -0
- package/_esm/hooks/useWaitForTransactionReceipt.js +175 -0
- package/_esm/hooks/useWaitForTransactionReceipt.js.map +1 -0
- package/_esm/index.js +3 -6
- package/_esm/index.js.map +1 -1
- package/_esm/utils/observe.js +46 -0
- package/_esm/utils/observe.js.map +1 -0
- package/_types/context.d.ts +12 -0
- package/_types/context.d.ts.map +1 -0
- package/_types/hooks/useAvailableCapabilities.d.ts +5 -0
- package/_types/hooks/useAvailableCapabilities.d.ts.map +1 -0
- package/_types/hooks/useSendTransaction.d.ts +34 -0
- package/_types/hooks/useSendTransaction.d.ts.map +1 -0
- package/_types/hooks/useWaitForTransactionReceipt.d.ts +92 -0
- package/_types/hooks/useWaitForTransactionReceipt.d.ts.map +1 -0
- package/_types/index.d.ts +3 -6
- package/_types/index.d.ts.map +1 -1
- package/_types/utils/observe.d.ts +23 -0
- package/_types/utils/observe.d.ts.map +1 -0
- package/context.ts +22 -0
- package/hooks/useAvailableCapabilities.ts +43 -0
- package/hooks/useSendTransaction.ts +148 -0
- package/hooks/useWaitForTransactionReceipt.ts +431 -0
- package/index.ts +6 -31
- package/package.json +3 -11
- package/utils/observe.ts +76 -0
- package/_cjs/connectors/biconomySmartAccount.js +0 -18
- package/_cjs/connectors/biconomySmartAccount.js.map +0 -1
- package/_cjs/connectors/kernelSmartAccount.js +0 -18
- package/_cjs/connectors/kernelSmartAccount.js.map +0 -1
- package/_cjs/connectors/safeSmartAccount.js +0 -18
- package/_cjs/connectors/safeSmartAccount.js.map +0 -1
- package/_cjs/connectors/simpleSmartAccount.js +0 -30
- package/_cjs/connectors/simpleSmartAccount.js.map +0 -1
- package/_cjs/connectors/smartAccount.js +0 -51
- package/_cjs/connectors/smartAccount.js.map +0 -1
- package/_esm/connectors/biconomySmartAccount.js +0 -14
- package/_esm/connectors/biconomySmartAccount.js.map +0 -1
- package/_esm/connectors/kernelSmartAccount.js +0 -14
- package/_esm/connectors/kernelSmartAccount.js.map +0 -1
- package/_esm/connectors/safeSmartAccount.js +0 -14
- package/_esm/connectors/safeSmartAccount.js.map +0 -1
- package/_esm/connectors/simpleSmartAccount.js +0 -26
- package/_esm/connectors/simpleSmartAccount.js.map +0 -1
- package/_esm/connectors/smartAccount.js +0 -53
- package/_esm/connectors/smartAccount.js.map +0 -1
- package/_types/connectors/biconomySmartAccount.d.ts +0 -317
- package/_types/connectors/biconomySmartAccount.d.ts.map +0 -1
- package/_types/connectors/kernelSmartAccount.d.ts +0 -317
- package/_types/connectors/kernelSmartAccount.d.ts.map +0 -1
- package/_types/connectors/safeSmartAccount.d.ts +0 -317
- package/_types/connectors/safeSmartAccount.d.ts.map +0 -1
- package/_types/connectors/simpleSmartAccount.d.ts +0 -635
- package/_types/connectors/simpleSmartAccount.d.ts.map +0 -1
- package/_types/connectors/smartAccount.d.ts +0 -294
- package/_types/connectors/smartAccount.d.ts.map +0 -1
- package/connectors/biconomySmartAccount.ts +0 -53
- package/connectors/kernelSmartAccount.ts +0 -53
- package/connectors/safeSmartAccount.ts +0 -50
- package/connectors/simpleSmartAccount.ts +0 -90
- package/connectors/smartAccount.ts +0 -72
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type MutateOptions,
|
|
3
|
+
type MutationOptions,
|
|
4
|
+
useMutation
|
|
5
|
+
} from "@tanstack/react-query"
|
|
6
|
+
import { sendTransaction } from "@wagmi/core"
|
|
7
|
+
import { sendCalls } from "@wagmi/core/experimental"
|
|
8
|
+
import type {
|
|
9
|
+
Prettify,
|
|
10
|
+
SendTransactionErrorType,
|
|
11
|
+
WalletCapabilities,
|
|
12
|
+
WalletSendCallsParameters
|
|
13
|
+
} from "viem"
|
|
14
|
+
import type { SendCallsErrorType } from "viem/experimental"
|
|
15
|
+
import { type Config, type ResolvedRegister, useConfig } from "wagmi"
|
|
16
|
+
import type {
|
|
17
|
+
SendTransactionVariables,
|
|
18
|
+
UseMutationParameters,
|
|
19
|
+
UseMutationReturnType
|
|
20
|
+
} from "wagmi/query"
|
|
21
|
+
import { useAvailableCapabilities } from "./useAvailableCapabilities"
|
|
22
|
+
|
|
23
|
+
const sendTransactionMutationOptions = <config extends Config>(
|
|
24
|
+
config: config,
|
|
25
|
+
parameters: {
|
|
26
|
+
capabilities?: WalletSendCallsParameters<WalletCapabilities>[number]["capabilities"]
|
|
27
|
+
} = {}
|
|
28
|
+
) => {
|
|
29
|
+
return {
|
|
30
|
+
mutationFn(variables) {
|
|
31
|
+
if (parameters.capabilities) {
|
|
32
|
+
return sendCalls(config, {
|
|
33
|
+
calls: [variables],
|
|
34
|
+
capabilities: parameters.capabilities
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return sendTransaction(config, variables) as Promise<string>
|
|
39
|
+
},
|
|
40
|
+
mutationKey: ["sendTransaction"]
|
|
41
|
+
} as const satisfies MutationOptions<
|
|
42
|
+
SendTransactionData,
|
|
43
|
+
SendTransactionErrorType | SendCallsErrorType,
|
|
44
|
+
SendTransactionVariables<config, config["chains"][number]["id"]>
|
|
45
|
+
>
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export type SendTransactionData = string
|
|
49
|
+
|
|
50
|
+
export type SendTransactionMutate<config extends Config, context = unknown> = <
|
|
51
|
+
chainId extends config["chains"][number]["id"]
|
|
52
|
+
>(
|
|
53
|
+
variables: SendTransactionVariables<config, chainId>,
|
|
54
|
+
options?:
|
|
55
|
+
| Prettify<
|
|
56
|
+
MutateOptions<
|
|
57
|
+
SendTransactionData,
|
|
58
|
+
SendTransactionErrorType | SendCallsErrorType,
|
|
59
|
+
Prettify<SendTransactionVariables<config, chainId>>,
|
|
60
|
+
context
|
|
61
|
+
>
|
|
62
|
+
>
|
|
63
|
+
| undefined
|
|
64
|
+
) => void
|
|
65
|
+
|
|
66
|
+
export type SendTransactionMutateAsync<
|
|
67
|
+
config extends Config,
|
|
68
|
+
context = unknown
|
|
69
|
+
> = <chainId extends config["chains"][number]["id"]>(
|
|
70
|
+
variables: SendTransactionVariables<config, chainId>,
|
|
71
|
+
options?:
|
|
72
|
+
| Prettify<
|
|
73
|
+
MutateOptions<
|
|
74
|
+
SendTransactionData,
|
|
75
|
+
SendTransactionErrorType | SendCallsErrorType,
|
|
76
|
+
Prettify<SendTransactionVariables<config, chainId>>,
|
|
77
|
+
context
|
|
78
|
+
>
|
|
79
|
+
>
|
|
80
|
+
| undefined
|
|
81
|
+
) => Promise<SendTransactionData>
|
|
82
|
+
|
|
83
|
+
export type UseSendTransactionReturnType<
|
|
84
|
+
config extends Config = Config,
|
|
85
|
+
context = unknown
|
|
86
|
+
> = Prettify<
|
|
87
|
+
UseMutationReturnType<
|
|
88
|
+
SendTransactionData,
|
|
89
|
+
SendTransactionErrorType | SendCallsErrorType,
|
|
90
|
+
SendTransactionVariables<config, config["chains"][number]["id"]>,
|
|
91
|
+
context
|
|
92
|
+
> & {
|
|
93
|
+
sendTransaction: SendTransactionMutate<config, context>
|
|
94
|
+
sendTransactionAsync: SendTransactionMutateAsync<config, context>
|
|
95
|
+
}
|
|
96
|
+
>
|
|
97
|
+
|
|
98
|
+
export type ConfigParameter<config extends Config = Config> = {
|
|
99
|
+
config?: Config | config | undefined
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export type UseSendTransactionParameters<
|
|
103
|
+
config extends Config = ResolvedRegister["config"],
|
|
104
|
+
context = unknown
|
|
105
|
+
> = Prettify<
|
|
106
|
+
ConfigParameter<config> & {
|
|
107
|
+
mutation?:
|
|
108
|
+
| UseMutationParameters<
|
|
109
|
+
SendTransactionData,
|
|
110
|
+
SendTransactionErrorType | SendCallsErrorType,
|
|
111
|
+
SendTransactionVariables<
|
|
112
|
+
config,
|
|
113
|
+
config["chains"][number]["id"]
|
|
114
|
+
>,
|
|
115
|
+
context
|
|
116
|
+
>
|
|
117
|
+
| undefined
|
|
118
|
+
}
|
|
119
|
+
>
|
|
120
|
+
|
|
121
|
+
export const useSendTransaction = <
|
|
122
|
+
config extends Config = ResolvedRegister["config"],
|
|
123
|
+
context = unknown
|
|
124
|
+
>(
|
|
125
|
+
parameters: UseSendTransactionParameters<config, context> = {}
|
|
126
|
+
): UseSendTransactionReturnType<config, context> => {
|
|
127
|
+
const { mutation } = parameters
|
|
128
|
+
const { capabilities } = useAvailableCapabilities()
|
|
129
|
+
|
|
130
|
+
const config = useConfig(parameters)
|
|
131
|
+
|
|
132
|
+
const mutationOptions = sendTransactionMutationOptions(config, {
|
|
133
|
+
...parameters,
|
|
134
|
+
capabilities
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
const { mutate, mutateAsync, ...result } = useMutation({
|
|
138
|
+
...mutation,
|
|
139
|
+
...mutationOptions
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
type Return = UseSendTransactionReturnType<config, context>
|
|
143
|
+
return {
|
|
144
|
+
...result,
|
|
145
|
+
sendTransaction: mutate as Return["sendTransaction"],
|
|
146
|
+
sendTransactionAsync: mutateAsync as Return["sendTransactionAsync"]
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
DefaultError,
|
|
5
|
+
QueryKey,
|
|
6
|
+
QueryOptions
|
|
7
|
+
} from "@tanstack/react-query"
|
|
8
|
+
import {
|
|
9
|
+
type Config,
|
|
10
|
+
type ResolvedRegister,
|
|
11
|
+
type WaitForTransactionReceiptErrorType,
|
|
12
|
+
type WaitForTransactionReceiptReturnType,
|
|
13
|
+
getConnectorClient,
|
|
14
|
+
waitForTransactionReceipt
|
|
15
|
+
} from "@wagmi/core"
|
|
16
|
+
import { ConnectorNotConnectedError } from "@wagmi/core"
|
|
17
|
+
import type {
|
|
18
|
+
GetCallsStatusData,
|
|
19
|
+
GetCallsStatusErrorType,
|
|
20
|
+
GetCallsStatusOptions,
|
|
21
|
+
GetCallsStatusQueryFnData
|
|
22
|
+
} from "@wagmi/core/experimental"
|
|
23
|
+
import type { WaitForTransactionReceiptData } from "@wagmi/core/query"
|
|
24
|
+
import {
|
|
25
|
+
type Hash,
|
|
26
|
+
type Prettify,
|
|
27
|
+
WaitForTransactionReceiptTimeoutError,
|
|
28
|
+
type WalletCapabilities,
|
|
29
|
+
type WalletSendCallsParameters,
|
|
30
|
+
isHash,
|
|
31
|
+
stringify
|
|
32
|
+
} from "viem"
|
|
33
|
+
import { getTransactionReceipt, watchBlockNumber } from "viem/actions"
|
|
34
|
+
import {
|
|
35
|
+
type GetCallsStatusReturnType,
|
|
36
|
+
type ShowCallsStatusErrorType,
|
|
37
|
+
getCallsStatus
|
|
38
|
+
} from "viem/experimental"
|
|
39
|
+
import { getAction } from "viem/utils"
|
|
40
|
+
import { useChainId, useConfig } from "wagmi"
|
|
41
|
+
import {
|
|
42
|
+
type UseQueryParameters,
|
|
43
|
+
type UseQueryReturnType,
|
|
44
|
+
type WaitForTransactionReceiptOptions,
|
|
45
|
+
type WaitForTransactionReceiptQueryFnData,
|
|
46
|
+
useQuery
|
|
47
|
+
} from "wagmi/query"
|
|
48
|
+
import { observe } from "../utils/observe"
|
|
49
|
+
import { useAvailableCapabilities } from "./useAvailableCapabilities"
|
|
50
|
+
import type { ConfigParameter } from "./useSendTransaction"
|
|
51
|
+
|
|
52
|
+
export type WaitForTransactionReceiptQueryKey<
|
|
53
|
+
config extends Config,
|
|
54
|
+
chainId extends config["chains"][number]["id"]
|
|
55
|
+
> = ReturnType<typeof waitForTransactionReceiptQueryKey<config, chainId>>
|
|
56
|
+
|
|
57
|
+
export function waitForTransactionReceiptQueryKey<
|
|
58
|
+
config extends Config,
|
|
59
|
+
chainId extends config["chains"][number]["id"]
|
|
60
|
+
>(
|
|
61
|
+
options: Omit<
|
|
62
|
+
WaitForTransactionReceiptOptions<config, chainId>,
|
|
63
|
+
"hash" | "onReplaced"
|
|
64
|
+
> & {
|
|
65
|
+
id?: string
|
|
66
|
+
capabilities?: WalletSendCallsParameters<WalletCapabilities>[number]["capabilities"]
|
|
67
|
+
} = {}
|
|
68
|
+
) {
|
|
69
|
+
const { ...rest } = options
|
|
70
|
+
return ["waitForTransactionReceipt", filterQueryOptions(rest)] as const
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function filterQueryOptions<type extends Record<string, unknown>>(
|
|
74
|
+
options: type
|
|
75
|
+
): type {
|
|
76
|
+
// destructuring is super fast
|
|
77
|
+
// biome-ignore format: no formatting
|
|
78
|
+
const {
|
|
79
|
+
// import('@tanstack/query-core').QueryOptions
|
|
80
|
+
_defaulted, behavior, gcTime, initialData, initialDataUpdatedAt, maxPages, meta, networkMode, queryFn, queryHash, queryKey, queryKeyHashFn, retry, retryDelay, structuralSharing,
|
|
81
|
+
|
|
82
|
+
// import('@tanstack/query-core').InfiniteQueryObserverOptions
|
|
83
|
+
getPreviousPageParam, getNextPageParam, initialPageParam,
|
|
84
|
+
|
|
85
|
+
// import('@tanstack/react-query').UseQueryOptions
|
|
86
|
+
_optimisticResults, enabled, notifyOnChangeProps, placeholderData, refetchInterval, refetchIntervalInBackground, refetchOnMount, refetchOnReconnect, refetchOnWindowFocus, retryOnMount, select, staleTime, suspense, throwOnError,
|
|
87
|
+
|
|
88
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
89
|
+
// wagmi
|
|
90
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
91
|
+
config, connector, query,
|
|
92
|
+
...rest
|
|
93
|
+
} = options
|
|
94
|
+
|
|
95
|
+
return rest as type
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export type QueryParameter<
|
|
99
|
+
queryFnData = unknown,
|
|
100
|
+
error = DefaultError,
|
|
101
|
+
data = queryFnData,
|
|
102
|
+
queryKey extends QueryKey = QueryKey
|
|
103
|
+
> = {
|
|
104
|
+
query?:
|
|
105
|
+
| Omit<
|
|
106
|
+
UseQueryParameters<queryFnData, error, data, queryKey>,
|
|
107
|
+
| "queryFn"
|
|
108
|
+
| "queryHash"
|
|
109
|
+
| "queryKey"
|
|
110
|
+
| "queryKeyHashFn"
|
|
111
|
+
| "throwOnError"
|
|
112
|
+
>
|
|
113
|
+
| undefined
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export type UseCallsStatusParameters<
|
|
117
|
+
config extends Config = Config,
|
|
118
|
+
chainId extends
|
|
119
|
+
config["chains"][number]["id"] = config["chains"][number]["id"],
|
|
120
|
+
selectData = GetCallsStatusData
|
|
121
|
+
> = Prettify<
|
|
122
|
+
Partial<GetCallsStatusOptions> &
|
|
123
|
+
ConfigParameter<config> &
|
|
124
|
+
QueryParameter<
|
|
125
|
+
GetCallsStatusQueryFnData,
|
|
126
|
+
GetCallsStatusErrorType,
|
|
127
|
+
selectData,
|
|
128
|
+
ReturnType<typeof getCallsStatusQueryKey>
|
|
129
|
+
> & {
|
|
130
|
+
chainId?:
|
|
131
|
+
| (chainId extends config["chains"][number]["id"]
|
|
132
|
+
? chainId
|
|
133
|
+
: undefined)
|
|
134
|
+
| config["chains"][number]["id"]
|
|
135
|
+
| undefined
|
|
136
|
+
}
|
|
137
|
+
>
|
|
138
|
+
|
|
139
|
+
export function getCallsStatusQueryKey(
|
|
140
|
+
options: Partial<GetCallsStatusOptions>
|
|
141
|
+
) {
|
|
142
|
+
return ["callsStatus", filterQueryOptions(options)] as const
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export async function waitForCallsStatus<
|
|
146
|
+
config extends Config,
|
|
147
|
+
chainId extends
|
|
148
|
+
config["chains"][number]["id"] = config["chains"][number]["id"]
|
|
149
|
+
>(
|
|
150
|
+
config: config,
|
|
151
|
+
parameters: Omit<
|
|
152
|
+
WaitForTransactionReceiptOptions<config, chainId>,
|
|
153
|
+
"hash" | "onReplaced"
|
|
154
|
+
> & {
|
|
155
|
+
id: string
|
|
156
|
+
}
|
|
157
|
+
): Promise<WaitForTransactionReceiptReturnType<config, chainId>> {
|
|
158
|
+
const {
|
|
159
|
+
timeout = 0,
|
|
160
|
+
id,
|
|
161
|
+
pollingInterval,
|
|
162
|
+
retryCount = 6,
|
|
163
|
+
confirmations = 1
|
|
164
|
+
} = parameters
|
|
165
|
+
|
|
166
|
+
const client = await getConnectorClient(config, {})
|
|
167
|
+
|
|
168
|
+
const observerId = stringify(["waitForTransactionReceipt", client.uid, id])
|
|
169
|
+
|
|
170
|
+
let count = 0
|
|
171
|
+
let receipt: GetCallsStatusReturnType
|
|
172
|
+
|
|
173
|
+
return new Promise((resolve, reject) => {
|
|
174
|
+
if (timeout)
|
|
175
|
+
setTimeout(
|
|
176
|
+
() =>
|
|
177
|
+
reject(
|
|
178
|
+
new WaitForTransactionReceiptTimeoutError({
|
|
179
|
+
hash: id as Hash
|
|
180
|
+
})
|
|
181
|
+
),
|
|
182
|
+
timeout
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
const _unobserve = observe(observerId, { resolve, reject }, (emit) => {
|
|
186
|
+
const _unwatch = getAction(
|
|
187
|
+
client,
|
|
188
|
+
watchBlockNumber,
|
|
189
|
+
"watchBlockNumber"
|
|
190
|
+
)({
|
|
191
|
+
emitMissed: true,
|
|
192
|
+
emitOnBegin: true,
|
|
193
|
+
poll: true,
|
|
194
|
+
pollingInterval,
|
|
195
|
+
async onBlockNumber(blockNumber) {
|
|
196
|
+
const done = (fn: () => void) => {
|
|
197
|
+
_unwatch()
|
|
198
|
+
fn()
|
|
199
|
+
_unobserve()
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (count > retryCount)
|
|
203
|
+
done(() =>
|
|
204
|
+
emit.reject(
|
|
205
|
+
new WaitForTransactionReceiptTimeoutError({
|
|
206
|
+
hash: id as Hash
|
|
207
|
+
})
|
|
208
|
+
)
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
try {
|
|
212
|
+
// If we already have a valid receipt, let's check if we have enough
|
|
213
|
+
// confirmations. If we do, then we can resolve.
|
|
214
|
+
if (receipt) {
|
|
215
|
+
if (
|
|
216
|
+
confirmations > 1 &&
|
|
217
|
+
(!receipt.receipts?.[0]?.blockNumber ||
|
|
218
|
+
blockNumber -
|
|
219
|
+
receipt.receipts?.[0]?.blockNumber +
|
|
220
|
+
1n <
|
|
221
|
+
confirmations)
|
|
222
|
+
)
|
|
223
|
+
return
|
|
224
|
+
|
|
225
|
+
if (receipt.status === "PENDING") {
|
|
226
|
+
return
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (receipt.receipts?.length === 0) {
|
|
230
|
+
return
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const finalReceipt = receipt.receipts
|
|
234
|
+
|
|
235
|
+
if (!finalReceipt) {
|
|
236
|
+
return
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const transactionReceipt = await getAction(
|
|
240
|
+
client,
|
|
241
|
+
getTransactionReceipt,
|
|
242
|
+
"getTransactionReceipt"
|
|
243
|
+
)({ hash: finalReceipt[0].transactionHash })
|
|
244
|
+
|
|
245
|
+
done(() =>
|
|
246
|
+
emit.resolve({
|
|
247
|
+
...transactionReceipt,
|
|
248
|
+
chainId: client.chain.id
|
|
249
|
+
} as WaitForTransactionReceiptReturnType<
|
|
250
|
+
config,
|
|
251
|
+
chainId
|
|
252
|
+
>)
|
|
253
|
+
)
|
|
254
|
+
return
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// Get the receipt to check if it's been processed.
|
|
258
|
+
receipt = await getAction(
|
|
259
|
+
client,
|
|
260
|
+
getCallsStatus,
|
|
261
|
+
"getCallsStatus"
|
|
262
|
+
)({ id })
|
|
263
|
+
|
|
264
|
+
if (receipt.status === "PENDING") {
|
|
265
|
+
return
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// Check if we have enough confirmations. If not, continue polling.
|
|
269
|
+
if (
|
|
270
|
+
confirmations > 1 &&
|
|
271
|
+
(!receipt.receipts?.[0]?.blockNumber ||
|
|
272
|
+
blockNumber -
|
|
273
|
+
receipt.receipts?.[0]?.blockNumber +
|
|
274
|
+
1n <
|
|
275
|
+
confirmations)
|
|
276
|
+
)
|
|
277
|
+
return
|
|
278
|
+
|
|
279
|
+
if (receipt.receipts?.length === 0) {
|
|
280
|
+
return
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const finalReceipt = receipt.receipts
|
|
284
|
+
|
|
285
|
+
if (!finalReceipt) {
|
|
286
|
+
return
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const transactionReceipt = await getAction(
|
|
290
|
+
client,
|
|
291
|
+
getTransactionReceipt,
|
|
292
|
+
"getTransactionReceipt"
|
|
293
|
+
)({ hash: finalReceipt[0].transactionHash })
|
|
294
|
+
|
|
295
|
+
done(() =>
|
|
296
|
+
emit.resolve({
|
|
297
|
+
...transactionReceipt,
|
|
298
|
+
chainId: client.chain.id
|
|
299
|
+
} as WaitForTransactionReceiptReturnType<
|
|
300
|
+
config,
|
|
301
|
+
chainId
|
|
302
|
+
>)
|
|
303
|
+
)
|
|
304
|
+
} catch (err) {
|
|
305
|
+
done(() => emit.reject(err))
|
|
306
|
+
} finally {
|
|
307
|
+
count++
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
})
|
|
311
|
+
})
|
|
312
|
+
})
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
export function waitForTransactionReceiptQueryOptions<
|
|
316
|
+
config extends Config,
|
|
317
|
+
chainId extends
|
|
318
|
+
config["chains"][number]["id"] = config["chains"][number]["id"]
|
|
319
|
+
>(
|
|
320
|
+
config: config,
|
|
321
|
+
options: Omit<
|
|
322
|
+
WaitForTransactionReceiptOptions<config, chainId>,
|
|
323
|
+
"hash" | "onReplaced"
|
|
324
|
+
> & {
|
|
325
|
+
id?: string
|
|
326
|
+
capabilities?: WalletSendCallsParameters<WalletCapabilities>[number]["capabilities"]
|
|
327
|
+
}
|
|
328
|
+
) {
|
|
329
|
+
return {
|
|
330
|
+
async queryFn({ queryKey }) {
|
|
331
|
+
const { scopeKey: _, id, ...parameters } = queryKey[1]
|
|
332
|
+
if (!id) throw new Error("id is required")
|
|
333
|
+
|
|
334
|
+
if (!options.capabilities && !isHash(id)) {
|
|
335
|
+
throw new Error("capabilities or hash is required")
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
if (options.capabilities) {
|
|
339
|
+
const status = await waitForCallsStatus(config, {
|
|
340
|
+
id,
|
|
341
|
+
...parameters
|
|
342
|
+
})
|
|
343
|
+
|
|
344
|
+
return status
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
const status = await waitForTransactionReceipt(config, {
|
|
348
|
+
hash: id as Hash,
|
|
349
|
+
...options,
|
|
350
|
+
...parameters
|
|
351
|
+
})
|
|
352
|
+
return status
|
|
353
|
+
},
|
|
354
|
+
queryKey: waitForTransactionReceiptQueryKey(options),
|
|
355
|
+
retry(failureCount, error) {
|
|
356
|
+
if (error instanceof ConnectorNotConnectedError) return false
|
|
357
|
+
return failureCount < 3
|
|
358
|
+
}
|
|
359
|
+
} as const satisfies QueryOptions<
|
|
360
|
+
WaitForTransactionReceiptQueryFnData<config, chainId>,
|
|
361
|
+
WaitForTransactionReceiptErrorType | ShowCallsStatusErrorType,
|
|
362
|
+
WaitForTransactionReceiptData<config, chainId>,
|
|
363
|
+
WaitForTransactionReceiptQueryKey<config, chainId>
|
|
364
|
+
>
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
export type UseCallsStatusReturnType<selectData = GetCallsStatusData> =
|
|
368
|
+
UseQueryReturnType<selectData, GetCallsStatusErrorType>
|
|
369
|
+
|
|
370
|
+
export type UseWaitForTransactionReceiptReturnType<
|
|
371
|
+
config extends Config = Config,
|
|
372
|
+
chainId extends
|
|
373
|
+
config["chains"][number]["id"] = config["chains"][number]["id"],
|
|
374
|
+
selectData = WaitForTransactionReceiptData<config, chainId>
|
|
375
|
+
> = UseQueryReturnType<
|
|
376
|
+
selectData,
|
|
377
|
+
WaitForTransactionReceiptErrorType | ShowCallsStatusErrorType
|
|
378
|
+
>
|
|
379
|
+
|
|
380
|
+
export type UseWaitForTransactionReceiptParameters<
|
|
381
|
+
config extends Config = Config,
|
|
382
|
+
chainId extends
|
|
383
|
+
config["chains"][number]["id"] = config["chains"][number]["id"],
|
|
384
|
+
selectData = WaitForTransactionReceiptData<config, chainId>
|
|
385
|
+
> = Prettify<
|
|
386
|
+
Omit<
|
|
387
|
+
WaitForTransactionReceiptOptions<config, chainId>,
|
|
388
|
+
"hash" | "onReplaced"
|
|
389
|
+
> & {
|
|
390
|
+
id?: string
|
|
391
|
+
} & ConfigParameter<config> &
|
|
392
|
+
QueryParameter<
|
|
393
|
+
WaitForTransactionReceiptQueryFnData<config, chainId>,
|
|
394
|
+
WaitForTransactionReceiptErrorType,
|
|
395
|
+
selectData,
|
|
396
|
+
WaitForTransactionReceiptQueryKey<config, chainId>
|
|
397
|
+
>
|
|
398
|
+
>
|
|
399
|
+
|
|
400
|
+
export function useWaitForTransactionReceipt<
|
|
401
|
+
config extends Config = ResolvedRegister["config"],
|
|
402
|
+
chainId extends
|
|
403
|
+
config["chains"][number]["id"] = config["chains"][number]["id"],
|
|
404
|
+
selectData = WaitForTransactionReceiptData<config, chainId>
|
|
405
|
+
>(
|
|
406
|
+
parameters: UseWaitForTransactionReceiptParameters<
|
|
407
|
+
config,
|
|
408
|
+
chainId,
|
|
409
|
+
selectData
|
|
410
|
+
> = {}
|
|
411
|
+
): UseWaitForTransactionReceiptReturnType<config, chainId, selectData> {
|
|
412
|
+
const { query = {} } = parameters
|
|
413
|
+
const { capabilities } = useAvailableCapabilities()
|
|
414
|
+
|
|
415
|
+
const config = useConfig(parameters)
|
|
416
|
+
const chainId = useChainId({ config })
|
|
417
|
+
|
|
418
|
+
const enabled = Boolean(parameters.id && (query.enabled ?? true))
|
|
419
|
+
|
|
420
|
+
const options = waitForTransactionReceiptQueryOptions(config, {
|
|
421
|
+
...parameters,
|
|
422
|
+
chainId: parameters.chainId ?? chainId,
|
|
423
|
+
capabilities
|
|
424
|
+
})
|
|
425
|
+
|
|
426
|
+
return useQuery({
|
|
427
|
+
...query,
|
|
428
|
+
...options,
|
|
429
|
+
enabled
|
|
430
|
+
}) as UseWaitForTransactionReceiptReturnType<config, chainId, selectData>
|
|
431
|
+
}
|
package/index.ts
CHANGED
|
@@ -1,32 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type SimpleSmartAccountParameters,
|
|
3
|
-
simpleSmartAccount
|
|
4
|
-
} from "./connectors/simpleSmartAccount"
|
|
5
|
-
import { smartAccount } from "./connectors/smartAccount"
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
type SafeSmartAccountParameters,
|
|
9
|
-
safeSmartAccount
|
|
10
|
-
} from "./connectors/safeSmartAccount"
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
type BiconomySmartAccountParameters,
|
|
14
|
-
biconomySmartAccount
|
|
15
|
-
} from "./connectors/biconomySmartAccount"
|
|
16
|
-
|
|
17
|
-
import {
|
|
18
|
-
type KernelSmartAccountParameters,
|
|
19
|
-
kernelSmartAccount
|
|
20
|
-
} from "./connectors/kernelSmartAccount"
|
|
21
|
-
|
|
22
1
|
export {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
type BiconomySmartAccountParameters,
|
|
30
|
-
kernelSmartAccount,
|
|
31
|
-
type KernelSmartAccountParameters
|
|
32
|
-
}
|
|
2
|
+
PermissionlessProvider,
|
|
3
|
+
type PermissionlessProviderProps
|
|
4
|
+
} from "./context"
|
|
5
|
+
|
|
6
|
+
export { useSendTransaction } from "./hooks/useSendTransaction"
|
|
7
|
+
export { useWaitForTransactionReceipt } from "./hooks/useWaitForTransactionReceipt"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@permissionless/wagmi",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"author": "Pimlico",
|
|
5
5
|
"homepage": "https://docs.pimlico.io/permissionless/wagmi",
|
|
6
6
|
"repository": "github:pimlicolabs/permissionless.js",
|
|
@@ -11,13 +11,7 @@
|
|
|
11
11
|
"type": "module",
|
|
12
12
|
"sideEffects": false,
|
|
13
13
|
"description": "A utility library for working with ERC-4337",
|
|
14
|
-
"keywords": [
|
|
15
|
-
"ethereum",
|
|
16
|
-
"erc-4337",
|
|
17
|
-
"eip-4337",
|
|
18
|
-
"paymaster",
|
|
19
|
-
"bundler"
|
|
20
|
-
],
|
|
14
|
+
"keywords": ["ethereum", "erc-4337", "eip-4337", "paymaster", "bundler"],
|
|
21
15
|
"license": "MIT",
|
|
22
16
|
"exports": {
|
|
23
17
|
".": {
|
|
@@ -27,8 +21,6 @@
|
|
|
27
21
|
}
|
|
28
22
|
},
|
|
29
23
|
"peerDependencies": {
|
|
30
|
-
"wagmi": "^2.
|
|
31
|
-
"viem": "^2.0.0",
|
|
32
|
-
"permissionless": "^0.0.36"
|
|
24
|
+
"wagmi": "^2.12.8"
|
|
33
25
|
}
|
|
34
26
|
}
|