11import { action , computed , observable , runInAction } from 'mobx' ;
22import { get } from 'lodash' ;
3- import BigNumber from 'bignumber.js' ;
43import Store from './lib/Store' ;
54import Request from './lib/LocalizedRequest' ;
65import { ROUTES } from '../routes-config' ;
@@ -30,8 +29,8 @@ import { EventCategories } from '../analytics';
3029import type { DelegationCalculateFeeResponse } from '../api/staking/types' ;
3130import Wallet from '../domains/Wallet' ;
3231import ApiError from '../domains/ApiError' ;
33- import type { DelegationAction } from '../types/stakingTypes' ;
3432import { GenericApiError } from '../api/common/errors' ;
33+ import { logger } from '../utils/logging' ;
3534
3635export 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