@aave/react 4.0.0-next.4 → 4.0.0-next.41
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 +8 -3
- package/dist/chunk-4GURAVFN.js +2 -0
- package/dist/chunk-4GURAVFN.js.map +1 -0
- package/dist/chunk-4NA4FB6K.js +2 -0
- package/dist/chunk-4NA4FB6K.js.map +1 -0
- package/dist/chunk-IAK4S3R4.js +2 -0
- package/dist/chunk-IAK4S3R4.js.map +1 -0
- package/dist/ethers.cjs +1 -1
- package/dist/ethers.cjs.map +1 -1
- package/dist/ethers.d.cts +10 -66
- package/dist/ethers.d.ts +10 -66
- package/dist/ethers.js +1 -1
- package/dist/ethers.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1112 -351
- package/dist/index.d.ts +1112 -351
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/{misc-BkG5G4yl.d.cts → misc-COaS62_P.d.ts} +54 -24
- package/dist/{misc-gmAnSdm5.d.ts → misc-DBn3Mp67.d.cts} +54 -24
- package/dist/privy.cjs +1 -1
- package/dist/privy.cjs.map +1 -1
- package/dist/privy.d.cts +9 -54
- package/dist/privy.d.ts +9 -54
- package/dist/privy.js +1 -1
- package/dist/privy.js.map +1 -1
- package/dist/thirdweb.cjs +1 -1
- package/dist/thirdweb.cjs.map +1 -1
- package/dist/thirdweb.d.cts +9 -54
- package/dist/thirdweb.d.ts +9 -54
- package/dist/thirdweb.js +1 -1
- package/dist/thirdweb.js.map +1 -1
- package/dist/viem/index.cjs +1 -1
- package/dist/viem/index.cjs.map +1 -1
- package/dist/viem/index.d.cts +13 -68
- package/dist/viem/index.d.ts +13 -68
- package/dist/viem/index.js +1 -1
- package/dist/viem/index.js.map +1 -1
- package/dist/{writes-BXnwYgAQ.d.cts → writes-CcVGQGt5.d.cts} +13 -6
- package/dist/{writes-BXnwYgAQ.d.ts → writes-CcVGQGt5.d.ts} +13 -6
- package/package.json +6 -6
- package/dist/chunk-GTUQRT5Q.js +0 -2
- package/dist/chunk-GTUQRT5Q.js.map +0 -1
- package/dist/chunk-YJ6HF5HO.js +0 -2
- package/dist/chunk-YJ6HF5HO.js.map +0 -1
|
@@ -1,32 +1,36 @@
|
|
|
1
1
|
import { UnexpectedError, CurrencyQueryOptions } from '@aave/client';
|
|
2
2
|
import { UnexpectedError as UnexpectedError$1 } from '@aave/core';
|
|
3
|
-
import { ChainRequest, Chain,
|
|
3
|
+
import { ChainRequest, Chain, ChainsRequest, ExchangeRateRequest, ExchangeAmount, ActivityItem, PreviewAction, NativeAmount } from '@aave/graphql';
|
|
4
4
|
import { NullishDeep, Prettify } from '@aave/types';
|
|
5
|
-
import { a as UseAsyncTask } from './writes-
|
|
5
|
+
import { a as UseAsyncTask } from './writes-CcVGQGt5.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* A read hook result that supports pausing.
|
|
9
9
|
*/
|
|
10
|
-
type PausableReadResult<T, E
|
|
10
|
+
type PausableReadResult<T, E = UnexpectedError> = {
|
|
11
11
|
data: T | undefined;
|
|
12
12
|
error: E | undefined;
|
|
13
13
|
loading: false;
|
|
14
14
|
paused: true;
|
|
15
|
+
reloading: false;
|
|
15
16
|
} | {
|
|
16
17
|
data: undefined;
|
|
17
18
|
error: undefined;
|
|
18
19
|
loading: true;
|
|
19
20
|
paused: false;
|
|
21
|
+
reloading: false;
|
|
20
22
|
} | {
|
|
21
23
|
data: T;
|
|
22
24
|
error: undefined;
|
|
23
25
|
loading: false;
|
|
24
26
|
paused: false;
|
|
27
|
+
reloading: boolean;
|
|
25
28
|
} | {
|
|
26
29
|
data: undefined;
|
|
27
30
|
error: E;
|
|
28
31
|
loading: false;
|
|
29
32
|
paused: false;
|
|
33
|
+
reloading: boolean;
|
|
30
34
|
};
|
|
31
35
|
/**
|
|
32
36
|
* A read hook result.
|
|
@@ -35,27 +39,30 @@ type PausableReadResult<T, E extends UnexpectedError = UnexpectedError> = {
|
|
|
35
39
|
* - Rely on the `loading` value to determine if the `data` or `error` can be evaluated.
|
|
36
40
|
* - If `error` is `undefined`, then `data` value will be available.
|
|
37
41
|
*/
|
|
38
|
-
type ReadResult<T, E
|
|
42
|
+
type ReadResult<T, E = UnexpectedError> = {
|
|
39
43
|
data: undefined;
|
|
40
44
|
error: undefined;
|
|
41
45
|
loading: true;
|
|
46
|
+
reloading: false;
|
|
42
47
|
} | {
|
|
43
48
|
data: T;
|
|
44
49
|
error: undefined;
|
|
45
50
|
loading: false;
|
|
51
|
+
reloading: boolean;
|
|
46
52
|
} | {
|
|
47
53
|
data: undefined;
|
|
48
54
|
error: E;
|
|
49
55
|
loading: false;
|
|
56
|
+
reloading: boolean;
|
|
50
57
|
};
|
|
51
58
|
/**
|
|
52
59
|
* @internal
|
|
53
60
|
*/
|
|
54
61
|
declare const ReadResult: {
|
|
55
|
-
Loading: <T, E
|
|
56
|
-
Success: <T, E
|
|
57
|
-
Failure: <T, E
|
|
58
|
-
Paused: <T, E
|
|
62
|
+
Loading: <T, E = UnexpectedError>() => PausableReadResult<T, E>;
|
|
63
|
+
Success: <T, E = UnexpectedError>(data: T, reloading?: boolean) => PausableReadResult<T, E>;
|
|
64
|
+
Failure: <T, E = UnexpectedError>(error: E, reloading?: boolean) => PausableReadResult<T, E>;
|
|
65
|
+
Paused: <T, E = UnexpectedError>(data: T | undefined, error: E | undefined) => PausableReadResult<T, E>;
|
|
59
66
|
};
|
|
60
67
|
/**
|
|
61
68
|
* A read hook result that supports React Suspense.
|
|
@@ -74,7 +81,6 @@ type PausableSuspenseResult<T> = {
|
|
|
74
81
|
data: T;
|
|
75
82
|
};
|
|
76
83
|
|
|
77
|
-
type Selector<T, V> = (data: T) => V;
|
|
78
84
|
type Pausable<T, WhenPaused = NullishDeep<T>> = Prettify<WhenPaused & {
|
|
79
85
|
/**
|
|
80
86
|
* Prevents the hook from automatically executing GraphQL query operations.
|
|
@@ -83,8 +89,8 @@ type Pausable<T, WhenPaused = NullishDeep<T>> = Prettify<WhenPaused & {
|
|
|
83
89
|
*
|
|
84
90
|
* @remarks
|
|
85
91
|
* `pause` may be set to `true` to stop the query operation from executing
|
|
86
|
-
* automatically. The hook will stop receiving updates and won
|
|
87
|
-
* operation until it
|
|
92
|
+
* automatically. The hook will stop receiving updates and won't execute the query
|
|
93
|
+
* operation until it's set to `false`.
|
|
88
94
|
*/
|
|
89
95
|
pause: boolean;
|
|
90
96
|
}>;
|
|
@@ -145,9 +151,33 @@ declare function useChain(args: UseChainArgs): ReadResult<Chain | null>;
|
|
|
145
151
|
* ```
|
|
146
152
|
*/
|
|
147
153
|
declare function useChain(args: Pausable<UseChainArgs>): PausableReadResult<Chain | null>;
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
154
|
+
/**
|
|
155
|
+
* Low-level hook to execute a {@link chain} action directly.
|
|
156
|
+
*
|
|
157
|
+
* @experimental This hook is experimental and may be subject to breaking changes.
|
|
158
|
+
* @remarks
|
|
159
|
+
* This hook **does not** actively watch for updated data on the chain.
|
|
160
|
+
* Use this hook to retrieve data on demand as part of a larger workflow
|
|
161
|
+
* (e.g., in an event handler in order to move to the next step).
|
|
162
|
+
*
|
|
163
|
+
* ```ts
|
|
164
|
+
* const [execute, { called, data, error, loading }] = useChainAction();
|
|
165
|
+
*
|
|
166
|
+
* // …
|
|
167
|
+
*
|
|
168
|
+
* const result = await execute({
|
|
169
|
+
* chainId: chainId(1),
|
|
170
|
+
* });
|
|
171
|
+
*
|
|
172
|
+
* if (result.isOk()) {
|
|
173
|
+
* console.log(result.value); // Chain | null
|
|
174
|
+
* } else {
|
|
175
|
+
* console.error(result.error);
|
|
176
|
+
* }
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
declare function useChainAction(): UseAsyncTask<ChainRequest, Chain | null, UnexpectedError$1>;
|
|
180
|
+
type UseChainsArgs = ChainsRequest;
|
|
151
181
|
/**
|
|
152
182
|
* Fetches the list of supported chains.
|
|
153
183
|
*
|
|
@@ -155,7 +185,7 @@ type UseChainsArgs = {
|
|
|
155
185
|
*
|
|
156
186
|
* ```tsx
|
|
157
187
|
* const { data } = useChains({
|
|
158
|
-
* filter: ChainsFilter.ALL,
|
|
188
|
+
* query: { filter: ChainsFilter.ALL },
|
|
159
189
|
* suspense: true,
|
|
160
190
|
* });
|
|
161
191
|
* ```
|
|
@@ -168,7 +198,7 @@ declare function useChains(args: UseChainsArgs & Suspendable): SuspenseResult<Ch
|
|
|
168
198
|
*
|
|
169
199
|
* ```tsx
|
|
170
200
|
* const { data } = useChains({
|
|
171
|
-
* filter: ChainsFilter.ALL,
|
|
201
|
+
* query: { filter: ChainsFilter.ALL },
|
|
172
202
|
* suspense: true,
|
|
173
203
|
* pause: true,
|
|
174
204
|
* });
|
|
@@ -180,7 +210,7 @@ declare function useChains(args: Pausable<UseChainsArgs> & Suspendable): Pausabl
|
|
|
180
210
|
*
|
|
181
211
|
* ```tsx
|
|
182
212
|
* const { data, error, loading } = useChains({
|
|
183
|
-
* filter: ChainsFilter.ALL,
|
|
213
|
+
* query: { filter: ChainsFilter.ALL },
|
|
184
214
|
* });
|
|
185
215
|
* ```
|
|
186
216
|
*/
|
|
@@ -192,7 +222,7 @@ declare function useChains(args?: UseChainsArgs): ReadResult<Chain[]>;
|
|
|
192
222
|
*
|
|
193
223
|
* ```tsx
|
|
194
224
|
* const { data, error, loading, paused } = useChains({
|
|
195
|
-
* filter: ChainsFilter.ALL,
|
|
225
|
+
* query: { filter: ChainsFilter.ALL },
|
|
196
226
|
* pause: true,
|
|
197
227
|
* });
|
|
198
228
|
* ```
|
|
@@ -222,7 +252,7 @@ declare function useChains(args?: Pausable<UseChainsArgs>): PausableReadResult<C
|
|
|
222
252
|
* console.log('Exchange rate:', result.value);
|
|
223
253
|
* ```
|
|
224
254
|
*/
|
|
225
|
-
declare function useExchangeRateAction(): UseAsyncTask<ExchangeRateRequest,
|
|
255
|
+
declare function useExchangeRateAction(): UseAsyncTask<ExchangeRateRequest, ExchangeAmount, UnexpectedError$1>;
|
|
226
256
|
type UseExchangeRateArgs = ExchangeRateRequest;
|
|
227
257
|
/**
|
|
228
258
|
* Fetches exchange rates between tokens and fiat currencies with automatic polling.
|
|
@@ -242,7 +272,7 @@ type UseExchangeRateArgs = ExchangeRateRequest;
|
|
|
242
272
|
* });
|
|
243
273
|
* ```
|
|
244
274
|
*/
|
|
245
|
-
declare function useExchangeRate(args: UseExchangeRateArgs & Suspendable): SuspenseResult<
|
|
275
|
+
declare function useExchangeRate(args: UseExchangeRateArgs & Suspendable): SuspenseResult<ExchangeAmount>;
|
|
246
276
|
/**
|
|
247
277
|
* Fetches exchange rates between tokens and fiat currencies with automatic polling.
|
|
248
278
|
*
|
|
@@ -262,7 +292,7 @@ declare function useExchangeRate(args: UseExchangeRateArgs & Suspendable): Suspe
|
|
|
262
292
|
* });
|
|
263
293
|
* ```
|
|
264
294
|
*/
|
|
265
|
-
declare function useExchangeRate(args: Pausable<UseExchangeRateArgs> & Suspendable): PausableSuspenseResult<
|
|
295
|
+
declare function useExchangeRate(args: Pausable<UseExchangeRateArgs> & Suspendable): PausableSuspenseResult<ExchangeAmount>;
|
|
266
296
|
/**
|
|
267
297
|
* Fetches exchange rates between tokens and fiat currencies with automatic polling.
|
|
268
298
|
*
|
|
@@ -280,7 +310,7 @@ declare function useExchangeRate(args: Pausable<UseExchangeRateArgs> & Suspendab
|
|
|
280
310
|
* <Component value={somewhere} fxRate={data} />
|
|
281
311
|
* ```
|
|
282
312
|
*/
|
|
283
|
-
declare function useExchangeRate(args: UseExchangeRateArgs): ReadResult<
|
|
313
|
+
declare function useExchangeRate(args: UseExchangeRateArgs): ReadResult<ExchangeAmount>;
|
|
284
314
|
/**
|
|
285
315
|
* Fetches exchange rates between tokens and fiat currencies with automatic polling.
|
|
286
316
|
*
|
|
@@ -299,7 +329,7 @@ declare function useExchangeRate(args: UseExchangeRateArgs): ReadResult<FiatAmou
|
|
|
299
329
|
* });
|
|
300
330
|
* ```
|
|
301
331
|
*/
|
|
302
|
-
declare function useExchangeRate(args: Pausable<UseExchangeRateArgs>): PausableReadResult<
|
|
332
|
+
declare function useExchangeRate(args: Pausable<UseExchangeRateArgs>): PausableReadResult<ExchangeAmount>;
|
|
303
333
|
type UseNetworkFeeRequestQuery = {
|
|
304
334
|
activity: ActivityItem;
|
|
305
335
|
} | {
|
|
@@ -374,4 +404,4 @@ type UseNetworkFee<T extends NativeAmount = NativeAmount> =
|
|
|
374
404
|
*/
|
|
375
405
|
((args: Pausable<UseNetworkFeeArgs, PausableUseNetworkFeeArgs>) => PausableReadResult<T>);
|
|
376
406
|
|
|
377
|
-
export { type Pausable as P, ReadResult as R, type Suspendable as S, type UseNetworkFee as U, type SuspenseResult as a, type PausableSuspenseResult as b, type PausableReadResult as c, type
|
|
407
|
+
export { type Pausable as P, ReadResult as R, type Suspendable as S, type UseNetworkFee as U, type SuspenseResult as a, type PausableSuspenseResult as b, type PausableReadResult as c, type UseChainArgs as d, useChainAction as e, type UseChainsArgs as f, useChains as g, useExchangeRateAction as h, type UseExchangeRateArgs as i, useExchangeRate as j, type UseNetworkFeeRequestQuery as k, type UseNetworkFeeArgs as l, useChain as u };
|
|
@@ -1,32 +1,36 @@
|
|
|
1
1
|
import { UnexpectedError, CurrencyQueryOptions } from '@aave/client';
|
|
2
2
|
import { UnexpectedError as UnexpectedError$1 } from '@aave/core';
|
|
3
|
-
import { ChainRequest, Chain,
|
|
3
|
+
import { ChainRequest, Chain, ChainsRequest, ExchangeRateRequest, ExchangeAmount, ActivityItem, PreviewAction, NativeAmount } from '@aave/graphql';
|
|
4
4
|
import { NullishDeep, Prettify } from '@aave/types';
|
|
5
|
-
import { a as UseAsyncTask } from './writes-
|
|
5
|
+
import { a as UseAsyncTask } from './writes-CcVGQGt5.cjs';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* A read hook result that supports pausing.
|
|
9
9
|
*/
|
|
10
|
-
type PausableReadResult<T, E
|
|
10
|
+
type PausableReadResult<T, E = UnexpectedError> = {
|
|
11
11
|
data: T | undefined;
|
|
12
12
|
error: E | undefined;
|
|
13
13
|
loading: false;
|
|
14
14
|
paused: true;
|
|
15
|
+
reloading: false;
|
|
15
16
|
} | {
|
|
16
17
|
data: undefined;
|
|
17
18
|
error: undefined;
|
|
18
19
|
loading: true;
|
|
19
20
|
paused: false;
|
|
21
|
+
reloading: false;
|
|
20
22
|
} | {
|
|
21
23
|
data: T;
|
|
22
24
|
error: undefined;
|
|
23
25
|
loading: false;
|
|
24
26
|
paused: false;
|
|
27
|
+
reloading: boolean;
|
|
25
28
|
} | {
|
|
26
29
|
data: undefined;
|
|
27
30
|
error: E;
|
|
28
31
|
loading: false;
|
|
29
32
|
paused: false;
|
|
33
|
+
reloading: boolean;
|
|
30
34
|
};
|
|
31
35
|
/**
|
|
32
36
|
* A read hook result.
|
|
@@ -35,27 +39,30 @@ type PausableReadResult<T, E extends UnexpectedError = UnexpectedError> = {
|
|
|
35
39
|
* - Rely on the `loading` value to determine if the `data` or `error` can be evaluated.
|
|
36
40
|
* - If `error` is `undefined`, then `data` value will be available.
|
|
37
41
|
*/
|
|
38
|
-
type ReadResult<T, E
|
|
42
|
+
type ReadResult<T, E = UnexpectedError> = {
|
|
39
43
|
data: undefined;
|
|
40
44
|
error: undefined;
|
|
41
45
|
loading: true;
|
|
46
|
+
reloading: false;
|
|
42
47
|
} | {
|
|
43
48
|
data: T;
|
|
44
49
|
error: undefined;
|
|
45
50
|
loading: false;
|
|
51
|
+
reloading: boolean;
|
|
46
52
|
} | {
|
|
47
53
|
data: undefined;
|
|
48
54
|
error: E;
|
|
49
55
|
loading: false;
|
|
56
|
+
reloading: boolean;
|
|
50
57
|
};
|
|
51
58
|
/**
|
|
52
59
|
* @internal
|
|
53
60
|
*/
|
|
54
61
|
declare const ReadResult: {
|
|
55
|
-
Loading: <T, E
|
|
56
|
-
Success: <T, E
|
|
57
|
-
Failure: <T, E
|
|
58
|
-
Paused: <T, E
|
|
62
|
+
Loading: <T, E = UnexpectedError>() => PausableReadResult<T, E>;
|
|
63
|
+
Success: <T, E = UnexpectedError>(data: T, reloading?: boolean) => PausableReadResult<T, E>;
|
|
64
|
+
Failure: <T, E = UnexpectedError>(error: E, reloading?: boolean) => PausableReadResult<T, E>;
|
|
65
|
+
Paused: <T, E = UnexpectedError>(data: T | undefined, error: E | undefined) => PausableReadResult<T, E>;
|
|
59
66
|
};
|
|
60
67
|
/**
|
|
61
68
|
* A read hook result that supports React Suspense.
|
|
@@ -74,7 +81,6 @@ type PausableSuspenseResult<T> = {
|
|
|
74
81
|
data: T;
|
|
75
82
|
};
|
|
76
83
|
|
|
77
|
-
type Selector<T, V> = (data: T) => V;
|
|
78
84
|
type Pausable<T, WhenPaused = NullishDeep<T>> = Prettify<WhenPaused & {
|
|
79
85
|
/**
|
|
80
86
|
* Prevents the hook from automatically executing GraphQL query operations.
|
|
@@ -83,8 +89,8 @@ type Pausable<T, WhenPaused = NullishDeep<T>> = Prettify<WhenPaused & {
|
|
|
83
89
|
*
|
|
84
90
|
* @remarks
|
|
85
91
|
* `pause` may be set to `true` to stop the query operation from executing
|
|
86
|
-
* automatically. The hook will stop receiving updates and won
|
|
87
|
-
* operation until it
|
|
92
|
+
* automatically. The hook will stop receiving updates and won't execute the query
|
|
93
|
+
* operation until it's set to `false`.
|
|
88
94
|
*/
|
|
89
95
|
pause: boolean;
|
|
90
96
|
}>;
|
|
@@ -145,9 +151,33 @@ declare function useChain(args: UseChainArgs): ReadResult<Chain | null>;
|
|
|
145
151
|
* ```
|
|
146
152
|
*/
|
|
147
153
|
declare function useChain(args: Pausable<UseChainArgs>): PausableReadResult<Chain | null>;
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
154
|
+
/**
|
|
155
|
+
* Low-level hook to execute a {@link chain} action directly.
|
|
156
|
+
*
|
|
157
|
+
* @experimental This hook is experimental and may be subject to breaking changes.
|
|
158
|
+
* @remarks
|
|
159
|
+
* This hook **does not** actively watch for updated data on the chain.
|
|
160
|
+
* Use this hook to retrieve data on demand as part of a larger workflow
|
|
161
|
+
* (e.g., in an event handler in order to move to the next step).
|
|
162
|
+
*
|
|
163
|
+
* ```ts
|
|
164
|
+
* const [execute, { called, data, error, loading }] = useChainAction();
|
|
165
|
+
*
|
|
166
|
+
* // …
|
|
167
|
+
*
|
|
168
|
+
* const result = await execute({
|
|
169
|
+
* chainId: chainId(1),
|
|
170
|
+
* });
|
|
171
|
+
*
|
|
172
|
+
* if (result.isOk()) {
|
|
173
|
+
* console.log(result.value); // Chain | null
|
|
174
|
+
* } else {
|
|
175
|
+
* console.error(result.error);
|
|
176
|
+
* }
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
declare function useChainAction(): UseAsyncTask<ChainRequest, Chain | null, UnexpectedError$1>;
|
|
180
|
+
type UseChainsArgs = ChainsRequest;
|
|
151
181
|
/**
|
|
152
182
|
* Fetches the list of supported chains.
|
|
153
183
|
*
|
|
@@ -155,7 +185,7 @@ type UseChainsArgs = {
|
|
|
155
185
|
*
|
|
156
186
|
* ```tsx
|
|
157
187
|
* const { data } = useChains({
|
|
158
|
-
* filter: ChainsFilter.ALL,
|
|
188
|
+
* query: { filter: ChainsFilter.ALL },
|
|
159
189
|
* suspense: true,
|
|
160
190
|
* });
|
|
161
191
|
* ```
|
|
@@ -168,7 +198,7 @@ declare function useChains(args: UseChainsArgs & Suspendable): SuspenseResult<Ch
|
|
|
168
198
|
*
|
|
169
199
|
* ```tsx
|
|
170
200
|
* const { data } = useChains({
|
|
171
|
-
* filter: ChainsFilter.ALL,
|
|
201
|
+
* query: { filter: ChainsFilter.ALL },
|
|
172
202
|
* suspense: true,
|
|
173
203
|
* pause: true,
|
|
174
204
|
* });
|
|
@@ -180,7 +210,7 @@ declare function useChains(args: Pausable<UseChainsArgs> & Suspendable): Pausabl
|
|
|
180
210
|
*
|
|
181
211
|
* ```tsx
|
|
182
212
|
* const { data, error, loading } = useChains({
|
|
183
|
-
* filter: ChainsFilter.ALL,
|
|
213
|
+
* query: { filter: ChainsFilter.ALL },
|
|
184
214
|
* });
|
|
185
215
|
* ```
|
|
186
216
|
*/
|
|
@@ -192,7 +222,7 @@ declare function useChains(args?: UseChainsArgs): ReadResult<Chain[]>;
|
|
|
192
222
|
*
|
|
193
223
|
* ```tsx
|
|
194
224
|
* const { data, error, loading, paused } = useChains({
|
|
195
|
-
* filter: ChainsFilter.ALL,
|
|
225
|
+
* query: { filter: ChainsFilter.ALL },
|
|
196
226
|
* pause: true,
|
|
197
227
|
* });
|
|
198
228
|
* ```
|
|
@@ -222,7 +252,7 @@ declare function useChains(args?: Pausable<UseChainsArgs>): PausableReadResult<C
|
|
|
222
252
|
* console.log('Exchange rate:', result.value);
|
|
223
253
|
* ```
|
|
224
254
|
*/
|
|
225
|
-
declare function useExchangeRateAction(): UseAsyncTask<ExchangeRateRequest,
|
|
255
|
+
declare function useExchangeRateAction(): UseAsyncTask<ExchangeRateRequest, ExchangeAmount, UnexpectedError$1>;
|
|
226
256
|
type UseExchangeRateArgs = ExchangeRateRequest;
|
|
227
257
|
/**
|
|
228
258
|
* Fetches exchange rates between tokens and fiat currencies with automatic polling.
|
|
@@ -242,7 +272,7 @@ type UseExchangeRateArgs = ExchangeRateRequest;
|
|
|
242
272
|
* });
|
|
243
273
|
* ```
|
|
244
274
|
*/
|
|
245
|
-
declare function useExchangeRate(args: UseExchangeRateArgs & Suspendable): SuspenseResult<
|
|
275
|
+
declare function useExchangeRate(args: UseExchangeRateArgs & Suspendable): SuspenseResult<ExchangeAmount>;
|
|
246
276
|
/**
|
|
247
277
|
* Fetches exchange rates between tokens and fiat currencies with automatic polling.
|
|
248
278
|
*
|
|
@@ -262,7 +292,7 @@ declare function useExchangeRate(args: UseExchangeRateArgs & Suspendable): Suspe
|
|
|
262
292
|
* });
|
|
263
293
|
* ```
|
|
264
294
|
*/
|
|
265
|
-
declare function useExchangeRate(args: Pausable<UseExchangeRateArgs> & Suspendable): PausableSuspenseResult<
|
|
295
|
+
declare function useExchangeRate(args: Pausable<UseExchangeRateArgs> & Suspendable): PausableSuspenseResult<ExchangeAmount>;
|
|
266
296
|
/**
|
|
267
297
|
* Fetches exchange rates between tokens and fiat currencies with automatic polling.
|
|
268
298
|
*
|
|
@@ -280,7 +310,7 @@ declare function useExchangeRate(args: Pausable<UseExchangeRateArgs> & Suspendab
|
|
|
280
310
|
* <Component value={somewhere} fxRate={data} />
|
|
281
311
|
* ```
|
|
282
312
|
*/
|
|
283
|
-
declare function useExchangeRate(args: UseExchangeRateArgs): ReadResult<
|
|
313
|
+
declare function useExchangeRate(args: UseExchangeRateArgs): ReadResult<ExchangeAmount>;
|
|
284
314
|
/**
|
|
285
315
|
* Fetches exchange rates between tokens and fiat currencies with automatic polling.
|
|
286
316
|
*
|
|
@@ -299,7 +329,7 @@ declare function useExchangeRate(args: UseExchangeRateArgs): ReadResult<FiatAmou
|
|
|
299
329
|
* });
|
|
300
330
|
* ```
|
|
301
331
|
*/
|
|
302
|
-
declare function useExchangeRate(args: Pausable<UseExchangeRateArgs>): PausableReadResult<
|
|
332
|
+
declare function useExchangeRate(args: Pausable<UseExchangeRateArgs>): PausableReadResult<ExchangeAmount>;
|
|
303
333
|
type UseNetworkFeeRequestQuery = {
|
|
304
334
|
activity: ActivityItem;
|
|
305
335
|
} | {
|
|
@@ -374,4 +404,4 @@ type UseNetworkFee<T extends NativeAmount = NativeAmount> =
|
|
|
374
404
|
*/
|
|
375
405
|
((args: Pausable<UseNetworkFeeArgs, PausableUseNetworkFeeArgs>) => PausableReadResult<T>);
|
|
376
406
|
|
|
377
|
-
export { type Pausable as P, ReadResult as R, type Suspendable as S, type UseNetworkFee as U, type SuspenseResult as a, type PausableSuspenseResult as b, type PausableReadResult as c, type
|
|
407
|
+
export { type Pausable as P, ReadResult as R, type Suspendable as S, type UseNetworkFee as U, type SuspenseResult as a, type PausableSuspenseResult as b, type PausableReadResult as c, type UseChainArgs as d, useChainAction as e, type UseChainsArgs as f, useChains as g, useExchangeRateAction as h, type UseExchangeRateArgs as i, useExchangeRate as j, type UseNetworkFeeRequestQuery as k, type UseNetworkFeeArgs as l, useChain as u };
|
package/dist/privy.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var client=require('@aave/client'),viem
|
|
1
|
+
'use strict';var client=require('@aave/client'),viem=require('@aave/client/viem'),types=require('@aave/types'),reactAuth=require('@privy-io/react-auth'),viem$1=require('viem'),b=require('react'),core=require('@aave/core'),actions=require('@aave/client/actions');require('@aave/graphql'),require('urql');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var b__default=/*#__PURE__*/_interopDefault(b);var l={Idle:()=>({called:false,loading:false,data:void 0,error:void 0}),Loading:e=>({called:true,loading:true,data:e,error:void 0}),Success:e=>({called:true,loading:false,data:e,error:void 0}),Failed:e=>({called:true,loading:false,data:void 0,error:e})};function u(e,t){let[n,s]=b.useState(l.Idle()),r=b.useRef(false),a=b.useCallback(e,t);return [b.useCallback(h=>{types.invariant(!r.current,"Cannot execute a task while another is in progress."),r.current=true;let d;s(o=>(d=o,{called:true,loading:true,data:o.data,error:void 0}));try{let o=a(h);return o.match(c=>{r.current=!1,s(l.Success(c));},c=>{r.current=!1,s(l.Failed(c));}),o}catch(o){throw r.current=false,s(types.nonNullable(d)),o}},[a]),n]}var i=class e{constructor(t){this.wait=t;}static isInstanceOf(t){return t instanceof e}static tryFrom(t){return e.isInstanceOf(t)?types.okAsync(t):core.UnexpectedError.from(t).asResultAsync()}};var v=b__default.default.createContext(null);function T(){let e=b.useContext(v);return types.invariant(e,"Could not find Aave SDK context, ensure your code is wrapped in a <AaveProvider>"),e}function g(){let e=T();return u(t=>actions.chain(e,t,{batch:false,requestPolicy:"cache-first"}),[e])}function H(e){if(e&&typeof e=="object"){if("code"in e&&e.code===4001)return true;if("message"in e&&typeof e.message=="string"){let t=e.message.toLowerCase();return t.includes("user rejected")||t.includes("user denied")||t.includes("rejected the request")}}return false}function he(){let{wallets:e}=reactAuth.useWallets(),[t]=g();return u(n=>{let s=e.find(r=>r.address===n.from);return types.invariant(s,`Expected a connected wallet with address ${n.from} to be found.`),t({chainId:n.chainId}).map(r=>(types.invariant(r,`Chain ${n.chainId} is not supported`),viem.toViemChain(r))).andThen(r=>types.ResultAsync.fromPromise(s.switchChain(n.chainId),a=>client.UnexpectedError.from(a)).map(()=>s.getEthereumProvider()).map(a=>viem$1.createWalletClient({account:n.from,chain:r,transport:viem$1.custom(a)})).andThen(a=>viem.sendTransaction(a,n).map(p=>new i(()=>viem.waitForTransactionResult(a,n,p)))))},[e,t])}function xe(){let{signTypedData:e}=reactAuth.useSignTypedData();return u(t=>types.ResultAsync.fromPromise(e({domain:t.domain,types:t.types,primaryType:t.primaryType,message:t.message}),n=>H(n)?client.CancelError.from(n):client.SigningError.from(n)).map(({signature:n})=>types.signatureFrom(n)),[e])}exports.useSendTransaction=he;exports.useSignTypedData=xe;//# sourceMappingURL=privy.cjs.map
|
|
2
2
|
//# sourceMappingURL=privy.cjs.map
|
package/dist/privy.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/helpers/tasks.ts","../src/helpers/writes.ts","../src/context.tsx","../src/permits.ts","../src/privy.ts"],"names":["AsyncTaskState","data","error","useAsyncTask","handler","deps","state","setState","useState","loadingRef","useRef","handle","useCallback","input","invariant","result","value","PendingTransaction","_PendingTransaction","wait","AaveContext","React","useAaveClient","client","useContext","usePermitTypedDataAction","request","permitTypedData","useSendTransaction","wallets","useWallets","wallet","ResultAsync","UnexpectedError","provider","createWalletClient","supportedChains","custom","walletClient","sendTransaction","hash","waitForTransactionResult","useERC20Permit","signTypedData","useSignTypedData","response","SigningError","signature","signatureFrom","useSignSwapTypedDataWith","typedData","message"],"mappings":"qYA6DA,IAAMA,CAAAA,CAAiB,CACrB,IAAA,CAAM,KAAqD,CACzD,MAAA,CAAQ,KAAA,CACR,OAAA,CAAS,KAAA,CACT,IAAA,CAAM,MAAA,CACN,KAAA,CA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AO,CACxB,QAAA,CAAUF,CAAAA,CAAS,OAAA,CAAQ,QAAA,CAC3B,KAAA,CAAOG,mBAAAA,CAAcD,CAAS,CAChC,CAAA,CAAE,CACJ,CAAA,CAEF,CAACpB,CAAAA,CAAiBgB,CAAa,CACjC,CACF,CAuBO,SAASM,EAAAA,EAId,CACA,GAAM,CAAE,aAAA,CAAAN,CAAc,CAAA,CAAIC,0BAAAA,EAAiB,CAE3C,OAAOzC,CAAAA,CACJ+C,CAAAA,EAA2D,CAC1D,IAAMC,CAAAA,CAAU,IAAA,CAAK,KAAA,CAAMD,CAAAA,CAAU,OAAO,CAAA,CAE5C,OAAOlB,iBAAAA,CAAY,WAAA,CACjBW,CAAAA,CAAc,CACZ,KAAA,CAAOO,CAAAA,CAAU,KAAA,CACjB,WAAA,CAAaA,CAAAA,CAAU,WAAA,CACvB,MAAA,CAAQA,CAAAA,CAAU,MAAA,CAClB,OAAA,CAAAC,CACF,CAAC,CAAA,CACAjD,CAAAA,EAAU4C,mBAAAA,CAAa,IAAA,CAAK5C,CAAK,CACpC,CAAA,CAAE,GAAA,CAAI,CAAC,CAAE,SAAA,CAAA6C,CAAU,CAAA,IAAO,CACxB,QAAA,CAAUI,CAAAA,CAAQ,QAAA,CAClB,KAAA,CAAOH,mBAAAA,CAAcD,CAAS,CAChC,CAAA,CAAE,CACJ,CAAA,CACA,CAACJ,CAAa,CAChB,CACF","file":"privy.cjs","sourcesContent":["import { invariant, type ResultAsync } from '@aave/types';\nimport { type DependencyList, useCallback, useRef, useState } from 'react';\n\n/**\n * An async task is a function that can be executed multiple times and that can be in a pending state.\n *\n * @internal\n */\nexport type AsyncTask<TInput, TResult extends ResultAsync<unknown, unknown>> = (\n input: TInput,\n) => TResult;\n\n/**\n * The initial state of a async task.\n */\nexport type AsyncTaskIdle = {\n called: boolean;\n loading: false;\n data: undefined;\n error: undefined;\n};\n\n/**\n * The state of a async task during the loading.\n */\nexport type AsyncTaskLoading<TData> = {\n called: true;\n loading: true;\n data: TData | undefined;\n error: undefined;\n};\n\n/**\n * The state of a async task after a successful call.\n */\nexport type AsyncTaskSuccess<TData> = {\n called: true;\n loading: false;\n data: TData;\n error: undefined;\n};\n\n/**\n * The state of a async task after a failed call.\n */\nexport type AsyncTaskError<TError> = {\n called: true;\n loading: false;\n data: undefined;\n error: TError;\n};\n\n/**\n * The possible statuses of a async task.\n */\nexport type AsyncTaskState<TData, TError> =\n | AsyncTaskIdle\n | AsyncTaskLoading<TData>\n | AsyncTaskSuccess<TData>\n | AsyncTaskError<TError>;\n\nconst AsyncTaskState = {\n Idle: <TData, TError>(): AsyncTaskState<TData, TError> => ({\n called: false,\n loading: false,\n data: undefined,\n error: undefined,\n }),\n Loading: <TData, TError>(data?: TData): AsyncTaskState<TData, TError> => ({\n called: true,\n loading: true,\n data,\n error: undefined,\n }),\n Success: <TData, TError>(data: TData): AsyncTaskState<TData, TError> => ({\n called: true,\n loading: false,\n data,\n error: undefined,\n }),\n Failed: <TData, TError>(error: TError): AsyncTaskState<TData, TError> => ({\n called: true,\n loading: false,\n data: undefined,\n error,\n }),\n};\n\n/**\n * A async task React Hook is a lightweight wrapper for an asynchronous function.\n * It allows tracking of the task's execution status and provides access to the\n * last error that occurred during the task's execution, if any.\n *\n * ```ts\n * const [execute, { called, loading, data, error }]: UseAsyncTask<TData, TError, TInput> = useAnyAsyncTask();\n *\n * if (!called) {\n * // data === undefined\n * // error === undefined\n * return <p>Click the button to execute the task</p>;\n * }\n *\n * if (loading) {\n * // data === undefined on first call\n * // data === TData from previous successful call\n * // error === undefined\n * return <Loader />;\n * }\n *\n * if (error) {\n * // data === undefined\n * // error === TError\n * return <p>Something went wrong: {error.message}</p>;\n * }\n *\n * // called === true\n * // data === TData\n * // error === undefined\n * return <p>Task completed: {data}</p>;\n * ```\n */\nexport type UseAsyncTask<TInput, TValue, TError> = [\n AsyncTask<TInput, ResultAsync<TValue, TError>>,\n AsyncTaskState<TValue, TError>,\n];\n\n/**\n * @internal\n */\nexport function useAsyncTask<\n TInput,\n TValue,\n TError,\n TResult extends ResultAsync<TValue, TError>,\n>(\n handler: AsyncTask<TInput, TResult>,\n deps: DependencyList,\n): UseAsyncTask<TInput, TValue, TError> {\n const [state, setState] = useState(AsyncTaskState.Idle<TValue, TError>());\n const loadingRef = useRef(false);\n // biome-ignore lint/correctness/useExhaustiveDependencies: useAsyncTask is a low-level hook\n const handle = useCallback(handler, deps);\n\n const execute = useCallback(\n (input: TInput) => {\n invariant(\n !loadingRef.current,\n 'Cannot execute a task while another is in progress.',\n );\n\n loadingRef.current = true;\n setState(({ data }) => {\n return {\n called: true,\n loading: true,\n data,\n error: undefined,\n };\n });\n\n const result = handle(input);\n\n result.match(\n (value) => {\n loadingRef.current = false;\n setState(AsyncTaskState.Success(value));\n },\n (error) => {\n loadingRef.current = false;\n setState(AsyncTaskState.Failed(error));\n },\n );\n\n return result;\n },\n [handle],\n );\n\n return [execute, state];\n}\n","import type { TransactionResult } from '@aave/client';\nimport {\n CancelError,\n type SigningError,\n type TimeoutError,\n type TransactionError,\n type UnexpectedError,\n} from '@aave/core';\nimport type {\n Erc20ApprovalRequired,\n PreContractActionRequired,\n TransactionRequest,\n} from '@aave/graphql';\nimport type { ResultAsync } from '@aave/types';\nimport { invariant } from '@aave/types';\nimport type { UseAsyncTask } from './tasks';\n\n/**\n * The errors that could occur in the early stage of sending a transaction.\n */\nexport type SendTransactionError = CancelError | SigningError | UnexpectedError;\n\nexport type CancelOperation = (\n message: string,\n) => ResultAsync<never, CancelError>;\n\n/**\n * @internal\n */\nexport const cancel: CancelOperation = (message: string) =>\n CancelError.from(message).asResultAsync();\n\nexport type TransactionHandlerOptions = {\n cancel: CancelOperation;\n};\n\n/**\n * The errors that could occur in the late stages of a transaction.\n */\nexport type PendingTransactionError =\n | CancelError\n | TimeoutError\n | TransactionError\n | UnexpectedError;\n\nexport class PendingTransaction {\n constructor(\n /**\n * @internal Do NOT rely on this method. It's used internally by the SDK and may be subject to breaking changes.\n */\n public readonly wait: () => ResultAsync<\n TransactionResult,\n PendingTransactionError\n >,\n ) {}\n\n /**\n * @internal\n */\n static ensure<T>(value: T): PendingTransaction & T {\n invariant(\n value instanceof PendingTransaction,\n 'Expected PendingTransaction',\n );\n return value as PendingTransaction & T;\n }\n}\n\nexport type UseSendTransactionResult = UseAsyncTask<\n TransactionRequest,\n PendingTransaction,\n SendTransactionError\n>;\n\n/**\n * The handler for sending Aave transactions.\n */\nexport type TransactionHandler = (\n result:\n | TransactionRequest\n | Erc20ApprovalRequired\n | PreContractActionRequired,\n options: TransactionHandlerOptions,\n) => ResultAsync<PendingTransaction, SendTransactionError>;\n","import type { AaveClient } from '@aave/client';\nimport { invariant } from '@aave/types';\nimport React, { type ReactNode, useContext } from 'react';\nimport { Provider as UrqlProvider } from 'urql';\n\nconst AaveContext = React.createContext<AaveClient | null>(null);\n\n/**\n * @internal\n */\nexport type AaveContextProviderProps = {\n children: ReactNode;\n client: AaveClient;\n};\n\n/**\n * @internal\n */\nexport function AaveContextProvider({\n children,\n client,\n}: AaveContextProviderProps) {\n return (\n <AaveContext.Provider value={client}>\n <UrqlProvider value={client.urql}>{children}</UrqlProvider>\n </AaveContext.Provider>\n );\n}\n\n/**\n * @internal\n */\nexport function useAaveClient(): AaveClient {\n const client = useContext(AaveContext);\n\n invariant(\n client,\n 'Could not find Aave SDK context, ensure your code is wrapped in a <AaveProvider>',\n );\n\n return client;\n}\n","import type { UnexpectedError } from '@aave/client';\nimport { permitTypedData } from '@aave/client/actions';\nimport type { PermitRequest, PermitTypedDataResponse } from '@aave/graphql';\nimport { useAaveClient } from './context';\nimport { type UseAsyncTask, useAsyncTask } from './helpers';\n\n/**\n * @internal\n */\nexport function usePermitTypedDataAction(): UseAsyncTask<\n PermitRequest,\n PermitTypedDataResponse,\n UnexpectedError\n> {\n const client = useAaveClient();\n\n return useAsyncTask(\n (request: PermitRequest) => permitTypedData(client, request),\n [client],\n );\n}\n","import { SigningError, UnexpectedError } from '@aave/client';\nimport {\n sendTransaction,\n supportedChains,\n waitForTransactionResult,\n} from '@aave/client/viem';\nimport type {\n CancelSwapTypedData,\n ERC20PermitSignature,\n PermitRequest,\n SwapByIntentTypedData,\n TransactionRequest,\n} from '@aave/graphql';\nimport { invariant, ResultAsync, signatureFrom } from '@aave/types';\nimport { useSignTypedData, useWallets } from '@privy-io/react-auth';\nimport { createWalletClient, custom } from 'viem';\nimport {\n PendingTransaction,\n type UseAsyncTask,\n type UseSendTransactionResult,\n useAsyncTask,\n} from './helpers';\nimport { usePermitTypedDataAction } from './permits';\n\n/**\n * A hook that provides a way to send Aave transactions using a Privy wallet.\n *\n * Import the `useSendTransaction` hook from `@aave/react/privy` entry point.\n *\n * ```ts\n * const [sendTransaction, { loading, error, data }] = useSendTransaction();\n * ```\n */\nexport function useSendTransaction(): UseSendTransactionResult {\n const { wallets } = useWallets();\n\n return useAsyncTask(\n (request: TransactionRequest) => {\n const wallet = wallets.find((wallet) => wallet.address === request.from);\n\n invariant(\n wallet,\n `Expected a connected wallet with address ${request.from} to be found.`,\n );\n\n return ResultAsync.fromPromise(\n wallet.switchChain(request.chainId),\n (error) => UnexpectedError.from(error),\n )\n .map(() => wallet.getEthereumProvider())\n .map((provider) =>\n createWalletClient({\n account: request.from,\n chain: supportedChains[request.chainId],\n transport: custom(provider),\n }),\n )\n .andThen((walletClient) =>\n sendTransaction(walletClient, request).map(\n (hash) =>\n new PendingTransaction(() =>\n waitForTransactionResult(walletClient, request, hash),\n ),\n ),\n );\n },\n [wallets],\n );\n}\n\nexport type SignERC20PermitError = SigningError | UnexpectedError;\n\n/**\n * A hook that provides a way to sign ERC20 permits using a Privy wallet.\n *\n * ```ts\n * const { ready, authenticated, user } = usePrivy(); // privy hook\n * const [signERC20Permit, { loading, error, data }] = useERC20Permit();\n *\n * const run = async () => {\n * const result = await signERC20Permit({\n * supply: {\n * sender: evmAddress(user!.wallet!.address), // User's address\n * reserve: {\n * reserveId: reserve.id,\n * chainId: reserve.chain.chainId,\n * spoke: reserve.spoke.address,\n * },\n * amount: {\n * value: bigDecimal(42), // 42 USDC\n * },\n * },\n * });\n *\n * if (result.isErr()) {\n * console.error(result.error);\n * return;\n * }\n *\n * console.log('ERC20 Permit signature:', result.value);\n * };\n * ```\n */\nexport function useERC20Permit(): UseAsyncTask<\n PermitRequest,\n ERC20PermitSignature,\n SignERC20PermitError\n> {\n const [permitTypedData] = usePermitTypedDataAction();\n const { signTypedData } = useSignTypedData();\n\n return useAsyncTask(\n (request: PermitRequest) => {\n return permitTypedData(request).andThen((response) =>\n ResultAsync.fromPromise(\n signTypedData({\n types: response.types,\n primaryType: response.primaryType,\n domain: response.domain,\n message: response.message,\n }),\n (error) => SigningError.from(error),\n ).map(({ signature }) => ({\n deadline: response.message.deadline,\n value: signatureFrom(signature),\n })),\n );\n },\n [permitTypedData, signTypedData],\n );\n}\n\nexport type SignSwapTypedDataError = SigningError | UnexpectedError;\n\n/**\n * @internal\n * A hook that provides a way to sign swap typed data using a Privy wallet.\n *\n * ```ts\n * const [signSwapTypedData, { loading, error, data }] = useSignSwapTypedDataWith();\n *\n * const run = async () => {\n * const result = await signSwapTypedData(swapTypedData);\n *\n * if (result.isErr()) {\n * console.error(result.error);\n * return;\n * }\n *\n * console.log('Swap typed data signed:', result.value);\n * };\n * ```\n */\nexport function useSignSwapTypedDataWith(): UseAsyncTask<\n SwapByIntentTypedData | CancelSwapTypedData,\n ERC20PermitSignature,\n SignSwapTypedDataError\n> {\n const { signTypedData } = useSignTypedData();\n\n return useAsyncTask(\n (typedData: SwapByIntentTypedData | CancelSwapTypedData) => {\n const message = JSON.parse(typedData.message);\n\n return ResultAsync.fromPromise(\n signTypedData({\n types: typedData.types,\n primaryType: typedData.primaryType,\n domain: typedData.domain,\n message,\n }),\n (error) => SigningError.from(error),\n ).map(({ signature }) => ({\n deadline: message.deadline,\n value: signatureFrom(signature),\n }));\n },\n [signTypedData],\n );\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/helpers/tasks.ts","../src/helpers/writes.ts","../src/context.tsx","../src/misc.ts","../src/privy.ts"],"names":["AsyncTaskState","data","error","useAsyncTask","handler","deps","state","setState","useState","loadingRef","useRef","handle","useCallback","input","invariant","previousState","result","value","nonNullable","PendingTransaction","_PendingTransaction","wait","okAsync","UnexpectedError","AaveContext","React","useAaveClient","client","useContext","useChainAction","request","fetchChain","isUserRejection","err","msg","useSendTransaction","wallets","useWallets","wallet","chain","toViemChain","ResultAsync","provider","createWalletClient","custom","walletClient","sendTransaction","hash","waitForTransactionResult","useSignTypedData","privySignTypedData","usePrivySignTypedData","typedData","CancelError","SigningError","signature","signatureFrom"],"mappings":"+ZA6DA,IAAMA,CAAAA,CAAiB,CACrB,IAAA,CAAM,KAAqD,CACzD,MAAA,CAAQ,KAAA,CACR,QAAS,KAAA,CACT,IAAA,CAAM,MAAA,CACN,KAAA,CAAO,MACT,CAAA,CAAA,CACA,OAAA,CAAyBC,CAAAA,GAAiD,CACxE,MAAA,CAAQ,IAAA,CACR,OAAA,CAAS,IAAA,CACT,IAAA,CAAAA,CAAAA,CACA,KAAA,CAAO,MACT,GACA,OAAA,CAAyBA,CAAAA,GAAgD,CACvE,MAAA,CAAQ,IAAA,CACR,OAAA,CAAS,KAAA,CACT,IAAA,CAAAA,EACA,KAAA,CAAO,MACT,CAAA,CAAA,CACA,MAAA,CAAwBC,CAAAA,GAAkD,CACxE,MAAA,CAAQ,IAAA,CACR,QAAS,KAAA,CACT,IAAA,CAAM,MAAA,CACN,KAAA,CAAAA,CACF,CAAA,CACF,CAAA,CA2CO,SAASC,EAMdC,CAAAA,CACAC,CAAAA,CACsC,CACtC,GAAM,CAACC,CAAAA,CAAOC,CAAQ,CAAA,CAAIC,WAASR,CAAAA,CAAe,IAAA,EAAsB,CAAA,CAClES,CAAAA,CAAaC,QAAAA,CAAO,KAAK,CAAA,CAEzBC,EAASC,aAAAA,CAAYR,CAAAA,CAASC,CAAI,CAAA,CA8CxC,OAAO,CA5CSO,aAAAA,CACbC,CAAAA,EAAkB,CACj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,CAAU,WAAA,CACvB,OAAA,CAASA,CAAAA,CAAU,OACrB,CAAC,CAAA,CACAlD,CAAAA,EACK8B,CAAAA,CAAgB9B,CAAK,CAAA,CAChBmD,kBAAAA,CAAY,IAAA,CAAKnD,CAAK,EAExBoD,mBAAAA,CAAa,IAAA,CAAKpD,CAAK,CAElC,CAAA,CAAE,GAAA,CAAI,CAAC,CAAE,UAAAqD,CAAU,CAAA,GAAMC,mBAAAA,CAAcD,CAAS,CAAC,CAAA,CAEnD,CAACL,CAAkB,CACrB,CACF","file":"privy.cjs","sourcesContent":["import { invariant, nonNullable, type ResultAsync } from '@aave/types';\nimport { type DependencyList, useCallback, useRef, useState } from 'react';\n\n/**\n * An async task is a function that can be executed multiple times and that can be in a pending state.\n *\n * @internal\n */\nexport type AsyncTask<TInput, TResult extends ResultAsync<unknown, unknown>> = (\n input: TInput,\n) => TResult;\n\n/**\n * The initial state of a async task.\n */\nexport type AsyncTaskIdle = {\n called: boolean;\n loading: false;\n data: undefined;\n error: undefined;\n};\n\n/**\n * The state of a async task during the loading.\n */\nexport type AsyncTaskLoading<TData> = {\n called: true;\n loading: true;\n data: TData | undefined;\n error: undefined;\n};\n\n/**\n * The state of a async task after a successful call.\n */\nexport type AsyncTaskSuccess<TData> = {\n called: true;\n loading: false;\n data: TData;\n error: undefined;\n};\n\n/**\n * The state of a async task after a failed call.\n */\nexport type AsyncTaskError<TError> = {\n called: true;\n loading: false;\n data: undefined;\n error: TError;\n};\n\n/**\n * The possible statuses of a async task.\n */\nexport type AsyncTaskState<TData, TError> =\n | AsyncTaskIdle\n | AsyncTaskLoading<TData>\n | AsyncTaskSuccess<TData>\n | AsyncTaskError<TError>;\n\nconst AsyncTaskState = {\n Idle: <TData, TError>(): AsyncTaskState<TData, TError> => ({\n called: false,\n loading: false,\n data: undefined,\n error: undefined,\n }),\n Loading: <TData, TError>(data?: TData): AsyncTaskState<TData, TError> => ({\n called: true,\n loading: true,\n data,\n error: undefined,\n }),\n Success: <TData, TError>(data: TData): AsyncTaskState<TData, TError> => ({\n called: true,\n loading: false,\n data,\n error: undefined,\n }),\n Failed: <TData, TError>(error: TError): AsyncTaskState<TData, TError> => ({\n called: true,\n loading: false,\n data: undefined,\n error,\n }),\n};\n\n/**\n * A async task React Hook is a lightweight wrapper for an asynchronous function.\n * It allows tracking of the task's execution status and provides access to the\n * last error that occurred during the task's execution, if any.\n *\n * ```ts\n * const [execute, { called, loading, data, error }]: UseAsyncTask<TData, TError, TInput> = useAnyAsyncTask();\n *\n * if (!called) {\n * // data === undefined\n * // error === undefined\n * return <p>Click the button to execute the task</p>;\n * }\n *\n * if (loading) {\n * // data === undefined on first call\n * // data === TData from previous successful call\n * // error === undefined\n * return <Loader />;\n * }\n *\n * if (error) {\n * // data === undefined\n * // error === TError\n * return <p>Something went wrong: {error.message}</p>;\n * }\n *\n * // called === true\n * // data === TData\n * // error === undefined\n * return <p>Task completed: {data}</p>;\n * ```\n */\nexport type UseAsyncTask<TInput, TValue, TError> = [\n AsyncTask<TInput, ResultAsync<TValue, TError>>,\n AsyncTaskState<TValue, TError>,\n];\n\n/**\n * @internal\n */\nexport function useAsyncTask<\n TInput,\n TValue,\n TError,\n TResult extends ResultAsync<TValue, TError>,\n>(\n handler: AsyncTask<TInput, TResult>,\n deps: DependencyList,\n): UseAsyncTask<TInput, TValue, TError> {\n const [state, setState] = useState(AsyncTaskState.Idle<TValue, TError>());\n const loadingRef = useRef(false);\n // biome-ignore lint/correctness/useExhaustiveDependencies: useAsyncTask is a low-level hook\n const handle = useCallback(handler, deps);\n\n const execute = useCallback(\n (input: TInput) => {\n invariant(\n !loadingRef.current,\n 'Cannot execute a task while another is in progress.',\n );\n\n loadingRef.current = true;\n\n let previousState: AsyncTaskState<TValue, TError> | undefined;\n setState((state) => {\n previousState = state;\n return {\n called: true,\n loading: true,\n data: state.data,\n error: undefined,\n };\n });\n\n try {\n const result = handle(input);\n\n result.match(\n (value) => {\n loadingRef.current = false;\n setState(AsyncTaskState.Success(value));\n },\n (error) => {\n loadingRef.current = false;\n setState(AsyncTaskState.Failed(error));\n },\n );\n\n return result;\n } catch (error) {\n loadingRef.current = false;\n setState(nonNullable(previousState));\n throw error;\n }\n },\n [handle],\n );\n\n return [execute, state];\n}\n","import type { TransactionResult } from '@aave/client';\nimport {\n CancelError,\n type SigningError,\n type TimeoutError,\n type TransactionError,\n UnexpectedError,\n} from '@aave/core';\nimport type { TransactionRequest } from '@aave/graphql';\nimport type { ResultAsync, Signature } from '@aave/types';\nimport { isSignature, okAsync } from '@aave/types';\nimport type { UseAsyncTask } from './tasks';\n\n/**\n * The errors that could occur in the early stage of sending a transaction.\n */\nexport type SendTransactionError = CancelError | SigningError | UnexpectedError;\n\nexport type CancelOperation = (\n message: string,\n) => ResultAsync<never, CancelError>;\n\n/**\n * @internal\n */\nexport const cancel: CancelOperation = (message: string) =>\n CancelError.from(message).asResultAsync();\n\nexport type TransactionHandlerOptions = {\n cancel: CancelOperation;\n};\n\n/**\n * The errors that could occur in the late stages of a transaction.\n */\nexport type PendingTransactionError =\n | CancelError\n | TimeoutError\n | TransactionError\n | UnexpectedError;\n\nexport class PendingTransaction {\n constructor(\n /**\n * @internal Do NOT rely on this method. It's used internally by the SDK and may be subject to breaking changes.\n */\n public readonly wait: () => ResultAsync<\n TransactionResult,\n PendingTransactionError\n >,\n ) {}\n\n /**\n * @internal\n */\n static isInstanceOf(value: unknown): value is PendingTransaction {\n return value instanceof PendingTransaction;\n }\n\n /**\n * Narrows a value to PendingTransaction.\n * Only accepts types that include PendingTransaction in the union.\n *\n * @internal\n */\n static tryFrom<T>(\n value: PendingTransaction extends T ? T : never,\n ): ResultAsync<PendingTransaction, UnexpectedError> {\n if (PendingTransaction.isInstanceOf(value)) {\n return okAsync(value);\n }\n return UnexpectedError.from(value).asResultAsync();\n }\n}\n\nexport type UseSendTransactionResult = UseAsyncTask<\n TransactionRequest,\n PendingTransaction,\n SendTransactionError\n>;\n\n/**\n * The Aave execution plan handler\n */\nexport type ExecutionPlanHandler<\n T,\n R extends Signature | PendingTransaction,\n> = (\n plan: T,\n options: TransactionHandlerOptions,\n) => ResultAsync<R, SendTransactionError>;\n\n/**\n * Tries to create a Signature from an unknown value.\n *\n * @internal\n */\nexport function trySignatureFrom(\n value: unknown,\n): ResultAsync<Signature, UnexpectedError> {\n if (isSignature(value)) {\n return okAsync(value);\n }\n return UnexpectedError.from(\n `Expected Signature, but got ${String(value)}`,\n ).asResultAsync();\n}\n","import type { AaveClient } from '@aave/client';\nimport { invariant } from '@aave/types';\nimport React, { type ReactNode, useContext } from 'react';\nimport { Provider as UrqlProvider } from 'urql';\n\nconst AaveContext = React.createContext<AaveClient | null>(null);\n\n/**\n * @internal\n */\nexport type AaveContextProviderProps = {\n children: ReactNode;\n client: AaveClient;\n};\n\n/**\n * @internal\n */\nexport function AaveContextProvider({\n children,\n client,\n}: AaveContextProviderProps) {\n return (\n <AaveContext.Provider value={client}>\n <UrqlProvider value={client.urql}>{children}</UrqlProvider>\n </AaveContext.Provider>\n );\n}\n\n/**\n * @internal\n */\nexport function useAaveClient(): AaveClient {\n const client = useContext(AaveContext);\n\n invariant(\n client,\n 'Could not find Aave SDK context, ensure your code is wrapped in a <AaveProvider>',\n );\n\n return client;\n}\n","import type { CurrencyQueryOptions } from '@aave/client';\nimport { exchangeRate, chain as fetchChain } from '@aave/client/actions';\nimport type { UnexpectedError } from '@aave/core';\nimport type { Chain, ExchangeAmount, ExchangeRateRequest } from '@aave/graphql';\nimport {\n type ActivityItem,\n ChainQuery,\n type ChainRequest,\n ChainsFilter,\n ChainsQuery,\n type ChainsRequest,\n ExchangeRateQuery,\n type NativeAmount,\n type PreviewAction,\n} from '@aave/graphql';\nimport type { NullishDeep, Prettify } from '@aave/types';\nimport { useAaveClient } from './context';\nimport {\n type Pausable,\n type PausableReadResult,\n type PausableSuspenseResult,\n type ReadResult,\n type Suspendable,\n type SuspendableResult,\n type SuspenseResult,\n useSuspendableQuery,\n} from './helpers';\nimport { type UseAsyncTask, useAsyncTask } from './helpers/tasks';\n\nexport type UseChainArgs = ChainRequest;\n\n/**\n * Fetch a specific chain by chain ID.\n *\n * This signature supports React Suspense:\n *\n * ```tsx\n * const { data } = useChain({\n * chainId: chainId(1),\n * suspense: true,\n * });\n * // data will be Chain | null\n * ```\n */\nexport function useChain(\n args: UseChainArgs & Suspendable,\n): SuspenseResult<Chain | null>;\n/**\n * Fetch a specific chain by chain ID.\n *\n * Pausable suspense mode.\n *\n * ```tsx\n * const { data } = useChain({\n * chainId: chainId(1),\n * suspense: true,\n * pause: true,\n * });\n * ```\n */\nexport function useChain(\n args: Pausable<UseChainArgs> & Suspendable,\n): PausableSuspenseResult<Chain | null>;\n/**\n * Fetch a specific chain by chain ID.\n *\n * ```tsx\n * const { data, error, loading } = useChain({\n * chainId: chainId(1),\n * });\n * // data will be Chain | null\n * ```\n */\nexport function useChain(args: UseChainArgs): ReadResult<Chain | null>;\n/**\n * Fetch a specific chain by chain ID.\n *\n * Pausable loading state mode.\n *\n * ```tsx\n * const { data, error, loading, paused } = useChain({\n * chainId: chainId(1),\n * pause: true,\n * });\n * ```\n */\nexport function useChain(\n args: Pausable<UseChainArgs>,\n): PausableReadResult<Chain | null>;\n\nexport function useChain({\n suspense = false,\n pause = false,\n ...request\n}: NullishDeep<UseChainArgs> & {\n suspense?: boolean;\n pause?: boolean;\n}): SuspendableResult<Chain | null, UnexpectedError> {\n return useSuspendableQuery({\n document: ChainQuery,\n variables: {\n request,\n },\n suspense,\n pause,\n });\n}\n\n/**\n * Low-level hook to execute a {@link chain} action directly.\n *\n * @experimental This hook is experimental and may be subject to breaking changes.\n * @remarks\n * This hook **does not** actively watch for updated data on the chain.\n * Use this hook to retrieve data on demand as part of a larger workflow\n * (e.g., in an event handler in order to move to the next step).\n *\n * ```ts\n * const [execute, { called, data, error, loading }] = useChainAction();\n *\n * // …\n *\n * const result = await execute({\n * chainId: chainId(1),\n * });\n *\n * if (result.isOk()) {\n * console.log(result.value); // Chain | null\n * } else {\n * console.error(result.error);\n * }\n * ```\n */\nexport function useChainAction(): UseAsyncTask<\n ChainRequest,\n Chain | null,\n UnexpectedError\n> {\n const client = useAaveClient();\n\n return useAsyncTask(\n (request: ChainRequest) =>\n fetchChain(client, request, {\n batch: false,\n requestPolicy: 'cache-first',\n }),\n [client],\n );\n}\n\nexport type UseChainsArgs = ChainsRequest;\n/**\n * Fetches the list of supported chains.\n *\n * This signature supports React Suspense:\n *\n * ```tsx\n * const { data } = useChains({\n * query: { filter: ChainsFilter.ALL },\n * suspense: true,\n * });\n * ```\n */\nexport function useChains(\n args: UseChainsArgs & Suspendable,\n): SuspenseResult<Chain[]>;\n/**\n * Fetches the list of supported chains.\n *\n * Pausable suspense mode.\n *\n * ```tsx\n * const { data } = useChains({\n * query: { filter: ChainsFilter.ALL },\n * suspense: true,\n * pause: true,\n * });\n * ```\n */\nexport function useChains(\n args: Pausable<UseChainsArgs> & Suspendable,\n): PausableSuspenseResult<Chain[]>;\n/**\n * Fetches the list of supported chains.\n *\n * ```tsx\n * const { data, error, loading } = useChains({\n * query: { filter: ChainsFilter.ALL },\n * });\n * ```\n */\nexport function useChains(args?: UseChainsArgs): ReadResult<Chain[]>;\n/**\n * Fetches the list of supported chains.\n *\n * Pausable loading state mode.\n *\n * ```tsx\n * const { data, error, loading, paused } = useChains({\n * query: { filter: ChainsFilter.ALL },\n * pause: true,\n * });\n * ```\n */\nexport function useChains(\n args?: Pausable<UseChainsArgs>,\n): PausableReadResult<Chain[]>;\n\nexport function useChains(\n {\n suspense = false,\n pause = false,\n ...request\n }: NullishDeep<UseChainsArgs> & {\n suspense?: boolean;\n pause?: boolean;\n } = { query: { filter: ChainsFilter.ALL } },\n): SuspendableResult<Chain[], UnexpectedError> {\n return useSuspendableQuery({\n document: ChainsQuery,\n variables: { request },\n suspense,\n pause,\n });\n}\n\n/**\n * Fetches exchange rates between tokens and fiat currencies.\n *\n * ```tsx\n * const [getExchangeRate, gettingRate] = useExchangeRateAction();\n *\n * const loading = gettingRate.loading;\n * const error = gettingRate.error;\n *\n * // …\n *\n * const result = await getExchangeRate({\n * from: { erc20: { chainId: chainId(1), address: evmAddress('0xA0b86a33E6...') } },\n * to: Currency.Usd,\n * });\n *\n * if (result.isErr()) {\n * console.error(result.error);\n * return;\n * }\n *\n * console.log('Exchange rate:', result.value);\n * ```\n */\nexport function useExchangeRateAction(): UseAsyncTask<\n ExchangeRateRequest,\n ExchangeAmount,\n UnexpectedError\n> {\n const client = useAaveClient();\n\n return useAsyncTask(\n (request: ExchangeRateRequest) =>\n exchangeRate(client, request, { requestPolicy: 'network-only' }),\n [client],\n );\n}\n\nexport type UseExchangeRateArgs = ExchangeRateRequest;\n\n/**\n * Fetches exchange rates between tokens and fiat currencies with automatic polling.\n *\n * This signature supports React Suspense:\n *\n * ```tsx\n * const { data } = useExchangeRate({\n * from: {\n * erc20: {\n * chainId: chainId(1),\n * address: evmAddress('0xA0b86a33E6...')\n * }\n * },\n * to: Currency.Usd,\n * suspense: true,\n * });\n * ```\n */\nexport function useExchangeRate(\n args: UseExchangeRateArgs & Suspendable,\n): SuspenseResult<ExchangeAmount>;\n/**\n * Fetches exchange rates between tokens and fiat currencies with automatic polling.\n *\n * Pausable suspense mode.\n *\n * ```tsx\n * const { data } = useExchangeRate({\n * from: {\n * erc20: {\n * chainId: chainId(1),\n * address: evmAddress('0xA0b86a33E6...')\n * }\n * },\n * to: Currency.Usd,\n * suspense: true,\n * pause: true,\n * });\n * ```\n */\nexport function useExchangeRate(\n args: Pausable<UseExchangeRateArgs> & Suspendable,\n): PausableSuspenseResult<ExchangeAmount>;\n/**\n * Fetches exchange rates between tokens and fiat currencies with automatic polling.\n *\n * ```tsx\n * const { data, error, loading } = useExchangeRate({\n * from: {\n * erc20: {\n * chainId: chainId(1),\n * address: evmAddress('0xA0b86a33E6...')\n * }\n * },\n * to: Currency.Usd,\n * });\n *\n * <Component value={somewhere} fxRate={data} />\n * ```\n */\nexport function useExchangeRate(\n args: UseExchangeRateArgs,\n): ReadResult<ExchangeAmount>;\n/**\n * Fetches exchange rates between tokens and fiat currencies with automatic polling.\n *\n * Pausable loading state mode.\n *\n * ```tsx\n * const { data, error, loading, paused } = useExchangeRate({\n * from: {\n * erc20: {\n * chainId: chainId(1),\n * address: evmAddress('0xA0b86a33E6...')\n * }\n * },\n * to: Currency.Usd,\n * pause: true,\n * });\n * ```\n */\nexport function useExchangeRate(\n args: Pausable<UseExchangeRateArgs>,\n): PausableReadResult<ExchangeAmount>;\n\nexport function useExchangeRate({\n suspense = false,\n pause = false,\n ...request\n}: NullishDeep<UseExchangeRateArgs> & {\n suspense?: boolean;\n pause?: boolean;\n}): SuspendableResult<ExchangeAmount, UnexpectedError> {\n const client = useAaveClient();\n\n return useSuspendableQuery({\n document: ExchangeRateQuery,\n variables: { request },\n suspense,\n pause,\n pollInterval: request.at\n ? 0\n : client.context.environment.exchangeRateInterval,\n });\n}\n\nexport type UseNetworkFeeRequestQuery =\n | {\n activity: ActivityItem;\n }\n | {\n estimate: PreviewAction;\n };\n\nexport type UseNetworkFeeArgs = Prettify<\n {\n query: UseNetworkFeeRequestQuery;\n } & CurrencyQueryOptions\n>;\n\ntype PausableUseNetworkFeeArgs = Partial<\n {\n query: Partial<UseNetworkFeeRequestQuery>;\n } & CurrencyQueryOptions\n>;\n\n/**\n * Fetch the network fee for an ActivityItem.\n *\n * @experimental This hook is experimental and may be subject to breaking changes.\n */\nexport type UseNetworkFee<T extends NativeAmount = NativeAmount> =\n /**\n * Fetches the network fee for a past ActivityItem.\n *\n * This signature supports React Suspense:\n *\n * ```tsx\n * const { data } = useNetworkFee({\n * query: { activity },\n * suspense: true,\n * });\n *\n * data: NativeAmount\n * ```\n */\n ((args: UseNetworkFeeArgs & Suspendable) => SuspenseResult<T>) &\n /**\n * Fetches the network fee for a past ActivityItem.\n *\n * Pausable suspense mode.\n *\n * ```tsx\n * const { data, paused } = useNetworkFee({\n * query: { activity },\n * suspense: true,\n * pause: true,\n * });\n *\n * data: NativeAmount | undefined\n * ```\n */\n ((\n args: Pausable<UseNetworkFeeArgs, PausableUseNetworkFeeArgs> &\n Suspendable,\n ) => PausableSuspenseResult<T>) &\n /**\n * Fetches the network fee for a past ActivityItem.\n *\n * ```tsx\n * const { data, error, loading } = useNetworkFee({\n * query: { activity },\n * });\n * ```\n */\n ((args: UseNetworkFeeArgs) => ReadResult<T>) &\n /**\n * Fetches the network fee for a past ActivityItem.\n *\n * Pausable loading state mode.\n *\n * ```tsx\n * const { data, error, loading, paused } = useNetworkFee({\n * query: { activity },\n * pause: true,\n * });\n *\n * data: NativeAmount | undefined\n * ```\n */\n ((\n args: Pausable<UseNetworkFeeArgs, PausableUseNetworkFeeArgs>,\n ) => PausableReadResult<T>);\n","import {\n CancelError,\n SigningError,\n type SignTypedDataError,\n type TypedData,\n UnexpectedError,\n} from '@aave/client';\nimport {\n sendTransaction,\n toViemChain,\n waitForTransactionResult,\n} from '@aave/client/viem';\nimport type { TransactionRequest } from '@aave/graphql';\nimport {\n invariant,\n ResultAsync,\n type Signature,\n signatureFrom,\n} from '@aave/types';\nimport {\n type MessageTypes,\n useSignTypedData as usePrivySignTypedData,\n useWallets,\n} from '@privy-io/react-auth';\nimport { createWalletClient, custom } from 'viem';\nimport {\n PendingTransaction,\n type UseAsyncTask,\n type UseSendTransactionResult,\n useAsyncTask,\n} from './helpers';\nimport { useChainAction } from './misc';\n\nfunction isUserRejection(err: unknown): boolean {\n if (err && typeof err === 'object') {\n if ('code' in err && err.code === 4001) return true;\n if ('message' in err && typeof err.message === 'string') {\n const msg = err.message.toLowerCase();\n return (\n msg.includes('user rejected') ||\n msg.includes('user denied') ||\n msg.includes('rejected the request')\n );\n }\n }\n return false;\n}\n\n/**\n * A hook that provides a way to send Aave transactions using a Privy wallet.\n *\n * Import the `useSendTransaction` hook from `@aave/react/privy` entry point.\n *\n * ```ts\n * const [sendTransaction, { loading, error, data }] = useSendTransaction();\n * ```\n */\nexport function useSendTransaction(): UseSendTransactionResult {\n const { wallets } = useWallets();\n const [fetchChain] = useChainAction();\n\n return useAsyncTask(\n (request: TransactionRequest) => {\n const wallet = wallets.find((wallet) => wallet.address === request.from);\n\n invariant(\n wallet,\n `Expected a connected wallet with address ${request.from} to be found.`,\n );\n\n return fetchChain({ chainId: request.chainId })\n .map((chain) => {\n invariant(chain, `Chain ${request.chainId} is not supported`);\n return toViemChain(chain);\n })\n .andThen((chain) =>\n ResultAsync.fromPromise(\n wallet.switchChain(request.chainId),\n (error) => UnexpectedError.from(error),\n )\n .map(() => wallet.getEthereumProvider())\n .map((provider) =>\n createWalletClient({\n account: request.from,\n chain,\n transport: custom(provider),\n }),\n )\n .andThen((walletClient) =>\n sendTransaction(walletClient, request).map(\n (hash) =>\n new PendingTransaction(() =>\n waitForTransactionResult(walletClient, request, hash),\n ),\n ),\n ),\n );\n },\n [wallets, fetchChain],\n );\n}\n\n/**\n * A hook that provides a way to sign EIP-712 typed data (ERC-20 permits, swap intents, etc.)\n * using a Privy wallet.\n *\n * ```ts\n * const [signTypedData, { loading, error, data }] = useSignTypedData();\n * ```\n */\nexport function useSignTypedData(): UseAsyncTask<\n TypedData,\n Signature,\n SignTypedDataError\n> {\n const { signTypedData: privySignTypedData } = usePrivySignTypedData();\n\n return useAsyncTask(\n (typedData: TypedData) => {\n return ResultAsync.fromPromise(\n privySignTypedData({\n domain: typedData.domain,\n types: typedData.types as MessageTypes,\n primaryType: typedData.primaryType,\n message: typedData.message,\n }),\n (error) => {\n if (isUserRejection(error)) {\n return CancelError.from(error);\n }\n return SigningError.from(error);\n },\n ).map(({ signature }) => signatureFrom(signature));\n },\n [privySignTypedData],\n );\n}\n"]}
|
package/dist/privy.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { U as UseSendTransactionResult, a as UseAsyncTask } from './writes-
|
|
1
|
+
import { TypedData, SignTypedDataError } from '@aave/client';
|
|
2
|
+
import { Signature } from '@aave/types';
|
|
3
|
+
import { U as UseSendTransactionResult, a as UseAsyncTask } from './writes-CcVGQGt5.cjs';
|
|
4
4
|
import '@aave/core';
|
|
5
|
-
import '@aave/
|
|
5
|
+
import '@aave/graphql';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* A hook that provides a way to send Aave transactions using a Privy wallet.
|
|
@@ -14,59 +14,14 @@ import '@aave/types';
|
|
|
14
14
|
* ```
|
|
15
15
|
*/
|
|
16
16
|
declare function useSendTransaction(): UseSendTransactionResult;
|
|
17
|
-
type SignERC20PermitError = SigningError | UnexpectedError;
|
|
18
17
|
/**
|
|
19
|
-
* A hook that provides a way to sign
|
|
18
|
+
* A hook that provides a way to sign EIP-712 typed data (ERC-20 permits, swap intents, etc.)
|
|
19
|
+
* using a Privy wallet.
|
|
20
20
|
*
|
|
21
21
|
* ```ts
|
|
22
|
-
* const {
|
|
23
|
-
* const [signERC20Permit, { loading, error, data }] = useERC20Permit();
|
|
24
|
-
*
|
|
25
|
-
* const run = async () => {
|
|
26
|
-
* const result = await signERC20Permit({
|
|
27
|
-
* supply: {
|
|
28
|
-
* sender: evmAddress(user!.wallet!.address), // User's address
|
|
29
|
-
* reserve: {
|
|
30
|
-
* reserveId: reserve.id,
|
|
31
|
-
* chainId: reserve.chain.chainId,
|
|
32
|
-
* spoke: reserve.spoke.address,
|
|
33
|
-
* },
|
|
34
|
-
* amount: {
|
|
35
|
-
* value: bigDecimal(42), // 42 USDC
|
|
36
|
-
* },
|
|
37
|
-
* },
|
|
38
|
-
* });
|
|
39
|
-
*
|
|
40
|
-
* if (result.isErr()) {
|
|
41
|
-
* console.error(result.error);
|
|
42
|
-
* return;
|
|
43
|
-
* }
|
|
44
|
-
*
|
|
45
|
-
* console.log('ERC20 Permit signature:', result.value);
|
|
46
|
-
* };
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
declare function useERC20Permit(): UseAsyncTask<PermitRequest, ERC20PermitSignature, SignERC20PermitError>;
|
|
50
|
-
type SignSwapTypedDataError = SigningError | UnexpectedError;
|
|
51
|
-
/**
|
|
52
|
-
* @internal
|
|
53
|
-
* A hook that provides a way to sign swap typed data using a Privy wallet.
|
|
54
|
-
*
|
|
55
|
-
* ```ts
|
|
56
|
-
* const [signSwapTypedData, { loading, error, data }] = useSignSwapTypedDataWith();
|
|
57
|
-
*
|
|
58
|
-
* const run = async () => {
|
|
59
|
-
* const result = await signSwapTypedData(swapTypedData);
|
|
60
|
-
*
|
|
61
|
-
* if (result.isErr()) {
|
|
62
|
-
* console.error(result.error);
|
|
63
|
-
* return;
|
|
64
|
-
* }
|
|
65
|
-
*
|
|
66
|
-
* console.log('Swap typed data signed:', result.value);
|
|
67
|
-
* };
|
|
22
|
+
* const [signTypedData, { loading, error, data }] = useSignTypedData();
|
|
68
23
|
* ```
|
|
69
24
|
*/
|
|
70
|
-
declare function
|
|
25
|
+
declare function useSignTypedData(): UseAsyncTask<TypedData, Signature, SignTypedDataError>;
|
|
71
26
|
|
|
72
|
-
export {
|
|
27
|
+
export { useSendTransaction, useSignTypedData };
|