Skip to content
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/good-pets-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@abstract-money/core": patch
"@abstract-money/react": patch
---

Added query and action to upgrade a module.
36 changes: 36 additions & 0 deletions packages/core/src/actions/account/wallet/upgrade-module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate'
import { ManagerClient, VersionControlTypes } from '../../../codegen/abstract'
import { WithCosmWasmSignOptions } from '../../../types/parameters'
import { getManagerClientFromApi } from './get-manager-client-from-api'

export type UpgradeModuleParameters = WithCosmWasmSignOptions<
{
accountId: VersionControlTypes.AccountId
signingCosmWasmClient: SigningCosmWasmClient
apiUrl: string
sender: string
} & Omit<
Parameters<typeof ManagerClient.prototype.upgrade>[0],
'accountId'
> & { subAccountId?: number }
>

export async function upgradeModule({
accountId,
subAccountId,
signingCosmWasmClient,
apiUrl,
sender,
fee,
memo,
funds,
...rest
}: UpgradeModuleParameters) {
const managerClient = await getManagerClientFromApi({
accountId,
signingCosmWasmClient,
sender,
apiUrl,
})
return managerClient.upgrade(rest, fee, memo, funds)
}
1 change: 1 addition & 0 deletions packages/core/src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export * from './account/wallet/execute'
export * from './account/wallet/get-manager-client-from-api'
export * from './account/wallet/get-proxy-client-from-api'
export * from './account/wallet/remove-namespace'
export * from './account/wallet/upgrade-module'
export * from './account/wallet/withdraw'

export * from './public/get-abstract-module-address-from-version-control'
Expand Down
14 changes: 14 additions & 0 deletions packages/core/src/clients/decorators/account-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { execute } from '../../actions/account/wallet/execute'
import { getManagerClientFromApi } from '../../actions/account/wallet/get-manager-client-from-api'
import { getProxyClientFromApi } from '../../actions/account/wallet/get-proxy-client-from-api'
import { revokeNamespace } from '../../actions/account/wallet/remove-namespace'
import { upgradeModule } from '../../actions/account/wallet/upgrade-module'
import { withdraw } from '../../actions/account/wallet/withdraw'
import { VersionControlTypes } from '../../codegen/abstract/index'
import { ExtractAndOmitParameters } from '../../types/parameters'
Expand Down Expand Up @@ -49,6 +50,11 @@ export type AccountWalletActions = {
typeof revokeNamespace
>,
): ReturnType<typeof revokeNamespace>
upgradeModule(
parameters: ExtractAndOmitDecoratedParametersFromParameters<
typeof upgradeModule
>,
): ReturnType<typeof upgradeModule>
withdraw(
parameters: ExtractAndOmitDecoratedParametersFromParameters<
typeof withdraw
Expand Down Expand Up @@ -95,6 +101,14 @@ export function accountWalletActions(
apiUrl,
sender,
}),
upgradeModule: (parameters) =>
upgradeModule({
...parameters,
accountId,
signingCosmWasmClient,
apiUrl,
sender,
}),
withdraw: (parameters) =>
withdraw({
...parameters,
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/hooks/account/wallet/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './use-deposit'
export * from './use-create-sub-account'
export * from './use-execute'
export * from './use-upgrade-module'
export * from './use-withdraw'
37 changes: 37 additions & 0 deletions packages/react/src/hooks/account/wallet/use-upgrade-module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { AccountWalletClient } from '@abstract-money/core/clients'
import { AccountId } from '@abstract-money/core/utils'
import { useMutation } from '@tanstack/react-query'
import { useConfig } from '../../../contexts'
import { ExtractArgsFromParameters } from '../../../types/args'
import { UseMutationParameters } from '../../../types/queries'

type UpgradeModuleMutation = ExtractArgsFromParameters<
Parameters<AccountWalletClient['upgradeModule']>[0]
>

export type UseUpgradeModuleParameters = {
accountId: AccountId | undefined
chainName: string | undefined
mutation?: UseMutationParameters<
Awaited<ReturnType<AccountWalletClient['upgradeModule']>>,
unknown,
UpgradeModuleMutation
>
}

export function useUpgradeModule({
accountId,
chainName,
mutation,
}: UseUpgradeModuleParameters) {
const config = useConfig()
const walletClient = config.useAccountWalletClient({
chainName,
accountId,
})

return useMutation(({ args, ...cosmWasmSignOptions }) => {
if (!walletClient) throw new Error('walletClient is not defined')
return walletClient.upgradeModule({ ...cosmWasmSignOptions, ...args })
}, mutation)
}