From 6b6809d7f9b4288aa3626c18818218dbc6805728 Mon Sep 17 00:00:00 2001 From: hotwater Date: Fri, 23 Feb 2024 01:08:03 +0200 Subject: [PATCH] fix: parameters for hooks that get the version --- .changeset/popular-points-live.md | 7 +++ ...trol.ts => get-abstract-module-version.ts} | 18 +++---- ...nt-factory-version-from-version-control.ts | 25 ---------- .../public/get-account-factory-version.ts | 25 ++++++++++ ...t-ans-host-version-from-version-control.ts | 25 ---------- .../actions/public/get-ans-host-version.ts | 25 ++++++++++ ...le-factory-version-from-version-control.ts | 25 ---------- .../public/get-module-factory-version.ts | 25 ++++++++++ .../core/src/clients/decorators/public.ts | 48 +++++++++---------- ...-api.ts => use-abstract-module-version.ts} | 26 ++++------ 10 files changed, 123 insertions(+), 126 deletions(-) create mode 100644 .changeset/popular-points-live.md rename packages/core/src/actions/public/{get-abstract-module-version-from-version-control.ts => get-abstract-module-version.ts} (67%) delete mode 100644 packages/core/src/actions/public/get-account-factory-version-from-version-control.ts create mode 100644 packages/core/src/actions/public/get-account-factory-version.ts delete mode 100644 packages/core/src/actions/public/get-ans-host-version-from-version-control.ts create mode 100644 packages/core/src/actions/public/get-ans-host-version.ts delete mode 100644 packages/core/src/actions/public/get-module-factory-version-from-version-control.ts create mode 100644 packages/core/src/actions/public/get-module-factory-version.ts rename packages/react/src/hooks/public/{use-abstract-module-version-from-api.ts => use-abstract-module-version.ts} (61%) diff --git a/.changeset/popular-points-live.md b/.changeset/popular-points-live.md new file mode 100644 index 00000000..4fa1a1ef --- /dev/null +++ b/.changeset/popular-points-live.md @@ -0,0 +1,7 @@ +--- +"wagemos-graz-nextjs": patch +"@abstract-money/core": patch +"@abstract-money/react": patch +--- + +Fix the parameters for hooks that get the version. diff --git a/packages/core/src/actions/public/get-abstract-module-version-from-version-control.ts b/packages/core/src/actions/public/get-abstract-module-version.ts similarity index 67% rename from packages/core/src/actions/public/get-abstract-module-version-from-version-control.ts rename to packages/core/src/actions/public/get-abstract-module-version.ts index 1eb2ffde..f5beac25 100644 --- a/packages/core/src/actions/public/get-abstract-module-version-from-version-control.ts +++ b/packages/core/src/actions/public/get-abstract-module-version.ts @@ -3,7 +3,7 @@ import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { VersionControlTypes } from '../../codegen/abstract' import { WithArgs } from '../../types/with-args' import { versionControlModuleToVersion } from '../../utils/version-control/version-control-module-to-version' -import { getVersionControlQueryClient } from './get-version-control-query-client' +import { getVersionControlQueryClientFromApi } from './get-version-control-query-client-from-api' export enum CommonModuleNames { ACCOUNT_FACTORY = 'account-factory', @@ -11,20 +11,20 @@ export enum CommonModuleNames { ANS_HOST = 'ans-host', } -export type GetAbstractModuleVersionFromVersionControl = WithArgs<{ +export type GetAbstractModuleVersion = WithArgs<{ moduleName: string cosmWasmClient: CosmWasmClient - versionControlAddress: string version?: string + apiUrl: string }> -export async function getAbstractModuleVersionFromVersionControl({ - args: { moduleName, cosmWasmClient, versionControlAddress, version }, -}: GetAbstractModuleVersionFromVersionControl) { - const versionControlQueryClient = getVersionControlQueryClient({ +export async function getAbstractModuleVersion({ + args: { moduleName, cosmWasmClient, version, apiUrl }, +}: GetAbstractModuleVersion) { + const versionControlQueryClient = await getVersionControlQueryClientFromApi({ args: { cosmWasmClient, - versionControlAddress, + apiUrl, }, }) @@ -44,7 +44,7 @@ export async function getAbstractModuleVersionFromVersionControl({ if (!moduleVersion) { throw new Error( - `Could not fetch address for module ${moduleName} version ${version} from registry ${versionControlAddress}`, + `Could not fetch address for module ${moduleName} version ${version} from registry ${versionControlQueryClient.contractAddress}`, ) } diff --git a/packages/core/src/actions/public/get-account-factory-version-from-version-control.ts b/packages/core/src/actions/public/get-account-factory-version-from-version-control.ts deleted file mode 100644 index a4a5dd8a..00000000 --- a/packages/core/src/actions/public/get-account-factory-version-from-version-control.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' - -import { WithArgs } from '../../types/with-args' -import { - CommonModuleNames, - getAbstractModuleVersionFromVersionControl, -} from './get-abstract-module-version-from-version-control' - -export type GetAccountFactoryVersionFromVersionControlParameters = WithArgs<{ - cosmWasmClient: CosmWasmClient - versionControlAddress: string - version?: string -}> -export async function getAccountFactoryVersionFromVersionControl({ - args: { cosmWasmClient, versionControlAddress, version }, -}: GetAccountFactoryVersionFromVersionControlParameters) { - return getAbstractModuleVersionFromVersionControl({ - args: { - moduleName: CommonModuleNames.ACCOUNT_FACTORY, - cosmWasmClient, - versionControlAddress, - version, - }, - }) -} diff --git a/packages/core/src/actions/public/get-account-factory-version.ts b/packages/core/src/actions/public/get-account-factory-version.ts new file mode 100644 index 00000000..fc45e73d --- /dev/null +++ b/packages/core/src/actions/public/get-account-factory-version.ts @@ -0,0 +1,25 @@ +import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' + +import { WithArgs } from '../../types/with-args' +import { + CommonModuleNames, + getAbstractModuleVersion, +} from './get-abstract-module-version' + +export type GetAccountFactoryVersionParameters = WithArgs<{ + cosmWasmClient: CosmWasmClient + apiUrl: string + version?: string +}> +export async function getAccountFactoryVersion({ + args: { cosmWasmClient, apiUrl, version }, +}: GetAccountFactoryVersionParameters) { + return getAbstractModuleVersion({ + args: { + apiUrl, + moduleName: CommonModuleNames.ACCOUNT_FACTORY, + cosmWasmClient, + version, + }, + }) +} diff --git a/packages/core/src/actions/public/get-ans-host-version-from-version-control.ts b/packages/core/src/actions/public/get-ans-host-version-from-version-control.ts deleted file mode 100644 index a6008ac4..00000000 --- a/packages/core/src/actions/public/get-ans-host-version-from-version-control.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' -import { WithArgs } from '../../types/with-args' -import { - CommonModuleNames, - getAbstractModuleVersionFromVersionControl, -} from './get-abstract-module-version-from-version-control' - -export type GetAnsHostVersionFromVersionControlParameters = WithArgs<{ - cosmWasmClient: CosmWasmClient - versionControlAddress: string - version?: string -}> - -export async function getAnsHostVersionFromVersionControl({ - args: { cosmWasmClient, versionControlAddress, version }, -}: GetAnsHostVersionFromVersionControlParameters) { - return getAbstractModuleVersionFromVersionControl({ - args: { - moduleName: CommonModuleNames.ANS_HOST, - cosmWasmClient, - versionControlAddress, - version, - }, - }) -} diff --git a/packages/core/src/actions/public/get-ans-host-version.ts b/packages/core/src/actions/public/get-ans-host-version.ts new file mode 100644 index 00000000..0b9588a1 --- /dev/null +++ b/packages/core/src/actions/public/get-ans-host-version.ts @@ -0,0 +1,25 @@ +import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' +import { WithArgs } from '../../types/with-args' +import { + CommonModuleNames, + getAbstractModuleVersion, +} from './get-abstract-module-version' + +export type GetAnsHostVersionParameters = WithArgs<{ + cosmWasmClient: CosmWasmClient + apiUrl: string + version?: string +}> + +export async function getAnsHostVersion({ + args: { cosmWasmClient, apiUrl, version }, +}: GetAnsHostVersionParameters) { + return getAbstractModuleVersion({ + args: { + moduleName: CommonModuleNames.ANS_HOST, + cosmWasmClient, + apiUrl, + version, + }, + }) +} diff --git a/packages/core/src/actions/public/get-module-factory-version-from-version-control.ts b/packages/core/src/actions/public/get-module-factory-version-from-version-control.ts deleted file mode 100644 index bb2e3501..00000000 --- a/packages/core/src/actions/public/get-module-factory-version-from-version-control.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' - -import { WithArgs } from '../../types/with-args' -import { - CommonModuleNames, - getAbstractModuleVersionFromVersionControl, -} from './get-abstract-module-version-from-version-control' - -export type GetModuleFactoryVersionFromVersionControlParameters = WithArgs<{ - cosmWasmClient: CosmWasmClient - versionControlAddress: string - version?: string -}> -export async function getModuleFactoryVersionFromVersionControl({ - args: { cosmWasmClient, versionControlAddress, version }, -}: GetModuleFactoryVersionFromVersionControlParameters) { - return getAbstractModuleVersionFromVersionControl({ - args: { - moduleName: CommonModuleNames.MODULE_FACTORY, - cosmWasmClient, - versionControlAddress, - version, - }, - }) -} diff --git a/packages/core/src/actions/public/get-module-factory-version.ts b/packages/core/src/actions/public/get-module-factory-version.ts new file mode 100644 index 00000000..8f168bf3 --- /dev/null +++ b/packages/core/src/actions/public/get-module-factory-version.ts @@ -0,0 +1,25 @@ +import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' + +import { WithArgs } from '../../types/with-args' +import { + CommonModuleNames, + getAbstractModuleVersion, +} from './get-abstract-module-version' + +export type GetModuleFactoryVersionParameters = WithArgs<{ + cosmWasmClient: CosmWasmClient + apiUrl: string + version?: string +}> +export async function getModuleFactoryVersion({ + args: { cosmWasmClient, apiUrl, version }, +}: GetModuleFactoryVersionParameters) { + return getAbstractModuleVersion({ + args: { + moduleName: CommonModuleNames.MODULE_FACTORY, + cosmWasmClient, + apiUrl, + version, + }, + }) +} diff --git a/packages/core/src/clients/decorators/public.ts b/packages/core/src/clients/decorators/public.ts index 922ebccb..9671f830 100644 --- a/packages/core/src/clients/decorators/public.ts +++ b/packages/core/src/clients/decorators/public.ts @@ -1,16 +1,16 @@ import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { getAbstractModuleAddressFromVersionControl } from '../../actions/public/get-abstract-module-address-from-version-control' -import { getAbstractModuleVersionFromVersionControl } from '../../actions/public/get-abstract-module-version-from-version-control' +import { getAbstractModuleVersion } from '../../actions/public/get-abstract-module-version' import { getAccountFactoryAddressFromVersionControl } from '../../actions/public/get-account-factory-address-from-version-control' import { getAccountFactoryQueryClient } from '../../actions/public/get-account-factory-query-client' import { getAccountFactoryQueryClientFromApi } from '../../actions/public/get-account-factory-query-client-from-api' import { getAccountFactoryQueryClientFromVersionControl } from '../../actions/public/get-account-factory-query-client-from-version-control' -import { getAccountFactoryVersionFromVersionControl } from '../../actions/public/get-account-factory-version-from-version-control' +import { getAccountFactoryVersion } from '../../actions/public/get-account-factory-version' import { getAnsHostAddressFromVersionControl } from '../../actions/public/get-ans-host-address-from-version-control' import { getAnsHostQueryClient } from '../../actions/public/get-ans-host-query-client' import { getAnsHostQueryClientFromApi } from '../../actions/public/get-ans-host-query-client-from-api' import { getAnsHostQueryClientFromVersionControl } from '../../actions/public/get-ans-host-query-client-from-version-control' -import { getAnsHostVersionFromVersionControl } from '../../actions/public/get-ans-host-version-from-version-control' +import { getAnsHostVersion } from '../../actions/public/get-ans-host-version' import { getCosmWasmClient } from '../../actions/public/get-cosm-wasm-client' import { getManagerQueryClient } from '../../actions/public/get-manager-query-client' import { getProxyQueryClient } from '../../actions/public/get-proxy-query-client' @@ -36,11 +36,11 @@ type CutCosmWasmClientAndApiUrlFromParameter any> = > export type PublicActions = { - getAbstractModuleVersionFromVersionControl( - args: CutCosmWasmClientFromParameter< - typeof getAbstractModuleVersionFromVersionControl + getAbstractModuleVersion( + args: CutCosmWasmClientAndApiUrlFromParameter< + typeof getAbstractModuleVersion >, - ): ReturnType + ): ReturnType getAbstractModuleAddressFromVersionControl( args: CutCosmWasmClientFromParameter< typeof getAbstractModuleAddressFromVersionControl @@ -51,11 +51,11 @@ export type PublicActions = { typeof getAccountFactoryAddressFromVersionControl >, ): ReturnType - getAccountFactoryVersionFromVersionControl( - args: CutCosmWasmClientFromParameter< - typeof getAccountFactoryVersionFromVersionControl + getAccountFactoryVersion( + args: CutCosmWasmClientAndApiUrlFromParameter< + typeof getAccountFactoryVersion >, - ): ReturnType + ): ReturnType getAccountFactoryQueryClientFromVersionControl( args: CutCosmWasmClientFromParameter< typeof getAccountFactoryQueryClientFromVersionControl @@ -69,11 +69,9 @@ export type PublicActions = { getAccountFactoryQueryClient( args: CutCosmWasmClientFromParameter, ): ReturnType - getAnsHostVersionFromVersionControl( - args: CutCosmWasmClientFromParameter< - typeof getAnsHostVersionFromVersionControl - >, - ): ReturnType + getAnsHostVersion( + args: CutCosmWasmClientAndApiUrlFromParameter, + ): ReturnType getAnsHostAddressFromVersionControl( args: CutCosmWasmClientFromParameter< typeof getAnsHostAddressFromVersionControl @@ -122,14 +120,14 @@ export function publicActions( args: { ...args, cosmWasmClient }, ...rest, }), - getAbstractModuleVersionFromVersionControl: ({ args, ...rest }) => - getAbstractModuleVersionFromVersionControl({ - args: { ...args, cosmWasmClient }, + getAbstractModuleVersion: ({ args, ...rest }) => + getAbstractModuleVersion({ + args: { ...args, cosmWasmClient, apiUrl }, ...rest, }), - getAccountFactoryVersionFromVersionControl: ({ args, ...rest }) => - getAccountFactoryVersionFromVersionControl({ - args: { ...args, cosmWasmClient }, + getAccountFactoryVersion: ({ args, ...rest }) => + getAccountFactoryVersion({ + args: { ...args, cosmWasmClient, apiUrl }, ...rest, }), getAccountFactoryAddressFromVersionControl: ({ args, ...rest }) => @@ -153,9 +151,9 @@ export function publicActions( ...rest, }), - getAnsHostVersionFromVersionControl: ({ args, ...rest }) => - getAnsHostVersionFromVersionControl({ - args: { ...args, cosmWasmClient }, + getAnsHostVersion: ({ args, ...rest }) => + getAnsHostVersion({ + args: { ...args, apiUrl, cosmWasmClient }, ...rest, }), diff --git a/packages/react/src/hooks/public/use-abstract-module-version-from-api.ts b/packages/react/src/hooks/public/use-abstract-module-version.ts similarity index 61% rename from packages/react/src/hooks/public/use-abstract-module-version-from-api.ts rename to packages/react/src/hooks/public/use-abstract-module-version.ts index 659d6c43..0a726a06 100644 --- a/packages/react/src/hooks/public/use-abstract-module-version-from-api.ts +++ b/packages/react/src/hooks/public/use-abstract-module-version.ts @@ -3,17 +3,15 @@ import { UseQueryOptions, useQuery } from '@tanstack/react-query' import React from 'react' import { useConfig } from '../../contexts' -type QueryFnData = Awaited< - ReturnType -> +type QueryFnData = Awaited> type QueryError = unknown type QueryData = QueryFnData type QueryKey = readonly [ - 'abstractModuleVersionFromVersionControl', + 'abstractModuleVersion', PublicClient | undefined, string | undefined, - UseAbstractModuleVersionFromVersionControlArgs['args'], + UseAbstractModuleVersionArgs['args'], ] type QueryOptions = Omit< @@ -21,11 +19,11 @@ type QueryOptions = Omit< 'queryFn' > -type UseAbstractModuleVersionFromVersionControlArgs = Parameters< - PublicClient['getAbstractModuleVersionFromVersionControl'] +type UseAbstractModuleVersionArgs = Parameters< + PublicClient['getAbstractModuleVersion'] >[0] & { chainName: string | undefined } -export function useAbstractModuleVersionFromVersionControl( - { args, chainName }: UseAbstractModuleVersionFromVersionControlArgs, +export function useAbstractModuleVersion( + { args, chainName }: UseAbstractModuleVersionArgs, options: QueryOptions = { enabled: true }, ) { const config = useConfig() @@ -33,13 +31,7 @@ export function useAbstractModuleVersionFromVersionControl( chainName, }) const queryKey = React.useMemo( - () => - [ - 'abstractModuleVersionFromVersionControl', - publicClient, - chainName, - args, - ] as const, + () => ['abstractModuleVersion', publicClient, chainName, args] as const, [publicClient, args], ) @@ -52,7 +44,7 @@ export function useAbstractModuleVersionFromVersionControl( if (!publicClient) throw new Error('No client') if (!args) throw new Error('No args') - return publicClient.getAbstractModuleVersionFromVersionControl({ + return publicClient.getAbstractModuleVersion({ args, }) }, [publicClient])