From 3d8f64465ab2b451950a9e7160a96b2080dcc5d8 Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Wed, 30 Oct 2019 16:26:17 +0100 Subject: [PATCH] add "reconnectionAttempts" to blockchain reducer --- src/reducers/BlockchainReducer.js | 32 ++++++------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/src/reducers/BlockchainReducer.js b/src/reducers/BlockchainReducer.js index 865f1f2f..d6a1e029 100644 --- a/src/reducers/BlockchainReducer.js +++ b/src/reducers/BlockchainReducer.js @@ -17,6 +17,7 @@ export type BlockchainNetwork = { feeLevels: Array, connected: boolean, connecting: boolean, + reconnectionAttempts: number, block: number, }; @@ -41,30 +42,7 @@ const onStartSubscribe = (state: State, shortcut: string): State => { shortcut, connected: false, connecting: true, - block: 0, - feeTimestamp: 0, - feeLevels: [], - }, - ]); -}; - -const onFailSubscribe = (state: State, shortcut: string): State => { - const network = state.find(b => b.shortcut === shortcut); - if (network) { - const others = state.filter(b => b !== network); - return others.concat([ - { - ...network, - connecting: false, - }, - ]); - } - - return state.concat([ - { - shortcut, - connected: false, - connecting: false, + reconnectionAttempts: 0, block: 0, feeTimestamp: 0, feeLevels: [], @@ -84,6 +62,7 @@ const onConnect = (state: State, action: BlockchainConnect): State => { block: info.block, connected: true, connecting: false, + reconnectionAttempts: 0, }, ]); } @@ -93,6 +72,7 @@ const onConnect = (state: State, action: BlockchainConnect): State => { shortcut, connected: true, connecting: false, + reconnectionAttempts: 0, block: info.block, feeTimestamp: 0, feeLevels: [], @@ -110,6 +90,7 @@ const onError = (state: State, action: BlockchainError): State => { ...network, connected: false, connecting: false, + reconnectionAttempts: network.reconnectionAttempts + 1, }, ]); } @@ -119,6 +100,7 @@ const onError = (state: State, action: BlockchainError): State => { shortcut, connected: false, connecting: false, + reconnectionAttempts: 0, block: 0, feeTimestamp: 0, feeLevels: [], @@ -160,8 +142,6 @@ export default (state: State = initialState, action: Action): State => { switch (action.type) { case BLOCKCHAIN_ACTION.START_SUBSCRIBE: return onStartSubscribe(state, action.shortcut); - case BLOCKCHAIN_ACTION.FAIL_SUBSCRIBE: - return onFailSubscribe(state, action.shortcut); case BLOCKCHAIN_EVENT.CONNECT: return onConnect(state, action); case BLOCKCHAIN_EVENT.ERROR: