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

Restrict drep id format to cip 105 #3247

Merged
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@
},
"dependencies": {
"@cardano-foundation/ledgerjs-hw-app-cardano": "7.1.3",
"@cardano-sdk/core": "^0.41.4",
"@iohk-jormungandr/wallet-js": "0.5.0-pre7",
"@ledgerhq/hw-transport-node-hid": "6.27.15",
"@trezor/connect": "9.3.0",
Expand Down
34 changes: 0 additions & 34 deletions source/common/utils/assertIsBech32WithPrefix.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ export const messages = defineMessages({
drepInputLabel: {
id: 'voting.governance.drepInputLabel',
defaultMessage:
'!!!Please type or paste a valid DRep ID here. Look up {drepDirectoryLink}',
'!!!Please type or paste a valid DRep ID (CIP-105) here. Look up {drepDirectoryLink}',
description: 'Label for DRep input on the governance page',
},
drepInputLabelPreprod: {
id: 'voting.governance.drepInputLabelPreprod',
defaultMessage: '!!!Please type or paste a valid DRep ID here.',
defaultMessage: '!!!Please type or paste a valid DRep ID (CIP-105) here.',
description: 'Label for DRep input on the governance page for preprod',
},
drepInputLabelLinkText: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Input } from 'react-polymorph/lib/components/Input';
import { Button } from 'react-polymorph/lib/components/Button';

import BigNumber from 'bignumber.js';
import { Cardano } from '@cardano-sdk/core';
import BorderedBox from '../../widgets/BorderedBox';
import { messages } from './VotingPowerDelegation.messages';
import styles from './VotingPowerDelegation.scss';
Expand All @@ -13,7 +14,6 @@ import WalletsDropdown from '../../widgets/forms/WalletsDropdown';
import Wallet from '../../../domains/Wallet';
import StakePool from '../../../domains/StakePool';
import ItemsDropdown from '../../widgets/forms/ItemsDropdown';
import { assertIsBech32WithPrefix } from '../../../../../common/utils/assertIsBech32WithPrefix';
import { Separator } from '../../widgets/separator/Separator';
import { InitializeVPDelegationTxError } from '../../../stores/VotingStore';
import { VoteType } from './types';
Expand Down Expand Up @@ -73,13 +73,9 @@ type State = Form | FormWithError | StateFormComplete | StateConfirmation;

// TODO discuss if we need to restrict the length
const isDrepIdValid = (drepId: string) => {
try {
assertIsBech32WithPrefix(drepId, ['drep', 'drep_script']);
} catch (e) {
return false;
}

return true;
const isDRepId = (value: string): value is Cardano.DRepID =>
Cardano.DRepID.isValid(value);
return isDRepId(drepId) && Cardano.DRepID.toCip105DRepID(drepId) === drepId;
};

const mapOfTxErrorCodeToIntl: Record<
Expand Down
4 changes: 2 additions & 2 deletions source/renderer/app/i18n/locales/defaultMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -4407,12 +4407,12 @@
{
"descriptors": [
{
"defaultMessage": "!!!Please type or paste a valid DRep ID here. Look up {drepDirectoryLink}",
"defaultMessage": "!!!Please type or paste a valid DRep ID (CIP-105) here. Look up {drepDirectoryLink}",
"description": "Label for DRep input on the governance page",
"id": "voting.governance.drepInputLabel"
},
{
"defaultMessage": "!!!Please type or paste a valid DRep ID here.",
"defaultMessage": "!!!Please type or paste a valid DRep ID (CIP-105) here.",
"description": "Label for DRep input on the governance page for preprod",
"id": "voting.governance.drepInputLabelPreprod"
},
Expand Down
4 changes: 2 additions & 2 deletions source/renderer/app/i18n/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -729,11 +729,11 @@
"voting.governance.confirmationDialog.vote": "Vote",
"voting.governance.delegateToDRep": "Delegate to DRep (default)",
"voting.governance.drepInputError": "Invalid DRep ID",
"voting.governance.drepInputLabel": "Please type or paste a valid DRep ID here. Look up {drepDirectoryLink}",
"voting.governance.drepInputLabel": "Please type or paste a valid DRep ID (CIP-105) here. Look up {drepDirectoryLink}",
"voting.governance.drepInputLabelLinkText": "DRep directory",
"voting.governance.drepInputLabelLinkUrl": "https://gov.tools/drep_directory",
"voting.governance.drepInputLabelLinkUrlPreview": "https://preview.gov.tools/drep_directory",
"voting.governance.drepInputLabelPreprod": "Please type or paste a valid DRep ID here.",
"voting.governance.drepInputLabelPreprod": "Please type or paste a valid DRep ID (CIP-105) here.",
"voting.governance.drepInputPlaceholder": "Paste DRep ID here …",
"voting.governance.heading": "CARDANO VOTING POWER DELEGATION",
"voting.governance.initializeTxError.generic": "Something went wrong during transaction initialization. Please try again in a few minutes. ",
Expand Down
4 changes: 2 additions & 2 deletions source/renderer/app/i18n/locales/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -729,11 +729,11 @@
"voting.governance.confirmationDialog.vote": "投票",
"voting.governance.delegateToDRep": "DRepに委任(初期設定)",
"voting.governance.drepInputError": "無効なDRep IDです",
"voting.governance.drepInputLabel": "有効なDRep IDを入力するか貼り付けます。{drepDirectoryLink}で検索する",
"voting.governance.drepInputLabel": "有効なDRep ID (CIP-105)を入力するか貼り付けます。{drepDirectoryLink}で検索する",
"voting.governance.drepInputLabelLinkText": "DRepディレクトリ",
"voting.governance.drepInputLabelLinkUrl": "https://gov.tools/drep_directory",
"voting.governance.drepInputLabelLinkUrlPreview": "https://preview.gov.tools/drep_directory",
"voting.governance.drepInputLabelPreprod": "有効なDRep IDを入力するか貼り付けます。",
"voting.governance.drepInputLabelPreprod": "有効なDRep ID (CIP-105)を入力するか貼り付けます。",
"voting.governance.drepInputPlaceholder": "DRep IDを追加してください",
"voting.governance.heading": "Cardano投票権の委任",
"voting.governance.initializeTxError.generic": "トランザクションの初期化中に問題が発生しました。しばらくしてからもう一度お試しください。",
Expand Down
4 changes: 2 additions & 2 deletions translations/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -4407,12 +4407,12 @@
{
"descriptors": [
{
"defaultMessage": "!!!Please type or paste a valid DRep ID here. Look up {drepDirectoryLink}",
"defaultMessage": "!!!Please type or paste a valid DRep ID (CIP-105) here. Look up {drepDirectoryLink}",
"description": "Label for DRep input on the governance page",
"id": "voting.governance.drepInputLabel"
},
{
"defaultMessage": "!!!Please type or paste a valid DRep ID here.",
"defaultMessage": "!!!Please type or paste a valid DRep ID (CIP-105) here.",
"description": "Label for DRep input on the governance page for preprod",
"id": "voting.governance.drepInputLabelPreprod"
},
Expand Down
Loading