Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature password hint #206

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added src/app/assets/images/copy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/app/components/all.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
@import './elements/HelpTip/styles';
@import './elements/Dropdown';
@import './elements/CreateCommunity';
@import './elements/CopyPassword/styles';
@import './elements/Toast/styles';

// modules
@import './modules/Header/styles';
Expand Down
61 changes: 56 additions & 5 deletions src/app/components/elements/ChangePassword.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ import { api } from '@steemit/steem-js';
import * as transactionActions from 'app/redux/TransactionReducer';
import * as appActions from 'app/redux/AppReducer';
import LoadingIndicator from 'app/components/elements/LoadingIndicator';
import CopyPassword from 'app/components/elements/CopyPassword';
import Toast from 'app/components/elements/Toast';
import { validate_account_name } from 'app/utils/ChainValidation';
import { cleanReduxInput } from 'app/utils/ReduxForms';
import { APP_NAME } from 'app/client_config';
import { userActionRecord } from 'app/utils/ServerApiClient';
import { CopyToClipboard } from 'react-copy-to-clipboard';
import copy from 'app/assets/images/copy.png';

const { string, oneOf } = PropTypes;

Expand All @@ -33,9 +37,12 @@ class ChangePassword extends React.Component {
accountName: props.username,
nameError: '',
generated: false,
modalVisible: false,
showToast: false,
};
this.onNameChange = this.onNameChange.bind(this);
this.generateWif = this.generateWif.bind(this);
this.copySuccess = this.copySuccess.bind(this);
}
componentWillMount() {
this.props.setRouteTag();
Expand All @@ -47,7 +54,17 @@ class ChangePassword extends React.Component {

generateWif(e) {
newWif = 'P' + key_utils.get_random_key().toWif();
this.setState({ generated: true });
this.setState({ generated: true, modalVisible: true });
}
copySuccess() {
this.setState({
showToast: true,
});
setTimeout(() => {
this.setState({
showToast: false,
});
}, 2000);
}
validateAccountName(name) {
let nameError = '';
Expand Down Expand Up @@ -115,7 +132,7 @@ class ChangePassword extends React.Component {
</div>
);
}
const { generated, loading, error } = this.state;
const { generated, loading, error, modalVisible } = this.state;
const { username, authType, priorAuthKey /*enable2fa*/ } = this.props;
const { handleSubmit, submitting, onClose } = this.props; // form stuff
const {
Expand Down Expand Up @@ -226,13 +243,24 @@ class ChangePassword extends React.Component {
<label>
{tt('g.generated_password') + ' '}{' '}
<span className="secondary">({tt('g.new')})</span>
{generated && (
<span
style={{ float: 'right' }}
onClick={this.generateWif}
>
<a>{tt('copy_password.regenerate')}</a>
</span>
)}
<br />
</label>
{(generated && (
<span>
<div>
{/* !! Do not put keys in a label, labels have an uppercase css style applied !! */}
<div className="overflow-ellipsis">
<div
className="overflow-ellipsis"
style={{ position: 'relative' }}
>
<code
style={{
display: 'block',
Expand All @@ -245,12 +273,26 @@ class ChangePassword extends React.Component {
}}
>
{newWif}
<CopyToClipboard
text={newWif}
onCopy={this.copySuccess}
>
<img
src={copy}
style={{
position: 'absolute',
top: 6,
right: 6,
cursor: 'pointer',
}}
/>
</CopyToClipboard>
</code>
</div>
</div>
<label className="ChangePassword__backup_text">
{/*<label className="ChangePassword__backup_text">
{tt('g.backup_password_by_storing_it')}.
</label>
</label>*/}
</span>
)) || (
<button
Expand Down Expand Up @@ -335,6 +377,15 @@ class ChangePassword extends React.Component {
</div>
)}
</form>
<CopyPassword
visible={modalVisible}
newWif={newWif}
close={() => this.setState({ modalVisible: false })}
/>
<Toast
text={tt('copy_password.copy_success')}
showToast={this.state.showToast}
/>
</span>
);
// {enable2fa && <p>
Expand Down
80 changes: 80 additions & 0 deletions src/app/components/elements/CopyPassword/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import React from 'react';
import copy from 'app/assets/images/copy.png';
import { CopyToClipboard } from 'react-copy-to-clipboard';
import tt from 'counterpart';
import Toast from 'app/components/elements/Toast';

export default class CopyPassword extends React.Component {
constructor(props) {
super(props);
this.state = {
password: '',
showToast: false,
copySuccess: false,
};
this.copySuccess = this.copySuccess.bind(this);
this.close = this.close.bind(this);
}

copySuccess() {
this.setState({
copySuccess: true,
showToast: true,
});
setTimeout(() => {
this.setState({
showToast: false,
});
}, 2000);
}

close() {
if (!this.state.copySuccess) return;
this.props.close();
this.setState({
copySuccess: false,
});
}
render() {
return (
<div>
{this.props.visible ? (
<div className="copy_password">
<div className="copy_password_cover" />
<div className="copy_password_modal">
<div className="title">
{tt('copy_password.back_up')}
</div>
<div className="content">
{tt('copy_password.back_up_tips')}
</div>
<div className="input_password">
{this.props.newWif}
<CopyToClipboard
text={this.props.newWif}
onCopy={this.copySuccess}
>
<img src={copy} />
</CopyToClipboard>
</div>
<div
className={`footer ${
this.state.copySuccess ? 'footer_blue' : ''
}`}
onClick={this.close}
>
{tt('copy_password.back_up_success')}
</div>
</div>
</div>
) : null}
{
<Toast
text={tt('copy_password.copy_success')}
showToast={this.state.showToast}
/>
}
</div>
);
}
}
80 changes: 80 additions & 0 deletions src/app/components/elements/CopyPassword/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@

.copy_password {
.copy_password_modal{
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
padding: 20px;
width: 533px;
height: 324px;
background: #FFFFFF;
border-radius: 12px;
z-index: 99;
.title {
font-family: PingFang SC;
font-style: normal;
font-weight: 600;
font-size: 16px;
line-height: 22px;

color: #252736;
margin-bottom: 14px;
}
.content {
font-family: PingFang SC;
font-style: normal;
font-weight: normal;
font-size: 14px;
line-height: 20px;
color: rgba(47, 47, 47, 0.5);
margin-bottom: 29px;
}
.input_password {
position: relative;
background: #FFFFFF;
border: 1px solid #CACACA;
box-sizing: border-box;
border-radius: 4px;
margin-bottom: 64px;
padding: 12px;
font-family: PingFang SC;
font-style: normal;
font-weight: normal;
font-size: 12px;
line-height: 17px;
color: #939393;
img {
position: absolute;
right: 11px;
cursor: pointer;
}
}
.footer {
background: #F7F7F7;
border-radius: 10px;
font-family: PingFang SC;
font-style: normal;
font-weight: 500;
font-size: 14px;
line-height: 20px;
color: rgba(47, 47, 47, 0.5);
text-align: center;
padding: 10px;
}
.footer_blue {
color: #fff;
background: #1720C9;
cursor: pointer;
}
}
.copy_password_cover {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.5);
z-index: 9;
}
};
15 changes: 15 additions & 0 deletions src/app/components/elements/Toast/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';

export default class Toast extends React.Component {
constructor(props) {
super(props);
}

render() {
return (
<div className={`copy_toast ${this.props.showToast ? 'show' : ''}`}>
{this.props.text}
</div>
);
}
}
74 changes: 74 additions & 0 deletions src/app/components/elements/Toast/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@

.copy_toast {
visibility: hidden;
max-width: 160px;
height: 50px;
/*margin-left: -125px;*/
margin: auto;
background-color: #333;
color: #fff;
text-align: center;
border-radius: 4px;
line-height: 50px;
position: fixed;
z-index: 1;
left: 0;right:0;
bottom: 30px;
font-size: 16px;
white-space: nowrap;
z-index: 100;
}

.copy_toast.show {
visibility: visible;
-webkit-animation: fadein 0.5s, fadeout 0.5s 2.5s;
animation: fadein 0.5s, fadeout 0.5s 4.5s;
}

@-webkit-keyframes fadein {
from {bottom: 0; opacity: 0;}
to {bottom: 30px; opacity: 1;}
}

@keyframes fadein {
from {bottom: 0; opacity: 0;}
to {bottom: 30px; opacity: 1;}
}

@-webkit-keyframes expand {
from {min-width: 50px}
to {min-width: 350px}
}

@keyframes expand {
from {min-width: 50px}
to {min-width: 350px}
}
@-webkit-keyframes stay {
from {min-width: 350px}
to {min-width: 350px}
}

@keyframes stay {
from {min-width: 350px}
to {min-width: 350px}
}
@-webkit-keyframes shrink {
from {min-width: 350px;}
to {min-width: 50px;}
}

@keyframes shrink {
from {min-width: 350px;}
to {min-width: 50px;}
}

@-webkit-keyframes fadeout {
from {bottom: 30px; opacity: 1;}
to {bottom: 60px; opacity: 0;}
}

@keyframes fadeout {
from {bottom: 30px; opacity: 1;}
to {bottom: 60px; opacity: 0;}
}
Loading