Skip to content

Add useClaimNamespace and re-export useSendFunds #140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/hip-feet-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@abstract-money/core": minor
"@abstract-money/react": minor
---

Add useClaimnamespace and re-export send funds
15 changes: 7 additions & 8 deletions packages/core/src/actions/account/wallet/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ import { CosmosMsgForEmpty } from '../../../codegen/abstract/cosmwasm-codegen/Ac
import { WithCosmWasmSignOptions } from '../../../types/parameters'
import { getAccountAddressFromApi } from '../public/get-account-address-from-api'

export type ExecuteParameters = Omit<
WithCosmWasmSignOptions<
BaseAccountWalletParameters & {
msgs: MaybeArray<AccountTypes.CosmosMsgForEmpty>
}
>,
'funds'
export type ExecuteParameters = WithCosmWasmSignOptions<
BaseAccountWalletParameters & {
msgs: MaybeArray<AccountTypes.CosmosMsgForEmpty>
}
>

/**
Expand All @@ -26,6 +23,7 @@ export type ExecuteParameters = Omit<
* @param msgs
* @param fee
* @param memo
* @param funds - funds FROM the wallet
*/
export async function execute({
accountId,
Expand All @@ -35,6 +33,7 @@ export async function execute({
msgs,
fee,
memo,
funds,
}: ExecuteParameters) {
const account = await getAccountAddressFromApi({
accountId,
Expand All @@ -55,7 +54,7 @@ export async function execute({
sender: sender,
contract: account,
msg: toUtf8(JSON.stringify(_msg)),
funds: [],
funds,
}),
}

Expand Down
30 changes: 27 additions & 3 deletions packages/core/src/actions/account/wallet/withdraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,31 @@ import { getAccountAddressFromApi } from '../public/get-account-address-from-api
import { execute } from './execute'
import { BaseAccountWalletParameters } from './types'

export type WithdrawParameters = WithCosmWasmSignOptions<
export type SendFundsParameters = WithCosmWasmSignOptions<
BaseAccountWalletParameters & {
assets: Asset[]
recipient: string
}
>

export async function withdraw({
/**
* @deprecated use `SendFundsParameters` instead
*/
export type WithdrawParameters = SendFundsParameters

/**
* Send funds or withdraw funds from the account.
* @param fee
* @param memo
* @param accountId
* @param signingCosmWasmClient
* @param apiUrl
* @param sender
* @param assets
* @param recipient
* @param funds - funds included from the WALLET.
*/
export async function sendFunds({
fee,
memo,
accountId,
Expand All @@ -20,7 +37,8 @@ export async function withdraw({
sender,
assets,
recipient,
}: WithdrawParameters) {
funds,
}: SendFundsParameters) {
const account = await getAccountAddressFromApi({
accountId,
cosmWasmClient: signingCosmWasmClient,
Expand All @@ -41,5 +59,11 @@ export async function withdraw({
msgs: transferMsgs,
fee,
memo,
funds,
})
}

/**
* @deprecated use `sendFunds` instead
*/
export const withdraw = sendFunds
20 changes: 19 additions & 1 deletion packages/core/src/clients/decorators/account-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { updateInfo } from '../../actions/account/wallet/update-info'
import { updateOwnership } from '../../actions/account/wallet/update-ownership'
import { updateStatus } from '../../actions/account/wallet/update-status'
import { upgradeModules } from '../../actions/account/wallet/upgrade-modules'
import { withdraw } from '../../actions/account/wallet/withdraw'
import { sendFunds, withdraw } from '../../actions/account/wallet/withdraw'
import { RegistryTypes } from '../../codegen/abstract/index'
import { ExtractAndPartializeParameters } from '../../types/parameters'

Expand Down Expand Up @@ -54,11 +54,20 @@ export type AccountWalletActions = {
typeof deposit
>,
): ReturnType<typeof deposit>
/**
* @deprecated
* @see sendFunds
*/
withdraw(
parameters: ExtractAndPartializeDecoratedParametersFromParameters<
typeof withdraw
>,
): ReturnType<typeof withdraw>
sendFunds(
parameters: ExtractAndPartializeDecoratedParametersFromParameters<
typeof sendFunds
>,
): ReturnType<typeof sendFunds>
execute(
parameters: ExtractAndPartializeDecoratedParametersFromParameters<
typeof execute
Expand Down Expand Up @@ -283,6 +292,15 @@ export function accountWalletActions(
...parameters,
...extra,
}),
sendFunds: ({ extra, ...parameters }) =>
sendFunds({
accountId,
signingCosmWasmClient,
apiUrl,
sender,
...parameters,
...extra,
}),
updateStatus: ({ extra, ...parameters }) =>
updateStatus({
accountId,
Expand Down
4 changes: 3 additions & 1 deletion packages/react/src/hooks/account/wallet/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './use-claim-namespace'
export * from './use-create-remote-account'
export * from './use-create-sub-account'
export * from './use-deposit'
Expand All @@ -6,8 +7,9 @@ export * from './use-execute'
export * from './use-execute-on-remote'
export * from './use-execute-on-remote-module'
export * from './use-execute-remote'
export * from './use-send-funds-to-remote'
export * from './use-install-modules'
export * from './use-request-remote-funds'
export * from './use-send-funds-to-remote'
export * from './use-update-info'
export * from './use-update-settings'
export * from './use-update-status'
Expand Down
55 changes: 55 additions & 0 deletions packages/react/src/hooks/account/wallet/use-claim-namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { AccountWalletClient } from '@abstract-money/core/clients'
import { AccountId } from '@abstract-money/core/utils'
import { ExecuteResult } from '@cosmjs/cosmwasm-stargate'
import { DeliverTxResponse } from '@cosmjs/stargate'
import { useMutation } from '@tanstack/react-query'
import { useConfig } from '../../../contexts'
import { ExtractArgsFromParameters } from '../../../types/args'
import {
UseMutationParameters,
UseMutationReturnType,
} from '../../../types/queries'

type ClaimNamespaceMutation = ExtractArgsFromParameters<
Parameters<AccountWalletClient['claimNamespace']>[0]
>

export type UseClaimNamespaceParameters = {
accountId: AccountId | undefined
chainName: string | undefined
mutation?: UseMutationParameters<
ExecuteResult,
unknown,
ClaimNamespaceMutation
>
}

/**
* Claim a namespace from version control on the account.
* @param accountId
* @param chainName
* @param mutation
*/
export function useClaimNamespace({
accountId,
chainName,
mutation,
}: UseClaimNamespaceParameters): UseMutationReturnType<
ExecuteResult,
unknown,
ClaimNamespaceMutation
> {
const config = useConfig()
const accountClient = config.useAccountWalletClient({
chainName,
accountId,
})
return useMutation(
['claimNamespace', chainName, accountId],
({ args, ...cosmWasmSignOptions }) => {
if (!accountClient) throw new Error('client is not defined')
return accountClient.claimNamespace({ ...cosmWasmSignOptions, ...args })
},
mutation,
)
}
18 changes: 11 additions & 7 deletions packages/react/src/hooks/account/wallet/use-install-modules.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AccountWalletClient } from '@abstract-money/core/clients'
import { AccountId } from '@abstract-money/core/utils'
import { DeliverTxResponse } from '@cosmjs/stargate'
import { ExecuteResult } from '@cosmjs/cosmwasm-stargate'
import { useMutation } from '@tanstack/react-query'
import { useConfig } from '../../../contexts'
import { ExtractArgsFromParameters } from '../../../types/args'
Expand All @@ -9,14 +9,18 @@ import {
UseMutationReturnType,
} from '../../../types/queries'

type ExecuteMutation = ExtractArgsFromParameters<
type InstallModulesMutation = ExtractArgsFromParameters<
Parameters<AccountWalletClient['installModules']>[0]
>

export type UseExecuteParameters = {
export type UseInstallModulesParameters = {
accountId: AccountId | undefined
chainName: string | undefined
mutation?: UseMutationParameters<DeliverTxResponse, unknown, ExecuteMutation>
mutation?: UseMutationParameters<
ExecuteResult,
unknown,
InstallModulesMutation
>
}

/**
Expand All @@ -29,10 +33,10 @@ export function useInstallModules({
accountId,
chainName,
mutation,
}: UseExecuteParameters): UseMutationReturnType<
DeliverTxResponse,
}: UseInstallModulesParameters): UseMutationReturnType<
ExecuteResult,
unknown,
ExecuteMutation
InstallModulesMutation
> {
const config = useConfig()
const accountClient = config.useAccountWalletClient({
Expand Down
23 changes: 15 additions & 8 deletions packages/react/src/hooks/account/wallet/use-withdraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,26 @@ import {
} from '../../../types/queries'

type WithdrawMutation = ExtractArgsFromParameters<
Parameters<AccountWalletClient['withdraw']>[0]
Parameters<AccountWalletClient['sendFunds']>[0]
>

export type UseWithdrawParameters = {
export type UseSendFundsParameters = {
accountId: AccountId | undefined
chainName: string | undefined
mutation?: UseMutationParameters<DeliverTxResponse, unknown, WithdrawMutation>
}

export type UseWithdrawParameters = UseSendFundsParameters

/**
* Hook to withdraw to an Account.
* @param options withdraw options.
* Hook to send funds from an Account.
* @param options send funds options.
*/
export function useWithdraw({
export function useSendFunds({
accountId,
chainName,
mutation,
}: UseWithdrawParameters): UseMutationReturnType<
}: UseSendFundsParameters): UseMutationReturnType<
DeliverTxResponse,
unknown,
WithdrawMutation
Expand All @@ -38,11 +40,16 @@ export function useWithdraw({
accountId,
})
return useMutation(
['withdraw', chainName, accountId],
['sendFunds', chainName, accountId],
({ args, ...cosmWasmSignOptions }) => {
if (!accountClient) throw new Error('accountClient is not defined')
return accountClient.withdraw({ ...args, ...cosmWasmSignOptions })
return accountClient.sendFunds({ ...args, ...cosmWasmSignOptions })
},
mutation,
)
}

/**
* @deprecated use `useSendFunds` instead.
*/
export const useWithdraw = useSendFunds
Loading