1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-14 04:19:09 +00:00

add "reconnectionAttempts" to blockchain reducer

This commit is contained in:
Szymon Lesisz 2019-10-30 16:26:17 +01:00
parent 0e10925769
commit 3d8f64465a

View File

@ -17,6 +17,7 @@ export type BlockchainNetwork = {
feeLevels: Array<BlockchainFeeLevel>,
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: