From 969a6797fae69f3285b3e7c303a1e498836951f4 Mon Sep 17 00:00:00 2001 From: hotwater Date: Mon, 18 Mar 2024 19:31:45 +0200 Subject: [PATCH 1/4] feat: bring `chainName` back --- .changeset/young-dingos-speak.md | 8 +++ .../src/_generated/index.ts | 58 ++++++++++++++----- .../src/app/_components/place-bet-dialog.tsx | 1 + .../wagemos-cosmoskit-nextjs/src/app/page.tsx | 1 + .../src/_generated/index.ts | 58 ++++++++++++++----- .../src/app/_components/place-bet-dialog.tsx | 1 + .../src/app/authz-osmosis/page.tsx | 1 + examples/wagemos-graz-nextjs/src/app/page.tsx | 1 + packages/cli/src/plugins/react.ts | 4 +- .../use-account-base-addresses-from-api.ts | 4 +- ...se-module-instantiate2-address-from-api.ts | 4 +- .../public/use-sub-accounts-ids-from-api.ts | 4 +- .../account/wallet/use-create-sub-account.ts | 4 +- .../src/hooks/account/wallet/use-deposit.ts | 4 +- .../src/hooks/account/wallet/use-execute.ts | 4 +- .../src/hooks/account/wallet/use-withdraw.ts | 4 +- 16 files changed, 126 insertions(+), 35 deletions(-) create mode 100644 .changeset/young-dingos-speak.md diff --git a/.changeset/young-dingos-speak.md b/.changeset/young-dingos-speak.md new file mode 100644 index 00000000..796c3b3c --- /dev/null +++ b/.changeset/young-dingos-speak.md @@ -0,0 +1,8 @@ +--- +"wagemos-cosmoskit-nextjs": patch +"wagemos-graz-nextjs": patch +"@abstract-money/cli": patch +"@abstract-money/react": patch +--- + +Brought `chainName` parameter back to account-dependant hooks./ diff --git a/examples/wagemos-cosmoskit-nextjs/src/_generated/index.ts b/examples/wagemos-cosmoskit-nextjs/src/_generated/index.ts index a5220b37..5d9fad37 100644 --- a/examples/wagemos-cosmoskit-nextjs/src/_generated/index.ts +++ b/examples/wagemos-cosmoskit-nextjs/src/_generated/index.ts @@ -60,7 +60,10 @@ export const betting = { }: Omit< Parameters>[0], 'client' - > & { accountId: AccountId | undefined }) => { + > & { + accountId: AccountId | undefined + chainName: string | undefined + }) => { const { data: bettingAppQueryClient, isLoading: isBettingAppQueryClientLoading, @@ -120,7 +123,10 @@ export const betting = { }: Omit< Parameters>[0], 'client' - > & { accountId: AccountId | undefined }) => { + > & { + accountId: AccountId | undefined + chainName: string | undefined + }) => { const { data: bettingAppQueryClient, isLoading: isBettingAppQueryClientLoading, @@ -182,7 +188,10 @@ export const betting = { typeof useBettingListOddsQuery >[0], 'client' - > & { accountId: AccountId | undefined }) => { + > & { + accountId: AccountId | undefined + chainName: string | undefined + }) => { const { data: bettingAppQueryClient, isLoading: isBettingAppQueryClientLoading, @@ -243,7 +252,10 @@ export const betting = { }: Omit< Parameters>[0], 'client' - > & { accountId: AccountId | undefined }) => { + > & { + accountId: AccountId | undefined + chainName: string | undefined + }) => { const { data: bettingAppQueryClient, isLoading: isBettingAppQueryClientLoading, @@ -306,7 +318,10 @@ export const betting = { typeof useBettingListRoundsQuery >[0], 'client' - > & { accountId: AccountId | undefined }) => { + > & { + accountId: AccountId | undefined + chainName: string | undefined + }) => { const { data: bettingAppQueryClient, isLoading: isBettingAppQueryClientLoading, @@ -367,7 +382,10 @@ export const betting = { }: Omit< Parameters>[0], 'client' - > & { accountId: AccountId | undefined }) => { + > & { + accountId: AccountId | undefined + chainName: string | undefined + }) => { const { data: bettingAppQueryClient, isLoading: isBettingAppQueryClientLoading, @@ -424,7 +442,9 @@ export const betting = { }, mutations: { useUpdateConfig: ( - { accountId }: { accountId: AccountId | undefined }, + { + accountId, + }: { accountId: AccountId | undefined; chainName: string | undefined }, options?: Omit< UseMutationOptions< ExecuteResult, @@ -474,7 +494,9 @@ export const betting = { return { mutate, mutateAsync, ...rest } as const }, useCloseRound: ( - { accountId }: { accountId: AccountId | undefined }, + { + accountId, + }: { accountId: AccountId | undefined; chainName: string | undefined }, options?: Omit< UseMutationOptions< ExecuteResult, @@ -524,7 +546,9 @@ export const betting = { return { mutate, mutateAsync, ...rest } as const }, useDistributeWinnings: ( - { accountId }: { accountId: AccountId | undefined }, + { + accountId, + }: { accountId: AccountId | undefined; chainName: string | undefined }, options?: Omit< UseMutationOptions< ExecuteResult, @@ -574,7 +598,9 @@ export const betting = { return { mutate, mutateAsync, ...rest } as const }, usePlaceBet: ( - { accountId }: { accountId: AccountId | undefined }, + { + accountId, + }: { accountId: AccountId | undefined; chainName: string | undefined }, options?: Omit< UseMutationOptions< ExecuteResult, @@ -624,7 +650,9 @@ export const betting = { return { mutate, mutateAsync, ...rest } as const }, useUpdateAccounts: ( - { accountId }: { accountId: AccountId | undefined }, + { + accountId, + }: { accountId: AccountId | undefined; chainName: string | undefined }, options?: Omit< UseMutationOptions< ExecuteResult, @@ -674,7 +702,9 @@ export const betting = { return { mutate, mutateAsync, ...rest } as const }, useRegister: ( - { accountId }: { accountId: AccountId | undefined }, + { + accountId, + }: { accountId: AccountId | undefined; chainName: string | undefined }, options?: Omit< UseMutationOptions< ExecuteResult, @@ -724,7 +754,9 @@ export const betting = { return { mutate, mutateAsync, ...rest } as const }, useCreateRound: ( - { accountId }: { accountId: AccountId | undefined }, + { + accountId, + }: { accountId: AccountId | undefined; chainName: string | undefined }, options?: Omit< UseMutationOptions< ExecuteResult, diff --git a/examples/wagemos-cosmoskit-nextjs/src/app/_components/place-bet-dialog.tsx b/examples/wagemos-cosmoskit-nextjs/src/app/_components/place-bet-dialog.tsx index 6c299188..36fe1983 100644 --- a/examples/wagemos-cosmoskit-nextjs/src/app/_components/place-bet-dialog.tsx +++ b/examples/wagemos-cosmoskit-nextjs/src/app/_components/place-bet-dialog.tsx @@ -64,6 +64,7 @@ export function PlaceBetDialog({ round }: { round: RoundResponse }) { const { mutateAsync: placeBetAsync, isLoading } = betting.mutations.usePlaceBet({ accountId: stringToAccountId('neutron-18'), + chainName: 'neutron', }) const onSubmit: SubmitHandler> = useCallback( diff --git a/examples/wagemos-cosmoskit-nextjs/src/app/page.tsx b/examples/wagemos-cosmoskit-nextjs/src/app/page.tsx index a27d50db..9bb8c303 100644 --- a/examples/wagemos-cosmoskit-nextjs/src/app/page.tsx +++ b/examples/wagemos-cosmoskit-nextjs/src/app/page.tsx @@ -23,6 +23,7 @@ export default function Home() { const { data, isLoading, isError } = betting.queries.useListRounds({ args: {}, accountId: stringToAccountId('neutron-18'), + chainName: 'neutron', }) if (isLoading) return

Loading...

if (isError) return

Error

diff --git a/examples/wagemos-graz-nextjs/src/_generated/index.ts b/examples/wagemos-graz-nextjs/src/_generated/index.ts index a5220b37..5d9fad37 100644 --- a/examples/wagemos-graz-nextjs/src/_generated/index.ts +++ b/examples/wagemos-graz-nextjs/src/_generated/index.ts @@ -60,7 +60,10 @@ export const betting = { }: Omit< Parameters>[0], 'client' - > & { accountId: AccountId | undefined }) => { + > & { + accountId: AccountId | undefined + chainName: string | undefined + }) => { const { data: bettingAppQueryClient, isLoading: isBettingAppQueryClientLoading, @@ -120,7 +123,10 @@ export const betting = { }: Omit< Parameters>[0], 'client' - > & { accountId: AccountId | undefined }) => { + > & { + accountId: AccountId | undefined + chainName: string | undefined + }) => { const { data: bettingAppQueryClient, isLoading: isBettingAppQueryClientLoading, @@ -182,7 +188,10 @@ export const betting = { typeof useBettingListOddsQuery >[0], 'client' - > & { accountId: AccountId | undefined }) => { + > & { + accountId: AccountId | undefined + chainName: string | undefined + }) => { const { data: bettingAppQueryClient, isLoading: isBettingAppQueryClientLoading, @@ -243,7 +252,10 @@ export const betting = { }: Omit< Parameters>[0], 'client' - > & { accountId: AccountId | undefined }) => { + > & { + accountId: AccountId | undefined + chainName: string | undefined + }) => { const { data: bettingAppQueryClient, isLoading: isBettingAppQueryClientLoading, @@ -306,7 +318,10 @@ export const betting = { typeof useBettingListRoundsQuery >[0], 'client' - > & { accountId: AccountId | undefined }) => { + > & { + accountId: AccountId | undefined + chainName: string | undefined + }) => { const { data: bettingAppQueryClient, isLoading: isBettingAppQueryClientLoading, @@ -367,7 +382,10 @@ export const betting = { }: Omit< Parameters>[0], 'client' - > & { accountId: AccountId | undefined }) => { + > & { + accountId: AccountId | undefined + chainName: string | undefined + }) => { const { data: bettingAppQueryClient, isLoading: isBettingAppQueryClientLoading, @@ -424,7 +442,9 @@ export const betting = { }, mutations: { useUpdateConfig: ( - { accountId }: { accountId: AccountId | undefined }, + { + accountId, + }: { accountId: AccountId | undefined; chainName: string | undefined }, options?: Omit< UseMutationOptions< ExecuteResult, @@ -474,7 +494,9 @@ export const betting = { return { mutate, mutateAsync, ...rest } as const }, useCloseRound: ( - { accountId }: { accountId: AccountId | undefined }, + { + accountId, + }: { accountId: AccountId | undefined; chainName: string | undefined }, options?: Omit< UseMutationOptions< ExecuteResult, @@ -524,7 +546,9 @@ export const betting = { return { mutate, mutateAsync, ...rest } as const }, useDistributeWinnings: ( - { accountId }: { accountId: AccountId | undefined }, + { + accountId, + }: { accountId: AccountId | undefined; chainName: string | undefined }, options?: Omit< UseMutationOptions< ExecuteResult, @@ -574,7 +598,9 @@ export const betting = { return { mutate, mutateAsync, ...rest } as const }, usePlaceBet: ( - { accountId }: { accountId: AccountId | undefined }, + { + accountId, + }: { accountId: AccountId | undefined; chainName: string | undefined }, options?: Omit< UseMutationOptions< ExecuteResult, @@ -624,7 +650,9 @@ export const betting = { return { mutate, mutateAsync, ...rest } as const }, useUpdateAccounts: ( - { accountId }: { accountId: AccountId | undefined }, + { + accountId, + }: { accountId: AccountId | undefined; chainName: string | undefined }, options?: Omit< UseMutationOptions< ExecuteResult, @@ -674,7 +702,9 @@ export const betting = { return { mutate, mutateAsync, ...rest } as const }, useRegister: ( - { accountId }: { accountId: AccountId | undefined }, + { + accountId, + }: { accountId: AccountId | undefined; chainName: string | undefined }, options?: Omit< UseMutationOptions< ExecuteResult, @@ -724,7 +754,9 @@ export const betting = { return { mutate, mutateAsync, ...rest } as const }, useCreateRound: ( - { accountId }: { accountId: AccountId | undefined }, + { + accountId, + }: { accountId: AccountId | undefined; chainName: string | undefined }, options?: Omit< UseMutationOptions< ExecuteResult, diff --git a/examples/wagemos-graz-nextjs/src/app/_components/place-bet-dialog.tsx b/examples/wagemos-graz-nextjs/src/app/_components/place-bet-dialog.tsx index e86e4fc3..7225b5c9 100644 --- a/examples/wagemos-graz-nextjs/src/app/_components/place-bet-dialog.tsx +++ b/examples/wagemos-graz-nextjs/src/app/_components/place-bet-dialog.tsx @@ -64,6 +64,7 @@ export function PlaceBetDialog({ round }: { round: RoundResponse }) { const { mutateAsync: placeBetAsync, isLoading } = betting.mutations.usePlaceBet({ accountId: stringToAccountId('neutron-18'), + chainName: 'neutron', }) const onSubmit: SubmitHandler> = useCallback( diff --git a/examples/wagemos-graz-nextjs/src/app/authz-osmosis/page.tsx b/examples/wagemos-graz-nextjs/src/app/authz-osmosis/page.tsx index b4500767..1ecb723f 100644 --- a/examples/wagemos-graz-nextjs/src/app/authz-osmosis/page.tsx +++ b/examples/wagemos-graz-nextjs/src/app/authz-osmosis/page.tsx @@ -61,6 +61,7 @@ export default function AuthzPage() { const { data: savingsAppAddress } = useModuleInstantiate2AddressFromApi({ accountId: stringToAccountId(TEST_SAVINGS_ACCOUNT_ID, CHAIN_NAME), + chainName: CHAIN_NAME, args: { moduleId: SAVINGS_APP_MODULE_ID, }, diff --git a/examples/wagemos-graz-nextjs/src/app/page.tsx b/examples/wagemos-graz-nextjs/src/app/page.tsx index ac473b69..a7f7d3a1 100644 --- a/examples/wagemos-graz-nextjs/src/app/page.tsx +++ b/examples/wagemos-graz-nextjs/src/app/page.tsx @@ -22,6 +22,7 @@ import { WalletButton } from './_components/wallet-button' export default function Home() { const { data, isLoading, isError } = betting.queries.useListRounds({ accountId: stringToAccountId('neutron-18'), + chainName: 'neutron', args: {}, }) if (isLoading) return

Loading...

diff --git a/packages/cli/src/plugins/react.ts b/packages/cli/src/plugins/react.ts index 6ecb974b..d1b7ca40 100644 --- a/packages/cli/src/plugins/react.ts +++ b/packages/cli/src/plugins/react.ts @@ -292,7 +292,7 @@ export function react(options: ReactOptions = {}): ReactResult { hookName, )}>>[0], 'client'> & { ${ hasAbstractApp - ? 'accountId: AccountId | undefined;' + ? 'accountId: AccountId | undefined; chainName: string | undefined;' : 'contractAddress: string | undefined;' }}) => { const { @@ -385,7 +385,7 @@ export function react(options: ReactOptions = {}): ReactResult { hasAbstractApp ? 'accountId' : 'contractAddress' } }: { ${ hasAbstractApp - ? 'accountId: AccountId | undefined' + ? 'accountId: AccountId | undefined; chainName: string | undefined' : 'contractAddress: string | undefined' } }, options?: Omit< diff --git a/packages/react/src/hooks/account/public/use-account-base-addresses-from-api.ts b/packages/react/src/hooks/account/public/use-account-base-addresses-from-api.ts index 651e152b..7bf14c65 100644 --- a/packages/react/src/hooks/account/public/use-account-base-addresses-from-api.ts +++ b/packages/react/src/hooks/account/public/use-account-base-addresses-from-api.ts @@ -28,17 +28,19 @@ type QueryResult = UseQueryReturnType export type UseAccountBaseAddressesFromApiParameters = { accountId: AccountId | undefined + chainName: string | undefined query?: QueryOptions } export function useAccountBaseAddressesFromApi({ accountId, + chainName, query = {}, }: UseAccountBaseAddressesFromApiParameters): QueryResult { const config = useConfig() const accountPublicClient = config.useAccountPublicClient({ accountId, - chainName: accountId?.chainName, + chainName, }) const queryKey = React.useMemo( () => ['accountBaseAddresses', accountPublicClient, accountId] as const, diff --git a/packages/react/src/hooks/account/public/use-module-instantiate2-address-from-api.ts b/packages/react/src/hooks/account/public/use-module-instantiate2-address-from-api.ts index 318cd8ff..9fac5f6e 100644 --- a/packages/react/src/hooks/account/public/use-module-instantiate2-address-from-api.ts +++ b/packages/react/src/hooks/account/public/use-module-instantiate2-address-from-api.ts @@ -34,17 +34,19 @@ export type UseModuleInstantiate2AddressFromApiParameters = WithArgs< Parameters[0] > & { query?: QueryOptions + chainName: string | undefined accountId: AccountId | undefined } export function useModuleInstantiate2AddressFromApi({ args, accountId, + chainName, query = {}, }: UseModuleInstantiate2AddressFromApiParameters): QueryResult { const config = useConfig() const accountPublicClient = config.useAccountPublicClient({ accountId, - chainName: accountId?.chainName, + chainName, }) const queryKey = React.useMemo( () => diff --git a/packages/react/src/hooks/account/public/use-sub-accounts-ids-from-api.ts b/packages/react/src/hooks/account/public/use-sub-accounts-ids-from-api.ts index b646e1de..d61f4026 100644 --- a/packages/react/src/hooks/account/public/use-sub-accounts-ids-from-api.ts +++ b/packages/react/src/hooks/account/public/use-sub-accounts-ids-from-api.ts @@ -17,6 +17,7 @@ export type UseSubAccountIdsFromApiParameters = WithArgs< Parameters[0] > & { query?: QueryOptions + chainName: string | undefined accountId: AccountId | undefined } type QueryKey = readonly [ @@ -35,12 +36,13 @@ type QueryResult = UseQueryReturnType export function useSubAccountIdsFromApi({ args, accountId, + chainName, query = {}, }: UseSubAccountIdsFromApiParameters): QueryResult { const config = useConfig() const accountPublicClient = config.useAccountPublicClient({ accountId, - chainName: accountId?.chainName, + chainName, }) const queryKey = React.useMemo( () => diff --git a/packages/react/src/hooks/account/wallet/use-create-sub-account.ts b/packages/react/src/hooks/account/wallet/use-create-sub-account.ts index 12c8ab0a..50d26ac8 100644 --- a/packages/react/src/hooks/account/wallet/use-create-sub-account.ts +++ b/packages/react/src/hooks/account/wallet/use-create-sub-account.ts @@ -11,6 +11,7 @@ type CreateSubAccountMutation = ExtractArgsFromParameters< export type UseCreateSubAccountParameters = { accountId: AccountId | undefined + chainName: string | undefined mutation?: UseMutationParameters< Awaited>, unknown, @@ -20,11 +21,12 @@ export type UseCreateSubAccountParameters = { export function useCreateSubAccount({ accountId, + chainName, mutation, }: UseCreateSubAccountParameters) { const config = useConfig() const walletClient = config.useAccountWalletClient({ - chainName: accountId?.chainName, + chainName, accountId, }) diff --git a/packages/react/src/hooks/account/wallet/use-deposit.ts b/packages/react/src/hooks/account/wallet/use-deposit.ts index 5c97fc61..22e3edca 100644 --- a/packages/react/src/hooks/account/wallet/use-deposit.ts +++ b/packages/react/src/hooks/account/wallet/use-deposit.ts @@ -15,6 +15,7 @@ type DepositMutation = ExtractArgsFromParameters< export type UseDepositParameters = { accountId: AccountId | undefined + chainName: string | undefined mutation?: UseMutationParameters } @@ -24,6 +25,7 @@ export type UseDepositParameters = { */ export function useDeposit({ accountId, + chainName, mutation, }: UseDepositParameters): UseMutationReturnType< DeliverTxResponse, @@ -33,7 +35,7 @@ export function useDeposit({ const config = useConfig() const accountWalletClient = config.useAccountWalletClient({ accountId, - chainName: accountId?.chainName, + chainName, }) return useMutation(({ args, ...cosmWasmSignOptions }) => { if (!accountWalletClient) throw new Error('client is not defined') diff --git a/packages/react/src/hooks/account/wallet/use-execute.ts b/packages/react/src/hooks/account/wallet/use-execute.ts index 59bc476f..110f8363 100644 --- a/packages/react/src/hooks/account/wallet/use-execute.ts +++ b/packages/react/src/hooks/account/wallet/use-execute.ts @@ -15,10 +15,12 @@ type ExecuteMutation = ExtractArgsFromParameters< export type UseExecuteParameters = { accountId: AccountId | undefined + chainName: string | undefined mutation?: UseMutationParameters } export function useExecute({ accountId, + chainName, mutation, }: UseExecuteParameters): UseMutationReturnType< DeliverTxResponse, @@ -27,7 +29,7 @@ export function useExecute({ > { const config = useConfig() const accountWalletClient = config.useAccountWalletClient({ - chainName: accountId?.chainName, + chainName, accountId, }) return useMutation(({ args, ...cosmWasmSignOptions }) => { diff --git a/packages/react/src/hooks/account/wallet/use-withdraw.ts b/packages/react/src/hooks/account/wallet/use-withdraw.ts index 4cd4bb11..9d6508d0 100644 --- a/packages/react/src/hooks/account/wallet/use-withdraw.ts +++ b/packages/react/src/hooks/account/wallet/use-withdraw.ts @@ -15,6 +15,7 @@ type WithdrawMutation = ExtractArgsFromParameters< export type UseWithdrawParameters = { accountId: AccountId | undefined + chainName: string | undefined mutation?: UseMutationParameters } @@ -24,6 +25,7 @@ export type UseWithdrawParameters = { */ export function useWithdraw({ accountId, + chainName, mutation, }: UseWithdrawParameters): UseMutationReturnType< DeliverTxResponse, @@ -32,7 +34,7 @@ export function useWithdraw({ > { const config = useConfig() const accountWalletClient = config.useAccountWalletClient({ - chainName: accountId?.chainName, + chainName, accountId, }) return useMutation(({ args, ...cosmWasmSignOptions }) => { From ec3670474da26fcebe27124d4af9b2e2b8327548 Mon Sep 17 00:00:00 2001 From: Vladyslav Dalechyn Date: Mon, 18 Mar 2024 19:32:38 +0200 Subject: [PATCH 2/4] nit: typo --- .changeset/young-dingos-speak.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/young-dingos-speak.md b/.changeset/young-dingos-speak.md index 796c3b3c..4cb33d2e 100644 --- a/.changeset/young-dingos-speak.md +++ b/.changeset/young-dingos-speak.md @@ -5,4 +5,4 @@ "@abstract-money/react": patch --- -Brought `chainName` parameter back to account-dependant hooks./ +Brought `chainName` parameter back to account-dependant hooks. From 7647fa564b9c49b80f303c520eb0faa2731345b2 Mon Sep 17 00:00:00 2001 From: hotwater Date: Mon, 18 Mar 2024 19:42:51 +0200 Subject: [PATCH 3/4] fix: unused accountId --- .../src/_generated/index.ts | 14 +++++++ .../src/_generated/index.ts | 14 +++++++ packages/cli/src/plugins/react.ts | 5 ++- .../src/utils/use-abstract-module-client.ts | 4 +- .../utils/use-abstract-module-query-client.ts | 4 +- .../src/utils/use-abstract-query-client.ts | 38 ++++++++++--------- 6 files changed, 58 insertions(+), 21 deletions(-) diff --git a/examples/wagemos-cosmoskit-nextjs/src/_generated/index.ts b/examples/wagemos-cosmoskit-nextjs/src/_generated/index.ts index 5d9fad37..e25c1175 100644 --- a/examples/wagemos-cosmoskit-nextjs/src/_generated/index.ts +++ b/examples/wagemos-cosmoskit-nextjs/src/_generated/index.ts @@ -444,6 +444,7 @@ export const betting = { useUpdateConfig: ( { accountId, + chainName, }: { accountId: AccountId | undefined; chainName: string | undefined }, options?: Omit< UseMutationOptions< @@ -463,6 +464,7 @@ export const betting = { } = useAbstractModuleClient({ moduleId: BETTING_MODULE_ID, accountId, + chainName, Module: BettingAppClient, }) @@ -496,6 +498,7 @@ export const betting = { useCloseRound: ( { accountId, + chainName, }: { accountId: AccountId | undefined; chainName: string | undefined }, options?: Omit< UseMutationOptions< @@ -515,6 +518,7 @@ export const betting = { } = useAbstractModuleClient({ moduleId: BETTING_MODULE_ID, accountId, + chainName, Module: BettingAppClient, }) @@ -548,6 +552,7 @@ export const betting = { useDistributeWinnings: ( { accountId, + chainName, }: { accountId: AccountId | undefined; chainName: string | undefined }, options?: Omit< UseMutationOptions< @@ -567,6 +572,7 @@ export const betting = { } = useAbstractModuleClient({ moduleId: BETTING_MODULE_ID, accountId, + chainName, Module: BettingAppClient, }) @@ -600,6 +606,7 @@ export const betting = { usePlaceBet: ( { accountId, + chainName, }: { accountId: AccountId | undefined; chainName: string | undefined }, options?: Omit< UseMutationOptions< @@ -619,6 +626,7 @@ export const betting = { } = useAbstractModuleClient({ moduleId: BETTING_MODULE_ID, accountId, + chainName, Module: BettingAppClient, }) @@ -652,6 +660,7 @@ export const betting = { useUpdateAccounts: ( { accountId, + chainName, }: { accountId: AccountId | undefined; chainName: string | undefined }, options?: Omit< UseMutationOptions< @@ -671,6 +680,7 @@ export const betting = { } = useAbstractModuleClient({ moduleId: BETTING_MODULE_ID, accountId, + chainName, Module: BettingAppClient, }) @@ -704,6 +714,7 @@ export const betting = { useRegister: ( { accountId, + chainName, }: { accountId: AccountId | undefined; chainName: string | undefined }, options?: Omit< UseMutationOptions< @@ -723,6 +734,7 @@ export const betting = { } = useAbstractModuleClient({ moduleId: BETTING_MODULE_ID, accountId, + chainName, Module: BettingAppClient, }) @@ -756,6 +768,7 @@ export const betting = { useCreateRound: ( { accountId, + chainName, }: { accountId: AccountId | undefined; chainName: string | undefined }, options?: Omit< UseMutationOptions< @@ -775,6 +788,7 @@ export const betting = { } = useAbstractModuleClient({ moduleId: BETTING_MODULE_ID, accountId, + chainName, Module: BettingAppClient, }) diff --git a/examples/wagemos-graz-nextjs/src/_generated/index.ts b/examples/wagemos-graz-nextjs/src/_generated/index.ts index 5d9fad37..e25c1175 100644 --- a/examples/wagemos-graz-nextjs/src/_generated/index.ts +++ b/examples/wagemos-graz-nextjs/src/_generated/index.ts @@ -444,6 +444,7 @@ export const betting = { useUpdateConfig: ( { accountId, + chainName, }: { accountId: AccountId | undefined; chainName: string | undefined }, options?: Omit< UseMutationOptions< @@ -463,6 +464,7 @@ export const betting = { } = useAbstractModuleClient({ moduleId: BETTING_MODULE_ID, accountId, + chainName, Module: BettingAppClient, }) @@ -496,6 +498,7 @@ export const betting = { useCloseRound: ( { accountId, + chainName, }: { accountId: AccountId | undefined; chainName: string | undefined }, options?: Omit< UseMutationOptions< @@ -515,6 +518,7 @@ export const betting = { } = useAbstractModuleClient({ moduleId: BETTING_MODULE_ID, accountId, + chainName, Module: BettingAppClient, }) @@ -548,6 +552,7 @@ export const betting = { useDistributeWinnings: ( { accountId, + chainName, }: { accountId: AccountId | undefined; chainName: string | undefined }, options?: Omit< UseMutationOptions< @@ -567,6 +572,7 @@ export const betting = { } = useAbstractModuleClient({ moduleId: BETTING_MODULE_ID, accountId, + chainName, Module: BettingAppClient, }) @@ -600,6 +606,7 @@ export const betting = { usePlaceBet: ( { accountId, + chainName, }: { accountId: AccountId | undefined; chainName: string | undefined }, options?: Omit< UseMutationOptions< @@ -619,6 +626,7 @@ export const betting = { } = useAbstractModuleClient({ moduleId: BETTING_MODULE_ID, accountId, + chainName, Module: BettingAppClient, }) @@ -652,6 +660,7 @@ export const betting = { useUpdateAccounts: ( { accountId, + chainName, }: { accountId: AccountId | undefined; chainName: string | undefined }, options?: Omit< UseMutationOptions< @@ -671,6 +680,7 @@ export const betting = { } = useAbstractModuleClient({ moduleId: BETTING_MODULE_ID, accountId, + chainName, Module: BettingAppClient, }) @@ -704,6 +714,7 @@ export const betting = { useRegister: ( { accountId, + chainName, }: { accountId: AccountId | undefined; chainName: string | undefined }, options?: Omit< UseMutationOptions< @@ -723,6 +734,7 @@ export const betting = { } = useAbstractModuleClient({ moduleId: BETTING_MODULE_ID, accountId, + chainName, Module: BettingAppClient, }) @@ -756,6 +768,7 @@ export const betting = { useCreateRound: ( { accountId, + chainName, }: { accountId: AccountId | undefined; chainName: string | undefined }, options?: Omit< UseMutationOptions< @@ -775,6 +788,7 @@ export const betting = { } = useAbstractModuleClient({ moduleId: BETTING_MODULE_ID, accountId, + chainName, Module: BettingAppClient, }) diff --git a/packages/cli/src/plugins/react.ts b/packages/cli/src/plugins/react.ts index d1b7ca40..a5e06fb8 100644 --- a/packages/cli/src/plugins/react.ts +++ b/packages/cli/src/plugins/react.ts @@ -382,7 +382,9 @@ export function react(options: ReactOptions = {}): ReactResult { dedent` ( { ${ - hasAbstractApp ? 'accountId' : 'contractAddress' + hasAbstractApp + ? 'accountId, chainName' + : 'contractAddress' } }: { ${ hasAbstractApp ? 'accountId: AccountId | undefined; chainName: string | undefined' @@ -410,6 +412,7 @@ export function react(options: ReactOptions = {}): ReactResult { ? ` moduleId: ${constantCase(contract.name)}_MODULE_ID, accountId, + chainName, ` : 'contractAddress,' } diff --git a/packages/react/src/utils/use-abstract-module-client.ts b/packages/react/src/utils/use-abstract-module-client.ts index 0b524ce6..11920fe5 100644 --- a/packages/react/src/utils/use-abstract-module-client.ts +++ b/packages/react/src/utils/use-abstract-module-client.ts @@ -50,6 +50,7 @@ export type UseAbstractModuleClientParameters< TModule extends AbstractModuleClientConstructor, > = { accountId: AccountId | undefined + chainName: string | undefined moduleId: string Module: TModule query?: UseQueryParameters< @@ -71,6 +72,7 @@ export function useAbstractModuleClient< >({ moduleId, accountId, + chainName, Module, query = {}, }: UseAbstractModuleClientParameters) { @@ -80,7 +82,7 @@ export function useAbstractModuleClient< isError: isAbstractClientError, error: abstractClientError, } = useAbstractClient({ - chainName: accountId?.chainName, + chainName, query: { enabled: query.enabled ?? true }, }) diff --git a/packages/react/src/utils/use-abstract-module-query-client.ts b/packages/react/src/utils/use-abstract-module-query-client.ts index 912261f8..d7ad0b0d 100644 --- a/packages/react/src/utils/use-abstract-module-query-client.ts +++ b/packages/react/src/utils/use-abstract-module-query-client.ts @@ -66,6 +66,7 @@ export type UseAbstractModuleQueryClientParameters< TModule extends AbstractModuleQueryClientConstructor, > = { accountId: AccountId | undefined + chainName: string | undefined moduleId: string Module: TModule query?: UseQueryParameters< @@ -80,6 +81,7 @@ export function useAbstractModuleQueryClient< TModule extends AbstractModuleQueryClientConstructor, >({ accountId, + chainName, moduleId, Module, query = {}, @@ -92,7 +94,7 @@ export function useAbstractModuleQueryClient< isError: isAbstractClientError, error: abstractClientError, } = useAbstractQueryClient({ - chainName: accountId?.chainName, + chainName, query: { enabled: query.enabled ?? true }, }) diff --git a/packages/react/src/utils/use-abstract-query-client.ts b/packages/react/src/utils/use-abstract-query-client.ts index ff663c2f..424b0df8 100644 --- a/packages/react/src/utils/use-abstract-query-client.ts +++ b/packages/react/src/utils/use-abstract-query-client.ts @@ -40,25 +40,27 @@ async function getAbstractQueryClient({ ) } -export type UseAbstractQueryClientParameters = { - chainName?: string | undefined - query?: UseQueryParameters< - AbstractQueryClient | undefined, - unknown, - AbstractQueryClient | undefined, - readonly [ - 'abstract-query-client', - string | undefined, - string, - CosmWasmClient | undefined, - ] - > -} +export type UseAbstractQueryClientParameters = + | { + chainName?: string | undefined + query?: UseQueryParameters< + AbstractQueryClient | undefined, + unknown, + AbstractQueryClient | undefined, + readonly [ + 'abstract-query-client', + string | undefined, + string, + CosmWasmClient | undefined, + ] + > + } + | never -export function useAbstractQueryClient({ - chainName, - query = {}, -}: UseAbstractQueryClientParameters) { +export function useAbstractQueryClient( + parameters: UseAbstractQueryClientParameters, +) { + const { chainName, query = {} } = parameters ?? {} const { apiUrl } = useConfig() const { From 12f463b48e255de901346a99783c43e0b07105f2 Mon Sep 17 00:00:00 2001 From: hotwater Date: Mon, 18 Mar 2024 19:44:43 +0200 Subject: [PATCH 4/4] nit: types fix --- .../react/src/utils/use-abstract-client.ts | 32 +++++++++---------- .../src/utils/use-abstract-query-client.ts | 30 ++++++++--------- 2 files changed, 29 insertions(+), 33 deletions(-) diff --git a/packages/react/src/utils/use-abstract-client.ts b/packages/react/src/utils/use-abstract-client.ts index f0157f5a..3332c8ff 100644 --- a/packages/react/src/utils/use-abstract-client.ts +++ b/packages/react/src/utils/use-abstract-client.ts @@ -43,23 +43,21 @@ export async function getAbstractClient({ ) } -export type UseAbstractClientParameters = - | { - chainName?: string | undefined - query?: UseQueryParameters< - AbstractClient | undefined, - unknown, - AbstractClient | undefined, - readonly [ - 'abstract-client', - string | undefined, - string | undefined, - string, - SigningCosmWasmClient | undefined, - ] - > - } - | never +export type UseAbstractClientParameters = { + chainName: string | undefined + query?: UseQueryParameters< + AbstractClient | undefined, + unknown, + AbstractClient | undefined, + readonly [ + 'abstract-client', + string | undefined, + string | undefined, + string, + SigningCosmWasmClient | undefined, + ] + > +} export function useAbstractClient(parameters: UseAbstractClientParameters) { const { chainName, query = {} } = parameters ?? {} diff --git a/packages/react/src/utils/use-abstract-query-client.ts b/packages/react/src/utils/use-abstract-query-client.ts index 424b0df8..74b656c8 100644 --- a/packages/react/src/utils/use-abstract-query-client.ts +++ b/packages/react/src/utils/use-abstract-query-client.ts @@ -40,22 +40,20 @@ async function getAbstractQueryClient({ ) } -export type UseAbstractQueryClientParameters = - | { - chainName?: string | undefined - query?: UseQueryParameters< - AbstractQueryClient | undefined, - unknown, - AbstractQueryClient | undefined, - readonly [ - 'abstract-query-client', - string | undefined, - string, - CosmWasmClient | undefined, - ] - > - } - | never +export type UseAbstractQueryClientParameters = { + chainName: string | undefined + query?: UseQueryParameters< + AbstractQueryClient | undefined, + unknown, + AbstractQueryClient | undefined, + readonly [ + 'abstract-query-client', + string | undefined, + string, + CosmWasmClient | undefined, + ] + > +} export function useAbstractQueryClient( parameters: UseAbstractQueryClientParameters,