2017-12-28 14:54:07 -05:00
|
|
|
import React from 'react';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
import './Word.scss';
|
2018-03-01 12:53:29 -05:00
|
|
|
import { Input } from 'components/ui';
|
2017-12-28 14:54:07 -05:00
|
|
|
|
|
|
|
interface Props {
|
|
|
|
index: number;
|
2018-04-12 21:50:36 -07:00
|
|
|
confirmIndex: number;
|
2017-12-28 14:54:07 -05:00
|
|
|
word: string;
|
|
|
|
value: string;
|
2018-04-12 21:50:36 -07:00
|
|
|
showIndex: boolean;
|
|
|
|
isNext: boolean;
|
|
|
|
isBeingRevealed: boolean;
|
|
|
|
isConfirming: boolean;
|
|
|
|
hasBeenConfirmed: boolean;
|
|
|
|
onClick(index: number, value: string): void;
|
2017-12-28 14:54:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
interface State {
|
2018-04-12 21:50:36 -07:00
|
|
|
flashingError: boolean;
|
2017-12-28 14:54:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export default class MnemonicWord extends React.Component<Props, State> {
|
|
|
|
public state = {
|
2018-04-12 21:50:36 -07:00
|
|
|
flashingError: false
|
2017-12-28 14:54:07 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
public render() {
|
2018-04-12 21:50:36 -07:00
|
|
|
const {
|
|
|
|
hasBeenConfirmed,
|
|
|
|
isBeingRevealed,
|
|
|
|
showIndex,
|
|
|
|
index,
|
|
|
|
isConfirming,
|
|
|
|
confirmIndex,
|
|
|
|
word
|
|
|
|
} = this.props;
|
|
|
|
const { flashingError } = this.state;
|
|
|
|
const btnClassName = classnames({
|
|
|
|
btn: true,
|
|
|
|
'btn-default': !(isBeingRevealed || flashingError),
|
|
|
|
'btn-success': isBeingRevealed,
|
|
|
|
'btn-danger': flashingError
|
|
|
|
});
|
|
|
|
const indexClassName = 'input-group-addon input-group-addon--transparent';
|
2017-12-28 14:54:07 -05:00
|
|
|
|
|
|
|
return (
|
2018-03-01 12:53:29 -05:00
|
|
|
<div className="input-group-wrapper MnemonicWord">
|
2018-03-08 14:28:43 -05:00
|
|
|
<label className="input-group input-group-inline ENSInput-name">
|
2018-04-12 21:50:36 -07:00
|
|
|
{showIndex && <span className={indexClassName}>{index + 1}.</span>}
|
|
|
|
{hasBeenConfirmed && (
|
|
|
|
<span className="MnemonicWord-button-index">{confirmIndex + 1}</span>
|
|
|
|
)}
|
|
|
|
{isConfirming ? (
|
|
|
|
<button
|
|
|
|
className={`MnemonicWord-button ${btnClassName} ${
|
|
|
|
hasBeenConfirmed ? 'disabled' : ''
|
|
|
|
}`}
|
|
|
|
onClick={() => this.handleClick(word)}
|
2017-12-28 14:54:07 -05:00
|
|
|
>
|
2018-04-12 21:50:36 -07:00
|
|
|
{word}
|
|
|
|
</button>
|
|
|
|
) : (
|
|
|
|
<Input className="MnemonicWord-word-input" value={word} readOnly={true} />
|
2017-12-28 14:54:07 -05:00
|
|
|
)}
|
2018-03-01 12:53:29 -05:00
|
|
|
</label>
|
2017-12-28 14:54:07 -05:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-04-12 21:50:36 -07:00
|
|
|
private handleClick = (value: string) => {
|
|
|
|
const { isNext, index, onClick } = this.props;
|
|
|
|
|
|
|
|
if (!isNext) {
|
|
|
|
this.flashError();
|
|
|
|
}
|
|
|
|
|
|
|
|
onClick(index, value);
|
2017-12-28 14:54:07 -05:00
|
|
|
};
|
|
|
|
|
2018-04-12 21:50:36 -07:00
|
|
|
private flashError = () => {
|
|
|
|
const errorDuration = 200;
|
|
|
|
|
|
|
|
this.setState(
|
|
|
|
{
|
|
|
|
flashingError: true
|
|
|
|
},
|
|
|
|
() =>
|
|
|
|
setTimeout(
|
|
|
|
() =>
|
|
|
|
this.setState({
|
|
|
|
flashingError: false
|
|
|
|
}),
|
|
|
|
errorDuration
|
|
|
|
)
|
|
|
|
);
|
2017-12-28 14:54:07 -05:00
|
|
|
};
|
|
|
|
}
|