Skip to content

Commit

Permalink
Refactor of code
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeltomasik committed Mar 16, 2018
1 parent f326c98 commit eee0f2f
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 15 deletions.
13 changes: 5 additions & 8 deletions src/components/header/header.js
Expand Up @@ -49,23 +49,20 @@ class Header extends React.Component {
</div>
<CopyToClipboard value={this.props.account.address} className={`${styles.address} account-information-address`}/>
{this.props.autoLog ? <div className={styles.timer}>
{((!this.props.account.expireTime ||
this.props.account.expireTime === 0) ||
!this.props.account.passphrase) ?
<span><FontIcon value='locked' className={styles.lock}/> {this.props.t('Account locked!')}</span> :
{((this.props.account.expireTime &
this.props.account.expireTime !== 0) &
this.props.account.passphrase) ?
<div>
{this.props.t('Address timeout in')} <i> </i>
<Countdown
date={this.props.account.expireTime}
renderer={CountDownTemplate}

onComplete={() => {
this.props.removePassphrase(this.props.account);
this.props.removeSavedAccountPassphrase(this.props.account);
this.props.removeSavedAccountPassphrase();
}
}
/>
</div>}
</div> : <div></div>}
</div>
: <div className={styles.timer}>
{this.props.account.passphrase ? '' : <span>
Expand Down
2 changes: 1 addition & 1 deletion src/components/header/index.js
Expand Up @@ -17,7 +17,7 @@ const mapDispatchToProps = dispatch => ({
setActiveDialog: data => dispatch(dialogDisplayed(data)),
logOut: () => dispatch(accountLoggedOut()),
removePassphrase: data => dispatch(removePassphrase(data)),
removeSavedAccountPassphrase: data => dispatch(removeSavedAccountPassphrase(data)),
removeSavedAccountPassphrase: () => dispatch(removeSavedAccountPassphrase()),
});
export default withRouter(connect(
mapStateToProps,
Expand Down
4 changes: 2 additions & 2 deletions src/components/header/index.test.js
Expand Up @@ -63,8 +63,8 @@ describe('HeaderHOC', () => {

it('should dispatch removeSavedAccountPassphrase action', () => {
const actionsSpy = sinon.spy(savedAccountsActions, 'removeSavedAccountPassphrase');
wrapper.find(Header).props().removeSavedAccountPassphrase({});
expect(actionsSpy).to.be.calledWith({});
wrapper.find(Header).props().removeSavedAccountPassphrase();
expect(actionsSpy).to.be.calledWith();
actionsSpy.restore();
});
});
2 changes: 1 addition & 1 deletion src/components/savedAccounts/savedAccounts.css
Expand Up @@ -202,13 +202,13 @@

& span {
margin-bottom: 3px;
transition: transform ease-in-out 500ms;
}

&:hover {
& span {
transform: scale(1.1);
transform-origin: 100%;
transition: transform ease-in-out 500ms;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/savedAccounts/savedAccounts.js
Expand Up @@ -73,7 +73,7 @@ class SavedAccounts extends React.Component {
this.setState({ isSecureAppears: { ...this.state.isSecureAppears, [uniqueID]: true } });
setTimeout(() => {
this.setState({ isSecureAppears: { ...this.state.isSecureAppears, [uniqueID]: false } });
}, 3000);
}, 5000);
}

render() {
Expand Down
19 changes: 18 additions & 1 deletion src/components/savedAccounts/savedAccounts.test.js
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { expect } from 'chai';
import { MemoryRouter as Router } from 'react-router-dom';
import { mount } from 'enzyme';
import { spy } from 'sinon';
import { spy, useFakeTimers } from 'sinon';
import configureStore from 'redux-mock-store';
import PropTypes from 'prop-types';
import i18n from '../../i18n';
Expand Down Expand Up @@ -106,6 +106,23 @@ describe('SavedAccounts', () => {
expect(props.history.push).to.have.been.calledWith(`${routes.main.path}${routes.dashboard.path}`);
});

it('should check if "Your ID is now secured!" disapears after 5sec', () => {
const clock = useFakeTimers({
toFake: ['setTimeout', 'clearTimeout', 'Date'],
});

expect(wrapper.find('strong.unlockedSecured')).to.have.lengthOf(0);
wrapper.find('strong.unlocked').at(1).simulate('click');
clock.tick(2000);
expect(wrapper.find('strong.unlockedSecured')).to.have.lengthOf(1);

clock.tick(7000);
wrapper.update();
expect(wrapper.find('strong.unlockedSecured')).to.have.lengthOf(0);

clock.restore();
});

it('should not call props.accountSwitched on the "saved account card" click if in "edit" mode', () => {
wrapper.find('button.edit-button').simulate('click');
wrapper.find('.saved-account-card').at(0).simulate('click');
Expand Down
2 changes: 1 addition & 1 deletion src/store/reducers/savedAccounts.js
Expand Up @@ -63,7 +63,7 @@ const savedAccounts = (state = { accounts: [] }, action) => {
return {
...state,
accounts: state.accounts.map((account) => {
if ((`${action.data.network}${action.data.passphrase}` === `${account.network}${account.passphrase}`)) {
if (!action.data || (`${action.data.network}${action.data.passphrase}` === `${account.network}${account.passphrase}`)) {
delete account.passphrase;
}
return account;
Expand Down

0 comments on commit eee0f2f

Please sign in to comment.