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

Migrate account switcher to a page - Closes #530, #338 #562

Merged
merged 26 commits into from
Mar 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1ff9995
Start with routes for new page
faival Mar 15, 2018
0246444
adapt styles for saved accounts when rendered in mainbox
faival Mar 15, 2018
1c7cb96
fix overflow hiding the remove button on cards
faival Mar 15, 2018
9c4a8aa
Fix overflow-x behaviour, breaks overflow-y
faival Mar 15, 2018
fd7d0bd
fix typo
faival Mar 15, 2018
196d870
render saved accounts outside content section
faival Mar 16, 2018
7a8c2bb
revert changed styles for accounts in content section
faival Mar 16, 2018
2a5113d
Adapt fontsizes after change em to px
faival Mar 16, 2018
f34fddc
add react-router-redux
faival Mar 16, 2018
bbac644
revert react-router-redux
faival Mar 16, 2018
75c39d6
add utils func to handle uniqueIds in components
faival Mar 19, 2018
e096df0
Progress on fix test after refactor, history not available
faival Mar 19, 2018
162c28c
fix integration test failing due to missing history
faival Mar 19, 2018
448f5e3
:recycle: adapt styles for margins set on body, PR changes
faival Mar 21, 2018
ffc1e51
:recycle: handle scrolling on cards area
faival Mar 21, 2018
f552847
:nail_care: prefix font-smoothing, postcss doesn't recognize it
faival Mar 21, 2018
aa83abd
:books: add comment for non suported property
faival Mar 21, 2018
0e89ea3
Merge branch '0.4.0' into 530-migrate-account-switcher-to-a-page
faival Mar 21, 2018
c6c4f04
:nail_care: fix lint errors after merge
faival Mar 21, 2018
d075e2d
:recycle: remove unneeded dialog files, pr changes, breaking tests
faival Mar 21, 2018
24c07fd
:white_check_mark: fix dialog tests after refactor
faival Mar 21, 2018
5113123
:white_check_mark: increase coverage of dialog
faival Mar 21, 2018
baa3e10
:nail_care: fix lint errors
faival Mar 21, 2018
985c30d
:bug: fix vertical scroll
faival Mar 21, 2018
fbafd0c
:bug: remove padding showing scrollbar displaced
faival Mar 22, 2018
91b3c76
Make vote url e2e scenario pending
slaweet Mar 22, 2018
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
3 changes: 0 additions & 3 deletions i18n/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@
"Redo": "Redo",
"Register": "Register",
"Register 2nd passphrase": "Register 2nd passphrase",
"Register Second Passphrase": "Register Second Passphrase",
"Register as delegate": "Register as delegate",
"Reload": "Reload",
"Remove": "Remove",
"Remove vote from": "Remove vote from",
Expand Down Expand Up @@ -220,7 +218,6 @@
"Username": "Username",
"Version": "Version",
"View": "View",
"Vote for delegates": "Vote for delegates",
"Vote_noun": "Vote",
"Vote_verb": "Vote",
"Voted": "Voted",
Expand Down
22 changes: 19 additions & 3 deletions src/components/accountVisual/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import BigNumber from 'bignumber.js';
import React from 'react';
import sha256 from 'js-sha256';
import { Gradients, gradientSchemes } from './gradients';
import generateUniqueId from './../../utils/generateUniqueId';
import breakpoints from './../../constants/breakpoints';
import styles from './accountVisual.css';

Expand Down Expand Up @@ -184,6 +185,10 @@ class AccountVisual extends React.Component {
this.setState({ isSBreakpoint: window.innerWidth <= breakpoints.s });
}

componentWillMount() {
this.uniqueSvgUrlHash = generateUniqueId();
}

componentDidMount() {
window.addEventListener('resize', this.resizeWindow.bind(this));
}
Expand All @@ -196,14 +201,25 @@ class AccountVisual extends React.Component {
const {
address, size, sizeS, className,
} = this.props;

const replaceUrlByHashOnScheme = gradientScheme => ({
...gradientScheme,
url: gradientScheme.url.replace(/\)/g, `-${this.uniqueSvgUrlHash})`),
id: `${gradientScheme.id}-${this.uniqueSvgUrlHash}`,
});
const sizeL = size || 200;
const newSize = this.state.isSBreakpoint && sizeS ? sizeS : sizeL;

