Skip to content

Commit

Permalink
Merge branch 'feature/blockchain-agnostic' into 4208-refactor-nextwor…
Browse files Browse the repository at this point in the history
…k-domain
  • Loading branch information
ikem-legend authored Apr 25, 2022
2 parents ce46242 + d345864 commit bd7b2f6
Show file tree
Hide file tree
Showing 251 changed files with 1,058 additions and 984 deletions.
2 changes: 1 addition & 1 deletion jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
"@block/*": ["./packages/block/*"],
"@bookmark/*": ["./packages/bookmark/*"],
"@common/*": ["./packages/common/*"],
"@legacy/*": ["./packages/legacy/*"],
"@dpos/*": ["./packages/dpos/*"],
"@network/*": ["./packages/network/*"],
"@settings/*": ["./packages/settings/*"],
"@token/*": ["./packages/token/*"],
"@transaction/*": ["./packages/transaction/*"],
"@updater/*": ["./packages/updater/*"],
"@wallet/*": ["./packages/wallet/*"],
"@legacy/*": ["./packages/legacy/*"],
"@views/*": ["./packages/views/*"],
"@shared/*": ["./packages/views/shared/*"],
"@basics/*": ["./packages/views/basics/*"],
Expand Down
2 changes: 1 addition & 1 deletion packages/block/store/reducer.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import accounts from '@tests/constants/accounts';
import accounts from '@tests/constants/wallets';
import actionTypes from './actionTypes';
import blocksReducer from './reducer';

Expand Down
6 changes: 3 additions & 3 deletions packages/bookmark/list/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Tooltip from '@basics/tooltip/tooltip';
import { truncateAddress } from '@wallet/utilities/account';
import { Input } from '@basics/inputs';
import { PrimaryButton, TertiaryButton } from '@basics/buttons';
import AccountVisual from '@wallet/detail/info/accountVisual';
import WalletVisual from '@wallet/detail/identity/walletVisual';
import Box from '@basics/box';
import BoxHeader from '@basics/box/header';
import BoxContent from '@basics/box/content';
Expand Down Expand Up @@ -163,13 +163,13 @@ export class BookmarksList extends React.Component {
onClick={e => this.onRowClick(e, bookmark)}
key={bookmark.address}
className={`${styles.row} ${editedAddress === bookmark.address ? styles.editing : ''} ${bookmark.disabled ? styles.disabled : ''} bookmark-list-row`}
to={`${routes.account.path}?address=${bookmark.address}`}
to={`${routes.explorer.path}?address=${bookmark.address}`}
>
<div className={styles.avatarAndDescriptionWrapper}>
{
token.active === tokenMap.LSK.key
? (
<AccountVisual
<WalletVisual
className={styles.avatar}
address={bookmark.address}
/>
Expand Down
14 changes: 7 additions & 7 deletions packages/bookmark/store/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ export const bookmarksRetrieved = () => (dispatch) => {
getFromStorage('bookmarks', emptyBookmarks, (data) => {
const bookmarks = {
BTC: data.BTC,
LSK: data.LSK.map(account => ({
...account,
disabled: validateAddress('LSK', account.address) === 1,
LSK: data.LSK.map(wallet => ({
...wallet,
disabled: validateAddress('LSK', wallet.address) === 1,
})),
};
dispatch({
Expand All @@ -23,13 +23,13 @@ export const bookmarksRetrieved = () => (dispatch) => {
});
};

export const bookmarkAdded = ({ account, token = tokenMap.LSK.key }) => ({
data: { account, token },
export const bookmarkAdded = ({ wallet, token = tokenMap.LSK.key }) => ({
data: { wallet, token },
type: actionTypes.bookmarkAdded,
});

export const bookmarkUpdated = ({ account, token = tokenMap.LSK.key }) => ({
data: { account, token },
export const bookmarkUpdated = ({ wallet, token = tokenMap.LSK.key }) => ({
data: { wallet, token },
type: actionTypes.bookmarkUpdated,
});

Expand Down
26 changes: 13 additions & 13 deletions packages/bookmark/store/action.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { tokenMap } from '@token/configuration/tokens';
import { getFromStorage } from '@common/utilities/localJSONStorage';
import { emptyBookmarks } from '@bookmark/utilities/bookmarks';
import accounts from '@tests/constants/accounts';
import wallets from '@tests/constants/wallets';
import actionTypes from './actionTypes';
import {
bookmarksRetrieved,
Expand All @@ -16,11 +16,11 @@ jest.mock('@common/utilities/localJSONStorage', () => ({

describe('actions: boomarks', () => {
const data = {
account: {
address: accounts.genesis.summary.address,
publicKey: accounts.genesis.summary.publicKey,
balance: accounts.genesis.balance,
title: accounts.genesis.summary.address,
wallet: {
address: wallets.genesis.summary.address,
publicKey: wallets.genesis.summary.publicKey,
balance: wallets.genesis.balance,
title: wallets.genesis.summary.address,
},
token: tokenMap.LSK.key,
};
Expand Down Expand Up @@ -53,34 +53,34 @@ describe('actions: boomarks', () => {
});
});

it('should create an action to add a bookmark account', () => {
it('should create an action to add a bookmark wallet', () => {
const expectedAction = {
data,
type: actionTypes.bookmarkAdded,
};
expect(bookmarkAdded(data)).toEqual(expectedAction);
expect(bookmarkAdded({ account: data.account })).toEqual(expectedAction);
expect(bookmarkAdded({ wallet: data.wallet })).toEqual(expectedAction);
});

it('should create an action to update a bookmark account', () => {
it('should create an action to update a bookmark wallet', () => {
const expectedAction = {
data,
type: actionTypes.bookmarkUpdated,
};
expect(bookmarkUpdated(data)).toEqual(expectedAction);
expect(bookmarkUpdated({ account: data.account })).toEqual(expectedAction);
expect(bookmarkUpdated({ wallet: data.wallet })).toEqual(expectedAction);
});

it('should create an action to remove a bookmark account', () => {
it('should create an action to remove a bookmark wallet', () => {
const removedData = {
address: accounts.genesis.summary.address,
address: wallets.genesis.summary.address,
token: tokenMap.LSK.key,
};
const expectedAction = {
data: removedData,
type: actionTypes.bookmarkRemoved,
};
expect(bookmarkRemoved(removedData)).toEqual(expectedAction);
expect(bookmarkRemoved({ address: accounts.genesis.summary.address })).toEqual(expectedAction);
expect(bookmarkRemoved({ address: wallets.genesis.summary.address })).toEqual(expectedAction);
});
});
2 changes: 1 addition & 1 deletion packages/bookmark/store/middleware.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as localJSONStorage from '@common/utilities/localJSONStorage';
import accounts from '@tests/constants/accounts';
import accounts from '@tests/constants/wallets';
import actionTypes from './actionTypes';
import bookmarksMiddleware from './middleware';

Expand Down
14 changes: 7 additions & 7 deletions packages/bookmark/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ const bookmarks = (state = emptyBookmarks, action) => {
...state,
[action.data.token]: [
{
...action.data.account,
title: action.data.account.title.trim(),
...action.data.wallet,
title: action.data.wallet.title.trim(),
},
...state[action.data.token],
],
};

case actionTypes.bookmarkUpdated: {
const { account, token } = action.data;
const { wallet, token } = action.data;
const tokenBookmarks = state[token];
const indexOfBookmark = getIndexOfBookmark(state, {
address: account.address,
address: wallet.address,
token,
});
return (indexOfBookmark !== -1
Expand All @@ -31,9 +31,9 @@ const bookmarks = (state = emptyBookmarks, action) => {
...tokenBookmarks.slice(0, indexOfBookmark),
{
...tokenBookmarks[indexOfBookmark],
address: account.address,
title: account.title.trim(),
publicKey: account.publicKey,
address: wallet.address,
title: wallet.title.trim(),
publicKey: wallet.publicKey,
},
...tokenBookmarks.slice(indexOfBookmark + 1),
],
Expand Down
88 changes: 44 additions & 44 deletions packages/bookmark/store/reducer.test.js
Original file line number Diff line number Diff line change
@@ -1,112 +1,112 @@
import {
bookmarkAdded, bookmarkUpdated, bookmarkRemoved,
} from '@common/store/actions';
import accounts from '@tests/constants/accounts';
import wallets from '@tests/constants/wallets';
import actionTypes from './actionTypes';
import bookmarks from './reducer';

// eslint-disable-next-line camelcase
const { genesis, delegate, empty_account } = accounts;
const { genesis, delegate, empty_wallet } = wallets;

describe('Reducer: bookmarks(state, action)', () => {
const account = {
const wallet = {
address: genesis.summary.address,
title: genesis.summary.address,
publicKey: genesis.summary.publicKey,
};
const account2 = {
const wallet2 = {
address: delegate.summary.address,
title: genesis.summary.address,
publicKey: delegate.summary.publicKey,
};

it(`should return accounts with added account if action.type is ${actionTypes.bookmarkAdded}`, () => {
const account3 = {
address: empty_account.summary.address,
title: empty_account.summary.address,
publicKey: empty_account.summary.publicKey,
it(`should return wallets with added wallet if action.type is ${actionTypes.bookmarkAdded}`, () => {
const wallet3 = {
address: empty_wallet.summary.address,
title: empty_wallet.summary.address,
publicKey: empty_wallet.summary.publicKey,
};

const state = { LSK: [account, account2], BTC: [] };
const action = bookmarkAdded({ account: account3, token: 'BTC' });
const state = { LSK: [wallet, wallet2], BTC: [] };
const action = bookmarkAdded({ wallet: wallet3, token: 'BTC' });
const changedState = bookmarks(state, action);
expect(changedState.LSK[0]).toEqual(account);
expect(changedState.LSK[1]).toEqual(account2);
expect(changedState.BTC[0]).toMatchObject(account3);
expect(changedState.LSK[0]).toEqual(wallet);
expect(changedState.LSK[1]).toEqual(wallet2);
expect(changedState.BTC[0]).toMatchObject(wallet3);
});

it(`should return accounts with added account and trimmed title if action.type is ${actionTypes.bookmarkAdded}`, () => {
const account3 = {
address: empty_account.summary.address,
title: empty_account.summary.address,
publicKey: empty_account.summary.publicKey,
it(`should return wallets with added wallet and trimmed title if action.type is ${actionTypes.bookmarkAdded}`, () => {
const wallet3 = {
address: empty_wallet.summary.address,
title: empty_wallet.summary.address,
publicKey: empty_wallet.summary.publicKey,
};

const state = { LSK: [account, account2], BTC: [] };
const state = { LSK: [wallet, wallet2], BTC: [] };
const action = bookmarkAdded({
account: {
...account3,
title: ` ${account3.title} `,
wallet: {
...wallet3,
title: ` ${wallet3.title} `,
},
token: 'BTC',
});
const changedState = bookmarks(state, action);
expect(changedState.LSK[0]).toEqual(account);
expect(changedState.LSK[1]).toEqual(account2);
expect(changedState.BTC[0]).toMatchObject(account3);
expect(changedState.LSK[0]).toEqual(wallet);
expect(changedState.LSK[1]).toEqual(wallet2);
expect(changedState.BTC[0]).toMatchObject(wallet3);
});

it(`should return accounts with updated account if action.type is ${actionTypes.bookmarkUpdated}`, () => {
const updatedAccount = {
it(`should return wallets with updated wallet if action.type is ${actionTypes.bookmarkUpdated}`, () => {
const updatedWallet = {
address: delegate.summary.address,
title: 'bob',
publicKey: delegate.summary.publicKey,
};

const state = { LSK: [account, account2], BTC: [] };
const action = bookmarkUpdated({ account: updatedAccount });
const state = { LSK: [wallet, wallet2], BTC: [] };
const action = bookmarkUpdated({ wallet: updatedWallet });

const changedState = bookmarks(state, action);

expect(changedState.LSK[0]).toEqual(account);
expect(changedState.LSK[1]).toEqual(updatedAccount);
expect(changedState.LSK[0]).toEqual(wallet);
expect(changedState.LSK[1]).toEqual(updatedWallet);
});

it(`should return accounts with updated account and trimmed title if action.type is ${actionTypes.bookmarkUpdated}`, () => {
const updatedAccount = {
it(`should return wallets with updated wallet and trimmed title if action.type is ${actionTypes.bookmarkUpdated}`, () => {
const updatedWallet = {
address: delegate.summary.address,
title: 'bob',
publicKey: delegate.summary.publicKey,
};

const state = { LSK: [account, account2], BTC: [] };
const state = { LSK: [wallet, wallet2], BTC: [] };
const action = bookmarkUpdated({
account: {
...updatedAccount,
wallet: {
...updatedWallet,
title: ' bob ',
},
});

const changedState = bookmarks(state, action);

expect(changedState.LSK[0]).toEqual(account);
expect(changedState.LSK[1]).toEqual(updatedAccount);
expect(changedState.LSK[0]).toEqual(wallet);
expect(changedState.LSK[1]).toEqual(updatedWallet);
});

it(`should return accounts without deleted account if action.type is ${actionTypes.bookmarkRemoved}`, () => {
const state = { LSK: [account, account2] };
const action = bookmarkRemoved({ address: account2.address, token: 'LSK' });
it(`should return wallets without deleted wallet if action.type is ${actionTypes.bookmarkRemoved}`, () => {
const state = { LSK: [wallet, wallet2] };
const action = bookmarkRemoved({ address: wallet2.address, token: 'LSK' });

const changedState = bookmarks(state, action);

expect(changedState.LSK[0]).toEqual(account);
expect(changedState.LSK[0]).toEqual(wallet);
expect(changedState.LSK[1]).toEqual(undefined);
});

it('should return validated bookmarks if action.type = actionType.bookmarksRetrieved', () => {
const action = {
type: actionTypes.bookmarksRetrieved,
data: { LSK: [account, account2], BTC: [] },
data: { LSK: [wallet, wallet2], BTC: [] },
};

let state;
Expand Down
2 changes: 1 addition & 1 deletion packages/common/store/actions/urlProcessor.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as accounts from '@wallet/utilities/api';
import mockAccounts from '@tests/constants/accounts';
import mockAccounts from '@tests/constants/wallets';
import setVotesByLaunchProtocol from './urlProcessor';

jest.mock('@wallet/utilities/api', () => ({
Expand Down
2 changes: 1 addition & 1 deletion packages/common/store/middlewares/hwManager.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { toast } from 'react-toastify';
import { subscribeToDeviceConnected, subscribeToDeviceDisconnected } from '@wallet/utilities/hwManager';
import { addSearchParamsToUrl } from '@screens/router/searchParams';
import accounts from '@tests/constants/accounts';
import accounts from '@tests/constants/wallets';
import actionTypes from '../actions/actionTypes';
import hwManagerMiddleware from './hwManager';

Expand Down
2 changes: 1 addition & 1 deletion packages/common/store/reducers/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { default as account } from '@wallet/store/reducer';
export { default as wallet } from '@wallet/store/reducer';
export { default as blocks } from '@block/store/reducer';
export { default as bookmarks } from '@bookmark/store/reducer';
export { default as network } from '@network/store/reducer';
Expand Down
Loading

0 comments on commit bd7b2f6

Please sign in to comment.