mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-30 20:28:09 +00:00
Simplify actions with modals
This commit is contained in:
parent
f738d0be9c
commit
8ed59317c7
@ -7,16 +7,10 @@ import * as NOTIFICATION from 'actions/constants/notification';
|
|||||||
import * as SIGN_VERIFY from './constants/signVerify';
|
import * as SIGN_VERIFY from './constants/signVerify';
|
||||||
|
|
||||||
export type SignVerifyAction = {
|
export type SignVerifyAction = {
|
||||||
type: typeof SIGN_VERIFY.SIGN_PROGRESS,
|
|
||||||
isSignProgress: boolean
|
|
||||||
} | {
|
|
||||||
type: typeof SIGN_VERIFY.SIGN_SUCCESS,
|
type: typeof SIGN_VERIFY.SIGN_SUCCESS,
|
||||||
signature: string
|
signature: string
|
||||||
} | {
|
} | {
|
||||||
type: typeof SIGN_VERIFY.VERIFY_PROGRESS,
|
type: typeof SIGN_VERIFY.CLEAR,
|
||||||
isVerifyProgress: boolean
|
|
||||||
} | {
|
|
||||||
type: typeof SIGN_VERIFY.CLEAR
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const sign = (
|
export const sign = (
|
||||||
@ -27,8 +21,6 @@ export const sign = (
|
|||||||
const selected = getState().wallet.selectedDevice;
|
const selected = getState().wallet.selectedDevice;
|
||||||
if (!selected) return;
|
if (!selected) return;
|
||||||
|
|
||||||
dispatch({ type: SIGN_VERIFY.SIGN_PROGRESS, isSignProgress: true });
|
|
||||||
|
|
||||||
const response = await TrezorConnect.ethereumSignMessage({
|
const response = await TrezorConnect.ethereumSignMessage({
|
||||||
device: {
|
device: {
|
||||||
path: selected.path,
|
path: selected.path,
|
||||||
@ -41,8 +33,6 @@ export const sign = (
|
|||||||
useEmptyPassphrase: selected.useEmptyPassphrase,
|
useEmptyPassphrase: selected.useEmptyPassphrase,
|
||||||
});
|
});
|
||||||
|
|
||||||
dispatch({ type: SIGN_VERIFY.SIGN_PROGRESS, isSignProgress: false });
|
|
||||||
|
|
||||||
if (response && response.success) {
|
if (response && response.success) {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: SIGN_VERIFY.SIGN_SUCCESS,
|
type: SIGN_VERIFY.SIGN_SUCCESS,
|
||||||
@ -77,8 +67,6 @@ export const verify = (
|
|||||||
const selected = getState().wallet.selectedDevice;
|
const selected = getState().wallet.selectedDevice;
|
||||||
if (!selected) return;
|
if (!selected) return;
|
||||||
|
|
||||||
dispatch({ type: SIGN_VERIFY.VERIFY_PROGRESS, isVerifyProgress: true });
|
|
||||||
|
|
||||||
const response = await TrezorConnect.ethereumVerifyMessage({
|
const response = await TrezorConnect.ethereumVerifyMessage({
|
||||||
device: {
|
device: {
|
||||||
path: selected.path,
|
path: selected.path,
|
||||||
@ -92,8 +80,6 @@ export const verify = (
|
|||||||
useEmptyPassphrase: selected.useEmptyPassphrase,
|
useEmptyPassphrase: selected.useEmptyPassphrase,
|
||||||
});
|
});
|
||||||
|
|
||||||
dispatch({ type: SIGN_VERIFY.VERIFY_PROGRESS, isVerifyProgress: false });
|
|
||||||
|
|
||||||
if (response && response.success) {
|
if (response && response.success) {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: NOTIFICATION.ADD,
|
type: NOTIFICATION.ADD,
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
/* @flow */
|
/* @flow */
|
||||||
export const SIGN_SUCCESS: 'sign__verify__sign__success' = 'sign__verify__sign__success';
|
export const SIGN_SUCCESS: 'sign__verify__sign__success' = 'sign__verify__sign__success';
|
||||||
export const SIGN_PROGRESS: 'sign__verify__sign_progress' = 'sign__verify__sign_progress';
|
|
||||||
export const VERIFY_PROGRESS: 'sign__verify__verify_progress' = 'sign__verify__verify_progress';
|
|
||||||
export const CLEAR: 'sign__verify__sign__clear' = 'sign__verify__sign__clear';
|
export const CLEAR: 'sign__verify__sign__clear' = 'sign__verify__sign__clear';
|
@ -228,7 +228,7 @@ Input.propTypes = {
|
|||||||
sideAddons: PropTypes.arrayOf(PropTypes.node),
|
sideAddons: PropTypes.arrayOf(PropTypes.node),
|
||||||
isDisabled: PropTypes.bool,
|
isDisabled: PropTypes.bool,
|
||||||
name: PropTypes.string,
|
name: PropTypes.string,
|
||||||
isSmallText: PropTypes.string,
|
isSmallText: PropTypes.bool,
|
||||||
isPartiallyHidden: PropTypes.bool,
|
isPartiallyHidden: PropTypes.bool,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ const ModalWindow = styled.div`
|
|||||||
const getDeviceContextModal = (props: Props) => {
|
const getDeviceContextModal = (props: Props) => {
|
||||||
const { modal, modalActions } = props;
|
const { modal, modalActions } = props;
|
||||||
if (modal.context !== MODAL.CONTEXT_DEVICE) return null;
|
if (modal.context !== MODAL.CONTEXT_DEVICE) return null;
|
||||||
|
console.log('modal.windowType', modal.windowType);
|
||||||
switch (modal.windowType) {
|
switch (modal.windowType) {
|
||||||
case UI.REQUEST_PIN:
|
case UI.REQUEST_PIN:
|
||||||
return (
|
return (
|
||||||
@ -91,6 +91,9 @@ const getDeviceContextModal = (props: Props) => {
|
|||||||
case 'ButtonRequest_SignTx':
|
case 'ButtonRequest_SignTx':
|
||||||
return <ConfirmSignTx device={modal.device} sendForm={props.sendForm} />;
|
return <ConfirmSignTx device={modal.device} sendForm={props.sendForm} />;
|
||||||
|
|
||||||
|
case 'ButtonRequest_ProtectCall':
|
||||||
|
return <ConfirmAction />;
|
||||||
|
|
||||||
case 'ButtonRequest_Other':
|
case 'ButtonRequest_Other':
|
||||||
return <ConfirmAction />;
|
return <ConfirmAction />;
|
||||||
|
|
||||||
|
@ -3,37 +3,21 @@ import type { Action } from 'flowtype';
|
|||||||
import * as SIGN_VERIFY from '../actions/constants/signVerify';
|
import * as SIGN_VERIFY from '../actions/constants/signVerify';
|
||||||
|
|
||||||
export type State = {
|
export type State = {
|
||||||
signature: string;
|
signature: string
|
||||||
isSignProgress: boolean;
|
|
||||||
isVerifyProgress: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const initialState: State = {
|
export const initialState: State = {
|
||||||
signature: '',
|
signature: '',
|
||||||
isSignProgress: false,
|
|
||||||
isVerifyProgress: false,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default (state: State = initialState, action: Action): State => {
|
export default (state: State = initialState, action: Action): State => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case SIGN_VERIFY.SIGN_PROGRESS:
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
isSignProgress: action.isSignProgress,
|
|
||||||
};
|
|
||||||
|
|
||||||
case SIGN_VERIFY.SIGN_SUCCESS:
|
case SIGN_VERIFY.SIGN_SUCCESS:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
signature: action.signature,
|
signature: action.signature,
|
||||||
};
|
};
|
||||||
|
|
||||||
case SIGN_VERIFY.VERIFY_PROGRESS:
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
isVerifyProgress: action.isVerifyProgress,
|
|
||||||
};
|
|
||||||
|
|
||||||
case SIGN_VERIFY.CLEAR:
|
case SIGN_VERIFY.CLEAR:
|
||||||
return {
|
return {
|
||||||
...initialState,
|
...initialState,
|
||||||
|
@ -14,8 +14,6 @@ export type StateProps = {
|
|||||||
wallet: $ElementType<State, 'wallet'>,
|
wallet: $ElementType<State, 'wallet'>,
|
||||||
selectedAccount: $ElementType<State, 'selectedAccount'>,
|
selectedAccount: $ElementType<State, 'selectedAccount'>,
|
||||||
signature: string,
|
signature: string,
|
||||||
isSignProgress: boolean,
|
|
||||||
isVerifyProgress: boolean
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type DispatchProps = {
|
export type DispatchProps = {
|
||||||
@ -28,8 +26,6 @@ const mapStateToProps: MapStateToProps<State, OwnProps, StateProps> = (state: St
|
|||||||
wallet: state.wallet,
|
wallet: state.wallet,
|
||||||
selectedAccount: state.selectedAccount,
|
selectedAccount: state.selectedAccount,
|
||||||
signature: state.signVerifyReducer.signature,
|
signature: state.signVerifyReducer.signature,
|
||||||
isSignProgress: state.signVerifyReducer.isSignProgress,
|
|
||||||
isVerifyProgress: state.signVerifyReducer.isVerifyProgress,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const mapDispatchToProps: MapDispatchToProps<Dispatch, OwnProps, DispatchProps> = (dispatch: Dispatch): DispatchProps => ({
|
const mapDispatchToProps: MapDispatchToProps<Dispatch, OwnProps, DispatchProps> = (dispatch: Dispatch): DispatchProps => ({
|
||||||
|
@ -69,15 +69,6 @@ class SignVerify extends Component<Props, State> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
getAddress() {
|
|
||||||
let result = null;
|
|
||||||
const { selectedAccount } = this.props;
|
|
||||||
if (selectedAccount.account && selectedAccount.account.address) {
|
|
||||||
result = selectedAccount.account.address;
|
|
||||||
}
|
|
||||||
return result || 'loading...';
|
|
||||||
}
|
|
||||||
|
|
||||||
handleInputChange = (event: SyntheticInputEvent<Text>) => {
|
handleInputChange = (event: SyntheticInputEvent<Text>) => {
|
||||||
this.setState({ [event.target.name]: event.target.value });
|
this.setState({ [event.target.name]: event.target.value });
|
||||||
}
|
}
|
||||||
@ -120,7 +111,7 @@ class SignVerify extends Component<Props, State> {
|
|||||||
<Label>Address</Label>
|
<Label>Address</Label>
|
||||||
<Input
|
<Input
|
||||||
name="signAddress"
|
name="signAddress"
|
||||||
value={this.getAddress()}
|
value={account.address}
|
||||||
height={50}
|
height={50}
|
||||||
type="text"
|
type="text"
|
||||||
isSmallText
|
isSmallText
|
||||||
@ -156,7 +147,7 @@ class SignVerify extends Component<Props, State> {
|
|||||||
>Clear
|
>Clear
|
||||||
</Button>
|
</Button>
|
||||||
<StyledButton
|
<StyledButton
|
||||||
onClick={() => signVerifyActions.sign(this.props.selectedAccount.account.addressPath, this.state.signMessage)}
|
onClick={() => signVerifyActions.sign(account.addressPath, this.state.signMessage)}
|
||||||
>Sign
|
>Sign
|
||||||
</StyledButton>
|
</StyledButton>
|
||||||
</RowButtons>
|
</RowButtons>
|
||||||
|
Loading…
Reference in New Issue
Block a user