mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-02-02 14:23:42 +00:00
7320413dab
* Added a shuffle to swap out the numbers and made them read-only. * Add a border and an index when selecting a confirmation word * Add error flashing * Transform the inputs into buttons when confirming * Change naming of "peek" to "revealing" * If statement needs brackets * Linter complaints * Code cleanup * Formatting and removing unused styles. * Move out shuffle to a util * Additional test cases * Function call, forgot the parens * Adjust sizing and position of confirmation index in Mnemonic button * Implement requested style changes: selected buttons, margins on inputs * Use lodahs shuffle * No need to spread this array
99 lines
2.3 KiB
TypeScript
99 lines
2.3 KiB
TypeScript
import React from 'react';
|
|
import classnames from 'classnames';
|
|
import './Word.scss';
|
|
import { Input } from 'components/ui';
|
|
|
|
interface Props {
|
|
index: number;
|
|
confirmIndex: number;
|
|
word: string;
|
|
value: string;
|
|
showIndex: boolean;
|
|
isNext: boolean;
|
|
isBeingRevealed: boolean;
|
|
isConfirming: boolean;
|
|
hasBeenConfirmed: boolean;
|
|
onClick(index: number, value: string): void;
|
|
}
|
|
|
|
interface State {
|
|
flashingError: boolean;
|
|
}
|
|
|
|
export default class MnemonicWord extends React.Component<Props, State> {
|
|
public state = {
|
|
flashingError: false
|
|
};
|
|
|
|
public render() {
|
|
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';
|
|
|
|
return (
|
|
<div className="input-group-wrapper MnemonicWord">
|
|
<label className="input-group input-group-inline ENSInput-name">
|
|
{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)}
|
|
>
|
|
{word}
|
|
</button>
|
|
) : (
|
|
<Input className="MnemonicWord-word-input" value={word} readOnly={true} />
|
|
)}
|
|
</label>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
private handleClick = (value: string) => {
|
|
const { isNext, index, onClick } = this.props;
|
|
|
|
if (!isNext) {
|
|
this.flashError();
|
|
}
|
|
|
|
onClick(index, value);
|
|
};
|
|
|
|
private flashError = () => {
|
|
const errorDuration = 200;
|
|
|
|
this.setState(
|
|
{
|
|
flashingError: true
|
|
},
|
|
() =>
|
|
setTimeout(
|
|
() =>
|
|
this.setState({
|
|
flashingError: false
|
|
}),
|
|
errorDuration
|
|
)
|
|
);
|
|
};
|
|
}
|