Skip to content

Commit f6e57bf

Browse files
committed
feat: changes UseAsynTask to return tuple
1 parent b7c8c60 commit f6e57bf

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

packages/client/src/viem.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ export function sendTransactionAndWait(
3838
walletClient: WalletClient,
3939
request: TransactionRequest,
4040
): ResultAsync<TxHash, SigningError> {
41+
// TODO: verify it's on the correct chain, ask to switch if possible
42+
// TODO: verify if wallet account is correct, switch if possible
43+
4144
return ResultAsync.fromPromise(
4245
sendTransaction(walletClient, request),
4346
(err) => SigningError.from(err),

packages/react/src/helpers/tasks.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,10 @@ const AsyncTaskState = {
119119
* return <p>Task completed: {data}</p>;
120120
* ```
121121
*/
122-
export type UseAsyncTask<TInput, TValue, TError> = AsyncTaskState<
123-
TValue,
124-
TError
125-
> & {
126-
execute: AsyncTask<TInput, ResultAsync<TValue, TError>>;
127-
};
122+
export type UseAsyncTask<TInput, TValue, TError> = [
123+
AsyncTask<TInput, ResultAsync<TValue, TError>>,
124+
AsyncTaskState<TValue, TError>,
125+
];
128126

129127
/**
130128
* @internal
@@ -165,8 +163,5 @@ export function useAsyncTask<
165163
[handler, state],
166164
);
167165

168-
return {
169-
...state,
170-
execute,
171-
};
166+
return [execute, state];
172167
}

packages/react/src/transactions.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import type { UnexpectedError } from '@aave/client';
2+
import type { ExecutionPlan, SupplyRequest } from '@aave/graphql';
3+
import { supply } from '../../client/src/actions';
4+
import { useAaveClient } from './context';
5+
import { type UseAsyncTask, useAsyncTask } from './helpers';
6+
7+
/**
8+
* A hook that provides a way to supply assets to an Aave market.
9+
*
10+
* ```ts
11+
* const [supply, { loading, error, data }] = useSupply();
12+
* ```
13+
*/
14+
export function useSupply(): UseAsyncTask<
15+
SupplyRequest,
16+
ExecutionPlan,
17+
UnexpectedError
18+
> {
19+
const client = useAaveClient();
20+
21+
return useAsyncTask((request: SupplyRequest) => supply(client, request));
22+
}

0 commit comments

Comments
 (0)