Skip to content
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 @@ -2,11 +2,9 @@ import { Button, Stack, Typography, styled, useTheme } from '@mui/material';
import BigNumber from 'bignumber.js';
import { observer } from 'mobx-react';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { dRepNormalize } from '../../../api/ada/lib/cardanoCrypto/utils';
import LocalStorageApi from '../../../api/localStorage/index';
import globalMessages from '../../../i18n/global-messages';
import { ROUTES } from '../../../routes-config';
import { YOROI_DREP_ID } from '../../features/governace/common/constants';
import { IconWrapper, Icons } from '../icons';
import { Ilustration } from './Ilustration';

Expand Down Expand Up @@ -71,17 +69,14 @@ export const DrepPromotionBanner = observer(({ stores, onClose, intl }) => {

const [governanceInfo, setGovernanceInfo] = useState({
isParticipatingToGovernance: false,
isDelegatingToYoroiDrep: false,
});

useEffect(() => {
const getGovStatus = () => {
const govInfo = stores.delegation.governanceStatus?.drepDelegation;
if (govInfo) {
const isParticipatingToGovernance = govInfo !== null;
const drepEncoded = dRepNormalize(govInfo?.drep, govInfo?.drepKind);
const isDelegatingToYoroiDrep = isParticipatingToGovernance && drepEncoded === YOROI_DREP_ID;
setGovernanceInfo({ isParticipatingToGovernance, isDelegatingToYoroiDrep });
setGovernanceInfo({ isParticipatingToGovernance });
}
};

Expand Down Expand Up @@ -126,10 +121,7 @@ export const DrepPromotionBanner = observer(({ stores, onClose, intl }) => {
},
}}
onClick={() => {
stores.routing.goToRoute({
route: ROUTES.GOVERNANCE.ROOT,
query: { delegateToYoroiDrep: true },
});
stores.routing.goToRoute({ route: ROUTES.GOVERNANCE.ROOT });
}}
>
{intl.formatMessage(globalMessages.delegateVote)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,12 @@ import {

export const LEARN_MORE_LINK =
'https://help.yoroi-wallet.com/en/article/how-can-i-participate-in-governance-through-yoroi-155o8l3/ ';
export const YOROI_VOTING_RECORD_LINK =
'https://2025budget.intersectmbo.org/voters/drep1ygr9tuapcanc3kpeyy4dc3vmrz9cfe5q7v9wj3x9j0ap3tswtre9j';
export const FIND_DREPS_LINK = 'https://beta.cexplorer.io/drep?tab=list';
export const FIND_DREPS_LINK_TESTNET = 'https://preprod.cexplorer.io/drep';
export const YOROI_DREP_ID = 'drep1ygr9tuapcanc3kpeyy4dc3vmrz9cfe5q7v9wj3x9j0ap3tswtre9j';
export const YOROI_DREP_ID_TESTNET = 'drep1y23nc498g205wtvp9esysyxam0n7msusm5d734xqlzhvkgq3pn5r7';
export const EMURGO_DREP_ID = 'drep1ytvlwvyjmzfyn56n0zz4f6lj94wxhmsl5zky6knnzrf4jygpyahug';

export const DREP_ALWAYS_ABSTAIN = API_ABSTAIN;
export const DREP_ALWAYS_NO_CONFIDENCE = API_NO_CONFIDENCE;

export const drepNames = {
[YOROI_DREP_ID]: 'Yoroi W₳llet',
[EMURGO_DREP_ID]: 'EMURGO',
[YOROI_DREP_ID_TESTNET]: 'Testnet DRep',
};

export const GOVERNANCE_STATUS = {
IDLE: 'idle',
HOVER: 'hover',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { DREP_ALWAYS_ABSTAIN, DREP_ALWAYS_NO_CONFIDENCE, YOROI_DREP_ID, YOROI_DREP_ID_TESTNET } from '../../common/constants';
import { DREP_ALWAYS_ABSTAIN, DREP_ALWAYS_NO_CONFIDENCE } from '../../common/constants';
import { useGovernance } from '../../module/GovernanceContextProvider';

type UseGovernanceDelegationStatusParams = {
Expand All @@ -10,33 +10,27 @@ type UseGovernanceDelegationStatusParams = {
type UseGovernanceDelegationStatusResult = {
isAbstain: boolean;
isNoConfidence: boolean;
isDelegationToYoroiDrep: boolean;
isDelegationToOtherDrep: boolean;
isDelegationToDrep: boolean;
drepID: string;
};

export const useGovernanceDelegationStatus = ({
governanceStatus,
isDelegated,
}: UseGovernanceDelegationStatusParams): UseGovernanceDelegationStatusResult => {
const { isTestnet } = useGovernance();

return React.useMemo(() => {
const yoroiDrepId = isTestnet ? YOROI_DREP_ID_TESTNET : YOROI_DREP_ID;
const drepID = governanceStatus?.drep ? governanceStatus?.drep : yoroiDrepId;
const drepID = governanceStatus?.drep ?? null;

const isAbstain = isDelegated && governanceStatus?.drep === null && governanceStatus?.status === DREP_ALWAYS_ABSTAIN;
const isNoConfidence =
isDelegated && governanceStatus?.drep === null && governanceStatus?.status === DREP_ALWAYS_NO_CONFIDENCE;
const isDelegationToYoroiDrep = isDelegated && !(isAbstain || isNoConfidence) && drepID === yoroiDrepId;
const isDelegationToOtherDrep = isDelegated && !(isAbstain || isNoConfidence) && drepID !== yoroiDrepId;
const isDelegationToDrep = isDelegated && !(isAbstain || isNoConfidence) && drepID != null;

return {
isAbstain,
isNoConfidence,
isDelegationToYoroiDrep,
isDelegationToOtherDrep,
drepID,
isDelegationToDrep,
drepID: drepID ?? '',
};
}, [governanceStatus?.status, governanceStatus?.drep, isDelegated, isTestnet]);
}, [governanceStatus?.status, governanceStatus?.drep, isDelegated]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export const messages = Object.freeze(
},
chooseDelegationOption: {
id: 'governance.chooseDelegationOption',
defaultMessage: '!!!Choose to delegate your voting power to Yoroi DRep or explore other options',
defaultMessage: '!!!Your delegation to DReps helps shaping Cardano’s future. You may change your governance status at any time.',
},
exploreOtherDRepsOrAbstain: {
id: 'governance.exploreOtherDRepsOrAbstain',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useGovernance } from '../../module/GovernanceContextProvider';
import { useGovernanceDelegationToYoroiDrep } from '../../common/hooks/useGovernanceDelegationToYoroiDrep';
import { useGovernanceStatusState } from '../../common/hooks/useGovernanceStatusState';
import { useGovernanceDelegationStatus } from '../../common/hooks/useGovernanceDelegationStatus';
import { GOVERNANCE_STATUS, YOROI_DREP_ID, YOROI_DREP_ID_TESTNET, YOROI_VOTING_RECORD_LINK } from '../../common/constants';
import { GOVERNANCE_STATUS } from '../../common/constants';
import { OptionsSkeletonScreen } from '../../common/SkeletonCardLoaders';

interface DRepOptionsScreenProps {}
Expand All @@ -19,14 +19,14 @@ export const DRepOptions: React.FC<DRepOptionsScreenProps> = () => {
const strings = useStrings();
const theme: any = useTheme();

const { submitedTransactions, isTestnet } = useGovernance();
const { loadingUnsignTx, delegateToDrep, openDelegateModalForCustomDrep, delegateToAbstain, delegateToNoConfidence } =
const { submitedTransactions } = useGovernance();
const { loadingUnsignTx, openDelegateModalForCustomDrep, delegateToAbstain, delegateToNoConfidence } =
useGovernanceDelegationToYoroiDrep();
const isPendingDrepDelegationTx = submitedTransactions.length > 0 && submitedTransactions[0]?.isDrepDelegation === true;

const { governanceStatusState: cardState, governanceStatus } = useGovernanceStatusState();
const isDelegated = cardState === GOVERNANCE_STATUS.DELEGATED;
const { isAbstain, isNoConfidence, isDelegationToYoroiDrep, isDelegationToOtherDrep } = useGovernanceDelegationStatus({
const { isAbstain, isNoConfidence, isDelegationToDrep } = useGovernanceDelegationStatus({
governanceStatus,
isDelegated,
});
Expand All @@ -35,40 +35,23 @@ export const DRepOptions: React.FC<DRepOptionsScreenProps> = () => {
navigateTo.selectRevampStatus();
};

const drepYoroiId = isTestnet ? YOROI_DREP_ID_TESTNET : YOROI_DREP_ID;

const drepOptionsConfig = [
{
key: 'yoroi',
title: isTestnet ? strings.yoroiTestnetDRep : strings.yoroiDRep,
description: strings.yoroiDRepInfo,
buttonText: strings.delegateLabel,
variant: 'primary' as const,
icon: <Icon.YoroiLogo fill={theme.palette.ds.gray_min} />,
onAction: () => delegateToDrep(drepYoroiId),
onViewDetails: isTestnet ? undefined : () => window.open(YOROI_VOTING_RECORD_LINK, '_blank'),
status: cardState,
drepId: governanceStatus.drep,
isDelegated: isDelegationToYoroiDrep,
},
{
key: 'others',
title: strings.otherDReps,
description: strings.designatingSomeoneElse,
buttonText: isDelegationToOtherDrep ? strings.delegateToOtherDrep : strings.delegateLabel,
variant: 'outlined' as const,
title: strings.delegateToDRep,
description: strings.identifyDrep,
buttonText: isDelegationToDrep ? strings.changeToDrep : strings.delegateLabel,
icon: <Icon.VotingDrep />,
onAction: () => openDelegateModalForCustomDrep(),
status: cardState,
drepId: governanceStatus.drep,
isDelegated: isDelegationToOtherDrep,
isDelegated: isDelegationToDrep,
},
{
key: 'abstain',
title: strings.abstain,
description: strings.chooseAbstain,
buttonText: isAbstain ? strings.changeToDrep : strings.delegateLabel,
variant: 'outlined' as const,
icon: <Icon.VotingAbstain />,
onAction: () => (isAbstain ? openDelegateModalForCustomDrep() : delegateToAbstain()),
status: cardState,
Expand All @@ -80,7 +63,6 @@ export const DRepOptions: React.FC<DRepOptionsScreenProps> = () => {
title: strings.noConfidence,
description: strings.chooseNoConfidence,
buttonText: isNoConfidence ? strings.changeToDrep : strings.delegateLabel,
variant: 'outlined' as const,
icon: <Icon.VotingNoConfidence />,
onAction: () => (isNoConfidence ? openDelegateModalForCustomDrep() : delegateToNoConfidence()),
status: cardState,
Expand All @@ -101,7 +83,7 @@ export const DRepOptions: React.FC<DRepOptionsScreenProps> = () => {
<TitleSection>
<Typography variant="h5">{strings.chooseVotingPower}</Typography>
<Typography variant="body1" color="ds.text_gray_low">
{strings.letYoroiDRepVoteForYou}
{strings.chooseDelegationOption}
</Typography>
</TitleSection>

Expand All @@ -113,10 +95,8 @@ export const DRepOptions: React.FC<DRepOptionsScreenProps> = () => {
title={option.title}
description={option.description}
buttonText={option.buttonText}
variant={option.variant}
icon={option.icon}
onAction={option.onAction}
onViewDetails={option.onViewDetails}
status={option.status}
drepId={option.drepId}
isDelegated={option.isDelegated}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import { Box, Typography, Button, Stack, Link } from '@mui/material';
import { Box, Typography, Button } from '@mui/material';
import { styled } from '@mui/system';
import { useStrings } from '../../common/hooks/useStrings';
import { GOVERNANCE_STATUS, GovernanceStatusState } from '../../common/constants';
import { LoadingButton } from '@mui/lab';
import { CopyButton } from '../../../../components';
import { truncateFormatter } from '../../../../common/helpers/formatters';

interface ActionCardProps {
title: string;
description: string;
buttonText: string;
variant: 'primary' | 'outlined';
icon?: React.ReactNode;
onAction: () => void;
onViewDetails?: () => void;
status: GovernanceStatusState;
drepId: string | null;
isDelegated: boolean;
Expand All @@ -24,22 +21,18 @@ export const DrepOptionsCard: React.FC<ActionCardProps> = ({
title,
description,
buttonText,
variant,
icon,
onAction,
onViewDetails,
status,
drepId,
isDelegated,
pending = false,
}) => {
const strings = useStrings();

return (
<ActionCardContainer variant={variant} status={status} isCardDelegated={isDelegated} pending={pending}>
<ActionCardContainer status={status} isCardDelegated={isDelegated} pending={pending}>
<CardWrapper>
<CardTitleRow>
<CardIcon variant={variant} isDelegated={isDelegated}>
<CardIcon isDelegated={isDelegated}>
{icon}
</CardIcon>
<Typography variant="h5">{title}</Typography>
Expand All @@ -51,36 +44,15 @@ export const DrepOptionsCard: React.FC<ActionCardProps> = ({
</CardWrapper>

<CTASet>
{variant === 'primary' ? (
<Stack direction="column" spacing={12} width="100%">
{(status === GOVERNANCE_STATUS.DELEGATED || drepId === null) && !isDelegated && (
// @ts-ignore
<LoadingButton variant="primary" onClick={onAction} fullWidth height="40px">
{buttonText}
</LoadingButton>
)}

{onViewDetails && (
<Link
textAlign="center"
onClick={e => {
e.stopPropagation();
onViewDetails();
}}
rel="noopener"
underline="hover"
sx={{ cursor: 'pointer' }}
>
{strings.yoroiVotingRecord}
</Link>
)}
</Stack>
) : (
// @ts-ignore
<Button height="40px" variant="secondary" onClick={onAction} fullWidth sx={{ padding: '13px 10px !important' }}>
{buttonText}
</Button>
)}
<Button
fullWidth
onClick={onAction}
sx={{ height: '40px', padding: '13px 10px !important' }}
/* @ts-ignore */
variant="secondary"
>
{buttonText}
</Button>
</CTASet>
</ActionCardContainer>
);
Expand Down Expand Up @@ -147,26 +119,23 @@ const DelegatingLabel = () => {
);
};

type ActionCardVariant = 'primary' | 'outlined';

interface ActionCardContainerProps {
variant: ActionCardVariant;
status: GovernanceStatusState;
isCardDelegated?: boolean;
pending?: boolean;
}

export const ActionCardContainer = styled(Box, {
shouldForwardProp: prop => prop !== 'variant' && prop !== 'status' && prop !== 'isCardDelegated' && prop !== 'pending',
})<ActionCardContainerProps>(({ pending, theme, variant, status, isCardDelegated }: any) => {
shouldForwardProp: prop => prop !== 'status' && prop !== 'isCardDelegated' && prop !== 'pending',
})<ActionCardContainerProps>(({ pending, theme, status, isCardDelegated }: any) => {
const base: React.CSSProperties = {
boxSizing: 'border-box',
display: 'flex',
flexDirection: 'column',
justifyContent: 'space-between',
alignItems: 'flex-start',
padding: '16px',
gap: variant === 'primary' ? '16px' : '12px',
gap: '12px',
width: '294px',
height: '320px',
borderRadius: '8px',
Expand All @@ -191,15 +160,6 @@ export const ActionCardContainer = styled(Box, {
background: theme.palette.ds.bg_gradient_2,
};
}
if (variant === 'primary') {
return {
...base,
backgroundImage: theme.palette.ds.bg_gradient_1,
'&:hover': {
backgroundImage: theme.palette.ds.bg_gradient_2,
},
};
}

return {
...base,
Expand Down Expand Up @@ -240,16 +200,11 @@ const CardTitleRow = styled(Box)(() => ({
}));

const CardIcon = styled(Box, {
shouldForwardProp: prop => prop !== 'variant' && prop !== 'isDelegated',
})<{ variant: 'primary' | 'outlined'; isDelegated?: boolean }>(({ variant, isDelegated, theme }: any) => ({
shouldForwardProp: prop => prop !== 'isDelegated',
})<{ isDelegated?: boolean }>(({ isDelegated, theme }: any) => ({
width: '48px',
height: '48px',
background:
variant === 'primary'
? theme.palette.ds.primary_500
: isDelegated
? theme.palette.ds.secondary_200
: theme.palette.ds.gray_100,
background: isDelegated ? theme.palette.ds.secondary_200 : theme.palette.ds.gray_100,
borderRadius: '1200px',
display: 'flex',
alignItems: 'center',
Expand Down
Loading
Loading