Skip to content

Commit

Permalink
iirge branch 'development' into 1888-minimal-btc-wallet-page
Browse files Browse the repository at this point in the history
  • Loading branch information
slaweet committed Jun 11, 2019
2 parents 3b19993 + b6b40aa commit 23b89ad
Show file tree
Hide file tree
Showing 153 changed files with 2,960 additions and 2,424 deletions.
2 changes: 1 addition & 1 deletion docs/REDUX_ACTIONS.md
Expand Up @@ -95,7 +95,7 @@ and every 10 seconds dispatches [`newBlockCreated`](https://github.com/LiskHQ/li
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;⬇️ [`updateAccountData`](https://github.com/LiskHQ/lisk-hub/blob/77b6defdf98b6f67f005c25c28ea85378d375817/src/store/middlewares/account.js#L21)<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;⬇️ [`updateTransactions`](https://github.com/LiskHQ/lisk-hub/blob/77b6defdf98b6f67f005c25c28ea85378d375817/src/store/middlewares/account.js#L97)<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;↪️ Account Middleware<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;⬇️ [`votesFetched`](https://github.com/LiskHQ/lisk-hub/blob/77b6defdf98b6f67f005c25c28ea85378d375817/src/store/middlewares/account.js#L156) (sometimes)<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;⬇️ [`loadVotes`](https://github.com/LiskHQ/lisk-hub/blob/77b6defdf98b6f67f005c25c28ea85378d375817/src/store/middlewares/account.js#L156) (sometimes)<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;⬇️ [`updateDelegateAccount`](https://github.com/LiskHQ/lisk-hub/blob/77b6defdf98b6f67f005c25c28ea85378d375817/src/store/middlewares/account.js#L155) (sometimes)<br/>

## Local Storage
Expand Down
65 changes: 39 additions & 26 deletions i18n/locales/en/common.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions jest.config.js
Expand Up @@ -19,7 +19,7 @@ module.exports = {
'src/store/reducers/liskService.test.js',
'src/store/middlewares/socket.test.js',
'src/store/middlewares/peers.test.js',
'src/components/votingListViewV2/*',
'src/components/delegatesListView/*',
'src/components/registerV2/registerV2.test.js',
'src/components/headerV2/headerV2.test.js',
],
Expand Down Expand Up @@ -129,7 +129,7 @@ module.exports = {
'src/components/hwWallet/trezorLogin.js',
'src/components/loginV2/loginV2.js',
'src/utils/hwWallet.js',
'src/components/votingListViewV2/*',
'src/components/delegatesListView/*',
'src/components/headerV2/headerV2.js',
'src/components/registerV2/registerV2.js',
],
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -72,6 +72,7 @@
"is-electron": "2.2.0",
"js-sha256": "0.9.0",
"jspdf": "1.5.3",
"jsx-to-string": "1.4.0",
"lodash.throttle": "4.1.1",
"lolex": "=2.3.2",
"moment": "2.23.0",
Expand Down
37 changes: 19 additions & 18 deletions src/actions/account.js
@@ -1,7 +1,7 @@
import i18next from 'i18next';
import actionTypes from '../constants/actions';
import { getAccount, setSecondPassphrase } from '../utils/api/account';
import { registerDelegate, getDelegate } from '../utils/api/delegate';
import { registerDelegate, getDelegates } from '../utils/api/delegates';
import { getTransactions } from '../utils/api/transactions';
import { getBlocks } from '../utils/api/blocks';
import { updateTransactions } from './transactions';
Expand Down Expand Up @@ -103,7 +103,7 @@ export const secondPassphraseRegistered = ({ secondPassphrase, account, passphra
export const updateDelegateAccount = ({ publicKey }) =>
(dispatch, getState) => {
const liskAPIClient = getState().peers.liskAPIClient;
return getDelegate(liskAPIClient, { publicKey })
return getDelegates(liskAPIClient, { publicKey })
.then((response) => {
dispatch(accountUpdated({
token: 'LSK',
Expand Down Expand Up @@ -177,22 +177,23 @@ export const accountDataUpdated = ({
}) =>
(dispatch, getState) => {
const networkConfig = getState().network;
getAccount({ networkConfig, address: account.address }).then((result) => {
if (result.balance !== account.balance) {
dispatch(updateTransactionsIfNeeded(
{
transactions,
account,
},
!windowIsFocused,
));
}
dispatch(accountUpdated(result));
dispatch(updateWallet(result, getState().peers));
dispatch(liskAPIClientUpdate({ online: true }));
}).catch((res) => {
dispatch(liskAPIClientUpdate({ online: false, code: res.error.code }));
});
getAccount({ networkConfig, address: account.address })
.then((result) => {
if (result.balance !== account.balance) {
dispatch(updateTransactionsIfNeeded(
{
transactions,
account,
},
!windowIsFocused,
));
}
dispatch(accountUpdated(result));
dispatch(updateWallet(result, getState().peers));
dispatch(liskAPIClientUpdate({ online: true }));
}).catch((res) => {
dispatch(liskAPIClientUpdate({ online: false, code: res.error.code }));
});
};

export const updateAccountDelegateStats = account =>
Expand Down
8 changes: 4 additions & 4 deletions src/actions/account.test.js
Expand Up @@ -18,7 +18,7 @@ import {
import { secondPassphraseRegisteredFailure } from './secondPassphrase';
import { delegateRegisteredFailure } from './delegate';
import * as accountApi from '../utils/api/account';
import * as delegateApi from '../utils/api/delegate';
import * as delegateApi from '../utils/api/delegates';
import * as transactionsApi from '../utils/api/transactions';
import * as blocksApi from '../utils/api/blocks';
import Fees from '../constants/fees';
Expand Down Expand Up @@ -311,7 +311,7 @@ describe('actions: account', () => {
let getState;

beforeEach(() => {
stub(delegateApi, 'getDelegate').returnsPromise();
stub(delegateApi, 'getDelegates').returnsPromise();
getState = () => ({
peers: { liskAPIClient: {} },
account: {
Expand All @@ -323,11 +323,11 @@ describe('actions: account', () => {
});

afterEach(() => {
delegateApi.getDelegate.restore();
delegateApi.getDelegates.restore();
});

it('should fetch delegate and update account', () => {
delegateApi.getDelegate.resolves({ data: [{ account: 'delegate data' }] });
delegateApi.getDelegates.resolves({ data: [{ account: 'delegate data' }] });
const data = {
publicKey: accounts.genesis.publicKey,
};
Expand Down
10 changes: 5 additions & 5 deletions src/actions/delegate.js
@@ -1,18 +1,18 @@
import {
getDelegate,
} from '../utils/api/delegate';
getDelegates,
} from '../utils/api/delegates';
import actionTypes from '../constants/actions';

/**
* Pass response from getDelegate to reducers
* Pass response from getDelegates to reducers
*/
export const delegateRetrieved = data => ({
type: actionTypes.delegateRetrieved,
data,
});

/**
* Set a flag until response from getDelegate is resolved
* Set a flag until response from getDelegates is resolved
*/
export const delegateRetrieving = data => ({
type: actionTypes.delegateRetrieving,
Expand All @@ -26,7 +26,7 @@ export const delegatesFetched = ({ username }) =>
(dispatch, getState) => {
const liskAPIClient = getState().peers.liskAPIClient;
dispatch(delegateRetrieving());
getDelegate(liskAPIClient, { username })
getDelegates(liskAPIClient, { username })
.then((response) => {
if (response.data.length > 0) {
dispatch(delegateRetrieved({ delegate: response.data[0], username }));
Expand Down
16 changes: 8 additions & 8 deletions src/actions/delegate.test.js
@@ -1,6 +1,6 @@
import { expect } from 'chai';
import sinon from 'sinon';
import * as delegateApi from '../utils/api/delegate';
import * as delegateApi from '../utils/api/delegates';

import {
delegateRetrieving,
Expand All @@ -10,28 +10,28 @@ import {

describe('actions: delegate', () => {
let dispatch;
let getDelegateStub;
let getDelegatesStub;
let getState;

describe('delegatesFetched', () => {
const username = 'username';
const delegatesFetchedAction = delegatesFetched({ username });

beforeEach(() => {
getDelegateStub = sinon.stub(delegateApi, 'getDelegate');
getDelegatesStub = sinon.stub(delegateApi, 'getDelegates');
dispatch = sinon.spy();
getState = () => ({
peers: { liskAPIClient: {} },
});
});

afterEach(() => {
getDelegateStub.restore();
getDelegatesStub.restore();
});

it('should create actions to handle getDelegate response', () => {
it('should create actions to handle getDelegates response', () => {
const responseData = { delegate: {} };
getDelegateStub.returnsPromise().resolves({ data: [{ ...responseData }] });
getDelegatesStub.returnsPromise().resolves({ data: [{ ...responseData }] });

const expectedActionDelegateRetrieved = {
delegate: responseData,
Expand All @@ -44,9 +44,9 @@ describe('actions: delegate', () => {
.calledWith(delegateRetrieved(expectedActionDelegateRetrieved));
});

it('should create actions to handle getDelegate response failure', () => {
it('should create actions to handle getDelegates response failure', () => {
const responseData = { delegate: null };
getDelegateStub.returnsPromise().resolves({ data: [] });
getDelegatesStub.returnsPromise().resolves({ data: [] });

const expectedActionDelegateRetrieved = {
...responseData,
Expand Down
12 changes: 6 additions & 6 deletions src/actions/search.js
@@ -1,7 +1,7 @@
import actionTypes from '../constants/actions';
import { loadingStarted, loadingFinished } from '../actions/loading';
import { getAccount } from '../utils/api/account';
import { getDelegate, getVotes, listDelegates } from '../utils/api/delegate';
import { getDelegates, getVotes } from '../utils/api/delegates';
import { getTransactions } from '../utils/api/transactions';
import { getBlocks } from '../utils/api/blocks';
import searchAll from '../utils/api/search';
Expand All @@ -14,7 +14,7 @@ const searchDelegate = ({ publicKey, address }) =>
const liskAPIClient = getState().peers.liskAPIClient;
const networkConfig = getState().network;
const token = tokenMap.LSK.key;
const delegates = await getDelegate(liskAPIClient, { publicKey });
const delegates = await getDelegates(liskAPIClient, { publicKey });
const transactions = await getTransactions({
token, networkConfig, address, limit: 1, type: transactionTypes.registerDelegate,
});
Expand Down Expand Up @@ -42,7 +42,7 @@ export const fetchVotedDelegateInfo = (votes, {
/* istanbul ignore if */
if (!liskAPIClient) return;
dispatch(loadingStarted(actionTypes.searchVotes));
const delegates = await listDelegates(liskAPIClient, { limit, offset });
const delegates = await getDelegates(liskAPIClient, { limit, offset });
const votesWithDelegateInfo = votes.map((vote) => {
const delegate = delegates.data.find(d => d.username === vote.username) || {};
return { ...vote, ...delegate };
Expand Down Expand Up @@ -71,13 +71,13 @@ export const fetchVotedDelegateInfo = (votes, {
}
};

const searchVotes = ({ address, offset, limit }) =>
const searchVotes = ({ address }) =>
async (dispatch, getState) => {
const liskAPIClient = getState().peers.liskAPIClient;
/* istanbul ignore if */
if (!liskAPIClient) return;
dispatch(loadingStarted(actionTypes.searchVotes));
const votes = await getVotes(liskAPIClient, { address, offset, limit })
const votes = await getVotes(liskAPIClient, { address })
.then(res => res.data.votes || [])
.catch(() => dispatch(loadingFinished(actionTypes.searchVotes)));

Expand All @@ -103,7 +103,7 @@ export const searchAccount = ({ address }) =>
dispatch({ data: accountData, type: actionTypes.searchAccount });
dispatch(updateWallet(response, getState().peers));
if (accountData.token === tokenMap.LSK.key) {
searchVotes({ address, offset: 0, limit: 101 })(dispatch, getState);
searchVotes({ address })(dispatch, getState);
}
});
}
Expand Down
8 changes: 4 additions & 4 deletions src/actions/search.test.js
Expand Up @@ -3,7 +3,7 @@ import networks from '../constants/networks';
import txFilters from '../constants/transactionFilters';
import * as searchAPI from '../utils/api/search';
import * as accountAPI from '../utils/api/account';
import * as delegateAPI from '../utils/api/delegate';
import * as delegateAPI from '../utils/api/delegates';
import * as transactionsAPI from '../utils/api/transactions';
import accounts from '../../test/constants/accounts';
import * as actions from './search';
Expand All @@ -18,7 +18,7 @@ const {

jest.mock('../utils/api/search');
jest.mock('../utils/api/account');
jest.mock('../utils/api/delegate');
jest.mock('../utils/api/delegates');
jest.mock('../utils/api/transactions');

describe('actions: search', () => {
Expand Down Expand Up @@ -78,7 +78,7 @@ describe('actions: search', () => {
}];
const fetchVotedDelegateInfoSpy = jest.spyOn(actions, 'fetchVotedDelegateInfo');

delegateAPI.listDelegates.mockResolvedValue(delegates);
delegateAPI.getDelegates.mockResolvedValue(delegates);
await fetchVotedDelegateInfo(votes, { address })(dispatch, getState);

// TODO figure out how to make this assertion work and remove the 'not'
Expand All @@ -89,7 +89,7 @@ describe('actions: search', () => {
});

it('should dispatch searchVotes action if we have all info for all votes', async () => {
delegateAPI.listDelegates.mockResolvedValue(delegates);
delegateAPI.getDelegates.mockResolvedValue(delegates);
const votes = delegates.data;
await fetchVotedDelegateInfo(votes, { address })(dispatch, getState);
expect(dispatch).toHaveBeenNthCalledWith(1, {
Expand Down
6 changes: 3 additions & 3 deletions src/actions/transactions.js
Expand Up @@ -3,7 +3,7 @@ import i18next from 'i18next';
import to from 'await-to-js';
import actionTypes from '../constants/actions';
import { loadingStarted, loadingFinished } from '../actions/loading';
import { getDelegate } from '../utils/api/delegate';
import { getDelegates } from '../utils/api/delegates';
import { loadDelegateCache } from '../utils/delegates';
import { extractAddress } from '../utils/account';
import { passphraseUsed } from './account';
Expand Down Expand Up @@ -138,7 +138,7 @@ export const loadSingleTransaction = ({ id }) =>
type: actionTypes.transactionAddDelegateName,
});
} else {
getDelegate(liskAPIClient, { publicKey })
getDelegates(liskAPIClient, { publicKey })
.then((delegateData) => {
dispatch({
data: { delegate: delegateData.data[0], voteArrayName: 'deleted' },
Expand All @@ -156,7 +156,7 @@ export const loadSingleTransaction = ({ id }) =>
type: actionTypes.transactionAddDelegateName,
});
} else {
getDelegate(liskAPIClient, { publicKey })
getDelegates(liskAPIClient, { publicKey })
.then((delegateData) => {
dispatch({
data: { delegate: delegateData.data[0], voteArrayName: 'added' },
Expand Down
8 changes: 4 additions & 4 deletions src/actions/transactions.test.js
Expand Up @@ -7,13 +7,13 @@ import {
updateTransactions,
} from './transactions';
import * as transactionsApi from '../utils/api/transactions';
import * as delegateApi from '../utils/api/delegate';
import * as delegateApi from '../utils/api/delegates';
import accounts from '../../test/constants/accounts';
import Fees from '../constants/fees';
import { toRawLsk } from '../utils/lsk';

jest.mock('../utils/api/transactions');
jest.mock('../utils/api/delegate');
jest.mock('../utils/api/delegates');

describe('actions: transactions', () => {
const dispatch = jest.fn();
Expand Down Expand Up @@ -126,7 +126,7 @@ describe('actions: transactions', () => {
voteArrayName: 'added',
};
transactionsApi.getSingleTransaction.mockResolvedValue({ data: [transactionResponse] });
delegateApi.getDelegate.mockResolvedValue({ data: [delegateResponse] });
delegateApi.getDelegates.mockResolvedValue({ data: [delegateResponse] });

await actionFunction(dispatch, getState);
// the following timeout ensures that the async code inside `actionFunction `
Expand All @@ -148,7 +148,7 @@ describe('actions: transactions', () => {
},
};
transactionsApi.getSingleTransaction.mockResolvedValue({ data: [transactionResponse] });
delegateApi.getDelegate.mockResolvedValue({ data: [delegateResponse] });
delegateApi.getDelegates.mockResolvedValue({ data: [delegateResponse] });
const expectedActionPayload = {
delegate: delegateResponse,
voteArrayName: 'deleted',
Expand Down

0 comments on commit 23b89ad

Please sign in to comment.