Skip to content

Commit 5472147

Browse files
authored
Merge pull request #3273 from input-output-hk/fix/LW-12119-fix-vote-delegation-form
fix: vote delegation form
2 parents dd63902 + bd7d70d commit 5472147

File tree

5 files changed

+35
-21
lines changed

5 files changed

+35
-21
lines changed

source/renderer/app/api/wallets/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ export type SyncStateStatus =
7777
| 'syncing'
7878
| 'not_responding';
7979
export type Discovery = 'random' | 'sequential';
80-
export type DelegationStatus = 'delegating' | 'not_delegating';
80+
export type DelegationStatus =
81+
| 'delegating'
82+
| 'not_delegating'
83+
| 'voting'
84+
| 'voting_and_delegating';
8185
export type WalletSyncStateProgress = {
8286
quantity: number;
8387
unit: 'percentage';

source/renderer/app/domains/Wallet.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@ export const WalletSyncStateStatuses: {
3333
export const WalletDelegationStatuses: {
3434
DELEGATING: DelegationStatus;
3535
NOT_DELEGATING: DelegationStatus;
36+
VOTING: DelegationStatus;
37+
VOTING_AND_DELEGATING: DelegationStatus;
3638
} = {
3739
DELEGATING: 'delegating',
3840
NOT_DELEGATING: 'not_delegating',
41+
VOTING: 'voting',
42+
VOTING_AND_DELEGATING: 'voting_and_delegating',
3943
};
4044
export type HwDeviceStatus =
4145
| 'connecting'
@@ -234,10 +238,12 @@ export default class Wallet {
234238

235239
@computed
236240
get isDelegating(): boolean {
237-
return this.lastDelegationStakePoolStatus
238-
? this.lastDelegationStakePoolStatus ===
239-
WalletDelegationStatuses.DELEGATING
240-
: this.delegationStakePoolStatus === WalletDelegationStatuses.DELEGATING;
241+
const statusToCheck = (this.lastDelegationStakePoolStatus ||
242+
this.delegationStakePoolStatus) as DelegationStatus;
243+
return [
244+
WalletDelegationStatuses.DELEGATING,
245+
WalletDelegationStatuses.VOTING_AND_DELEGATING,
246+
].includes(statusToCheck);
241247
}
242248

243249
@computed

source/renderer/app/utils/dataSerialization.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import blakejs from 'blakejs';
33
import { encode } from 'borc';
44
import { utils } from '@cardano-foundation/ledgerjs-hw-app-cardano';
55
import { base58_decode } from '@cardano-foundation/ledgerjs-hw-app-cardano/dist/utils/address';
6+
import { Cardano } from '@cardano-sdk/core';
67
import { AddressStyles } from '../domains/WalletAddress';
78
import {
89
derivationPathToLedgerPath,
@@ -182,11 +183,12 @@ const parseVoteDelegation = (vote: string): [number] | [number, Buffer] => {
182183
if (vote === 'abstain') return [2];
183184
if (vote === 'no_confidence') return [3];
184185

185-
const voteHash = Buffer.from(
186-
utils.buf_to_hex(utils.bech32_decodeAddress(vote)),
187-
'hex'
188-
);
189-
return [vote.includes('_script') ? 1 : 0, voteHash];
186+
const { type, hash } = Cardano.DRepID.toCredential(Cardano.DRepID(vote));
187+
188+
return [
189+
type === Cardano.CredentialType.ScriptHash ? 1 : 0,
190+
Buffer.from(hash, 'hex'),
191+
];
190192
};
191193

192194
export function toTxCertificate(cert: {

source/renderer/app/utils/shelleyLedger.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
base58_decode,
1414
str_to_path,
1515
} from '@cardano-foundation/ledgerjs-hw-app-cardano/dist/utils/address';
16+
import { Cardano } from '@cardano-sdk/core';
1617
import {
1718
CATALYST_VOTING_REGISTRATION_TYPE,
1819
CERTIFICATE_TYPE,
@@ -67,18 +68,18 @@ const parseVoteDelegation = (
6768
};
6869
}
6970

70-
const votHash = utils.buf_to_hex(utils.bech32_decodeAddress(cert.vote));
71+
const { type, hash } = Cardano.DRepID.toCredential(Cardano.DRepID(cert.vote));
7172

72-
if (cert.vote.includes('_script')) {
73+
if (type === Cardano.CredentialType.ScriptHash) {
7374
return {
7475
type: DRepParamsType.SCRIPT_HASH,
75-
scriptHashHex: votHash,
76+
scriptHashHex: hash,
7677
};
7778
}
7879

7980
return {
8081
type: DRepParamsType.KEY_HASH,
81-
keyHashHex: votHash,
82+
keyHashHex: hash,
8283
};
8384
};
8485

source/renderer/app/utils/shelleyTrezor.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ import { utils } from '@cardano-foundation/ledgerjs-hw-app-cardano';
22
import { Messages } from '@trezor/transport';
33
import { CardanoDRep, PROTO } from '@trezor/connect';
44
import { map } from 'lodash';
5+
import { Cardano } from '@cardano-sdk/core';
56
import {
6-
derivationPathToString,
77
CERTIFICATE_TYPE,
8+
derivationPathToString,
89
groupTokensByPolicyId,
910
} from './hardwareWalletUtils';
1011
import type {
12+
CoinSelectionAssetsType,
13+
CoinSelectionCertificate,
1114
CoinSelectionInput,
1215
CoinSelectionOutput,
13-
CoinSelectionCertificate,
1416
CoinSelectionWithdrawal,
15-
CoinSelectionAssetsType,
1617
} from '../api/transactions/types';
1718

1819
export const TrezorTransactionSigningMode = {
@@ -67,18 +68,18 @@ const parseVoteDelegation = (cert: CoinSelectionCertificate): CardanoDRep => {
6768
};
6869
}
6970

70-
const voteHash = utils.bech32_decodeAddress(cert.vote).toString('hex');
71+
const { type, hash } = Cardano.DRepID.toCredential(Cardano.DRepID(cert.vote));
7172

72-
if (cert.vote.includes('_script')) {
73+
if (type === Cardano.CredentialType.ScriptHash) {
7374
return {
7475
type: PROTO.CardanoDRepType.SCRIPT_HASH,
75-
scriptHash: voteHash,
76+
scriptHash: hash,
7677
};
7778
}
7879

7980
return {
8081
type: PROTO.CardanoDRepType.KEY_HASH,
81-
keyHash: voteHash,
82+
keyHash: hash,
8283
};
8384
};
8485

0 commit comments

Comments
 (0)