update fee levels in reducer only if needed

pull/288/head
Szymon Lesisz 5 years ago
parent e7c4329a0c
commit 7d9cbf7cbe

@ -106,8 +106,7 @@
"minFee": "10", "minFee": "10",
"maxFee": "10000", "maxFee": "10000",
"levels": [ "levels": [
{"name": "High", "value": "20" }, {"name": "Normal", "value": "12", "recommended": true }
{"name": "Normal", "value": "10", "recommended": true }
] ]
}, },
"explorer": { "explorer": {

@ -5,6 +5,7 @@ import * as BLOCKCHAIN from 'actions/constants/blockchain';
import * as PENDING from 'actions/constants/pendingTx'; import * as PENDING from 'actions/constants/pendingTx';
import * as AccountsActions from 'actions/AccountsActions'; import * as AccountsActions from 'actions/AccountsActions';
import { toDecimalAmount } from 'utils/formatUtils'; import { toDecimalAmount } from 'utils/formatUtils';
import { observeChanges } from 'reducers/utils';
import type { BlockchainNotification } from 'trezor-connect'; import type { BlockchainNotification } from 'trezor-connect';
import type { import type {
@ -48,7 +49,8 @@ export const onBlockMined = (network: string): PromiseAction<void> => async (dis
const feeRequest = await TrezorConnect.blockchainEstimateFee({ const feeRequest = await TrezorConnect.blockchainEstimateFee({
coin: network, coin: network,
}); });
if (feeRequest.success) { if (feeRequest.success && observeChanges(blockchain.feeLevels, feeRequest.payload)) {
// check if downloaded fee levels are different
dispatch({ dispatch({
type: BLOCKCHAIN.UPDATE_FEE, type: BLOCKCHAIN.UPDATE_FEE,
shortcut: network, shortcut: network,

@ -115,7 +115,7 @@ export const getWeb3 = (state: State): ?Web3Instance => {
return state.web3.find(w3 => w3.network === locationState.network); return state.web3.find(w3 => w3.network === locationState.network);
}; };
export const observeChanges = (prev: ?Object, current: ?Object, filter?: {[k: string]: Array<string>}): boolean => { export const observeChanges = (prev: ?any, current: ?any, filter?: {[k: string]: Array<string>}): boolean => {
// 1. both objects are the same (solves simple types like string, boolean and number) // 1. both objects are the same (solves simple types like string, boolean and number)
if (prev === current) return false; if (prev === current) return false;
// 2. one of the objects is null/undefined // 2. one of the objects is null/undefined

Loading…
Cancel
Save