diff --git a/src/actions/BlockchainActions.js b/src/actions/BlockchainActions.js index a127d985..c3a5a0b1 100644 --- a/src/actions/BlockchainActions.js +++ b/src/actions/BlockchainActions.js @@ -8,6 +8,7 @@ import type { Dispatch, GetState, PromiseAction, + BlockchainFeeLevel, } from 'flowtype'; import type { BlockchainBlock, BlockchainNotification, BlockchainError } from 'trezor-connect'; @@ -17,7 +18,7 @@ export type BlockchainAction = { } | { type: typeof BLOCKCHAIN.UPDATE_FEE, shortcut: string, - fee: string, + feeLevels: Array, } // Conditionally subscribe to blockchain backend @@ -100,7 +101,7 @@ export const onNotification = (payload: $ElementType): PromiseAction => async (dispatch: Dispatch, getState: GetState): Promise => { const shortcut = payload.coin.shortcut.toLowerCase(); const { config } = getState().localStorage; diff --git a/src/actions/SendFormActions.js b/src/actions/SendFormActions.js index 187b09cb..16c6230a 100644 --- a/src/actions/SendFormActions.js +++ b/src/actions/SendFormActions.js @@ -2,6 +2,7 @@ import * as ACCOUNT from 'actions/constants/account'; import * as SEND from 'actions/constants/send'; import * as WEB3 from 'actions/constants/web3'; +import * as BLOCKCHAIN from 'actions/constants/blockchain'; import type { Dispatch, @@ -36,6 +37,7 @@ export type SendFormAction = { const actions = [ ACCOUNT.UPDATE_SELECTED_ACCOUNT, WEB3.GAS_PRICE_UPDATED, + BLOCKCHAIN.UPDATE_FEE, ...Object.values(SEND).filter(v => typeof v === 'string'), ]; diff --git a/src/flowtype/index.js b/src/flowtype/index.js index 28d23197..e5e24d07 100644 --- a/src/flowtype/index.js +++ b/src/flowtype/index.js @@ -159,6 +159,7 @@ export type { Account } from 'reducers/AccountsReducer'; export type { Discovery } from 'reducers/DiscoveryReducer'; export type { Token } from 'reducers/TokensReducer'; export type { Web3Instance } from 'reducers/Web3Reducer'; +export type { BlockchainFeeLevel } from 'reducers/BlockchainReducer'; export type Accounts = $ElementType; export type LocalStorage = $ElementType; diff --git a/src/reducers/BlockchainReducer.js b/src/reducers/BlockchainReducer.js index 9bb77944..3831eb51 100644 --- a/src/reducers/BlockchainReducer.js +++ b/src/reducers/BlockchainReducer.js @@ -6,12 +6,17 @@ import * as BLOCKCHAIN_ACTION from 'actions/constants/blockchain'; import type { Action } from 'flowtype'; import type { BlockchainConnect, BlockchainError, BlockchainBlock } from 'trezor-connect'; +export type BlockchainFeeLevel = { + name: string, + value: string, +}; + export type BlockchainNetwork = { +shortcut: string, + feeTimestamp: number, + feeLevels: Array, connected: boolean, block: number, - reserved: string, // xrp specific - fee: string, }; export type State = Array; @@ -27,8 +32,6 @@ const onConnect = (state: State, action: BlockchainConnect): State => { return others.concat([{ ...network, connected: true, - fee: info.fee, - block: info.block, }]); } @@ -36,8 +39,8 @@ const onConnect = (state: State, action: BlockchainConnect): State => { shortcut, connected: true, block: info.block, - fee: info.fee, - reserved: info.reserved || '0', + feeTimestamp: 0, + feeLevels: [], }]); }; @@ -56,8 +59,8 @@ const onError = (state: State, action: BlockchainError): State => { shortcut, connected: false, block: 0, - fee: '0', - reserved: '0', + feeTimestamp: 0, + feeLevels: [], }]); }; @@ -75,14 +78,15 @@ const onBlock = (state: State, action: BlockchainBlock): State => { return state; }; -const updateFee = (state: State, shortcut: string, fee: string): State => { +const updateFee = (state: State, shortcut: string, feeLevels: Array): State => { const network = state.find(b => b.shortcut === shortcut); if (!network) return state; const others = state.filter(b => b !== network); return others.concat([{ ...network, - fee, + feeTimestamp: new Date().getTime(), + feeLevels, }]); }; @@ -96,7 +100,7 @@ export default (state: State = initialState, action: Action): State => { case BLOCKCHAIN_EVENT.BLOCK: return onBlock(state, action); case BLOCKCHAIN_ACTION.UPDATE_FEE: - return updateFee(state, action.shortcut, action.fee); + return updateFee(state, action.shortcut, action.feeLevels); default: return state;