Skip to content

Commit

Permalink
fix: parameters for hooks that get the version
Browse files Browse the repository at this point in the history
  • Loading branch information
dalechyn committed Feb 22, 2024
1 parent 766e9cf commit 6b6809d
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 126 deletions.
7 changes: 7 additions & 0 deletions .changeset/popular-points-live.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@ 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',
MODULE_FACTORY = 'module-factory',
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,
},
})

Expand All @@ -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}`,
)
}

Expand Down

This file was deleted.

25 changes: 25 additions & 0 deletions packages/core/src/actions/public/get-account-factory-version.ts
Original file line number Diff line number Diff line change
@@ -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,
},
})
}

This file was deleted.

25 changes: 25 additions & 0 deletions packages/core/src/actions/public/get-ans-host-version.ts
Original file line number Diff line number Diff line change
@@ -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,
},
})
}

This file was deleted.

25 changes: 25 additions & 0 deletions packages/core/src/actions/public/get-module-factory-version.ts
Original file line number Diff line number Diff line change
@@ -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,
},
})
}
48 changes: 23 additions & 25 deletions packages/core/src/clients/decorators/public.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -36,11 +36,11 @@ type CutCosmWasmClientAndApiUrlFromParameter<T extends (payload: any) => any> =
>

export type PublicActions = {
getAbstractModuleVersionFromVersionControl(
args: CutCosmWasmClientFromParameter<
typeof getAbstractModuleVersionFromVersionControl
getAbstractModuleVersion(
args: CutCosmWasmClientAndApiUrlFromParameter<
typeof getAbstractModuleVersion
>,
): ReturnType<typeof getAbstractModuleVersionFromVersionControl>
): ReturnType<typeof getAbstractModuleVersion>
getAbstractModuleAddressFromVersionControl(
args: CutCosmWasmClientFromParameter<
typeof getAbstractModuleAddressFromVersionControl
Expand All @@ -51,11 +51,11 @@ export type PublicActions = {
typeof getAccountFactoryAddressFromVersionControl
>,
): ReturnType<typeof getAccountFactoryAddressFromVersionControl>
getAccountFactoryVersionFromVersionControl(
args: CutCosmWasmClientFromParameter<
typeof getAccountFactoryVersionFromVersionControl
getAccountFactoryVersion(
args: CutCosmWasmClientAndApiUrlFromParameter<
typeof getAccountFactoryVersion
>,
): ReturnType<typeof getAccountFactoryVersionFromVersionControl>
): ReturnType<typeof getAccountFactoryVersion>
getAccountFactoryQueryClientFromVersionControl(
args: CutCosmWasmClientFromParameter<
typeof getAccountFactoryQueryClientFromVersionControl
Expand All @@ -69,11 +69,9 @@ export type PublicActions = {
getAccountFactoryQueryClient(
args: CutCosmWasmClientFromParameter<typeof getAccountFactoryQueryClient>,
): ReturnType<typeof getAccountFactoryQueryClient>
getAnsHostVersionFromVersionControl(
args: CutCosmWasmClientFromParameter<
typeof getAnsHostVersionFromVersionControl
>,
): ReturnType<typeof getAnsHostVersionFromVersionControl>
getAnsHostVersion(
args: CutCosmWasmClientAndApiUrlFromParameter<typeof getAnsHostVersion>,
): ReturnType<typeof getAnsHostVersion>
getAnsHostAddressFromVersionControl(
args: CutCosmWasmClientFromParameter<
typeof getAnsHostAddressFromVersionControl
Expand Down Expand Up @@ -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 }) =>
Expand All @@ -153,9 +151,9 @@ export function publicActions(
...rest,
}),

getAnsHostVersionFromVersionControl: ({ args, ...rest }) =>
getAnsHostVersionFromVersionControl({
args: { ...args, cosmWasmClient },
getAnsHostVersion: ({ args, ...rest }) =>
getAnsHostVersion({
args: { ...args, apiUrl, cosmWasmClient },
...rest,
}),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,35 @@ import { UseQueryOptions, useQuery } from '@tanstack/react-query'
import React from 'react'
import { useConfig } from '../../contexts'

type QueryFnData = Awaited<
ReturnType<PublicClient['getAbstractModuleVersionFromVersionControl']>
>
type QueryFnData = Awaited<ReturnType<PublicClient['getAbstractModuleVersion']>>

type QueryError = unknown
type QueryData = QueryFnData
type QueryKey = readonly [
'abstractModuleVersionFromVersionControl',
'abstractModuleVersion',
PublicClient | undefined,
string | undefined,
UseAbstractModuleVersionFromVersionControlArgs['args'],
UseAbstractModuleVersionArgs['args'],
]

type QueryOptions = Omit<
UseQueryOptions<QueryFnData, QueryError, QueryData, QueryKey>,
'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()
const publicClient = config.usePublicClient({
chainName,
})
const queryKey = React.useMemo(
() =>
[
'abstractModuleVersionFromVersionControl',
publicClient,
chainName,
args,
] as const,
() => ['abstractModuleVersion', publicClient, chainName, args] as const,
[publicClient, args],
)

Expand All @@ -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])
Expand Down

0 comments on commit 6b6809d

Please sign in to comment.