Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Commit

Permalink
Update lisk core to 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
slaweet committed Jan 23, 2018
1 parent aa1ff41 commit e951c03
Show file tree
Hide file tree
Showing 28 changed files with 127 additions and 89 deletions.
6 changes: 3 additions & 3 deletions src/actions/peers.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ export const activePeerSet = data =>
}
if (config.custom) {
getNethash(Lisk.api(config)).then((response) => {
config.testnet = response.nethash === netHashes.testnet;
if (!config.testnet && response.nethash !== netHashes.mainnet) {
config.nethash = response.nethash;
config.testnet = response.data.nethash === netHashes.testnet;
if (!config.testnet && response.data.nethash !== netHashes.mainnet) {
config.nethash = response.data.nethash;
}
dispatch(peerSet(data, config));
}).catch(() => {
Expand Down
6 changes: 3 additions & 3 deletions src/actions/peers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('actions: peers', () => {
};

activePeerSet(data)(dispatch);
getNetHash.resolves({ nethash });
getNetHash.resolves({ data: { nethash } });

expect(dispatch).to.have.been.calledWith(match.hasNested('data.activePeer.options', data.network));
});
Expand All @@ -72,7 +72,7 @@ describe('actions: peers', () => {
};

activePeerSet({ passphrase, network })(dispatch);
getNetHash.resolves({ nethash: netHashes.testnet });
getNetHash.resolves({ data: { nethash: netHashes.testnet } });

expect(dispatch).to.have.been.calledWith(match.hasNested('data.activePeer.testnet', true));
});
Expand All @@ -85,7 +85,7 @@ describe('actions: peers', () => {
};

activePeerSet({ passphrase, network })(dispatch);
getNetHash.resolves({ nethash: 'some other nethash' });
getNetHash.resolves({ data: { nethash: 'some other nethash' } });

expect(dispatch).to.have.been.calledWith(match.hasNested('data.activePeer.testnet', false));
});
Expand Down
2 changes: 1 addition & 1 deletion src/actions/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const transactionsRequested = ({ activePeer, address, limit, offset }) =>
.then((response) => {
dispatch(transactionsLoaded({
count: parseInt(response.count, 10),
confirmed: response.transactions,
confirmed: response.data,
}));
});
};
2 changes: 1 addition & 1 deletion src/actions/transactions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('actions: transactions', () => {
});

it('should dispatch transactionAdded action if resolved', () => {
accountApiMock.returnsPromise().resolves({ transactions: [], count: '0' });
accountApiMock.returnsPromise().resolves({ data: [], count: '0' });
const expectedAction = {
count: 0,
confirmed: [],
Expand Down
16 changes: 8 additions & 8 deletions src/actions/voting.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,28 +118,28 @@ export const votePlaced = ({ activePeer, passphrase, account, votes, secondSecre
*/
export const votesFetched = ({ activePeer, address, type }) =>
(dispatch) => {
listAccountDelegates(activePeer, address).then(({ delegates }) => {
listAccountDelegates(activePeer, address).then(({ data }) => {
if (type === 'update') {
dispatch(votesUpdated({ list: delegates }));
dispatch(votesUpdated({ list: data.votes }));
} else {
dispatch(votesAdded({ list: delegates }));
dispatch(votesAdded({ list: data.votes }));
}
});
};

/**
* Gets list of all delegates
*/
export const delegatesFetched = ({ activePeer, q, offset, refresh }) =>
export const delegatesFetched = ({ activePeer, search, offset, refresh }) =>
(dispatch) => {
listDelegates(
activePeer, {
offset,
limit: '100',
q,
...(search === '' ? {} : { search }),
},
).then(({ delegates, totalCount }) => {
dispatch(delegatesAdded({ list: delegates, totalDelegates: totalCount, refresh }));
).then(({ data, totalCount }) => {
dispatch(delegatesAdded({ list: data, totalDelegates: totalCount, refresh }));
});
};

Expand All @@ -153,6 +153,6 @@ export const urlVotesFound = ({ activePeer, upvotes, unvotes, address }) =>
dispatch(votesAdded({ list: votes, upvotes, unvotes }));
};
listAccountDelegates(activePeer, address)
.then(({ delegates }) => { processUrlVotes(delegates); })
.then(({ data }) => { processUrlVotes(data); })
.catch(() => { processUrlVotes([]); });
};
22 changes: 16 additions & 6 deletions src/actions/voting.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,18 @@ import { errorAlertDialogDisplayed } from './dialog';
import * as delegateApi from '../utils/api/delegate';

const delegateList = [
{ username: 'username1', publicKey: '123HG3452245L' },
{ username: 'username2', publicKey: '123HG3522345L' },
{
username: 'username1',
account: {
publicKey: '123HG3452245L',
},
},
{
username: 'username2',
account: {
publicKey: '123HG3522345L',
},
},
];

describe('actions: voting', () => {
Expand Down Expand Up @@ -172,7 +182,7 @@ describe('actions: voting', () => {
it('should dispatch votesAdded action when resolved if type !== \'update\'', () => {
const dispatch = sinon.spy();

delegateApiMock.resolves({ delegates });
delegateApiMock.resolves({ data: { votes: delegates } });
const expectedAction = { list: delegates };

votesFetched(data)(dispatch);
Expand All @@ -182,7 +192,7 @@ describe('actions: voting', () => {
it('should dispatch votesUpdated action when resolved if type === \'update\'', () => {
const dispatch = sinon.spy();

delegateApiMock.resolves({ delegates });
delegateApiMock.resolves({ data: { votes: delegates } });
const expectedAction = { list: delegates };

votesFetched({ ...data, type: 'update' })(dispatch);
Expand All @@ -208,7 +218,7 @@ describe('actions: voting', () => {
const delegateApiMock = sinon.stub(delegateApi, 'listDelegates');
const dispatch = sinon.spy();

delegateApiMock.returnsPromise().resolves({ delegates, totalCount: 10 });
delegateApiMock.returnsPromise().resolves({ data: delegates, totalCount: 10 });
const expectedAction = { list: delegates, totalDelegates: 10, refresh: true };

actionFunction(dispatch);
Expand Down Expand Up @@ -249,7 +259,7 @@ describe('actions: voting', () => {


urlVotesFound(data)(dispatch);
delegateApiMock.resolves({ delegates });
delegateApiMock.resolves({ data: delegates });
expect(dispatch).to.have.been.calledWith(votesAdded(expectedAction));
});

Expand Down
2 changes: 1 addition & 1 deletion src/components/forging/delegateStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const addPercentSign = x => (`${x}%`);

const progressCircleCardList = [
{
key: 'rate',
key: 'rank',
label: 'Rank',
percentageTransform: percentage => (Math.max(0, 101 - percentage)),
textForPercentage: identity,
Expand Down
2 changes: 1 addition & 1 deletion src/components/forging/delegateStats.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import DelegateStats from './delegateStats';
describe('DelegateStats', () => {
const delegate = {
username: 'genesis_17',
rate: 19,
rank: 19,
approval: 30,
productivity: 99.2,
};
Expand Down
5 changes: 4 additions & 1 deletion src/components/voting/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ describe('VotingHOC', () => {
},
voting: {
delegates: [
{ username: 'username1', publicKey: 'sample_key' },
{
username: 'username1',
account: { publicKey: 'sample_key' },
},
],
votes: {
username1: { confirmed: true, unconfirmed: true, publicKey: 'sample_key' },
Expand Down
4 changes: 2 additions & 2 deletions src/components/voting/voteCheckbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import Checkbox from 'react-toolbox/lib/checkbox';
import Spinner from '../spinner';

const VoteCheckbox = ({ data, status, styles, toggle }) => {
const { username, publicKey } = data;
const { username, account } = data;
const template = status && status.pending ?
<Spinner /> :
<Checkbox
className={styles.field}
checked={status ? status.unconfirmed : false}
onChange={toggle.bind(null, { username, publicKey })}
onChange={toggle.bind(null, { username, account })}
/>;
return template;
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/voting/voteCheckbox.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('VoteCheckbox', () => {
const props = {
data: {
username: 'yashar',
publicKey: 'address 1',
account: { publicKey: 'address 1' },
},
styles,
toggle: sinon.spy(),
Expand Down
6 changes: 3 additions & 3 deletions src/components/voting/voting.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ class Voting extends React.Component {
* should replace the old delegates list
* @param {Number} limit - The maximum number of results
*/
loadDelegates(q = '', refresh) {
loadDelegates(search = '', refresh) {
this.freezeLoading = true;
this.offset = refresh ? -1 : this.offset;
this.props.delegatesFetched({
activePeer: this.props.activePeer,
offset: this.offset > -1 ? this.offset : 0,
q,
search,
refresh,
});
}
Expand Down Expand Up @@ -112,7 +112,7 @@ class Voting extends React.Component {
<TableCell>{this.props.t('Approval')}</TableCell>
</TableHead>
{this.props.delegates.map(item => (
<VotingRow key={item.address} data={item}
<VotingRow key={item.account.address} data={item}
voteToggled={this.props.voteToggled}
voteStatus={this.props.votes[item.username]}
/>
Expand Down
16 changes: 11 additions & 5 deletions src/components/voting/voting.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,20 @@ describe('Voting', () => {

const delegates = [
{
address: 'address 1',
username: 'username1',
publicKey: 'sample_key',
account: {
address: 'address 1',
publicKey: 'sample_key',
},
rank: 1,
},
{
address: 'address 2',
username: 'username2',
publicKey: 'sample_key',
account: {
address: 'address 2',
publicKey: 'sample_key',
},
rank: 2,
},
];
const votes = {
Expand Down Expand Up @@ -80,7 +86,7 @@ describe('Voting', () => {
expect(props.delegatesFetched).to.be.calledWith({
activePeer: props.activePeer,
offset: 0,
q: 'query',
search: 'query',
refresh: true,
});
clock.restore();
Expand Down
2 changes: 1 addition & 1 deletion src/components/voting/votingRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class VotingRow extends React.Component {
</TableCell>
<TableCell>{data.rank}</TableCell>
<TableCell>{data.username}</TableCell>
<TableCell>{data.address}</TableCell>
<TableCell>{data.account.address}</TableCell>
<TableCell>{data.productivity} %</TableCell>
<TableCell>{data.approval} %</TableCell>
</TableRow>
Expand Down
8 changes: 7 additions & 1 deletion src/components/voting/votingRow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ describe('VotingRow', () => {
const unvoteStatus = { confirmed: true, unconfirmed: false, publicKey: 'sample_key' };
const pendingStatus = { confirmed: true, unconfirmed: true, pending: true, publicKey: 'sample_key' };
const props = {
data: {},
data: {
rank: 1,
username: 'genesis_17',
account: {
address: '16313739661670634666L',
},
},
voteToggled: () => {},
};
const options = {
Expand Down
5 changes: 5 additions & 0 deletions src/store/middlewares/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,18 @@ const checkTransactionsAndUpdateAccount = (store, action) => {
updateTransactions(store, peers, account);
}

/*
* commented out because of API changed and it no longer provides list of transactions
const tx = action.data.block.transactions;
const accountAddress = state.account.address;
const blockContainsRelevantTransaction = tx.filter((transaction) => {
const sender = transaction ? transaction.senderId : null;
const recipient = transaction ? transaction.recipientId : null;
return accountAddress === recipient || accountAddress === sender;
}).length > 0;
*/
const emptyPayloadHash = ' e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855';
const blockContainsRelevantTransaction = action.data.block.payloadHash !== emptyPayloadHash;

if (blockContainsRelevantTransaction) {
updateAccountData(store, action);
Expand Down
18 changes: 5 additions & 13 deletions src/store/middlewares/login.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import i18next from 'i18next';
import { getAccount, extractAddress, extractPublicKey } from '../../utils/api/account';
import { getDelegate } from '../../utils/api/delegate';
import { accountLoggedIn } from '../../actions/account';
import actionTypes from '../../constants/actions';
import { errorToastDisplayed } from '../../actions/toaster';
Expand All @@ -24,18 +23,11 @@ const loginMiddleware = store => next => (action) => {

// redirect to main/transactions
return getAccount(activePeer, address).then(accountData =>
getDelegate(activePeer, { publicKey })
.then((delegateData) => {
store.dispatch(accountLoggedIn(Object.assign(
{}, accountData, accountBasics,
{ delegate: delegateData.delegate, isDelegate: true },
)));
}).catch(() => {
store.dispatch(accountLoggedIn(Object.assign(
{}, accountData, accountBasics,
{ delegate: {}, isDelegate: false },
)));
}),
store.dispatch(accountLoggedIn({
...accountData,
...accountBasics,
...{ isDelegate: accountData.delegate !== undefined },
})),
).catch(() => store.dispatch(errorToastDisplayed({ label: i18next.t('Unable to connect to the node') })));
};

Expand Down
2 changes: 1 addition & 1 deletion src/store/middlewares/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const transactionsUpdated = (store) => {
unconfirmedTransactions(peers.data, account.address)
.then(response => store.dispatch(transactionsFailed({
failed: transactions.pending.filter(tx =>
response.transactions.filter(unconfirmedTx => tx.id === unconfirmedTx.id).length === 0),
response.data.filter(unconfirmedTx => tx.id === unconfirmedTx.id).length === 0),
})));
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/store/middlewares/transactions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('transaction middleware', () => {
];
accountApiMock.expects('unconfirmedTransactions')
.withExactArgs(state.peers.data, state.account.address)
.returnsPromise().resolves({ transactions });
.returnsPromise().resolves({ data: transactions });
store.getState = () => ({
...state,
transactions: {
Expand Down
4 changes: 2 additions & 2 deletions src/store/reducers/voting.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const mergeVotes = (newList, oldDict) => {
confirmed: true,
unconfirmed: true,
pending: false,
publicKey: delegate.publicKey,
account: delegate.account,
};
return tempDict;
}, {});
Expand Down Expand Up @@ -51,7 +51,7 @@ const voting = (state = {
votesDict[delegate.username] = {
confirmed: true,
unconfirmed: true,
publicKey: delegate.publicKey,
account: delegate.account,
};
return votesDict;
}, {}),
Expand Down
Loading

0 comments on commit e951c03

Please sign in to comment.