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

Commit

Permalink
Merge branch 'development' into 180-fix-states
Browse files Browse the repository at this point in the history
  • Loading branch information
karmacoma authored May 9, 2017
2 parents 6245104 + 228dcec commit 23af8d5
Show file tree
Hide file tree
Showing 16 changed files with 233 additions and 153 deletions.
2 changes: 1 addition & 1 deletion src/app/components/main/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ app.component('main', {
this.$rootScope.reset();
return this.account.getAccountPromise(this.account.get().address)
.then((res) => {
this.account.set({ balance: res.balance });
this.account.set(res);
})
.catch((res) => {
this.account.set({ balance: null });
Expand Down
8 changes: 4 additions & 4 deletions src/app/components/main/setSecondPassDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import './secondPass.less';

app.directive('setSecondPass', (setSecondPass, Account, $rootScope, dialog) => {
/* eslint no-param-reassign: ["error", { "props": false }] */
const SetSecondPassLink = function (scope, element, attrs) {
const SetSecondPassLink = function (scope, element) {
element.bind('click', () => {
setSecondPass.show();
});

scope.passConfirmSubmit = (secondsecret) => {
Account.setSecondSecret(secondsecret, attrs.publicKey, attrs.passphrase)
Account.setSecondSecret(secondsecret, Account.get().publicKey, Account.get().passphrase)
.then(() => {
dialog.successAlert('Your second passphrase was successfully registered.');
dialog.successAlert({ text: 'Your second passphrase was successfully registered.' });
})
.catch((err) => {
let text = '';
Expand All @@ -19,7 +19,7 @@ app.directive('setSecondPass', (setSecondPass, Account, $rootScope, dialog) => {
} else if (/^(Account does not have enough LSK)/.test(err.message)) {
text = 'You have insuffcient funds to register a second passphrase.';
} else {
text = 'An error occurred while registering your second passphrase. Please try again.';
text = err.message || 'An error occurred while registering your second passphrase. Please try again.';
}
dialog.errorAlert({ text });
});
Expand Down
90 changes: 25 additions & 65 deletions src/app/components/send/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,74 +45,34 @@ app.component('send', {
reset() {
this.recipient.value = '';
this.amount.value = '';
this.sendForm.$setUntouched();
}

promptSecondPassphrase() {
return this.$q((resolve, reject) => {
if (this.account.secondSignature) {
this.$mdDialog.show({
controllerAs: '$ctrl',
template: require('./second.pug')(),
controller: /* @ngInject*/ class second {
constructor($scope, $mdDialog) {
this.$mdDialog = $mdDialog;
}

ok() {
this.$mdDialog.hide();
resolve(this.value);
}

cancel() {
this.$mdDialog.hide();
reject();
}
},
});
} else {
resolve(null);
}
});
}

go() {
sendLSK() {
this.loading = true;

this.promptSecondPassphrase()
.then((secondPassphrase) => {
this.account.sendLSK(
this.recipient.value,
this.amount.raw,
this.account.get().passphrase,
secondPassphrase,
)
.then(
(data) => {
const transaction = {
id: data.transactionId,
senderPublicKey: this.account.get().publicKey,
senderId: this.account.get().address,
recipientId: this.recipient.value,
amount: this.amount.raw,
fee: 10000000,
};
this.$rootScope.$broadcast('transaction-sent', transaction);
return this.dialog.successAlert({ text: `${this.amount.value} sent to ${this.recipient.value}` })
.then(() => {
this.reset();
});
},
(res) => {
this.dialog.errorAlert({ text: res && res.message ? res.message : 'An error occurred while sending the transaction.' });
},
)
.finally(() => {
this.loading = false;
});
}, () => {
this.loading = false;
});
this.account.sendLSK(
this.recipient.value,
this.amount.raw,
this.account.get().passphrase,
this.secondPassphrase,
).then((data) => {
const transaction = {
id: data.transactionId,
senderPublicKey: this.account.get().publicKey,
senderId: this.account.get().address,
recipientId: this.recipient.value,
amount: this.amount.raw,
fee: 10000000,
};
this.$rootScope.$broadcast('transaction-sent', transaction);
return this.dialog.successAlert({ text: `${this.amount.value} sent to ${this.recipient.value}` })
.then(() => {
this.reset();
});
}).catch((res) => {
this.dialog.errorAlert({ text: res && res.message ? res.message : 'An error occurred while sending the transaction.' });
}).finally(() => {
this.loading = false;
});
}

setMaxAmount() {
Expand Down
8 changes: 5 additions & 3 deletions src/app/components/send/send.pug
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ div.dialog-send(aria-label='Send funds')
div(ng-messages='$ctrl.sendForm.recipient.$error')
div(ng-message='required') Required
div(ng-message='pattern') Invalid
<div layout="row">
div(layout="row")
md-input-container.md-block.flex-95
label Transaction Amount
input(type='text', name='amount', ng-model='$ctrl.amount.value', required, ng-pattern='$ctrl.amount.regexp', ng-disabled='$ctrl.loading', ng-max='$ctrl.amount.max')
Expand All @@ -29,8 +29,10 @@ div.dialog-send(aria-label='Send funds')
md-button(ng-click='$ctrl.setMaxAmount()')
div(layout='row', flex='')
p(flex='') Set maximum amount

md-input-container.md-block(ng-if='$ctrl.account.get().secondSignature')
label Second Passphrase
input(type='password', ng-model='$ctrl.secondPassphrase', required)
md-dialog-actions(layout='row')
md-button.md-raised.md-secondary(ng-disabled='$ctrl.loading', ng-click='$ctrl.cancel()') {{ 'Cancel' }}
span(flex)
md-button.md-raised.md-primary(ng-disabled='!$ctrl.sendForm.$valid || $ctrl.loading', ng-click='$ctrl.go()') {{ $ctrl.loading ? 'Sending...' : 'Send' }}
md-button.md-raised.md-primary(ng-disabled='!$ctrl.sendForm.$valid || $ctrl.loading', ng-click='$ctrl.sendLSK()') {{ $ctrl.loading ? 'Sending...' : 'Send' }}
8 changes: 6 additions & 2 deletions src/app/components/sign-verify/verify-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ app.component('verifyMessage', {
try {
this.result = lisk.crypto.verifyMessageWithPublicKey(
this.signature.value, this.publicKey.value);
if (this.result && this.result.message) {
throw this.result;
}
} catch (e) {
if (e.message.substring(0, 4) === 'nacl' && this.publicKey.value) {
if (e.message.indexOf('Invalid publicKey') !== -1 && this.publicKey.value) {
this.publicKey.error.invalid = true;
} else if (e.message.indexOf('length') !== -1 && this.signature.value) {
} else if (e.message.indexOf('Invalid signature') !== -1 && this.signature.value) {
this.signature.error.invalid = true;
}
this.result = '';
}
}
},
Expand Down
37 changes: 13 additions & 24 deletions src/app/components/transactions/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ app.component('transactions', {
});
}

init(show) {
init(showLoading) {
this.reset();
this.update(show);
this.update(showLoading);
}

$onDestroy() {
Expand All @@ -46,39 +46,32 @@ app.component('transactions', {
reset() {
this.loaded = false;
}

showMore() {
if (this.more) {
if (this.moreTransactionsExist) {
this.update(true, true);
}
}
update(show, more) {
this.loading = true;

if (show) {
this.loading_show = true;
update(showLoading, showMore) {
if (showLoading) {
this.loaded = false;
}

this.$timeout.cancel(this.timeout);
const limit = Math.max(10, this.transactions.length + (showMore ? 10 : 0));
return this.loadTransactions(limit);
}

let limit = (this.transactions.length || 10) + (more ? 10 : 0);

if (limit < 10) {
limit = 10;
}

loadTransactions(limit) {
return this.account.listTransactions(this.account.get().address, limit)
.then(this._processTransactionsResponse.bind(this))
.catch(() => {
this.transactions = [];
this.more = 0;
this.moreTransactionsExist = 0;
})
.finally(() => {
this.loaded = true;
this.loading = false;

if (show) {
this.loading_show = false;
}

this.timeout = this.$timeout(this.update.bind(this), UPDATE_INTERVAL);
});
Expand All @@ -90,11 +83,7 @@ app.component('transactions', {
this.transactions = this.pendingTransactions.concat(response.transactions);
this.total = response.count;

if (this.total > this.transactions.length) {
this.more = this.total - this.transactions.length;
} else {
this.more = 0;
}
this.moreTransactionsExist = Math.max(0, this.total - this.transactions.length);
}
},
});
4 changes: 2 additions & 2 deletions src/app/components/transactions/transactions.pug
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ md-card.offline-hide
md-content(layout='row', layout-align='start center', layout-padding)
span.title.md-title Transactions
div(flex)
span.empty(ng-show='!$ctrl.transactions.length') No transactions
span.empty(ng-show='!$ctrl.transactions.length && $ctrl.loaded') No transactions
md-content(layout='column', layout-align='center center')
md-table-container(ng-show='$ctrl.transactions.length')
table(md-table)
Expand Down Expand Up @@ -47,4 +47,4 @@ md-card.offline-hide
.fee
lsk(amount='transaction.fee')
.loading
md-progress-linear(md-mode='indeterminate', ng-show='$ctrl.loading_show || !$ctrl.loaded')
md-progress-linear(md-mode='indeterminate', ng-show='!$ctrl.loaded')
16 changes: 9 additions & 7 deletions src/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ module.exports = function (config) {

preprocessors,

mochaReporter: {
output: 'autowatch',
},

babelPreprocessor: {
options: {
presets: ['es2015'],
Expand Down Expand Up @@ -78,13 +82,11 @@ module.exports = function (config) {
},

coverageReporter: {
reporters: [{
type: 'text',
dir: 'coverage/',
}, {
type: opts.onTravis ? 'lcov' : 'html',
dir: 'coverage/',
}],
reporters: [
{
type: opts.onTravis ? 'lcov' : 'html',
dir: 'coverage/',
}].concat(opts.onTravis ? [{ type: 'text' }] : []),
},

// Start these browsers
Expand Down
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"bitcore-mnemonic": "=1.1.1",
"debug": "=2.2.0",
"jquery": "=2.2.4",
"lisk-js": "=0.4.0",
"lisk-js": "=0.4.1",
"lodash": "=4.16.4",
"moment": "=2.15.1",
"ng-infinite-scroll": "=1.3.0",
Expand Down
66 changes: 65 additions & 1 deletion src/test/components/delegates/delegates.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@ describe('delegates component controller', () => {
let $peers;
let delegates;
let $q;
let $timeout;

beforeEach(inject((_$componentController_, _$rootScope_, _$q_, _$peers_) => {
beforeEach(inject((_$componentController_, _$rootScope_, _$q_, _$peers_, _$timeout_) => {
$componentController = _$componentController_;
$rootScope = _$rootScope_;
$peers = _$peers_;
$q = _$q_;
$timeout = _$timeout_;
}));

beforeEach(() => {
Expand Down Expand Up @@ -240,6 +242,68 @@ describe('delegates component controller', () => {
});
});

describe('checkPendingVotes()', () => {
let delegateServiceMock;
let accountDelegtatesDeferred;
let delegate41;
let delegate42;

beforeEach(() => {
accountDelegtatesDeferred = $q.defer();
delegateServiceMock = sinon.mock(controller.delegateService);
delegateServiceMock.expects('listAccountDelegates').returns(accountDelegtatesDeferred.promise);
delegate41 = { username: 'genesis_41', status: {} };
delegate42 = { username: 'genesis_42', status: {} };
});

afterEach(() => {
delegateServiceMock.verify();
delegateServiceMock.restore();
});

it('calls delegateService.listAccountDelegates and then removes all returned delegates from this.votePendingList', () => {
controller.votePendingList = [delegate41, delegate42];
controller.unvotePendingList = [];

controller.checkPendingVotes();

$timeout.flush();
accountDelegtatesDeferred.resolve({ success: true, delegates: [delegate42] });
$scope.$apply();

expect(controller.votePendingList.length).to.equal(1);
expect(controller.votePendingList[0]).to.deep.equal(delegate41);
});

it('calls delegateService.listAccountDelegates and then removes all NOT returned delegates from this.unvotePendingList', () => {
controller.votePendingList = [];
controller.unvotePendingList = [delegate41, delegate42];

controller.checkPendingVotes();

$timeout.flush();
accountDelegtatesDeferred.resolve({ success: true, delegates: [delegate42] });
$scope.$apply();

expect(controller.unvotePendingList.length).to.equal(1);
expect(controller.unvotePendingList[0]).to.deep.equal(delegate42);
});

it('calls delegateService.listAccountDelegates and if in the end there are still some votes pending calls itself again', () => {
controller.votePendingList = [];
controller.unvotePendingList = [delegate41, delegate42];

controller.checkPendingVotes();

$timeout.flush();
const selfMock = sinon.mock(controller);
selfMock.expects('checkPendingVotes');
accountDelegtatesDeferred.resolve({ success: true, delegates: [] });

$scope.$apply();
});
});

describe('parseVoteListFromInput(list)', () => {
let delegateServiceMock;

Expand Down
Loading

0 comments on commit 23af8d5

Please sign in to comment.