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

fix: [LW 11920] fix VP delegation when delegating to SP #3250

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: 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