Skip to content

Commit

Permalink
fix: refetch all token factory data on success (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
chalabi2 authored Nov 26, 2024
1 parent b3904e3 commit 86d57e6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
2 changes: 0 additions & 2 deletions components/factory/components/MyDenoms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ import { usePoaGetAdmin } from '@/hooks';
export default function MyDenoms({
denoms,
isLoading,
isError,
refetchDenoms,
address,
}: {
denoms: ExtendedMetadataSDKType[];
isLoading: boolean;
isError: Error | null | boolean;
refetchDenoms: () => void;
address: string;
}) {
Expand Down
27 changes: 19 additions & 8 deletions pages/factory/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,28 @@ import { MFX_TOKEN_DATA } from '@/utils/constants';

export default function Factory() {
const { address, isWalletConnected } = useChain(chainName);
const { denoms, isDenomsLoading, isDenomsError } = useTokenFactoryDenoms(address ?? '');
const { metadatas, isMetadatasLoading, isMetadatasError } = useTokenFactoryDenomsMetadata();
const { balances, isBalancesLoading, isBalancesError } = useTokenBalances(address ?? '');
const { totalSupply, isTotalSupplyLoading, isTotalSupplyError } = useTotalSupply();
const { denoms, isDenomsLoading, isDenomsError, refetchDenoms } = useTokenFactoryDenoms(
address ?? ''
);
const { metadatas, isMetadatasLoading, isMetadatasError, refetchMetadatas } =
useTokenFactoryDenomsMetadata();
const { balances, isBalancesLoading, isBalancesError, refetchBalances } = useTokenBalances(
address ?? ''
);
const { totalSupply, isTotalSupplyLoading, isTotalSupplyError, refetchTotalSupply } =
useTotalSupply();

const isLoading =
isDenomsLoading || isMetadatasLoading || isBalancesLoading || isTotalSupplyLoading;
const isError = isDenomsError || isMetadatasError || isBalancesError || isTotalSupplyError;

const refetchData = () => {
refetchDenoms();
refetchMetadatas();
refetchBalances();
refetchTotalSupply();
};

const combinedData = useMemo(() => {
if (denoms?.denoms && metadatas?.metadatas && balances && totalSupply) {
const mfxBalance = balances.find(bal => bal.denom === 'umfx')?.amount || '0';
Expand Down Expand Up @@ -117,8 +130,7 @@ export default function Factory() {
<MyDenoms
denoms={combinedData}
isLoading={isLoading}
isError={isError}
refetchDenoms={() => {}}
refetchDenoms={refetchData}
address={address ?? ''}
/>
) : isError ? (
Expand All @@ -131,8 +143,7 @@ export default function Factory() {
<MyDenoms
denoms={combinedData}
isLoading={isLoading}
isError={isError}
refetchDenoms={() => {}}
refetchDenoms={refetchData}
address={address ?? ''}
/>
)}
Expand Down

0 comments on commit 86d57e6

Please sign in to comment.