const addressHashChunks = getHashChunks(address);
const gradientScheme = gradientSchemes[
addressHashChunks[0].substr(1, 2) % gradientSchemes.length];
const primaryGradients = pickTwo(addressHashChunks[1], gradientScheme.primary);
const secondaryGradients = pickTwo(addressHashChunks[2], gradientScheme.secondary);

const gradientsSchemesUrlsHashed = {
primary: gradientScheme.primary.map(replaceUrlByHashOnScheme),
secondary: gradientScheme.secondary.map(replaceUrlByHashOnScheme),
};
const primaryGradients = pickTwo(addressHashChunks[1], gradientsSchemesUrlsHashed.primary);
const secondaryGradients = pickTwo(addressHashChunks[2], gradientsSchemesUrlsHashed.secondary);
const shapes = [
getBackgroundCircle(newSize, primaryGradients[0]),
getShape(addressHashChunks[1], newSize, primaryGradients[1], 1),
Expand All @@ -213,7 +229,7 @@ class AccountVisual extends React.Component {
return (
<div style={{ height: newSize, width: newSize }} className={`${styles.wrapper} ${className}`}>
<svg height={newSize} width={newSize} className={styles.accountVisual}>
<Gradients scheme={gradientScheme}/>
<Gradients scheme={gradientsSchemesUrlsHashed}/>
{shapes.map((shape, i) => (
<shape.component {...shape.props} key={i}/>
))}
Expand Down
22 changes: 11 additions & 11 deletions src/components/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import SearchResult from '../search/searchResult';
import TransactionDashboard from '../transactionDashboard';
import AccountTransactions from '../accountTransactions';
import Voting from '../voting';
import SavedAccounts from '../savedAccounts';
import SingleTransaction from './../singleTransaction';
import styles from './app.css';
import Dialog from '../dialog';
import Toaster from '../toaster';
import MainMenu from '../mainMenu';
import LoadingBar from '../loadingBar';
Expand All @@ -35,38 +35,38 @@ class App extends React.Component {
<OfflineWrapper>
<main className={`${styles.bodyWrapper}`} ref={(el) => { this.main = el; }}>
<MainMenu />
<Route path={routes.accounts.path} component={SavedAccounts} />
<section>
<div className={styles.mainBox}>
<Header />
<Switch>
<PrivateRoutes path={routes.main.path} render={ ({ match }) => (
<main className={offlineStyle.disableWhenOffline}>
<Switch>
<Route path={`${match.url}${routes.accountVisualDemo.path}/:dialog?`} component={AccountVisualDemo} />
<Route path={`${match.url}${routes.dashboard.path}/:dialog?`} component={Dashboard} />
<Route path={`${match.url}${routes.wallet.path}/:dialog?`} component={TransactionDashboard} />
<Route path={`${match.url}${routes.voting.path}/:dialog?`} component={Voting} />
<Route path={`${match.url}${routes.sidechains.path}/:dialog?`} component={Sidechains} />
<Route path={`${match.url}${routes.secondPassphrase.path}/:dialog?`} component={SecondPassphrase} />
<Route path={`${match.url}${routes.accountVisualDemo.path}`} component={AccountVisualDemo} />
<Route path={`${match.url}${routes.dashboard.path}`} component={Dashboard} />
<Route path={`${match.url}${routes.wallet.path}`} component={TransactionDashboard} />
<Route path={`${match.url}${routes.voting.path}`} component={Voting} />
<Route path={`${match.url}${routes.sidechains.path}`} component={Sidechains} />
<Route path={`${match.url}${routes.secondPassphrase.path}`} component={SecondPassphrase} />
<Route path='*' component={NotFound} />
</Switch>
</main>
)} />
<Route path={routes.explorer.path} render={ ({ match }) => (
<main>
<Route path={`${match.url}${routes.search.path}/:dialog?`} component={Search} />
<Route path={`${match.url}${routes.search.path}`} component={Search} />
<Route path={`${match.url}${routes.searchResult.path}/:query?`} component={SearchResult} />
<Route path={`${match.url}${routes.account.path}/:address?`} component={AccountTransactions} />
<Route path={`${match.url}${routes.transaction.path}/:id`} component={SingleTransaction} />
</main>
)} />
<Route path={`${routes.register.path}:dialog?`} component={Register} />
<Route path={`${routes.addAccount.path}:dialog?`} component={Login} />
<Route path={routes.register.path} component={Register} />
<Route path={routes.addAccount.path} component={Login} />
<Route exact path={routes.login.path} component={Login} />
<Route path='*' component={NotFound} />
</Switch>
</div>
<Dialog />
<Toaster />
<LoadingBar markAsLoaded={this.markAsLoaded.bind(this)} />
</section>
Expand Down
3 changes: 3 additions & 0 deletions src/components/app/variables.css
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ or "warn/action" ineastd of "red/green"
Z-Indexes
*************************/
--normal-index: 1;
--headerbar-index: 20;
--menubar-index: 4;
--accounts-index: 21;

/*************************
Margins
Expand Down
43 changes: 7 additions & 36 deletions src/components/dialog/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,24 @@ import AppBar from 'react-toolbox/lib/app_bar';
import IconButton from '../toolbox/buttons/iconButton';
import { parseSearchParams } from '../../utils/searchParams';
import styles from './dialog.css';
import getDialogs from './dialogs';
import routesReg from '../../utils/routes';

class DialogElement extends Component {
constructor() {
super();
this.state = {};
this.current = {
pathname: '/',
reg: routesReg[3],
list: [],
dialog: '',
};
}

componentDidMount() {
this.checkForDialog();
}

componentDidUpdate() {
this.checkForDialog();
}

checkForDialog() {
// if the dialog is wrong, show a toast
if (this.current.pathname !== this.props.history.location.pathname) {
this.current.reg = routesReg.find(item =>
item.regex.test(this.props.history.location.pathname));
this.current.pathname = this.props.history.location.pathname;
const dialogName = this.props.history.location.pathname.replace(this.current.reg.path, '');
const dialogs = getDialogs();
if (dialogs[dialogName] !== undefined) {
this.open(this.current.reg, dialogs[dialogName]);
} else {
this.close();
}
}
this.open();
}

open(config, dialog) {
open() {
clearTimeout(this.timeout);
this.setState({ hidden: false });
this.props.dialogDisplayed({
title: dialog.title,
theme: dialog.theme,
childComponent: dialog.component,
title: this.props.dialog.title,
theme: this.props.dialog.theme,
childComponent: this.props.dialog.childComponent,
childComponentProps: parseSearchParams(this.props.history.location.search),
});
}
Expand All @@ -64,9 +36,8 @@ class DialogElement extends Component {
}

goBack() {
this.props.history.push((this.current.reg.path instanceof RegExp) ?
this.props.history.location.pathname.match(this.current.reg.path)[0] :
this.current.reg.path);
this.close();
this.props.history.goBack();
}

render() {
Expand Down
29 changes: 25 additions & 4 deletions src/components/dialog/dialog.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('Dialog', () => {
pathname: `${routes.explorer.path}${routes.search.path}saved-accounts`,
search: '',
},
push: sinon.spy(),
goBack: sinon.spy(),
};
dialogProps = {
title: 'Saved Accounts',
Expand All @@ -31,6 +31,7 @@ describe('Dialog', () => {

props = {
dialogDisplayed: () => {},
dialogHidden: sinon.spy(),
t: key => key,
};
wrapper = shallow(<Dialog dialog={dialogProps} history={history} {...props}/>);
Expand All @@ -44,19 +45,39 @@ describe('Dialog', () => {
expect(wrapper.find(SavedAccounts)).to.have.length(1);
});

it('doesn\'t render appBar if title not provided', () => {
const propsWithoutTitle = { ...dialogProps };
delete propsWithoutTitle.title;
wrapper = shallow(<Dialog dialog={propsWithoutTitle} history={history} {...props}/>);
expect(wrapper.find('AppBar')).to.have.length(0);
});

it('doesn\'t render body if not childComponents present', () => {
const propsWithoutChildComponent = { ...dialogProps };
delete propsWithoutChildComponent.childComponent;
wrapper = shallow(<Dialog dialog={propsWithoutChildComponent} history={history} {...props}/>);
expect(wrapper.find(SavedAccounts)).to.have.length(0);
});

it('allows to close the dialog on regexp path ', () => {
const basePath = `${routes.explorer.path}${routes.wallet.path}/1523498127498/`;
history.location.pathname = `${basePath}saved-accounts`;
wrapper.setProps({ history });
wrapper.find('.x-button').simulate('click');
expect(history.push).to.have.been.calledWith(basePath);
expect(history.goBack).to.have.been.calledWith();
});

it('allows to close the dialog on non-regexp path ', () => {
const clock = sinon.useFakeTimers({
toFake: ['setTimeout', 'clearTimeout'],
});
history.location.pathname = `${routes.main.path}${routes.wallet.path}saved-accounts`;
wrapper.setProps({ history });
wrapper.find('.x-button').simulate('click');
expect(history.push).to.have.been.calledWith();
clock.tick(600);
expect(props.dialogHidden).to.have.been.calledWith();
expect(history.goBack).to.have.been.calledWith();
clock.restore();
});

// this test used to pass only because the history.push spy was not in beforeEach
Expand All @@ -65,6 +86,6 @@ describe('Dialog', () => {
newProps.dialog.title = 'Send1';
// trying to update the component
wrapper.setProps(newProps);
expect(history.push).to.have.been.calledWith();
expect(history.goBack).to.have.been.calledWith();
});
});
30 changes: 0 additions & 30 deletions src/components/dialog/dialogs.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/components/header/header.css
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
position: fixed;
top: 0;
background-color: var(--color-white);
z-index: 20;
z-index: var(--headerbar-index);
height: auto;

& .searchBar {
Expand Down
10 changes: 5 additions & 5 deletions src/components/header/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import logo from '../../assets/images/logo-beta.svg';
import PrivateWrapper from '../privateWrapper';
import { ActionButton } from './../toolbox/buttons/button';
import styles from './header.css';
import RelativeLink from '../relativeLink';
import routes from './../../constants/routes';

class Header extends React.Component {
Expand Down Expand Up @@ -72,16 +71,17 @@ class Header extends React.Component {
</div>
}
</div>
<RelativeLink to='saved-accounts' className={styles.avatar}>
<Link to={`${routes.accounts.path}`} className={styles.avatar}>
<AccountVisual
address={this.props.account.address}
size={69} sizeS={40}
/>
</RelativeLink>
</Link>
<div className={styles.menu}>
<figure className={styles.iconCircle}>
<RelativeLink className={`${styles.link} saved-accounts`}
to='saved-accounts'><FontIcon value='more'/></RelativeLink>
<Link to={`${routes.accounts.path}`} className={`${styles.link} saved-accounts`}>
<FontIcon value='more'/>
</Link>
</figure>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/menuBar/menuBar.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
font-size: var(--menu-bar-font-size-m);
font-family: var(--heading-font);
background-color: var(--color-white);
z-index: 1;
z-index: var(--menubar-index);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. We should have used variables for z-indexes from the beginning.

flex-direction: row-reverse;
justify-content: space-between;
}
Expand Down
9 changes: 1 addition & 8 deletions src/components/relativeLink/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Link } from 'react-router-dom';
import { withRouter } from 'react-router';
import buttonStyle from 'react-toolbox/lib/button/theme.css';
import offlineStyle from '../offlineWrapper/offlineWrapper.css';
import dialogs from '../dialog/dialogs';

const RelativeLink = ({
location, to, children, className, raised, neutral, primary, flat, disableWhenOffline,
Expand All @@ -17,13 +16,7 @@ const RelativeLink = ({
if (disableWhenOffline !== undefined) style += `${offlineStyle.disableWhenOffline} `;
if (style !== '') style += ` ${buttonStyle.button}`;

const dialogNames = Object.keys(dialogs());
let pathname = location.pathname;
dialogNames.forEach((dialog) => {
pathname = pathname.replace(`/${dialog}`, '');
});

const path = `${pathname}/${to}`.replace('//', '/');
const path = `${location.pathname}/${to}`.replace('//', '/');
return (
<Link className={`${className} ${style}`} to={path}>{ children }</Link>
);
Expand Down
3 changes: 1 addition & 2 deletions src/components/savedAccounts/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { connect } from 'react-redux';
import { withRouter } from 'react-router';
import { translate } from 'react-i18next';
import { accountRemoved, accountSwitched, removeSavedAccountPassphrase } from '../../actions/savedAccounts';
import { removePassphrase } from '../../actions/account';
Expand All @@ -20,4 +19,4 @@ const mapDispatchToProps = dispatch => ({
export default connect(
mapStateToProps,
mapDispatchToProps,
)(withRouter(translate()(SavedAccounts)));
)(translate()(SavedAccounts));
Loading