Skip to content

Commit

Permalink
[#918] Fixes after CR
Browse files Browse the repository at this point in the history
  • Loading branch information
JanJaroszczak committed May 9, 2024
1 parent caa8bb0 commit 83e7798
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import { PendingTransaction } from "@context";
import { useTranslation } from "@hooks";
import { AutomatedVotingCard } from "@molecules";
import { openInNewTab } from "@/utils";
import {
AutomatedVotingOptionCurrentDelegation,
AutomatedVotingOptionDelegationId,
} from "@/types/automatedVotingOptions";

type AutomatedVotingOptionsProps = {
currentDelegation?: string | null;
Expand Down Expand Up @@ -41,12 +45,16 @@ export const AutomatedVotingOptions = ({
// TODO: Change to certain automated voted option if available
const onClickInfo = () => openInNewTab("https://docs.sanchogov.tools/");

const isDelegatedToAbstain = currentDelegation === "drep_always_abstain";
const isDelegationToAbstainInProgress = delegationInProgress === "abstain";
const isDelegatedToAbstain =
currentDelegation ===
AutomatedVotingOptionCurrentDelegation.drep_always_abstain;
const isDelegationToAbstainInProgress =
delegationInProgress === AutomatedVotingOptionDelegationId.abstain;
const isDelegatedToNoConfidence =
currentDelegation === "drep_always_no_confidence";
currentDelegation ===
AutomatedVotingOptionCurrentDelegation.drep_always_no_confidence;
const isDelegationToNoConfidenceInProgress =
delegationInProgress === "no confidence";
delegationInProgress === AutomatedVotingOptionDelegationId.no_confidence;

useEffect(() => {
const shouldBeSetOpen =
Expand Down Expand Up @@ -98,7 +106,9 @@ export const AutomatedVotingOptions = ({
isConnected={isConnected}
isDelegateLoading={isDelegationLoading}
isSelected={isDelegatedToAbstain}
onClickDelegate={() => delegate("abstain")}
onClickDelegate={() =>
delegate(AutomatedVotingOptionDelegationId.abstain)
}
onClickInfo={onClickInfo}
title={
isDelegatedToAbstain
Expand All @@ -109,7 +119,8 @@ export const AutomatedVotingOptions = ({
}
votingPower={votingPower}
transactionId={
pendingTransaction?.delegate?.resourceId === "abstain"
pendingTransaction?.delegate?.resourceId ===
AutomatedVotingOptionDelegationId.abstain
? pendingTransaction?.delegate?.transactionHash
: isDelegatedToAbstain
? txHash
Expand All @@ -126,7 +137,9 @@ export const AutomatedVotingOptions = ({
isConnected={isConnected}
isDelegateLoading={isDelegationLoading}
isSelected={isDelegatedToNoConfidence}
onClickDelegate={() => delegate("no confidence")}
onClickDelegate={() =>
delegate(AutomatedVotingOptionDelegationId.no_confidence)
}
onClickInfo={onClickInfo}
title={
isDelegatedToNoConfidence
Expand All @@ -137,7 +150,8 @@ export const AutomatedVotingOptions = ({
}
votingPower={votingPower}
transactionId={
pendingTransaction?.delegate?.resourceId === "no confidence"
pendingTransaction?.delegate?.resourceId ===
AutomatedVotingOptionDelegationId.no_confidence
? pendingTransaction?.delegate?.transactionHash
: isDelegatedToNoConfidence
? txHash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import {
DelegationAction,
} from "@molecules";
import { correctAdaFormat, formHexToBech32, openInNewTab } from "@utils";
import {
AutomatedVotingOptionCurrentDelegation,
AutomatedVotingOptionDelegationId,
} from "@/types/automatedVotingOptions";

type DelegateDashboardCardProps = {
currentDelegation: CurrentDelegation;
Expand Down Expand Up @@ -129,9 +133,11 @@ export const DelegateDashboardCard = ({

const getDelegationTitle = (currentDelegation: string | null, ada: number) => {
const key =
currentDelegation === "drep_always_no_confidence"
currentDelegation ===
AutomatedVotingOptionCurrentDelegation.drep_always_no_confidence
? "dashboard.cards.delegation.noConfidenceDelegationTitle"
: currentDelegation === "drep_always_abstain"
: currentDelegation ===
AutomatedVotingOptionCurrentDelegation.drep_always_abstain
? "dashboard.cards.delegation.abstainDelegationTitle"
: "dashboard.cards.delegation.dRepDelegationTitle";

Expand All @@ -140,9 +146,11 @@ const getDelegationTitle = (currentDelegation: string | null, ada: number) => {

const getDelegationDescription = (currentDelegation: string | null) => {
const key =
currentDelegation === "drep_always_no_confidence"
currentDelegation ===
AutomatedVotingOptionCurrentDelegation.drep_always_no_confidence
? "dashboard.cards.delegation.noDescription"
: currentDelegation === "drep_always_abstain"
: currentDelegation ===
AutomatedVotingOptionCurrentDelegation.drep_always_abstain
? "dashboard.cards.delegation.abstainDescription"
: undefined;
return <Trans i18nKey={key} />;
Expand All @@ -152,9 +160,9 @@ const getProgressDescription = (delegateTo: string, ada: number) => {
const key = (() => {
if (!delegateTo) return undefined;
switch (delegateTo) {
case "no confidence":
case AutomatedVotingOptionDelegationId.no_confidence:
return "dashboard.cards.delegation.inProgress.no";
case "abstain":
case AutomatedVotingOptionDelegationId.abstain:
return "dashboard.cards.delegation.inProgress.abstain";
default:
return "dashboard.cards.delegation.inProgress.dRep";
Expand All @@ -174,10 +182,10 @@ const getDisplayedDelegationId = ({
}) => {
const restrictedNames = [
dRepID,
"drep_always_abstain",
"drep_always_no_confidence",
"abstain",
"no confidence",
AutomatedVotingOptionCurrentDelegation.drep_always_abstain,
AutomatedVotingOptionCurrentDelegation.drep_always_no_confidence,
AutomatedVotingOptionDelegationId.abstain,
AutomatedVotingOptionDelegationId.no_confidence,
];
if (delegateTo) {
if (!restrictedNames.includes(delegateTo)) {
Expand Down
15 changes: 12 additions & 3 deletions govtool/frontend/src/context/pendingTransaction/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { QueryClient, QueryKey } from "react-query";
import { QUERY_KEYS } from "@/consts";
import { TransactionType, TransactionState } from "./types";
import {
AutomatedVotingOptionCurrentDelegation,
AutomatedVotingOptionDelegationId,
} from "@/types/automatedVotingOptions";

export const getDesiredResult = (
type: TransactionType,
Expand All @@ -9,8 +13,10 @@ export const getDesiredResult = (
switch (type) {
case "delegate": {
// current delegation
if (resourceId === "no confidence") return "drep_always_no_confidence";
if (resourceId === "abstain") return "drep_always_abstain";
if (resourceId === AutomatedVotingOptionDelegationId.no_confidence)
return AutomatedVotingOptionCurrentDelegation.drep_always_no_confidence;
if (resourceId === AutomatedVotingOptionDelegationId.abstain)
return AutomatedVotingOptionCurrentDelegation.drep_always_abstain;
return resourceId;
}
case "registerAsDrep":
Expand Down Expand Up @@ -60,7 +66,10 @@ export const refetchData = async (
const data = await queryClient.getQueryData<any>(queryKey);

if (type === "delegate") {
if (resourceId === "no confidence" || resourceId === "abstain") {
if (
resourceId === AutomatedVotingOptionDelegationId.no_confidence ||
resourceId === AutomatedVotingOptionDelegationId.abstain
) {
return data.dRepView;
}
return data.dRepHash;
Expand Down
5 changes: 3 additions & 2 deletions govtool/frontend/src/context/wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import {
TransactionStateWithoutResource,
usePendingTransaction,
} from "./pendingTransaction";
import { AutomatedVotingOptionDelegationId } from "@/types/automatedVotingOptions";

interface Props {
children: React.ReactNode;
Expand Down Expand Up @@ -585,9 +586,9 @@ const CardanoProvider = (props: Props) => {

// Create correct DRep
let targetDRep;
if (target === "abstain") {
if (target === AutomatedVotingOptionDelegationId.abstain) {
targetDRep = DRep.new_always_abstain();
} else if (target === "no confidence") {
} else if (target === AutomatedVotingOptionDelegationId.no_confidence) {
targetDRep = DRep.new_always_no_confidence();
} else if (target.includes("drep")) {
targetDRep = DRep.new_key_hash(Ed25519KeyHash.from_bech32(target));
Expand Down
17 changes: 13 additions & 4 deletions govtool/frontend/src/pages/DRepDirectoryContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import { Card, DataActionsBar } from "@molecules";
import { AutomatedVotingOptions, DRepCard } from "@organisms";
import { correctAdaFormat, formHexToBech32, isSameDRep } from "@utils";
import { DRepListSort, DRepStatus } from "@models";
import {
AutomatedVotingOptionCurrentDelegation,
AutomatedVotingOptionDelegationId,
} from "@/types/automatedVotingOptions";

interface DRepDirectoryContentProps {
isConnected?: boolean;
Expand Down Expand Up @@ -95,11 +99,13 @@ export const DRepDirectoryContent: FC<DRepDirectoryContentProps> = ({
const dRepListToDisplay = yourselfDRep
? [yourselfDRep, ...dRepsWithoutYourself]
: dRepList;

const isAnAutomatedOptionChosen =
currentDelegation?.dRepView &&
["drep_always_abstain", "drep_always_no_confidence"].includes(
currentDelegation?.dRepView,
);
(currentDelegation?.dRepView ===
AutomatedVotingOptionCurrentDelegation.drep_always_abstain ||
currentDelegation?.dRepView ===
AutomatedVotingOptionCurrentDelegation.drep_always_no_confidence);

return (
<Box display="flex" flex={1} flexDirection="column" gap={4}>
Expand Down Expand Up @@ -133,7 +139,10 @@ export const DRepDirectoryContent: FC<DRepDirectoryContentProps> = ({
delegate={delegate}
delegationInProgress={
inProgressDelegation &&
["abstain", "no confidence"].includes(inProgressDelegation)
(inProgressDelegation ===
AutomatedVotingOptionDelegationId.abstain ||
inProgressDelegation ===
AutomatedVotingOptionDelegationId.no_confidence)
? inProgressDelegation
: undefined
}
Expand Down
9 changes: 9 additions & 0 deletions govtool/frontend/src/types/automatedVotingOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export enum AutomatedVotingOptionCurrentDelegation {
drep_always_abstain = "drep_always_abstain",
drep_always_no_confidence = "drep_always_no_confidence",
}

export enum AutomatedVotingOptionDelegationId {
abstain = "abstain",
no_confidence = "no_confidence",
}

0 comments on commit 83e7798

Please sign in to comment.