Skip to content

Commit 89c8d26

Browse files
committed
feat: force a user to pass accountId in account hooks
1 parent 95a5cd6 commit 89c8d26

File tree

5 files changed

+24
-107
lines changed

5 files changed

+24
-107
lines changed

.changeset/silent-suits-yell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@abstract-money/react": patch
3+
---
4+
5+
Force a user to always pass accountId in account related hooks.

packages/react/src/hooks/account/utils.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.

packages/react/src/hooks/account/wallet/use-deposit.ts

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,25 @@
11
import { AccountId, AccountWalletClient } from '@abstract-money/core'
22
import { DeliverTxResponse } from '@cosmjs/stargate'
3-
import {
4-
UseMutationOptions,
5-
UseMutationResult,
6-
useMutation,
7-
} from '@tanstack/react-query'
8-
import { useAccountId, useConfig } from '../../../contexts'
9-
import { parseAccountIdArgs } from '../utils'
3+
import { UseMutationOptions, useMutation } from '@tanstack/react-query'
4+
import { useConfig } from '../../../contexts'
105

116
type DepositMutation = Parameters<AccountWalletClient['deposit']>[0]
127

13-
export function useDeposit(
14-
options?: Omit<
15-
UseMutationOptions<DeliverTxResponse, unknown, DepositMutation>,
16-
'mutationFn'
17-
>,
18-
): UseMutationResult<DeliverTxResponse, unknown, DepositMutation>
19-
export function useDeposit(
20-
abstractOptions: { accountId: AccountId | undefined },
21-
options?: Omit<
22-
UseMutationOptions<DeliverTxResponse, unknown, DepositMutation>,
23-
'mutationFn'
24-
>,
25-
): UseMutationResult<DeliverTxResponse, unknown, DepositMutation>
268
/**
279
* Hook to deposit assets to an Account.
2810
* @param options deposit options.
2911
*/
3012
export function useDeposit(
31-
arg1:
32-
| { accountId: AccountId | undefined }
33-
| UseMutationOptions<DeliverTxResponse, unknown, DepositMutation>
34-
| undefined,
35-
arg2?: UseMutationOptions<DeliverTxResponse, unknown, DepositMutation>,
13+
{ accountId }: { accountId: AccountId | undefined },
14+
options?: Omit<
15+
UseMutationOptions<DeliverTxResponse, unknown, DepositMutation>,
16+
'mutationFn'
17+
>,
3618
) {
37-
const { accountId, options } = parseAccountIdArgs(arg1, arg2)
3819
const config = useConfig()
39-
const { accountId: finalAccountId } = useAccountId({ accountId })
4020
const accountWalletClient = config.useAccountWalletClient({
41-
chainName: finalAccountId?.chainName,
21+
accountId,
22+
chainName: accountId?.chainName,
4223
})
4324
return useMutation(({ ...rest }) => {
4425
if (!accountWalletClient) throw new Error('client is not defined')

packages/react/src/hooks/account/wallet/use-execute.ts

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,20 @@
11
import { AccountId, AccountWalletClient } from '@abstract-money/core'
22
import { DeliverTxResponse } from '@cosmjs/stargate'
3-
import {
4-
UseMutationOptions,
5-
UseMutationResult,
6-
useMutation,
7-
} from '@tanstack/react-query'
8-
import { useAccountId, useConfig } from '../../../contexts'
9-
import { parseAccountIdArgs } from '../utils'
3+
import { UseMutationOptions, useMutation } from '@tanstack/react-query'
4+
import { useConfig } from '../../../contexts'
105

116
type ExecuteMutation = Parameters<AccountWalletClient['execute']>[0]
127

138
export function useExecute(
9+
{ accountId }: { accountId: AccountId | undefined },
1410
options?: Omit<
1511
UseMutationOptions<DeliverTxResponse, unknown, ExecuteMutation>,
1612
'mutationFn'
1713
>,
18-
): UseMutationResult<DeliverTxResponse, unknown, ExecuteMutation>
19-
export function useExecute(
20-
abstractOptions: { accountId: AccountId | undefined },
21-
options?: Omit<
22-
UseMutationOptions<DeliverTxResponse, unknown, ExecuteMutation>,
23-
'mutationFn'
24-
>,
25-
): UseMutationResult<DeliverTxResponse, unknown, ExecuteMutation>
26-
export function useExecute(
27-
arg1:
28-
| { accountId: AccountId | undefined }
29-
| UseMutationOptions<DeliverTxResponse, unknown, ExecuteMutation>
30-
| undefined,
31-
arg2?: UseMutationOptions<DeliverTxResponse, unknown, ExecuteMutation>,
32-
): UseMutationResult<DeliverTxResponse, unknown, ExecuteMutation> {
33-
const { accountId, options } = parseAccountIdArgs(arg1, arg2)
14+
) {
3415
const config = useConfig()
35-
const { accountId: finalAccountId } = useAccountId({ accountId })
3616
const accountWalletClient = config.useAccountWalletClient({
37-
chainName: finalAccountId?.chainName,
17+
chainName: accountId?.chainName,
3818
})
3919
return useMutation(({ ...rest }) => {
4020
if (!accountWalletClient) throw new Error('client is not defined')

packages/react/src/hooks/account/wallet/use-withdraw.ts

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,21 @@
11
import { AccountId, AccountWalletClient } from '@abstract-money/core'
22
import { DeliverTxResponse } from '@cosmjs/stargate'
3-
import {
4-
UseMutationOptions,
5-
UseMutationResult,
6-
useMutation,
7-
} from '@tanstack/react-query'
8-
import { useAccountId, useConfig } from '../../../contexts'
9-
import { parseAccountIdArgs } from '../utils'
3+
import { UseMutationOptions, useMutation } from '@tanstack/react-query'
4+
import { useConfig } from '../../../contexts'
105

116
type WithdrawMutation = Parameters<AccountWalletClient['withdraw']>[0]
127

13-
export function useWithdraw(
14-
options?: Omit<
15-
UseMutationOptions<DeliverTxResponse, unknown, WithdrawMutation>,
16-
'mutationFn'
17-
>,
18-
): UseMutationResult<DeliverTxResponse, unknown, WithdrawMutation>
19-
export function useWithdraw(
20-
abstractOptions: { accountId: AccountId | undefined },
21-
options?: Omit<
22-
UseMutationOptions<DeliverTxResponse, unknown, WithdrawMutation>,
23-
'mutationFn'
24-
>,
25-
): UseMutationResult<DeliverTxResponse, unknown, WithdrawMutation>
268
/**
279
* Hook to withdraw to an Account.
2810
* @param options withdraw options.
2911
*/
3012
export function useWithdraw(
31-
arg1:
32-
| { accountId: AccountId | undefined }
33-
| UseMutationOptions<DeliverTxResponse, unknown, WithdrawMutation>
34-
| undefined,
35-
arg2?: UseMutationOptions<DeliverTxResponse, unknown, WithdrawMutation>,
13+
{ accountId }: { accountId: AccountId | undefined },
14+
options?: UseMutationOptions<DeliverTxResponse, unknown, WithdrawMutation>,
3615
) {
37-
const { accountId, options } = parseAccountIdArgs(arg1, arg2)
3816
const config = useConfig()
39-
const { accountId: finalAccountId } = useAccountId({ accountId })
4017
const accountWalletClient = config.useAccountWalletClient({
41-
chainName: finalAccountId?.chainName,
18+
chainName: accountId?.chainName,
4219
})
4320
return useMutation(({ ...rest }) => {
4421
if (!accountWalletClient) throw new Error('client is not defined')

0 commit comments

Comments
 (0)