1- import { FC , useEffect } from "react" ;
1+ import { FC , useEffect , useState } from "react" ;
22import { Trans , useTranslation } from "react-i18next" ;
33import { Box , CircularProgress } from "@mui/material" ;
44
@@ -15,11 +15,12 @@ import {
1515import { DataActionsBar , EmptyStateDrepDirectory } from "@molecules" ;
1616import { AutomatedVotingOptions , DRepCard } from "@organisms" ;
1717import { correctAdaFormat , isSameDRep } from "@utils" ;
18- import { DRepListSort , DRepStatus } from "@models" ;
18+ import { DRepData , DRepListSort , DRepStatus } from "@models" ;
1919import {
2020 AutomatedVotingOptionCurrentDelegation ,
2121 AutomatedVotingOptionDelegationId ,
2222} from "@/types/automatedVotingOptions" ;
23+ import usePrevious from "@/hooks/usePrevious" ;
2324
2425interface DRepDirectoryContentProps {
2526 isConnected ?: boolean ;
@@ -48,6 +49,9 @@ export const DRepDirectoryContent: FC<DRepDirectoryContentProps> = ({
4849 const { chosenFilters, chosenSorting, setChosenSorting } =
4950 dataActionsBarProps ;
5051
52+ const [ inProgressDelegationDRepData , setInProgressDelegationDRepData ] =
53+ useState < DRepData | undefined > ( undefined ) ;
54+
5155 useEffect ( ( ) => {
5256 if ( ! chosenSorting ) setChosenSorting ( DRepListSort . Random ) ;
5357 } , [ chosenSorting , setChosenSorting ] ) ;
@@ -57,6 +61,7 @@ export const DRepDirectoryContent: FC<DRepDirectoryContentProps> = ({
5761 const { votingPower } = useGetAdaHolderVotingPowerQuery ( stakeKey ) ;
5862 const { currentDelegation } = useGetAdaHolderCurrentDelegationQuery ( stakeKey ) ;
5963 const inProgressDelegation = pendingTransaction . delegate ?. resourceId ;
64+ const prevInProgressDelegation = usePrevious ( inProgressDelegation ) ;
6065
6166 const { dRep : myDrep } = useGetDRepDetailsQuery ( currentDelegation ?. dRepView , {
6267 enabled : ! ! inProgressDelegation || ! ! currentDelegation ,
@@ -85,6 +90,12 @@ export const DRepDirectoryContent: FC<DRepDirectoryContentProps> = ({
8590 } ,
8691 ) ;
8792
93+ useEffect ( ( ) => {
94+ if ( ! inProgressDelegation && prevInProgressDelegation ) {
95+ setInProgressDelegationDRepData ( undefined ) ;
96+ }
97+ } , [ prevInProgressDelegation , inProgressDelegation ] ) ;
98+
8899 if (
89100 ( stakeKey && votingPower === undefined ) ||
90101 ! dRepList ||
@@ -103,12 +114,6 @@ export const DRepDirectoryContent: FC<DRepDirectoryContentProps> = ({
103114 ? [ yourselfDRep , ...listedDRepsWithoutYourself ]
104115 : listedDRepsWithoutYourself ;
105116
106- const inProgressDelegationDRepData = dRepListToDisplay . find (
107- ( dRep ) =>
108- dRep . drepId === inProgressDelegation ||
109- dRep . view === inProgressDelegation ,
110- ) ;
111-
112117 const isAnAutomatedVotingOptionChosen =
113118 currentDelegation ?. dRepView &&
114119 ( currentDelegation ?. dRepView ===
@@ -216,7 +221,10 @@ export const DRepDirectoryContent: FC<DRepDirectoryContentProps> = ({
216221 }
217222 isMe = { isSameDRep ( dRep , myDRepId ) }
218223 isMyDrep = { isSameDRep ( dRep , currentDelegation ?. dRepView ) }
219- onDelegate = { ( ) => delegate ( dRep . drepId ) }
224+ onDelegate = { ( ) => {
225+ setInProgressDelegationDRepData ( dRep ) ;
226+ delegate ( dRep . drepId ) ;
227+ } }
220228 />
221229 </ Box >
222230 ) ) }
0 commit comments