Skip to content

Commit b977de0

Browse files
feat: restrict drep id format to cip 105 (#3247)
Co-authored-by: Dominik Guzei <dominik.guzei@gmail.com>
1 parent 957896f commit b977de0

File tree

9 files changed

+1474
-82
lines changed

9 files changed

+1474
-82
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@
197197
},
198198
"dependencies": {
199199
"@cardano-foundation/ledgerjs-hw-app-cardano": "7.1.3",
200+
"@cardano-sdk/core": "^0.41.4",
200201
"@iohk-jormungandr/wallet-js": "0.5.0-pre7",
201202
"@ledgerhq/hw-transport-node-hid": "6.27.15",
202203
"@trezor/connect": "9.3.0",

source/common/utils/assertIsBech32WithPrefix.ts

Lines changed: 0 additions & 34 deletions
This file was deleted.

source/renderer/app/components/voting/voting-governance/VotingPowerDelegation.messages.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ export const messages = defineMessages({
44
drepInputLabel: {
55
id: 'voting.governance.drepInputLabel',
66
defaultMessage:
7-
'!!!Please type or paste a valid DRep ID here. Look up {drepDirectoryLink}',
7+
'!!!Please type or paste a valid DRep ID (CIP-105) here. Look up {drepDirectoryLink}',
88
description: 'Label for DRep input on the governance page',
99
},
1010
drepInputLabelPreprod: {
1111
id: 'voting.governance.drepInputLabelPreprod',
12-
defaultMessage: '!!!Please type or paste a valid DRep ID here.',
12+
defaultMessage: '!!!Please type or paste a valid DRep ID (CIP-105) here.',
1313
description: 'Label for DRep input on the governance page for preprod',
1414
},
1515
drepInputLabelLinkText: {

source/renderer/app/components/voting/voting-governance/VotingPowerDelegation.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Input } from 'react-polymorph/lib/components/Input';
55
import { Button } from 'react-polymorph/lib/components/Button';
66

77
import BigNumber from 'bignumber.js';
8+
import { Cardano } from '@cardano-sdk/core';
89
import BorderedBox from '../../widgets/BorderedBox';
910
import { messages } from './VotingPowerDelegation.messages';
1011
import styles from './VotingPowerDelegation.scss';
@@ -13,7 +14,6 @@ import WalletsDropdown from '../../widgets/forms/WalletsDropdown';
1314
import Wallet from '../../../domains/Wallet';
1415
import StakePool from '../../../domains/StakePool';
1516
import ItemsDropdown from '../../widgets/forms/ItemsDropdown';
16-
import { assertIsBech32WithPrefix } from '../../../../../common/utils/assertIsBech32WithPrefix';
1717
import { Separator } from '../../widgets/separator/Separator';
1818
import { InitializeVPDelegationTxError } from '../../../stores/VotingStore';
1919
import { VoteType } from './types';
@@ -73,13 +73,9 @@ type State = Form | FormWithError | StateFormComplete | StateConfirmation;
7373

7474
// TODO discuss if we need to restrict the length
7575
const isDrepIdValid = (drepId: string) => {
76-
try {
77-
assertIsBech32WithPrefix(drepId, ['drep', 'drep_script']);
78-
} catch (e) {
79-
return false;
80-
}
81-
82-
return true;
76+
const isDRepId = (value: string): value is Cardano.DRepID =>
77+
Cardano.DRepID.isValid(value);
78+
return isDRepId(drepId) && Cardano.DRepID.toCip105DRepID(drepId) === drepId;
8379
};
8480

8581
const mapOfTxErrorCodeToIntl: Record<

source/renderer/app/i18n/locales/defaultMessages.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4407,12 +4407,12 @@
44074407
{
44084408
"descriptors": [
44094409
{
4410-
"defaultMessage": "!!!Please type or paste a valid DRep ID here. Look up {drepDirectoryLink}",
4410+
"defaultMessage": "!!!Please type or paste a valid DRep ID (CIP-105) here. Look up {drepDirectoryLink}",
44114411
"description": "Label for DRep input on the governance page",
44124412
"id": "voting.governance.drepInputLabel"
44134413
},
44144414
{
4415-
"defaultMessage": "!!!Please type or paste a valid DRep ID here.",
4415+
"defaultMessage": "!!!Please type or paste a valid DRep ID (CIP-105) here.",
44164416
"description": "Label for DRep input on the governance page for preprod",
44174417
"id": "voting.governance.drepInputLabelPreprod"
44184418
},

source/renderer/app/i18n/locales/en-US.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,11 +729,11 @@
729729
"voting.governance.confirmationDialog.vote": "Vote",
730730
"voting.governance.delegateToDRep": "Delegate to DRep (default)",
731731
"voting.governance.drepInputError": "Invalid DRep ID",
732-
"voting.governance.drepInputLabel": "Please type or paste a valid DRep ID here. Look up {drepDirectoryLink}",
732+
"voting.governance.drepInputLabel": "Please type or paste a valid DRep ID (CIP-105) here. Look up {drepDirectoryLink}",
733733
"voting.governance.drepInputLabelLinkText": "DRep directory",
734734
"voting.governance.drepInputLabelLinkUrl": "https://gov.tools/drep_directory",
735735
"voting.governance.drepInputLabelLinkUrlPreview": "https://preview.gov.tools/drep_directory",
736-
"voting.governance.drepInputLabelPreprod": "Please type or paste a valid DRep ID here.",
736+
"voting.governance.drepInputLabelPreprod": "Please type or paste a valid DRep ID (CIP-105) here.",
737737
"voting.governance.drepInputPlaceholder": "Paste DRep ID here …",
738738
"voting.governance.heading": "CARDANO VOTING POWER DELEGATION",
739739
"voting.governance.initializeTxError.generic": "Something went wrong during transaction initialization. Please try again in a few minutes. ",

source/renderer/app/i18n/locales/ja-JP.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,11 +729,11 @@
729729
"voting.governance.confirmationDialog.vote": "投票",
730730
"voting.governance.delegateToDRep": "DRepに委任(初期設定)",
731731
"voting.governance.drepInputError": "無効なDRep IDです",
732-
"voting.governance.drepInputLabel": "有効なDRep IDを入力するか貼り付けます。{drepDirectoryLink}で検索する",
732+
"voting.governance.drepInputLabel": "有効なDRep ID (CIP-105)を入力するか貼り付けます。{drepDirectoryLink}で検索する",
733733
"voting.governance.drepInputLabelLinkText": "DRepディレクトリ",
734734
"voting.governance.drepInputLabelLinkUrl": "https://gov.tools/drep_directory",
735735
"voting.governance.drepInputLabelLinkUrlPreview": "https://preview.gov.tools/drep_directory",
736-
"voting.governance.drepInputLabelPreprod": "有効なDRep IDを入力するか貼り付けます",
736+
"voting.governance.drepInputLabelPreprod": "有効なDRep ID (CIP-105)を入力するか貼り付けます",
737737
"voting.governance.drepInputPlaceholder": "DRep IDを追加してください",
738738
"voting.governance.heading": "Cardano投票権の委任",
739739
"voting.governance.initializeTxError.generic": "トランザクションの初期化中に問題が発生しました。しばらくしてからもう一度お試しください。",

translations/messages.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4407,12 +4407,12 @@
44074407
{
44084408
"descriptors": [
44094409
{
4410-
"defaultMessage": "!!!Please type or paste a valid DRep ID here. Look up {drepDirectoryLink}",
4410+
"defaultMessage": "!!!Please type or paste a valid DRep ID (CIP-105) here. Look up {drepDirectoryLink}",
44114411
"description": "Label for DRep input on the governance page",
44124412
"id": "voting.governance.drepInputLabel"
44134413
},
44144414
{
4415-
"defaultMessage": "!!!Please type or paste a valid DRep ID here.",
4415+
"defaultMessage": "!!!Please type or paste a valid DRep ID (CIP-105) here.",
44164416
"description": "Label for DRep input on the governance page for preprod",
44174417
"id": "voting.governance.drepInputLabelPreprod"
44184418
},

0 commit comments

Comments
 (0)