mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-24 01:08:27 +00:00
new actions: request and receive wallet type
This commit is contained in:
parent
3183426137
commit
291e771a6b
@ -71,6 +71,13 @@ export type TrezorConnectAction = {
|
||||
payload: Array<TrezorDevice>
|
||||
} | {
|
||||
type: typeof CONNECT.START_ACQUIRING | typeof CONNECT.STOP_ACQUIRING,
|
||||
} | {
|
||||
type: typeof CONNECT.REQUEST_WALLET_TYPE,
|
||||
device: TrezorDevice
|
||||
} | {
|
||||
type: typeof CONNECT.RECEIVE_WALLET_TYPE,
|
||||
device: TrezorDevice,
|
||||
hidden: boolean,
|
||||
};
|
||||
|
||||
export const init = (): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
||||
@ -152,7 +159,19 @@ export const postInit = (): ThunkAction => (dispatch: Dispatch): void => {
|
||||
}
|
||||
};
|
||||
|
||||
export const getSelectedDeviceState = (): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
||||
export const requestWalletType = (): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
||||
const selected = getState().wallet.selectedDevice;
|
||||
if (!selected) return;
|
||||
const isDeviceReady = selected.connected && selected.features && !selected.state && selected.mode === 'normal' && selected.firmware !== 'required';
|
||||
if (!isDeviceReady) return;
|
||||
|
||||
dispatch({
|
||||
type: CONNECT.REQUEST_WALLET_TYPE,
|
||||
device: selected,
|
||||
});
|
||||
};
|
||||
|
||||
export const authorizeDevice = (): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
||||
const selected = getState().wallet.selectedDevice;
|
||||
if (!selected) return;
|
||||
const isDeviceReady = selected.connected && selected.features && !selected.state && selected.mode === 'normal' && selected.firmware !== 'required';
|
||||
@ -164,7 +183,7 @@ export const getSelectedDeviceState = (): AsyncAction => async (dispatch: Dispat
|
||||
instance: selected.instance,
|
||||
state: selected.state,
|
||||
},
|
||||
useEmptyPassphrase: !selected.instance,
|
||||
useEmptyPassphrase: selected.useEmptyPassphrase,
|
||||
});
|
||||
|
||||
if (response && response.success) {
|
||||
@ -190,14 +209,13 @@ export const getSelectedDeviceState = (): AsyncAction => async (dispatch: Dispat
|
||||
type: NOTIFICATION.CLOSE,
|
||||
payload: { devicePath: selected.path },
|
||||
});
|
||||
dispatch(getSelectedDeviceState());
|
||||
dispatch(authorizeDevice());
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
export const deviceDisconnect = (device: Device): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
||||
@ -231,11 +249,14 @@ export function acquire(): AsyncAction {
|
||||
type: CONNECT.START_ACQUIRING,
|
||||
});
|
||||
|
||||
// this is the only place where useEmptyPassphrase should be used every time
|
||||
// the goal here is to acquire device and get his features
|
||||
// authentication (passphrase) is not needed here yet
|
||||
const response = await TrezorConnect.getFeatures({
|
||||
device: {
|
||||
path: selected.path,
|
||||
},
|
||||
useEmptyPassphrase: !selected.instance,
|
||||
useEmptyPassphrase: true,
|
||||
});
|
||||
|
||||
if (!response.success) {
|
||||
@ -270,7 +291,7 @@ export const forget = (device: TrezorDevice): Action => ({
|
||||
device,
|
||||
});
|
||||
|
||||
export const duplicateDevice = (device: TrezorDevice): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
||||
export const duplicateDevice1 = (device: TrezorDevice): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
||||
// dispatch({
|
||||
// type: CONNECT.TRY_TO_DUPLICATE,
|
||||
// device,
|
||||
@ -283,3 +304,15 @@ export const duplicateDevice = (device: TrezorDevice): AsyncAction => async (dis
|
||||
device: { ...device, ...extended },
|
||||
});
|
||||
};
|
||||
|
||||
export const duplicateDevice = (device: TrezorDevice): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
||||
// dispatch({
|
||||
// type: CONNECT.TRY_TO_DUPLICATE,
|
||||
// device,
|
||||
// });
|
||||
|
||||
dispatch({
|
||||
type: CONNECT.REQUEST_WALLET_TYPE,
|
||||
device,
|
||||
});
|
||||
};
|
||||
|
@ -87,6 +87,7 @@ export const clearUnavailableDevicesData = (prevState: State, device: Device): T
|
||||
const actions = [
|
||||
LOCATION_CHANGE,
|
||||
CONNECT.AUTH_DEVICE,
|
||||
CONNECT.RECEIVE_WALLET_TYPE,
|
||||
...Object.values(DEVICE).filter(v => typeof v === 'string'),
|
||||
];
|
||||
|
||||
|
@ -25,4 +25,7 @@ export const DUPLICATE: 'connect__duplicate' = 'connect__duplicate';
|
||||
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';
|
||||
export const STOP_ACQUIRING: 'connect__stop_acquiring' = 'connect__stop_acquiring';
|
||||
|
||||
export const REQUEST_WALLET_TYPE: 'connect__request_wallet_type' = 'connect__request_wallet_type';
|
||||
export const RECEIVE_WALLET_TYPE: 'connect__receive_wallet_type' = 'connect__receive_wallet_type';
|
@ -49,10 +49,9 @@ const WalletService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispa
|
||||
api.dispatch(LocalStorageActions.loadData());
|
||||
break;
|
||||
case WALLET.SET_SELECTED_DEVICE:
|
||||
if (action.device) {
|
||||
// try to authorize device
|
||||
api.dispatch(TrezorConnectActions.getSelectedDeviceState());
|
||||
}
|
||||
// try to authorize device
|
||||
// api.dispatch(TrezorConnectActions.authorizeDevice());
|
||||
api.dispatch(TrezorConnectActions.requestWalletType());
|
||||
break;
|
||||
case DEVICE.CONNECT:
|
||||
api.dispatch(WalletActions.clearUnavailableDevicesData(prevState, action.device));
|
||||
@ -102,10 +101,18 @@ const WalletService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispa
|
||||
// if "selectedAccount" didn't change observe send form props changes
|
||||
api.dispatch(SendFormActionActions.observe(prevState, action));
|
||||
}
|
||||
} else if (action.type === CONNECT.AUTH_DEVICE) {
|
||||
// selected device did changed
|
||||
// try to restore discovery after device authentication
|
||||
api.dispatch(DiscoveryActions.restore());
|
||||
} else {
|
||||
switch (action.type) {
|
||||
case CONNECT.AUTH_DEVICE:
|
||||
// selected device did changed
|
||||
// try to restore discovery after device authentication
|
||||
api.dispatch(DiscoveryActions.restore());
|
||||
break;
|
||||
case CONNECT.RECEIVE_WALLET_TYPE:
|
||||
api.dispatch(TrezorConnectActions.authorizeDevice());
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
// even if "selectedDevice" didn't change because it was updated on DEVICE.CHANGED before DEVICE.CONNECT action
|
||||
|
Loading…
Reference in New Issue
Block a user