diff --git a/src/actions/BlockchainActions.js b/src/actions/BlockchainActions.js index c3a5a0b1..f3e31755 100644 --- a/src/actions/BlockchainActions.js +++ b/src/actions/BlockchainActions.js @@ -19,6 +19,9 @@ export type BlockchainAction = { type: typeof BLOCKCHAIN.UPDATE_FEE, shortcut: string, feeLevels: Array, +} | { + type: typeof BLOCKCHAIN.START_SUBSCRIBE, + shortcut: string, } // Conditionally subscribe to blockchain backend @@ -52,6 +55,11 @@ export const subscribe = (networkName: string): PromiseAction => async (di const network = config.networks.find(c => c.shortcut === networkName); if (!network) return; + dispatch({ + type: BLOCKCHAIN.START_SUBSCRIBE, + shortcut: network.shortcut, + }); + switch (network.type) { case 'ethereum': await dispatch(EthereumBlockchainActions.subscribe(networkName)); diff --git a/src/actions/constants/blockchain.js b/src/actions/constants/blockchain.js index 9e19d3e3..7e1baeab 100644 --- a/src/actions/constants/blockchain.js +++ b/src/actions/constants/blockchain.js @@ -1,4 +1,5 @@ /* @flow */ +export const START_SUBSCRIBE: 'blockchain__start_subscribe' = 'blockchain__start_subscribe'; export const READY: 'blockchain__ready' = 'blockchain__ready'; export const UPDATE_FEE: 'blockchain__update_fee' = 'blockchain__update_fee'; \ No newline at end of file diff --git a/src/components/notifications/Context/components/Account/index.js b/src/components/notifications/Context/components/Account/index.js index a4924900..59d87299 100644 --- a/src/components/notifications/Context/components/Account/index.js +++ b/src/components/notifications/Context/components/Account/index.js @@ -8,6 +8,7 @@ import type { Props } from '../../index'; export default (props: Props) => { const { network, notification } = props.selectedAccount; if (!network || !notification) return null; + const blockchain = props.blockchain.find(b => b.shortcut === network.shortcut); if (notification.type === 'backend') { // special case: backend is down @@ -17,6 +18,7 @@ export default (props: Props) => { type="error" title={notification.title} message={notification.message} + isActionInProgress={blockchain && blockchain.connecting} actions={ [{ label: 'Connect', diff --git a/src/reducers/BlockchainReducer.js b/src/reducers/BlockchainReducer.js index 3831eb51..c5cc44ab 100644 --- a/src/reducers/BlockchainReducer.js +++ b/src/reducers/BlockchainReducer.js @@ -16,6 +16,7 @@ export type BlockchainNetwork = { feeTimestamp: number, feeLevels: Array, connected: boolean, + connecting: boolean, block: number, }; @@ -23,6 +24,26 @@ export type State = Array; export const initialState: State = []; +const onStartSubscribe = (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: true, + }]); + } + + return state.concat([{ + shortcut, + connected: false, + connecting: true, + block: 0, + feeTimestamp: 0, + feeLevels: [], + }]); +}; + const onConnect = (state: State, action: BlockchainConnect): State => { const shortcut = action.payload.coin.shortcut.toLowerCase(); const network = state.find(b => b.shortcut === shortcut); @@ -31,13 +52,16 @@ const onConnect = (state: State, action: BlockchainConnect): State => { const others = state.filter(b => b !== network); return others.concat([{ ...network, + block: info.block, connected: true, + connecting: false, }]); } return state.concat([{ shortcut, connected: true, + connecting: false, block: info.block, feeTimestamp: 0, feeLevels: [], @@ -52,12 +76,14 @@ const onError = (state: State, action: BlockchainError): State => { return others.concat([{ ...network, connected: false, + connecting: false, }]); } return state.concat([{ shortcut, connected: false, + connecting: false, block: 0, feeTimestamp: 0, feeLevels: [], @@ -93,6 +119,8 @@ const updateFee = (state: State, shortcut: string, feeLevels: Array { switch (action.type) { + case BLOCKCHAIN_ACTION.START_SUBSCRIBE: + return onStartSubscribe(state, action.shortcut); case BLOCKCHAIN_EVENT.CONNECT: return onConnect(state, action); case BLOCKCHAIN_EVENT.ERROR: