Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/invalidate admin queries #135

Merged
merged 3 commits into from
Jan 31, 2023
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
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