Skip to content

Commit

Permalink
fix: run coin selection always with join pool action when preparing t…
Browse files Browse the repository at this point in the history
…he TX form VP delegation
  • Loading branch information
szymonmaslowski committed Dec 2, 2024
1 parent 899701a commit a4df596
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions source/renderer/app/stores/VotingStore.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { action, computed, observable, runInAction } from 'mobx';
import { get } from 'lodash';
import BigNumber from 'bignumber.js';
import Store from './lib/Store';
import Request from './lib/LocalizedRequest';
import { ROUTES } from '../routes-config';
Expand Down Expand Up @@ -30,7 +29,6 @@ import { EventCategories } from '../analytics';
import type { DelegationCalculateFeeResponse } from '../api/staking/types';
import Wallet from '../domains/Wallet';
import ApiError from '../domains/ApiError';
import type { DelegationAction } from '../types/stakingTypes';
import { GenericApiError } from '../api/common/errors';

export type VotingRegistrationKeyType = {
Expand Down Expand Up @@ -280,29 +278,25 @@ export default class VotingStore extends Store {
wallet: Wallet;
}) => {
if (wallet.isHardwareWallet) {
const [{ id: stakePoolId }] = this.stores.staking.stakePools;
let dlegationData: {
delegationAction: DelegationAction;
poolId: string;
} = {
delegationAction: 'join',
poolId: stakePoolId,
};
let poolId: string;

if (wallet.isDelegating) {
const { lastDelegatedStakePoolId, delegatedStakePoolId } = wallet;
const poolId = lastDelegatedStakePoolId || delegatedStakePoolId || '';
dlegationData = {
delegationAction: 'quit',
poolId,
};
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,
...dlegationData,
delegationAction: 'join',
poolId,
}
);

Expand Down Expand Up @@ -417,6 +411,7 @@ export default class VotingStore extends Store {
success: true,
};
} catch (error) {
console.log('!DEBUG error', error);
const errorCode: GenericErrorCode = 'generic';
return {
success: false,
Expand Down

0 comments on commit a4df596

Please sign in to comment.