Skip to content

Commit

Permalink
Merge pull request #1492 from LiskHQ/1404-rename-activePeer
Browse files Browse the repository at this point in the history
Rename active peer - Closes #1404
  • Loading branch information
michaeltomasik authored Nov 15, 2018
2 parents 3280832 + f559979 commit f352148
Show file tree
Hide file tree
Showing 84 changed files with 446 additions and 439 deletions.
8 changes: 4 additions & 4 deletions docs/REDUX_ACTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<br/>
- [`liskAPIClientSet`](https://github.com/LiskHQ/lisk-hub/blob/d2207d4e8cab7776bf6fc3b3544afb8808866fac/src/components/login/index.js#L27) with passphrase<br/>
↪️ Login Middleware<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;⬇️ [`getAccount`](https://github.com/LiskHQ/lisk-hub/blob/ea41bf3a898b2955de2d39e3a2bdd79ad150842e/src/store/middlewares/login.js#L31)<br/>
&nbsp;&nbsp;&nbsp;&nbsp;
Expand All @@ -68,15 +68,15 @@ 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
![alt text](assets/voting_confirm_screen.png "Voting Screen")


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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion i18n/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
38 changes: 19 additions & 19 deletions src/actions/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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: {
Expand All @@ -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(
{},
Expand All @@ -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({
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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(
{
Expand All @@ -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 }));
});
};
16 changes: 8 additions & 8 deletions src/actions/account.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -137,7 +137,7 @@ describe('actions: account', () => {
delegateApiMock = stub(delegateApi, 'registerDelegate');
dispatch = spy();
getState = () => ({
peers: { data: {} },
peers: { liskAPIClient: {} },
blocks: { latestBlocks: [] },
});
});
Expand Down Expand Up @@ -198,7 +198,7 @@ describe('actions: account', () => {
delegateApiMock = stub(delegateApi, 'getDelegate');
dispatch = spy();
getState = () => ({
peers: { data: {} },
peers: { liskAPIClient: {} },
});
});

Expand Down Expand Up @@ -247,7 +247,7 @@ describe('actions: account', () => {
getAccountStub = stub(accountApi, 'getAccount').returnsPromise();
transactionsActionsStub = spy(transactionsActions, 'loadTransactionsFinish');
getState = () => ({
peers: { data: {} },
peers: { liskAPIClient: {} },
});
});

Expand Down Expand Up @@ -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: {} },
});
});

Expand Down Expand Up @@ -373,7 +373,7 @@ describe('actions: account', () => {
beforeEach(() => {
transactionsActionsStub = spy(transactionsActions, 'transactionsUpdated');
getState = () => ({
peers: { data: {} },
peers: { liskAPIClient: {} },
});
});

Expand Down Expand Up @@ -409,7 +409,7 @@ describe('actions: account', () => {
beforeEach(() => {
stub(delegateApi, 'getDelegate').returnsPromise();
getState = () => ({
peers: { data: {} },
peers: { liskAPIClient: {} },
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/actions/delegate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
Expand Down
2 changes: 1 addition & 1 deletion src/actions/delegate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('actions: delegate', () => {
getDelegateStub = sinon.stub(delegateApi, 'getDelegate');
dispatch = sinon.spy();
getState = () => ({
peers: { data: {} },
peers: { liskAPIClient: {} },
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/actions/followedAccounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/actions/followedAccounts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
14 changes: 7 additions & 7 deletions src/actions/peers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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 = {
Expand All @@ -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 = {
Expand Down Expand Up @@ -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 || {};

Expand Down Expand Up @@ -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,
});
Loading

0 comments on commit f352148

Please sign in to comment.