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

feat: use pool delegation endpoint for constructing drep tx no matter the wallet type #3262

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
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

## vNext
## 7.0.2

### Fixes

- Changed Cardano Wallet endpoint used to initialize VP delegation transaction ([PR 3262](https://github.com/input-output-hk/daedalus/pull/3262))

## 7.0.1

Expand Down
86 changes: 31 additions & 55 deletions source/renderer/app/stores/VotingStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,29 +278,29 @@ export default class VotingStore extends Store {
chosenOption: string;
wallet: Wallet;
}) => {
if (wallet.isHardwareWallet) {
let poolId: string;

if (wallet.isDelegating) {
const { lastDelegatedStakePoolId, delegatedStakePoolId } = wallet;
const currentPoolId = lastDelegatedStakePoolId || delegatedStakePoolId;
poolId = this.stores.staking.stakePools.find(
(stakePool) => stakePool.id !== currentPoolId
).id;
} else {
const [{ id }] = this.stores.staking.stakePools;
poolId = id;
}
let poolId: string;

if (wallet.isDelegating) {
const { lastDelegatedStakePoolId, delegatedStakePoolId } = wallet;
const currentPoolId = lastDelegatedStakePoolId || delegatedStakePoolId;
poolId = this.stores.staking.stakePools.find(
(stakePool) => stakePool.id !== currentPoolId
).id;
} else {
const [{ id }] = this.stores.staking.stakePools;
poolId = id;
}

try {
const initialCoinSelection = await this.stores.hardwareWallets.selectDelegationCoins(
{
walletId: wallet.id,
delegationAction: 'join',
poolId,
}
);
try {
let coinSelection = await this.stores.hardwareWallets.selectDelegationCoins(
{
walletId: wallet.id,
delegationAction: 'join',
poolId,
}
);

if (wallet.isHardwareWallet) {
let certificates: object[] = [
{
certificateType: 'cast_vote',
Expand All @@ -309,7 +309,7 @@ export default class VotingStore extends Store {
},
];

const walletNeedsRegisteringRewardAccount = initialCoinSelection.certificates.some(
const walletNeedsRegisteringRewardAccount = coinSelection.certificates.some(
(c) => c.certificateType === 'register_reward_account'
);
if (walletNeedsRegisteringRewardAccount) {
Expand All @@ -322,52 +322,28 @@ export default class VotingStore extends Store {
];
}

const coinSelection = {
...initialCoinSelection,
coinSelection = {
...coinSelection,
certificates,
};

this.stores.hardwareWallets.updateTxSignRequest(coinSelection);
this.stores.hardwareWallets.initiateTransaction({
walletId: wallet.id,
});

return {
success: true,
fees: coinSelection.fee,
};
} catch (error) {
logger.error(
'VotingStore: error while initializing VP delegation TX with HW',
{
error,
}
);
return {
success: false,
errorCode: parseApiCode(
expectedInitializeVPDelegationTxErrors,
error
),
};
}
}

this.constructTxRequest.reset();
try {
const constructedTx = await this.constructTxRequest.execute({
walletId: wallet.id,
data: { vote: chosenOption },
}).promise;

return {
success: true,
fees: constructedTx.fee,
fees: coinSelection.fee,
};
} catch (error) {
logger.error('VotingStore: error while initializing VP delegation TX', {
error,
});
logger.error(
'VotingStore: error while initializing VP delegation TX with HW',
szymonmaslowski marked this conversation as resolved.
Show resolved Hide resolved
{
error,
}
);
return {
success: false,
errorCode: parseApiCode(expectedInitializeVPDelegationTxErrors, error),
Expand Down
Loading