Skip to content

Commit

Permalink
fix: wait for transaciton and refetch stakes
Browse files Browse the repository at this point in the history
  • Loading branch information
VmMad committed Dec 5, 2024
1 parent 8467b96 commit 746134a
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions apps/wallet-dashboard/app/(protected)/staking/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,18 @@ import {
StakedCard,
useFormatCoin,
} from '@iota/core';
import { useCurrentAccount, useIotaClientQuery } from '@iota/dapp-kit';
import { useCurrentAccount, useIotaClient, useIotaClientQuery } from '@iota/dapp-kit';
import { IotaSystemStateSummary } from '@iota/iota-sdk/client';
import { Info } from '@iota/ui-icons';
import { useMemo } from 'react';
import { useStakeDialog } from '@/components/Dialogs/Staking/hooks/useStakeDialog';
import { IOTA_TYPE_ARG } from '@iota/iota-sdk/utils';

function StakingDashboardPage(): JSX.Element {
function StakingDashboardPage(): React.JSX.Element {
const account = useCurrentAccount();
const { data: system } = useIotaClientQuery('getLatestIotaSystemState');
const activeValidators = (system as IotaSystemStateSummary)?.activeValidators;
const iotaClient = useIotaClient();

const {
isDialogStakeOpen,
Expand All @@ -52,7 +53,7 @@ function StakingDashboardPage(): JSX.Element {
handleNewStake,
} = useStakeDialog();

const { data: delegatedStakeData } = useGetDelegatedStake({
const { data: delegatedStakeData, refetch: refetchDelegatedStakes } = useGetDelegatedStake({
address: account?.address || '',
staleTime: DELEGATED_STAKES_QUERY_STALE_TIME,
refetchInterval: DELEGATED_STAKES_QUERY_REFETCH_INTERVAL,
Expand Down Expand Up @@ -91,6 +92,14 @@ function StakingDashboardPage(): JSX.Element {
setSelectedStake(extendedStake);
};

function handleOnStakeSuccess(digest: string): void {
iotaClient
.waitForTransaction({
digest,
})
.then(() => refetchDelegatedStakes());
}

return (
<div className="flex justify-center">
<div className="w-3/4">
Expand Down Expand Up @@ -164,6 +173,7 @@ function StakingDashboardPage(): JSX.Element {
</div>
<StakeDialog
stakedDetails={selectedStake}
onSuccess={handleOnStakeSuccess}
isOpen={isDialogStakeOpen}
handleClose={handleCloseStakeDialog}
view={stakeDialogView}
Expand Down

0 comments on commit 746134a

Please sign in to comment.