Skip to content

Commit

Permalink
delete delegation for direct voter
Browse files Browse the repository at this point in the history
  • Loading branch information
Sworzen1 authored and MSzalowski committed Jun 7, 2024
1 parent 204ae85 commit 85998b9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ export const DelegateDashboardCard = ({

const cardProps: Partial<DashboardActionCardProps> = (() => {
// transaction in progress
if (delegateTx && !voter.isRegisteredAsSoleVoter) {
if (
delegateTx &&
(!(delegateTx?.resourceId === dRepID) || voter?.isRegisteredAsDRep)
) {
return {
buttons: [learnMoreButton],
description: getProgressDescription(delegateTx?.resourceId, ada),
Expand All @@ -68,7 +71,10 @@ export const DelegateDashboardCard = ({
}

// current delegation
if (currentDelegation && !voter.isRegisteredAsSoleVoter) {
if (
currentDelegation &&
(!(currentDelegation?.dRepHash === dRepID) || voter?.isRegisteredAsDRep)
) {
return {
buttons: currentDelegation?.dRepView
? [
Expand Down Expand Up @@ -119,22 +125,25 @@ export const DelegateDashboardCard = ({
<DashboardActionCard
imageURL={IMAGES.govActionDelegateImage}
isSpaceBetweenButtons={
!!currentDelegation?.dRepView && !voter.isRegisteredAsSoleVoter
!!currentDelegation?.dRepView &&
(!(currentDelegation?.dRepHash === dRepID) || voter?.isRegisteredAsDRep)
}
transactionId={
!voter.isRegisteredAsSoleVoter
!(currentDelegation?.dRepHash === dRepID) || voter?.isRegisteredAsDRep
? delegateTx?.transactionHash ?? currentDelegation?.txHash
: undefined
}
{...cardProps}
>
{displayedDelegationId && !voter.isRegisteredAsSoleVoter && (
<DelegationAction
dRepId={displayedDelegationId}
onCardClick={navigateToDRepDetails}
sx={{ mt: 1.5 }}
/>
)}
{displayedDelegationId &&
(!(currentDelegation?.dRepHash === dRepID) ||
voter?.isRegisteredAsDRep) && (
<DelegationAction
dRepId={displayedDelegationId}
onCardClick={navigateToDRepDetails}
sx={{ mt: 1.5 }}
/>
)}
</DashboardActionCard>
);
};
Expand Down
31 changes: 18 additions & 13 deletions govtool/frontend/src/pages/DRepDirectoryContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
useGetAdaHolderCurrentDelegationQuery,
useGetAdaHolderVotingPowerQuery,
useGetDRepListInfiniteQuery,
useGetVoterInfo,
} from "@hooks";
import { DataActionsBar, EmptyStateDrepDirectory } from "@molecules";
import { AutomatedVotingOptions, DRepCard } from "@organisms";
Expand Down Expand Up @@ -48,6 +49,7 @@ export const DRepDirectoryContent: FC<DRepDirectoryContentProps> = ({

const { delegate, isDelegating } = useDelegateTodRep();

const { voter } = useGetVoterInfo();
const { votingPower } = useGetAdaHolderVotingPowerQuery(stakeKey);
const { currentDelegation } = useGetAdaHolderCurrentDelegationQuery(stakeKey);
const inProgressDelegation = pendingTransaction.delegate?.resourceId;
Expand Down Expand Up @@ -118,19 +120,22 @@ export const DRepDirectoryContent: FC<DRepDirectoryContentProps> = ({
return (
<Box display="flex" flex={1} flexDirection="column" gap={4}>
{/* My delegation */}
{myDrep && !inProgressDelegation && (
<div>
<Typography variant="title2" sx={{ mb: 2 }}>
<Trans i18nKey="dRepDirectory.myDelegation" values={{ ada }} />
</Typography>
<DRepCard
dRep={myDrep}
isConnected={!!isConnected}
isInProgress={isSameDRep(myDrep, inProgressDelegation)}
isMe={isSameDRep(myDrep, myDRepId)}
/>
</div>
)}
{myDrep &&
!inProgressDelegation &&
(!(currentDelegation?.dRepHash === myDRepId) ||
voter?.isRegisteredAsDRep) && (
<div>
<Typography variant="title2" sx={{ mb: 2 }}>
<Trans i18nKey="dRepDirectory.myDelegation" values={{ ada }} />
</Typography>
<DRepCard
dRep={myDrep}
isConnected={!!isConnected}
isInProgress={isSameDRep(myDrep, inProgressDelegation)}
isMe={isSameDRep(myDrep, myDRepId)}
/>
</div>
)}
{inProgressDelegation && inProgressDelegationDRepData && (
<DRepCard
dRep={inProgressDelegationDRepData}
Expand Down

0 comments on commit 85998b9

Please sign in to comment.