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/1257-dashboard-shows-delegation-in-two-places-should-be-one-after-becoming-a-drep #1262

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
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ export const DelegateDashboardCard = ({
currentDelegation,
delegateTx,
dRepID,
voter,
votingPower,
}: DelegateDashboardCardProps) => {
const navigate = useNavigate();
const { t } = useTranslation();

const { dRepData, isDRepListFetching } = useGetDRepListInfiniteQuery(
{
searchPhrase: currentDelegation?.dRepHash ?? delegateTx?.resourceId ?? "",
searchPhrase: delegateTx?.resourceId ?? currentDelegation?.dRepHash ?? "",
},
{
enabled: !!currentDelegation?.dRepHash || !!delegateTx?.resourceId,
Expand Down Expand Up @@ -73,10 +73,7 @@ export const DelegateDashboardCard = ({

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

// current delegation
if (
!delegateTx &&
currentDelegation &&
(!(currentDelegation?.dRepHash === dRepID) || voter?.isRegisteredAsDRep)
currentDelegation?.dRepHash !== dRepID
) {
return {
buttons: currentDelegation?.dRepView
Expand Down Expand Up @@ -141,36 +139,38 @@ export const DelegateDashboardCard = ({
imageURL={IMAGES.govActionDelegateImage}
isSpaceBetweenButtons={
!!currentDelegation?.dRepView &&
(!(currentDelegation?.dRepHash === dRepID) || voter?.isRegisteredAsDRep)
!(currentDelegation?.dRepHash === dRepID)
}
transactionId={
!(currentDelegation?.dRepHash === dRepID) ||
voter?.isRegisteredAsDRep ||
!voter?.isRegisteredAsSoleVoter
(delegateTx && delegateTx?.resourceId !== dRepID) ||
(!delegateTx &&
currentDelegation &&
currentDelegation?.dRepHash !== dRepID)
? delegateTx?.transactionHash ?? currentDelegation?.txHash
: undefined
}
{...cardProps}
>
{displayedDelegationId &&
(!(currentDelegation?.dRepHash === dRepID) ||
voter?.isRegisteredAsDRep ||
!voter?.isRegisteredAsSoleVoter) && (
<DelegationAction
drepName={
isDRepListFetching
? "Loading..."
: myDRepDelegationData?.metadataStatus
? getMetadataDataMissingStatusTranslation(
myDRepDelegationData.metadataStatus,
)
: myDRepDelegationData?.dRepName ?? ""
}
dRepId={displayedDelegationId}
onCardClick={navigateToDRepDetails}
sx={{ mt: 1.5 }}
/>
)}
((delegateTx && delegateTx?.resourceId !== dRepID) ||
(!delegateTx &&
currentDelegation &&
currentDelegation?.dRepHash !== dRepID)) ? (
<DelegationAction
drepName={
isDRepListFetching
? "Loading..."
: myDRepDelegationData?.metadataStatus
? getMetadataDataMissingStatusTranslation(
myDRepDelegationData.metadataStatus,
)
: myDRepDelegationData?.dRepName ?? ""
}
dRepId={displayedDelegationId}
onCardClick={navigateToDRepDetails}
sx={{ mt: 1.5 }}
/>
) : null}
</DashboardActionCard>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const refetchData = async (
) {
return data.dRepView;
}
return data.dRepView;
return data.dRepHash;
}
if (type === "registerAsDrep" || type === "retireAsDrep")
return data.isRegisteredAsDRep;
Expand Down
2 changes: 1 addition & 1 deletion govtool/frontend/src/pages/DRepDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ export const DRepDetails = ({ isConnected }: DRepDetailsProps) => {
isLoading={
isDelegating === dRep.view || isDelegating === dRep.drepId
}
onClick={() => delegate(dRep.view)}
onClick={() => delegate(dRep.drepId)}
size="extraLarge"
sx={{ width: "100%" }}
variant="contained"
Expand Down
27 changes: 14 additions & 13 deletions govtool/frontend/src/pages/DRepDirectoryContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
useGetAdaHolderCurrentDelegationQuery,
useGetAdaHolderVotingPowerQuery,
useGetDRepListInfiniteQuery,
useGetVoterInfo,
} from "@hooks";
import { DataActionsBar, EmptyStateDrepDirectory } from "@molecules";
import { AutomatedVotingOptions, DRepCard } from "@organisms";
Expand Down Expand Up @@ -49,7 +48,6 @@ 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 @@ -106,6 +104,7 @@ export const DRepDirectoryContent: FC<DRepDirectoryContentProps> = ({
const dRepListToDisplay = yourselfDRep
? [yourselfDRep, ...dRepsWithoutYourself]
: dRepList;

const inProgressDelegationDRepData = dRepListToDisplay.find(
(dRep) =>
dRep.drepId === inProgressDelegation ||
Expand All @@ -124,8 +123,8 @@ export const DRepDirectoryContent: FC<DRepDirectoryContentProps> = ({
{/* My delegation */}
{myDrep &&
!inProgressDelegation &&
(!(currentDelegation?.dRepHash === myDRepId) ||
voter?.isRegisteredAsDRep) && (
currentDelegation &&
currentDelegation?.dRepHash !== myDRepId && (
<div>
<Typography variant="title2" sx={{ mb: 2 }}>
<Trans i18nKey="dRepDirectory.myDelegation" values={{ ada }} />
Expand All @@ -138,14 +137,16 @@ export const DRepDirectoryContent: FC<DRepDirectoryContentProps> = ({
/>
</div>
)}
{inProgressDelegation && inProgressDelegationDRepData && (
<DRepCard
dRep={inProgressDelegationDRepData}
isConnected={!!isConnected}
isMe={isSameDRep(inProgressDelegationDRepData, myDRepId)}
isInProgress
/>
)}
{inProgressDelegation &&
inProgressDelegation !== myDRepId &&
inProgressDelegationDRepData && (
<DRepCard
dRep={inProgressDelegationDRepData}
isConnected={!!isConnected}
isMe={isSameDRep(inProgressDelegationDRepData, myDRepId)}
isInProgress
/>
)}

{/* Automated voting options */}
{isConnected && (
Expand Down Expand Up @@ -223,7 +224,7 @@ export const DRepDirectoryContent: FC<DRepDirectoryContentProps> = ({
isDelegating === dRep.view || isDelegating === dRep.drepId
}
isMe={isSameDRep(dRep, myDRepId)}
onDelegate={() => delegate(dRep.view)}
onDelegate={() => delegate(dRep.drepId)}
/>
</Box>
);
Expand Down
Loading