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

Implement add account with recovery phrase flow - Closes #4302 #4329

Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
b8c6e92
implemented add account page
eniolam1000752 May 25, 2022
fc74eeb
Merge branch 'feature/blockchain-agnostic-new' into 4302-implement-ad…
eniolam1000752 May 25, 2022
07a26e9
implemented and linked add account form
eniolam1000752 May 27, 2022
775cc3c
Merge branch '4302-implement-add-account-with-recovery-phrase-flow' o…
eniolam1000752 May 27, 2022
5cc27a1
made add account a multi step flow
eniolam1000752 May 27, 2022
77ee278
added test for addAccountChoice
eniolam1000752 May 30, 2022
c9c1fdd
Merge branch 'feature/blockchain-agnostic-new' into 4302-implement-ad…
eniolam1000752 May 30, 2022
c6ea27a
implemented unit test to addAccount form
eniolam1000752 May 31, 2022
4287d86
Merge branch '4302-implement-add-account-with-recovery-phrase-flow' o…
eniolam1000752 May 31, 2022
c411e0e
fixed merge conflict
eniolam1000752 May 31, 2022
a6d3810
linked up password set success component to the flow
eniolam1000752 Jun 1, 2022
926b634
Merge branch 'feature/blockchain-agnostic-new' into 4302-implement-ad…
eniolam1000752 Jun 1, 2022
7b51f4f
reverted modal flow to full multi step
eniolam1000752 Jun 2, 2022
c3bc0fb
reverted jest config
eniolam1000752 Jun 2, 2022
f21c92d
Merge branch '4302-implement-add-account-with-recovery-phrase-flow' o…
eniolam1000752 Jun 2, 2022
1b7ec1a
reveted jest config and fixed failing unit tests
eniolam1000752 Jun 2, 2022
9a931a5
fixed lint error
eniolam1000752 Jun 2, 2022
aaaaedc
changed accountSelect -> manageAccount in all instance
eniolam1000752 Jun 2, 2022
d7ac797
:recycle: Refactor account management
Jun 2, 2022
978e8bb
feat: add useCurrentAccount mock from gad pr
soroushm Jun 3, 2022
78a31db
feat: add useEncryptionAccount mock
soroushm Jun 3, 2022
698789b
chore: fix setpasswordForm encryption
soroushm Jun 3, 2022
82f8b93
chore: fix SetPasswordSuccess file names
soroushm Jun 3, 2022
ecf90c3
chore: change account init route
soroushm Jun 3, 2022
6bb88fb
feat: add useCurrentAccount functionality, fix add flow
soroushm Jun 3, 2022
e7ab06b
feat: added test for account reducer and action
eniolam1000752 Jun 3, 2022
6ed0b14
fixed failing unit tests
eniolam1000752 Jun 3, 2022
d4169aa
added test to selectors
eniolam1000752 Jun 3, 2022
f13f81e
Merge branch 'feature/blockchain-agnostic-new' into 4302-implement-ad…
ManuGowda Jun 3, 2022
a94eb01
fixed test coverage issues
eniolam1000752 Jun 3, 2022
2e5b0b0
Merge branch '4302-implement-add-account-with-recovery-phrase-flow' o…
eniolam1000752 Jun 3, 2022
0d74b60
fixed lint issues
eniolam1000752 Jun 3, 2022
56244b2
added unit test and istanbul ignore to addAccount
eniolam1000752 Jun 3, 2022
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
666 changes: 9 additions & 657 deletions app/package-lock.json

Large diffs are not rendered by default.

