From 7d9cbf7cbe4152718798eb5ea81309406e15ab26 Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Wed, 2 Jan 2019 17:14:54 +0100 Subject: [PATCH] update fee levels in reducer only if needed --- public/data/appConfig.json | 3 +-- src/actions/ripple/BlockchainActions.js | 4 +++- src/reducers/utils/index.js | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/public/data/appConfig.json b/public/data/appConfig.json index aa7861f8..6125250a 100644 --- a/public/data/appConfig.json +++ b/public/data/appConfig.json @@ -106,8 +106,7 @@ "minFee": "10", "maxFee": "10000", "levels": [ - {"name": "High", "value": "20" }, - {"name": "Normal", "value": "10", "recommended": true } + {"name": "Normal", "value": "12", "recommended": true } ] }, "explorer": { diff --git a/src/actions/ripple/BlockchainActions.js b/src/actions/ripple/BlockchainActions.js index 754d9a7c..bd59339d 100644 --- a/src/actions/ripple/BlockchainActions.js +++ b/src/actions/ripple/BlockchainActions.js @@ -5,6 +5,7 @@ import * as BLOCKCHAIN from 'actions/constants/blockchain'; import * as PENDING from 'actions/constants/pendingTx'; import * as AccountsActions from 'actions/AccountsActions'; import { toDecimalAmount } from 'utils/formatUtils'; +import { observeChanges } from 'reducers/utils'; import type { BlockchainNotification } from 'trezor-connect'; import type { @@ -48,7 +49,8 @@ export const onBlockMined = (network: string): PromiseAction => async (dis const feeRequest = await TrezorConnect.blockchainEstimateFee({ coin: network, }); - if (feeRequest.success) { + if (feeRequest.success && observeChanges(blockchain.feeLevels, feeRequest.payload)) { + // check if downloaded fee levels are different dispatch({ type: BLOCKCHAIN.UPDATE_FEE, shortcut: network, diff --git a/src/reducers/utils/index.js b/src/reducers/utils/index.js index 7104ca8e..df7c6cc3 100644 --- a/src/reducers/utils/index.js +++ b/src/reducers/utils/index.js @@ -115,7 +115,7 @@ export const getWeb3 = (state: State): ?Web3Instance => { return state.web3.find(w3 => w3.network === locationState.network); }; -export const observeChanges = (prev: ?Object, current: ?Object, filter?: {[k: string]: Array}): boolean => { +export const observeChanges = (prev: ?any, current: ?any, filter?: {[k: string]: Array}): boolean => { // 1. both objects are the same (solves simple types like string, boolean and number) if (prev === current) return false; // 2. one of the objects is null/undefined