Skip to content

Commit 1078fae

Browse files
committed
useClaimNamespace, useSendFunds
1 parent 4d84a9f commit 1078fae

File tree

7 files changed

+132
-23
lines changed

7 files changed

+132
-23
lines changed

.changeset/hip-feet-serve.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@abstract-money/core": minor
3+
"@abstract-money/react": minor
4+
---
5+
6+
Add useClaimnamespace and re-export send funds

packages/core/src/actions/account/wallet/execute.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,10 @@ import { CosmosMsgForEmpty } from '../../../codegen/abstract/cosmwasm-codegen/Ac
88
import { WithCosmWasmSignOptions } from '../../../types/parameters'
99
import { getAccountAddressFromApi } from '../public/get-account-address-from-api'
1010

11-
export type ExecuteParameters = Omit<
12-
WithCosmWasmSignOptions<
13-
BaseAccountWalletParameters & {
14-
msgs: MaybeArray<AccountTypes.CosmosMsgForEmpty>
15-
}
16-
>,
17-
'funds'
11+
export type ExecuteParameters = WithCosmWasmSignOptions<
12+
BaseAccountWalletParameters & {
13+
msgs: MaybeArray<AccountTypes.CosmosMsgForEmpty>
14+
}
1815
>
1916

2017
/**
@@ -26,6 +23,7 @@ export type ExecuteParameters = Omit<
2623
* @param msgs
2724
* @param fee
2825
* @param memo
26+
* @param funds - funds FROM the wallet
2927
*/
3028
export async function execute({
3129
accountId,
@@ -35,6 +33,7 @@ export async function execute({
3533
msgs,
3634
fee,
3735
memo,
36+
funds,
3837
}: ExecuteParameters) {
3938
const account = await getAccountAddressFromApi({
4039
accountId,
@@ -55,7 +54,7 @@ export async function execute({
5554
sender: sender,
5655
contract: account,
5756
msg: toUtf8(JSON.stringify(_msg)),
58-
funds: [],
57+
funds,
5958
}),
6059
}
6160

packages/core/src/actions/account/wallet/withdraw.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,31 @@ import { getAccountAddressFromApi } from '../public/get-account-address-from-api
44
import { execute } from './execute'
55
import { BaseAccountWalletParameters } from './types'
66

7-
export type WithdrawParameters = WithCosmWasmSignOptions<
7+
export type SendFundsParameters = WithCosmWasmSignOptions<
88
BaseAccountWalletParameters & {
99
assets: Asset[]
1010
recipient: string
1111
}
1212
>
1313

14-
export async function withdraw({
14+
/**
15+
* @deprecated use `SendFundsParameters` instead
16+
*/
17+
export type WithdrawParameters = SendFundsParameters
18+
19+
/**
20+
* Send funds or withdraw funds from the account.
21+
* @param fee
22+
* @param memo
23+
* @param accountId
24+
* @param signingCosmWasmClient
25+
* @param apiUrl
26+
* @param sender
27+
* @param assets
28+
* @param recipient
29+
* @param funds - funds included from the WALLET.
30+
*/
31+
export async function sendFunds({
1532
fee,
1633
memo,
1734
accountId,
@@ -20,7 +37,8 @@ export async function withdraw({
2037
sender,
2138
assets,
2239
recipient,
23-
}: WithdrawParameters) {
40+
funds,
41+
}: SendFundsParameters) {
2442
const account = await getAccountAddressFromApi({
2543
accountId,
2644
cosmWasmClient: signingCosmWasmClient,
@@ -41,5 +59,11 @@ export async function withdraw({
4159
msgs: transferMsgs,
4260
fee,
4361
memo,
62+
funds,
4463
})
4564
}
65+
66+
/**
67+
* @deprecated use `sendFunds` instead
68+
*/
69+
export const withdraw = sendFunds

packages/core/src/clients/decorators/account-wallet.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { updateInfo } from '../../actions/account/wallet/update-info'
1919
import { updateOwnership } from '../../actions/account/wallet/update-ownership'
2020
import { updateStatus } from '../../actions/account/wallet/update-status'
2121
import { upgradeModules } from '../../actions/account/wallet/upgrade-modules'
22-
import { withdraw } from '../../actions/account/wallet/withdraw'
22+
import { sendFunds, withdraw } from '../../actions/account/wallet/withdraw'
2323
import { RegistryTypes } from '../../codegen/abstract/index'
2424
import { ExtractAndPartializeParameters } from '../../types/parameters'
2525

@@ -54,11 +54,20 @@ export type AccountWalletActions = {
5454
typeof deposit
5555
>,
5656
): ReturnType<typeof deposit>
57+
/**
58+
* @deprecated
59+
* @see sendFunds
60+
*/
5761
withdraw(
5862
parameters: ExtractAndPartializeDecoratedParametersFromParameters<
5963
typeof withdraw
6064
>,
6165
): ReturnType<typeof withdraw>
66+
sendFunds(
67+
parameters: ExtractAndPartializeDecoratedParametersFromParameters<
68+
typeof sendFunds
69+
>,
70+
): ReturnType<typeof sendFunds>
6271
execute(
6372
parameters: ExtractAndPartializeDecoratedParametersFromParameters<
6473
typeof execute
@@ -283,6 +292,15 @@ export function accountWalletActions(
283292
...parameters,
284293
...extra,
285294
}),
295+
sendFunds: ({ extra, ...parameters }) =>
296+
sendFunds({
297+
accountId,
298+
signingCosmWasmClient,
299+
apiUrl,
300+
sender,
301+
...parameters,
302+
...extra,
303+
}),
286304
updateStatus: ({ extra, ...parameters }) =>
287305
updateStatus({
288306
accountId,
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { AccountWalletClient } from '@abstract-money/core/clients'
2+
import { AccountId } from '@abstract-money/core/utils'
3+
import { ExecuteResult } from '@cosmjs/cosmwasm-stargate'
4+
import { DeliverTxResponse } from '@cosmjs/stargate'
5+
import { useMutation } from '@tanstack/react-query'
6+
import { useConfig } from '../../../contexts'
7+
import { ExtractArgsFromParameters } from '../../../types/args'
8+
import {
9+
UseMutationParameters,
10+
UseMutationReturnType,
11+
} from '../../../types/queries'
12+
13+
type ClaimNamespaceMutation = ExtractArgsFromParameters<
14+
Parameters<AccountWalletClient['claimNamespace']>[0]
15+
>
16+
17+
export type UseClaimNamespaceParameters = {
18+
accountId: AccountId | undefined
19+
chainName: string | undefined
20+
mutation?: UseMutationParameters<
21+
ExecuteResult,
22+
unknown,
23+
ClaimNamespaceMutation
24+
>
25+
}
26+
27+
/**
28+
* Execute a msg as the account.
29+
* @param accountId
30+
* @param chainName
31+
* @param mutation
32+
*/
33+
export function useClaimNamespace({
34+
accountId,
35+
chainName,
36+
mutation,
37+
}: UseClaimNamespaceParameters): UseMutationReturnType<
38+
ExecuteResult,
39+
unknown,
40+
ClaimNamespaceMutation
41+
> {
42+
const config = useConfig()
43+
const accountClient = config.useAccountWalletClient({
44+
chainName,
45+
accountId,
46+
})
47+
return useMutation(
48+
['claimNamespace', chainName, accountId],
49+
({ args, ...cosmWasmSignOptions }) => {
50+
if (!accountClient) throw new Error('client is not defined')
51+
return accountClient.claimNamespace({ ...cosmWasmSignOptions, ...args })
52+
},
53+
mutation,
54+
)
55+
}

packages/react/src/hooks/account/wallet/use-install-modules.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { AccountWalletClient } from '@abstract-money/core/clients'
22
import { AccountId } from '@abstract-money/core/utils'
3-
import { DeliverTxResponse } from '@cosmjs/stargate'
3+
import { ExecuteResult } from '@cosmjs/cosmwasm-stargate'
44
import { useMutation } from '@tanstack/react-query'
55
import { useConfig } from '../../../contexts'
66
import { ExtractArgsFromParameters } from '../../../types/args'
@@ -16,7 +16,7 @@ type ExecuteMutation = ExtractArgsFromParameters<
1616
export type UseExecuteParameters = {
1717
accountId: AccountId | undefined
1818
chainName: string | undefined
19-
mutation?: UseMutationParameters<DeliverTxResponse, unknown, ExecuteMutation>
19+
mutation?: UseMutationParameters<ExecuteResult, unknown, ExecuteMutation>
2020
}
2121

2222
/**
@@ -30,7 +30,7 @@ export function useInstallModules({
3030
chainName,
3131
mutation,
3232
}: UseExecuteParameters): UseMutationReturnType<
33-
DeliverTxResponse,
33+
ExecuteResult,
3434
unknown,
3535
ExecuteMutation
3636
> {

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,26 @@ import {
1010
} from '../../../types/queries'
1111

1212
type WithdrawMutation = ExtractArgsFromParameters<
13-
Parameters<AccountWalletClient['withdraw']>[0]
13+
Parameters<AccountWalletClient['sendFunds']>[0]
1414
>
1515

16-
export type UseWithdrawParameters = {
16+
export type UseSendFundsParameters = {
1717
accountId: AccountId | undefined
1818
chainName: string | undefined
1919
mutation?: UseMutationParameters<DeliverTxResponse, unknown, WithdrawMutation>
2020
}
2121

22+
export type UseWithdrawParameters = UseSendFundsParameters
23+
2224
/**
23-
* Hook to withdraw to an Account.
24-
* @param options withdraw options.
25+
* Hook to send funds from an Account.
26+
* @param options send funds options.
2527
*/
26-
export function useWithdraw({
28+
export function useSendFunds({
2729
accountId,
2830
chainName,
2931
mutation,
30-
}: UseWithdrawParameters): UseMutationReturnType<
32+
}: UseSendFundsParameters): UseMutationReturnType<
3133
DeliverTxResponse,
3234
unknown,
3335
WithdrawMutation
@@ -38,11 +40,16 @@ export function useWithdraw({
3840
accountId,
3941
})
4042
return useMutation(
41-
['withdraw', chainName, accountId],
43+
['sendFunds', chainName, accountId],
4244
({ args, ...cosmWasmSignOptions }) => {
4345
if (!accountClient) throw new Error('accountClient is not defined')
44-
return accountClient.withdraw({ ...args, ...cosmWasmSignOptions })
46+
return accountClient.sendFunds({ ...args, ...cosmWasmSignOptions })
4547
},
4648
mutation,
4749
)
4850
}
51+
52+
/**
53+
* @deprecated use `useSendFunds` instead.
54+
*/
55+
export const useWithdraw = useSendFunds

0 commit comments

Comments
 (0)