1
0
mirror of https://github.com/trezor/trezor-wallet synced 2025-03-12 06:36:04 +00:00
trezor-wallet/src/js/components/modal/Pin.js

146 lines
4.7 KiB
JavaScript
Raw Normal View History

2017-12-13 11:01:37 +00:00
/* @flow */
'use strict';
2018-04-16 21:19:50 +00:00
import React, { Component } from 'react';
2017-12-13 11:01:37 +00:00
2018-04-16 21:19:50 +00:00
import type { Props } from './index';
2018-02-20 09:30:36 +00:00
type State = {
pin: string;
}
2018-04-16 21:19:50 +00:00
export default class Pin extends Component<Props, State> {
2017-12-13 11:01:37 +00:00
2018-04-16 21:19:50 +00:00
keyboardHandler: (event: KeyboardEvent) => void;
2018-02-20 09:30:36 +00:00
state: State;
2018-04-16 21:19:50 +00:00
constructor(props: Props) {
2018-02-20 09:30:36 +00:00
super(props);
this.state = {
pin: '',
}
2017-12-13 11:01:37 +00:00
}
2018-02-20 09:30:36 +00:00
onPinAdd = (input: number): void => {
let pin: string = this.state.pin;
if (pin.length < 9) {
pin += input;
this.setState({
pin: pin
});
}
}
onPinBackspace = (): void => {
this.setState({
pin: this.state.pin.substring(0, this.state.pin.length - 1),
});
2017-12-13 11:01:37 +00:00
}
keyboardHandler(event: KeyboardEvent): void {
2018-04-16 21:19:50 +00:00
const { onPinSubmit } = this.props.modalActions;
2018-02-20 09:30:36 +00:00
const { pin } = this.state;
2017-12-13 11:01:37 +00:00
event.preventDefault();
switch (event.keyCode) {
case 13 :
// enter,
onPinSubmit(pin);
break;
// backspace
case 8 :
2018-02-20 09:30:36 +00:00
this.onPinBackspace();
2017-12-13 11:01:37 +00:00
break;
// numeric and numpad
case 49 :
case 97 :
2018-02-20 09:30:36 +00:00
this.onPinAdd(1);
2017-12-13 11:01:37 +00:00
break;
case 50 :
case 98 :
2018-02-20 09:30:36 +00:00
this.onPinAdd(2);
2017-12-13 11:01:37 +00:00
break;
case 51 :
case 99 :
2018-02-20 09:30:36 +00:00
this.onPinAdd(3);
2017-12-13 11:01:37 +00:00
break;
case 52 :
case 100 :
2018-02-20 09:30:36 +00:00
this.onPinAdd(4);
2017-12-13 11:01:37 +00:00
break;
case 53 :
case 101 :
2018-02-20 09:30:36 +00:00
this.onPinAdd(5);
2017-12-13 11:01:37 +00:00
break;
case 54 :
case 102 :
2018-02-20 09:30:36 +00:00
this.onPinAdd(6);
2017-12-13 11:01:37 +00:00
break;
case 55 :
case 103 :
2018-02-20 09:30:36 +00:00
this.onPinAdd(7);
2017-12-13 11:01:37 +00:00
break;
case 56 :
case 104 :
2018-02-20 09:30:36 +00:00
this.onPinAdd(8);
2017-12-13 11:01:37 +00:00
break;
case 57 :
case 105 :
2018-02-20 09:30:36 +00:00
this.onPinAdd(9);
2017-12-13 11:01:37 +00:00
break;
}
}
2018-02-20 09:30:36 +00:00
componentWillMount(): void {
this.keyboardHandler = this.keyboardHandler.bind(this);
window.addEventListener('keydown', this.keyboardHandler, false);
}
componentWillUnmount(): void {
window.removeEventListener('keydown', this.keyboardHandler, false);
}
render(): any {
2018-05-02 09:01:08 +00:00
if (!this.props.modal.opened) return null;
2018-02-20 09:30:36 +00:00
const { onPinSubmit } = this.props.modalActions;
const { device } = this.props.modal;
const { pin } = this.state;
2017-12-13 11:01:37 +00:00
return (
<div className="pin">
2018-02-20 09:30:36 +00:00
{/* <button className="close-modal transparent"></button> */}
<h3>Enter { device.label } PIN</h3>
<p>The PIN layout is displayed on your TREZOR.</p>
<div className="pin-input-row">
<input type="password" autoComplete="off" maxLength="9" disabled value={pin} />
<button type="button" className="pin-backspace transparent" onClick={ event => this.onPinBackspace() }></button>
2017-12-13 11:01:37 +00:00
</div>
2018-02-20 09:30:36 +00:00
<div className="pin-row">
<button type="button" data-value="7" onClick={ event => this.onPinAdd(7) }>&#8226;</button>
<button type="button" data-value="8" onClick={ event => this.onPinAdd(8) }>&#8226;</button>
<button type="button" data-value="9" onClick={ event => this.onPinAdd(9) }>&#8226;</button>
2017-12-13 11:01:37 +00:00
</div>
2018-02-20 09:30:36 +00:00
<div className="pin-row">
<button type="button" data-value="4" onClick={ event => this.onPinAdd(4) }>&#8226;</button>
<button type="button" data-value="5" onClick={ event => this.onPinAdd(5) }>&#8226;</button>
<button type="button" data-value="6" onClick={ event => this.onPinAdd(6) }>&#8226;</button>
2017-12-13 11:01:37 +00:00
</div>
2018-02-20 09:30:36 +00:00
<div className="pin-row">
<button type="button" data-value="1" onClick={ event => this.onPinAdd(1) }>&#8226;</button>
<button type="button" data-value="2" onClick={ event => this.onPinAdd(2) }>&#8226;</button>
<button type="button" data-value="3" onClick={ event => this.onPinAdd(3) }>&#8226;</button>
2017-12-13 11:01:37 +00:00
</div>
2018-02-20 09:30:36 +00:00
2018-03-08 16:10:53 +00:00
<div><button className="submit" type="button" onClick={ event => onPinSubmit(pin) }>Enter PIN</button></div>
<p>Not sure how PIN works? <a className="green" href="http://doc.satoshilabs.com/trezor-user/enteringyourpin.html" target="_blank" rel="noreferrer noopener">Learn more</a></p>
2017-12-13 11:01:37 +00:00
</div>
);
}
}