1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-24 09:18:09 +00:00

renamed "acquiring" to "acquiringDevice" in connect reducer

This commit is contained in:
Szymon Lesisz 2018-10-02 10:05:51 +02:00
parent 49aa31774e
commit 2e4acf3ee8
5 changed files with 33 additions and 47 deletions

View File

@ -71,9 +71,7 @@ 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.START_ACQUIRING | typeof CONNECT.STOP_ACQUIRING,
} | {
type: typeof CONNECT.STOP_ACQUIRING,
}; };
export const init = (): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise<void> => { export const init = (): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
@ -128,10 +126,10 @@ export const init = (): AsyncAction => async (dispatch: Dispatch, getState: GetS
pendingTransportEvent: (getState().devices.length < 1), pendingTransportEvent: (getState().devices.length < 1),
}); });
} catch (error) { } catch (error) {
// dispatch({ dispatch({
// type: CONNECT.INITIALIZATION_ERROR, type: CONNECT.INITIALIZATION_ERROR,
// error error,
// }) });
} }
}; };

View File

@ -94,7 +94,6 @@ const addDevice = (state: State, device: Device): State => {
const newDevice: TrezorDevice = device.type === 'acquired' ? { const newDevice: TrezorDevice = device.type === 'acquired' ? {
...device, ...device,
// acquiring: false,
...extended, ...extended,
} : { } : {
...device, ...device,
@ -154,7 +153,6 @@ const duplicate = (state: State, device: TrezorDevice): State => {
const newDevice: TrezorDevice = { const newDevice: TrezorDevice = {
...device, ...device,
// acquiring: false,
remember: false, remember: false,
state: null, state: null,
// instance, (instance is already part of device - added in modal) // instance, (instance is already part of device - added in modal)

View File

@ -10,9 +10,7 @@ export type SelectedDevice = {
} }
export type State = { export type State = {
// devices: Array<TrezorDevice>; initialized: boolean;
// selectedDevice: ?SelectedDevice;
discoveryComplete: boolean;
error: ?string; error: ?string;
transport: ?{ transport: ?{
type: string; type: string;
@ -26,54 +24,42 @@ export type State = {
// mobile: boolean; // mobile: boolean;
// } | {}; // } | {};
browserState: any; browserState: any;
acquiring: boolean; acquiringDevice: boolean;
} }
const initialState: State = { const initialState: State = {
// devices: [], initialized: false,
//selectedDevice: null,
discoveryComplete: false,
error: null, error: null,
transport: null, transport: null,
browserState: {}, browserState: {},
acquiring: false, acquiringDevice: false,
}; };
export default function connect(state: State = initialState, action: Action): State { export default function connect(state: State = initialState, action: Action): State {
switch (action.type) { switch (action.type) {
case UI.IFRAME_HANDSHAKE: // trezor-connect iframe didn't loaded properly
return {
...state,
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 {
...state, ...state,
error: action.error, error: action.error,
}; };
// trezor-connect iframe loaded
case UI.IFRAME_HANDSHAKE:
return {
...state,
initialized: true,
browserState: action.payload.browser,
};
// trezor-connect (trezor-link) initialized
case TRANSPORT.START: case TRANSPORT.START:
return { return {
...state, ...state,
transport: action.payload, transport: action.payload,
error: null, error: null,
}; };
// trezor-connect (trezor-link)
// will be called continuously in interval until connection (bridge/webusb) will be established
case TRANSPORT.ERROR: case TRANSPORT.ERROR:
return { return {
...state, ...state,
@ -82,6 +68,17 @@ export default function connect(state: State = initialState, action: Action): St
transport: null, transport: null,
}; };
case CONNECT.START_ACQUIRING:
return {
...state,
acquiringDevice: true,
};
case CONNECT.STOP_ACQUIRING:
return {
...state,
acquiringDevice: false,
};
default: default:
return state; return state;

View File

@ -46,7 +46,7 @@ const Acquire = (props: Props) => {
export default connect( export default connect(
(state: State) => ({ (state: State) => ({
acquiring: state.connect.acquiring, acquiring: state.connect.acquiringDevice,
}), }),
(dispatch: Dispatch) => ({ (dispatch: Dispatch) => ({
acquireDevice: bindActionCreators(TrezorConnectActions.acquire, dispatch), acquireDevice: bindActionCreators(TrezorConnectActions.acquire, dispatch),

View File

@ -23,11 +23,4 @@ const UnreadableDevice = () => (
</Wrapper> </Wrapper>
); );
export default connect( export default connect(null, null)(UnreadableDevice);
(state: State) => ({
acquiring: state.connect.acquiring,
}),
(dispatch: Dispatch) => ({
acquireDevice: bindActionCreators(TrezorConnectActions.acquire, dispatch),
}),
)(UnreadableDevice);