diff --git a/docs/REDUX_ACTIONS.md b/docs/REDUX_ACTIONS.md index c786f40631..62b66dc66e 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/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)
     @@ -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/d2207d4e8cab7776bf6fc3b3544afb8808866fac/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/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 @@ -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/d2207d4e8cab7776bf6fc3b3544afb8808866fac/src/store/reducers/transactions.js#L10) ## Socket 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..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'; @@ -69,8 +69,8 @@ export const passphraseUsed = data => ({ */ export const accountVotesFetched = ({ address }) => (dispatch, getState) => { - const activePeer = getState().peers.data; - 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.data; - 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.data; + 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.data; - 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.data; - 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.data; - 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.data; - 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.data; - getAccount(activePeer, account.address).then((result) => { + const liskAPIClient = getState().peers.liskAPIClient; + getAccount(liskAPIClient, account.address).then((result) => { if (result.balance !== account.balance) { dispatch(updateTransactionsIfNeeded( { @@ -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 8a3f69d16e..2a7b2d0df2 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: {} }, }); }); @@ -312,11 +312,11 @@ 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 = () => ({ - 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.js b/src/actions/delegate.js index ce51ed79a9..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.data; + 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/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.js b/src/actions/followedAccounts.js index efba72b129..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.data; - 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/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.js b/src/actions/peers.js index 3b2d66f933..cd637daa37 100644 --- a/src/actions/peers.js +++ b/src/actions/peers.js @@ -15,11 +15,11 @@ 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, }), - type: actionTypes.activePeerSet, + type: actionTypes.liskAPIClientSet, }); const login = (dispatch, getState, data, config) => { @@ -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 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 = { @@ -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 || {}; @@ -119,7 +119,7 @@ export const activePeerSet = 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 25b9dad702..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 { activePeerSet, 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,13 +20,13 @@ 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); }); }); - describe('activePeerSet', () => { + describe('liskAPIClientSet', () => { let dispatch; let APIClientBackup; let getConstantsMock; @@ -38,7 +38,7 @@ describe('actions: peers', () => { getState = () => ({ peers: { - data: {}, + liskAPIClient: {}, }, account: {}, settings: { autoLog: true }, @@ -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/actions/search.js b/src/actions/search.js index 9bafccc8af..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.data; - 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.data; - 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.data; - 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.data; - 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.data; + 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.data; + 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.data; + 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.data; + 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 1fe79a88f8..f1b104c838 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: {}, }, }); @@ -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 98042917a8..46888699d4 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.data; + 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.data; - 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.data; + 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.data; + 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.data; + const liskAPIClient = getState().peers.liskAPIClient; dispatch({ type: actionTypes.transactionCleared }); - getSingleTransaction({ activePeer, id }) + getSingleTransaction({ liskAPIClient, id }) .then((response) => { let added = []; let deleted = []; @@ -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.data; + 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.data; + 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/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.js b/src/actions/voting.js index 2b59cb9416..1fb2009f46 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 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.data; - 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,14 +148,14 @@ export const delegatesFetched = ({ offset, refresh, q, }) => (dispatch, getState) => { - const activePeer = getState().peers.data; + const liskAPIClient = getState().peers.liskAPIClient; let params = { offset, limit: '100', sort: 'rank:asc', }; params = q ? { ...params, search: q } : params; - listDelegates(activePeer, params).then((response) => { + listDelegates(liskAPIClient, params).then((response) => { updateDelegateCache(response.data, getState().peers); dispatch(delegatesAdded({ list: response.data, @@ -173,11 +173,11 @@ export const urlVotesFound = ({ upvotes, unvotes, address, }) => (dispatch, getState) => { - const activePeer = getState().peers.data; + 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/actions/voting.test.js b/src/actions/voting.test.js index 8865bc3b53..6c35d45dfa 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,6 +229,11 @@ describe('actions: voting', () => { const dispatch = sinon.spy(); getState = () => ({ peers: { + liskAPIClient: { + options: { + name: networks.mainnet.name, + }, + }, options: { name: networks.mainnet.name, code: networks.mainnet.code, @@ -260,13 +265,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.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..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, }, @@ -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/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/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 908b6b34a5..0712065637 100644 --- a/src/components/header/header.test.js +++ b/src/components/header/header.test.js @@ -14,9 +14,9 @@ describe('Header', () => { let wrapper; const mountWithRouter = (node, options) => mount({node}, options); const storeObject = { - peers: { data: {}, options: {} }, + 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 6fa4feba28..cca3464100 100644 --- a/src/components/header/index.test.js +++ b/src/components/header/index.test.js @@ -16,9 +16,9 @@ import HeaderHOC from './index'; describe('HeaderHOC', () => { let wrapper; const store = configureMockStore([])({ - peers: { data: {}, options: {} }, + 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 0fadde45db..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'; @@ -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({ @@ -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 @@ -192,12 +192,12 @@ class LedgerLogin extends React.Component { } const mapStateToProps = state => ({ - activePeer: state.peers && state.peers.data, + liskAPIClient: state.peers && state.peers.liskAPIClient, settings: state.settings, }); 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/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/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/login/index.js b/src/components/login/index.js index 8e4121a141..ced58c3ddc 100644 --- a/src/components/login/index.js +++ b/src/components/login/index.js @@ -3,8 +3,8 @@ import { withRouter } from 'react-router'; import { setDefaults, translate } from 'react-i18next'; import { dialogDisplayed } from '../../actions/dialog'; import Login from './login'; +import { liskAPIClientSet } from '../../actions/peers'; import { errorToastDisplayed } from '../../actions/toaster'; -import { activePeerSet } from '../../actions/peers'; import { settingsUpdated } from '../../actions/settings'; import { loadingStarted, loadingFinished } from '../../actions/loading'; @@ -24,11 +24,11 @@ const mapStateToProps = state => ({ account: state.account, peers: state.peers, settings: state.settings, - activePeer: state.peers && state.peers.data, + liskAPIClient: state.peers && state.peers.liskAPIClient, }); 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 3983981db5..86c3734bfc 100644 --- a/src/components/login/login.js +++ b/src/components/login/login.js @@ -94,7 +94,7 @@ class Login extends React.Component { } // set active peer - this.props.activePeerSet({ + this.props.liskAPIClientSet({ publicKey: ledgerAccount.publicKey, loginType: 1, network, @@ -155,7 +155,7 @@ class Login extends React.Component { if (this.alreadyLoggedWithThisAddress(extractAddress(passphrase), network)) { this.redirectToReferrer(); } else { - this.props.activePeerSet({ + this.props.liskAPIClientSet({ passphrase, network, }); @@ -217,7 +217,7 @@ class Login extends React.Component { liskAPIClient.node.getConstants() .then((res) => { if (res.data) { - this.props.activePeerSet({ + this.props.liskAPIClientSet({ network: this.getNetwork(this.state.network), }); this.props.history.push(routes.register.path); @@ -229,7 +229,7 @@ class Login extends React.Component { }); } else { const network = this.getNetwork(this.state.network); - this.props.activePeerSet({ network }); + this.props.liskAPIClientSet({ network }); this.props.history.push(routes.register.path); } } diff --git a/src/components/login/login.test.js b/src/components/login/login.test.js index d19ffa73d0..7963206243 100644 --- a/src/components/login/login.test.js +++ b/src/components/login/login.test.js @@ -56,7 +56,7 @@ describe('Login', () => { t: data => data, onAccountUpdated: () => {}, setActiveDialog: spy(), - activePeerSet: spy(), + liskAPIClientSet: spy(), }; options = { context: { @@ -144,11 +144,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 64e1e2ae0a..68f846b5f8 100644 --- a/src/components/register/index.js +++ b/src/components/register/index.js @@ -1,11 +1,11 @@ import { connect } from 'react-redux'; import { translate } from 'react-i18next'; -import { activePeerSet } from '../../actions/peers'; +import { liskAPIClientSet } from '../../actions/peers'; import Register from './register'; import getNetwork from '../../utils/getNetwork'; 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 85ea7039bb..c49afbc8de 100644 --- a/src/components/register/register.js +++ b/src/components/register/register.js @@ -28,7 +28,8 @@ class Register extends React.Component { } onRegister(passphrase) { - this.props.activePeerSet({ + // set active peer + this.props.liskAPIClientSet({ passphrase, network: this.props.network, }); diff --git a/src/components/register/register.test.js b/src/components/register/register.test.js index 4360e0a3cf..4cdf2d9d35 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, - 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({ passphrase, network: networks.mainnet, })); 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/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/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/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/explorerTransactions/index.test.js b/src/components/transactions/explorerTransactions/index.test.js index 03de2244ff..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'; @@ -73,20 +73,20 @@ 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, }).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/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/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/transactions/walletTransactions/index.test.js b/src/components/transactions/walletTransactions/index.test.js index df434b04e6..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'; @@ -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, @@ -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/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/constants/actions.js b/src/constants/actions.js index 634557d710..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', - activePeerSet: '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 ac1a3c016c..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 { activePeerSet, 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'; @@ -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: { @@ -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 90cc7a6b96..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, }; @@ -61,7 +61,7 @@ describe('Account middleware', () => { store.dispatch = spy(); state = { peers: { - data: {}, + liskAPIClient: {}, }, account: { address: 'sample_address', @@ -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); + 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(); }); @@ -145,7 +145,7 @@ describe('Account middleware', () => { }], confirmed: [{ confirmations: 10, address: 'sample_address' }], }, - peers: { data: {} }, + peers: { liskAPIClient: {} }, }); middleware(store)(next)(newBlockCreated); @@ -207,17 +207,17 @@ 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], }); 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/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 bd8985ed42..7ec89e8a53 100644 --- a/src/store/middlewares/login.js +++ b/src/store/middlewares/login.js @@ -8,16 +8,16 @@ 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); - 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/offline.js b/src/store/middlewares/offline.js index 70883a307a..1c3edca8a5 100644 --- a/src/store/middlewares/offline.js +++ b/src/store/middlewares/offline.js @@ -20,9 +20,9 @@ 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.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..0772213f81 100644 --- a/src/store/middlewares/offline.test.js +++ b/src/store/middlewares/offline.test.js @@ -19,11 +19,11 @@ describe('Offline middleware', () => { store.dispatch = spy(); next = spy(); action = { - type: actionType.activePeerUpdate, + type: actionType.liskAPIClientUpdate, data: {}, }; peers = { - data: { + liskAPIClient: { port: 4000, currentPeer: 'localhost', }, @@ -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, @@ -63,11 +63,11 @@ 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}` }), })); }); - 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 eede43c35e..387fc0065c 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, liskAPIClientUpdate } from '../../actions/peers'; import actionTypes from '../../constants/actions'; import networks from './../../constants/networks'; import getNetwork from './../../utils/getNetwork'; @@ -24,14 +24,14 @@ 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 */ if (!shouldAutoLogIn(autologinData)) { - store.dispatch(activePeerSet({ network })); + store.dispatch(liskAPIClientSet({ network })); } - store.dispatch(activePeerUpdate({ online: true })); + store.dispatch(liskAPIClientUpdate({ online: true })); break; default: break; } diff --git a/src/store/middlewares/peers.test.js b/src/store/middlewares/peers.test.js index 33f70b7872..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', () => { @@ -21,7 +21,7 @@ describe('Peer middleware', () => { store.getState = () => ({ peers: { - data: {}, + liskAPIClient: {}, }, account: {}, }); @@ -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/middlewares/socket.js b/src/store/middlewares/socket.js index 781c27a9bb..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; @@ -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, @@ -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 56d126d63a..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; @@ -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(), @@ -60,34 +60,34 @@ 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`, () => { 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 })); + 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/middlewares/voting.js b/src/store/middlewares/voting.js index 271dfd9171..4212e934d2 100644 --- a/src/store/middlewares/voting.js +++ b/src/store/middlewares/voting.js @@ -11,7 +11,7 @@ const updateLookupStatus = (store, list, username) => { const lookupDelegate = (store, username) => { const state = store.getState(); - const activePeer = state.peers.data; + const liskAPIClient = state.peers.liskAPIClient; const localStorageDelegates = loadDelegateCache(state.peers); const delegate = localStorageDelegates[username] || state.voting.delegates.find(d => d.username === username); @@ -20,7 +20,7 @@ const lookupDelegate = (store, username) => { resolve({ data: [delegate] }); }); } - return getDelegate(activePeer, { username }); + return getDelegate(liskAPIClient, { username }); }; const processVote = (store, options, username) => { diff --git a/src/store/middlewares/voting.test.js b/src/store/middlewares/voting.test.js index ea69fa394e..2628cd48a3 100644 --- a/src/store/middlewares/voting.test.js +++ b/src/store/middlewares/voting.test.js @@ -76,7 +76,7 @@ describe('voting middleware', () => { }, }, peers: { - data: {}, + liskAPIClient: {}, options: { code: networks.mainnet.code, }, diff --git a/src/store/reducers/peers.js b/src/store/reducers/peers.js index 783fad3200..82b90ba045 100644 --- a/src/store/reducers/peers.js +++ b/src/store/reducers/peers.js @@ -10,13 +10,13 @@ import actionTypes from '../../constants/actions'; */ const peers = (state = { status: {}, options: {} }, action) => { switch (action.type) { - case actionTypes.activePeerSet: + case actionTypes.liskAPIClientSet: return Object.assign({}, state, { - data: 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, }); - 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 6036e97d4b..0310962695 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, @@ -17,15 +17,15 @@ 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); }); - 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.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..3a63bab9a8 100644 --- a/src/utils/api/account.test.js +++ b/src/utils/api/account.test.js @@ -6,44 +6,44 @@ describe('Utils: Account API', () => { const address = '1449310910991872227L'; describe('getAccount', () => { - let activePeerMock; - const activePeer = { + let liskAPIClientMock; + const liskAPIClient = { accounts: { get: () => {}, }, }; beforeEach(() => { - activePeerMock = mock(activePeer.accounts); + liskAPIClientMock = mock(liskAPIClient.accounts); }); afterEach(() => { - activePeerMock.verify(); - activePeerMock.restore(); + liskAPIClientMock.verify(); + liskAPIClientMock.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); + liskAPIClientMock.expects('get').withArgs({ address }).returnsPromise().resolves(response); + 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); + liskAPIClientMock.expects('get').withArgs({ address }).returnsPromise().resolves({ data: [] }); + const requestPromise = getAccount(liskAPIClient, address); return expect(requestPromise).to.eventually.eql(account); }); it('should otherwise return a promise that is rejected', () => { const response = { success: false }; - activePeerMock.expects('get').withArgs({ address }).returnsPromise().rejects(response); - const requestPromise = getAccount(activePeer, address); + 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.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..8f528fd3a9 100644 --- a/src/utils/api/delegate.test.js +++ b/src/utils/api/delegate.test.js @@ -13,15 +13,15 @@ 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; - const activePeer = { + const liskAPIClient = { delegates: { get: () => { }, }, @@ -39,23 +39,23 @@ 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' }); + 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,38 +64,38 @@ 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(); - listAccountDelegates(activePeer, address); + liskAPIClientMockVotes.expects('get').withArgs({ address, limit: '101' }).once(); + 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); + liskAPIClientMockDelegates.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); + liskAPIClientMockDelegates.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); + liskAPIClientMockDelegates.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); }); }); @@ -138,49 +138,49 @@ describe('Utils: Delegate', () => { const address = '123L'; const offset = 0; const limit = 100; - activePeerMockVotes.expects('get').withArgs({ address, offset, limit }).once(); - getVotes(activePeer, { address, offset, limit }); + liskAPIClientMockVotes.expects('get').withArgs({ address, offset, limit }).once(); + getVotes(liskAPIClient, { address, offset, limit }); }); }); 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(activePeer, address); + const returnedPromise = getAllVotes(liskAPIClient, address); expect(returnedPromise).to.eventually.equal([1, 2, 3, 4]); }); 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(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 }) + liskAPIClientMockVoters.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 }) + liskAPIClientMockVoters.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..4f5c070a86 100644 --- a/src/utils/api/peers.test.js +++ b/src/utils/api/peers.test.js @@ -5,38 +5,38 @@ import { requestToActivePeer } from './peers'; describe('Utils: Peers', () => { describe('requestToActivePeer', () => { - let activePeerMock; + let liskAPIClientMock; const path = '/test/'; const urlParams = {}; - const activePeer = { + const liskAPIClient = { sendRequest: () => { }, }; beforeEach(() => { - activePeerMock = mock(activePeer); + liskAPIClientMock = mock(liskAPIClient); }); afterEach(() => { - activePeerMock.restore(); + liskAPIClientMock.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); + liskAPIClientMock.expects('sendRequest').withArgs(path, urlParams).callsArgWith(2, response); + 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); + liskAPIClientMock.expects('sendRequest').withArgs(path, urlParams).callsArgWith(2, response); + 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 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); }); }); diff --git a/test/integration/accountTransactions.test.js b/test/integration/accountTransactions.test.js index 55a5ab3073..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'; @@ -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, @@ -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 551a32b5de..166252ed21 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'; @@ -134,7 +134,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..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, 'activePeerSet'); + 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(); @@ -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 919874c660..adf63c6a31 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'; @@ -121,7 +121,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'] }] }); @@ -165,7 +165,7 @@ describe('@integration: Wallet', () => { // transactionsFilterSet do pass filter getTransactionsStub.withArgs({ - activePeer: match.defined, + liskAPIClient: match.defined, address: match.defined, limit: 25, filter: txFilters.all, @@ -173,7 +173,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 } }); @@ -340,7 +340,7 @@ describe('@integration: Wallet', () => { // transactionsFilterSet do pass filter getTransactionsStub.withArgs({ - activePeer: match.defined, + liskAPIClient: match.defined, address: match.defined, limit: 25, filter: txFilters.all, @@ -348,14 +348,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, @@ -365,14 +365,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,