From e130b1edc0c9d1e022cb666367b80446c5d00e00 Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Wed, 5 Dec 2018 14:12:53 +0100 Subject: [PATCH] update recommended fee in blockchain reducer --- src/reducers/BlockchainReducer.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/reducers/BlockchainReducer.js b/src/reducers/BlockchainReducer.js index 48a44db2..e92d9468 100644 --- a/src/reducers/BlockchainReducer.js +++ b/src/reducers/BlockchainReducer.js @@ -1,6 +1,7 @@ /* @flow */ -import { BLOCKCHAIN } from 'trezor-connect'; +import { BLOCKCHAIN as BLOCKCHAIN_EVENT } from 'trezor-connect'; +import * as BLOCKCHAIN_ACTION from 'actions/constants/blockchain'; import type { Action } from 'flowtype'; import type { BlockchainConnect, BlockchainError, BlockchainBlock } from 'trezor-connect'; @@ -66,15 +67,28 @@ const onBlock = (state: State, action: BlockchainBlock): State => { return state; }; +const updateFee = (state: State, shortcut: string, fee: string): State => { + const network = state.find(b => b.shortcut === shortcut); + if (!network) return state; + + const others = state.filter(b => b !== network); + return others.concat([{ + ...network, + fee, + }]); +}; + export default (state: State = initialState, action: Action): State => { switch (action.type) { - case BLOCKCHAIN.CONNECT: + case BLOCKCHAIN_EVENT.CONNECT: return onConnect(state, action); - case BLOCKCHAIN.ERROR: + case BLOCKCHAIN_EVENT.ERROR: return onError(state, action); - case BLOCKCHAIN.BLOCK: + case BLOCKCHAIN_EVENT.BLOCK: return onBlock(state, action); + case BLOCKCHAIN_ACTION.UPDATE_FEE: + return updateFee(state, action.shortcut, action.fee); default: return state;