Skip to content

Commit d5f7e32

Browse files
fix: run coin selection always with join pool action when preparing the TX form VP delegation (#3250)
1 parent a662d17 commit d5f7e32

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

source/renderer/app/api/api.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,7 @@ export default class AdaApi {
13001300
error,
13011301
});
13021302

1303-
throw new ApiError(error);
1303+
throw new ApiError(error).result();
13041304
}
13051305
};
13061306

@@ -1318,7 +1318,7 @@ export default class AdaApi {
13181318
logger.error('AdaApi::createExternalTransaction error', {
13191319
error,
13201320
});
1321-
throw new ApiError(error);
1321+
throw new ApiError(error).result();
13221322
}
13231323
};
13241324
inspectAddress = async (request: {
@@ -2827,7 +2827,7 @@ export default class AdaApi {
28272827
error,
28282828
});
28292829

2830-
throw new ApiError(error);
2830+
throw new ApiError(error).result();
28312831
}
28322832
};
28332833

source/renderer/app/stores/VotingStore.ts

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { action, computed, observable, runInAction } from 'mobx';
22
import { get } from 'lodash';
3-
import BigNumber from 'bignumber.js';
43
import Store from './lib/Store';
54
import Request from './lib/LocalizedRequest';
65
import { ROUTES } from '../routes-config';
@@ -30,8 +29,8 @@ import { EventCategories } from '../analytics';
3029
import type { DelegationCalculateFeeResponse } from '../api/staking/types';
3130
import Wallet from '../domains/Wallet';
3231
import ApiError from '../domains/ApiError';
33-
import type { DelegationAction } from '../types/stakingTypes';
3432
import { GenericApiError } from '../api/common/errors';
33+
import { logger } from '../utils/logging';
3534

3635
export type VotingRegistrationKeyType = {
3736
bytes: (...args: Array<any>) => any;
@@ -280,29 +279,25 @@ export default class VotingStore extends Store {
280279
wallet: Wallet;
281280
}) => {
282281
if (wallet.isHardwareWallet) {
283-
const [{ id: stakePoolId }] = this.stores.staking.stakePools;
284-
let dlegationData: {
285-
delegationAction: DelegationAction;
286-
poolId: string;
287-
} = {
288-
delegationAction: 'join',
289-
poolId: stakePoolId,
290-
};
282+
let poolId: string;
291283

292284
if (wallet.isDelegating) {
293285
const { lastDelegatedStakePoolId, delegatedStakePoolId } = wallet;
294-
const poolId = lastDelegatedStakePoolId || delegatedStakePoolId || '';
295-
dlegationData = {
296-
delegationAction: 'quit',
297-
poolId,
298-
};
286+
const currentPoolId = lastDelegatedStakePoolId || delegatedStakePoolId;
287+
poolId = this.stores.staking.stakePools.find(
288+
(stakePool) => stakePool.id !== currentPoolId
289+
).id;
290+
} else {
291+
const [{ id }] = this.stores.staking.stakePools;
292+
poolId = id;
299293
}
300294

301295
try {
302296
const initialCoinSelection = await this.stores.hardwareWallets.selectDelegationCoins(
303297
{
304298
walletId: wallet.id,
305-
...dlegationData,
299+
delegationAction: 'join',
300+
poolId,
306301
}
307302
);
308303

@@ -342,6 +337,12 @@ export default class VotingStore extends Store {
342337
fees: coinSelection.fee,
343338
};
344339
} catch (error) {
340+
logger.error(
341+
'VotingStore: error while initializing VP delegation TX with HW',
342+
{
343+
error,
344+
}
345+
);
345346
return {
346347
success: false,
347348
errorCode: parseApiCode(
@@ -364,6 +365,9 @@ export default class VotingStore extends Store {
364365
fees: constructedTx.fee,
365366
};
366367
} catch (error) {
368+
logger.error('VotingStore: error while initializing VP delegation TX', {
369+
error,
370+
});
367371
return {
368372
success: false,
369373
errorCode: parseApiCode(expectedInitializeVPDelegationTxErrors, error),
@@ -417,6 +421,9 @@ export default class VotingStore extends Store {
417421
success: true,
418422
};
419423
} catch (error) {
424+
logger.error('VotingStore: error while delegating vote with HW', {
425+
error,
426+
});
420427
const errorCode: GenericErrorCode = 'generic';
421428
return {
422429
success: false,

0 commit comments

Comments
 (0)