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

Check delegation status and display a warning if the wallet hasn't delegated #2088

Merged
merged 1 commit into from
May 12, 2021
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
25 changes: 25 additions & 0 deletions packages/yoroi-extension/app/components/wallet/voting/Voting.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,21 @@ const messages = defineMessages({
id: 'wallet.voting.line4',
defaultMessage: '!!!Open the Catalyst Voting App and click on the Complete registration button.',
},
notDelegated: {
id: 'wallet.voting.notDelegated',
defaultMessage: '!!!You have not delegated. Your voting power is how much you delegate and the voting rewards will be distributed to your delegation reward address. Please make sure to delegate before voting.',
},
keepDelegated: {
id: 'wallet.voting.keepDelegated',
defaultMessage: '!!!Your voting power is how much you delegate and the voting rewards will be distributed to your delegation reward address. Please keep delegated until the voting ends.',
},
});

type Props = {|
+start: void => void,
+onExternalLinkClick: MouseEvent => void,
+hasAnyPending: boolean,
+isDelegated: boolean,
|};

@observer
Expand Down Expand Up @@ -108,6 +117,22 @@ export default class Voting extends Component<Props> {
</div>
</div>
</div>
<div className={styles.delegationStatus}>
{this.props.isDelegated ?
(
<div className={styles.lineText}>
{intl.formatMessage(messages.keepDelegated)}
</div>
) :
(
<div className={styles.warningBox}>
<WarningBox>
{intl.formatMessage(messages.notDelegated)}
</WarningBox>
</div>
)
}
</div>
<div className={styles.registerButton}>
<Button
className={buttonClasses}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,9 @@
text-align: center;
margin-bottom: 32px;
}

.delegationStatus {
text-align: center;
margin-bottom: 32px;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import environment from '../../../environment';
import { MultiToken } from '../../../api/common/lib/MultiToken';
import RegistrationOver from './RegistrationOver';
import { networks, } from '../../../api/ada/lib/storage/database/prepackaged/networks';
import type { DelegationRequests } from '../../../stores/toplevel/DelegationStore';

export type GeneratedData = typeof VotingPage.prototype.generated;
type Props = {|
Expand All @@ -47,6 +48,36 @@ export default class VotingPage extends Component<Props> {
this.generated.actions.dialogs.open.trigger({ dialog: VotingRegistrationDialogContainer });
};

get isDelegated(): ?boolean {
const publicDeriver = this.generated.stores.wallets.selected;
const delegationStore = this.generated.stores.delegation;

if (!publicDeriver) {
throw new Error(`${nameof(this.isDelegated)} no public deriver. Should never happen`);
}

const delegationRequests = delegationStore.getDelegationRequests(publicDeriver);
if (delegationRequests == null) {
throw new Error(`${nameof(this.isDelegated)} called for non-reward wallet`);
}
const currentDelegation = delegationRequests.getCurrentDelegation;

if (
!currentDelegation.wasExecuted ||
currentDelegation.isExecuting ||
currentDelegation.result == null
) {
return undefined;
}
if(
!currentDelegation.result.currEpoch ||
currentDelegation.result.currEpoch.pools.length === 0
) {
return false;
}
return true;
}

render(): Node {
const {
uiDialogs,
Expand Down Expand Up @@ -120,6 +151,7 @@ export default class VotingPage extends Component<Props> {
start={this.start}
hasAnyPending={this.generated.hasAnyPending}
onExternalLinkClick={handleExternalLinkClick}
isDelegated={this.isDelegated === true}
/>
</div>
);
Expand Down Expand Up @@ -152,6 +184,9 @@ export default class VotingPage extends Component<Props> {
wallets: {|
selected: null | PublicDeriver<>,
|},
delegation: {|
getDelegationRequests: (PublicDeriver<>) => void | DelegationRequests,
|},
|},
|} {
if (this.props.generated !== undefined) {
Expand Down Expand Up @@ -197,6 +232,9 @@ export default class VotingPage extends Component<Props> {
tokenInfoStore: {
tokenInfo: stores.tokenInfoStore.tokenInfo,
},
delegation: {
getDelegationRequests: stores.delegation.getDelegationRequests,
},
},
VotingRegistrationDialogProps: ({
actions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ const defaultProps: ({|
tokenInfoStore: {
tokenInfo: mockFromDefaults(defaultAssets),
},
delegation: {
getDelegationRequests: walletLookup([request.wallet]).getDelegation,
},
},
actions: {
dialogs: {
Expand Down
2 changes: 2 additions & 0 deletions packages/yoroi-extension/app/i18n/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -779,10 +779,12 @@
"wallet.voting.dialog.stepQrCode": "QR Code",
"wallet.voting.dialog.title": "Register for Voting",
"wallet.voting.dialog.transactionLabel": "Transaction",
"wallet.voting.keepDelegated": "Your voting power is how much you delegate and the voting rewards will be distributed to your delegation reward address. Please keep delegated until the voting ends.",
"wallet.voting.line2": "Before you begin, make sure to complete steps below",
"wallet.voting.line3": "Download the Catalyst Voting App.",
"wallet.voting.line4": "Open the Catalyst Voting App and click on the Complete registration button.",
"wallet.voting.lineTitle": "Register to vote on Fund 3",
"wallet.voting.notDelegated": "You have not delegated. Your voting power is how much you delegate and the voting rewards will be distributed to your delegation reward address. Please make sure to delegate before voting.",
"wallet.withdrawal.transaction.unregister": "This transaction will unregister one or more staking keys, giving you back your {refundAmount} {ticker} from your deposit",
"widgets.copyableaddress.addressCopyTooltipMessage": "Copy to clipboard",
"widgets.explorer.tooltip": "Go to {websiteName}",
Expand Down