51,579 changes: 237 additions & 51,342 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/common/store/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export { default as voting } from '@dpos/validator/store/reducers/voting';
export { default as watchList } from '@dpos/validator/store/reducers/watchList';
export { default as service } from './service';
export { default as loading } from './loading';
export { account } from 'src/modules/account/store/reducer';
100 changes: 58 additions & 42 deletions packages/views/screens/router/routes.js
Original file line number Diff line number Diff line change
@@ -1,77 +1,72 @@
export default {
wallet: {
path: '/wallet',
isPrivate: true,
exact: false,
forbiddenTokens: [],
},
addAccount: {
path: '/add-account',
isPrivate: false,
forbiddenTokens: [],
},
explorer: {
path: '/explorer',
searchParam: 'address',
addAccountBySecretRecovery: {
path: '/account/add/secrete-recovery',
isPrivate: false,
forbiddenTokens: [],
exact: true,
},
hwWallet: {
path: '/hw-wallet-login',
isSigninFlow: true,
addAccountOptions: {
path: '/account',
isPrivate: false,
forbiddenTokens: [],
exact: true,
},
register: {
path: '/register',
block: {
path: '/block',
searchParam: 'id',
isPrivate: false,
isSigninFlow: true,
exact: true,
forbiddenTokens: [],
},
login: {
path: '/login',
blocks: {
path: '/blocks',
isPrivate: false,
isSigninFlow: true,
exact: true,
forbiddenTokens: [],
},
termsOfUse: {
path: '/terms-of-use',
dashboard: {
path: '/',
isPrivate: false,
isSigninFlow: true,
forbiddenTokens: [],
exact: true,
},
transactions: {
path: '/transactions',
delegates: {
path: '/delegates',
exact: true,
isPrivate: false,
forbiddenTokens: [],
},
blocks: {
path: '/blocks',
explorer: {
path: '/explorer',
searchParam: 'address',
isPrivate: false,
exact: true,
forbiddenTokens: [],
},
block: {
path: '/block',
searchParam: 'id',
hwWallet: {
path: '/hw-wallet-login',
isSigninFlow: true,
isPrivate: false,
exact: true,
forbiddenTokens: [],
},
wallets: {
path: '/wallets',
login: {
path: '/login',
isPrivate: false,
isSigninFlow: true,
exact: true,
forbiddenTokens: [],
},
network: {
path: '/network',
manageAccounts: {
path: '/account/manage',
isPrivate: false,
forbiddenTokens: [],
},
delegates: {
path: '/delegates',
exact: true,
network: {
path: '/network',
isPrivate: false,
forbiddenTokens: [],
},
Expand All @@ -80,16 +75,33 @@ export default {
isPrivate: true,
forbiddenTokens: [],
},
accountSelect: {
path: '/account/manage',
register: {
path: '/register',
isPrivate: false,
isSigninFlow: true,
forbiddenTokens: [],
},
dashboard: {
path: '/',
termsOfUse: {
path: '/terms-of-use',
isPrivate: false,
isSigninFlow: true,
forbiddenTokens: [],
},
transactions: {
path: '/transactions',
isPrivate: false,
forbiddenTokens: [],
exact: true,
},
wallets: {
path: '/wallets',
isPrivate: false,
forbiddenTokens: [],
},
wallet: {
path: '/wallet',
isPrivate: true,
exact: false,
forbiddenTokens: [],
},
};

Expand Down Expand Up @@ -174,4 +186,8 @@ export const modals = {
isPrivate: false,
forbiddenTokens: [],
},
setPassword: {
isPrivate: false,
forbiddenTokens: [],
},
};
10 changes: 8 additions & 2 deletions packages/views/screens/router/routesMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ import ReclaimBalanceModal from '@legacy/manager/reclaimBalanceModal';
import RegisterMultisig from '@wallet/manager/registerMultisigManager';
import SignMultiSig from '@wallet/manager/signMultisigManager';
import MultisigAccountDetails from '@wallet/manager/multisigAccountDetailsManager';
import AccountSelect from '@account/components/AccountSelect';
import ManageAccounts from '@account/components/ManageAccounts';
import AddAccountOptions from '@account/components/AddAccountOptions';
import AddAccountBySecretRecovery from 'src/modules/account/components/AddAccountBySecretRecovery';
import AddAccountForm from '@account/components/AddAccountForm';

export default {
wallet: AccountDetails,
Expand Down Expand Up @@ -70,5 +73,8 @@ export default {
multiSignature: RegisterMultisig,
multisigAccountDetails: MultisigAccountDetails,
signMultiSignTransaction: SignMultiSig,
accountSelect: AccountSelect,
manageAccounts: ManageAccounts,
addAccountOptions: AddAccountOptions,
accountAdd: AddAccountForm,
addAccountBySecretRecovery: AddAccountBySecretRecovery,
};
5 changes: 5 additions & 0 deletions setup/react/assets/images/icons/account-upload.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions setup/react/assets/images/icons/download-blue.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions setup/react/assets/images/icons/secret-passphrase.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
"Discreet mode": "Discreet mode",
"Does the problem still persist?": "Does the problem still persist?",
"Done": "Done",
"Don’t have a Lisk account yet?": "Don’t have a Lisk account yet?",
"Download": "Download",
"Download completed": "Download completed",
"Duplicate public keys detected.": "Duplicate public keys detected.",
Expand Down Expand Up @@ -158,6 +159,7 @@
"From": "From",
"Generated by": "Generated by",
"German": "German",
"Go Back": "Go Back",
"Go back": "Go back",
"Go to confirmation": "Go to confirmation",
"Go to dashboard": "Go to dashboard",
Expand Down Expand Up @@ -342,6 +344,8 @@
"Secret recovery phrase": "Secret recovery phrase",
"Security": "Security",
"Select All": "Select All",
"Select Network": "Select Network",
"Select the applicable mode.": "Select the applicable mode.",
"Send": "Send",
"Send a reclaim transaction": "Send a reclaim transaction",
"Send using second passphrase right away": "Send using second passphrase right away",
Expand Down
1 change: 0 additions & 1 deletion src/modules/account/components/AccountSelect/index.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@import '../../../../../setup/react/app/mixins.css';

.addAccount {
align-items: center;
display: flex;
flex-grow: 1;
margin: 0;
min-height: 100%;
justify-content: center;
text-align: center;
width: 100%;
}

.wrapper {
align-items: center;
display: flex;
flex-direction: column;
padding: 20px 24px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* eslint-disable max-lines */
import React, { useRef, useState } from 'react';
import { withRouter } from 'react-router';
import grid from 'flexboxgrid/dist/flexboxgrid.css';
import SetPasswordForm from 'src/modules/auth/components/SetPasswordForm/SetPasswordForm';
import MultiStep from 'src/modules/common/components/MultiStep';
import SetPasswordSuccess from 'src/modules/auth/components/SetPasswordSuccess';
import routes from '@views/screens/router/routes';
import { useCurrentAccount } from '@account/hooks';
import AddAccountForm from '../AddAccountForm';
import styles from './AddAccountBySecretRecovery.css';

const AddAccountBySecretRecovery = ({ history, login }) => {
const multiStepRef = useRef(null);
const [passphrase, setPassphrase] = useState(null);
const [currentAccount, setCurrentAccount] = useCurrentAccount();
const onAddAccount = (passphraseData) => {
setPassphrase(passphraseData);
multiStepRef.current.next();
};

const onSetPassword = (account) => {
setCurrentAccount(account);
multiStepRef.current.next();
};

const onPasswordSetComplete = () => {
login(passphrase); // Todo this login method is depricated
history.push(routes.dashboard.path);
};

return (
<div className={`${styles.addAccount} ${grid.row}`}>
<MultiStep
navStyles={{ multiStepWrapper: styles.wrapper }}
ref={multiStepRef}
>
<AddAccountForm onAddAccount={onAddAccount} />
<SetPasswordForm recoveryPhrase={passphrase} onSubmit={onSetPassword} />
<SetPasswordSuccess
encryptedPhrase={currentAccount}
onClose={onPasswordSetComplete}
/>
</MultiStep>
</div>
);
};

export default withRouter(AddAccountBySecretRecovery);
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import {
createEvent, fireEvent, screen, waitFor,
} from '@testing-library/react';
import mockSavedAccounts from '@tests/fixtures/accounts';
import { renderWithRouter } from 'src/utils/testHelpers';
import AddAccountByPassPhrase from './AddAccountBySecretRecovery';

jest.mock('react-i18next');
jest.mock('../../hooks/useAccounts', () => ({
useAccounts: jest.fn().mockReturnValue([mockSavedAccounts]),
}));

const props = {
history: { push: jest.fn() },
login: jest.fn(),
};

beforeEach(() => {
renderWithRouter(AddAccountByPassPhrase, props);
});

describe('Add account by secrete recovery phrase flow', async () => {
it('Should successfull go though the flow', async () => {
expect(screen.getByText('Add account')).toBeTruthy();
expect(screen.getByText('Enter your secret recovery phrase to manage your account.')).toBeTruthy();
expect(screen.getByText('Continue')).toBeTruthy();
expect(screen.getByText('Go Back')).toBeTruthy();

const inputField = screen.getByTestId('recovery-1');
const pasteEvent = createEvent.paste(inputField, {
clipboardData: {
getData: () => 'below record evolve eye youth post control consider spice swamp hidden easily',
},
});

fireEvent(inputField, pasteEvent);
fireEvent.click(screen.getByText('Continue'));

const password = screen.getByTestId('password');
const cPassword = screen.getByTestId('cPassword');
const accountName = screen.getByTestId('accountName');
const hasAgreed = screen.getByTestId('hasAgreed');

fireEvent.change(password, { target: { value: 'Password1$' } });
fireEvent.change(cPassword, { target: { value: 'Password1$' } });
fireEvent.change(accountName, { target: { value: 'test account name' } });
fireEvent.click(hasAgreed);
fireEvent.click(screen.getByText('Save Account'));

await waitFor(() => {
expect(screen.getByText('Perfect! You\'re all set')).toBeTruthy();
expect(screen.getByText('You can now download your encrypted secret recovery phrase and use it to add your account on other devices.')).toBeTruthy();
expect(screen.getByText('Download')).toBeTruthy();

fireEvent.click(screen.getByText('Continue to Dashboard'));

expect(props.login).toBeCalled();
});
});
});
13 changes: 13 additions & 0 deletions src/modules/account/components/AddAccountBySecretRecovery/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* istanbul ignore file */
soroushm marked this conversation as resolved.
Show resolved Hide resolved
import { connect } from 'react-redux';
import { login } from '@auth/store/action';
import AddAccountBySecretRecovery from './AddAccountBySecretRecovery';

const mapDispatchToProps = {
login,
};

export default connect(
null,
mapDispatchToProps,
)(AddAccountBySecretRecovery);
Loading