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 (#3250)
  • Loading branch information
szymonmaslowski authored Dec 2, 2024
1 parent a662d17 commit d5f7e32
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
6 changes: 3 additions & 3 deletions source/renderer/app/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,7 @@ export default class AdaApi {
error,
});

throw new ApiError(error);
throw new ApiError(error).result();
}
};

Expand All @@ -1318,7 +1318,7 @@ export default class AdaApi {
logger.error('AdaApi::createExternalTransaction error', {
error,
});
throw new ApiError(error);
throw new ApiError(error).result();
}
};
inspectAddress = async (request: {
Expand Down Expand Up @@ -2827,7 +2827,7 @@ export default class AdaApi {
error,
});

throw new ApiError(error);
throw new ApiError(error).result();
}
};

Expand Down
39 changes: 23 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,8 +29,8 @@ 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';
import { logger } from '../utils/logging';

export type VotingRegistrationKeyType = {
bytes: (...args: Array<any>) => any;
Expand Down Expand Up @@ -280,29 +279,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 @@ -342,6 +337,12 @@ export default class VotingStore extends Store {
fees: coinSelection.fee,
};
} catch (error) {
logger.error(
'VotingStore: error while initializing VP delegation TX with HW',
{
error,
}
);
return {
success: false,
errorCode: parseApiCode(
Expand All @@ -364,6 +365,9 @@ export default class VotingStore extends Store {
fees: constructedTx.fee,
};
} catch (error) {
logger.error('VotingStore: error while initializing VP delegation TX', {
error,
});
return {
success: false,
errorCode: parseApiCode(expectedInitializeVPDelegationTxErrors, error),
Expand Down Expand Up @@ -417,6 +421,9 @@ export default class VotingStore extends Store {
success: true,
};
} catch (error) {
logger.error('VotingStore: error while delegating vote with HW', {
error,
});
const errorCode: GenericErrorCode = 'generic';
return {
success: false,
Expand Down

0 comments on commit d5f7e32

Please sign in to comment.