From 2b4592343e5873fb7653fd438ce34044826da075 Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Wed, 23 May 2018 11:46:57 +0200 Subject: [PATCH] START/STOP_ACQUIRING (Acquire page) --- src/js/actions/TrezorConnectActions.js | 28 ++++++++++++++++------- src/js/actions/constants/TrezorConnect.js | 5 +++- src/js/components/wallet/pages/Acquire.js | 6 ++--- src/js/reducers/TrezorConnectReducer.js | 15 +++++++++++- 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/src/js/actions/TrezorConnectActions.js b/src/js/actions/TrezorConnectActions.js index a5a81711..2e80fbaf 100644 --- a/src/js/actions/TrezorConnectActions.js +++ b/src/js/actions/TrezorConnectActions.js @@ -74,6 +74,10 @@ export type TrezorConnectAction = { } | { type: typeof CONNECT.DEVICE_FROM_STORAGE, payload: Array +} | { + type: typeof CONNECT.START_ACQUIRING, +} | { + type: typeof CONNECT.STOP_ACQUIRING, }; @@ -366,6 +370,10 @@ export function acquire(): AsyncAction { const selected: ?TrezorDevice = getState().wallet.selectedDevice; if (!selected) return; + dispatch({ + type: CONNECT.START_ACQUIRING, + }) + const response = await TrezorConnect.getFeatures({ device: { path: selected.path, @@ -381,17 +389,21 @@ export function acquire(): AsyncAction { title: 'Acquire device error', message: response.payload.error, cancelable: true, - actions: [ - { - label: 'Try again', - callback: () => { - dispatch(acquire()) - } - } - ] + // actions: [ + // { + // label: 'Try again', + // callback: () => { + // dispatch(acquire()) + // } + // } + // ] } }) } + + dispatch({ + type: CONNECT.STOP_ACQUIRING, + }) } } diff --git a/src/js/actions/constants/TrezorConnect.js b/src/js/actions/constants/TrezorConnect.js index 139c03fb..0e4f3cd7 100644 --- a/src/js/actions/constants/TrezorConnect.js +++ b/src/js/actions/constants/TrezorConnect.js @@ -22,4 +22,7 @@ export const REMEMBER: 'connect__remember' = 'connect__remember'; export const TRY_TO_DUPLICATE: 'connect__try_to_duplicate' = 'connect__try_to_duplicate'; export const DUPLICATE: 'connect__duplicate' = 'connect__duplicate'; -export const DEVICE_STATE_EXCEPTION: 'connect__device_state_exception' = 'connect__device_state_exception'; \ No newline at end of file +export const DEVICE_STATE_EXCEPTION: 'connect__device_state_exception' = 'connect__device_state_exception'; + +export const START_ACQUIRING: 'connect__start_acquiring' = 'connect__start_acquiring'; +export const STOP_ACQUIRING: 'connect__stop_acquiring' = 'connect__stop_acquiring'; \ No newline at end of file diff --git a/src/js/components/wallet/pages/Acquire.js b/src/js/components/wallet/pages/Acquire.js index 1412f3b1..4db6e048 100644 --- a/src/js/components/wallet/pages/Acquire.js +++ b/src/js/components/wallet/pages/Acquire.js @@ -9,13 +9,13 @@ import * as TrezorConnectActions from '~/js/actions/TrezorConnectActions'; import type { State, Dispatch } from '~/flowtype'; type Props = { - connect: $ElementType, + acquiring: boolean; acquireDevice: typeof TrezorConnectActions.acquire } const Acquire = (props: Props) => { - const actions = [ + const actions = props.acquiring ? [] : [ { label: 'Acquire device', callback: () => { @@ -40,7 +40,7 @@ const Acquire = (props: Props) => { export default connect( (state: State) => { return { - log: state.log + acquiring: state.connect.acquiring }; }, (dispatch: Dispatch) => { diff --git a/src/js/reducers/TrezorConnectReducer.js b/src/js/reducers/TrezorConnectReducer.js index f948e210..7c750f0b 100644 --- a/src/js/reducers/TrezorConnectReducer.js +++ b/src/js/reducers/TrezorConnectReducer.js @@ -30,6 +30,7 @@ export type State = { // mobile: boolean; // } | {}; browserState: any; + acquiring: boolean; } @@ -39,7 +40,8 @@ const initialState: State = { discoveryComplete: false, error: null, transport: null, - browserState: {} + browserState: {}, + acquiring: false, }; @@ -55,6 +57,17 @@ export default function connect(state: State = initialState, action: Action): St browserState: action.payload.browser } + case CONNECT.START_ACQUIRING : + return { + ...state, + acquiring: true + } + + case CONNECT.STOP_ACQUIRING : + return { + ...state, + acquiring: false + } case CONNECT.INITIALIZATION_ERROR : return {