diff --git a/src/common/components/exchange/DeviceErrorDialog.vue b/src/common/components/exchange/DeviceErrorDialog.vue index 5447c54d..71226244 100644 --- a/src/common/components/exchange/DeviceErrorDialog.vue +++ b/src/common/components/exchange/DeviceErrorDialog.vue @@ -9,7 +9,7 @@ -

+

{{ errorMessage }}

{{messageToUserOnLink}}

@@ -27,7 +27,7 @@
-

+

{{ errorMessage }}

= { [constants.PEGOUT_TX_SELECT_FEE_LEVEL]: ({ commit }, feeLevel: MiningSpeedFee) => { @@ -16,26 +16,32 @@ export const actions: ActionTree = { commit(constants.PEGOUT_TX_SET_AMOUNT, amountToTransfer); }, [constants.PEGOUT_TX_CALCULATE_FEE]: async ({ commit, state, rootState }) => { - const bridgeService = new BridgeService(); const web3 = rootState.web3Session?.web3 as Web3; const sender = rootState.web3Session?.account as string; - // RSK Fee - const gas = await web3.eth.estimateGas({ - from: sender, - to: state.pegoutConfiguration.bridgeContractAddress, - value: state.amountToTransfer.toWeiString(), - }); - commit(constants.PEGOUT_TX_SET_GAS, gas); - const gasPrice = Number(await web3.eth.getGasPrice()); - const calculatedFee = new WeiBig(gasPrice * gas, 'wei'); - commit(constants.PEGOUT_TX_SET_RSK_ESTIMATED_FEE, calculatedFee); - // BTC Fee - const [nextPegoutCost, pegoutQueueCount] = await Promise.all([ - bridgeService.getEstimatedFeesForNextPegOutEvent(), - bridgeService.getQueuedPegoutsCount(), - ]); - const estimatedFee = pegoutQueueCount > 0 ? nextPegoutCost / pegoutQueueCount : 0; - commit(constants.PEGOUT_TX_SET_BTC_ESTIMATED_FEE, new SatoshiBig(estimatedFee, 'satoshi')); + + try { + // RSK Fee + const gas = await web3.eth.estimateGas({ + from: sender, + to: state.pegoutConfiguration.bridgeContractAddress, + value: state.amountToTransfer.toWeiString(), + }); + commit(constants.PEGOUT_TX_SET_GAS, gas); + const gasPrice = Number(await web3.eth.getGasPrice()); + const calculatedFee = new WeiBig(gasPrice * gas, 'wei'); + commit(constants.PEGOUT_TX_SET_RSK_ESTIMATED_FEE, calculatedFee); + } catch (e) { + commit(constants.PEGOUT_TX_SET_GAS, 0); + commit(constants.PEGOUT_TX_SET_RSK_ESTIMATED_FEE, 0); + } + + try { + // BTC Fee + const estimatedFee = await getEstimatedFee(); + commit(constants.PEGOUT_TX_SET_BTC_ESTIMATED_FEE, new SatoshiBig(estimatedFee, 'satoshi')); + } catch (e) { + commit(constants.PEGOUT_TX_SET_BTC_ESTIMATED_FEE, new SatoshiBig(0, 'satoshi')); + } }, [constants.PEGOUT_TX_ADD_PEGOUT_CONFIGURATION]: ({ commit }) => { commit(constants.PEGOUT_TX_SET_PEGOUT_CONFIGURATION, { diff --git a/src/status/store/actions.ts b/src/status/store/actions.ts index ccfab0c7..5285088c 100644 --- a/src/status/store/actions.ts +++ b/src/status/store/actions.ts @@ -9,6 +9,7 @@ import { EnvironmentAccessorService } from '@/common/services/enviroment-accesso import * as constants from '@/common/store/constants'; import { ApiService } from '@/common/services'; import { BridgeService } from '@/common/services/BridgeService'; +import { getEstimatedFee } from '@/common/utils'; export const actions: ActionTree = { [constants.STATUS_CLEAR]: ({ commit }) => { @@ -29,18 +30,13 @@ export const actions: ActionTree = { commit(constants.STATUS_SET_TX_TYPE, TxStatusType.UNEXPECTED_ERROR); }); }, - [constants.STATUS_GET_ESTIMATED_FEE]: ({ commit }) => { - const bridgeService = new BridgeService(); - Promise.all([ - bridgeService.getEstimatedFeesForNextPegOutEvent(), - bridgeService.getQueuedPegoutsCount(), - ]).then(([nextPegoutCost, pegoutQueueCount]) => { - const estimatedFee = pegoutQueueCount > 0 ? nextPegoutCost / pegoutQueueCount : 0; + [constants.STATUS_GET_ESTIMATED_FEE]: async ({ commit }) => { + try { + const estimatedFee = await getEstimatedFee(); commit(constants.STATUS_SET_BTC_ESTIMATED_FEE, new SatoshiBig(estimatedFee, 'satoshi')); - }) - .catch(() => { - commit(constants.STATUS_SET_BTC_ESTIMATED_FEE, new SatoshiBig(0, 'satoshi')); - }); + } catch (e) { + commit(constants.STATUS_SET_BTC_ESTIMATED_FEE, new SatoshiBig(0, 'satoshi')); + } }, [constants.STATUS_GET_ESTIMATED_RELEASE_TIME_IN_MINUTES]: ({ state, commit }) : Promise => new Promise((resolve, reject) => {