wallet type from passphrase modal

- added new action "CONNECT.UPDATE_WALLET_TYPE" to update DeviceReducer
- pass device straight from action getState() instead of param of this action
- replace switch with if
pull/230/head
Szymon Lesisz 6 years ago
parent bdf1a1d409
commit 474871d375

@ -25,7 +25,19 @@ export const onPinSubmit = (value: string): Action => {
}; };
}; };
export const onPassphraseSubmit = (passphrase: string): AsyncAction => async (dispatch: Dispatch): Promise<void> => { export const onPassphraseSubmit = (passphrase: string): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
const { modal } = getState();
if (modal.context !== MODAL.CONTEXT_DEVICE) return;
if (passphrase === '') {
// set standard wallet type if passphrase is blank
dispatch({
type: CONNECT.UPDATE_WALLET_TYPE,
device: modal.device,
hidden: false,
});
}
await TrezorConnect.uiResponse({ await TrezorConnect.uiResponse({
type: UI.RECEIVE_PASSPHRASE, type: UI.RECEIVE_PASSPHRASE,
payload: { payload: {
@ -106,15 +118,16 @@ export const onDeviceConnect = (device: Device): ThunkAction => (dispatch: Dispa
} }
}; };
export const onWalletTypeRequest = (device: TrezorDevice, hidden: boolean, state: ?string): ThunkAction => (dispatch: Dispatch): void => { export const onWalletTypeRequest = (hidden: boolean): ThunkAction => (dispatch: Dispatch, getState: GetState): void => {
const { modal } = getState();
if (modal.context !== MODAL.CONTEXT_DEVICE) return;
dispatch({ dispatch({
type: MODAL.CLOSE, type: MODAL.CLOSE,
}); });
dispatch({ dispatch({
type: CONNECT.RECEIVE_WALLET_TYPE, type: CONNECT.RECEIVE_WALLET_TYPE,
device, device: modal.device,
hidden, hidden,
state,
}); });
}; };
@ -129,7 +142,6 @@ export const gotoExternalWallet = (id: string, url: string): ThunkAction => (dis
export default { export default {
onPinSubmit, onPinSubmit,
onPassphraseSubmit, onPassphraseSubmit,
// askForRemember,
onRememberDevice, onRememberDevice,
onForgetDevice, onForgetDevice,
onForgetSingleDevice, onForgetSingleDevice,

@ -78,10 +78,9 @@ export type TrezorConnectAction = {
type: typeof CONNECT.REQUEST_WALLET_TYPE, type: typeof CONNECT.REQUEST_WALLET_TYPE,
device: TrezorDevice device: TrezorDevice
} | { } | {
type: typeof CONNECT.RECEIVE_WALLET_TYPE, type: typeof CONNECT.RECEIVE_WALLET_TYPE | typeof CONNECT.UPDATE_WALLET_TYPE,
device: TrezorDevice, device: TrezorDevice,
hidden: boolean, hidden: boolean,
state: ?string,
}; };
declare var LOCAL: ?string; declare var LOCAL: ?string;

@ -29,4 +29,5 @@ export const START_ACQUIRING: 'connect__start_acquiring' = 'connect__start_acqui
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 REQUEST_WALLET_TYPE: 'connect__request_wallet_type' = 'connect__request_wallet_type';
export const RECEIVE_WALLET_TYPE: 'connect__receive_wallet_type' = 'connect__receive_wallet_type'; export const RECEIVE_WALLET_TYPE: 'connect__receive_wallet_type' = 'connect__receive_wallet_type';
export const UPDATE_WALLET_TYPE: 'connect__update_wallet_type' = 'connect__update_wallet_type';

@ -91,18 +91,14 @@ class WalletType extends PureComponent<Props> {
keyboardHandler(event: KeyboardEvent): void { keyboardHandler(event: KeyboardEvent): void {
if (event.keyCode === 13) { if (event.keyCode === 13) {
event.preventDefault(); event.preventDefault();
this.changeType(false); this.props.onWalletTypeRequest(false);
} }
} }
keyboardHandler: (event: KeyboardEvent) => void; keyboardHandler: (event: KeyboardEvent) => void;
changeType(hidden: boolean, state: ?string) {
this.props.onWalletTypeRequest(this.props.device, hidden, state);
}
render() { render() {
const { device, onCancel } = this.props; const { device, onCancel, onWalletTypeRequest } = this.props;
return ( return (
<Wrapper> <Wrapper>
@ -122,7 +118,7 @@ class WalletType extends PureComponent<Props> {
Standard Wallet Standard Wallet
</Header> </Header>
<P isSmaller>Continue to access your standard wallet.</P> <P isSmaller>Continue to access your standard wallet.</P>
<StyledButton onClick={() => this.changeType(false, device.state)}>Go to your standard wallet</StyledButton> <StyledButton onClick={() => onWalletTypeRequest(false)}>Go to your standard wallet</StyledButton>
</Content> </Content>
<Content> <Content>
<Tooltip <Tooltip
@ -146,7 +142,7 @@ class WalletType extends PureComponent<Props> {
Hidden Wallet Hidden Wallet
</Header> </Header>
<P isSmaller>You will be asked to enter your passphrase to unlock your hidden wallet.</P> <P isSmaller>You will be asked to enter your passphrase to unlock your hidden wallet.</P>
<StyledButton isWhite onClick={() => this.changeType(true, device.state)}>Go to your hidden wallet</StyledButton> <StyledButton isWhite onClick={() => onWalletTypeRequest(true)}>Go to your hidden wallet</StyledButton>
</Content> </Content>
</Wrapper> </Wrapper>
); );

@ -317,6 +317,7 @@ export default function devices(state: State = initialState, action: Action): St
return onSelectedDevice(state, action.device); return onSelectedDevice(state, action.device);
case CONNECT.RECEIVE_WALLET_TYPE: case CONNECT.RECEIVE_WALLET_TYPE:
case CONNECT.UPDATE_WALLET_TYPE:
return onChangeWalletType(state, action.device, action.hidden); return onChangeWalletType(state, action.device, action.hidden);
default: default:

@ -105,22 +105,22 @@ const WalletService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispa
api.dispatch(SendFormActionActions.observe(prevState, action)); api.dispatch(SendFormActionActions.observe(prevState, action));
} }
} else { } else {
switch (action.type) { // no changes in common values
case CONNECT.AUTH_DEVICE: if (action.type === CONNECT.RECEIVE_WALLET_TYPE) {
// selected device did changed if (action.device.state) {
// try to restore discovery after device authentication // redirect to root view (Dashboard) if device was authenticated before
api.dispatch(DiscoveryActions.restore()); api.dispatch(RouterActions.selectFirstAvailableDevice(true));
break; }
case CONNECT.RECEIVE_WALLET_TYPE: api.dispatch(TrezorConnectActions.authorizeDevice());
if (action.state) { }
api.dispatch(RouterActions.selectFirstAvailableDevice(true)); if (action.type === CONNECT.AUTH_DEVICE) {
} // selected device did changed
api.dispatch(TrezorConnectActions.authorizeDevice()); // try to restore discovery after device authentication
break; api.dispatch(DiscoveryActions.restore());
default: break;
} }
} }
// even if "selectedDevice" didn't change because it was updated on DEVICE.CHANGED before DEVICE.CONNECT action // even if "selectedDevice" didn't change because it was updated on DEVICE.CHANGED before DEVICE.CONNECT action
// try to restore discovery // try to restore discovery
if (action.type === DEVICE.CONNECT) { if (action.type === DEVICE.CONNECT) {

Loading…
Cancel
Save