mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-28 03:08:30 +00:00
modals onKeyboard enter actions
This commit is contained in:
parent
27ca8ed37a
commit
cefddd98b8
@ -1,7 +1,7 @@
|
|||||||
/* @flow */
|
/* @flow */
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
import React from 'react';
|
import React, { Component } from 'react';
|
||||||
import { findAccount } from '../../reducers/AccountsReducer';
|
import { findAccount } from '../../reducers/AccountsReducer';
|
||||||
import { findSelectedDevice } from '../../reducers/TrezorConnectReducer';
|
import { findSelectedDevice } from '../../reducers/TrezorConnectReducer';
|
||||||
|
|
||||||
@ -29,61 +29,80 @@ const ConfirmAddress = (props: Props) => {
|
|||||||
}
|
}
|
||||||
export default ConfirmAddress;
|
export default ConfirmAddress;
|
||||||
|
|
||||||
export const ConfirmUnverifiedAddress = (props: Props) => {
|
export class ConfirmUnverifiedAddress extends Component<Props> {
|
||||||
|
|
||||||
if (!props.modal.opened) return null;
|
keyboardHandler: (event: KeyboardEvent) => void;
|
||||||
const {
|
|
||||||
device
|
|
||||||
} = props.modal;
|
|
||||||
|
|
||||||
const { accounts, abstractAccount } = props;
|
keyboardHandler(event: KeyboardEvent): void {
|
||||||
|
if (event.keyCode === 13) {
|
||||||
|
event.preventDefault();
|
||||||
|
this.verifyAddress();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount(): void {
|
||||||
|
this.keyboardHandler = this.keyboardHandler.bind(this);
|
||||||
|
window.addEventListener('keydown', this.keyboardHandler, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount(): void {
|
||||||
|
window.removeEventListener('keydown', this.keyboardHandler, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
verifyAddress() {
|
||||||
|
if (!this.props.modal.opened) return;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
onCancel
|
accounts,
|
||||||
} = props.modalActions;
|
abstractAccount
|
||||||
|
} = this.props;
|
||||||
const {
|
|
||||||
showUnverifiedAddress,
|
|
||||||
showAddress
|
|
||||||
} = props.receiveActions;
|
|
||||||
|
|
||||||
if(!abstractAccount) return null;
|
if(!abstractAccount) return null;
|
||||||
|
|
||||||
const account = findAccount(accounts, abstractAccount.index, abstractAccount.deviceState, abstractAccount.network);
|
const account = findAccount(accounts, abstractAccount.index, abstractAccount.deviceState, abstractAccount.network);
|
||||||
if (!account) return null;
|
if (!account) return null;
|
||||||
|
|
||||||
|
this.props.modalActions.onCancel();
|
||||||
|
this.props.receiveActions.showAddress(account.addressPath);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
showUnverifiedAddress() {
|
||||||
|
if (!this.props.modal.opened) return;
|
||||||
|
|
||||||
|
this.props.modalActions.onCancel();
|
||||||
|
this.props.receiveActions.showUnverifiedAddress();
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
if (!this.props.modal.opened) return null;
|
||||||
|
const {
|
||||||
|
device
|
||||||
|
} = this.props.modal;
|
||||||
|
|
||||||
|
const {
|
||||||
|
onCancel
|
||||||
|
} = this.props.modalActions;
|
||||||
|
|
||||||
|
let deviceStatus: string;
|
||||||
|
let claim: string;
|
||||||
|
|
||||||
if (!device.connected) {
|
if (!device.connected) {
|
||||||
return (
|
deviceStatus = `${ device.label } is not connected`;
|
||||||
<div className="confirm-address-unverified">
|
claim = 'Please connect your device'
|
||||||
<button className="close-modal transparent" onClick={ onCancel }></button>
|
|
||||||
<h3>{ device.label } is not connected</h3>
|
|
||||||
<p>To prevent phishing attacks, you should verify the address on your TREZOR first. Please reconnect your device to continue with the verification process.</p>
|
|
||||||
<button onClick={ event => {
|
|
||||||
onCancel();
|
|
||||||
showAddress(account.addressPath);
|
|
||||||
} }>Try again</button>
|
|
||||||
<button className="white" onClick={ event => {
|
|
||||||
onCancel();
|
|
||||||
showUnverifiedAddress();
|
|
||||||
} }>Show unverified address</button>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
// corner-case where device is connected but it is unavailable because it was created with different "passphrase_protection" settings
|
// corner-case where device is connected but it is unavailable because it was created with different "passphrase_protection" settings
|
||||||
const enable: string = device.features && device.features.passphrase_protection ? 'Enable' : 'Disable';
|
const enable: string = device.features && device.features.passphrase_protection ? 'enable' : 'disable';
|
||||||
|
deviceStatus = `${ device.label } is unavailable`;
|
||||||
|
claim = `Please ${ enable } passphrase settings`;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="confirm-address-unverified">
|
<div className="confirm-address-unverified">
|
||||||
<button className="close-modal transparent" onClick={ onCancel }></button>
|
<button className="close-modal transparent" onClick={ onCancel }></button>
|
||||||
<h3>{ device.label } is unavailable</h3>
|
<h3>{ deviceStatus }</h3>
|
||||||
<p>To prevent phishing attacks, you should verify the address on your TREZOR first. { enable } passphrase settings to continue with the verification process.</p>
|
<p>To prevent phishing attacks, you should verify the address on your TREZOR first. { claim } to continue with the verification process.</p>
|
||||||
<button onClick={ event => {
|
<button onClick={ event => this.verifyAddress() }>Try again</button>
|
||||||
onCancel();
|
<button className="white" onClick={ event => this.showUnverifiedAddress() }>Show unverified address</button>
|
||||||
showAddress(account.addressPath);
|
|
||||||
} }>Try again</button>
|
|
||||||
<button className="white" onClick={ event => {
|
|
||||||
onCancel();
|
|
||||||
showUnverifiedAddress();
|
|
||||||
} }>Show unverified address</button>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ type State = {
|
|||||||
|
|
||||||
export default class DuplicateDevice extends Component<Props, State> {
|
export default class DuplicateDevice extends Component<Props, State> {
|
||||||
|
|
||||||
|
keyboardHandler: (event: KeyboardEvent) => void;
|
||||||
state: State;
|
state: State;
|
||||||
|
|
||||||
constructor(props: Props) {
|
constructor(props: Props) {
|
||||||
@ -28,12 +29,34 @@ export default class DuplicateDevice extends Component<Props, State> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
keyboardHandler(event: KeyboardEvent): void {
|
||||||
|
if (event.keyCode === 13) {
|
||||||
|
event.preventDefault();
|
||||||
|
this.submit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount(): void {
|
||||||
|
this.keyboardHandler = this.keyboardHandler.bind(this);
|
||||||
|
window.addEventListener('keydown', this.keyboardHandler, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount(): void {
|
||||||
|
window.removeEventListener('keydown', this.keyboardHandler, false);
|
||||||
|
}
|
||||||
|
|
||||||
onNameChange = (value: string): void => {
|
onNameChange = (value: string): void => {
|
||||||
this.setState({
|
this.setState({
|
||||||
instanceName: value.length > 0 ? value : null
|
instanceName: value.length > 0 ? value : null
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
submit() {
|
||||||
|
if (this.props.modal.opened) {
|
||||||
|
this.props.modalActions.onDuplicateDevice( { ...this.props.modal.device, instanceName: this.state.instanceName } );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|
||||||
if (!this.props.modal.opened) return null;
|
if (!this.props.modal.opened) return null;
|
||||||
@ -55,7 +78,7 @@ export default class DuplicateDevice extends Component<Props, State> {
|
|||||||
placeholder={ this.state.defaultName }
|
placeholder={ this.state.defaultName }
|
||||||
onChange={ event => this.onNameChange(event.currentTarget.value) }
|
onChange={ event => this.onNameChange(event.currentTarget.value) }
|
||||||
defaultValue={ this.state.instanceName } />
|
defaultValue={ this.state.instanceName } />
|
||||||
<button onClick={ event => onDuplicateDevice( { ...device, instanceName: this.state.instanceName } ) }>Create new instance</button>
|
<button onClick={ event => this.submit() }>Create new instance</button>
|
||||||
<button className="white" onClick={ onCancel }>Cancel</button>
|
<button className="white" onClick={ onCancel }>Cancel</button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -13,6 +13,7 @@ type State = {
|
|||||||
|
|
||||||
export default class RememberDevice extends Component<Props, State> {
|
export default class RememberDevice extends Component<Props, State> {
|
||||||
|
|
||||||
|
keyboardHandler: (event: KeyboardEvent) => void;
|
||||||
state: State;
|
state: State;
|
||||||
|
|
||||||
constructor(props: Props) {
|
constructor(props: Props) {
|
||||||
@ -21,9 +22,13 @@ export default class RememberDevice extends Component<Props, State> {
|
|||||||
this.state = {
|
this.state = {
|
||||||
countdown: 10,
|
countdown: 10,
|
||||||
}
|
}
|
||||||
// this.setState({
|
}
|
||||||
// countdown: 10
|
|
||||||
// });
|
keyboardHandler(event: KeyboardEvent): void {
|
||||||
|
if (event.keyCode === 13) {
|
||||||
|
event.preventDefault();
|
||||||
|
this.forget();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount(): void {
|
componentDidMount(): void {
|
||||||
@ -48,19 +53,23 @@ export default class RememberDevice extends Component<Props, State> {
|
|||||||
ticker: window.setInterval(ticker, 1000)
|
ticker: window.setInterval(ticker, 1000)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.keyboardHandler = this.keyboardHandler.bind(this);
|
||||||
|
window.addEventListener('keydown', this.keyboardHandler, false);
|
||||||
//this.keyboardHandler = this.keyboardHandler.bind(this);
|
|
||||||
//window.addEventListener('keydown', this.keyboardHandler, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount(): void {
|
componentWillUnmount(): void {
|
||||||
//window.removeEventListener('keydown', this.keyboardHandler, false);
|
window.removeEventListener('keydown', this.keyboardHandler, false);
|
||||||
if (this.state.ticker) {
|
if (this.state.ticker) {
|
||||||
window.clearInterval(this.state.ticker);
|
window.clearInterval(this.state.ticker);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
forget() {
|
||||||
|
if (this.props.modal.opened) {
|
||||||
|
this.props.modalActions.onForgetDevice(this.props.modal.device);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
if (!this.props.modal.opened) return null;
|
if (!this.props.modal.opened) return null;
|
||||||
const { device, instances } = this.props.modal;
|
const { device, instances } = this.props.modal;
|
||||||
@ -81,23 +90,50 @@ export default class RememberDevice extends Component<Props, State> {
|
|||||||
<div className="remember">
|
<div className="remember">
|
||||||
<h3>Forget {label}?</h3>
|
<h3>Forget {label}?</h3>
|
||||||
<p>Would you like TREZOR Wallet to forget your { devicePlural }, so that it is still visible even while disconnected?</p>
|
<p>Would you like TREZOR Wallet to forget your { devicePlural }, so that it is still visible even while disconnected?</p>
|
||||||
<button onClick={ event => onForgetDevice(device) }>Forget</button>
|
<button onClick={ event => this.forget() }>Forget</button>
|
||||||
<button className="white" onClick={ event => onRememberDevice(device) }><span>Remember <Loader size="28" label={ this.state.countdown.toString() } /></span></button>
|
<button className="white" onClick={ event => onRememberDevice(device) }><span>Remember <Loader size="28" label={ this.state.countdown.toString() } /></span></button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ForgetDevice = (props: Props) => {
|
export class ForgetDevice extends Component<Props> {
|
||||||
if (!props.modal.opened) return null;
|
|
||||||
const { device } = props.modal;
|
keyboardHandler: (event: KeyboardEvent) => void;
|
||||||
const { onForgetSingleDevice, onCancel } = props.modalActions;
|
|
||||||
|
keyboardHandler(event: KeyboardEvent): void {
|
||||||
|
if (event.keyCode === 13) {
|
||||||
|
event.preventDefault();
|
||||||
|
this.forget();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount(): void {
|
||||||
|
this.keyboardHandler = this.keyboardHandler.bind(this);
|
||||||
|
window.addEventListener('keydown', this.keyboardHandler, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount(): void {
|
||||||
|
window.removeEventListener('keydown', this.keyboardHandler, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
forget() {
|
||||||
|
if (this.props.modal.opened) {
|
||||||
|
this.props.modalActions.onForgetSingleDevice(this.props.modal.device);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
if (!this.props.modal.opened) return null;
|
||||||
|
const { device } = this.props.modal;
|
||||||
|
const { onCancel } = this.props.modalActions;
|
||||||
return (
|
return (
|
||||||
<div className="remember">
|
<div className="remember">
|
||||||
<h3>Forget { device.instanceLabel } ?</h3>
|
<h3>Forget { device.instanceLabel } ?</h3>
|
||||||
<p>Forgetting only removes the device from the list on the left, your coins are still safe and you can access them by reconnecting your TREZOR again.</p>
|
<p>Forgetting only removes the device from the list on the left, your coins are still safe and you can access them by reconnecting your TREZOR again.</p>
|
||||||
<button onClick={ (event) => onForgetSingleDevice(device) }>Forget</button>
|
<button onClick={ event => this.forget() }>Forget</button>
|
||||||
<button className="white" onClick={ onCancel }>Don't forget</button>
|
<button className="white" onClick={ onCancel }>Don't forget</button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user