mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-24 09:18:09 +00:00
duplicate device unique name
This commit is contained in:
parent
cefddd98b8
commit
ed6450f3ef
@ -8,12 +8,14 @@ import type { Props } from './index';
|
|||||||
type State = {
|
type State = {
|
||||||
defaultName: string;
|
defaultName: string;
|
||||||
instanceName: ?string;
|
instanceName: ?string;
|
||||||
|
isUsed: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class DuplicateDevice extends Component<Props, State> {
|
export default class DuplicateDevice extends Component<Props, State> {
|
||||||
|
|
||||||
keyboardHandler: (event: KeyboardEvent) => void;
|
keyboardHandler: (event: KeyboardEvent) => void;
|
||||||
state: State;
|
state: State;
|
||||||
|
input: ?HTMLInputElement;
|
||||||
|
|
||||||
constructor(props: Props) {
|
constructor(props: Props) {
|
||||||
super(props);
|
super(props);
|
||||||
@ -25,18 +27,22 @@ export default class DuplicateDevice extends Component<Props, State> {
|
|||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
defaultName: `${device.label} (${instance.toString()})`,
|
defaultName: `${device.label} (${instance.toString()})`,
|
||||||
instanceName: null
|
instanceName: null,
|
||||||
|
isUsed: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
keyboardHandler(event: KeyboardEvent): void {
|
keyboardHandler(event: KeyboardEvent): void {
|
||||||
if (event.keyCode === 13) {
|
if (event.keyCode === 13 && !this.state.isUsed) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
this.submit();
|
this.submit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount(): void {
|
componentDidMount(): void {
|
||||||
|
// one time autofocus
|
||||||
|
if (this.input)
|
||||||
|
this.input.focus();
|
||||||
this.keyboardHandler = this.keyboardHandler.bind(this);
|
this.keyboardHandler = this.keyboardHandler.bind(this);
|
||||||
window.addEventListener('keydown', this.keyboardHandler, false);
|
window.addEventListener('keydown', this.keyboardHandler, false);
|
||||||
}
|
}
|
||||||
@ -46,15 +52,21 @@ export default class DuplicateDevice extends Component<Props, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onNameChange = (value: string): void => {
|
onNameChange = (value: string): void => {
|
||||||
|
|
||||||
|
let isUsed: boolean = false;
|
||||||
|
if (value.length > 0) {
|
||||||
|
isUsed = ( this.props.connect.devices.find(d => d.instanceName === value) !== undefined );
|
||||||
|
}
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
instanceName: value.length > 0 ? value : null
|
instanceName: value.length > 0 ? value : null,
|
||||||
|
isUsed
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
submit() {
|
submit() {
|
||||||
if (this.props.modal.opened) {
|
if (!this.props.modal.opened) return;
|
||||||
this.props.modalActions.onDuplicateDevice( { ...this.props.modal.device, instanceName: this.state.instanceName } );
|
this.props.modalActions.onDuplicateDevice( { ...this.props.modal.device, instanceName: this.state.instanceName } );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -63,22 +75,33 @@ export default class DuplicateDevice extends Component<Props, State> {
|
|||||||
|
|
||||||
const { device } = this.props.modal;
|
const { device } = this.props.modal;
|
||||||
const { onCancel, onDuplicateDevice } = this.props.modalActions;
|
const { onCancel, onDuplicateDevice } = this.props.modalActions;
|
||||||
|
const {
|
||||||
|
defaultName,
|
||||||
|
instanceName,
|
||||||
|
isUsed
|
||||||
|
} = this.state;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="duplicate">
|
<div className="duplicate">
|
||||||
|
<button className="close-modal transparent" onClick={ onCancel }></button>
|
||||||
<h3>Clone { device.label }?</h3>
|
<h3>Clone { device.label }?</h3>
|
||||||
<p>This will create new instance of device which can be used with different passphrase</p>
|
<p>This will create new instance of device which can be used with different passphrase</p>
|
||||||
<label>Instance name</label>
|
<div className="row">
|
||||||
<input
|
<label>Instance name</label>
|
||||||
type="text"
|
<input
|
||||||
autoComplete="off"
|
type="text"
|
||||||
autoCorrect="off"
|
autoComplete="off"
|
||||||
autoCapitalize="off"
|
autoCorrect="off"
|
||||||
spellCheck="false"
|
autoCapitalize="off"
|
||||||
placeholder={ this.state.defaultName }
|
spellCheck="false"
|
||||||
onChange={ event => this.onNameChange(event.currentTarget.value) }
|
className={ isUsed ? 'not-valid' : null }
|
||||||
defaultValue={ this.state.instanceName } />
|
placeholder={ defaultName }
|
||||||
<button onClick={ event => this.submit() }>Create new instance</button>
|
ref={ (element) => { this.input = element; } }
|
||||||
|
onChange={ event => this.onNameChange(event.currentTarget.value) }
|
||||||
|
defaultValue={ instanceName } />
|
||||||
|
{ isUsed ? <span className="error">Instance name is already in use</span> : null }
|
||||||
|
</div>
|
||||||
|
<button disabled={ isUsed } onClick={ event => this.submit() }>Create new instance</button>
|
||||||
<button className="white" onClick={ onCancel }>Cancel</button>
|
<button className="white" onClick={ onCancel }>Cancel</button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -126,14 +126,28 @@
|
|||||||
padding: 14px 0px;
|
padding: 14px 0px;
|
||||||
}
|
}
|
||||||
|
|
||||||
label {
|
.row {
|
||||||
display: block;
|
position: relative;
|
||||||
padding-bottom: 6px;
|
|
||||||
text-align: left;
|
text-align: left;
|
||||||
color: @color_text_secondary;
|
padding-bottom: 20px;
|
||||||
|
|
||||||
|
label {
|
||||||
|
display: block;
|
||||||
|
padding-bottom: 6px;
|
||||||
|
text-align: left;
|
||||||
|
color: @color_text_secondary;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error {
|
||||||
|
position: absolute;
|
||||||
|
left: 0px;
|
||||||
|
bottom: 0px;
|
||||||
|
font-size: 12px;
|
||||||
|
color: @color_error_primary;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
button {
|
button:not(.close-modal) {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
margin-top: 12px;
|
margin-top: 12px;
|
||||||
span {
|
span {
|
||||||
@ -256,20 +270,14 @@
|
|||||||
color: @color_error_primary;
|
color: @color_error_primary;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// input[type="text"] {
|
|
||||||
// font-family: 'fontello';
|
|
||||||
// font-size: 6px;
|
|
||||||
// line-height: 14px;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
input[type="text"],
|
input[type="text"],
|
||||||
input[type="password"] {
|
input[type="password"] {
|
||||||
width: 260px;
|
width: 260px;
|
||||||
box-shadow: none;
|
// box-shadow: none;
|
||||||
border-radius: 0px;
|
// border-radius: 0px;
|
||||||
border: 1px solid @color_divider;
|
// border: 1px solid @color_divider;
|
||||||
height: auto;
|
height: auto;
|
||||||
|
|
||||||
.placeholder({
|
.placeholder({
|
||||||
|
Loading…
Reference in New Issue
Block a user