mirror of
https://github.com/trezor/trezor-wallet
synced 2025-07-19 04:58:13 +00:00
add "reconnectionAttempts" to blockchain reducer
This commit is contained in:
parent
0e10925769
commit
3d8f64465a
@ -17,6 +17,7 @@ export type BlockchainNetwork = {
|
|||||||
feeLevels: Array<BlockchainFeeLevel>,
|
feeLevels: Array<BlockchainFeeLevel>,
|
||||||
connected: boolean,
|
connected: boolean,
|
||||||
connecting: boolean,
|
connecting: boolean,
|
||||||
|
reconnectionAttempts: number,
|
||||||
block: number,
|
block: number,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -41,30 +42,7 @@ const onStartSubscribe = (state: State, shortcut: string): State => {
|
|||||||
shortcut,
|
shortcut,
|
||||||
connected: false,
|
connected: false,
|
||||||
connecting: true,
|
connecting: true,
|
||||||
block: 0,
|
reconnectionAttempts: 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,
|
|
||||||
block: 0,
|
block: 0,
|
||||||
feeTimestamp: 0,
|
feeTimestamp: 0,
|
||||||
feeLevels: [],
|
feeLevels: [],
|
||||||
@ -84,6 +62,7 @@ const onConnect = (state: State, action: BlockchainConnect): State => {
|
|||||||
block: info.block,
|
block: info.block,
|
||||||
connected: true,
|
connected: true,
|
||||||
connecting: false,
|
connecting: false,
|
||||||
|
reconnectionAttempts: 0,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@ -93,6 +72,7 @@ const onConnect = (state: State, action: BlockchainConnect): State => {
|
|||||||
shortcut,
|
shortcut,
|
||||||
connected: true,
|
connected: true,
|
||||||
connecting: false,
|
connecting: false,
|
||||||
|
reconnectionAttempts: 0,
|
||||||
block: info.block,
|
block: info.block,
|
||||||
feeTimestamp: 0,
|
feeTimestamp: 0,
|
||||||
feeLevels: [],
|
feeLevels: [],
|
||||||
@ -110,6 +90,7 @@ const onError = (state: State, action: BlockchainError): State => {
|
|||||||
...network,
|
...network,
|
||||||
connected: false,
|
connected: false,
|
||||||
connecting: false,
|
connecting: false,
|
||||||
|
reconnectionAttempts: network.reconnectionAttempts + 1,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@ -119,6 +100,7 @@ const onError = (state: State, action: BlockchainError): State => {
|
|||||||
shortcut,
|
shortcut,
|
||||||
connected: false,
|
connected: false,
|
||||||
connecting: false,
|
connecting: false,
|
||||||
|
reconnectionAttempts: 0,
|
||||||
block: 0,
|
block: 0,
|
||||||
feeTimestamp: 0,
|
feeTimestamp: 0,
|
||||||
feeLevels: [],
|
feeLevels: [],
|
||||||
@ -160,8 +142,6 @@ export default (state: State = initialState, action: Action): State => {
|
|||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case BLOCKCHAIN_ACTION.START_SUBSCRIBE:
|
case BLOCKCHAIN_ACTION.START_SUBSCRIBE:
|
||||||
return onStartSubscribe(state, action.shortcut);
|
return onStartSubscribe(state, action.shortcut);
|
||||||
case BLOCKCHAIN_ACTION.FAIL_SUBSCRIBE:
|
|
||||||
return onFailSubscribe(state, action.shortcut);
|
|
||||||
case BLOCKCHAIN_EVENT.CONNECT:
|
case BLOCKCHAIN_EVENT.CONNECT:
|
||||||
return onConnect(state, action);
|
return onConnect(state, action);
|
||||||
case BLOCKCHAIN_EVENT.ERROR:
|
case BLOCKCHAIN_EVENT.ERROR:
|
||||||
|
Loading…
Reference in New Issue
Block a user