Skip to content

Commit

Permalink
Merge pull request #135 from alleslabs/fix/invalidate-admin-queries
Browse files Browse the repository at this point in the history
Fix/invalidate admin queries
  • Loading branch information
poomthiti committed Jan 31, 2023
2 parents 2dc251e + a191a4c commit 12c3f92
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Improvements

- [#135](https://github.com/alleslabs/celatone-frontend/pull/135) Invalidate queries after update/clear admin tx
- [#123](https://github.com/alleslabs/celatone-frontend/pull/123) Refactor tables to use custom components
- [#128](https://github.com/alleslabs/celatone-frontend/pull/128) Rewrite add to other list state and add default list to save to
- [#114](https://github.com/alleslabs/celatone-frontend/pull/114) Handle wallet connection cases in instantiate button
Expand Down
4 changes: 2 additions & 2 deletions src/lib/app-fns/tx/clearAdmin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface ClearAdminTxParams {
fee: StdFee;
memo?: string;
client: SigningCosmWasmClient;
onTxSucceed?: (txHash: string) => void;
onTxSucceed?: () => void;
}

export const clearAdminTx = ({
Expand All @@ -40,7 +40,7 @@ export const clearAdminTx = ({
postFn: () => client.clearAdmin(address, contractAddress, fee, memo),
}),
({ value: txInfo }) => {
onTxSucceed?.(txInfo.transactionHash);
onTxSucceed?.();
return {
value: null,
phase: TxStreamPhase.SUCCEED,
Expand Down
18 changes: 15 additions & 3 deletions src/lib/app-provider/tx/clearAdmin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useWallet } from "@cosmos-kit/react";
import { useQueryClient } from "@tanstack/react-query";
import { useCallback } from "react";

import { useFabricateFee } from "../hooks";
Expand All @@ -7,11 +8,12 @@ import { CLEAR_ADMIN_GAS } from "lib/data";
import type { ContractAddr } from "lib/types";

export interface ClearAdminStreamParams {
onTxSucceed?: (txHash: string) => void;
onTxSucceed?: () => void;
}

export const useClearAdminTx = (contractAddress: ContractAddr) => {
const { address, getCosmWasmClient } = useWallet();
const queryClient = useQueryClient();
const fabricateFee = useFabricateFee();
const clearAdminFee = fabricateFee(CLEAR_ADMIN_GAS);

Expand All @@ -26,9 +28,19 @@ export const useClearAdminTx = (contractAddress: ContractAddr) => {
contractAddress,
fee: clearAdminFee,
client,
onTxSucceed,
onTxSucceed: () => {
onTxSucceed?.();
Promise.all([
queryClient.invalidateQueries({
queryKey: ["admin_by_contracts"],
}),
queryClient.invalidateQueries({
queryKey: ["query", "instantiate_info"],
}),
]);
},
});
},
[address, clearAdminFee, contractAddress, getCosmWasmClient]
[address, clearAdminFee, queryClient, contractAddress, getCosmWasmClient]
);
};
2 changes: 1 addition & 1 deletion src/lib/components/ContractSelectSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export const ContractSelectSection = observer(
});

const { refetch } = useQuery(
["query", "instantiateInfo", endpoint, contractAddress],
["query", "instantiate_info", endpoint, contractAddress],
async () =>
queryInstantiateInfo(endpoint, indexerGraphClient, contractAddress),
{
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/modal/contract/ClearAdminContract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const ClearAdminContract = ({
const clearAdminTx = useClearAdminTx(contractAddress);

const proceed = useCallback(async () => {
const stream = await clearAdminTx({ onTxSucceed: () => {} });
const stream = await clearAdminTx({});
if (stream) broadcast(stream);
}, [broadcast, clearAdminTx]);

Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/modal/contract/SaveNewContract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export function SaveNewContract({ list, buttonProps }: SaveNewContractProps) {

// TODO: Abstract query
const { refetch } = useQuery(
["query", "instantiateInfo", endpoint, contractAddressState],
["query", "instantiate_info", endpoint, contractAddressState],
async () =>
queryInstantiateInfo(
endpoint,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/model/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export const useContractData = (
const { data: publicInfoBySlug } = usePublicProjectBySlug(publicInfo?.slug);

const { data: instantiateInfo } = useQuery(
["query", "instantiateInfo", endpoint, contractAddress],
["query", "instantiate_info", endpoint, contractAddress],
async () =>
queryInstantiateInfo(endpoint, indexerGraphClient, contractAddress),
{ enabled: !!currentChainRecord }
Expand Down
2 changes: 1 addition & 1 deletion src/lib/pages/admin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const UpdateAdmin = () => {
* @remarks Contract admin validation
*/
useQuery(
["query", "instantiateInfo", endpoint, contractAddressParam],
["query", "instantiate_info", endpoint, contractAddressParam],
async () =>
queryInstantiateInfo(endpoint, indexerGraphClient, contractAddressParam),
{
Expand Down
2 changes: 1 addition & 1 deletion src/lib/pages/migrate/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const Migrate = () => {
);

useQuery(
["query", "instantiateInfo", endpoint, contractAddress],
["query", "instantiate_info", endpoint, contractAddress],
async () =>
queryInstantiateInfo(endpoint, indexerGraphClient, contractAddress),
{
Expand Down

2 comments on commit 12c3f92

@vercel
Copy link

@vercel vercel bot commented on 12c3f92 Jan 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 12c3f92 Jan 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.