From 3ae45ddd7e4feff790d5db4b2e83593b564d629a Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Wed, 5 Dec 2018 14:11:03 +0100 Subject: [PATCH] update fee in reducer only if changed --- src/actions/BlockchainActions.js | 1 + src/actions/ripple/BlockchainActions.js | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/actions/BlockchainActions.js b/src/actions/BlockchainActions.js index 5393813e..9dde3442 100644 --- a/src/actions/BlockchainActions.js +++ b/src/actions/BlockchainActions.js @@ -16,6 +16,7 @@ export type BlockchainAction = { type: typeof BLOCKCHAIN.READY, } | { type: typeof BLOCKCHAIN.UPDATE_FEE, + shortcut: string, fee: string, } diff --git a/src/actions/ripple/BlockchainActions.js b/src/actions/ripple/BlockchainActions.js index 14f7e020..3f4cf884 100644 --- a/src/actions/ripple/BlockchainActions.js +++ b/src/actions/ripple/BlockchainActions.js @@ -23,16 +23,22 @@ export const subscribe = (network: string): PromiseAction => async (dispat }; -export const onBlockMined = (network: string): PromiseAction => async (dispatch: Dispatch): Promise => { +export const onBlockMined = (network: string): PromiseAction => async (dispatch: Dispatch, getState: GetState): Promise => { const fee = await TrezorConnect.blockchainGetFee({ coin: network, }); if (!fee.success) return; - dispatch({ - type: BLOCKCHAIN.UPDATE_FEE, - fee: fee.payload, - }); + const blockchain = getState().blockchain.find(b => b.shortcut === network); + if (!blockchain) return; + + if (fee.payload !== blockchain.fee) { + dispatch({ + type: BLOCKCHAIN.UPDATE_FEE, + shortcut: network, + fee: fee.payload, + }); + } }; export const onNotification = (payload: $ElementType): PromiseAction => async (dispatch: Dispatch, getState: GetState): Promise => {