From cd863287f04f9715a413983388df6738d8a4f467 Mon Sep 17 00:00:00 2001 From: michaeltomasik Date: Thu, 15 Nov 2018 01:01:51 +0100 Subject: [PATCH 01/11] :recycle: Rename peers.data to peers.liskAPIClient --- i18n/locales/en/common.json | 1 - src/actions/account.js | 16 ++++++++-------- src/actions/delegate.js | 2 +- src/actions/followedAccounts.js | 2 +- src/actions/peers.js | 2 +- src/actions/search.js | 16 ++++++++-------- src/actions/transactions.js | 14 +++++++------- src/actions/voting.js | 8 ++++---- src/components/account/account.js | 4 ++-- src/components/account/account.test.js | 2 +- src/components/ledger/ledgerLogin.js | 2 +- src/components/loadingBar/loadingBar.js | 4 ++-- src/components/login/index.js | 2 +- src/components/singleTransaction/index.js | 4 ++-- .../transactions/transactionDetailView.js | 4 ++-- src/store/middlewares/offline.js | 2 +- src/store/middlewares/offline.test.js | 2 +- src/store/middlewares/socket.js | 2 +- src/store/middlewares/voting.js | 2 +- 19 files changed, 45 insertions(+), 46 deletions(-) diff --git a/i18n/locales/en/common.json b/i18n/locales/en/common.json index 53496e54ec..0de381890d 100644 --- a/i18n/locales/en/common.json +++ b/i18n/locales/en/common.json @@ -305,7 +305,6 @@ "Sender": "Sender", "Session timeout": "Session timeout", "Session timeout in": "Session timeout in", - "Set max. amount": "Set max. amount", "Set up Lisk Hub and your account.": "Set up Lisk Hub and your account.", "Settings": "Settings", "Show more": "Show more", diff --git a/src/actions/account.js b/src/actions/account.js index ffafd67aa6..af1d38e9c8 100644 --- a/src/actions/account.js +++ b/src/actions/account.js @@ -69,7 +69,7 @@ export const passphraseUsed = data => ({ */ export const accountVotesFetched = ({ address }) => (dispatch, getState) => { - const activePeer = getState().peers.data; + const activePeer = getState().peers.liskAPIClient; return getAllVotes(activePeer, address).then(({ data }) => { dispatch({ type: actionTypes.accountAddVotes, @@ -83,7 +83,7 @@ export const accountVotesFetched = ({ address }) => */ export const accountVotersFetched = ({ publicKey }) => (dispatch, getState) => { - const activePeer = getState().peers.data; + const activePeer = getState().peers.liskAPIClient; return getVoters(activePeer, { publicKey }).then(({ data }) => { dispatch({ type: actionTypes.accountAddVoters, @@ -96,7 +96,7 @@ export const accountVotersFetched = ({ publicKey }) => */ export const secondPassphraseRegistered = ({ secondPassphrase, account, passphrase }) => (dispatch, getState) => { - const activePeer = getState().peers.data; + const activePeer = getState().peers.liskAPIClient; const timeOffset = getTimeOffset(getState()); setSecondPassphrase(activePeer, secondPassphrase, account.publicKey, passphrase, timeOffset) .then((data) => { @@ -120,7 +120,7 @@ export const secondPassphraseRegistered = ({ secondPassphrase, account, passphra export const updateDelegateAccount = ({ publicKey }) => (dispatch, getState) => { - const activePeer = getState().peers.data; + const activePeer = getState().peers.liskAPIClient; return getDelegate(activePeer, { publicKey }) .then((response) => { dispatch(accountUpdated(Object.assign( @@ -138,7 +138,7 @@ export const delegateRegistered = ({ }) => (dispatch, getState) => { const timeOffset = getTimeOffset(getState()); - const activePeer = getState().peers.data; + const activePeer = getState().peers.liskAPIClient; registerDelegate(activePeer, username, passphrase, secondPassphrase, timeOffset) .then((data) => { // dispatch to add to pending transaction @@ -163,7 +163,7 @@ export const delegateRegistered = ({ export const loadDelegate = ({ publicKey }) => (dispatch, getState) => { - const activePeer = getState().peers.data; + const activePeer = getState().peers.liskAPIClient; getDelegate(activePeer, { publicKey }).then((response) => { dispatch({ data: { @@ -180,7 +180,7 @@ export const loadAccount = ({ isSameAccount, }) => (dispatch, getState) => { - const activePeer = getState().peers.data; + const activePeer = getState().peers.liskAPIClient; getAccount(activePeer, address) .then((response) => { let accountDataUpdated = { @@ -228,7 +228,7 @@ export const accountDataUpdated = ({ account, windowIsFocused, transactions, }) => (dispatch, getState) => { - const activePeer = getState().peers.data; + const activePeer = getState().peers.liskAPIClient; getAccount(activePeer, account.address).then((result) => { if (result.balance !== account.balance) { dispatch(updateTransactionsIfNeeded( diff --git a/src/actions/delegate.js b/src/actions/delegate.js index ce51ed79a9..5cd3f91f7e 100644 --- a/src/actions/delegate.js +++ b/src/actions/delegate.js @@ -24,7 +24,7 @@ export const delegateRetrieving = data => ({ */ export const delegatesFetched = ({ username }) => (dispatch, getState) => { - const activePeer = getState().peers.data; + const activePeer = getState().peers.liskAPIClient; dispatch(delegateRetrieving()); getDelegate(activePeer, { username }) .then((response) => { diff --git a/src/actions/followedAccounts.js b/src/actions/followedAccounts.js index efba72b129..149d230fdc 100644 --- a/src/actions/followedAccounts.js +++ b/src/actions/followedAccounts.js @@ -23,7 +23,7 @@ export const followedAccountsRetrieved = accounts => ({ export const followedAccountFetchedAndUpdated = ({ account }) => (dispatch, getState) => { - const activePeer = getState().peers.data; + const activePeer = getState().peers.liskAPIClient; getAccount(activePeer, account.address).then((result) => { if (result.balance !== account.balance) { account.balance = result.balance; diff --git a/src/actions/peers.js b/src/actions/peers.js index 3b2d66f933..119a8b81e6 100644 --- a/src/actions/peers.js +++ b/src/actions/peers.js @@ -29,7 +29,7 @@ const login = (dispatch, getState, data, config) => { const { passphrase } = data; const { code } = data.network; const publicKey = passphrase ? extractPublicKey(passphrase) : data.publicKey; - const activePeer = store.peers.data || + const activePeer = store.peers.liskAPIClient || new Lisk.APIClient(config.nodes, { nethash: config.nethash }); const address = extractAddress(publicKey); const accountBasics = { diff --git a/src/actions/search.js b/src/actions/search.js index 9bafccc8af..182d77fd75 100644 --- a/src/actions/search.js +++ b/src/actions/search.js @@ -7,7 +7,7 @@ import searchAll from '../utils/api/search'; const searchDelegate = ({ publicKey, address }) => (dispatch, getState) => { - const activePeer = getState().peers.data; + const activePeer = getState().peers.liskAPIClient; getDelegate(activePeer, { publicKey }).then((response) => { dispatch({ data: { @@ -21,7 +21,7 @@ const searchDelegate = ({ publicKey, address }) => const searchVotes = ({ address }) => (dispatch, getState) => { - const activePeer = getState().peers.data; + const activePeer = getState().peers.liskAPIClient; getAllVotes(activePeer, address).then(response => dispatch({ type: actionTypes.searchVotes, @@ -36,7 +36,7 @@ const searchVoters = ({ address, publicKey, offset, limit, append, }) => (dispatch, getState) => { - const activePeer = getState().peers.data; + const activePeer = getState().peers.liskAPIClient; getVoters(activePeer, { publicKey, offset, limit, }).then(response => @@ -53,7 +53,7 @@ const searchVoters = ({ export const searchMoreVoters = ({ address, offset = 0, limit = 100 }) => (dispatch, getState) => { - const activePeer = getState().peers.data; + const activePeer = getState().peers.liskAPIClient; getAccount(activePeer, address).then((response) => { const accountData = { ...response, @@ -68,7 +68,7 @@ export const searchMoreVoters = ({ address, offset = 0, limit = 100 }) => export const searchAccount = ({ address }) => (dispatch, getState) => { - const activePeer = getState().peers.data; + const activePeer = getState().peers.liskAPIClient; dispatch(searchVotes({ address })); getAccount(activePeer, address).then((response) => { const accountData = { @@ -86,7 +86,7 @@ export const searchTransactions = ({ address, limit, filter, showLoading = true, }) => (dispatch, getState) => { - const activePeer = getState().peers.data; + const activePeer = getState().peers.liskAPIClient; if (showLoading) dispatch(loadingStarted(actionTypes.searchTransactions)); getTransactions({ activePeer, address, limit, filter, @@ -118,7 +118,7 @@ export const searchMoreTransactions = ({ address, limit, offset, filter, }) => (dispatch, getState) => { - const activePeer = getState().peers.data; + const activePeer = getState().peers.liskAPIClient; getTransactions({ activePeer, address, limit, offset, filter, }) @@ -137,7 +137,7 @@ export const searchMoreTransactions = ({ export const searchSuggestions = ({ searchTerm }) => (dispatch, getState) => { - const activePeer = getState().peers.data; + const activePeer = getState().peers.liskAPIClient; dispatch({ data: {}, type: actionTypes.searchClearSuggestions, diff --git a/src/actions/transactions.js b/src/actions/transactions.js index 6987db43f2..4b72242e8d 100644 --- a/src/actions/transactions.js +++ b/src/actions/transactions.js @@ -18,7 +18,7 @@ export const cleanTransactions = () => ({ export const transactionsFilterSet = ({ address, limit, filter, }) => (dispatch, getState) => { - const activePeer = getState().peers.data; + const activePeer = getState().peers.liskAPIClient; return getTransactions({ activePeer, @@ -48,7 +48,7 @@ export const transactionsFilterSet = ({ export const transactionsUpdateUnconfirmed = ({ address, pendingTransactions }) => (dispatch, getState) => { - const activePeer = getState().peers.data; + const activePeer = getState().peers.liskAPIClient; return unconfirmedTransactions(activePeer, address).then(response => dispatch({ data: { failed: pendingTransactions.filter(tx => @@ -69,7 +69,7 @@ export const loadTransactionsFinish = accountUpdated => export const loadTransactions = ({ publicKey, address }) => (dispatch, getState) => { - const activePeer = getState().peers.data; + const activePeer = getState().peers.liskAPIClient; const lastActiveAddress = publicKey && extractAddress(publicKey); const isSameAccount = lastActiveAddress === address; dispatch(loadingStarted(actionTypes.transactionsLoad)); @@ -94,7 +94,7 @@ export const transactionsRequested = ({ address, limit, offset, filter, }) => (dispatch, getState) => { - const activePeer = getState().peers.data; + const activePeer = getState().peers.liskAPIClient; getTransactions({ activePeer, address, limit, offset, filter, }) @@ -113,7 +113,7 @@ export const transactionsRequested = ({ export const loadTransaction = ({ id }) => (dispatch, getState) => { - const activePeer = getState().peers.data; + const activePeer = getState().peers.liskAPIClient; dispatch({ type: actionTypes.transactionCleared }); getSingleTransaction({ activePeer, id }) .then((response) => { @@ -185,7 +185,7 @@ export const transactionsUpdated = ({ address, limit, filter, pendingTransactions, }) => (dispatch, getState) => { - const activePeer = getState().peers.data; + const activePeer = getState().peers.liskAPIClient; getTransactions({ activePeer, address, limit, filter, }) @@ -219,7 +219,7 @@ export const sent = ({ account, recipientId, amount, passphrase, secondPassphrase, data, }) => (dispatch, getState) => { - const activePeer = getState().peers.data; + const activePeer = getState().peers.liskAPIClient; const timeOffset = getTimeOffset(getState()); send(activePeer, recipientId, toRawLsk(amount), passphrase, secondPassphrase, data, timeOffset) .then((response) => { diff --git a/src/actions/voting.js b/src/actions/voting.js index a8c4ca12bd..49a964d3dd 100644 --- a/src/actions/voting.js +++ b/src/actions/voting.js @@ -79,7 +79,7 @@ export const votePlaced = ({ votes, secondSecret, goToNextStep, }) => (dispatch, getState) => { - const activePeer = getState().peers.data; + const activePeer = getState().peers.liskAPIClient; const votedList = []; const unvotedList = []; const timeOffset = getTimeOffset(getState()); @@ -131,7 +131,7 @@ export const votePlaced = ({ */ export const votesFetched = ({ address, type }) => (dispatch, getState) => { - const activePeer = getState().peers.data; + const activePeer = getState().peers.liskAPIClient; listAccountDelegates(activePeer, address).then((response) => { if (type === 'update') { dispatch(votesUpdated({ list: response.data.votes })); @@ -148,7 +148,7 @@ export const delegatesFetched = ({ offset, refresh, q, }) => (dispatch, getState) => { - const activePeer = getState().peers.data; + const activePeer = getState().peers.liskAPIClient; let params = { offset, limit: '100', @@ -173,7 +173,7 @@ export const urlVotesFound = ({ upvotes, unvotes, address, }) => (dispatch, getState) => { - const activePeer = getState().peers.data; + const activePeer = getState().peers.liskAPIClient; const processUrlVotes = (votes) => { dispatch(votesAdded({ list: votes, upvotes, unvotes })); }; diff --git a/src/components/account/account.js b/src/components/account/account.js index 89798ce4e0..d0b2cd4eca 100644 --- a/src/components/account/account.js +++ b/src/components/account/account.js @@ -27,7 +27,7 @@ const Account = ({ peers, t, showNetworkIndicator }) => { : ; - const shouldShowNetworkIndicator = (peers.data && + const shouldShowNetworkIndicator = (peers.liskAPIClient && (showNetworkIndicator || peers.options.code !== networks.mainnet.code)); return (shouldShowNetworkIndicator ? @@ -38,7 +38,7 @@ const Account = ({ peers, t, showNetworkIndicator }) => { {t('Connected to ')}{translations[iconCode]} - {peers.data.currentNode} + {peers.liskAPIClient.currentNode} : diff --git a/src/components/account/account.test.js b/src/components/account/account.test.js index 401021512a..06cda92edb 100644 --- a/src/components/account/account.test.js +++ b/src/components/account/account.test.js @@ -63,7 +63,7 @@ describe('Account', () => { props.peers.status.online = true; props.peers.options.nethash = Lisk.constants.TESTNET_NETHASH; props.peers.options.code = networks.customNode.code; - props.peers.data.currentNode = 'http://localhost:4000'; + props.peers.liskAPIClient.currentNode = 'http://localhost:4000'; const wrapper = shallow(); wrapper.update(); expect(wrapper).to.have.exactly(1).descendants('.online'); diff --git a/src/components/ledger/ledgerLogin.js b/src/components/ledger/ledgerLogin.js index 0fadde45db..c778e92afe 100644 --- a/src/components/ledger/ledgerLogin.js +++ b/src/components/ledger/ledgerLogin.js @@ -192,7 +192,7 @@ class LedgerLogin extends React.Component { } const mapStateToProps = state => ({ - activePeer: state.peers && state.peers.data, + activePeer: state.peers && state.peers.liskAPIClient, settings: state.settings, }); diff --git a/src/components/loadingBar/loadingBar.js b/src/components/loadingBar/loadingBar.js index 33ea260577..d3ede8c1bd 100644 --- a/src/components/loadingBar/loadingBar.js +++ b/src/components/loadingBar/loadingBar.js @@ -15,7 +15,7 @@ class LoadingBar extends React.Component { } componentWillReceiveProps(nextProps) { - if (!this.markedAsLoaded && nextProps.peers.data) this.markLoaded(); + if (!this.markedAsLoaded && nextProps.peers.liskAPIClient) this.markLoaded(); if (nextProps.loading && nextProps.loading.length > 0 && this.props.loading.length === 0) { this.startTime = new Date(); @@ -31,7 +31,7 @@ class LoadingBar extends React.Component { } componentDidMount() { - if (this.props.peers.data) this.markLoaded(); + if (this.props.peers.liskAPIClient) this.markLoaded(); } componentWillUnmount() { diff --git a/src/components/login/index.js b/src/components/login/index.js index fd149fa63e..4b4d7ee322 100644 --- a/src/components/login/index.js +++ b/src/components/login/index.js @@ -24,7 +24,7 @@ const mapStateToProps = state => ({ account: state.account, peers: state.peers, settings: state.settings, - activePeer: state.peers && state.peers.data, + activePeer: state.peers && state.peers.liskAPIClient, }); const mapDispatchToProps = dispatch => ({ diff --git a/src/components/singleTransaction/index.js b/src/components/singleTransaction/index.js index e0c6412518..2c0ef94695 100644 --- a/src/components/singleTransaction/index.js +++ b/src/components/singleTransaction/index.js @@ -12,7 +12,7 @@ import styles from './singleTransaction.css'; class SingleTransaction extends React.Component { constructor(props) { super(props); - if (props.peers.data) { + if (props.peers.liskAPIClient) { this.props.loadTransaction({ id: this.props.match.params.id, }); @@ -20,7 +20,7 @@ class SingleTransaction extends React.Component { } componentWillReceiveProps(nextProps) { - if (nextProps.peers.data !== this.props.peers.data + if (nextProps.peers.liskAPIClient !== this.props.peers.liskAPIClient || nextProps.match.params.id !== this.props.match.params.id) { this.props.loadTransaction({ id: nextProps.match.params.id, diff --git a/src/components/transactions/transactionDetailView.js b/src/components/transactions/transactionDetailView.js index 399215586f..f4fa686496 100644 --- a/src/components/transactions/transactionDetailView.js +++ b/src/components/transactions/transactionDetailView.js @@ -23,7 +23,7 @@ class TransactionDetailView extends React.Component { const transactionId = this.getTransactionIdFromURL(); - if (props.peers.data && transactionId) { + if (props.peers.liskAPIClient && transactionId) { this.props.loadTransaction({ id: transactionId, }); @@ -38,7 +38,7 @@ class TransactionDetailView extends React.Component { nextProps.pendingTransactions.length === 0 && typeof nextProps.transaction === 'string') { const transactionId = this.getTransactionIdFromURL(); - if (this.props.peers.data && transactionId) { + if (this.props.peers.liskAPIClient && transactionId) { this.props.loadTransaction({ id: transactionId, }); diff --git a/src/store/middlewares/offline.js b/src/store/middlewares/offline.js index 70883a307a..d7bb31b994 100644 --- a/src/store/middlewares/offline.js +++ b/src/store/middlewares/offline.js @@ -22,7 +22,7 @@ const offlineMiddleware = store => next => (action) => { switch (action.type) { case actionsType.activePeerUpdate: if (action.data.online === false && state.peers.status.online === true) { - const address = `${state.peers.data.currentPeer}:${state.peers.data.port}`; + const address = `${state.peers.liskAPIClient.currentPeer}:${state.peers.liskAPIClient.port}`; const label = getErrorMessage(action.data.code, address); store.dispatch(errorToastDisplayed({ label })); store.dispatch(loadingStarted('offline')); diff --git a/src/store/middlewares/offline.test.js b/src/store/middlewares/offline.test.js index 7625bdd7be..4fb8bb3c80 100644 --- a/src/store/middlewares/offline.test.js +++ b/src/store/middlewares/offline.test.js @@ -63,7 +63,7 @@ describe('Offline middleware', () => { middleware(store)(next)(action); expect(store.dispatch).to.have.been.calledWith(errorToastDisplayed({ - label: i18next.t('Failed to connect: Node {{address}} is not active', { address: `${peers.data.currentPeer}:${peers.data.port}` }), + label: i18next.t('Failed to connect: Node {{address}} is not active', { address: `${peers.liskAPIClient.currentPeer}:${peers.liskAPIClient.port}` }), })); }); diff --git a/src/store/middlewares/socket.js b/src/store/middlewares/socket.js index 781c27a9bb..4e0d759640 100644 --- a/src/store/middlewares/socket.js +++ b/src/store/middlewares/socket.js @@ -21,7 +21,7 @@ const socketSetup = (store) => { ipc.on('focus', () => { windowIsFocused = true; }); } - connection = io.connect(store.getState().peers.data.currentNode); + connection = io.connect(store.getState().peers.liskAPIClient.currentNode); connection.on('blocks/change', (block) => { store.dispatch({ type: actionTypes.newBlockCreated, diff --git a/src/store/middlewares/voting.js b/src/store/middlewares/voting.js index 50e6025da0..0cd64781f2 100644 --- a/src/store/middlewares/voting.js +++ b/src/store/middlewares/voting.js @@ -10,7 +10,7 @@ const updateLookupStatus = (store, list, username) => { const lookupDelegate = (store, username) => { const state = store.getState(); - const activePeer = state.peers.data; + const activePeer = state.peers.liskAPIClient; const delegate = state.voting.delegates.filter(d => d.username === username)[0]; if (delegate) { return new Promise((resolve) => { From 7cb33dc18459e5b8a44dbe81a7230c8c7c9b605d Mon Sep 17 00:00:00 2001 From: michaeltomasik Date: Thu, 15 Nov 2018 01:13:58 +0100 Subject: [PATCH 02/11] :recycle: peers.data to peers.liskAPIClient --- src/actions/account.test.js | 14 +++++++------- src/actions/delegate.test.js | 2 +- src/actions/followedAccounts.test.js | 2 +- src/actions/peers.test.js | 2 +- src/actions/search.test.js | 2 +- src/actions/transactions.test.js | 10 +++++----- src/actions/voting.test.js | 14 +++++++------- src/components/account/account.test.js | 2 +- src/components/app/index.test.js | 4 ++-- src/components/header/header.test.js | 2 +- src/components/header/index.test.js | 2 +- src/components/loadingBar/loadingBar.test.js | 2 +- .../transactions/transactionDetailView.test.js | 6 +++--- .../transactions/transactionType.test.js | 2 +- .../transactions/transactionsOverview.test.js | 4 ++-- src/components/voteUrlProcessor/index.test.js | 2 +- src/components/votingListView/votingHeader.test.js | 2 +- src/store/middlewares/account.test.js | 4 ++-- src/store/middlewares/peers.test.js | 2 +- src/store/middlewares/socket.test.js | 4 ++-- src/store/middlewares/voting.test.js | 2 +- 21 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/actions/account.test.js b/src/actions/account.test.js index 8a3f69d16e..c4cd684a94 100644 --- a/src/actions/account.test.js +++ b/src/actions/account.test.js @@ -70,7 +70,7 @@ describe('actions: account', () => { accountApiMock = stub(accountApi, 'setSecondPassphrase'); dispatch = spy(); getState = () => ({ - peers: { data: {} }, + peers: { liskAPIClient: {} }, }); i18nextMock = stub(i18next, 't'); i18next.t = key => key; @@ -137,7 +137,7 @@ describe('actions: account', () => { delegateApiMock = stub(delegateApi, 'registerDelegate'); dispatch = spy(); getState = () => ({ - peers: { data: {} }, + peers: { liskAPIClient: {} }, blocks: { latestBlocks: [] }, }); }); @@ -198,7 +198,7 @@ describe('actions: account', () => { delegateApiMock = stub(delegateApi, 'getDelegate'); dispatch = spy(); getState = () => ({ - peers: { data: {} }, + peers: { liskAPIClient: {} }, }); }); @@ -247,7 +247,7 @@ describe('actions: account', () => { getAccountStub = stub(accountApi, 'getAccount').returnsPromise(); transactionsActionsStub = spy(transactionsActions, 'loadTransactionsFinish'); getState = () => ({ - peers: { data: {} }, + peers: { liskAPIClient: {} }, }); }); @@ -316,7 +316,7 @@ describe('actions: account', () => { getAccountStub = stub(accountApi, 'getAccount').returnsPromise(); transactionsActionsStub = spy(transactionsActions, 'transactionsUpdated'); getState = () => ({ - peers: { data: {} }, + peers: { liskAPIClient: {} }, }); }); @@ -373,7 +373,7 @@ describe('actions: account', () => { beforeEach(() => { transactionsActionsStub = spy(transactionsActions, 'transactionsUpdated'); getState = () => ({ - peers: { data: {} }, + peers: { liskAPIClient: {} }, }); }); @@ -409,7 +409,7 @@ describe('actions: account', () => { beforeEach(() => { stub(delegateApi, 'getDelegate').returnsPromise(); getState = () => ({ - peers: { data: {} }, + peers: { liskAPIClient: {} }, }); }); diff --git a/src/actions/delegate.test.js b/src/actions/delegate.test.js index cd1c2a1314..3c19dacacb 100644 --- a/src/actions/delegate.test.js +++ b/src/actions/delegate.test.js @@ -21,7 +21,7 @@ describe('actions: delegate', () => { getDelegateStub = sinon.stub(delegateApi, 'getDelegate'); dispatch = sinon.spy(); getState = () => ({ - peers: { data: {} }, + peers: { liskAPIClient: {} }, }); }); diff --git a/src/actions/followedAccounts.test.js b/src/actions/followedAccounts.test.js index 0f1c79ee3e..91c8b7ceda 100644 --- a/src/actions/followedAccounts.test.js +++ b/src/actions/followedAccounts.test.js @@ -19,7 +19,7 @@ describe('actions: followedAccount', () => { title: accounts.genesis.address, }; const getState = () => ({ - peers: { data: {} }, + peers: { liskAPIClient: {} }, }); it('should create an action to retrieve the followed accounts list', () => { diff --git a/src/actions/peers.test.js b/src/actions/peers.test.js index 25b9dad702..1777cc43fa 100644 --- a/src/actions/peers.test.js +++ b/src/actions/peers.test.js @@ -38,7 +38,7 @@ describe('actions: peers', () => { getState = () => ({ peers: { - data: {}, + liskAPIClient: {}, }, account: {}, settings: { autoLog: true }, diff --git a/src/actions/search.test.js b/src/actions/search.test.js index 1fe79a88f8..8c70097e70 100644 --- a/src/actions/search.test.js +++ b/src/actions/search.test.js @@ -19,7 +19,7 @@ describe('actions: search', () => { dispatch = spy(); getState = stub().withArgs(match.any).returns({ peers: { - data: {}, + liskAPIClient: {}, }, }); diff --git a/src/actions/transactions.test.js b/src/actions/transactions.test.js index 744526e16c..07d388454c 100644 --- a/src/actions/transactions.test.js +++ b/src/actions/transactions.test.js @@ -13,7 +13,7 @@ import { toRawLsk } from '../utils/lsk'; describe('actions: transactions', () => { let getState = () => ({ - peers: { data: {} }, + peers: { liskAPIClient: {} }, }); describe('transactionsUpdated', () => { @@ -93,7 +93,7 @@ describe('actions: transactions', () => { describe('loadTransaction', () => { getState = () => ({ peers: { - data: { + liskAPIClient: { options: { name: networks.mainnet.name, }, @@ -117,7 +117,7 @@ describe('actions: transactions', () => { dispatch = sinon.spy(); getState = () => ({ peers: { - data: { + liskAPIClient: { options: { name: 'Mainnet', }, @@ -176,7 +176,7 @@ describe('actions: transactions', () => { describe('sent', () => { getState = () => ({ - peers: { data: {} }, + peers: { liskAPIClient: {} }, }); let transactionsApiMock; const data = { @@ -196,7 +196,7 @@ describe('actions: transactions', () => { transactionsApiMock = sinon.stub(transactionsApi, 'send'); dispatch = sinon.spy(); getState = () => ({ - peers: { data: {} }, + peers: { liskAPIClient: {} }, }); }); diff --git a/src/actions/voting.test.js b/src/actions/voting.test.js index dd43297453..8e842a310d 100644 --- a/src/actions/voting.test.js +++ b/src/actions/voting.test.js @@ -24,7 +24,7 @@ const delegateList = [ describe('actions: voting', () => { let getState = () => ({ - peers: { data: {} }, + peers: { liskAPIClient: {} }, }); describe('voteToggled', () => { @@ -112,7 +112,7 @@ describe('actions: voting', () => { account, votes, secondSecret, goToNextStep, }); getState = () => ({ - peers: { data: {} }, + peers: { liskAPIClient: {} }, }); }); @@ -166,7 +166,7 @@ describe('actions: voting', () => { beforeEach(() => { delegateApiMock = sinon.stub(delegateApi, 'listAccountDelegates').returnsPromise(); getState = () => ({ - peers: { data: {} }, + peers: { liskAPIClient: {} }, }); }); @@ -212,7 +212,7 @@ describe('actions: voting', () => { getState = () => ({ peers: { - data: { + liskAPIClient: { options: { name: networks.mainnet.name, }, @@ -229,7 +229,7 @@ describe('actions: voting', () => { const dispatch = sinon.spy(); getState = () => ({ peers: { - data: { + liskAPIClient: { options: { name: networks.mainnet.name, }, @@ -261,13 +261,13 @@ describe('actions: voting', () => { }; getState = () => ({ - peers: { data: {} }, + peers: { liskAPIClient: {} }, }); beforeEach(() => { delegateApiMock = sinon.stub(delegateApi, 'listAccountDelegates').returnsPromise(); getState = () => ({ - peers: { data: {} }, + peers: { liskAPIClient: {} }, }); }); diff --git a/src/components/account/account.test.js b/src/components/account/account.test.js index 06cda92edb..f8017af8ee 100644 --- a/src/components/account/account.test.js +++ b/src/components/account/account.test.js @@ -20,7 +20,7 @@ describe('Account', () => { status: { online: false, }, - data: { + liskAPIClient: { currentPeer: 'localhost', port: 4000, }, diff --git a/src/components/app/index.test.js b/src/components/app/index.test.js index 47d1775bbd..8e530c3475 100644 --- a/src/components/app/index.test.js +++ b/src/components/app/index.test.js @@ -38,7 +38,7 @@ describe('App', () => { const store = fakeStore({ account: {}, dialog: {}, - peers: { data: { options: {} }, options: {} }, + peers: { liskAPIClient: { options: {} }, options: {} }, settings: { autoLog: true, advancedMode: true, @@ -84,7 +84,7 @@ describe('App', () => { status: { online: true, }, - data: { + liskAPIClient: { options: { name: 'Test', }, diff --git a/src/components/header/header.test.js b/src/components/header/header.test.js index dc4580d8ed..ea264442ff 100644 --- a/src/components/header/header.test.js +++ b/src/components/header/header.test.js @@ -14,7 +14,7 @@ describe('Header', () => { let wrapper; const mountWithRouter = (node, options) => mount({node}, options); const storeObject = { - peers: { data: {}, options: {} }, + peers: { liskAPIClient: {}, options: {} }, account: {}, activePeerSet: () => {}, search: { diff --git a/src/components/header/index.test.js b/src/components/header/index.test.js index 6fa4feba28..711b06e6ca 100644 --- a/src/components/header/index.test.js +++ b/src/components/header/index.test.js @@ -16,7 +16,7 @@ import HeaderHOC from './index'; describe('HeaderHOC', () => { let wrapper; const store = configureMockStore([])({ - peers: { data: {}, options: {} }, + peers: { liskAPIClient: {}, options: {} }, account: {}, activePeerSet: () => {}, settings: { diff --git a/src/components/loadingBar/loadingBar.test.js b/src/components/loadingBar/loadingBar.test.js index 358b3d4e86..abf55c23e4 100644 --- a/src/components/loadingBar/loadingBar.test.js +++ b/src/components/loadingBar/loadingBar.test.js @@ -55,7 +55,7 @@ describe('LoadingBar Container', () => { it('should call markAsLoaded after peer is set', () => { const wrapper = mount(); expect(props.markAsLoaded).to.not.have.been.calledWith(); - wrapper.setProps({ peers: { data: {} } }); + wrapper.setProps({ peers: { liskAPIClient: {} } }); expect(props.markAsLoaded).to.have.been.calledWith(); }); }); diff --git a/src/components/transactions/transactionDetailView.test.js b/src/components/transactions/transactionDetailView.test.js index f2095d336f..a28a9a19fd 100644 --- a/src/components/transactions/transactionDetailView.test.js +++ b/src/components/transactions/transactionDetailView.test.js @@ -11,7 +11,7 @@ describe('TransactionDetailView', () => { const context = { storeState: { peers: { - data: {}, + liskAPIClient: {}, options: {}, }, transaction: { @@ -50,7 +50,7 @@ describe('TransactionDetailView', () => { const context = { storeState: { peers: { - data: {}, + liskAPIClient: {}, options: {}, }, transaction: { @@ -99,7 +99,7 @@ describe('TransactionDetailView', () => { const context = { storeState: { peers: { - data: {}, + liskAPIClient: {}, options: {}, }, transaction: { diff --git a/src/components/transactions/transactionType.test.js b/src/components/transactions/transactionType.test.js index 704c446313..408e28f9fa 100644 --- a/src/components/transactions/transactionType.test.js +++ b/src/components/transactions/transactionType.test.js @@ -10,7 +10,7 @@ import i18n from '../../i18n'; const store = configureMockStore([])({ peers: { - data: {}, + liskAPIClient: {}, }, account: {}, }); diff --git a/src/components/transactions/transactionsOverview.test.js b/src/components/transactions/transactionsOverview.test.js index ecd8a00dd0..2d447b85bf 100644 --- a/src/components/transactions/transactionsOverview.test.js +++ b/src/components/transactions/transactionsOverview.test.js @@ -19,7 +19,7 @@ describe('TransactionsOverview', () => { t: () => {}, loading: [], peers: { - data: {}, + liskAPIClient: {}, }, transactions: [{ id: '13395546734664987127' }], count: 1000, @@ -30,7 +30,7 @@ describe('TransactionsOverview', () => { }; store.getState = () => ({ followedAccounts: { accounts: [] }, - peers: { status: {}, options: {}, data: {} }, + peers: { status: {}, options: {}, liskAPIClient: {} }, transactions: { confirmed: [], }, diff --git a/src/components/voteUrlProcessor/index.test.js b/src/components/voteUrlProcessor/index.test.js index a69f8ea2e0..731661a096 100644 --- a/src/components/voteUrlProcessor/index.test.js +++ b/src/components/voteUrlProcessor/index.test.js @@ -17,7 +17,7 @@ describe('VoteUrlProcessorHOC', () => { dummy: 'dummy', }; const state = { - peers: { data: {} }, + peers: { liskAPIClient: {} }, account: {}, voting: { voteLookupStatus: { diff --git a/src/components/votingListView/votingHeader.test.js b/src/components/votingListView/votingHeader.test.js index 0c55a0425c..c9e1732519 100644 --- a/src/components/votingListView/votingHeader.test.js +++ b/src/components/votingListView/votingHeader.test.js @@ -20,7 +20,7 @@ describe('VotingHeader', () => { const store = configureMockStore([])({ peers: { - data: {}, + liskAPIClient: {}, }, voting: { votes, diff --git a/src/store/middlewares/account.test.js b/src/store/middlewares/account.test.js index 90cc7a6b96..5d4fed03e6 100644 --- a/src/store/middlewares/account.test.js +++ b/src/store/middlewares/account.test.js @@ -61,7 +61,7 @@ describe('Account middleware', () => { store.dispatch = spy(); state = { peers: { - data: {}, + liskAPIClient: {}, }, account: { address: 'sample_address', @@ -145,7 +145,7 @@ describe('Account middleware', () => { }], confirmed: [{ confirmations: 10, address: 'sample_address' }], }, - peers: { data: {} }, + peers: { liskAPIClient: {} }, }); middleware(store)(next)(newBlockCreated); diff --git a/src/store/middlewares/peers.test.js b/src/store/middlewares/peers.test.js index 33f70b7872..8b1c4e6195 100644 --- a/src/store/middlewares/peers.test.js +++ b/src/store/middlewares/peers.test.js @@ -21,7 +21,7 @@ describe('Peer middleware', () => { store.getState = () => ({ peers: { - data: {}, + liskAPIClient: {}, }, account: {}, }); diff --git a/src/store/middlewares/socket.test.js b/src/store/middlewares/socket.test.js index 56d126d63a..562311eb41 100644 --- a/src/store/middlewares/socket.test.js +++ b/src/store/middlewares/socket.test.js @@ -32,7 +32,7 @@ describe('Socket middleware', () => { store = { getState: () => ({ - peers: { data: { options: { address: 'localhost:4000' } } }, + peers: { liskAPIClient: { options: { address: 'localhost:4000' } } }, account: { address: '1234' }, }), dispatch: spy(), @@ -78,7 +78,7 @@ describe('Socket middleware', () => { it(`should dispatch ${actionTypes.accountLoggedIn} with https protocol`, () => { store.getState = () => ({ ...store, - peers: { data: { options: { ssl: true, address: 'localhost:4000' } } }, + peers: { liskAPIClient: { options: { ssl: true, address: 'localhost:4000' } } }, }); middleware(store)(next)({ type: actionTypes.accountLoggedIn }); expect(store.dispatch).to.not.have.been.calledWith(activePeerUpdate({ online: true })); diff --git a/src/store/middlewares/voting.test.js b/src/store/middlewares/voting.test.js index 618149cc71..9d0605e296 100644 --- a/src/store/middlewares/voting.test.js +++ b/src/store/middlewares/voting.test.js @@ -75,7 +75,7 @@ describe('voting middleware', () => { }, }, peers: { - data: {}, + liskAPIClient: {}, }, }; let getDelegateMock; From a9d24a910597e6dd8382580a4c51e21991ee44d3 Mon Sep 17 00:00:00 2001 From: michaeltomasik Date: Thu, 15 Nov 2018 01:24:16 +0100 Subject: [PATCH 03/11] :recycle: Fix more tests after renaming peers.data --- src/store/middlewares/offline.test.js | 2 +- src/store/reducers/peers.js | 2 +- src/store/reducers/peers.test.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/store/middlewares/offline.test.js b/src/store/middlewares/offline.test.js index 4fb8bb3c80..21d0dd74ec 100644 --- a/src/store/middlewares/offline.test.js +++ b/src/store/middlewares/offline.test.js @@ -23,7 +23,7 @@ describe('Offline middleware', () => { data: {}, }; peers = { - data: { + liskAPIClient: { port: 4000, currentPeer: 'localhost', }, diff --git a/src/store/reducers/peers.js b/src/store/reducers/peers.js index 783fad3200..35476c7ceb 100644 --- a/src/store/reducers/peers.js +++ b/src/store/reducers/peers.js @@ -12,7 +12,7 @@ const peers = (state = { status: {}, options: {} }, action) => { switch (action.type) { case actionTypes.activePeerSet: return Object.assign({}, state, { - data: action.data.activePeer ? action.data.activePeer : action.data, + liskAPIClient: action.data.activePeer ? action.data.activePeer : action.data, // options are duplicated here because lisk-js later on removes it from the 'data' object options: action.data.options, }); diff --git a/src/store/reducers/peers.test.js b/src/store/reducers/peers.test.js index 6036e97d4b..79e7949474 100644 --- a/src/store/reducers/peers.test.js +++ b/src/store/reducers/peers.test.js @@ -17,7 +17,7 @@ describe('Reducer: peers(state, action)', () => { }, }; - const newState = { data: action.data, options: action.data.options }; + const newState = { liskAPIClient: action.data, options: action.data.options }; const changedState = peers(state, action); expect(changedState).to.deep.equal(newState); }); From 3fa4e46dcb1019e2e4a9a5db139277eb8b19d397 Mon Sep 17 00:00:00 2001 From: michaeltomasik Date: Thu, 15 Nov 2018 01:28:52 +0100 Subject: [PATCH 04/11] :recycle: change activePeer -> liskAPIClient --- docs/REDUX_ACTIONS.md | 6 +-- src/actions/account.js | 32 ++++++------ src/actions/delegate.js | 4 +- src/actions/followedAccounts.js | 4 +- src/actions/peers.js | 6 +-- src/actions/search.js | 32 ++++++------ src/actions/search.test.js | 2 +- src/actions/transactions.js | 37 +++++++------- src/actions/voting.js | 18 +++---- src/components/ledger/ledgerLogin.js | 6 +-- src/components/login/index.js | 2 +- src/components/send/steps/form/stories.js | 4 +- .../explorerTransactions/index.test.js | 4 +- .../walletTransactions/index.test.js | 4 +- src/store/middlewares/login.js | 4 +- src/store/middlewares/peers.js | 2 +- src/store/middlewares/voting.js | 4 +- src/store/reducers/peers.js | 2 +- src/utils/api/account.js | 14 +++--- src/utils/api/account.test.js | 14 +++--- src/utils/api/delegate.js | 37 +++++++------- src/utils/api/delegate.test.js | 50 +++++++++---------- src/utils/api/ledger.js | 24 ++++----- src/utils/api/peers.js | 4 +- src/utils/api/peers.test.js | 12 ++--- src/utils/api/search.js | 20 ++++---- src/utils/api/transactions.js | 18 +++---- src/utils/api/transactions.test.js | 24 ++++----- src/utils/delegates.js | 8 +-- src/utils/delegates.test.js | 6 +-- test/integration/accountTransactions.test.js | 8 +-- test/integration/wallet.test.js | 14 +++--- 32 files changed, 214 insertions(+), 212 deletions(-) diff --git a/docs/REDUX_ACTIONS.md b/docs/REDUX_ACTIONS.md index c786f40631..0a03dbe23a 100644 --- a/docs/REDUX_ACTIONS.md +++ b/docs/REDUX_ACTIONS.md @@ -68,7 +68,7 @@ After clicking `Logout` it executes: After clicking `Send` it executes: -- Calls [`activePeer.transactions.broadcast(transaction)`](https://github.com/LiskHQ/lisk-hub/blob/e71527bd273af2f16d6980fe3b0c1a379694c45b/src/utils/api/transactions.js#L17) and then dispatches [`TRANSACTION_ADDED`](https://github.com/LiskHQ/lisk-hub/blob/2811c2be14fe5ab4ead3e4a375b20b67348fc191/src/store/reducers/transactions.js#L10) +- Calls [`liskAPIClient.transactions.broadcast(transaction)`](https://github.com/LiskHQ/lisk-hub/blob/e71527bd273af2f16d6980fe3b0c1a379694c45b/src/utils/api/transactions.js#L17) and then dispatches [`TRANSACTION_ADDED`](https://github.com/LiskHQ/lisk-hub/blob/2811c2be14fe5ab4ead3e4a375b20b67348fc191/src/store/reducers/transactions.js#L10) ### Delegates voting @@ -76,7 +76,7 @@ After clicking `Send` it executes: After clicking `Confirm` it executes: -- Calls [`activePeer.transactions.broadcast(transaction)`](https://github.com/LiskHQ/lisk-hub/blob/e71527bd273af2f16d6980fe3b0c1a379694c45b/src/utils/api/delegate.js#L34) and then dispatches [`TRANSACTION_ADDED`](https://github.com/LiskHQ/lisk-hub/blob/2811c2be14fe5ab4ead3e4a375b20b67348fc191/src/store/reducers/transactions.js#L10) +- Calls [`liskAPIClient.transactions.broadcast(transaction)`](https://github.com/LiskHQ/lisk-hub/blob/e71527bd273af2f16d6980fe3b0c1a379694c45b/src/utils/api/delegate.js#L34) and then dispatches [`TRANSACTION_ADDED`](https://github.com/LiskHQ/lisk-hub/blob/2811c2be14fe5ab4ead3e4a375b20b67348fc191/src/store/reducers/transactions.js#L10) On delegate select/uselect it executes: - On Select -- [`voteToggled`](https://github.com/LiskHQ/lisk-hub/blob/d27796d57eb9246fae5876f02b242e6bb8343775/src/store/reducers/voting.js#L76) it adds to `voting.votes` redux new voted delegate object @@ -87,7 +87,7 @@ On delegate select/uselect it executes: After going thru whole process and clicking `Confirm` it executes: -- Calls [`activePeer.transactions.broadcast(transaction)`](https://github.com/LiskHQ/lisk-hub/blob/e71527bd273af2f16d6980fe3b0c1a379694c45b/src/utils/api/transactions.js#L17) and then dispatches [`TRANSACTION_ADDED`](https://github.com/LiskHQ/lisk-hub/blob/2811c2be14fe5ab4ead3e4a375b20b67348fc191/src/store/reducers/transactions.js#L10) +- Calls [`liskAPIClient.transactions.broadcast(transaction)`](https://github.com/LiskHQ/lisk-hub/blob/e71527bd273af2f16d6980fe3b0c1a379694c45b/src/utils/api/transactions.js#L17) and then dispatches [`TRANSACTION_ADDED`](https://github.com/LiskHQ/lisk-hub/blob/2811c2be14fe5ab4ead3e4a375b20b67348fc191/src/store/reducers/transactions.js#L10) ## Socket diff --git a/src/actions/account.js b/src/actions/account.js index af1d38e9c8..5ccf2bc921 100644 --- a/src/actions/account.js +++ b/src/actions/account.js @@ -69,8 +69,8 @@ export const passphraseUsed = data => ({ */ export const accountVotesFetched = ({ address }) => (dispatch, getState) => { - const activePeer = getState().peers.liskAPIClient; - return getAllVotes(activePeer, address).then(({ data }) => { + const liskAPIClient = getState().peers.liskAPIClient; + return getAllVotes(liskAPIClient, address).then(({ data }) => { dispatch({ type: actionTypes.accountAddVotes, votes: data.votes, @@ -83,8 +83,8 @@ export const accountVotesFetched = ({ address }) => */ export const accountVotersFetched = ({ publicKey }) => (dispatch, getState) => { - const activePeer = getState().peers.liskAPIClient; - return getVoters(activePeer, { publicKey }).then(({ data }) => { + const liskAPIClient = getState().peers.liskAPIClient; + return getVoters(liskAPIClient, { publicKey }).then(({ data }) => { dispatch({ type: actionTypes.accountAddVoters, voters: data, @@ -96,9 +96,9 @@ export const accountVotersFetched = ({ publicKey }) => */ export const secondPassphraseRegistered = ({ secondPassphrase, account, passphrase }) => (dispatch, getState) => { - const activePeer = getState().peers.liskAPIClient; + const liskAPIClient = getState().peers.liskAPIClient; const timeOffset = getTimeOffset(getState()); - setSecondPassphrase(activePeer, secondPassphrase, account.publicKey, passphrase, timeOffset) + setSecondPassphrase(liskAPIClient, secondPassphrase, account.publicKey, passphrase, timeOffset) .then((data) => { dispatch({ data: { @@ -120,8 +120,8 @@ export const secondPassphraseRegistered = ({ secondPassphrase, account, passphra export const updateDelegateAccount = ({ publicKey }) => (dispatch, getState) => { - const activePeer = getState().peers.liskAPIClient; - return getDelegate(activePeer, { publicKey }) + const liskAPIClient = getState().peers.liskAPIClient; + return getDelegate(liskAPIClient, { publicKey }) .then((response) => { dispatch(accountUpdated(Object.assign( {}, @@ -138,8 +138,8 @@ export const delegateRegistered = ({ }) => (dispatch, getState) => { const timeOffset = getTimeOffset(getState()); - const activePeer = getState().peers.liskAPIClient; - registerDelegate(activePeer, username, passphrase, secondPassphrase, timeOffset) + const liskAPIClient = getState().peers.liskAPIClient; + registerDelegate(liskAPIClient, username, passphrase, secondPassphrase, timeOffset) .then((data) => { // dispatch to add to pending transaction dispatch({ @@ -163,8 +163,8 @@ export const delegateRegistered = ({ export const loadDelegate = ({ publicKey }) => (dispatch, getState) => { - const activePeer = getState().peers.liskAPIClient; - getDelegate(activePeer, { publicKey }).then((response) => { + const liskAPIClient = getState().peers.liskAPIClient; + getDelegate(liskAPIClient, { publicKey }).then((response) => { dispatch({ data: { delegate: response.delegate, @@ -180,8 +180,8 @@ export const loadAccount = ({ isSameAccount, }) => (dispatch, getState) => { - const activePeer = getState().peers.liskAPIClient; - getAccount(activePeer, address) + const liskAPIClient = getState().peers.liskAPIClient; + getAccount(liskAPIClient, address) .then((response) => { let accountDataUpdated = { confirmed: transactionsResponse.data, @@ -228,8 +228,8 @@ export const accountDataUpdated = ({ account, windowIsFocused, transactions, }) => (dispatch, getState) => { - const activePeer = getState().peers.liskAPIClient; - getAccount(activePeer, account.address).then((result) => { + const liskAPIClient = getState().peers.liskAPIClient; + getAccount(liskAPIClient, account.address).then((result) => { if (result.balance !== account.balance) { dispatch(updateTransactionsIfNeeded( { diff --git a/src/actions/delegate.js b/src/actions/delegate.js index 5cd3f91f7e..d756075b37 100644 --- a/src/actions/delegate.js +++ b/src/actions/delegate.js @@ -24,9 +24,9 @@ export const delegateRetrieving = data => ({ */ export const delegatesFetched = ({ username }) => (dispatch, getState) => { - const activePeer = getState().peers.liskAPIClient; + const liskAPIClient = getState().peers.liskAPIClient; dispatch(delegateRetrieving()); - getDelegate(activePeer, { username }) + getDelegate(liskAPIClient, { username }) .then((response) => { if (response.data.length > 0) { dispatch(delegateRetrieved({ delegate: response.data[0], username })); diff --git a/src/actions/followedAccounts.js b/src/actions/followedAccounts.js index 149d230fdc..97b1055000 100644 --- a/src/actions/followedAccounts.js +++ b/src/actions/followedAccounts.js @@ -23,8 +23,8 @@ export const followedAccountsRetrieved = accounts => ({ export const followedAccountFetchedAndUpdated = ({ account }) => (dispatch, getState) => { - const activePeer = getState().peers.liskAPIClient; - getAccount(activePeer, account.address).then((result) => { + const liskAPIClient = getState().peers.liskAPIClient; + getAccount(liskAPIClient, account.address).then((result) => { if (result.balance !== account.balance) { account.balance = result.balance; dispatch(followedAccountUpdated(account)); diff --git a/src/actions/peers.js b/src/actions/peers.js index 119a8b81e6..7acb731828 100644 --- a/src/actions/peers.js +++ b/src/actions/peers.js @@ -15,7 +15,7 @@ const peerSet = (data, config) => ({ data: Object.assign({ passphrase: data.passphrase, publicKey: data.publicKey, - activePeer: new Lisk.APIClient(config.nodes, { nethash: config.nethash }), + liskAPIClient: new Lisk.APIClient(config.nodes, { nethash: config.nethash }), options: config, loginType: data.loginType, }), @@ -29,7 +29,7 @@ const login = (dispatch, getState, data, config) => { const { passphrase } = data; const { code } = data.network; const publicKey = passphrase ? extractPublicKey(passphrase) : data.publicKey; - const activePeer = store.peers.liskAPIClient || + const liskAPIClient = store.peers.liskAPIClient || new Lisk.APIClient(config.nodes, { nethash: config.nethash }); const address = extractAddress(publicKey); const accountBasics = { @@ -43,7 +43,7 @@ const login = (dispatch, getState, data, config) => { dispatch(accountLoading()); // redirect to main/transactions - getAccount(activePeer, address).then((accountData) => { + getAccount(liskAPIClient, address).then((accountData) => { const duration = (passphrase && store.settings.autoLog) ? Date.now() + lockDuration : 0; const accountUpdated = { diff --git a/src/actions/search.js b/src/actions/search.js index 182d77fd75..3c20cee2e4 100644 --- a/src/actions/search.js +++ b/src/actions/search.js @@ -7,8 +7,8 @@ import searchAll from '../utils/api/search'; const searchDelegate = ({ publicKey, address }) => (dispatch, getState) => { - const activePeer = getState().peers.liskAPIClient; - getDelegate(activePeer, { publicKey }).then((response) => { + const liskAPIClient = getState().peers.liskAPIClient; + getDelegate(liskAPIClient, { publicKey }).then((response) => { dispatch({ data: { delegate: response.data[0], @@ -21,8 +21,8 @@ const searchDelegate = ({ publicKey, address }) => const searchVotes = ({ address }) => (dispatch, getState) => { - const activePeer = getState().peers.liskAPIClient; - getAllVotes(activePeer, address).then(response => + const liskAPIClient = getState().peers.liskAPIClient; + getAllVotes(liskAPIClient, address).then(response => dispatch({ type: actionTypes.searchVotes, data: { @@ -36,8 +36,8 @@ const searchVoters = ({ address, publicKey, offset, limit, append, }) => (dispatch, getState) => { - const activePeer = getState().peers.liskAPIClient; - getVoters(activePeer, { + const liskAPIClient = getState().peers.liskAPIClient; + getVoters(liskAPIClient, { publicKey, offset, limit, }).then(response => dispatch({ @@ -53,8 +53,8 @@ const searchVoters = ({ export const searchMoreVoters = ({ address, offset = 0, limit = 100 }) => (dispatch, getState) => { - const activePeer = getState().peers.liskAPIClient; - getAccount(activePeer, address).then((response) => { + const liskAPIClient = getState().peers.liskAPIClient; + getAccount(liskAPIClient, address).then((response) => { const accountData = { ...response, }; @@ -68,9 +68,9 @@ export const searchMoreVoters = ({ address, offset = 0, limit = 100 }) => export const searchAccount = ({ address }) => (dispatch, getState) => { - const activePeer = getState().peers.liskAPIClient; + const liskAPIClient = getState().peers.liskAPIClient; dispatch(searchVotes({ address })); - getAccount(activePeer, address).then((response) => { + getAccount(liskAPIClient, address).then((response) => { const accountData = { ...response, }; @@ -86,10 +86,10 @@ export const searchTransactions = ({ address, limit, filter, showLoading = true, }) => (dispatch, getState) => { - const activePeer = getState().peers.liskAPIClient; + const liskAPIClient = getState().peers.liskAPIClient; if (showLoading) dispatch(loadingStarted(actionTypes.searchTransactions)); getTransactions({ - activePeer, address, limit, filter, + liskAPIClient, address, limit, filter, }) .then((transactionsResponse) => { dispatch({ @@ -118,9 +118,9 @@ export const searchMoreTransactions = ({ address, limit, offset, filter, }) => (dispatch, getState) => { - const activePeer = getState().peers.liskAPIClient; + const liskAPIClient = getState().peers.liskAPIClient; getTransactions({ - activePeer, address, limit, offset, filter, + liskAPIClient, address, limit, offset, filter, }) .then((transactionsResponse) => { dispatch({ @@ -137,12 +137,12 @@ export const searchMoreTransactions = ({ export const searchSuggestions = ({ searchTerm }) => (dispatch, getState) => { - const activePeer = getState().peers.liskAPIClient; + const liskAPIClient = getState().peers.liskAPIClient; dispatch({ data: {}, type: actionTypes.searchClearSuggestions, }); - searchAll({ activePeer, searchTerm }).then(response => dispatch({ + searchAll({ liskAPIClient, searchTerm }).then(response => dispatch({ data: response, type: actionTypes.searchSuggestions, })); diff --git a/src/actions/search.test.js b/src/actions/search.test.js index 8c70097e70..f1b104c838 100644 --- a/src/actions/search.test.js +++ b/src/actions/search.test.js @@ -32,7 +32,7 @@ describe('actions: search', () => { }); it('should clear suggestions and search for {delegates,addresses,transactions}', () => { - const data = { activePeer: {}, searchTerm: '' }; + const data = { liskAPIClient: {}, searchTerm: '' }; const action = searchSuggestions(data); action(dispatch, getState); expect(dispatch).to.have.been.calledWith({ diff --git a/src/actions/transactions.js b/src/actions/transactions.js index 4b72242e8d..0ea78a3932 100644 --- a/src/actions/transactions.js +++ b/src/actions/transactions.js @@ -18,10 +18,10 @@ export const cleanTransactions = () => ({ export const transactionsFilterSet = ({ address, limit, filter, }) => (dispatch, getState) => { - const activePeer = getState().peers.liskAPIClient; + const liskAPIClient = getState().peers.liskAPIClient; return getTransactions({ - activePeer, + liskAPIClient, address, limit, filter, @@ -48,8 +48,8 @@ export const transactionsFilterSet = ({ export const transactionsUpdateUnconfirmed = ({ address, pendingTransactions }) => (dispatch, getState) => { - const activePeer = getState().peers.liskAPIClient; - return unconfirmedTransactions(activePeer, address).then(response => dispatch({ + const liskAPIClient = getState().peers.liskAPIClient; + return unconfirmedTransactions(liskAPIClient, address).then(response => dispatch({ data: { failed: pendingTransactions.filter(tx => response.data.filter(unconfirmedTx => tx.id === unconfirmedTx.id).length === 0), @@ -69,11 +69,11 @@ export const loadTransactionsFinish = accountUpdated => export const loadTransactions = ({ publicKey, address }) => (dispatch, getState) => { - const activePeer = getState().peers.liskAPIClient; + const liskAPIClient = getState().peers.liskAPIClient; const lastActiveAddress = publicKey && extractAddress(publicKey); const isSameAccount = lastActiveAddress === address; dispatch(loadingStarted(actionTypes.transactionsLoad)); - getTransactions({ activePeer, address, limit: 25 }) + getTransactions({ liskAPIClient, address, limit: 25 }) .then((transactionsResponse) => { dispatch(loadAccount({ address, @@ -94,9 +94,9 @@ export const transactionsRequested = ({ address, limit, offset, filter, }) => (dispatch, getState) => { - const activePeer = getState().peers.liskAPIClient; + const liskAPIClient = getState().peers.liskAPIClient; getTransactions({ - activePeer, address, limit, offset, filter, + liskAPIClient, address, limit, offset, filter, }) .then((response) => { dispatch({ @@ -113,9 +113,9 @@ export const transactionsRequested = ({ export const loadTransaction = ({ id }) => (dispatch, getState) => { - const activePeer = getState().peers.liskAPIClient; + const liskAPIClient = getState().peers.liskAPIClient; dispatch({ type: actionTypes.transactionCleared }); - getSingleTransaction({ activePeer, id }) + getSingleTransaction({ liskAPIClient, id }) .then((response) => { let added = []; let deleted = []; @@ -132,7 +132,7 @@ export const loadTransaction = ({ id }) => deleted = response.data[0].asset.votes.filter(item => item.startsWith('-')).map(item => item.replace('-', '')); } - const localStorageDelegates = loadDelegateCache(activePeer); + const localStorageDelegates = loadDelegateCache(liskAPIClient); deleted.forEach((publicKey) => { const address = extractAddress(publicKey); const storedDelegate = localStorageDelegates[address]; @@ -148,7 +148,7 @@ export const loadTransaction = ({ id }) => type: actionTypes.transactionAddDelegateName, }); } else { - getDelegate(activePeer, { publicKey }) + getDelegate(liskAPIClient, { publicKey }) .then((delegateData) => { dispatch({ data: { delegate: delegateData.data[0], voteArrayName: 'deleted' }, @@ -166,7 +166,7 @@ export const loadTransaction = ({ id }) => type: actionTypes.transactionAddDelegateName, }); } else { - getDelegate(activePeer, { publicKey }) + getDelegate(liskAPIClient, { publicKey }) .then((delegateData) => { dispatch({ data: { delegate: delegateData.data[0], voteArrayName: 'added' }, @@ -185,9 +185,9 @@ export const transactionsUpdated = ({ address, limit, filter, pendingTransactions, }) => (dispatch, getState) => { - const activePeer = getState().peers.liskAPIClient; + const liskAPIClient = getState().peers.liskAPIClient; getTransactions({ - activePeer, address, limit, filter, + liskAPIClient, address, limit, filter, }) .then((response) => { dispatch({ @@ -206,7 +206,7 @@ export const transactionsUpdated = ({ // TODO: figure out how to make this work again /* dispatch(transactionsUpdateUnconfirmed({ - activePeer, + liskAPIClient, address, pendingTransactions, })); @@ -219,9 +219,10 @@ export const sent = ({ account, recipientId, amount, passphrase, secondPassphrase, data, }) => (dispatch, getState) => { - const activePeer = getState().peers.liskAPIClient; + const liskAPIClient = getState().peers.liskAPIClient; const timeOffset = getTimeOffset(getState()); - send(activePeer, recipientId, toRawLsk(amount), passphrase, secondPassphrase, data, timeOffset) + // eslint-disable-next-line + send(liskAPIClient, recipientId, toRawLsk(amount),passphrase, secondPassphrase, data, timeOffset) .then((response) => { dispatch({ data: { diff --git a/src/actions/voting.js b/src/actions/voting.js index 49a964d3dd..9e5f6d76e3 100644 --- a/src/actions/voting.js +++ b/src/actions/voting.js @@ -79,7 +79,7 @@ export const votePlaced = ({ votes, secondSecret, goToNextStep, }) => (dispatch, getState) => { - const activePeer = getState().peers.liskAPIClient; + const liskAPIClient = getState().peers.liskAPIClient; const votedList = []; const unvotedList = []; const timeOffset = getTimeOffset(getState()); @@ -93,7 +93,7 @@ export const votePlaced = ({ }); vote( - activePeer, + liskAPIClient, passphrase, account.publicKey, votedList, @@ -131,8 +131,8 @@ export const votePlaced = ({ */ export const votesFetched = ({ address, type }) => (dispatch, getState) => { - const activePeer = getState().peers.liskAPIClient; - listAccountDelegates(activePeer, address).then((response) => { + const liskAPIClient = getState().peers.liskAPIClient; + listAccountDelegates(liskAPIClient, address).then((response) => { if (type === 'update') { dispatch(votesUpdated({ list: response.data.votes })); } else { @@ -148,15 +148,15 @@ export const delegatesFetched = ({ offset, refresh, q, }) => (dispatch, getState) => { - const activePeer = getState().peers.liskAPIClient; + const liskAPIClient = getState().peers.liskAPIClient; let params = { offset, limit: '100', sort: 'rank:asc', }; params = q ? { ...params, search: q } : params; - listDelegates(activePeer, params).then((response) => { - updateDelegateCache(response.data, activePeer); + listDelegates(liskAPIClient, params).then((response) => { + updateDelegateCache(response.data, liskAPIClient); dispatch(delegatesAdded({ list: response.data, totalDelegates: response.data.length, @@ -173,11 +173,11 @@ export const urlVotesFound = ({ upvotes, unvotes, address, }) => (dispatch, getState) => { - const activePeer = getState().peers.liskAPIClient; + const liskAPIClient = getState().peers.liskAPIClient; const processUrlVotes = (votes) => { dispatch(votesAdded({ list: votes, upvotes, unvotes })); }; - listAccountDelegates(activePeer, address) + listAccountDelegates(liskAPIClient, address) .then((response) => { processUrlVotes(response.data.votes); }) .catch(() => { processUrlVotes([]); }); }; diff --git a/src/components/ledger/ledgerLogin.js b/src/components/ledger/ledgerLogin.js index c778e92afe..3d177e3818 100644 --- a/src/components/ledger/ledgerLogin.js +++ b/src/components/ledger/ledgerLogin.js @@ -31,7 +31,7 @@ class LedgerLogin extends React.Component { // async componentDidUpdate(prevProps) { // if (this.props.settings.ledgerAccountAmount !== prevProps.settings.ledgerAccountAmount) { // const accountInfo = await getLedgerAccountInfo - // (this.props.activePeer, this.state.hwAccounts.length); // eslint-disable-line + // (this.props.liskAPIClient, this.state.hwAccounts.length); // eslint-disable-line // this.setState({ hwAccounts: this.state.hwAccounts.concat([accountInfo]) }); // } @@ -54,7 +54,7 @@ class LedgerLogin extends React.Component { try { switch (this.props.loginType) { // eslint-disable-line case 0: - accountInfo = await getLedgerAccountInfo(this.props.activePeer, index); + accountInfo = await getLedgerAccountInfo(this.props.liskAPIClient, index); break; // case loginTypes.trezor: // this.props.errorToastDisplayed({ @@ -192,7 +192,7 @@ class LedgerLogin extends React.Component { } const mapStateToProps = state => ({ - activePeer: state.peers && state.peers.liskAPIClient, + liskAPIClient: state.peers && state.peers.liskAPIClient, settings: state.settings, }); diff --git a/src/components/login/index.js b/src/components/login/index.js index 4b4d7ee322..15818e5b0c 100644 --- a/src/components/login/index.js +++ b/src/components/login/index.js @@ -24,7 +24,7 @@ const mapStateToProps = state => ({ account: state.account, peers: state.peers, settings: state.settings, - activePeer: state.peers && state.peers.liskAPIClient, + liskAPIClient: state.peers && state.peers.liskAPIClient, }); const mapDispatchToProps = dispatch => ({ diff --git a/src/components/send/steps/form/stories.js b/src/components/send/steps/form/stories.js index d394677005..0d19c1db87 100644 --- a/src/components/send/steps/form/stories.js +++ b/src/components/send/steps/form/stories.js @@ -17,8 +17,8 @@ storiesOf('Form', module) )) .add('pre-filled recipient and amount', () => ( -
+ )) .add('without pre-filles', () => ( - + )); diff --git a/src/components/transactions/explorerTransactions/index.test.js b/src/components/transactions/explorerTransactions/index.test.js index 03de2244ff..77d1c613c0 100644 --- a/src/components/transactions/explorerTransactions/index.test.js +++ b/src/components/transactions/explorerTransactions/index.test.js @@ -73,14 +73,14 @@ describe('ExplorerTransactions Component', () => { }; transactionsActionStub.withArgs({ - activePeer: match.any, + liskAPIClient: match.any, address: accounts.genesis.address, limit: 25, filter: undefined, }).returnsPromise().resolves({ data: [{ id: 'Some ID', type: txTypes.vote }], meta: { count: 1000 } }); transactionsActionStub.withArgs({ - activePeer: match.any, + liskAPIClient: match.any, address: accounts.genesis.address, limit: 25, filter: txFilters.all, diff --git a/src/components/transactions/walletTransactions/index.test.js b/src/components/transactions/walletTransactions/index.test.js index df434b04e6..a4727955a1 100644 --- a/src/components/transactions/walletTransactions/index.test.js +++ b/src/components/transactions/walletTransactions/index.test.js @@ -58,7 +58,7 @@ describe('WalletTransactions Component', () => { }; transactionsActionsStub.withArgs({ - activePeer: match.any, + liskAPIClient: match.any, address: accounts.genesis.address, limit: 25, filter: txFilters.all, @@ -66,7 +66,7 @@ describe('WalletTransactions Component', () => { transactionsActionsStub.withArgs({ - activePeer: match.any, + liskAPIClient: match.any, address: match.any, limit: 25, filter: txFilters.statistics, diff --git a/src/store/middlewares/login.js b/src/store/middlewares/login.js index bd8985ed42..de68971773 100644 --- a/src/store/middlewares/login.js +++ b/src/store/middlewares/login.js @@ -17,7 +17,7 @@ const loginMiddleware = store => next => (action) => { } next(action); - const { passphrase, activePeer, options } = action.data; + const { passphrase, liskAPIClient, options } = action.data; const publicKey = passphrase ? extractPublicKey(passphrase) : action.data.publicKey; const address = extractAddress(publicKey); const accountBasics = { @@ -31,7 +31,7 @@ const loginMiddleware = store => next => (action) => { store.dispatch(accountLoading()); // redirect to main/transactions - return getAccount(activePeer, address).then((accountData) => { + return getAccount(liskAPIClient, address).then((accountData) => { const duration = (passphrase && store.getState().settings.autoLog) ? Date.now() + lockDuration : 0; const accountUpdated = { diff --git a/src/store/middlewares/peers.js b/src/store/middlewares/peers.js index eede43c35e..b8bcb661fa 100644 --- a/src/store/middlewares/peers.js +++ b/src/store/middlewares/peers.js @@ -24,7 +24,7 @@ const peersMiddleware = store => next => (action) => { switch (action.type) { case actionTypes.storeCreated: - // It stops activePeer to be overridden to mainnet + // It stops liskAPIClient to be overridden to mainnet // when we want to autologin for explorer account // https://github.com/LiskHQ/lisk-hub/issues/1339 /* istanbul ignore else */ diff --git a/src/store/middlewares/voting.js b/src/store/middlewares/voting.js index 0cd64781f2..507e39e5ad 100644 --- a/src/store/middlewares/voting.js +++ b/src/store/middlewares/voting.js @@ -10,14 +10,14 @@ const updateLookupStatus = (store, list, username) => { const lookupDelegate = (store, username) => { const state = store.getState(); - const activePeer = state.peers.liskAPIClient; + const liskAPIClient = state.peers.liskAPIClient; const delegate = state.voting.delegates.filter(d => d.username === username)[0]; if (delegate) { return new Promise((resolve) => { resolve({ delegate }); }); } - return getDelegate(activePeer, { username }); + return getDelegate(liskAPIClient, { username }); }; const processVote = (store, options, username) => { diff --git a/src/store/reducers/peers.js b/src/store/reducers/peers.js index 35476c7ceb..eb2154099b 100644 --- a/src/store/reducers/peers.js +++ b/src/store/reducers/peers.js @@ -12,7 +12,7 @@ const peers = (state = { status: {}, options: {} }, action) => { switch (action.type) { case actionTypes.activePeerSet: return Object.assign({}, state, { - liskAPIClient: action.data.activePeer ? action.data.activePeer : action.data, + liskAPIClient: action.data.liskAPIClient ? action.data.liskAPIClient : action.data, // options are duplicated here because lisk-js later on removes it from the 'data' object options: action.data.options, }); diff --git a/src/utils/api/account.js b/src/utils/api/account.js index aacab33785..4878c932d4 100644 --- a/src/utils/api/account.js +++ b/src/utils/api/account.js @@ -1,12 +1,12 @@ // import { requestToActivePeer } from './peers'; import Lisk from 'lisk-elements'; -export const getAccount = (activePeer, address) => +export const getAccount = (liskAPIClient, address) => new Promise((resolve, reject) => { - if (!activePeer) { + if (!liskAPIClient) { reject(); } - activePeer.accounts.get({ address }).then((res) => { + liskAPIClient.accounts.get({ address }).then((res) => { if (res.data.length > 0) { resolve({ ...res.data[0], @@ -23,11 +23,11 @@ export const getAccount = (activePeer, address) => }).catch(reject); }); -// export const setSecondPassphrase = (activePeer, secondSecret, publicKey, secret) => -// requestToActivePeer(activePeer, 'signatures', { secondSecret, publicKey, secret }); +// export const setSecondPassphrase = (liskAPIClient, secondSecret, publicKey, secret) => +// requestToActivePeer(liskAPIClient, 'signatures', { secondSecret, publicKey, secret }); export const setSecondPassphrase = ( - activePeer, + liskAPIClient, secondPassphrase, publicKey, passphrase, @@ -36,7 +36,7 @@ export const setSecondPassphrase = ( new Promise((resolve, reject) => { const transaction = Lisk.transaction .registerSecondPassphrase({ passphrase, secondPassphrase, timeOffset }); - activePeer.transactions.broadcast(transaction).then(() => { + liskAPIClient.transactions.broadcast(transaction).then(() => { resolve(transaction); }).catch(reject); }); diff --git a/src/utils/api/account.test.js b/src/utils/api/account.test.js index a0a5ab6e21..bcd85be59e 100644 --- a/src/utils/api/account.test.js +++ b/src/utils/api/account.test.js @@ -7,14 +7,14 @@ describe('Utils: Account API', () => { describe('getAccount', () => { let activePeerMock; - const activePeer = { + const liskAPIClient = { accounts: { get: () => {}, }, }; beforeEach(() => { - activePeerMock = mock(activePeer.accounts); + activePeerMock = mock(liskAPIClient.accounts); }); afterEach(() => { @@ -22,20 +22,20 @@ describe('Utils: Account API', () => { activePeerMock.restore(); }); - it('should return a promise that is resolved when activePeer.getAccount() calls its callback with data.success == true', () => { + it('should return a promise that is resolved when liskAPIClient.getAccount() calls its callback with data.success == true', () => { const account = { address, balance: 0, publicKey: 'sample_key' }; const response = { data: [{ ...account }] }; activePeerMock.expects('get').withArgs({ address }).returnsPromise().resolves(response); - const requestPromise = getAccount(activePeer, address); + const requestPromise = getAccount(liskAPIClient, address); return expect(requestPromise).to.eventually.eql({ ...account, serverPublicKey: 'sample_key' }); }); - it('should return a promise that is resolved even when activePeer.getAccount() calls its callback with data.success == false and "Account not found"', () => { + it('should return a promise that is resolved even when liskAPIClient.getAccount() calls its callback with data.success == false and "Account not found"', () => { const account = { address, balance: 0 }; activePeerMock.expects('get').withArgs({ address }).returnsPromise().resolves({ data: [] }); - const requestPromise = getAccount(activePeer, address); + const requestPromise = getAccount(liskAPIClient, address); return expect(requestPromise).to.eventually.eql(account); }); @@ -43,7 +43,7 @@ describe('Utils: Account API', () => { const response = { success: false }; activePeerMock.expects('get').withArgs({ address }).returnsPromise().rejects(response); - const requestPromise = getAccount(activePeer, address); + const requestPromise = getAccount(liskAPIClient, address); return expect(requestPromise).to.eventually.be.rejectedWith(response); }); }); diff --git a/src/utils/api/delegate.js b/src/utils/api/delegate.js index 5a64bde3f2..ac18ed447c 100644 --- a/src/utils/api/delegate.js +++ b/src/utils/api/delegate.js @@ -1,23 +1,23 @@ import Lisk from 'lisk-elements'; -export const listAccountDelegates = (activePeer, address) => - activePeer.votes.get({ address, limit: '101' }); +export const listAccountDelegates = (liskAPIClient, address) => + liskAPIClient.votes.get({ address, limit: '101' }); -export const listDelegates = (activePeer, options) => new Promise((resolve, reject) => { - if (!activePeer) { +export const listDelegates = (liskAPIClient, options) => new Promise((resolve, reject) => { + if (!liskAPIClient) { reject(); } else { - activePeer.delegates.get(options) + liskAPIClient.delegates.get(options) .then(response => resolve(response)) .catch(error => reject(error)); } }); -export const getDelegate = (activePeer, options) => - activePeer.delegates.get(options); +export const getDelegate = (liskAPIClient, options) => + liskAPIClient.delegates.get(options); export const vote = ( - activePeer, + liskAPIClient, passphrase, publicKey, votes, @@ -33,31 +33,32 @@ export const vote = ( timeOffset, }); return new Promise((resolve, reject) => { - activePeer.transactions.broadcast(transaction).then(() => resolve(transaction)).catch(reject); + liskAPIClient.transactions.broadcast(transaction) + .then(() => resolve(transaction)).catch(reject); }); }; -export const getVotes = (activePeer, { address, offset, limit }) => - activePeer.votes.get({ address, limit, offset }); +export const getVotes = (liskAPIClient, { address, offset, limit }) => + liskAPIClient.votes.get({ address, limit, offset }); -export const getAllVotes = (activePeer, address) => +export const getAllVotes = (liskAPIClient, address) => new Promise((resolve, reject) => { - getVotes(activePeer, { address, offset: 0, limit: 100 }).then((votesEarlyBatch) => { + getVotes(liskAPIClient, { address, offset: 0, limit: 100 }).then((votesEarlyBatch) => { if (votesEarlyBatch.data.votes && votesEarlyBatch.data.votesUsed < 101) { return resolve(votesEarlyBatch); } - return getVotes(activePeer, { address, offset: 100, limit: 1 }).then((votesLasteBatch) => { + return getVotes(liskAPIClient, { address, offset: 100, limit: 1 }).then((votesLasteBatch) => { votesEarlyBatch.data.votes = [...votesEarlyBatch.data.votes, ...votesLasteBatch.data.votes]; return resolve(votesEarlyBatch); }).catch(reject); }).catch(reject); }); -export const getVoters = (activePeer, { publicKey, offset = 0, limit = 100 }) => - activePeer.voters.get({ publicKey, offset, limit }); +export const getVoters = (liskAPIClient, { publicKey, offset = 0, limit = 100 }) => + liskAPIClient.voters.get({ publicKey, offset, limit }); export const registerDelegate = ( - activePeer, + liskAPIClient, username, passphrase, secondPassphrase = null, @@ -69,7 +70,7 @@ export const registerDelegate = ( } return new Promise((resolve, reject) => { const transaction = Lisk.transaction.registerDelegate({ ...data }); - activePeer.transactions + liskAPIClient.transactions .broadcast(transaction) .then(() => { resolve(transaction); diff --git a/src/utils/api/delegate.test.js b/src/utils/api/delegate.test.js index 18d888ec14..e749316827 100644 --- a/src/utils/api/delegate.test.js +++ b/src/utils/api/delegate.test.js @@ -21,7 +21,7 @@ describe('Utils: Delegate', () => { let liskTransactionsRegisterDelegateStub; const timeOffset = 0; - const activePeer = { + const liskAPIClient = { delegates: { get: () => { }, }, @@ -39,10 +39,10 @@ describe('Utils: Delegate', () => { beforeEach(() => { liskTransactionsCastVotesStub = sinon.stub(Lisk.transaction, 'castVotes'); liskTransactionsRegisterDelegateStub = sinon.stub(Lisk.transaction, 'registerDelegate'); - activePeerMockDelegates = sinon.mock(activePeer.delegates); - activePeerMockVotes = sinon.mock(activePeer.votes); - activePeerMockVoters = sinon.mock(activePeer.voters); - activePeerMockTransations = sinon.stub(activePeer.transactions, 'broadcast').returnsPromise().resolves({ id: '1234' }); + activePeerMockDelegates = sinon.mock(liskAPIClient.delegates); + activePeerMockVotes = sinon.mock(liskAPIClient.votes); + activePeerMockVoters = sinon.mock(liskAPIClient.voters); + activePeerMockTransations = sinon.stub(liskAPIClient.transactions, 'broadcast').returnsPromise().resolves({ id: '1234' }); }); afterEach(() => { @@ -65,37 +65,37 @@ describe('Utils: Delegate', () => { it('should get votes for an address with 101 limit', () => { const address = '123L'; activePeerMockVotes.expects('get').withArgs({ address, limit: '101' }).once(); - listAccountDelegates(activePeer, address); + listAccountDelegates(liskAPIClient, address); }); }); describe('listDelegates', () => { - it('should return getDelegate(activePeer, options) if options = {}', () => { + it('should return getDelegate(liskAPIClient, options) if options = {}', () => { const options = {}; const response = { data: [] }; activePeerMockDelegates.expects('get').withArgs(options).returnsPromise().resolves(response); - const returnedPromise = listDelegates(activePeer, options); + const returnedPromise = listDelegates(liskAPIClient, options); expect(returnedPromise).to.eventually.equal(response); }); - it('should return getDelegate(activePeer, options) if options.q is set', () => { + it('should return getDelegate(liskAPIClient, options) if options.q is set', () => { const options = { q: 'genesis_1' }; const response = { data: [] }; activePeerMockDelegates.expects('get').withArgs(options).returnsPromise().resolves(response); - const returnedPromise = listDelegates(activePeer, options); + const returnedPromise = listDelegates(liskAPIClient, options); return expect(returnedPromise).to.eventually.equal(response); }); }); describe('getDelegate', () => { - it('should return getDelegate(activePeer, options)', () => { + it('should return getDelegate(liskAPIClient, options)', () => { const options = { publicKey: `"${accounts.delegate.publicKey}"` }; const response = { data: [] }; activePeerMockDelegates.expects('get').withArgs(options).returnsPromise().resolves(response); - const returnedPromise = getDelegate(activePeer, options); + const returnedPromise = getDelegate(liskAPIClient, options); return expect(returnedPromise).to.eventually.equal(response); }); }); @@ -121,7 +121,7 @@ describe('Utils: Delegate', () => { }).returns(transaction); vote( - activePeer, + liskAPIClient, accounts.genesis.passphrase, accounts.genesis.publicKey, votes, @@ -129,7 +129,7 @@ describe('Utils: Delegate', () => { secondPassphrase, timeOffset, ); - expect(activePeer.transactions.broadcast).to.have.been.calledWith(transaction); + expect(liskAPIClient.transactions.broadcast).to.have.been.calledWith(transaction); }); }); @@ -139,7 +139,7 @@ describe('Utils: Delegate', () => { const offset = 0; const limit = 100; activePeerMockVotes.expects('get').withArgs({ address, offset, limit }).once(); - getVotes(activePeer, { address, offset, limit }); + getVotes(liskAPIClient, { address, offset, limit }); }); }); @@ -150,7 +150,7 @@ describe('Utils: Delegate', () => { .returnsPromise().resolves({ data: { votes: [1, 2, 3], votesUsed: 101 } }); activePeerMockVotes.expects('get').withArgs({ address, offset: 100, limit: 1 }) .returnsPromise().resolves({ data: { votes: [4], votesUsed: 101 } }); - const returnedPromise = getAllVotes(activePeer, address); + const returnedPromise = getAllVotes(liskAPIClient, address); expect(returnedPromise).to.eventually.equal([1, 2, 3, 4]); }); @@ -158,29 +158,29 @@ describe('Utils: Delegate', () => { const address = '123L'; activePeerMockVotes.expects('get').withArgs({ address, offset: 0, limit: 100 }) .returnsPromise().resolves({ data: { votes: [1], votesUsed: 1 } }); - const returnedPromise = getAllVotes(activePeer, address); + const returnedPromise = getAllVotes(liskAPIClient, address); expect(returnedPromise).to.eventually.equal([1]); }); }); describe('getVoters', () => { - it('should return getVoters(activePeer, { publicKey, offset: 0, limit: 100 })', () => { + it('should return getVoters(liskAPIClient, { publicKey, offset: 0, limit: 100 })', () => { const publicKey = ''; activePeerMockVoters.expects('get').withArgs({ publicKey, offset: 0, limit: 100 }) .returnsPromise().resolves('resolved promise'); - const returnedPromise = getVoters(activePeer, { publicKey, offset: 0, limit: 100 }); + const returnedPromise = getVoters(liskAPIClient, { publicKey, offset: 0, limit: 100 }); expect(returnedPromise).to.eventually.equal('resolved promise'); }); }); describe('getVoters', () => { - it('should return getVoters(activePeer, { publicKey })', () => { + it('should return getVoters(liskAPIClient, { publicKey })', () => { const publicKey = ''; activePeerMockVoters.expects('get').withArgs({ publicKey, offset: 0, limit: 100 }) .returnsPromise().resolves('resolved promise'); - const returnedPromise = getVoters(activePeer, { publicKey }); + const returnedPromise = getVoters(liskAPIClient, { publicKey }); expect(returnedPromise).to.eventually.equal('resolved promise'); }); }); @@ -198,8 +198,8 @@ describe('Utils: Delegate', () => { timeOffset, }).returns(transaction); - registerDelegate(activePeer, username, passphrase, secondPassphrase, timeOffset); - expect(activePeer.transactions.broadcast).to.have.been.calledWith(transaction); + registerDelegate(liskAPIClient, username, passphrase, secondPassphrase, timeOffset); + expect(liskAPIClient.transactions.broadcast).to.have.been.calledWith(transaction); }); it('should broadcast a registerDelegate transaction with second passphrase', () => { @@ -215,8 +215,8 @@ describe('Utils: Delegate', () => { timeOffset, }).returns(transaction); - registerDelegate(activePeer, username, passphrase, secondPassphrase, timeOffset); - expect(activePeer.transactions.broadcast).to.have.been.calledWith(transaction); + registerDelegate(liskAPIClient, username, passphrase, secondPassphrase, timeOffset); + expect(liskAPIClient.transactions.broadcast).to.have.been.calledWith(transaction); }); }); }); diff --git a/src/utils/api/ledger.js b/src/utils/api/ledger.js index 3edc381721..6d117518d2 100644 --- a/src/utils/api/ledger.js +++ b/src/utils/api/ledger.js @@ -19,7 +19,7 @@ import { getAccount } from './account'; */ /* eslint-disable prefer-const */ export const sendWithLedger = - (activePeer, account, recipientId, amount, pin = null, data = null) => + (liskAPIClient, account, recipientId, amount, pin = null, data = null) => new Promise(async (resolve, reject) => { const rawTx = createSendTX(account.publicKey, recipientId, amount, data); let error; @@ -28,7 +28,7 @@ export const sendWithLedger = if (error) { reject(error); } else { - activePeer.transactions.broadcast(signedTx).then(() => { + liskAPIClient.transactions.broadcast(signedTx).then(() => { resolve(signedTx); }).catch(reject); } @@ -39,7 +39,7 @@ export const sendWithLedger = * NOTE: secondPassphrase for ledger is a PIN (numeric) * @returns Promise - Action RegisterDelegate with Ledger */ -export const registerDelegateWithLedger = (activePeer, account, username, pin = null) => +export const registerDelegateWithLedger = (liskAPIClient, account, username, pin = null) => new Promise(async (resolve, reject) => { const rawTx = createDelegateTX(account.publicKey, username); let error; @@ -48,7 +48,7 @@ export const registerDelegateWithLedger = (activePeer, account, username, pin = if (error) { reject(error); } else { - activePeer.transactions.broadcast(signedTx).then(() => { + liskAPIClient.transactions.broadcast(signedTx).then(() => { resolve(signedTx); }).catch(reject); } @@ -58,7 +58,7 @@ export const registerDelegateWithLedger = (activePeer, account, username, pin = * NOTE: secondPassphrase for ledger is a PIN (numeric) * @returns Promise - Action Vote with Ledger */ -export const voteWithLedger = (activePeer, account, votedList, unvotedList, pin = null) => +export const voteWithLedger = (liskAPIClient, account, votedList, unvotedList, pin = null) => new Promise(async (resolve, reject) => { const rawTx = createRawVoteTX(account.publicKey, account.address, votedList, unvotedList); let error; @@ -67,7 +67,7 @@ export const voteWithLedger = (activePeer, account, votedList, unvotedList, pin if (error) { reject(error); } else { - activePeer.transactions.broadcast(signedTx).then(() => { + liskAPIClient.transactions.broadcast(signedTx).then(() => { resolve(signedTx); }).catch(reject); } @@ -77,7 +77,7 @@ export const voteWithLedger = (activePeer, account, votedList, unvotedList, pin * NOTE: secondPassphrase for ledger is a PIN (numeric) * @returns Promise - Action SetSecondPassphrase with Ledger */ -export const setSecondPassphraseWithLedger = (activePeer, account, pin) => +export const setSecondPassphraseWithLedger = (liskAPIClient, account, pin) => new Promise(async (resolve, reject) => { let error; let signedTx; @@ -94,28 +94,28 @@ export const setSecondPassphraseWithLedger = (activePeer, account, pin) => if (error) { reject(error); } else { - activePeer.transactions.broadcast(signedTx).then(() => { + liskAPIClient.transactions.broadcast(signedTx).then(() => { resolve(signedTx); }).catch(reject); } }); -export const getLedgerAccountInfo = async (activePeer, accountIndex) => { +export const getLedgerAccountInfo = async (liskAPIClient, accountIndex) => { let error; let liskAccount; [error, liskAccount] = await to(getAccountFromLedgerIndex(accountIndex)); if (error) { throw error; } - let resAccount = await getAccount(activePeer, liskAccount.address); + let resAccount = await getAccount(liskAPIClient, liskAccount.address); const isInitialized = !!resAccount.unconfirmedBalance; Object.assign(resAccount, { isInitialized }); // Set PublicKey from Ledger Info // so we can switch on this account even if publicKey is not revealed to the network Object.assign(resAccount, { publicKey: liskAccount.publicKey }); // if (isInitialized) { - // const txAccount = await getTransactions(activePeer, liskAccount.address); + // const txAccount = await getTransactions(liskAPIClient, liskAccount.address); // Object.assign(resAccount, { txCount: txAccount.meta.count }); - // const votesAccount = await getVotes(activePeer, liskAccount.address); + // const votesAccount = await getVotes(liskAPIClient, liskAccount.address); // Object.assign(resAccount, { votesCount: votesAccount.data.votesUsed }); // } return resAccount; diff --git a/src/utils/api/peers.js b/src/utils/api/peers.js index f8802ca8af..7f56f270f1 100644 --- a/src/utils/api/peers.js +++ b/src/utils/api/peers.js @@ -1,7 +1,7 @@ // eslint-disable-next-line import/prefer-default-export -export const requestToActivePeer = (activePeer, path, urlParams) => +export const requestToActivePeer = (liskAPIClient, path, urlParams) => new Promise((resolve, reject) => { - activePeer.sendRequest(path, urlParams, (data) => { + liskAPIClient.sendRequest(path, urlParams, (data) => { if (data.success) { resolve(data); } else { diff --git a/src/utils/api/peers.test.js b/src/utils/api/peers.test.js index 04916de475..4a75f3fb74 100644 --- a/src/utils/api/peers.test.js +++ b/src/utils/api/peers.test.js @@ -8,35 +8,35 @@ describe('Utils: Peers', () => { let activePeerMock; const path = '/test/'; const urlParams = {}; - const activePeer = { + const liskAPIClient = { sendRequest: () => { }, }; beforeEach(() => { - activePeerMock = mock(activePeer); + activePeerMock = mock(liskAPIClient); }); afterEach(() => { activePeerMock.restore(); }); - it('should return a promise that is resolved when activePeer.sendRequest() calls its callback with data.success == true', () => { + it('should return a promise that is resolved when liskAPIClient.sendRequest() calls its callback with data.success == true', () => { const response = { success: true, data: [], }; activePeerMock.expects('sendRequest').withArgs(path, urlParams).callsArgWith(2, response); - const requestPromise = requestToActivePeer(activePeer, path, urlParams); + const requestPromise = requestToActivePeer(liskAPIClient, path, urlParams); expect(requestPromise).to.eventually.deep.equal(response); }); - it('should return a promise that is resolved when activePeer.sendRequest() calls its callback with data.success == true', () => { + it('should return a promise that is resolved when liskAPIClient.sendRequest() calls its callback with data.success == true', () => { const response = { success: false, message: 'some error message', }; activePeerMock.expects('sendRequest').withArgs(path, urlParams).callsArgWith(2, response); - const requestPromise = requestToActivePeer(activePeer, path, urlParams); + const requestPromise = requestToActivePeer(liskAPIClient, path, urlParams); expect(requestPromise).to.be.rejectedWith(response); }); }); diff --git a/src/utils/api/search.js b/src/utils/api/search.js index ca3f9bfdeb..e12f43dd0e 100644 --- a/src/utils/api/search.js +++ b/src/utils/api/search.js @@ -15,13 +15,13 @@ const filterAndOrderByMatch = (searchTerm, delegates) => }); /* eslint-disable prefer-promise-reject-errors */ -const searchAddresses = ({ activePeer, searchTerm }) => new Promise((resolve, reject) => - getAccount(activePeer, searchTerm) +const searchAddresses = ({ liskAPIClient, searchTerm }) => new Promise((resolve, reject) => + getAccount(liskAPIClient, searchTerm) .then(response => resolve({ addresses: [response] })) .catch(() => reject({ addresses: [] }))); -const searchDelegates = ({ activePeer, searchTerm }) => new Promise(resolve => - listDelegates(activePeer, { +const searchDelegates = ({ liskAPIClient, searchTerm }) => new Promise(resolve => + listDelegates(liskAPIClient, { search: searchTerm, sort: 'username:asc', }).then((response) => { @@ -33,9 +33,9 @@ const searchDelegates = ({ activePeer, searchTerm }) => new Promise(resolve => }) .catch(() => resolve({ delegates: [] }))); -const searchTransactions = ({ activePeer, searchTerm }) => new Promise((resolve, reject) => +const searchTransactions = ({ liskAPIClient, searchTerm }) => new Promise((resolve, reject) => getSingleTransaction({ - activePeer, + liskAPIClient, id: searchTerm, }).then(response => resolve({ transactions: response.data })) .catch(() => reject({ transactions: [] }))); @@ -48,9 +48,9 @@ const getSearches = search => ([ searchDelegates, // allways add delegates promise as they share format (address, tx) ]); -const resolveAll = (activePeer, apiCalls, searchTerm) => { +const resolveAll = (liskAPIClient, apiCalls, searchTerm) => { const promises = apiCalls.map(apiCall => - apiCall({ activePeer, searchTerm }) + apiCall({ liskAPIClient, searchTerm }) .catch(err => err)); return new Promise((resolve, reject) => { @@ -61,9 +61,9 @@ const resolveAll = (activePeer, apiCalls, searchTerm) => { }; /* eslint-enable prefer-promise-reject-errors */ -const searchAll = ({ activePeer, searchTerm }) => { +const searchAll = ({ liskAPIClient, searchTerm }) => { const apiCalls = getSearches(searchTerm); - return resolveAll(activePeer, apiCalls, searchTerm); + return resolveAll(liskAPIClient, apiCalls, searchTerm); }; export default searchAll; diff --git a/src/utils/api/transactions.js b/src/utils/api/transactions.js index 1c594b9845..29a5ec05af 100644 --- a/src/utils/api/transactions.js +++ b/src/utils/api/transactions.js @@ -2,7 +2,7 @@ import Lisk from 'lisk-elements'; import txFilters from './../../constants/transactionFilters'; export const send = ( - activePeer, + liskAPIClient, recipientId, amount, passphrase, @@ -14,13 +14,13 @@ export const send = ( const transaction = Lisk.transaction.transfer({ recipientId, amount, passphrase, secondPassphrase, data, timeOffset, }); - activePeer.transactions.broadcast(transaction).then(() => { + liskAPIClient.transactions.broadcast(transaction).then(() => { resolve(transaction); }).catch(reject); }); export const getTransactions = ({ - activePeer, address, limit = 20, offset = 0, + liskAPIClient, address, limit = 20, offset = 0, sort = 'timestamp:desc', filter = txFilters.all, }) => { const params = { @@ -32,19 +32,19 @@ export const getTransactions = ({ if (filter === txFilters.incoming) params.recipientId = address; if (filter === txFilters.outgoing) params.senderId = address; if (filter === txFilters.all) params.senderIdOrRecipientId = address; - return activePeer.transactions.get(params); + return liskAPIClient.transactions.get(params); }; -export const getSingleTransaction = ({ activePeer, id }) => new Promise((resolve, reject) => { - if (!activePeer) { +export const getSingleTransaction = ({ liskAPIClient, id }) => new Promise((resolve, reject) => { + if (!liskAPIClient) { reject(); } else { - activePeer.transactions.get({ id }).then(response => resolve(response)); + liskAPIClient.transactions.get({ id }).then(response => resolve(response)); } }); -export const unconfirmedTransactions = (activePeer, address, limit = 20, offset = 0, sort = 'timestamp:desc') => - activePeer.node.getTransactions('unconfirmed', { +export const unconfirmedTransactions = (liskAPIClient, address, limit = 20, offset = 0, sort = 'timestamp:desc') => + liskAPIClient.node.getTransactions('unconfirmed', { senderId: address, limit, offset, diff --git a/src/utils/api/transactions.test.js b/src/utils/api/transactions.test.js index 051ecd4107..21a1c141a2 100644 --- a/src/utils/api/transactions.test.js +++ b/src/utils/api/transactions.test.js @@ -8,7 +8,7 @@ describe('Utils: Transactions API', () => { const id = '124701289470'; const amount = '100000'; const recipientId = '123L'; - const activePeer = { + const liskAPIClient = { transactions: { get: stub().returnsPromise(), broadcast: stub().returnsPromise().resolves({ recipientId, amount, id }), @@ -21,30 +21,30 @@ describe('Utils: Transactions API', () => { // TODO: fix these tests for assert more than just a promise is returned describe('send', () => { it('should broadcast a transaction and return a promise', () => { - const promise = send(activePeer, recipientId, amount, accounts.genesis.passphrase); - expect(activePeer.transactions.broadcast).to.have.been.calledWith(); + const promise = send(liskAPIClient, recipientId, amount, accounts.genesis.passphrase); + expect(liskAPIClient.transactions.broadcast).to.have.been.calledWith(); expect(typeof promise.then).to.be.equal('function'); }); }); describe('transactions', () => { it('should return a promise', () => { - const promise = getTransactions({ activePeer }); + const promise = getTransactions({ liskAPIClient }); expect(typeof promise.then).to.be.equal('function'); }); it('should call transactions.get for incoming promise', () => { - getTransactions({ activePeer, address: '123L', filter: txFilters.incoming }); + getTransactions({ liskAPIClient, address: '123L', filter: txFilters.incoming }); - expect(activePeer.transactions.get).to.have.been.calledWith({ + expect(liskAPIClient.transactions.get).to.have.been.calledWith({ limit: 20, offset: 0, recipientId: '123L', sort: 'timestamp:desc', }); }); it('should call transactions.get for outgoing promise', () => { - getTransactions({ activePeer, address: '123L', filter: txFilters.outgoing }); + getTransactions({ liskAPIClient, address: '123L', filter: txFilters.outgoing }); - expect(activePeer.transactions.get).to.have.been.calledWith({ + expect(liskAPIClient.transactions.get).to.have.been.calledWith({ limit: 20, offset: 0, senderId: '123L', sort: 'timestamp:desc', }); }); @@ -52,15 +52,15 @@ describe('Utils: Transactions API', () => { describe('unconfirmedTransactions', () => { it('should return a promise', () => { - const promise = unconfirmedTransactions(activePeer); + const promise = unconfirmedTransactions(liskAPIClient); expect(typeof promise.then).to.be.equal('function'); }); }); describe('getSingleTransaction', () => { - it('should activePeer.transactions.get and return a promise', () => { - const promise = getSingleTransaction({ activePeer, id }); - expect(activePeer.transactions.get).to.have.been.calledWith({ id }); + it('should liskAPIClient.transactions.get and return a promise', () => { + const promise = getSingleTransaction({ liskAPIClient, id }); + expect(liskAPIClient.transactions.get).to.have.been.calledWith({ id }); expect(typeof promise.then).to.be.equal('function'); }); }); diff --git a/src/utils/delegates.js b/src/utils/delegates.js index 45e0189597..6cab8ee10d 100644 --- a/src/utils/delegates.js +++ b/src/utils/delegates.js @@ -1,8 +1,8 @@ import localJSONStorage from './localJSONStorage'; -export const updateDelegateCache = (delegates, activePeer) => { - const network = activePeer.currentNode; +export const updateDelegateCache = (delegates, liskAPIClient) => { + const network = liskAPIClient.currentNode; const savedDelegates = localJSONStorage.get(`delegateCache-${network}`, {}); const formatedDelegates = delegates.reduce((delegate, { address, publicKey, username }) => { delegate[address] = { publicKey, username }; @@ -13,9 +13,9 @@ export const updateDelegateCache = (delegates, activePeer) => { localJSONStorage.set(`delegateCache-${network}`, updatedDelegates); }; -export const loadDelegateCache = (activePeer) => { +export const loadDelegateCache = (liskAPIClient) => { // TODO network just based on currentNode will not work well on Mainnet // because there are multiplercurrentNode options for Mainnet - const network = activePeer.currentNode; + const network = liskAPIClient.currentNode; return localJSONStorage.get(`delegateCache-${network}`, {}); }; diff --git a/src/utils/delegates.test.js b/src/utils/delegates.test.js index f744baab57..a3324993a1 100644 --- a/src/utils/delegates.test.js +++ b/src/utils/delegates.test.js @@ -19,8 +19,8 @@ describe('Delegates Utils', () => { }; it('sets and gets the item', () => { - const activePeer = { options: { address: 'item' } }; - updateDelegateCache(item, activePeer); - expect(loadDelegateCache(activePeer)).to.eql(itemExpected); + const liskAPIClient = { options: { address: 'item' } }; + updateDelegateCache(item, liskAPIClient); + expect(loadDelegateCache(liskAPIClient)).to.eql(itemExpected); }); }); diff --git a/test/integration/accountTransactions.test.js b/test/integration/accountTransactions.test.js index 55a5ab3073..84d66a34c3 100644 --- a/test/integration/accountTransactions.test.js +++ b/test/integration/accountTransactions.test.js @@ -148,28 +148,28 @@ describe('@integration: Account Transactions', () => { // transactionsFilterSet do pass filter getTransactionsStub.withArgs({ - activePeer: match.defined, + liskAPIClient: match.defined, address: match.defined, limit: 25, filter: txFilters.all, }).returnsPromise().resolves({ data: transactions, meta: { count: 40 } }); getTransactionsStub.withArgs({ - activePeer: match.defined, + liskAPIClient: match.defined, address: match.defined, limit: 25, filter: txFilters.outgoing, }).returnsPromise().resolves({ data: [...transactions].slice(0, 5), meta: { count: 5 } }); getTransactionsStub.withArgs({ - activePeer: match.defined, + liskAPIClient: match.defined, address: match.defined, limit: 25, filter: txFilters.incoming, }).returnsPromise().resolves({ data: [...transactions].slice(0, 15), meta: { count: 15 } }); getTransactionsStub.withArgs({ - activePeer: match.defined, + liskAPIClient: match.defined, address: match.defined, limit: 25, filter: txFilters.all, diff --git a/test/integration/wallet.test.js b/test/integration/wallet.test.js index f642f1af5f..506b248973 100644 --- a/test/integration/wallet.test.js +++ b/test/integration/wallet.test.js @@ -159,7 +159,7 @@ describe('@integration: Wallet', () => { // transactionsFilterSet do pass filter getTransactionsStub.withArgs({ - activePeer: match.defined, + liskAPIClient: match.defined, address: match.defined, limit: 25, filter: txFilters.all, @@ -167,7 +167,7 @@ describe('@integration: Wallet', () => { // loadTransactions does not pass filter getTransactionsStub.withArgs({ - activePeer: match.defined, + liskAPIClient: match.defined, address: match.defined, limit: 25, }).returnsPromise().resolves({ data: generateTransactions(25), meta: { count: 1000 } }); @@ -333,7 +333,7 @@ describe('@integration: Wallet', () => { // transactionsFilterSet do pass filter getTransactionsStub.withArgs({ - activePeer: match.defined, + liskAPIClient: match.defined, address: match.defined, limit: 25, filter: txFilters.all, @@ -341,14 +341,14 @@ describe('@integration: Wallet', () => { // loadTransactions does not pass filter getTransactionsStub.withArgs({ - activePeer: match.defined, + liskAPIClient: match.defined, address: match.defined, limit: 25, }).returnsPromise().resolves({ data: generateTransactions(25), meta: { count: 50 } }); // transactionsRequested does pass filter, offset getTransactionsStub.withArgs({ - activePeer: match.defined, + liskAPIClient: match.defined, address: match.defined, limit: 25, offset: match.defined, @@ -358,14 +358,14 @@ describe('@integration: Wallet', () => { // // NOTE: transactionsFilterSet does not use offset getTransactionsStub.withArgs({ - activePeer: match.defined, + liskAPIClient: match.defined, address: match.defined, limit: 25, filter: txFilters.outgoing, }).returnsPromise().resolves({ data: generateTransactions(25), meta: { count: 25 } }); getTransactionsStub.withArgs({ - activePeer: match.defined, + liskAPIClient: match.defined, address: match.defined, limit: 25, filter: txFilters.incoming, From 427ff6e498c3672c7fc2834612cfbdbaaf84c541 Mon Sep 17 00:00:00 2001 From: michaeltomasik Date: Thu, 15 Nov 2018 01:31:06 +0100 Subject: [PATCH 05/11] :recycle: Rename activePeerSet to liskAPIClientSet --- docs/REDUX_ACTIONS.md | 2 +- src/actions/peers.js | 4 +-- src/actions/peers.test.js | 36 +++++++++---------- src/components/account/index.test.js | 2 +- .../accountTransactions/index.test.js | 4 +-- src/components/header/header.test.js | 2 +- src/components/header/index.test.js | 2 +- src/components/ledger/ledgerLogin.js | 6 ++-- src/components/login/index.js | 4 +-- src/components/login/index.test.js | 4 +-- src/components/login/login.js | 4 +-- src/components/login/login.test.js | 6 ++-- src/components/mainMenu/index.test.js | 2 +- src/components/mainMenu/mainMenu.test.js | 2 +- src/components/register/index.js | 4 +-- src/components/register/register.js | 2 +- src/components/register/register.test.js | 8 ++--- .../registerDelegate/registerDelegate.test.js | 2 +- src/components/sendTo/sendTo.test.js | 6 ++-- src/components/setting/index.test.js | 2 +- src/components/setting/setting.test.js | 2 +- .../explorerTransactions/index.test.js | 4 +-- .../walletTransactions/index.test.js | 4 +-- src/constants/actions.js | 2 +- src/store/middlewares/account.js | 4 +-- src/store/middlewares/account.test.js | 4 +-- src/store/middlewares/followedAccounts.js | 2 +- .../middlewares/followedAccounts.test.js | 4 +-- src/store/middlewares/login.js | 4 +-- src/store/middlewares/peers.js | 4 +-- src/store/middlewares/peers.test.js | 8 ++--- src/store/reducers/peers.js | 2 +- src/store/reducers/peers.test.js | 4 +-- test/integration/accountTransactions.test.js | 4 +-- test/integration/dashboard.test.js | 4 +-- test/integration/login.test.js | 4 +-- test/integration/register.test.js | 4 +-- test/integration/transactionID.test.js | 4 +-- test/integration/voting.test.js | 4 +-- test/integration/wallet.test.js | 4 +-- 40 files changed, 90 insertions(+), 90 deletions(-) diff --git a/docs/REDUX_ACTIONS.md b/docs/REDUX_ACTIONS.md index 0a03dbe23a..6ce260b98d 100644 --- a/docs/REDUX_ACTIONS.md +++ b/docs/REDUX_ACTIONS.md @@ -42,7 +42,7 @@ When entering actions execution order: ![alt text](assets/login_screen.png "Login Screen") After clicking `Log in` it executes: -- [`activePeerSet`](https://github.com/LiskHQ/lisk-hub/blob/86ab1874d89519a37d817c326c37d594f29b94eb/src/components/login/index.js#L28) with passphrase
+- [`liskAPIClientSet`](https://github.com/LiskHQ/lisk-hub/blob/86ab1874d89519a37d817c326c37d594f29b94eb/src/components/login/index.js#L28) with passphrase
↪️ Login Middleware
     ⬇️ [`getAccount`](https://github.com/LiskHQ/lisk-hub/blob/ea41bf3a898b2955de2d39e3a2bdd79ad150842e/src/store/middlewares/login.js#L31)
     diff --git a/src/actions/peers.js b/src/actions/peers.js index 7acb731828..245110da8d 100644 --- a/src/actions/peers.js +++ b/src/actions/peers.js @@ -19,7 +19,7 @@ const peerSet = (data, config) => ({ options: config, loginType: data.loginType, }), - type: actionTypes.activePeerSet, + type: actionTypes.liskAPIClientSet, }); const login = (dispatch, getState, data, config) => { @@ -75,7 +75,7 @@ const login = (dispatch, getState, data, config) => { * @param {Object} data - Active peer data and the passphrase of account * @returns {Object} Action object */ -export const activePeerSet = data => +export const liskAPIClientSet = data => (dispatch, getState) => { const config = data.network || {}; diff --git a/src/actions/peers.test.js b/src/actions/peers.test.js index 1777cc43fa..a9730897fa 100644 --- a/src/actions/peers.test.js +++ b/src/actions/peers.test.js @@ -2,7 +2,7 @@ import { expect } from 'chai'; import Lisk from 'lisk-elements'; import { spy, stub, match } from 'sinon'; import actionTypes from '../constants/actions'; -import { activePeerSet, activePeerUpdate } from './peers'; +import { liskAPIClientSet, activePeerUpdate } from './peers'; import accounts from '../../test/constants/accounts'; import networks from '../constants/networks'; @@ -26,7 +26,7 @@ describe('actions: peers', () => { }); }); - describe('activePeerSet', () => { + describe('liskAPIClientSet', () => { let dispatch; let APIClientBackup; let getConstantsMock; @@ -72,22 +72,22 @@ describe('actions: peers', () => { nethash, }, }; - activePeerSet(data)(dispatch, getState); + liskAPIClientSet(data)(dispatch, getState); expect(dispatch).to.have.been.calledWith(match.hasNested('data.options.address', 'localhost:8000')); }); - it('dispatch activePeerSet action also when address http missing', () => { + it('dispatch liskAPIClientSet action also when address http missing', () => { const network = { address: 'localhost:8000' }; - activePeerSet({ passphrase, network })(dispatch, getState); + liskAPIClientSet({ passphrase, network })(dispatch, getState); expect(dispatch).to.have.been.calledWith(match.hasNested('data.options.address', 'localhost:8000')); }); - it('dispatch activePeerSet action with nodeXX.lisk.io node if mainnet', () => { + it('dispatch liskAPIClientSet action with nodeXX.lisk.io node if mainnet', () => { const network = networks.mainnet; - activePeerSet({ passphrase, network })(dispatch, getState); + liskAPIClientSet({ passphrase, network })(dispatch, getState); expect(dispatch).to.have.been.calledWith(match.hasNested( 'data.options.nodes', @@ -95,22 +95,22 @@ describe('actions: peers', () => { )); }); - it('dispatch activePeerSet action with testnet nodes if testnet option is set', () => { + it('dispatch liskAPIClientSet action with testnet nodes if testnet option is set', () => { const network = { testnet: true, }; - activePeerSet({ passphrase, network })(dispatch, getState); + liskAPIClientSet({ passphrase, network })(dispatch, getState); expect(dispatch).to.have.been.calledWith(match.hasNested('data.options.nodes', networks.testnet.nodes)); }); - it('dispatch activePeerSet with custom node', () => { + it('dispatch liskAPIClientSet with custom node', () => { const network = { address: 'http://localhost:4000', custom: true, }; - activePeerSet({ passphrase, network })(dispatch, getState); + liskAPIClientSet({ passphrase, network })(dispatch, getState); expect(dispatch).to.have.been.calledWith(match.hasNested('data.options.nodes[0]', 'http://localhost:4000')); }); @@ -120,21 +120,21 @@ describe('actions: peers', () => { address: 'http://localhost:4000', custom: true, }; - activePeerSet({ passphrase, network })(dispatch, getState); + liskAPIClientSet({ passphrase, network })(dispatch, getState); expect(dispatch).to.have.been.calledWith({ data: { label: 'Unable to connect to the node, no response from the server.', type: 'error' }, type: actionTypes.toastDisplayed, }); }); - it('dispatch activePeerSet action even if network is undefined', () => { - activePeerSet({ passphrase, network: {} })(dispatch, getState); + it('dispatch liskAPIClientSet action even if network is undefined', () => { + liskAPIClientSet({ passphrase, network: {} })(dispatch, getState); expect(dispatch).to.have.been.calledWith(); }); - it('dispatch activePeerSet action even if network.address is undefined', () => { - activePeerSet({ passphrase, network: {} })(dispatch, getState); + it('dispatch liskAPIClientSet action even if network.address is undefined', () => { + liskAPIClientSet({ passphrase, network: {} })(dispatch, getState); expect(dispatch).to.have.been.calledWith(); }); @@ -143,11 +143,11 @@ describe('actions: peers', () => { const network7000 = { address: 'http://127.0.0.1:7000', nethash }; const network4000 = { address: 'http://127.0.0.1:4000', nethash }; - activePeerSet({ passphrase, network: network7000 })(dispatch, getState); + liskAPIClientSet({ passphrase, network: network7000 })(dispatch, getState); expect(dispatch).to.have.been.calledWith(match.hasNested('data.options.nodes[0]', network7000.address)); expect(dispatch).to.have.been.calledWith(match.hasNested('data.options.nethash', nethash)); - activePeerSet({ passphrase, network: network4000 })(dispatch, getState); + liskAPIClientSet({ passphrase, network: network4000 })(dispatch, getState); expect(dispatch).to.have.been.calledWith(match.hasNested('data.options.nodes[0]', network4000.address)); expect(dispatch).to.have.been.calledWith(match.hasNested('data.options.nethash', nethash)); }); diff --git a/src/components/account/index.test.js b/src/components/account/index.test.js index f046ab749f..46c218a42f 100644 --- a/src/components/account/index.test.js +++ b/src/components/account/index.test.js @@ -29,7 +29,7 @@ describe('Account HOC', () => { const store = configureMockStore([])({ peers, account, - activePeerSet: () => {}, + liskAPIClientSet: () => {}, }); const options = { context: { i18n, store }, diff --git a/src/components/accountTransactions/index.test.js b/src/components/accountTransactions/index.test.js index 028fc0fc04..b66a641ddd 100644 --- a/src/components/accountTransactions/index.test.js +++ b/src/components/accountTransactions/index.test.js @@ -14,7 +14,7 @@ import loadingReducer from '../../store/reducers/loading'; import filtersReducer from '../../store/reducers/filters'; import followedAccountsReducer from '../../store/reducers/followedAccounts'; -import { activePeerSet } from './../../../src/actions/peers'; +import { liskAPIClientSet } from './../../../src/actions/peers'; import networks from './../../../src/constants/networks'; import getNetwork from './../../../src/utils/getNetwork'; @@ -47,7 +47,7 @@ describe('AccountTransaction Component', () => { t: key => key, }; - store.dispatch(activePeerSet({ network: getNetwork(networks.testnet.code) })); + store.dispatch(liskAPIClientSet({ network: getNetwork(networks.testnet.code) })); wrapper = mount( diff --git a/src/components/header/header.test.js b/src/components/header/header.test.js index ea264442ff..4f04f8b296 100644 --- a/src/components/header/header.test.js +++ b/src/components/header/header.test.js @@ -16,7 +16,7 @@ describe('Header', () => { const storeObject = { peers: { liskAPIClient: {}, options: {} }, account: {}, - activePeerSet: () => {}, + liskAPIClientSet: () => {}, search: { suggestions: { delegates: [], diff --git a/src/components/header/index.test.js b/src/components/header/index.test.js index 711b06e6ca..cca3464100 100644 --- a/src/components/header/index.test.js +++ b/src/components/header/index.test.js @@ -18,7 +18,7 @@ describe('HeaderHOC', () => { const store = configureMockStore([])({ peers: { liskAPIClient: {}, options: {} }, account: {}, - activePeerSet: () => {}, + liskAPIClientSet: () => {}, settings: { autoLog: true, advancedMode: true, diff --git a/src/components/ledger/ledgerLogin.js b/src/components/ledger/ledgerLogin.js index 3d177e3818..86f6237245 100644 --- a/src/components/ledger/ledgerLogin.js +++ b/src/components/ledger/ledgerLogin.js @@ -3,7 +3,7 @@ import { connect } from 'react-redux'; import { translate } from 'react-i18next'; import { getLedgerAccountInfo } from '../../utils/api/ledger'; -import { activePeerSet } from '../../actions/peers'; +import { liskAPIClientSet } from '../../actions/peers'; import { settingsUpdated } from '../../actions/settings'; import { errorToastDisplayed } from '../../actions/toaster'; @@ -99,7 +99,7 @@ class LedgerLogin extends React.Component { selectAccount(ledgerAccount) { // set active peer - this.props.activePeerSet({ + this.props.liskAPIClientSet({ publicKey: ledgerAccount.publicKey, network: this.props.network, hwInfo: { // Use pubKey[0] first 10 char as device id @@ -197,7 +197,7 @@ const mapStateToProps = state => ({ }); const mapDispatchToProps = dispatch => ({ - activePeerSet: data => dispatch(activePeerSet(data)), + liskAPIClientSet: data => dispatch(liskAPIClientSet(data)), settingsUpdated: data => dispatch(settingsUpdated(data)), errorToastDisplayed: data => dispatch(errorToastDisplayed(data)), }); diff --git a/src/components/login/index.js b/src/components/login/index.js index 15818e5b0c..73ddb78acd 100644 --- a/src/components/login/index.js +++ b/src/components/login/index.js @@ -3,7 +3,7 @@ import { withRouter } from 'react-router'; import { setDefaults, translate } from 'react-i18next'; import { dialogDisplayed } from '../../actions/dialog'; import Login from './login'; -import { activePeerSet } from '../../actions/peers'; +import { liskAPIClientSet } from '../../actions/peers'; import { settingsUpdated } from '../../actions/settings'; import { errorToastDisplayed } from '../../actions/toaster'; import { loadingStarted, loadingFinished } from '../../actions/loading'; @@ -28,7 +28,7 @@ const mapStateToProps = state => ({ }); const mapDispatchToProps = dispatch => ({ - activePeerSet: data => dispatch(activePeerSet(data)), + liskAPIClientSet: data => dispatch(liskAPIClientSet(data)), setActiveDialog: data => dispatch(dialogDisplayed(data)), settingsUpdated: data => dispatch(settingsUpdated(data)), errorToastDisplayed: data => dispatch(errorToastDisplayed(data)), diff --git a/src/components/login/index.test.js b/src/components/login/index.test.js index f61a938d89..1b3f8b0c67 100644 --- a/src/components/login/index.test.js +++ b/src/components/login/index.test.js @@ -36,7 +36,7 @@ describe('LoginHOC', () => { const store = configureMockStore([])({ peers, account, - activePeerSet: () => {}, + liskAPIClientSet: () => {}, settings: { autoLog: true, advancedMode: true, @@ -66,7 +66,7 @@ options, const props = wrapper.find('Login').props(); expect(props.peers).to.be.equal(peers); expect(props.account).to.be.equal(account); - expect(typeof props.activePeerSet).to.be.equal('function'); + expect(typeof props.liskAPIClientSet).to.be.equal('function'); expect(typeof props.setActiveDialog).to.be.equal('function'); }); }); diff --git a/src/components/login/login.js b/src/components/login/login.js index 367d8003ff..65c8ba4e66 100644 --- a/src/components/login/login.js +++ b/src/components/login/login.js @@ -92,7 +92,7 @@ class Login extends React.Component { } // set active peer - this.props.activePeerSet({ + this.props.liskAPIClientSet({ publicKey: ledgerAccount.publicKey, loginType: 1, network, @@ -153,7 +153,7 @@ class Login extends React.Component { if (this.alreadyLoggedWithThisAddress(extractAddress(passphrase), network)) { this.redirectToReferrer(); } else { - this.props.activePeerSet({ + this.props.liskAPIClientSet({ passphrase, network, }); diff --git a/src/components/login/login.test.js b/src/components/login/login.test.js index 6b772fc703..875b97cf86 100644 --- a/src/components/login/login.test.js +++ b/src/components/login/login.test.js @@ -55,7 +55,7 @@ describe('Login', () => { t: data => data, onAccountUpdated: () => {}, setActiveDialog: spy(), - activePeerSet: spy(), + liskAPIClientSet: spy(), }; options = { context: { @@ -138,11 +138,11 @@ describe('Login', () => { }); describe('After submission', () => { - it('it should call activePeerSet if not already logged with given passphrase', () => { + it('it should call liskAPIClientSet if not already logged with given passphrase', () => { wrapper.find('Input.passphrase input').simulate('change', { target: { value: passphrase } }); wrapper.update(); wrapper.find('form').simulate('submit'); - expect(props.activePeerSet).to.have.been.calledWith(); + expect(props.liskAPIClientSet).to.have.been.calledWith(); }); // @integration diff --git a/src/components/mainMenu/index.test.js b/src/components/mainMenu/index.test.js index cf6d82b308..e146c6a7ab 100644 --- a/src/components/mainMenu/index.test.js +++ b/src/components/mainMenu/index.test.js @@ -30,7 +30,7 @@ describe('MainMenuHOC', () => { const store = configureMockStore([])({ peers, account, - activePeerSet: () => {}, + liskAPIClientSet: () => {}, settings: { autoLog: true, advancedMode: true, diff --git a/src/components/mainMenu/mainMenu.test.js b/src/components/mainMenu/mainMenu.test.js index 0637c68754..3f073c9b20 100644 --- a/src/components/mainMenu/mainMenu.test.js +++ b/src/components/mainMenu/mainMenu.test.js @@ -32,7 +32,7 @@ describe('MainMenu', () => { const store = configureMockStore([])({ peers, account, - activePeerSet: () => {}, + liskAPIClientSet: () => {}, settings: { autoLog: true, advancedMode: true, diff --git a/src/components/register/index.js b/src/components/register/index.js index 09e948103e..16e70f37ad 100644 --- a/src/components/register/index.js +++ b/src/components/register/index.js @@ -1,10 +1,10 @@ import { connect } from 'react-redux'; import { translate } from 'react-i18next'; -import { activePeerSet } from '../../actions/peers'; +import { liskAPIClientSet } from '../../actions/peers'; import Register from './register'; const mapDispatchToProps = dispatch => ({ - activePeerSet: data => dispatch(activePeerSet(data)), + liskAPIClientSet: data => dispatch(liskAPIClientSet(data)), }); const mapStateToProps = state => ({ diff --git a/src/components/register/register.js b/src/components/register/register.js index d6c163516c..d6281a4eba 100644 --- a/src/components/register/register.js +++ b/src/components/register/register.js @@ -32,7 +32,7 @@ class Register extends React.Component { const network = Object.assign({}, getNetwork(this.props.network)); // set active peer - this.props.activePeerSet({ + this.props.liskAPIClientSet({ passphrase, network, }); diff --git a/src/components/register/register.test.js b/src/components/register/register.test.js index 9cc744d925..69d3f9c331 100644 --- a/src/components/register/register.test.js +++ b/src/components/register/register.test.js @@ -21,7 +21,7 @@ describe('Register', () => { const store = configureMockStore([])({ peers, account, - activePeerSet: () => {}, + liskAPIClientSet: () => {}, }); const options = { context: { store, i18n }, @@ -34,7 +34,7 @@ describe('Register', () => { account, peers, network: networks.mainnet.code, - activePeerSet: spy(), + liskAPIClientSet: spy(), t: key => key, }; @@ -60,9 +60,9 @@ describe('Register', () => { expect(wrapper.find('Register').props().history.location.pathname).to.be.equal('/'); }); - it('should call activePeerSet with network and passphrase', () => { + it('should call liskAPIClientSet with network and passphrase', () => { wrapper.find('MultiStep').props().finalCallback(passphrase); - expect(prop.activePeerSet).to.have.been.calledWith(match({ + expect(prop.liskAPIClientSet).to.have.been.calledWith(match({ network: networks.mainnet, passphrase, })); diff --git a/src/components/registerDelegate/registerDelegate.test.js b/src/components/registerDelegate/registerDelegate.test.js index 334c7660ee..5e657cd4ad 100644 --- a/src/components/registerDelegate/registerDelegate.test.js +++ b/src/components/registerDelegate/registerDelegate.test.js @@ -32,7 +32,7 @@ describe('RegisterDelegate', () => { peers, account, delegate, - activePeerSet: () => {}, + liskAPIClientSet: () => {}, }); const props = { diff --git a/src/components/sendTo/sendTo.test.js b/src/components/sendTo/sendTo.test.js index ba605b1e63..af4c8b172b 100644 --- a/src/components/sendTo/sendTo.test.js +++ b/src/components/sendTo/sendTo.test.js @@ -29,7 +29,7 @@ describe('SendTo Component', () => { followedAccounts: { accounts: [] }, account, search: {}, - activePeerSet: () => {}, + liskAPIClientSet: () => {}, }); wrapper = mountWithContext(, { storeState: store }); @@ -61,7 +61,7 @@ describe('SendTo Component', () => { followedAccounts: { accounts: [] }, account, search: {}, - activePeerSet: () => {}, + liskAPIClientSet: () => {}, }); wrapper = mountWithContext(, { storeState: store }); @@ -82,7 +82,7 @@ describe('SendTo Component', () => { followedAccounts: { accounts: [account] }, account, search: {}, - activePeerSet: () => {}, + liskAPIClientSet: () => {}, }); wrapper = mountWithContext(, { storeState: store }); diff --git a/src/components/setting/index.test.js b/src/components/setting/index.test.js index f0464b8a86..8ce952201e 100644 --- a/src/components/setting/index.test.js +++ b/src/components/setting/index.test.js @@ -21,7 +21,7 @@ describe('SettingHOC', () => { }; const store = configureMockStore([])({ account, - activePeerSet: () => {}, + liskAPIClientSet: () => {}, settings: { autoLog: true, advancedMode: true, diff --git a/src/components/setting/setting.test.js b/src/components/setting/setting.test.js index a8cf8f55c4..82a2357b49 100644 --- a/src/components/setting/setting.test.js +++ b/src/components/setting/setting.test.js @@ -32,7 +32,7 @@ describe('Setting', () => { }; const store = configureMockStore([])({ account, - activePeerSet: () => {}, + liskAPIClientSet: () => {}, settings, }); diff --git a/src/components/transactions/explorerTransactions/index.test.js b/src/components/transactions/explorerTransactions/index.test.js index 77d1c613c0..2906dfd9c8 100644 --- a/src/components/transactions/explorerTransactions/index.test.js +++ b/src/components/transactions/explorerTransactions/index.test.js @@ -17,7 +17,7 @@ import transactionsReducer from '../../../store/reducers/transactions'; import searchReducer from '../../../store/reducers/search'; import loadingReducer from '../../../store/reducers/loading'; import filtersReducer from '../../../store/reducers/filters'; -import { activePeerSet } from '../../../../src/actions/peers'; +import { liskAPIClientSet } from '../../../../src/actions/peers'; import networks from './../../../../src/constants/networks'; import getNetwork from './../../../../src/utils/getNetwork'; @@ -86,7 +86,7 @@ describe('ExplorerTransactions Component', () => { filter: txFilters.all, }).returnsPromise().resolves({ data: [{ id: 'Some ID', type: txTypes.vote }], meta: { count: 1000 } }); - store.dispatch(activePeerSet({ network: getNetwork(networks.mainnet.code) })); + store.dispatch(liskAPIClientSet({ network: getNetwork(networks.mainnet.code) })); wrapper = mount( diff --git a/src/components/transactions/walletTransactions/index.test.js b/src/components/transactions/walletTransactions/index.test.js index a4727955a1..d453ef09b1 100644 --- a/src/components/transactions/walletTransactions/index.test.js +++ b/src/components/transactions/walletTransactions/index.test.js @@ -17,7 +17,7 @@ import loadingReducer from '../../../store/reducers/loading'; import filtersReducer from '../../../store/reducers/filters'; import { accountLoggedIn } from '../../../../src/actions/account'; -import { activePeerSet } from '../../../../src/actions/peers'; +import { liskAPIClientSet } from '../../../../src/actions/peers'; import networks from './../../../../src/constants/networks'; import getNetwork from './../../../../src/utils/getNetwork'; @@ -78,7 +78,7 @@ describe('WalletTransactions Component', () => { delegate: { ...accounts['delegate candidate'] }, })); - store.dispatch(activePeerSet({ network: getNetwork(networks.mainnet.code) })); + store.dispatch(liskAPIClientSet({ network: getNetwork(networks.mainnet.code) })); wrapper = mount( diff --git a/src/constants/actions.js b/src/constants/actions.js index 634557d710..3a896794c6 100644 --- a/src/constants/actions.js +++ b/src/constants/actions.js @@ -7,7 +7,7 @@ const actionTypes = { accountLoading: 'ACCOUNT_LOADING', accountAddVotes: 'ACCOUNT_ADD_VOTES', accountAddVoters: 'ACCOUNT_ADD_VOTERS', - activePeerSet: 'ACTIVE_PEER_SET', + liskAPIClientSet: 'ACTIVE_PEER_SET', activePeerUpdate: 'ACTIVE_PEER_UPDATE', activePeerReset: 'ACTIVE_PEER_RESET', dialogDisplayed: 'DIALOG_DISPLAYED', diff --git a/src/store/middlewares/account.js b/src/store/middlewares/account.js index ac1a3c016c..20fd4abc68 100644 --- a/src/store/middlewares/account.js +++ b/src/store/middlewares/account.js @@ -11,7 +11,7 @@ import transactionTypes from '../../constants/transactionTypes'; import { extractAddress, extractPublicKey } from '../../utils/account'; import { getAutoLogInData, shouldAutoLogIn } from '../../utils/login'; -import { activePeerSet, activePeerUpdate } from '../../actions/peers'; +import { liskAPIClientSet, activePeerUpdate } from '../../actions/peers'; import networks from '../../constants/networks'; import settings from '../../constants/settings'; import txFilters from '../../constants/transactionFilters'; @@ -122,7 +122,7 @@ const checkTransactionsAndUpdateAccount = (store, action) => { const autoLogInIfNecessary = (store) => { const autologinData = getAutoLogInData(); if (shouldAutoLogIn(autologinData)) { - store.dispatch(activePeerSet({ + store.dispatch(liskAPIClientSet({ passphrase: autologinData[settings.keys.loginKey], network: { ...networks.customNode, address: autologinData[settings.keys.liskCoreUrl] }, options: { diff --git a/src/store/middlewares/account.test.js b/src/store/middlewares/account.test.js index 5d4fed03e6..7e16feee09 100644 --- a/src/store/middlewares/account.test.js +++ b/src/store/middlewares/account.test.js @@ -85,7 +85,7 @@ describe('Account middleware', () => { stubTransactions = stub(transactionsApi, 'getTransactions').returnsPromise().resolves(true); getAutoLogInDataMock = stub(accountUtils, 'getAutoLogInData'); getAutoLogInDataMock.withArgs().returns({ }); - activePeerSetMock = stub(peersActions, 'activePeerSet').returns(activePeerMock); + activePeerSetMock = stub(peersActions, 'liskAPIClientSet').returns(activePeerMock); accountDataUpdatedSpy = spy(accountActions, 'accountDataUpdated'); }); @@ -207,7 +207,7 @@ describe('Account middleware', () => { accountUpdatedSpy.restore(); }); - it(`should dispatch ${actionTypes.activePeerSet} action on ${actionTypes.storeCreated} if autologin data found in localStorage`, () => { + it(`should dispatch ${actionTypes.liskAPIClientSet} action on ${actionTypes.storeCreated} if autologin data found in localStorage`, () => { getAutoLogInDataMock.withArgs().returns({ [settings.keys.loginKey]: passphrase, [settings.keys.liskCoreUrl]: networks.testnet.nodes[0], diff --git a/src/store/middlewares/followedAccounts.js b/src/store/middlewares/followedAccounts.js index 793f81aa97..3760b7e73f 100644 --- a/src/store/middlewares/followedAccounts.js +++ b/src/store/middlewares/followedAccounts.js @@ -48,7 +48,7 @@ const followedAccountsMiddleware = (store) => { account: action.data, })); break; - case actionTypes.activePeerSet: + case actionTypes.liskAPIClientSet: updateFollowedAccounts(followedAccounts.accounts); break; default: diff --git a/src/store/middlewares/followedAccounts.test.js b/src/store/middlewares/followedAccounts.test.js index 5ef00aaf91..6e69597a5f 100644 --- a/src/store/middlewares/followedAccounts.test.js +++ b/src/store/middlewares/followedAccounts.test.js @@ -55,9 +55,9 @@ describe('FollowedAccounts middleware', () => { }); - it(`should update the following accounts on ${actionTypes.activePeerSet} action`, () => { + it(`should update the following accounts on ${actionTypes.liskAPIClientSet} action`, () => { middleware(store)(next)({ - type: actionTypes.activePeerSet, + type: actionTypes.liskAPIClientSet, data: {}, }); diff --git a/src/store/middlewares/login.js b/src/store/middlewares/login.js index de68971773..7ec89e8a53 100644 --- a/src/store/middlewares/login.js +++ b/src/store/middlewares/login.js @@ -8,11 +8,11 @@ import { errorToastDisplayed } from '../../actions/toaster'; const { lockDuration } = accountConfig; const loginMiddleware = store => next => (action) => { - if (action.type !== actionTypes.activePeerSet || + if (action.type !== actionTypes.liskAPIClientSet || (!action.data.publicKey && !action.data.passphrase)) { return next(action); } - if (action.type === actionTypes.activePeerSet && action.data.loginType === 1) { + if (action.type === actionTypes.liskAPIClientSet && action.data.loginType === 1) { return next(action); } next(action); diff --git a/src/store/middlewares/peers.js b/src/store/middlewares/peers.js index b8bcb661fa..ccd5fba25c 100644 --- a/src/store/middlewares/peers.js +++ b/src/store/middlewares/peers.js @@ -1,4 +1,4 @@ -import { activePeerSet, activePeerUpdate } from '../../actions/peers'; +import { liskAPIClientSet, activePeerUpdate } from '../../actions/peers'; import actionTypes from '../../constants/actions'; import networks from './../../constants/networks'; import getNetwork from './../../utils/getNetwork'; @@ -29,7 +29,7 @@ const peersMiddleware = store => next => (action) => { // https://github.com/LiskHQ/lisk-hub/issues/1339 /* istanbul ignore else */ if (!shouldAutoLogIn(autologinData)) { - store.dispatch(activePeerSet({ network })); + store.dispatch(liskAPIClientSet({ network })); } store.dispatch(activePeerUpdate({ online: true })); break; diff --git a/src/store/middlewares/peers.test.js b/src/store/middlewares/peers.test.js index 8b1c4e6195..cd46e2d378 100644 --- a/src/store/middlewares/peers.test.js +++ b/src/store/middlewares/peers.test.js @@ -2,7 +2,7 @@ import { expect } from 'chai'; import { spy, stub } from 'sinon'; import middleware from './peers'; import actionTypes from '../../constants/actions'; -import { activePeerSet } from '../../actions/peers'; +import { liskAPIClientSet } from '../../actions/peers'; import * as loginUtils from './../../utils/login'; describe('Peer middleware', () => { @@ -69,7 +69,7 @@ describe('Peer middleware', () => { expect(store.dispatch).to.have.been.calledWith(); }); - it('should dispatch activePeerSet if there are no saved accounts', () => { + it('should dispatch liskAPIClientSet if there are no saved accounts', () => { const storeCreated = { type: actionTypes.storeCreated }; localStorageStub.returns(JSON.stringify([])); getAutoLogInDataStub.returns({ @@ -79,14 +79,14 @@ describe('Peer middleware', () => { expect(store.dispatch).to.have.been.calledWith(); }); - it('should not dispatch activePeerSet if there are saved accounts', () => { + it('should not dispatch liskAPIClientSet if there are saved accounts', () => { const storeCreated = { type: actionTypes.storeCreated }; localStorageStub.returns(JSON.stringify([{}, {}])); getAutoLogInDataStub.returns({ liskCoreUrl: 'https://testnet.lisk.io', }); middleware(store)(next)(storeCreated); - expect(store.dispatch).to.not.have.been.calledWith(activePeerSet()); + expect(store.dispatch).to.not.have.been.calledWith(liskAPIClientSet()); }); }); diff --git a/src/store/reducers/peers.js b/src/store/reducers/peers.js index eb2154099b..742ee7cf20 100644 --- a/src/store/reducers/peers.js +++ b/src/store/reducers/peers.js @@ -10,7 +10,7 @@ import actionTypes from '../../constants/actions'; */ const peers = (state = { status: {}, options: {} }, action) => { switch (action.type) { - case actionTypes.activePeerSet: + case actionTypes.liskAPIClientSet: return Object.assign({}, state, { liskAPIClient: action.data.liskAPIClient ? action.data.liskAPIClient : action.data, // options are duplicated here because lisk-js later on removes it from the 'data' object diff --git a/src/store/reducers/peers.test.js b/src/store/reducers/peers.test.js index 79e7949474..3edff562f8 100644 --- a/src/store/reducers/peers.test.js +++ b/src/store/reducers/peers.test.js @@ -4,10 +4,10 @@ import actionTypes from '../../constants/actions'; describe('Reducer: peers(state, action)', () => { - it('should return state object with data of active peer in state.data if action is activePeerSet', () => { + it('should return state object with data of active peer in state.data if action is liskAPIClientSet', () => { const state = {}; const action = { - type: actionTypes.activePeerSet, + type: actionTypes.liskAPIClientSet, data: { currentPeer: 'localhost', port: 4000, diff --git a/test/integration/accountTransactions.test.js b/test/integration/accountTransactions.test.js index 84d66a34c3..fc3add9c0a 100644 --- a/test/integration/accountTransactions.test.js +++ b/test/integration/accountTransactions.test.js @@ -18,7 +18,7 @@ import filtersReducer from '../../src/store/reducers/filters'; import followedAccountsReducer from '../../src/store/reducers/followedAccounts'; import accountMiddleware from '../../src/store/middlewares/account'; import votingMiddleware from '../../src/store/middlewares/voting'; -import { activePeerSet } from '../../src/actions/peers'; +import { liskAPIClientSet } from '../../src/actions/peers'; import networks from './../../src/constants/networks'; import txTypes from './../../src/constants/transactionTypes'; import getNetwork from './../../src/utils/getNetwork'; @@ -234,7 +234,7 @@ describe('@integration: Account Transactions', () => { accountAPIStub.withArgs(match.any) .returnsPromise().resolves({ ...account }); - store.dispatch(activePeerSet({ network: getNetwork(networks.mainnet.code) })); + store.dispatch(liskAPIClientSet({ network: getNetwork(networks.mainnet.code) })); if (accountType) { store.dispatch(accountLoggedIn(account)); } wrapper = mount(renderWithRouter( AccountTransactions, store, diff --git a/test/integration/dashboard.test.js b/test/integration/dashboard.test.js index 95de97ec3a..5d25162ee4 100644 --- a/test/integration/dashboard.test.js +++ b/test/integration/dashboard.test.js @@ -21,7 +21,7 @@ import accountMiddleware from '../../src/store/middlewares/account'; import followedAccountsMiddleware from '../../src/store/middlewares/followedAccounts'; import peerMiddleware from '../../src/store/middlewares/peers'; import { accountLoggedIn } from '../../src/actions/account'; -import { activePeerSet } from '../../src/actions/peers'; +import { liskAPIClientSet } from '../../src/actions/peers'; import networks from './../../src/constants/networks'; import txTypes from './../../src/constants/transactionTypes'; import routes from '../../src/constants/routes'; @@ -128,7 +128,7 @@ describe('@integration: Dashboard', () => { passphrase, }; accountAPIStub.withArgs(match.any).returnsPromise().resolves({ data: [...account] }); - store.dispatch(activePeerSet({ network: getNetwork(networks.mainnet.code) })); + store.dispatch(liskAPIClientSet({ network: getNetwork(networks.mainnet.code) })); delegateAPIStub.withArgs(match.any).returnsPromise() .resolves({ delegate: { ...accounts['delegate candidate'] } }); diff --git a/test/integration/login.test.js b/test/integration/login.test.js index 29dfec7d00..4f750cee5a 100644 --- a/test/integration/login.test.js +++ b/test/integration/login.test.js @@ -15,7 +15,7 @@ import peersReducer from '../../src/store/reducers/peers'; import settingsReducer from '../../src/store/reducers/settings'; import accountMiddleware from '../../src/store/middlewares/account'; import peerMiddleware from '../../src/store/middlewares/peers'; -import { activePeerSet } from '../../src/actions/peers'; +import { liskAPIClientSet } from '../../src/actions/peers'; import * as toasterActions from '../../src/actions/toaster'; import { settingsUpdated } from '../../src/actions/settings'; import Login from './../../src/components/login'; @@ -129,7 +129,7 @@ describe('@integration: Login', () => { const store = createStore(); stubApis(); store.dispatch(settingsUpdated({ showNetwork: true })); - wrapper = mount(renderWithRouter(Login, store, { location: { search: '' } }), { activePeerSet }); + wrapper = mount(renderWithRouter(Login, store, { location: { search: '' } }), { liskAPIClientSet }); helper = new Helper(wrapper, store); }; diff --git a/test/integration/register.test.js b/test/integration/register.test.js index 9e6f185887..30bd0977df 100644 --- a/test/integration/register.test.js +++ b/test/integration/register.test.js @@ -47,7 +47,7 @@ describe('@integration: Register', () => { const stubApis = () => { localStorageStub = stub(localStorage, 'getItem'); - activePeerSetSpy = spy(peersActions, 'activePeerSet'); + activePeerSetSpy = spy(peersActions, 'liskAPIClientSet'); accountAPIStub = stub(accountAPI, 'getAccount'); accountAPIStub.returnsPromise().resolves({ success: false, @@ -107,7 +107,7 @@ describe('@integration: Register', () => { window.addEventListener = (name, event) => { events[name] = event; }; - const wrapper = mount(renderWithRouter(Register, store, { location: { search: '' } }), { activePeerSet: peersActions.activePeerSet }); + const wrapper = mount(renderWithRouter(Register, store, { location: { search: '' } }), { liskAPIClientSet: peersActions.liskAPIClientSet }); helper = new Helper(wrapper, store); }; diff --git a/test/integration/transactionID.test.js b/test/integration/transactionID.test.js index 9e823a4e65..ce951ca1f9 100644 --- a/test/integration/transactionID.test.js +++ b/test/integration/transactionID.test.js @@ -13,7 +13,7 @@ import peersReducer from '../../src/store/reducers/peers'; import votingReducer from '../../src/store/reducers/voting'; import accountMiddleware from '../../src/store/middlewares/account'; import votingMiddleware from '../../src/store/middlewares/voting'; -import { activePeerSet } from '../../src/actions/peers'; +import { liskAPIClientSet } from '../../src/actions/peers'; import networks from './../../src/constants/networks'; import getNetwork from './../../src/utils/getNetwork'; import { accountLoggedIn } from '../../src/actions/account'; @@ -99,7 +99,7 @@ describe('@integration: Single Transaction', () => { }; accountAPIStub.withArgs(match.any).returnsPromise().resolves({ ...account }); - store.dispatch(activePeerSet({ network: getNetwork(networks.mainnet.code) })); + store.dispatch(liskAPIClientSet({ network: getNetwork(networks.mainnet.code) })); accountAPIStub.withArgs(match.any).returnsPromise().resolves({ ...account }); if (accountType) { store.dispatch(accountLoggedIn(account)); } wrapper = mount(renderWithRouter( diff --git a/test/integration/voting.test.js b/test/integration/voting.test.js index b767615dea..33c63c67f8 100644 --- a/test/integration/voting.test.js +++ b/test/integration/voting.test.js @@ -17,7 +17,7 @@ import Voting from '../../src/components/voting'; import peersReducer from '../../src/store/reducers/peers'; import accountMiddleware from '../../src/store/middlewares/account'; import peerMiddleware from '../../src/store/middlewares/peers'; -import { activePeerSet } from '../../src/actions/peers'; +import { liskAPIClientSet } from '../../src/actions/peers'; import networks from './../../src/constants/networks'; import getNetwork from './../../src/utils/getNetwork'; @@ -120,7 +120,7 @@ const loginProcess = (votes = []) => { ]); accountAPIStub.withArgs(match.any).returnsPromise().resolves({ data: [account] }); - store.dispatch(activePeerSet({ network: getNetwork(networks.mainnet.code) })); + store.dispatch(liskAPIClientSet({ network: getNetwork(networks.mainnet.code) })); accountAPIStub.withArgs(match.any).returnsPromise().resolves({ data: [account] }); store.dispatch(accountLoggedIn(account)); diff --git a/test/integration/wallet.test.js b/test/integration/wallet.test.js index 506b248973..5894a65992 100644 --- a/test/integration/wallet.test.js +++ b/test/integration/wallet.test.js @@ -21,7 +21,7 @@ import filtersReducer from '../../src/store/reducers/filters'; import accountMiddleware from '../../src/store/middlewares/account'; import peerMiddleware from '../../src/store/middlewares/peers'; import { accountLoggedIn } from '../../src/actions/account'; -import { activePeerSet } from '../../src/actions/peers'; +import { liskAPIClientSet } from '../../src/actions/peers'; import networks from './../../src/constants/networks'; import txTypes from './../../src/constants/transactionTypes'; import getNetwork from './../../src/utils/getNetwork'; @@ -115,7 +115,7 @@ describe('@integration: Wallet', () => { } accountAPIStub.withArgs(match.any).returnsPromise().resolves({ data: [...account] }); - store.dispatch(activePeerSet({ network: getNetwork(networks.mainnet.code) })); + store.dispatch(liskAPIClientSet({ network: getNetwork(networks.mainnet.code) })); delegateAPIStub.withArgs(match.any).returnsPromise() .resolves({ data: [{ ...accounts['delegate candidate'] }] }); From c31bf2c5f6067bf1aa729fd916c4e923e130c9e0 Mon Sep 17 00:00:00 2001 From: michaeltomasik Date: Thu, 15 Nov 2018 11:26:48 +0100 Subject: [PATCH 06/11] :recycle: Remove last activePeer variables --- src/utils/delegates.js | 18 +++++++++--------- src/utils/delegates.test.js | 12 ++++++------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/utils/delegates.js b/src/utils/delegates.js index d912ecc39c..3c9335591a 100644 --- a/src/utils/delegates.js +++ b/src/utils/delegates.js @@ -2,16 +2,16 @@ import localJSONStorage from './localJSONStorage'; import networks from '../constants/networks'; -const getNetworkKey = activePeer => ( +const getNetworkKey = liskAPIClient => ( `delegateCache-${ - activePeer.options.code === networks.customNode.code ? - activePeer.currentNode : - activePeer.options.code + liskAPIClient.options.code === networks.customNode.code ? + liskAPIClient.currentNode : + liskAPIClient.options.code }` ); -export const updateDelegateCache = (delegates, activePeer) => { - const savedDelegates = localJSONStorage.get(getNetworkKey(activePeer), {}); +export const updateDelegateCache = (delegates, liskAPIClient) => { + const savedDelegates = localJSONStorage.get(getNetworkKey(liskAPIClient), {}); const formatedDelegates = delegates .reduce((newDelegates, delegate) => { const delegateObj = { [delegate.username]: delegate }; @@ -19,8 +19,8 @@ export const updateDelegateCache = (delegates, activePeer) => { }, {}); const updatedDelegates = { ...formatedDelegates, ...savedDelegates }; - localJSONStorage.set(getNetworkKey(activePeer), updatedDelegates); + localJSONStorage.set(getNetworkKey(liskAPIClient), updatedDelegates); }; -export const loadDelegateCache = activePeer => - localJSONStorage.get(getNetworkKey(activePeer), {}); +export const loadDelegateCache = liskAPIClient => + localJSONStorage.get(getNetworkKey(liskAPIClient), {}); diff --git a/src/utils/delegates.test.js b/src/utils/delegates.test.js index fbb0a0bbea..5325b5396b 100644 --- a/src/utils/delegates.test.js +++ b/src/utils/delegates.test.js @@ -20,17 +20,17 @@ describe('Delegates Utils', () => { }; it('sets and gets the delegate item with mainnet', () => { - const activePeer = { options: networks.mainnet }; - updateDelegateCache(delegateItem, activePeer); - expect(loadDelegateCache(activePeer)).to.eql(itemExpected); + const liskAPIClient = { options: networks.mainnet }; + updateDelegateCache(delegateItem, liskAPIClient); + expect(loadDelegateCache(liskAPIClient)).to.eql(itemExpected); }); it('sets and gets the delegate item with customNode', () => { - const activePeer = { + const liskAPIClient = { options: networks.customNode, currentNode: 'http://localhost:4000', }; - updateDelegateCache(delegateItem, activePeer); - expect(loadDelegateCache(activePeer)).to.eql(itemExpected); + updateDelegateCache(delegateItem, liskAPIClient); + expect(loadDelegateCache(liskAPIClient)).to.eql(itemExpected); }); }); From d2207d4e8cab7776bf6fc3b3544afb8808866fac Mon Sep 17 00:00:00 2001 From: michaeltomasik Date: Thu, 15 Nov 2018 11:34:05 +0100 Subject: [PATCH 07/11] :recycle: Remove activePeer all references --- src/actions/account.js | 6 ++-- src/actions/account.test.js | 2 +- src/actions/peers.js | 4 +-- src/actions/peers.test.js | 8 ++--- src/constants/actions.js | 6 ++-- src/store/middlewares/account.js | 4 +-- src/store/middlewares/account.test.js | 12 +++---- src/store/middlewares/offline.js | 2 +- src/store/middlewares/offline.test.js | 14 ++++---- src/store/middlewares/peers.js | 4 +-- src/store/middlewares/socket.js | 6 ++-- src/store/middlewares/socket.test.js | 12 +++---- src/store/reducers/peers.js | 2 +- src/store/reducers/peers.test.js | 4 +-- src/utils/api/account.test.js | 14 ++++---- src/utils/api/delegate.test.js | 50 +++++++++++++-------------- src/utils/api/peers.test.js | 10 +++--- test/integration/register.test.js | 8 ++--- 18 files changed, 84 insertions(+), 84 deletions(-) diff --git a/src/actions/account.js b/src/actions/account.js index 5ccf2bc921..8f87e4d7b0 100644 --- a/src/actions/account.js +++ b/src/actions/account.js @@ -5,7 +5,7 @@ import { registerDelegate, getDelegate, getAllVotes, getVoters } from '../utils/ import { loadTransactionsFinish, transactionsUpdated } from './transactions'; import { delegateRegisteredFailure } from './delegate'; import { errorAlertDialogDisplayed } from './dialog'; -import { activePeerUpdate } from './peers'; +import { liskAPIClientUpdate } from './peers'; import { getTimeOffset } from '../utils/hacks'; import Fees from '../constants/fees'; import transactionTypes from '../constants/transactionTypes'; @@ -240,8 +240,8 @@ export const accountDataUpdated = ({ )); } dispatch(accountUpdated(result)); - dispatch(activePeerUpdate({ online: true })); + dispatch(liskAPIClientUpdate({ online: true })); }).catch((res) => { - dispatch(activePeerUpdate({ online: false, code: res.error.code })); + dispatch(liskAPIClientUpdate({ online: false, code: res.error.code })); }); }; diff --git a/src/actions/account.test.js b/src/actions/account.test.js index c4cd684a94..2a7b2d0df2 100644 --- a/src/actions/account.test.js +++ b/src/actions/account.test.js @@ -312,7 +312,7 @@ describe('actions: account', () => { const dispatch = spy(); beforeEach(() => { - peersActionsStub = spy(peersActions, 'activePeerUpdate'); + peersActionsStub = spy(peersActions, 'liskAPIClientUpdate'); getAccountStub = stub(accountApi, 'getAccount').returnsPromise(); transactionsActionsStub = spy(transactionsActions, 'transactionsUpdated'); getState = () => ({ diff --git a/src/actions/peers.js b/src/actions/peers.js index 245110da8d..cd637daa37 100644 --- a/src/actions/peers.js +++ b/src/actions/peers.js @@ -119,7 +119,7 @@ export const liskAPIClientSet = data => * @param {Object} data - Active peer data * @returns {Object} Action object */ -export const activePeerUpdate = data => ({ +export const liskAPIClientUpdate = data => ({ data, - type: actionTypes.activePeerUpdate, + type: actionTypes.liskAPIClientUpdate, }); diff --git a/src/actions/peers.test.js b/src/actions/peers.test.js index a9730897fa..a91588859d 100644 --- a/src/actions/peers.test.js +++ b/src/actions/peers.test.js @@ -2,7 +2,7 @@ import { expect } from 'chai'; import Lisk from 'lisk-elements'; import { spy, stub, match } from 'sinon'; import actionTypes from '../constants/actions'; -import { liskAPIClientSet, activePeerUpdate } from './peers'; +import { liskAPIClientSet, liskAPIClientUpdate } from './peers'; import accounts from '../../test/constants/accounts'; import networks from '../constants/networks'; @@ -12,7 +12,7 @@ describe('actions: peers', () => { const { passphrase } = accounts.genesis; const nethash = '198f2b61a8eb95fbeed58b8216780b68f697f26b849acf00c8c93bb9b24f783d'; - describe('activePeerUpdate', () => { + describe('liskAPIClientUpdate', () => { it('should create an action to update the active peer', () => { const data = { online: true, @@ -20,9 +20,9 @@ describe('actions: peers', () => { const expectedAction = { data, - type: actionTypes.activePeerUpdate, + type: actionTypes.liskAPIClientUpdate, }; - expect(activePeerUpdate(data)).to.be.deep.equal(expectedAction); + expect(liskAPIClientUpdate(data)).to.be.deep.equal(expectedAction); }); }); diff --git a/src/constants/actions.js b/src/constants/actions.js index 3a896794c6..5d8b50d889 100644 --- a/src/constants/actions.js +++ b/src/constants/actions.js @@ -7,9 +7,9 @@ const actionTypes = { accountLoading: 'ACCOUNT_LOADING', accountAddVotes: 'ACCOUNT_ADD_VOTES', accountAddVoters: 'ACCOUNT_ADD_VOTERS', - liskAPIClientSet: 'ACTIVE_PEER_SET', - activePeerUpdate: 'ACTIVE_PEER_UPDATE', - activePeerReset: 'ACTIVE_PEER_RESET', + liskAPIClientSet: 'LISK_API_CLIENT_SET', + liskAPIClientUpdate: 'LISK_API_CLIENT_UPDATE', + liskAPIClientReset: 'LISK_API_CLIENT_RESET', dialogDisplayed: 'DIALOG_DISPLAYED', dialogHidden: 'DIALOG_HIDDEN', VotePlaced: 'VOTE_PLACED', diff --git a/src/store/middlewares/account.js b/src/store/middlewares/account.js index 20fd4abc68..08ee7c1dad 100644 --- a/src/store/middlewares/account.js +++ b/src/store/middlewares/account.js @@ -11,7 +11,7 @@ import transactionTypes from '../../constants/transactionTypes'; import { extractAddress, extractPublicKey } from '../../utils/account'; import { getAutoLogInData, shouldAutoLogIn } from '../../utils/login'; -import { liskAPIClientSet, activePeerUpdate } from '../../actions/peers'; +import { liskAPIClientSet, liskAPIClientUpdate } from '../../actions/peers'; import networks from '../../constants/networks'; import settings from '../../constants/settings'; import txFilters from '../../constants/transactionFilters'; @@ -130,7 +130,7 @@ const autoLogInIfNecessary = (store) => { address: autologinData[settings.keys.liskCoreUrl], }, })); - store.dispatch(activePeerUpdate({ + store.dispatch(liskAPIClientUpdate({ online: true, })); } diff --git a/src/store/middlewares/account.test.js b/src/store/middlewares/account.test.js index 7e16feee09..e80782237c 100644 --- a/src/store/middlewares/account.test.js +++ b/src/store/middlewares/account.test.js @@ -24,9 +24,9 @@ describe('Account middleware', () => { let stubTransactions; let transactionsActionsStub; let getAutoLogInDataMock; - let activePeerSetMock; + let liskAPIClientSetMock; let accountDataUpdatedSpy; - const activePeerMock = 'DUMMY_ACTIVE_PEER'; + const liskAPIClientMock = 'DUMMY_LISK_API_CLIENT'; const storeCreatedAction = { type: actionTypes.storeCreated, }; @@ -85,7 +85,7 @@ describe('Account middleware', () => { stubTransactions = stub(transactionsApi, 'getTransactions').returnsPromise().resolves(true); getAutoLogInDataMock = stub(accountUtils, 'getAutoLogInData'); getAutoLogInDataMock.withArgs().returns({ }); - activePeerSetMock = stub(peersActions, 'liskAPIClientSet').returns(activePeerMock); + liskAPIClientSetMock = stub(peersActions, 'liskAPIClientSet').returns(liskAPIClientMock); accountDataUpdatedSpy = spy(accountActions, 'accountDataUpdated'); }); @@ -97,7 +97,7 @@ describe('Account middleware', () => { stubTransactions.restore(); clock.restore(); getAutoLogInDataMock.restore(); - activePeerSetMock.restore(); + liskAPIClientSetMock.restore(); accountDataUpdatedSpy.restore(); }); @@ -213,11 +213,11 @@ describe('Account middleware', () => { [settings.keys.liskCoreUrl]: networks.testnet.nodes[0], }); middleware(store)(next)(storeCreatedAction); - expect(store.dispatch).to.have.been.calledWith(activePeerMock); + expect(store.dispatch).to.have.been.calledWith(liskAPIClientMock); }); it(`should do nothing on ${actionTypes.storeCreated} if autologin data NOT found in localStorage`, () => { middleware(store)(next)(storeCreatedAction); - expect(store.dispatch).to.not.have.been.calledWith(activePeerMock); + expect(store.dispatch).to.not.have.been.calledWith(liskAPIClientMock); }); }); diff --git a/src/store/middlewares/offline.js b/src/store/middlewares/offline.js index d7bb31b994..1c3edca8a5 100644 --- a/src/store/middlewares/offline.js +++ b/src/store/middlewares/offline.js @@ -20,7 +20,7 @@ const getErrorMessage = (errorCode, address) => { const offlineMiddleware = store => next => (action) => { const state = store.getState(); switch (action.type) { - case actionsType.activePeerUpdate: + case actionsType.liskAPIClientUpdate: if (action.data.online === false && state.peers.status.online === true) { const address = `${state.peers.liskAPIClient.currentPeer}:${state.peers.liskAPIClient.port}`; const label = getErrorMessage(action.data.code, address); diff --git a/src/store/middlewares/offline.test.js b/src/store/middlewares/offline.test.js index 21d0dd74ec..0772213f81 100644 --- a/src/store/middlewares/offline.test.js +++ b/src/store/middlewares/offline.test.js @@ -19,7 +19,7 @@ describe('Offline middleware', () => { store.dispatch = spy(); next = spy(); action = { - type: actionType.activePeerUpdate, + type: actionType.liskAPIClientUpdate, data: {}, }; peers = { @@ -41,7 +41,7 @@ describe('Offline middleware', () => { expect(next).to.have.been.calledWith(randomAction); }); - it(`should dispatch errorToastDisplayed on ${actionType.activePeerUpdate} action if !action.data.online and state.peer.status.online and action.data.code`, () => { + it(`should dispatch errorToastDisplayed on ${actionType.liskAPIClientUpdate} action if !action.data.online and state.peer.status.online and action.data.code`, () => { peers.status.online = true; action.data = { online: false, @@ -54,7 +54,7 @@ describe('Offline middleware', () => { })); }); - it(`should dispatch errorToastDisplayed on ${actionType.activePeerUpdate} action if !action.data.online and state.peer.status.online and action.data.code = "EUNAVAILABLE"`, () => { + it(`should dispatch errorToastDisplayed on ${actionType.liskAPIClientUpdate} action if !action.data.online and state.peer.status.online and action.data.code = "EUNAVAILABLE"`, () => { peers.status.online = true; action.data = { online: false, @@ -67,7 +67,7 @@ describe('Offline middleware', () => { })); }); - it(`should dispatch errorToastDisplayed on ${actionType.activePeerUpdate} action if !action.data.online and state.peer.status.online and action.data.code = "EPARSE"`, () => { + it(`should dispatch errorToastDisplayed on ${actionType.liskAPIClientUpdate} action if !action.data.online and state.peer.status.online and action.data.code = "EPARSE"`, () => { peers.status.online = true; action.data = { online: false, @@ -81,7 +81,7 @@ describe('Offline middleware', () => { })); }); - it(`should dispatch successToastDisplayed on ${actionType.activePeerUpdate} action if action.data.online and !state.peer.status.online`, () => { + it(`should dispatch successToastDisplayed on ${actionType.liskAPIClientUpdate} action if action.data.online and !state.peer.status.online`, () => { peers.status.online = false; action.data.online = true; @@ -91,7 +91,7 @@ describe('Offline middleware', () => { })); }); - it(`should not call next() on ${actionType.activePeerUpdate} action if action.data.online === state.peer.status.online`, () => { + it(`should not call next() on ${actionType.liskAPIClientUpdate} action if action.data.online === state.peer.status.online`, () => { peers.status.online = false; action.data.online = false; @@ -99,7 +99,7 @@ describe('Offline middleware', () => { expect(next).not.to.have.been.calledWith(); }); - it(`should call next() on ${actionType.activePeerUpdate} action if action.data.online !== state.peer.status.online`, () => { + it(`should call next() on ${actionType.liskAPIClientUpdate} action if action.data.online !== state.peer.status.online`, () => { peers.status.online = true; action.data.online = false; diff --git a/src/store/middlewares/peers.js b/src/store/middlewares/peers.js index ccd5fba25c..387fc0065c 100644 --- a/src/store/middlewares/peers.js +++ b/src/store/middlewares/peers.js @@ -1,4 +1,4 @@ -import { liskAPIClientSet, activePeerUpdate } from '../../actions/peers'; +import { liskAPIClientSet, liskAPIClientUpdate } from '../../actions/peers'; import actionTypes from '../../constants/actions'; import networks from './../../constants/networks'; import getNetwork from './../../utils/getNetwork'; @@ -31,7 +31,7 @@ const peersMiddleware = store => next => (action) => { if (!shouldAutoLogIn(autologinData)) { store.dispatch(liskAPIClientSet({ network })); } - store.dispatch(activePeerUpdate({ online: true })); + store.dispatch(liskAPIClientUpdate({ online: true })); break; default: break; } diff --git a/src/store/middlewares/socket.js b/src/store/middlewares/socket.js index 4e0d759640..e9e93ad276 100644 --- a/src/store/middlewares/socket.js +++ b/src/store/middlewares/socket.js @@ -1,6 +1,6 @@ import io from 'socket.io-client'; import actionTypes from '../../constants/actions'; -import { activePeerUpdate } from '../../actions/peers'; +import { liskAPIClientUpdate } from '../../actions/peers'; let connection; let forcedClosing = false; @@ -30,11 +30,11 @@ const socketSetup = (store) => { }); connection.on('disconnect', () => { if (!forcedClosing) { - store.dispatch(activePeerUpdate({ online: false })); + store.dispatch(liskAPIClientUpdate({ online: false })); } }); connection.on('reconnect', () => { - store.dispatch(activePeerUpdate({ online: true })); + store.dispatch(liskAPIClientUpdate({ online: true })); }); }; diff --git a/src/store/middlewares/socket.test.js b/src/store/middlewares/socket.test.js index 562311eb41..bfac8ede9d 100644 --- a/src/store/middlewares/socket.test.js +++ b/src/store/middlewares/socket.test.js @@ -3,7 +3,7 @@ import { spy } from 'sinon'; import io from 'socket.io-client'; import middleware from './socket'; import actionTypes from '../../constants/actions'; -import { activePeerUpdate } from '../../actions/peers'; +import { liskAPIClientUpdate } from '../../actions/peers'; describe('Socket middleware', () => { let store; @@ -60,19 +60,19 @@ describe('Socket middleware', () => { expect(io.connect().close).to.not.have.been.calledWith(); middleware(store)(next)({ type: actionTypes.accountLoggedOut }); expect(io.connect().close).to.have.been.calledWith(); - expect(store.dispatch).to.not.have.been.calledWith(activePeerUpdate({ online: false })); + expect(store.dispatch).to.not.have.been.calledWith(liskAPIClientUpdate({ online: false })); }); // it depends on actionTypes.accountLoggedOut in test above that sets connection to null it('should not dispatch any action then there is no connection', () => { middleware(store)(next)({ type: actionTypes.accountLoggedOut }); expect(io.connect().close).to.not.have.been.calledWith(); - expect(store.dispatch).to.not.have.been.calledWith(activePeerUpdate({ online: false })); + expect(store.dispatch).to.not.have.been.calledWith(liskAPIClientUpdate({ online: false })); }); it('should dispatch online event on reconnect', () => { middleware(store)(next)({ type: actionTypes.accountLoggedIn }); socketCallbacks.reconnect(); - expect(store.dispatch).to.have.been.calledWith(activePeerUpdate({ online: true })); + expect(store.dispatch).to.have.been.calledWith(liskAPIClientUpdate({ online: true })); }); it(`should dispatch ${actionTypes.accountLoggedIn} with https protocol`, () => { @@ -81,13 +81,13 @@ describe('Socket middleware', () => { peers: { liskAPIClient: { options: { ssl: true, address: 'localhost:4000' } } }, }); middleware(store)(next)({ type: actionTypes.accountLoggedIn }); - expect(store.dispatch).to.not.have.been.calledWith(activePeerUpdate({ online: true })); + expect(store.dispatch).to.not.have.been.calledWith(liskAPIClientUpdate({ online: true })); }); it('should dispatch offline event on disconnect', () => { middleware(store)(next)({ type: actionTypes.accountLoggedIn }); socketCallbacks.disconnect(); - expect(store.dispatch).to.have.been.calledWith(activePeerUpdate({ online: false })); + expect(store.dispatch).to.have.been.calledWith(liskAPIClientUpdate({ online: false })); }); it('should passes the action to next middleware', () => { diff --git a/src/store/reducers/peers.js b/src/store/reducers/peers.js index 742ee7cf20..82b90ba045 100644 --- a/src/store/reducers/peers.js +++ b/src/store/reducers/peers.js @@ -16,7 +16,7 @@ const peers = (state = { status: {}, options: {} }, action) => { // options are duplicated here because lisk-js later on removes it from the 'data' object options: action.data.options, }); - case actionTypes.activePeerUpdate: + case actionTypes.liskAPIClientUpdate: return Object.assign({}, state, { status: action.data }); default: return state; diff --git a/src/store/reducers/peers.test.js b/src/store/reducers/peers.test.js index 3edff562f8..0310962695 100644 --- a/src/store/reducers/peers.test.js +++ b/src/store/reducers/peers.test.js @@ -22,10 +22,10 @@ describe('Reducer: peers(state, action)', () => { expect(changedState).to.deep.equal(newState); }); - it('should return state object with updated status of active peer if action is activePeerUpdate', () => { + it('should return state object with updated status of active peer if action is liskAPIClientUpdate', () => { const state = {}; const action = { - type: actionTypes.activePeerUpdate, + type: actionTypes.liskAPIClientUpdate, data: { online: true }, }; diff --git a/src/utils/api/account.test.js b/src/utils/api/account.test.js index bcd85be59e..3a63bab9a8 100644 --- a/src/utils/api/account.test.js +++ b/src/utils/api/account.test.js @@ -6,7 +6,7 @@ describe('Utils: Account API', () => { const address = '1449310910991872227L'; describe('getAccount', () => { - let activePeerMock; + let liskAPIClientMock; const liskAPIClient = { accounts: { get: () => {}, @@ -14,19 +14,19 @@ describe('Utils: Account API', () => { }; beforeEach(() => { - activePeerMock = mock(liskAPIClient.accounts); + liskAPIClientMock = mock(liskAPIClient.accounts); }); afterEach(() => { - activePeerMock.verify(); - activePeerMock.restore(); + liskAPIClientMock.verify(); + liskAPIClientMock.restore(); }); it('should return a promise that is resolved when liskAPIClient.getAccount() calls its callback with data.success == true', () => { const account = { address, balance: 0, publicKey: 'sample_key' }; const response = { data: [{ ...account }] }; - activePeerMock.expects('get').withArgs({ address }).returnsPromise().resolves(response); + liskAPIClientMock.expects('get').withArgs({ address }).returnsPromise().resolves(response); const requestPromise = getAccount(liskAPIClient, address); return expect(requestPromise).to.eventually.eql({ ...account, serverPublicKey: 'sample_key' }); }); @@ -34,7 +34,7 @@ describe('Utils: Account API', () => { it('should return a promise that is resolved even when liskAPIClient.getAccount() calls its callback with data.success == false and "Account not found"', () => { const account = { address, balance: 0 }; - activePeerMock.expects('get').withArgs({ address }).returnsPromise().resolves({ data: [] }); + liskAPIClientMock.expects('get').withArgs({ address }).returnsPromise().resolves({ data: [] }); const requestPromise = getAccount(liskAPIClient, address); return expect(requestPromise).to.eventually.eql(account); }); @@ -42,7 +42,7 @@ describe('Utils: Account API', () => { it('should otherwise return a promise that is rejected', () => { const response = { success: false }; - activePeerMock.expects('get').withArgs({ address }).returnsPromise().rejects(response); + liskAPIClientMock.expects('get').withArgs({ address }).returnsPromise().rejects(response); const requestPromise = getAccount(liskAPIClient, address); return expect(requestPromise).to.eventually.be.rejectedWith(response); }); diff --git a/src/utils/api/delegate.test.js b/src/utils/api/delegate.test.js index e749316827..8f528fd3a9 100644 --- a/src/utils/api/delegate.test.js +++ b/src/utils/api/delegate.test.js @@ -13,10 +13,10 @@ import { import accounts from '../../../test/constants/accounts'; describe('Utils: Delegate', () => { - let activePeerMockDelegates; - let activePeerMockVotes; - let activePeerMockVoters; - let activePeerMockTransations; + let liskAPIClientMockDelegates; + let liskAPIClientMockVotes; + let liskAPIClientMockVoters; + let liskAPIClientMockTransations; let liskTransactionsCastVotesStub; let liskTransactionsRegisterDelegateStub; const timeOffset = 0; @@ -39,23 +39,23 @@ describe('Utils: Delegate', () => { beforeEach(() => { liskTransactionsCastVotesStub = sinon.stub(Lisk.transaction, 'castVotes'); liskTransactionsRegisterDelegateStub = sinon.stub(Lisk.transaction, 'registerDelegate'); - activePeerMockDelegates = sinon.mock(liskAPIClient.delegates); - activePeerMockVotes = sinon.mock(liskAPIClient.votes); - activePeerMockVoters = sinon.mock(liskAPIClient.voters); - activePeerMockTransations = sinon.stub(liskAPIClient.transactions, 'broadcast').returnsPromise().resolves({ id: '1234' }); + liskAPIClientMockDelegates = sinon.mock(liskAPIClient.delegates); + liskAPIClientMockVotes = sinon.mock(liskAPIClient.votes); + liskAPIClientMockVoters = sinon.mock(liskAPIClient.voters); + liskAPIClientMockTransations = sinon.stub(liskAPIClient.transactions, 'broadcast').returnsPromise().resolves({ id: '1234' }); }); afterEach(() => { - activePeerMockDelegates.verify(); - activePeerMockDelegates.restore(); + liskAPIClientMockDelegates.verify(); + liskAPIClientMockDelegates.restore(); - activePeerMockVotes.verify(); - activePeerMockVotes.restore(); + liskAPIClientMockVotes.verify(); + liskAPIClientMockVotes.restore(); - activePeerMockVoters.verify(); - activePeerMockVoters.restore(); + liskAPIClientMockVoters.verify(); + liskAPIClientMockVoters.restore(); - activePeerMockTransations.restore(); + liskAPIClientMockTransations.restore(); liskTransactionsCastVotesStub.restore(); liskTransactionsRegisterDelegateStub.restore(); @@ -64,7 +64,7 @@ describe('Utils: Delegate', () => { describe('listAccountDelegates', () => { it('should get votes for an address with 101 limit', () => { const address = '123L'; - activePeerMockVotes.expects('get').withArgs({ address, limit: '101' }).once(); + liskAPIClientMockVotes.expects('get').withArgs({ address, limit: '101' }).once(); listAccountDelegates(liskAPIClient, address); }); }); @@ -73,7 +73,7 @@ describe('Utils: Delegate', () => { it('should return getDelegate(liskAPIClient, options) if options = {}', () => { const options = {}; const response = { data: [] }; - activePeerMockDelegates.expects('get').withArgs(options).returnsPromise().resolves(response); + liskAPIClientMockDelegates.expects('get').withArgs(options).returnsPromise().resolves(response); const returnedPromise = listDelegates(liskAPIClient, options); expect(returnedPromise).to.eventually.equal(response); @@ -82,7 +82,7 @@ describe('Utils: Delegate', () => { it('should return getDelegate(liskAPIClient, options) if options.q is set', () => { const options = { q: 'genesis_1' }; const response = { data: [] }; - activePeerMockDelegates.expects('get').withArgs(options).returnsPromise().resolves(response); + liskAPIClientMockDelegates.expects('get').withArgs(options).returnsPromise().resolves(response); const returnedPromise = listDelegates(liskAPIClient, options); return expect(returnedPromise).to.eventually.equal(response); @@ -93,7 +93,7 @@ describe('Utils: Delegate', () => { it('should return getDelegate(liskAPIClient, options)', () => { const options = { publicKey: `"${accounts.delegate.publicKey}"` }; const response = { data: [] }; - activePeerMockDelegates.expects('get').withArgs(options).returnsPromise().resolves(response); + liskAPIClientMockDelegates.expects('get').withArgs(options).returnsPromise().resolves(response); const returnedPromise = getDelegate(liskAPIClient, options); return expect(returnedPromise).to.eventually.equal(response); @@ -138,7 +138,7 @@ describe('Utils: Delegate', () => { const address = '123L'; const offset = 0; const limit = 100; - activePeerMockVotes.expects('get').withArgs({ address, offset, limit }).once(); + liskAPIClientMockVotes.expects('get').withArgs({ address, offset, limit }).once(); getVotes(liskAPIClient, { address, offset, limit }); }); }); @@ -146,9 +146,9 @@ describe('Utils: Delegate', () => { describe('getAllVotes', () => { it('should get all votes for an address with no parameters > 100', () => { const address = '123L'; - activePeerMockVotes.expects('get').withArgs({ address, offset: 0, limit: 100 }) + liskAPIClientMockVotes.expects('get').withArgs({ address, offset: 0, limit: 100 }) .returnsPromise().resolves({ data: { votes: [1, 2, 3], votesUsed: 101 } }); - activePeerMockVotes.expects('get').withArgs({ address, offset: 100, limit: 1 }) + liskAPIClientMockVotes.expects('get').withArgs({ address, offset: 100, limit: 1 }) .returnsPromise().resolves({ data: { votes: [4], votesUsed: 101 } }); const returnedPromise = getAllVotes(liskAPIClient, address); expect(returnedPromise).to.eventually.equal([1, 2, 3, 4]); @@ -156,7 +156,7 @@ describe('Utils: Delegate', () => { it('should get all votes for an address with no parameters < 100', () => { const address = '123L'; - activePeerMockVotes.expects('get').withArgs({ address, offset: 0, limit: 100 }) + liskAPIClientMockVotes.expects('get').withArgs({ address, offset: 0, limit: 100 }) .returnsPromise().resolves({ data: { votes: [1], votesUsed: 1 } }); const returnedPromise = getAllVotes(liskAPIClient, address); expect(returnedPromise).to.eventually.equal([1]); @@ -166,7 +166,7 @@ describe('Utils: Delegate', () => { describe('getVoters', () => { it('should return getVoters(liskAPIClient, { publicKey, offset: 0, limit: 100 })', () => { const publicKey = ''; - activePeerMockVoters.expects('get').withArgs({ publicKey, offset: 0, limit: 100 }) + liskAPIClientMockVoters.expects('get').withArgs({ publicKey, offset: 0, limit: 100 }) .returnsPromise().resolves('resolved promise'); const returnedPromise = getVoters(liskAPIClient, { publicKey, offset: 0, limit: 100 }); @@ -177,7 +177,7 @@ describe('Utils: Delegate', () => { describe('getVoters', () => { it('should return getVoters(liskAPIClient, { publicKey })', () => { const publicKey = ''; - activePeerMockVoters.expects('get').withArgs({ publicKey, offset: 0, limit: 100 }) + liskAPIClientMockVoters.expects('get').withArgs({ publicKey, offset: 0, limit: 100 }) .returnsPromise().resolves('resolved promise'); const returnedPromise = getVoters(liskAPIClient, { publicKey }); diff --git a/src/utils/api/peers.test.js b/src/utils/api/peers.test.js index 4a75f3fb74..4f5c070a86 100644 --- a/src/utils/api/peers.test.js +++ b/src/utils/api/peers.test.js @@ -5,7 +5,7 @@ import { requestToActivePeer } from './peers'; describe('Utils: Peers', () => { describe('requestToActivePeer', () => { - let activePeerMock; + let liskAPIClientMock; const path = '/test/'; const urlParams = {}; const liskAPIClient = { @@ -13,11 +13,11 @@ describe('Utils: Peers', () => { }; beforeEach(() => { - activePeerMock = mock(liskAPIClient); + liskAPIClientMock = mock(liskAPIClient); }); afterEach(() => { - activePeerMock.restore(); + liskAPIClientMock.restore(); }); it('should return a promise that is resolved when liskAPIClient.sendRequest() calls its callback with data.success == true', () => { @@ -25,7 +25,7 @@ describe('Utils: Peers', () => { success: true, data: [], }; - activePeerMock.expects('sendRequest').withArgs(path, urlParams).callsArgWith(2, response); + liskAPIClientMock.expects('sendRequest').withArgs(path, urlParams).callsArgWith(2, response); const requestPromise = requestToActivePeer(liskAPIClient, path, urlParams); expect(requestPromise).to.eventually.deep.equal(response); }); @@ -35,7 +35,7 @@ describe('Utils: Peers', () => { success: false, message: 'some error message', }; - activePeerMock.expects('sendRequest').withArgs(path, urlParams).callsArgWith(2, response); + liskAPIClientMock.expects('sendRequest').withArgs(path, urlParams).callsArgWith(2, response); const requestPromise = requestToActivePeer(liskAPIClient, path, urlParams); expect(requestPromise).to.be.rejectedWith(response); }); diff --git a/test/integration/register.test.js b/test/integration/register.test.js index 30bd0977df..d26ea0bc9e 100644 --- a/test/integration/register.test.js +++ b/test/integration/register.test.js @@ -19,7 +19,7 @@ import { prepareStore, renderWithRouter } from '../utils/applicationInit'; describe('@integration: Register', () => { let helper; let localStorageStub; - let activePeerSetSpy; + let liskAPIClientSetSpy; let clock; let passphrase; let accountAPIStub; @@ -39,7 +39,7 @@ describe('@integration: Register', () => { const restoreStubs = () => { localStorageStub.restore(); - activePeerSetSpy.restore(); + liskAPIClientSetSpy.restore(); accountAPIStub.restore(); delegateAPIStub.restore(); clock.restore(); @@ -47,7 +47,7 @@ describe('@integration: Register', () => { const stubApis = () => { localStorageStub = stub(localStorage, 'getItem'); - activePeerSetSpy = spy(peersActions, 'liskAPIClientSet'); + liskAPIClientSetSpy = spy(peersActions, 'liskAPIClientSet'); accountAPIStub = stub(accountAPI, 'getAccount'); accountAPIStub.returnsPromise().resolves({ success: false, @@ -73,7 +73,7 @@ describe('@integration: Register', () => { // eslint-disable-next-line class-methods-use-this checkIfRegistrationConfirmed() { - expect(activePeerSetSpy).to.have.been.calledWith(match({ + expect(liskAPIClientSetSpy).to.have.been.calledWith(match({ passphrase, })); restoreStubs(); From 9283e46decfea4711966a84c715aa72536c2fba5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Stanislav?= Date: Thu, 15 Nov 2018 15:49:17 +0100 Subject: [PATCH 08/11] Update docs/REDUX_ACTIONS.md Co-Authored-By: michaeltomasik --- docs/REDUX_ACTIONS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/REDUX_ACTIONS.md b/docs/REDUX_ACTIONS.md index 6ce260b98d..e0e0c397fe 100644 --- a/docs/REDUX_ACTIONS.md +++ b/docs/REDUX_ACTIONS.md @@ -42,7 +42,7 @@ When entering actions execution order: ![alt text](assets/login_screen.png "Login Screen") After clicking `Log in` it executes: -- [`liskAPIClientSet`](https://github.com/LiskHQ/lisk-hub/blob/86ab1874d89519a37d817c326c37d594f29b94eb/src/components/login/index.js#L28) with passphrase
+- [`liskAPIClientSet`](https://github.com/LiskHQ/lisk-hub/blob/d2207d4e8cab7776bf6fc3b3544afb8808866fac/src/components/login/index.js#L27) with passphrase
↪️ Login Middleware
     ⬇️ [`getAccount`](https://github.com/LiskHQ/lisk-hub/blob/ea41bf3a898b2955de2d39e3a2bdd79ad150842e/src/store/middlewares/login.js#L31)
     From c1636d8de98b20a8aec43413911b305329730995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Stanislav?= Date: Thu, 15 Nov 2018 15:49:30 +0100 Subject: [PATCH 09/11] Update docs/REDUX_ACTIONS.md Co-Authored-By: michaeltomasik --- docs/REDUX_ACTIONS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/REDUX_ACTIONS.md b/docs/REDUX_ACTIONS.md index e0e0c397fe..8205ee7360 100644 --- a/docs/REDUX_ACTIONS.md +++ b/docs/REDUX_ACTIONS.md @@ -68,7 +68,7 @@ After clicking `Logout` it executes: After clicking `Send` it executes: -- Calls [`liskAPIClient.transactions.broadcast(transaction)`](https://github.com/LiskHQ/lisk-hub/blob/e71527bd273af2f16d6980fe3b0c1a379694c45b/src/utils/api/transactions.js#L17) and then dispatches [`TRANSACTION_ADDED`](https://github.com/LiskHQ/lisk-hub/blob/2811c2be14fe5ab4ead3e4a375b20b67348fc191/src/store/reducers/transactions.js#L10) +- Calls [`liskAPIClient.transactions.broadcast(transaction)`](https://github.com/LiskHQ/lisk-hub/blob/e71527bd273af2f16d6980fe3b0c1a379694c45b/src/utils/api/transactions.js#L17) and then dispatches [`TRANSACTION_ADDED`](https://github.com/LiskHQ/lisk-hub/blob/d2207d4e8cab7776bf6fc3b3544afb8808866fac/src/store/reducers/transactions.js#L10) ### Delegates voting From 7448db59a10a5a8cdf1f103454c6bc26dbfcb066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Stanislav?= Date: Thu, 15 Nov 2018 15:49:37 +0100 Subject: [PATCH 10/11] Update docs/REDUX_ACTIONS.md Co-Authored-By: michaeltomasik --- docs/REDUX_ACTIONS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/REDUX_ACTIONS.md b/docs/REDUX_ACTIONS.md index 8205ee7360..e8cb9a8bc7 100644 --- a/docs/REDUX_ACTIONS.md +++ b/docs/REDUX_ACTIONS.md @@ -87,7 +87,7 @@ On delegate select/uselect it executes: After going thru whole process and clicking `Confirm` it executes: -- Calls [`liskAPIClient.transactions.broadcast(transaction)`](https://github.com/LiskHQ/lisk-hub/blob/e71527bd273af2f16d6980fe3b0c1a379694c45b/src/utils/api/transactions.js#L17) and then dispatches [`TRANSACTION_ADDED`](https://github.com/LiskHQ/lisk-hub/blob/2811c2be14fe5ab4ead3e4a375b20b67348fc191/src/store/reducers/transactions.js#L10) +- Calls [`liskAPIClient.transactions.broadcast(transaction)`](https://github.com/LiskHQ/lisk-hub/blob/e71527bd273af2f16d6980fe3b0c1a379694c45b/src/utils/api/transactions.js#L17) and then dispatches [`TRANSACTION_ADDED`](https://github.com/LiskHQ/lisk-hub/blob/d2207d4e8cab7776bf6fc3b3544afb8808866fac/src/store/reducers/transactions.js#L10) ## Socket From f5599795b1939694899c5e3ef9e4fa5c96525647 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Stanislav?= Date: Thu, 15 Nov 2018 15:49:52 +0100 Subject: [PATCH 11/11] Update docs/REDUX_ACTIONS.md Co-Authored-By: michaeltomasik --- docs/REDUX_ACTIONS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/REDUX_ACTIONS.md b/docs/REDUX_ACTIONS.md index e8cb9a8bc7..62b66dc66e 100644 --- a/docs/REDUX_ACTIONS.md +++ b/docs/REDUX_ACTIONS.md @@ -76,7 +76,7 @@ After clicking `Send` it executes: After clicking `Confirm` it executes: -- Calls [`liskAPIClient.transactions.broadcast(transaction)`](https://github.com/LiskHQ/lisk-hub/blob/e71527bd273af2f16d6980fe3b0c1a379694c45b/src/utils/api/delegate.js#L34) and then dispatches [`TRANSACTION_ADDED`](https://github.com/LiskHQ/lisk-hub/blob/2811c2be14fe5ab4ead3e4a375b20b67348fc191/src/store/reducers/transactions.js#L10) +- Calls [`liskAPIClient.transactions.broadcast(transaction)`](https://github.com/LiskHQ/lisk-hub/blob/e71527bd273af2f16d6980fe3b0c1a379694c45b/src/utils/api/delegate.js#L34) and then dispatches [`TRANSACTION_ADDED`](https://github.com/LiskHQ/lisk-hub/blob/d2207d4e8cab7776bf6fc3b3544afb8808866fac/src/utils/api/delegate.js#L36) On delegate select/uselect it executes: - On Select -- [`voteToggled`](https://github.com/LiskHQ/lisk-hub/blob/d27796d57eb9246fae5876f02b242e6bb8343775/src/store/reducers/voting.js#L76) it adds to `voting.votes` redux new voted delegate object