Skip to content

Commit

Permalink
feat: restrict drep id format to cip 105
Browse files Browse the repository at this point in the history
  • Loading branch information
szymonmaslowski committed Nov 28, 2024
1 parent 97240f1 commit cb2ee0c
Show file tree
Hide file tree
Showing 9 changed files with 1,474 additions and 82 deletions.
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

0 comments on commit cb2ee0c

Please sign in to comment.