START/STOP_ACQUIRING (Acquire page)

pull/2/merge
Szymon Lesisz 6 years ago
parent 369ca892c0
commit 2b4592343e

@ -74,6 +74,10 @@ export type TrezorConnectAction = {
} | { } | {
type: typeof CONNECT.DEVICE_FROM_STORAGE, type: typeof CONNECT.DEVICE_FROM_STORAGE,
payload: Array<TrezorDevice> payload: Array<TrezorDevice>
} | {
type: typeof CONNECT.START_ACQUIRING,
} | {
type: typeof CONNECT.STOP_ACQUIRING,
}; };
@ -366,6 +370,10 @@ export function acquire(): AsyncAction {
const selected: ?TrezorDevice = getState().wallet.selectedDevice; const selected: ?TrezorDevice = getState().wallet.selectedDevice;
if (!selected) return; if (!selected) return;
dispatch({
type: CONNECT.START_ACQUIRING,
})
const response = await TrezorConnect.getFeatures({ const response = await TrezorConnect.getFeatures({
device: { device: {
path: selected.path, path: selected.path,
@ -381,17 +389,21 @@ export function acquire(): AsyncAction {
title: 'Acquire device error', title: 'Acquire device error',
message: response.payload.error, message: response.payload.error,
cancelable: true, cancelable: true,
actions: [ // actions: [
{ // {
label: 'Try again', // label: 'Try again',
callback: () => { // callback: () => {
dispatch(acquire()) // dispatch(acquire())
} // }
} // }
] // ]
} }
}) })
} }
dispatch({
type: CONNECT.STOP_ACQUIRING,
})
} }
} }

@ -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 TRY_TO_DUPLICATE: 'connect__try_to_duplicate' = 'connect__try_to_duplicate';
export const DUPLICATE: 'connect__duplicate' = 'connect__duplicate'; export const DUPLICATE: 'connect__duplicate' = 'connect__duplicate';
export const DEVICE_STATE_EXCEPTION: 'connect__device_state_exception' = 'connect__device_state_exception'; 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';

@ -9,13 +9,13 @@ import * as TrezorConnectActions from '~/js/actions/TrezorConnectActions';
import type { State, Dispatch } from '~/flowtype'; import type { State, Dispatch } from '~/flowtype';
type Props = { type Props = {
connect: $ElementType<State, 'connect'>, acquiring: boolean;
acquireDevice: typeof TrezorConnectActions.acquire acquireDevice: typeof TrezorConnectActions.acquire
} }
const Acquire = (props: Props) => { const Acquire = (props: Props) => {
const actions = [ const actions = props.acquiring ? [] : [
{ {
label: 'Acquire device', label: 'Acquire device',
callback: () => { callback: () => {
@ -40,7 +40,7 @@ const Acquire = (props: Props) => {
export default connect( export default connect(
(state: State) => { (state: State) => {
return { return {
log: state.log acquiring: state.connect.acquiring
}; };
}, },
(dispatch: Dispatch) => { (dispatch: Dispatch) => {

@ -30,6 +30,7 @@ export type State = {
// mobile: boolean; // mobile: boolean;
// } | {}; // } | {};
browserState: any; browserState: any;
acquiring: boolean;
} }
@ -39,7 +40,8 @@ const initialState: State = {
discoveryComplete: false, discoveryComplete: false,
error: null, error: null,
transport: 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 browserState: action.payload.browser
} }
case CONNECT.START_ACQUIRING :
return {
...state,
acquiring: true
}
case CONNECT.STOP_ACQUIRING :
return {
...state,
acquiring: false
}
case CONNECT.INITIALIZATION_ERROR : case CONNECT.INITIALIZATION_ERROR :
return { return {

Loading…
Cancel
Save