diff --git a/src/actions/BlockchainActions.js b/src/actions/BlockchainActions.js index 5d2a4781..9f68065c 100644 --- a/src/actions/BlockchainActions.js +++ b/src/actions/BlockchainActions.js @@ -86,7 +86,9 @@ export const estimateGasLimit = (network: string, data: string, value: string, g return await dispatch( Web3Actions.estimateGasLimit(network, { to: '', data, value, gasPrice }) ); } -export const onBlockMined = (network: string): PromiseAction => async (dispatch: Dispatch, getState: GetState): Promise => { +export const onBlockMined = (coinInfo: any): PromiseAction => async (dispatch: Dispatch, getState: GetState): Promise => { + // incoming "coinInfo" from TrezorConnect is CoinInfo | EthereumNetwork type + const network: string = coinInfo.shortcut.toLowerCase(); // try to resolve pending transactions await dispatch( Web3Actions.resolvePendingTransactions(network) ); @@ -119,12 +121,15 @@ export const onBlockMined = (network: string): PromiseAction => async (dis } } + +// not used for now, waiting for fix in blockbook export const onNotification = (payload: any): PromiseAction => async (dispatch: Dispatch, getState: GetState): Promise => { // this event can be triggered multiple times // 1. check if pair [txid + address] is already in reducer + const network: string = payload.coin.shortcut.toLowerCase(); const address: string = EthereumjsUtil.toChecksumAddress(payload.tx.address); - const txInfo = await dispatch( Web3Actions.getPendingInfo(payload.coin, payload.tx.txid) ); + const txInfo = await dispatch( Web3Actions.getPendingInfo(network, payload.tx.txid) ); // const exists = getState().pending.filter(p => p.id === payload.tx.txid && p.address === address); const exists = getState().pending.filter(p => { @@ -137,7 +142,7 @@ export const onNotification = (payload: any): PromiseAction => async (disp payload: { type: 'send', id: payload.tx.txid, - network: payload.coin, + network, currency: "tETH", amount: txInfo.value, total: "0", @@ -152,7 +157,7 @@ export const onNotification = (payload: any): PromiseAction => async (disp // dispatch({ // type: PENDING.ADD_UNKNOWN, // payload: { - // network: payload.coin, + // network, // ...payload.tx, // } // }); diff --git a/src/actions/Web3Actions.js b/src/actions/Web3Actions.js index cae70fe1..a6821ef8 100644 --- a/src/actions/Web3Actions.js +++ b/src/actions/Web3Actions.js @@ -299,7 +299,9 @@ export const estimateGasLimit = (network: string, options: EstimateGasOptions): return limit; }; -export const disconnect = (network: string): ThunkAction => (dispatch: Dispatch, getState: GetState): void => { +export const disconnect = (coinInfo: any): ThunkAction => (dispatch: Dispatch, getState: GetState): void => { + // incoming "coinInfo" from TrezorConnect is CoinInfo | EthereumNetwork type + const network: string = coinInfo.shortcut.toLowerCase(); // check if Web3 was already initialized const instance = getState().web3.find(w3 => w3.network === network); if (instance) { diff --git a/src/reducers/BlockchainReducer.js b/src/reducers/BlockchainReducer.js index 92de9c27..b4d4a12b 100644 --- a/src/reducers/BlockchainReducer.js +++ b/src/reducers/BlockchainReducer.js @@ -18,12 +18,13 @@ const find = (state: State, name: string): number => { } const connect = (state: State, action: any): State => { + const name = action.payload.coin.shortcut.toLowerCase(); const network: BlockchainNetwork = { - name: action.payload.coin, + name, connected: true, } const newState: State = [...state]; - const index: number = find(newState, action.payload.coin); + const index: number = find(newState, name); if (index >= 0) { newState[index] = network; } else { @@ -33,12 +34,13 @@ const connect = (state: State, action: any): State => { }; const disconnect = (state: State, action: any): State => { + const name = action.payload.coin.shortcut.toLowerCase(); const network: BlockchainNetwork = { - name: action.payload.coin, + name, connected: false, } const newState: State = [...state]; - const index: number = find(newState, action.payload.coin); + const index: number = find(newState, name); if (index >= 0) { newState[index] = network; } else {