diff --git a/src/app/components/delegates/delegates.js b/src/app/components/delegates/delegates.js
index 3c0651072..6a9c2f153 100644
--- a/src/app/components/delegates/delegates.js
+++ b/src/app/components/delegates/delegates.js
@@ -9,11 +9,11 @@ app.component('delegates', {
passphrase: '<',
},
controller: class delegates {
- constructor($scope, $rootScope, $peers, $mdDialog, $mdMedia,
+ constructor($scope, $rootScope, Peers, $mdDialog, $mdMedia,
dialog, $timeout, delegateService, Account) {
this.$scope = $scope;
this.$rootScope = $rootScope;
- this.$peers = $peers;
+ this.peers = Peers;
this.delegateService = delegateService;
this.$mdDialog = $mdDialog;
this.$mdMedia = $mdMedia;
@@ -47,7 +47,7 @@ app.component('delegates', {
updateAll() {
this.delegates = [];
this.delegatesDisplayedCount = 20;
- if (this.$peers.active) {
+ if (this.peers.active) {
this.delegateService.listAccountDelegates({
address: this.account.get().address,
}).then((data) => {
diff --git a/src/app/components/header/header.pug b/src/app/components/header/header.pug
index f30357258..849b0de6f 100644
--- a/src/app/components/header/header.pug
+++ b/src/app/components/header/header.pug
@@ -1,7 +1,7 @@
md-content.header(layout='row', layout-align='center center', layout-padding)
img.logo(src=require('../../assets/images/LISK-nano.png'))
div(flex)
- md-button.md-raised.md-primary.send(data-show-send-modal, ng-if='$root.logged') Send
+ md-button.md-raised.md-primary.transfer(data-show-transfer-modal, ng-if='$root.logged') Transfer
md-button.md-raised.md-secondary.logout(ng-click='$root.logout()', ng-if='$root.logged') Logout
md-menu.top-menu(ng-if='$root.logged', md-position-mode='target-right target', md-offset='14 0')
md-button.md-icon-button(ng-click='$mdOpenMenu()')
@@ -22,4 +22,4 @@ md-content.header(layout='row', layout-align='center center', layout-padding)
md-menu-item(ng-if='$root.logged && !$ctrl.account.get().isDelegate')
md-button(data-delegate-registration)
div(layout='row', flex='')
- p(flex='') Delegate registration
\ No newline at end of file
+ p(flex='') Delegate registration
diff --git a/src/app/components/login/login.js b/src/app/components/login/login.js
index 1f33f4fef..db8bdd79d 100644
--- a/src/app/components/login/login.js
+++ b/src/app/components/login/login.js
@@ -8,7 +8,7 @@ app.component('login', {
/* eslint no-param-reassign: ["error", { "props": false }] */
constructor($scope, $rootScope, $timeout, $document, $mdMedia,
- $cookies, $location, Passphrase, $state, Account) {
+ $cookies, $location, Passphrase, $state, Account, Peers) {
this.$scope = $scope;
this.$rootScope = $rootScope;
this.$timeout = $timeout;
@@ -18,6 +18,7 @@ app.component('login', {
this.$location = $location;
this.$state = $state;
this.account = Account;
+ this.peers = Peers;
this.Passphrase = Passphrase;
this.generatingNewPassphrase = false;
@@ -50,6 +51,8 @@ app.component('login', {
passConfirmSubmit(_passphrase = this.input_passphrase) {
if (this.Passphrase.normalize.constructor === Function) {
+ this.peers.setActive(this.network);
+
this.account.set({
passphrase: this.Passphrase.normalize(_passphrase),
network: this.network,
diff --git a/src/app/components/main/main.js b/src/app/components/main/main.js
index c9eb33883..424e34126 100644
--- a/src/app/components/main/main.js
+++ b/src/app/components/main/main.js
@@ -6,17 +6,18 @@ app.component('main', {
template: require('./main.pug')(),
controllerAs: '$ctrl',
controller: class main {
- constructor($scope, $rootScope, $timeout, $q, $state, $peers,
- dialog, SendModal, Account) {
+ constructor($scope, $rootScope, $timeout, $q, $state, Peers,
+ dialog, TransferModal, Account, AccountApi) {
this.$scope = $scope;
this.$rootScope = $rootScope;
this.$timeout = $timeout;
this.$q = $q;
- this.$peers = $peers;
+ this.peers = Peers;
this.dialog = dialog;
- this.sendModal = SendModal;
+ this.transferModal = TransferModal;
this.$state = $state;
this.account = Account;
+ this.accountApi = AccountApi;
this.init();
}
@@ -31,8 +32,6 @@ app.component('main', {
this.$rootScope.prelogged = true;
- this.$peers.setActive(this.account.get());
-
this.update()
.then(() => {
this.$rootScope.prelogged = false;
@@ -53,7 +52,7 @@ app.component('main', {
checkIfIsDelegate() {
if (this.account.get() && this.account.get().publicKey) {
- this.$peers.active.sendRequest('delegates/get', {
+ this.peers.active.sendRequest('delegates/get', {
publicKey: this.account.get().publicKey,
}, (data) => {
if (data.success && data.delegate) {
@@ -68,7 +67,7 @@ app.component('main', {
update() {
this.$rootScope.reset();
- return this.account.getAccountPromise(this.account.get().address)
+ return this.accountApi.get(this.account.get().address)
.then((res) => {
this.account.set(res);
})
diff --git a/src/app/components/main/setSecondPassDirective.js b/src/app/components/main/setSecondPassDirective.js
index 2eb2195fb..d688d2a3d 100644
--- a/src/app/components/main/setSecondPassDirective.js
+++ b/src/app/components/main/setSecondPassDirective.js
@@ -1,6 +1,6 @@
import './secondPass.less';
-app.directive('setSecondPass', (setSecondPass, Account, $rootScope, dialog) => {
+app.directive('setSecondPass', (setSecondPass, Account, $rootScope, dialog, AccountApi) => {
/* eslint no-param-reassign: ["error", { "props": false }] */
const SetSecondPassLink = function (scope, element) {
element.bind('click', () => {
@@ -8,7 +8,7 @@ app.directive('setSecondPass', (setSecondPass, Account, $rootScope, dialog) => {
});
scope.passConfirmSubmit = (secondsecret) => {
- Account.setSecondSecret(secondsecret, Account.get().publicKey, Account.get().passphrase)
+ AccountApi.setSecondSecret(secondsecret, Account.get().publicKey, Account.get().passphrase)
.then(() => {
dialog.successAlert({ text: 'Your second passphrase was successfully registered.' });
})
diff --git a/src/app/components/send/sendModalDirective.js b/src/app/components/send/sendModalDirective.js
deleted file mode 100644
index 0b43dda3e..000000000
--- a/src/app/components/send/sendModalDirective.js
+++ /dev/null
@@ -1,16 +0,0 @@
-app.directive('showSendModal', (SendModal) => {
- const ShowSendModalLink = function (scope, element) {
- element.bind('click', () => {
- SendModal.show(scope.recipientId, scope.amount);
- });
- };
-
- return {
- restrict: 'A',
- scope: {
- recipientId: '<',
- amount: '<',
- },
- link: ShowSendModalLink,
- };
-});
diff --git a/src/app/components/sign-verify/verify-message.js b/src/app/components/sign-verify/verify-message.js
index da217bd86..9e963b301 100644
--- a/src/app/components/sign-verify/verify-message.js
+++ b/src/app/components/sign-verify/verify-message.js
@@ -2,6 +2,7 @@ import lisk from 'lisk-js';
app.component('verifyMessage', {
template: require('./verify-message.pug')(),
+ controllerAs: '$ctrl',
controller: class verifyMessage {
constructor($mdDialog, Account) {
this.$mdDialog = $mdDialog;
diff --git a/src/app/components/top/top.js b/src/app/components/top/top.js
index b6e2aec03..3e5b74a12 100644
--- a/src/app/components/top/top.js
+++ b/src/app/components/top/top.js
@@ -3,8 +3,8 @@ import './top.less';
app.component('top', {
template: require('./top.pug')(),
controller: class top {
- constructor($peers, Account) {
- this.$peers = $peers;
+ constructor(Peers, Account) {
+ this.peers = Peers;
this.account = Account;
}
},
diff --git a/src/app/components/top/top.pug b/src/app/components/top/top.pug
index b9229c59f..c192f3ec6 100644
--- a/src/app/components/top/top.pug
+++ b/src/app/components/top/top.pug
@@ -7,14 +7,14 @@ md-content(layout='column', layout-gt-xs='row')
md-card.peer(flex-gt-xs=33)
md-card-content(layout='column', layout-align='center center')
span.status
- i.material-icons.offline(ng-show='!$ctrl.$peers.online') error
- i.material-icons.online(ng-show='$ctrl.$peers.online') check circle
+ i.material-icons.offline(ng-show='!$ctrl.peers.online') error
+ i.material-icons.online(ng-show='$ctrl.peers.online') check circle
span.md-title.title Peer
div.active-peer.value
- span(ng-bind="$ctrl.$peers.active.currentPeer")
- span(ng-if="$ctrl.$peers.active.port && $ctrl.$peers.active.port != '8000' ")
+ span(ng-bind="$ctrl.peers.active.currentPeer")
+ span(ng-if="$ctrl.peers.active.port && $ctrl.peers.active.port != '8000' ")
span :
- span(ng-bind="$ctrl.$peers.active.port")
+ span(ng-bind="$ctrl.peers.active.port")
md-card.offline-hide(flex-gt-xs=33)
md-card-content(layout='column', layout-align='center center')
span.md-title.title Balance
diff --git a/src/app/components/transactions/transactions.js b/src/app/components/transactions/transactions.js
index d0bd2d842..e14c29d29 100644
--- a/src/app/components/transactions/transactions.js
+++ b/src/app/components/transactions/transactions.js
@@ -5,13 +5,14 @@ const UPDATE_INTERVAL = 20000;
app.component('transactions', {
template: require('./transactions.pug')(),
controller: class transactions {
- constructor($scope, $rootScope, $timeout, $q, $peers, Account) {
+ constructor($scope, $rootScope, $timeout, $q, Peers, Account, AccountApi) {
this.$scope = $scope;
this.$rootScope = $rootScope;
this.$timeout = $timeout;
this.$q = $q;
- this.$peers = $peers;
+ this.peers = Peers;
this.account = Account;
+ this.accountApi = AccountApi;
this.loaded = false;
this.transactions = [];
@@ -64,7 +65,7 @@ app.component('transactions', {
}
loadTransactions(limit) {
- return this.account.listTransactions(this.account.get().address, limit)
+ return this.accountApi.transactions.get(this.account.get().address, limit)
.then(this._processTransactionsResponse.bind(this))
.catch(() => {
this.transactions = [];
diff --git a/src/app/components/transactions/transactions.pug b/src/app/components/transactions/transactions.pug
index 70fcdb423..5c3db31f7 100644
--- a/src/app/components/transactions/transactions.pug
+++ b/src/app/components/transactions/transactions.pug
@@ -12,7 +12,7 @@ md-card.offline-hide
th(md-column) Time
th(md-column) Transaction ID
th(md-column) From / To
- th(md-column) Send to this
+ th(md-column) Transfer to this
th(md-column) Amount
th(md-column) Fee
tbody(md-body, infinite-scroll='$ctrl.showMore()')
@@ -35,8 +35,8 @@ md-card.offline-hide
span(ng-bind='transaction.senderId', ng-if='transaction.senderId !== $ctrl.account.get().address')
span(ng-bind='transaction.recipientId', ng-if='transaction.senderId === $ctrl.account.get().address')
td(md-cell)
- i.material-icons.expanding-button(ng-if='transaction.senderId !== $ctrl.account.get().address', data-show-send-modal, data-recipient-id='transaction.senderId') arrow_forward
- i.material-icons.expanding-button(ng-if='transaction.senderId === $ctrl.account.get().address', data-show-send-modal, data-recipient-id='transaction.recipientId') arrow_forward
+ i.material-icons.expanding-button(ng-if='transaction.senderId !== $ctrl.account.get().address', data-show-transfer-modal, data-recipient-id='transaction.senderId') arrow_forward
+ i.material-icons.expanding-button(ng-if='transaction.senderId === $ctrl.account.get().address', data-show-transfer-modal, data-recipient-id='transaction.recipientId') arrow_forward
td(md-cell)
i.material-icons.in(ng-if='transaction.senderId !== $ctrl.account.get().address') call_received
i.material-icons.out(ng-if='transaction.senderId === $ctrl.account.get().address') call_made
diff --git a/src/app/components/send/second.pug b/src/app/components/transfer/second.pug
similarity index 100%
rename from src/app/components/send/second.pug
rename to src/app/components/transfer/second.pug
diff --git a/src/app/components/send/send.js b/src/app/components/transfer/transfer.js
similarity index 79%
rename from src/app/components/send/send.js
rename to src/app/components/transfer/transfer.js
index b81260e0f..98e0addd9 100644
--- a/src/app/components/send/send.js
+++ b/src/app/components/transfer/transfer.js
@@ -1,23 +1,23 @@
-import './send.less';
+import './transfer.less';
const ADDRESS_VALID_RE = '^[0-9]{1,21}[L|l]$';
const AMOUNT_VALID_RE = '^[0-9]+(.[0-9]{1,8})?$';
-app.component('send', {
- template: require('./send.pug')(),
+app.component('transfer', {
+ template: require('./transfer.pug')(),
bindings: {
recipientId: '<',
transferAmount: '<',
},
- controller: class send {
- constructor($scope, $peers, lsk, dialog, $mdDialog, $q, $rootScope, Account) {
+ controller: class transfer {
+ constructor($scope, lsk, dialog, $mdDialog, $q, $rootScope, Account, AccountApi) {
this.$scope = $scope;
- this.$peers = $peers;
this.dialog = dialog;
this.$mdDialog = $mdDialog;
this.$q = $q;
this.$rootScope = $rootScope;
this.account = Account;
+ this.accountApi = AccountApi;
this.recipient = {
regexp: ADDRESS_VALID_RE,
@@ -43,7 +43,7 @@ app.component('send', {
this.$scope.$watch('$ctrl.amount.value', () => {
if (this.amount.value) {
- this.sendForm.amount.$setValidity('max', parseFloat(this.amount.value) <= parseFloat(this.amount.max));
+ this.transferForm.amount.$setValidity('max', parseFloat(this.amount.value) <= parseFloat(this.amount.max));
}
});
}
@@ -53,9 +53,10 @@ app.component('send', {
this.amount.value = '';
}
- sendLSK() {
+ transfer() {
this.loading = true;
- this.account.sendLSK(
+
+ this.accountApi.transactions.create(
this.recipient.value,
this.amount.raw,
this.account.get().passphrase,
@@ -70,12 +71,12 @@ app.component('send', {
fee: 10000000,
};
this.$rootScope.$broadcast('transaction-sent', transaction);
- return this.dialog.successAlert({ text: `${this.amount.value} sent to ${this.recipient.value}` })
+ return this.dialog.successAlert({ text: `${this.amount.value} LSK was successfully transferred 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.' });
+ this.dialog.errorAlert({ text: res && res.message ? res.message : 'An error occurred while creating the transaction.' });
}).finally(() => {
this.loading = false;
});
diff --git a/src/app/components/send/send.less b/src/app/components/transfer/transfer.less
similarity index 98%
rename from src/app/components/send/send.less
rename to src/app/components/transfer/transfer.less
index be540fd7a..0da406726 100644
--- a/src/app/components/send/send.less
+++ b/src/app/components/transfer/transfer.less
@@ -1,4 +1,4 @@
-send {
+transfer {
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
-webkit-appearance: none;
diff --git a/src/app/components/send/send.pug b/src/app/components/transfer/transfer.pug
similarity index 80%
rename from src/app/components/send/send.pug
rename to src/app/components/transfer/transfer.pug
index dc83bcab7..918a2d201 100644
--- a/src/app/components/send/send.pug
+++ b/src/app/components/transfer/transfer.pug
@@ -1,15 +1,15 @@
-div.dialog-send(aria-label='Send funds')
- form(name='$ctrl.sendForm')
+div.dialog-transfer(aria-label='Transfer funds')
+ form(name='$ctrl.transferForm')
md-toolbar
.md-toolbar-tools
- h2 Send
+ h2 Transfer
md-dialog-content
.md-dialog-content
div
md-input-container.md-block
label Recipient Address
input(type='text', name='recipient', ng-model='$ctrl.recipient.value', required, ng-pattern='$ctrl.recipient.regexp', ng-disabled='$ctrl.loading')
- div(ng-messages='$ctrl.sendForm.recipient.$error')
+ div(ng-messages='$ctrl.transferForm.recipient.$error')
div(ng-message='required') Required
div(ng-message='pattern') Invalid
div(layout="row")
@@ -17,7 +17,7 @@ div.dialog-send(aria-label='Send funds')
label Transaction Amount
input(type='text', name='amount', ng-model='$ctrl.amount.value', required, ng-pattern='$ctrl.amount.regexp', ng-disabled='$ctrl.loading')
div.fee(ng-show='$ctrl.amount.value') Fee: 0.1 LSK
- div(ng-messages='$ctrl.sendForm.amount.$error')
+ div(ng-messages='$ctrl.transferForm.amount.$error')
div(ng-message='required') Required
div(ng-message='pattern') Invalid
div(ng-message='max') Insufficient funds
@@ -35,4 +35,4 @@ div.dialog-send(aria-label='Send funds')
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.sendLSK()') {{ $ctrl.loading ? 'Sending...' : 'Send' }}
\ No newline at end of file
+ md-button.md-raised.md-primary(ng-disabled='!$ctrl.transferForm.$valid || $ctrl.loading', ng-click='$ctrl.transfer()') {{ $ctrl.loading ? 'Transfering...' : 'Transfer' }}
diff --git a/src/app/components/transfer/transferModalDirective.js b/src/app/components/transfer/transferModalDirective.js
new file mode 100644
index 000000000..613179646
--- /dev/null
+++ b/src/app/components/transfer/transferModalDirective.js
@@ -0,0 +1,16 @@
+app.directive('showTransferModal', (TransferModal) => {
+ const ShowTransferModalLink = function (scope, element) {
+ element.bind('click', () => {
+ TransferModal.show(scope.recipientId, scope.amount);
+ });
+ };
+
+ return {
+ restrict: 'A',
+ scope: {
+ recipientId: '<',
+ amount: '<',
+ },
+ link: ShowTransferModalLink,
+ };
+});
diff --git a/src/app/components/send/sendModalService.js b/src/app/components/transfer/transferModalService.js
similarity index 65%
rename from src/app/components/send/sendModalService.js
rename to src/app/components/transfer/transferModalService.js
index dc8281e55..b4cf86fe1 100644
--- a/src/app/components/send/sendModalService.js
+++ b/src/app/components/transfer/transferModalService.js
@@ -1,4 +1,4 @@
-app.factory('SendModal', ($mdDialog) => {
+app.factory('TransferModal', ($mdDialog) => {
const init = () => {
};
@@ -6,8 +6,7 @@ app.factory('SendModal', ($mdDialog) => {
};
const show = (recipientId, amount) => ($mdDialog.show({
- template: '',
- parent: angular.element('#main'),
+ template: '',
locals: {
recipientId, amount,
},
diff --git a/src/app/lisk-nano.js b/src/app/lisk-nano.js
index 30744a196..c6e28d899 100644
--- a/src/app/lisk-nano.js
+++ b/src/app/lisk-nano.js
@@ -9,9 +9,9 @@ import './components/login/login';
import './components/login/passphrase';
import './components/top/top';
import './components/header/header';
-import './components/send/send';
-import './components/send/sendModalService';
-import './components/send/sendModalDirective';
+import './components/transfer/transfer';
+import './components/transfer/transferModalService';
+import './components/transfer/transferModalDirective';
import './components/transactions/transactions';
import './components/timestamp/timestamp';
import './components/lsk/lsk';
@@ -22,14 +22,15 @@ import './components/sign-verify/sign-message';
import './components/sign-verify/verify-message';
import './components/delegate-registration/delegateRegistration';
-import './services/peers/peers';
+import './services/api/peers';
import './services/lsk';
import './services/dialog';
import './services/passphrase';
import './services/sign-verify';
import './services/account';
-import './services/delegateService';
-import './services/forgingService';
+import './services/api/delegateApi';
+import './services/api/forgingApi';
+import './services/api/accountApi';
import './filters/lsk';
diff --git a/src/app/run.js b/src/app/run.js
index c2e62c361..448857684 100644
--- a/src/app/run.js
+++ b/src/app/run.js
@@ -1,5 +1,5 @@
-app.run(($rootScope, $timeout, $state, $transitions, $mdDialog, $peers, Account) => {
- $rootScope.peers = $peers;
+app.run(($rootScope, $timeout, $state, $transitions, $mdDialog, Peers, Account) => {
+ $rootScope.peers = Peers;
$transitions.onStart({ to: '*' }, () => {
$mdDialog.cancel();
@@ -11,7 +11,7 @@ app.run(($rootScope, $timeout, $state, $transitions, $mdDialog, $peers, Account)
$rootScope.logout = () => {
$rootScope.reset();
- $peers.reset(true);
+ Peers.reset(true);
$rootScope.logged = false;
$rootScope.prelogged = false;
diff --git a/src/app/services/account.js b/src/app/services/account.js
index afe408c98..1f993cd72 100644
--- a/src/app/services/account.js
+++ b/src/app/services/account.js
@@ -1,21 +1,35 @@
import lisk from 'lisk-js';
-app.factory('Account', function ($rootScope, $peers, $q) {
+app.factory('Account', function ($rootScope) {
this.account = {};
const merge = (obj) => {
const keys = Object.keys(obj);
+ const changes = {};
+
keys.forEach((key) => {
+ changes[key] = {
+ old: this.account[key],
+ new: obj[key],
+ };
this.account[key] = obj[key];
if (key === 'passphrase') {
const kp = lisk.crypto.getKeys(obj[key]);
+
+ changes.account = {
+ old: this.account.publicKey,
+ new: kp.publicKey,
+ };
this.account.publicKey = kp.publicKey;
+
+ changes.address = { old: this.account.address };
this.account.address = lisk.crypto.getAddress(kp.publicKey);
+ changes.address.new = this.account.address;
}
// Calling listeners with the list of changes
- $rootScope.$broadcast('onAccountChange', this.account);
+ $rootScope.$broadcast('onAccountChange', changes);
});
};
@@ -33,33 +47,5 @@ app.factory('Account', function ($rootScope, $peers, $q) {
});
};
- this.getAccountPromise = (address) => {
- const deferred = $q.defer();
- $peers.active.getAccount(this.account.address, (data) => {
- if (data.success) {
- deferred.resolve(data.account);
- } else {
- deferred.resolve({
- address,
- balance: 0,
- });
- }
- });
- return deferred.promise;
- };
-
- this.sendLSK = (recipientId, amount, secret, secondSecret) => $peers.sendRequestPromise(
- 'transactions', { recipientId, amount, secret, secondSecret });
-
- this.listTransactions = (address, limit = 20, offset = 0) => $peers.sendRequestPromise('transactions', {
- senderId: address,
- recipientId: address,
- limit,
- offset,
- });
-
- this.setSecondSecret = (secondSecret, publicKey, secret) => $peers.sendRequestPromise(
- 'signatures', { secondSecret, publicKey, secret });
-
return this;
});
diff --git a/src/app/services/api/accountApi.js b/src/app/services/api/accountApi.js
new file mode 100644
index 000000000..92a9a0fd4
--- /dev/null
+++ b/src/app/services/api/accountApi.js
@@ -0,0 +1,34 @@
+app.factory('AccountApi', function ($q, Peers, Account) {
+ this.get = (address) => {
+ const deferred = $q.defer();
+ Peers.active.getAccount(Account.get().address, (data) => {
+ if (data.success) {
+ deferred.resolve(data.account);
+ } else {
+ deferred.resolve({
+ address,
+ balance: 0,
+ });
+ }
+ });
+ return deferred.promise;
+ };
+
+ this.setSecondSecret = (secondSecret, publicKey, secret) => Peers.sendRequestPromise(
+ 'signatures', { secondSecret, publicKey, secret });
+
+ this.transactions = {};
+
+ this.transactions.create = (recipientId, amount, secret,
+ secondSecret = null) => Peers.sendRequestPromise('transactions',
+ { recipientId, amount, secret, secondSecret });
+
+ this.transactions.get = (address, limit = 20, offset = 0) => Peers.sendRequestPromise('transactions', {
+ senderId: address,
+ recipientId: address,
+ limit,
+ offset,
+ });
+
+ return this;
+});
diff --git a/src/app/services/delegateService.js b/src/app/services/api/delegateApi.js
similarity index 70%
rename from src/app/services/delegateService.js
rename to src/app/services/api/delegateApi.js
index cd28559df..44bdf4843 100644
--- a/src/app/services/delegateService.js
+++ b/src/app/services/api/delegateApi.js
@@ -1,18 +1,18 @@
-app.factory('delegateService', $peers => ({
+app.factory('delegateService', Peers => ({
listAccountDelegates(options) {
- return $peers.sendRequestPromise('accounts/delegates', options);
+ return Peers.sendRequestPromise('accounts/delegates', options);
},
listDelegates(options) {
- return $peers.sendRequestPromise(`delegates/${options.q ? 'search' : ''}`, options);
+ return Peers.sendRequestPromise(`delegates/${options.q ? 'search' : ''}`, options);
},
getDelegate(options) {
- return $peers.sendRequestPromise('delegates/get', options);
+ return Peers.sendRequestPromise('delegates/get', options);
},
vote(options) {
- return $peers.sendRequestPromise('accounts/delegates', {
+ return Peers.sendRequestPromise('accounts/delegates', {
secret: options.secret,
publicKey: options.publicKey,
secondSecret: options.secondSecret,
@@ -37,7 +37,7 @@ app.factory('delegateService', $peers => ({
if (secondSecret) {
data.secondSecret = secondSecret;
}
- return $peers.sendRequestPromise('delegates', data);
+ return Peers.sendRequestPromise('delegates', data);
},
}));
diff --git a/src/app/services/forgingService.js b/src/app/services/api/forgingApi.js
similarity index 63%
rename from src/app/services/forgingService.js
rename to src/app/services/api/forgingApi.js
index 685c47cb5..863e644bc 100644
--- a/src/app/services/forgingService.js
+++ b/src/app/services/api/forgingApi.js
@@ -1,14 +1,14 @@
import moment from 'moment';
-app.factory('forgingService', ($peers, Account) => ({
+app.factory('forgingService', (Peers, Account) => ({
getDelegate() {
- return $peers.sendRequestPromise('delegates/get', {
+ return Peers.sendRequestPromise('delegates/get', {
publicKey: Account.get().publicKey,
});
},
getForgedBlocks(limit = 10, offset = 0) {
- return $peers.sendRequestPromise('blocks', {
+ return Peers.sendRequestPromise('blocks', {
limit,
offset,
generatorPublicKey: Account.get().publicKey,
@@ -16,7 +16,7 @@ app.factory('forgingService', ($peers, Account) => ({
},
getForgedStats(startMoment) {
- return $peers.sendRequestPromise('delegates/forging/getForgedByAccount', {
+ return Peers.sendRequestPromise('delegates/forging/getForgedByAccount', {
generatorPublicKey: Account.get().publicKey,
start: moment(startMoment).unix(),
end: moment().unix(),
diff --git a/src/app/services/peers/peers.js b/src/app/services/api/peers.js
similarity index 80%
rename from src/app/services/peers/peers.js
rename to src/app/services/api/peers.js
index 9f0c8302c..5536fdd0c 100644
--- a/src/app/services/peers/peers.js
+++ b/src/app/services/api/peers.js
@@ -2,14 +2,10 @@ import lisk from 'lisk-js';
const UPDATE_INTERVAL_CHECK = 10000;
-app.factory('$peers', ($timeout, $cookies, $location, $q, $rootScope) => {
- class $peers {
+app.factory('Peers', ($timeout, $cookies, $location, $q) => {
+ class Peers {
constructor() {
this.check();
-
- $rootScope.$on('onAccountChange', (event, account) => {
- this.setActive(account);
- });
}
reset(active) {
@@ -20,9 +16,8 @@ app.factory('$peers', ($timeout, $cookies, $location, $q, $rootScope) => {
}
}
- setActive(account) {
+ setActive(network) {
let conf = { };
- const network = account.network;
if (network) {
conf = network;
if (network.address) {
@@ -50,7 +45,7 @@ app.factory('$peers', ($timeout, $cookies, $location, $q, $rootScope) => {
return deferred.promise;
}
- getStatusPromise() {
+ getStatus() {
return this.sendRequestPromise('loader/status', {});
}
@@ -64,12 +59,12 @@ app.factory('$peers', ($timeout, $cookies, $location, $q, $rootScope) => {
return;
}
- this.getStatusPromise()
+ this.getStatus()
.then(() => this.online = true)
.catch(() => this.online = false)
.finally(() => next());
}
}
- return new $peers();
+ return new Peers();
});
diff --git a/src/app/states.js b/src/app/states.js
index b56c34c57..c412b2256 100644
--- a/src/app/states.js
+++ b/src/app/states.js
@@ -8,12 +8,11 @@ app.config(($stateProvider, $urlRouterProvider) => {
component: 'login',
})
.state('main', {
- abstract: true,
url: '/main',
component: 'main',
})
.state('main.transactions', {
- url: '',
+ url: '/transactions',
component: 'transactions',
})
.state('main.voting', {
@@ -25,5 +24,4 @@ app.config(($stateProvider, $urlRouterProvider) => {
component: 'forging',
});
$urlRouterProvider.otherwise('/');
- // $locationProvider.html5Mode(true);
});
diff --git a/src/test/components/delegates/delegates.spec.js b/src/test/components/delegates/delegates.spec.js
index 696c83f7f..0b5f2a1b1 100644
--- a/src/test/components/delegates/delegates.spec.js
+++ b/src/test/components/delegates/delegates.spec.js
@@ -10,21 +10,21 @@ describe('Delegates component', () => {
let $rootScope;
let element;
let $scope;
- let $peers;
+ let Peers;
let lsk;
beforeEach(angular.mock.module('app'));
- beforeEach(inject((_$compile_, _$rootScope_, _$peers_, _lsk_) => {
+ beforeEach(inject((_$compile_, _$rootScope_, _Peers_, _lsk_) => {
$compile = _$compile_;
$rootScope = _$rootScope_;
- $peers = _$peers_;
+ Peers = _Peers_;
lsk = _lsk_;
}));
beforeEach(() => {
- $peers.active = { sendRequest() {} };
- const mock = sinon.mock($peers.active);
+ Peers.active = { sendRequest() {} };
+ const mock = sinon.mock(Peers.active);
mock.expects('sendRequest').withArgs('accounts/delegates').callsArgWith(2, {
success: true,
delegates: Array.from({ length: 10 }, (v, k) => ({
@@ -62,15 +62,15 @@ describe('delegates component controller', () => {
let controller;
let $componentController;
let activePeerMock;
- let $peers;
+ let Peers;
let delegates;
let $q;
let $timeout;
- beforeEach(inject((_$componentController_, _$rootScope_, _$q_, _$peers_, _$timeout_) => {
+ beforeEach(inject((_$componentController_, _$rootScope_, _$q_, _Peers_, _$timeout_) => {
$componentController = _$componentController_;
$rootScope = _$rootScope_;
- $peers = _$peers_;
+ Peers = _Peers_;
$q = _$q_;
$timeout = _$timeout_;
}));
@@ -81,8 +81,8 @@ describe('delegates component controller', () => {
status: {},
}));
- $peers.active = { sendRequest() {} };
- activePeerMock = sinon.mock($peers.active);
+ Peers.active = { sendRequest() {} };
+ activePeerMock = sinon.mock(Peers.active);
$scope = $rootScope.$new();
controller = $componentController('delegates', $scope, {
diff --git a/src/test/components/delegates/vote.spec.js b/src/test/components/delegates/vote.spec.js
index d0b3499dd..dc835cfc9 100644
--- a/src/test/components/delegates/vote.spec.js
+++ b/src/test/components/delegates/vote.spec.js
@@ -10,20 +10,20 @@ describe('Vote component', () => {
let $rootScope;
let element;
let $scope;
- let $peers;
+ let Peers;
let lsk;
beforeEach(angular.mock.module('app'));
- beforeEach(inject((_$compile_, _$rootScope_, _$peers_, _lsk_) => {
+ beforeEach(inject((_$compile_, _$rootScope_, _Peers_, _lsk_) => {
$compile = _$compile_;
$rootScope = _$rootScope_;
- $peers = _$peers_;
+ Peers = _Peers_;
lsk = _lsk_;
}));
beforeEach(() => {
- $peers.active = { sendRequest() {} };
+ Peers.active = { sendRequest() {} };
$scope = $rootScope.$new();
$scope.passphrase = 'robust swift grocery peasant forget share enable convince deputy road keep cheap';
diff --git a/src/test/components/header/header.spec.js b/src/test/components/header/header.spec.js
index 62ddd848b..67881cbe2 100644
--- a/src/test/components/header/header.spec.js
+++ b/src/test/components/header/header.spec.js
@@ -25,11 +25,11 @@ describe('Header component', () => {
$scope.$digest();
});
- const SEND_BUTTON_TEXT = 'Send';
- it(`should contain "${SEND_BUTTON_TEXT}" button if $root.logged`, () => {
+ const TRANSFER_BUTTON_TEXT = 'Transfer';
+ it(`should contain "${TRANSFER_BUTTON_TEXT}" button if $root.logged`, () => {
$rootScope.logged = true;
$scope.$digest();
- expect(element.find('button.md-primary.send').text()).to.equal(SEND_BUTTON_TEXT);
+ expect(element.find('button.md-primary.transfer').text()).to.equal(TRANSFER_BUTTON_TEXT);
});
const LOGOUT_BUTTON_TEXT = 'Logout';
diff --git a/src/test/components/main/main.spec.js b/src/test/components/main/main.spec.js
index 893d278f5..9dd204cfc 100644
--- a/src/test/components/main/main.spec.js
+++ b/src/test/components/main/main.spec.js
@@ -20,29 +20,28 @@ describe('main component controller', () => {
let $componentController;
let controller;
let account;
+ let peers;
+ let accountApi;
let delegateService;
- beforeEach(inject((_$componentController_, _$rootScope_, _$q_, _Account_, _delegateService_) => {
+ beforeEach(inject((_$componentController_, _$rootScope_, _Peers_,
+ _$q_, _Account_, _AccountApi_, _delegateService_) => {
$componentController = _$componentController_;
$rootScope = _$rootScope_;
$q = _$q_;
account = _Account_;
+ accountApi = _AccountApi_;
delegateService = _delegateService_;
+ peers = _Peers_;
}));
beforeEach(() => {
$scope = $rootScope.$new();
account.set({ passphrase: delegateAccount.passphrase });
- controller = $componentController('main', $scope, {});
- });
-
- describe('reset()', () => {
- // There's no reset anymore
- it.skip('cancels $timeout', () => {
- const spy = sinon.spy(controller.$timeout, 'cancel');
- controller.reset();
- expect(spy).to.have.been.calledWith(controller.timeout);
+ peers.setActive({
+ name: 'Mainnet',
});
+ controller = $componentController('main', $scope, {});
});
describe('init()', () => {
@@ -55,7 +54,7 @@ describe('main component controller', () => {
updateMock = sinon.mock(controller);
updateMock.expects('update').withArgs().returns(deffered.promise);
- peersMock = sinon.mock(controller.$peers);
+ peersMock = sinon.mock(controller.peers);
peersMock.expects('setActive').withArgs();
});
@@ -100,35 +99,6 @@ describe('main component controller', () => {
});
});
- describe('logout()', () => {
- it('resets main component', () => {
- const spy = sinon.spy($rootScope, 'reset');
- $rootScope.logout();
- expect(spy).to.have.been.calledWith();
- });
-
- it('resets peers', () => {
- const spy = sinon.spy(controller.$peers, 'reset');
- $rootScope.logout();
- expect(spy).to.have.been.calledWith(true);
- });
-
- it('sets $rootScope.logged = false', () => {
- $rootScope.logout();
- expect($rootScope.logged).to.equal(false);
- });
-
- it('sets $rootScope.prelogged = false', () => {
- $rootScope.logout();
- expect($rootScope.prelogged).to.equal(false);
- });
-
- it('resets account service', () => {
- $rootScope.logout();
- expect(account.get()).to.deep.equal({});
- });
- });
-
describe('checkIfIsDelegate()', () => {
beforeEach(() => {
account.set({
@@ -153,9 +123,9 @@ describe('main component controller', () => {
balance: '0',
passphrase: 'wagon stock borrow episode laundry kitten salute link globe zero feed marble',
});
- const mock = sinon.mock(controller.account);
- mock.expects('getAccountPromise').returns(deffered.promise);
- controller.$peers = {
+ const mock = sinon.mock(accountApi);
+ mock.expects('get').returns(deffered.promise);
+ controller.Peers = {
getStatusPromise() {
return $q.defer().promise;
},
@@ -164,7 +134,7 @@ describe('main component controller', () => {
account.reset();
});
- it('calls this.account.getAccountPromise(this.address) and then sets balance', () => {
+ it('calls this.accountApi.get(this.address) and then sets balance', () => {
expect(account.get().balance).to.equal(undefined);
controller.update();
deffered.resolve({ balance: 12345 });
@@ -172,7 +142,7 @@ describe('main component controller', () => {
expect(account.get().balance).to.equal(12345);
});
- it('calls this.account.getAccountPromise(this.address) and if it fails, then resets this.account.balance and reject the promise that update() returns', () => {
+ it('calls this.accountApi.get(this.address) and if it fails, then resets this.account.balance and reject the promise that update() returns', () => {
const spy = sinon.spy(controller.$q, 'reject');
controller.update();
deffered.reject();
diff --git a/src/test/components/main/setSecondPassDirective.spec.js b/src/test/components/main/setSecondPassDirective.spec.js
index 4e552067e..cd91229fd 100644
--- a/src/test/components/main/setSecondPassDirective.spec.js
+++ b/src/test/components/main/setSecondPassDirective.spec.js
@@ -10,7 +10,7 @@ describe('setSecondPass Directive', () => {
let $scope;
let $rootScope;
let element;
- let account;
+ let accountApi;
let setSecondPass;
let $q;
let dialog;
@@ -21,12 +21,12 @@ describe('setSecondPass Directive', () => {
// Store references to $rootScope and $compile
// so they are available to all tests in this describe block
- inject((_$compile_, _$rootScope_, _setSecondPass_, _Account_, _$q_, _dialog_) => {
+ inject((_$compile_, _$rootScope_, _setSecondPass_, _AccountApi_, _$q_, _dialog_) => {
// The injector unwraps the underscores (_) from around the parameter names when matching
$compile = _$compile_;
$rootScope = _$rootScope_;
setSecondPass = _setSecondPass_;
- account = _Account_;
+ accountApi = _AccountApi_;
$q = _$q_;
dialog = _dialog_;
$scope = $rootScope.$new();
@@ -39,7 +39,7 @@ describe('setSecondPass Directive', () => {
describe('SetSecondPassLink', () => {
it('listens for an onAfterSignup event', () => {
- const mock = sinon.mock(account);
+ const mock = sinon.mock(accountApi);
const deffered = $q.defer();
mock.expects('setSecondSecret').returns(deffered.promise);
@@ -66,8 +66,8 @@ describe('setSecondPass Directive', () => {
});
describe('scope.passConfirmSubmit', () => {
- it('should call account.setSecondSecret', () => {
- const mock = sinon.mock(account);
+ it('should call accountApi.setSecondSecret', () => {
+ const mock = sinon.mock(accountApi);
const deffered = $q.defer();
mock.expects('setSecondSecret').returns(deffered.promise);
@@ -81,7 +81,7 @@ describe('setSecondPass Directive', () => {
});
it('should show error dialog if trying to set second passphrase multiple times', () => {
- const mock = sinon.mock(account);
+ const mock = sinon.mock(accountApi);
const deffered = $q.defer();
mock.expects('setSecondSecret').returns(deffered.promise);
@@ -102,7 +102,7 @@ describe('setSecondPass Directive', () => {
});
it('should show error dialog if account does not have enough LSK', () => {
- const mock = sinon.mock(account);
+ const mock = sinon.mock(accountApi);
const deffered = $q.defer();
mock.expects('setSecondSecret').returns(deffered.promise);
@@ -115,7 +115,7 @@ describe('setSecondPass Directive', () => {
});
it('should show error dialog for all the other errors', () => {
- const mock = sinon.mock(account);
+ const mock = sinon.mock(accountApi);
const deffered = $q.defer();
mock.expects('setSecondSecret').returns(deffered.promise);
diff --git a/src/test/components/transactions/transactions.spec.js b/src/test/components/transactions/transactions.spec.js
index 6780354ea..dd3feea66 100644
--- a/src/test/components/transactions/transactions.spec.js
+++ b/src/test/components/transactions/transactions.spec.js
@@ -14,21 +14,23 @@ describe('transactions component controller', () => {
let controller;
let $componentController;
let account;
+ let accountApi;
let mock;
- beforeEach(inject((_$componentController_, _$rootScope_, _$q_, _Account_) => {
+ beforeEach(inject((_$componentController_, _$rootScope_, _$q_, _Account_, _AccountApi_) => {
$componentController = _$componentController_;
$rootScope = _$rootScope_;
$q = _$q_;
account = _Account_;
+ accountApi = _AccountApi_;
}));
beforeEach(() => {
$scope = $rootScope.$new();
- mock = sinon.mock(account);
+ mock = sinon.mock(accountApi.transactions);
const deffered = $q.defer();
- mock.expects('listTransactions').returns(deffered.promise);
- mock.expects('listTransactions').returns(deffered.promise);
+ mock.expects('get').returns(deffered.promise);
+ mock.expects('get').returns(deffered.promise);
controller = $componentController('transactions', $scope, {});
account.set({
passphrase: 'robust swift grocery peasant forget share enable convince deputy road keep cheap',
@@ -60,7 +62,7 @@ describe('transactions component controller', () => {
describe('showMore()', () => {
it('calls this.update(true, true) if this.moreTransactionsExist', () => {
controller.moreTransactionsExist = true;
- mock.expects('listTransactions').returns($q.defer().promise);
+ mock.expects('get').returns($q.defer().promise);
controller.loaded = true;
controller.showMore();
expect(controller.loaded).to.equal(false);
@@ -82,28 +84,28 @@ describe('transactions component controller', () => {
});
it('sets this.loaded = false if showLoading == true', () => {
- mock.expects('listTransactions').returns(transactionsDeferred.promise);
+ mock.expects('get').returns(transactionsDeferred.promise);
controller.loaded = undefined;
controller.update(true);
expect(controller.loaded).to.equal(false);
});
it('doesn\'t change this.loaded if showLoading == false', () => {
- mock.expects('listTransactions').returns(transactionsDeferred.promise);
+ mock.expects('get').returns(transactionsDeferred.promise);
controller.loaded = undefined;
controller.update(false);
expect(controller.loaded).to.equal(undefined);
});
it('cancels update timeout', () => {
- mock.expects('listTransactions').returns(transactionsDeferred.promise);
+ mock.expects('get').returns(transactionsDeferred.promise);
const spy = sinon.spy(controller.$timeout, 'cancel');
controller.update();
expect(spy).to.have.been.calledWith(controller.timeout);
});
- it('calls this.account.listTransactions(account.get().address, limit) with limit = 10 by default', () => {
- mock.expects('listTransactions').withArgs(account.get().address, 10).returns(transactionsDeferred.promise);
+ it('calls accountApi.transactions.get(account.get().address, limit) with limit = 10 by default', () => {
+ mock.expects('get').withArgs(account.get().address, 10).returns(transactionsDeferred.promise);
controller.update();
transactionsDeferred.reject();
diff --git a/src/test/components/send/send.spec.js b/src/test/components/transfer/transfer.spec.js
similarity index 71%
rename from src/test/components/send/send.spec.js
rename to src/test/components/transfer/transfer.spec.js
index ddc9441c9..8973f9905 100644
--- a/src/test/components/send/send.spec.js
+++ b/src/test/components/transfer/transfer.spec.js
@@ -5,21 +5,23 @@ const sinonChai = require('sinon-chai');
const expect = chai.expect;
chai.use(sinonChai);
-describe.skip('Send component', () => {
+describe.skip('Transfer component', () => {
let $compile;
let $rootScope;
let element;
let $scope;
let lsk;
let account;
+ let accountApi;
beforeEach(angular.mock.module('app'));
- beforeEach(inject((_$compile_, _$rootScope_, _lsk_, _Account_) => {
+ beforeEach(inject((_$compile_, _$rootScope_, _lsk_, _Account_, _AccountApi_) => {
$compile = _$compile_;
$rootScope = _$rootScope_;
lsk = _lsk_;
account = _Account_;
+ accountApi = _AccountApi_;
}));
beforeEach(() => {
@@ -29,11 +31,11 @@ describe.skip('Send component', () => {
balance: lsk.from(10535.77379498),
});
- element = $compile('')($scope);
+ element = $compile('')($scope);
$scope.$digest();
});
- const HEADER_TEXT = 'Send';
+ const HEADER_TEXT = 'Transfer';
it(`should contain header saying "${HEADER_TEXT}"`, () => {
expect(element.find('.md-title').text()).to.equal(HEADER_TEXT);
});
@@ -48,9 +50,9 @@ describe.skip('Send component', () => {
expect(element.find('form label:last').text()).to.equal(AMOUT_LABEL_TEXT);
});
- const SEND_BUTTON_TEXT = 'Send';
- it(`should contain a button saying "${SEND_BUTTON_TEXT}"`, () => {
- expect(element.find('button.md-raised.md-primary').text()).to.equal(SEND_BUTTON_TEXT);
+ const TRANSFER_BUTTON_TEXT = 'Transfer';
+ it(`should contain a button saying "${TRANSFER_BUTTON_TEXT}"`, () => {
+ expect(element.find('button.md-raised.md-primary').text()).to.equal(TRANSFER_BUTTON_TEXT);
});
const CANCEL_BUTTON_TEXT = 'Cancel';
@@ -58,7 +60,7 @@ describe.skip('Send component', () => {
expect(element.find('button.md-raised.md-secondary').text()).to.equal(CANCEL_BUTTON_TEXT);
});
- describe('send transaction', () => {
+ describe('create transaction', () => {
let dialog;
let $q;
@@ -67,13 +69,13 @@ describe.skip('Send component', () => {
$q = _$q_;
}));
- it('should allow to send a transaction', () => {
+ it('should allow to create a transaction', () => {
const RECIPIENT_ADDRESS = '5932438298200837883L';
const AMOUNT = '10';
const mock = sinon.mock(account);
const deffered = $q.defer();
- mock.expects('sendLSK').returns(deffered.promise);
+ mock.expects('transfer').returns(deffered.promise);
const spy = sinon.spy(dialog, 'successAlert');
@@ -88,13 +90,13 @@ describe.skip('Send component', () => {
mock.verify();
});
- it('should allow to send all funds', () => {
+ it('should allow to transfer all funds', () => {
const RECIPIENT_ADDRESS = '5932438298200837883L';
const AMOUNT = lsk.normalize(account.get().balance - 10000000);
- const mock = sinon.mock(account);
+ const mock = sinon.mock(accountApi);
const deffered = $q.defer();
- mock.expects('sendLSK').returns(deffered.promise);
+ mock.expects('transactions.create').returns(deffered.promise);
const spy = sinon.spy(dialog, 'successAlert');
@@ -107,13 +109,13 @@ describe.skip('Send component', () => {
deffered.resolve({});
$scope.$apply();
expect(spy).to.have.been.calledWith();
- expect(spy).to.have.been.calledWith({ text: `${AMOUNT} sent to ${RECIPIENT_ADDRESS}` });
+ expect(spy).to.have.been.calledWith({ text: `${AMOUNT} LSK was successfully transferred to ${RECIPIENT_ADDRESS}` });
mock.verify();
});
});
});
-describe('send component controller', () => {
+describe('Transfer component controller', () => {
beforeEach(angular.mock.module('app'));
let $rootScope;
@@ -132,7 +134,7 @@ describe('send component controller', () => {
beforeEach(() => {
$scope = $rootScope.$new();
- controller = $componentController('send', $scope, {});
+ controller = $componentController('transfer', $scope, {});
account.set({
balance: '10000',
passphrase: 'robust swift grocery peasant forget share enable convince deputy road keep cheap',
@@ -143,8 +145,8 @@ describe('send component controller', () => {
it('resets this.recipient.value and this.amount.value', () => {
controller.recipient.value = 'TEST';
controller.amount.value = '1000';
- controller.sendForm = { $setUntouched: () => {} };
- const mock = sinon.mock(controller.sendForm);
+ controller.transferForm = { $setUntouched: () => {} };
+ const mock = sinon.mock(controller.transferForm);
mock.expects('$setUntouched');
controller.reset();
@@ -154,26 +156,26 @@ describe('send component controller', () => {
});
});
- describe('sendLSK()', () => {
- it('calls this.account.sendLSK() and success.dialog on success', () => {
- const mock = sinon.mock(controller.account);
+ describe('transfer()', () => {
+ it('calls accountApi.transactions.create and success.dialog on success', () => {
+ const mock = sinon.mock(controller.accountApi.transactions);
const deffered = $q.defer();
- mock.expects('sendLSK').returns(deffered.promise);
- controller.sendLSK();
+ mock.expects('create').returns(deffered.promise);
+ controller.transfer();
const spy = sinon.spy(controller.dialog, 'successAlert');
deffered.resolve({});
$scope.$apply();
expect(spy).to.have.been.calledWith({
- text: `${controller.amount.value} sent to ${controller.recipient.value}`,
+ text: `${controller.amount.value} LSK was successfully transferred to ${controller.recipient.value}`,
});
});
- it('calls this.account.sendLSK() and error.dialog on error', () => {
- const mock = sinon.mock(controller.account);
+ it('calls accountApi.transactions.create and error.dialog on error', () => {
+ const mock = sinon.mock(controller.accountApi.transactions);
const deffered = $q.defer();
- mock.expects('sendLSK').returns(deffered.promise);
- controller.sendLSK();
+ mock.expects('create').returns(deffered.promise);
+ controller.transfer();
const spy = sinon.spy(controller.dialog, 'errorAlert');
const response = {
diff --git a/src/test/components/send/sendModalDirective.spec.js b/src/test/components/transfer/transferModalDirective.spec.js
similarity index 56%
rename from src/test/components/send/sendModalDirective.spec.js
rename to src/test/components/transfer/transferModalDirective.spec.js
index fb0078433..03c96208e 100644
--- a/src/test/components/send/sendModalDirective.spec.js
+++ b/src/test/components/transfer/transferModalDirective.spec.js
@@ -5,25 +5,25 @@ const sinonChai = require('sinon-chai');
const expect = chai.expect;
chai.use(sinonChai);
-describe('Send modal directive', () => {
+describe('Transfer modal directive', () => {
let $scope;
- let SendModal;
+ let TransferModal;
let compiled;
- const template = '
';
+ const template = '';
beforeEach(angular.mock.module('app'));
- beforeEach(inject(($compile, $rootScope, _SendModal_) => {
+ beforeEach(inject(($compile, $rootScope, _TransferModal_) => {
$scope = $rootScope.$new();
- SendModal = _SendModal_;
+ TransferModal = _TransferModal_;
compiled = $compile(template)($scope);
$scope.$digest();
}));
afterEach(() => {
- if (typeof SendModal.show.restore === 'function') {
- SendModal.show.restore();
+ if (typeof TransferModal.show.restore === 'function') {
+ TransferModal.show.restore();
}
});
@@ -32,9 +32,9 @@ describe('Send modal directive', () => {
expect(el.length).to.equal(1);
});
- it('should run SendModal.show() when clicked', () => {
+ it('should run TransferModal.show() when clicked', () => {
const el = compiled.find('button');
- const spy = sinon.spy(SendModal, 'show');
+ const spy = sinon.spy(TransferModal, 'show');
el.triggerHandler('click');
expect(spy).to.have.been.calledWith();
});
diff --git a/src/test/run.spec.js b/src/test/run.spec.js
new file mode 100644
index 000000000..742a51206
--- /dev/null
+++ b/src/test/run.spec.js
@@ -0,0 +1,72 @@
+const sinon = require('sinon');
+const sinonChai = require('sinon-chai');
+const chai = require('chai');
+
+const expect = chai.expect;
+
+const delegateAccount = {
+ passphrase: 'recipe bomb asset salon coil symbol tiger engine assist pact pumpkin visit',
+ address: '537318935439898807L',
+};
+
+chai.use(sinonChai);
+
+describe('Application run method', () => {
+ let $rootScope;
+ let account;
+ let peers;
+ let $timeout;
+
+ beforeEach(angular.mock.module('app'));
+
+ beforeEach(inject((_$rootScope_, _$timeout_, _Peers_, _Account_) => {
+ $rootScope = _$rootScope_;
+ $timeout = _$timeout_;
+ account = _Account_;
+ peers = _Peers_;
+ }));
+
+ beforeEach(() => {
+ account.set({ passphrase: delegateAccount.passphrase });
+ peers.setActive({
+ name: 'Mainnet',
+ });
+ });
+
+ describe('reset()', () => {
+ it('cancels $rootScope.$timeout', () => {
+ const spy = sinon.spy($timeout, 'cancel');
+ $rootScope.reset();
+ expect(spy).to.have.been.calledWith($rootScope.$timeout);
+ });
+ });
+
+ describe('logout()', () => {
+ it('resets application', () => {
+ const spy = sinon.spy($rootScope, 'reset');
+ $rootScope.logout();
+ expect(spy).to.have.been.calledWith();
+ });
+
+ it('resets peers', () => {
+ const spy = sinon.spy(peers, 'reset');
+ $rootScope.logout();
+ expect(spy).to.have.been.calledWith(true);
+ });
+
+ it('sets $rootScope.logged = false', () => {
+ $rootScope.logout();
+ expect($rootScope.logged).to.equal(false);
+ });
+
+ it('sets $rootScope.prelogged = false', () => {
+ $rootScope.logout();
+ expect($rootScope.prelogged).to.equal(false);
+ });
+
+ it('resets account service', () => {
+ $rootScope.logout();
+ expect(account.get()).to.deep.equal({});
+ });
+ });
+});
diff --git a/src/test/services/account.spec.js b/src/test/services/account.spec.js
index a385e46c9..dc4bc6797 100644
--- a/src/test/services/account.spec.js
+++ b/src/test/services/account.spec.js
@@ -2,81 +2,54 @@ const chai = require('chai');
const sinon = require('sinon');
const sinonChai = require('sinon-chai');
+const VALID_PASSPHRASE = 'illegal symbol search tree deposit youth mixture craft amazing tool soon unit';
+
const expect = chai.expect;
chai.use(sinonChai);
describe('Factory: Account', () => {
- let $peers;
- let $q;
let account;
- let mock;
- let deffered;
+ let $rootScope;
beforeEach(angular.mock.module('app'));
- beforeEach(inject((_$peers_, _$q_, Account) => {
- $peers = _$peers_;
- $q = _$q_;
- account = Account;
+ beforeEach(inject((_Account_, _$rootScope_) => {
+ account = _Account_;
+ $rootScope = _$rootScope_;
}));
- beforeEach(() => {
- deffered = $q.defer();
- mock = sinon.mock($peers);
- });
-
- afterEach(() => {
- mock.verify();
- mock.restore();
- });
-
- describe('sendLSK(recipientId, amount, secret, secondSecret)', () => {
- it('returns $peers.sendRequestPromise(\'transactions\', options);', () => {
- const options = {
- recipientId: '537318935439898807L',
- amount: 10,
- secret: 'wagon stock borrow episode laundry kitten salute link globe zero feed marble',
- secondSecret: null,
- };
- mock.expects('sendRequestPromise').withArgs('transactions', options).returns(deffered.promise);
+ describe('set(config)', () => {
+ it('returns this.account', () => {
+ const accountInstanse = account.get();
- const promise = account.sendLSK(
- options.recipientId, options.amount, options.secret, options.secondSecret);
+ const setReturnValue = account.set({ passphrase: VALID_PASSPHRASE });
- expect(promise).to.equal(deffered.promise);
+ expect(setReturnValue).to.equal(accountInstanse);
});
- });
- describe('listTransactions(address, limit, offset)', () => {
- it('returns $peers.sendRequestPromise(\'transactions\', options);', () => {
- const options = {
- senderId: '537318935439898807L',
- recipientId: '537318935439898807L',
- limit: 20,
- offset: 0,
- };
- mock.expects('sendRequestPromise').withArgs('transactions', options).returns(deffered.promise);
+ it('should set address and publicKey for a given valid passphrase', () => {
+ const accountInstanse = account.set({ passphrase: VALID_PASSPHRASE });
- const promise = account.listTransactions(
- options.recipientId, options.limit, options.offset);
+ expect(accountInstanse.address).to.not.equal(undefined);
+ expect(accountInstanse.publicKey).to.not.equal(undefined);
+ });
- expect(promise).to.equal(deffered.promise);
+ it('should broadcast the changes', () => {
+ const spy = sinon.spy($rootScope, '$broadcast');
+ account.set({ passphrase: VALID_PASSPHRASE });
+ expect(spy).to.have.been.calledWith();
});
});
- describe('setSecondSecret(secondSecret, publicKey, secret)', () => {
- it('returns $peers.sendRequestPromise(\'signatures\', { secondSecret, publicKey, secret });', () => {
- const publicKey = '3ff32442bb6da7d60c1b7752b24e6467813c9b698e0f278d48c43580da972135';
- const secret = 'wagon stock borrow episode laundry kitten salute link globe zero feed marble';
- const secondSecret = 'stay undo beyond powder sand laptop grow gloom apology hamster primary arrive';
- mock.expects('sendRequestPromise')
- .withArgs('signatures', { secondSecret, publicKey, secret })
- .returns(deffered.promise);
+ describe('get(config)', () => {
+ it('returns this.account', () => {
+ account.set({ passphrase: VALID_PASSPHRASE });
+ const accountInstanse = account.get();
- const promise = account.setSecondSecret(secondSecret, publicKey, secret);
-
- expect(promise).to.equal(deffered.promise);
+ expect(accountInstanse).to.not.equal(undefined);
+ expect(accountInstanse.address).to.not.equal(undefined);
+ expect(accountInstanse.publicKey).to.not.equal(undefined);
+ expect(accountInstanse.passphrase).to.not.equal(undefined);
});
});
});
-
diff --git a/src/test/services/api/accountApi.spec.js b/src/test/services/api/accountApi.spec.js
new file mode 100644
index 000000000..2750f2f11
--- /dev/null
+++ b/src/test/services/api/accountApi.spec.js
@@ -0,0 +1,81 @@
+const chai = require('chai');
+const sinon = require('sinon');
+const sinonChai = require('sinon-chai');
+
+const expect = chai.expect;
+chai.use(sinonChai);
+
+describe('Factory: AccountApi', () => {
+ let peers;
+ let accountApi;
+ let peersMock;
+
+ beforeEach(angular.mock.module('app'));
+
+ beforeEach(inject((_Peers_, _AccountApi_) => {
+ peers = _Peers_;
+ accountApi = _AccountApi_;
+ }));
+
+ beforeEach(() => {
+ peersMock = sinon.mock(peers);
+ peers.setActive({
+ name: 'Mainnet',
+ });
+ });
+
+ afterEach(() => {
+ peersMock.verify();
+ peersMock.restore();
+ });
+
+ describe('transaction.create(recipientId, amount, secret, secondSecret)', () => {
+ it('returns Peers.sendRequest(\'transactions\', options);', () => {
+ const options = {
+ recipientId: '537318935439898807L',
+ amount: 10,
+ secret: 'wagon stock borrow episode laundry kitten salute link globe zero feed marble',
+ secondSecret: null,
+ };
+ const spy = sinon.spy(peers, 'sendRequestPromise');
+
+ accountApi.transactions.create(
+ options.recipientId, options.amount, options.secret, options.secondSecret);
+
+ expect(spy).to.have.been.calledWith('transactions', options);
+ });
+ });
+
+ describe('transaction.get(address, limit, offset)', () => {
+ it('returns Peers.sendRequest(\'transactions\', options);', () => {
+ const options = {
+ senderId: '537318935439898807L',
+ recipientId: '537318935439898807L',
+ limit: 20,
+ offset: 0,
+ };
+
+ const spy = sinon.spy(peers, 'sendRequestPromise');
+
+ accountApi.transactions.get(
+ options.recipientId, options.limit, options.offset);
+
+ expect(spy).to.have.been.calledWith('transactions', options);
+ });
+ });
+
+ describe('setSecondSecret(secondSecret, publicKey, secret)', () => {
+ it('returns Peers.sendRequestPromise(\'signatures\', { secondSecret, publicKey, secret });', () => {
+ const publicKey = '3ff32442bb6da7d60c1b7752b24e6467813c9b698e0f278d48c43580da972135';
+ const secret = 'wagon stock borrow episode laundry kitten salute link globe zero feed marble';
+ const secondSecret = 'stay undo beyond powder sand laptop grow gloom apology hamster primary arrive';
+
+ const spy = sinon.spy(peers, 'sendRequestPromise');
+
+ accountApi.setSecondSecret(secondSecret, publicKey, secret);
+
+ expect(spy).to.have.been.calledWith('signatures', { secondSecret, publicKey, secret });
+ });
+ });
+});
+
diff --git a/src/test/services/delegateService.spec.js b/src/test/services/api/delegateApi.spec.js
similarity index 83%
rename from src/test/services/delegateService.spec.js
rename to src/test/services/api/delegateApi.spec.js
index fa13dc6d2..48a953455 100644
--- a/src/test/services/delegateService.spec.js
+++ b/src/test/services/api/delegateApi.spec.js
@@ -6,7 +6,7 @@ const expect = chai.expect;
chai.use(sinonChai);
describe('Factory: delegateService', () => {
- let $peers;
+ let Peers;
let $q;
let delegateService;
let mock;
@@ -14,15 +14,15 @@ describe('Factory: delegateService', () => {
beforeEach(angular.mock.module('app'));
- beforeEach(inject((_$peers_, _$q_, _delegateService_) => {
- $peers = _$peers_;
+ beforeEach(inject((_Peers_, _$q_, _delegateService_) => {
+ Peers = _Peers_;
$q = _$q_;
delegateService = _delegateService_;
}));
beforeEach(() => {
deffered = $q.defer();
- mock = sinon.mock($peers);
+ mock = sinon.mock(Peers);
});
afterEach(() => {
@@ -31,7 +31,7 @@ describe('Factory: delegateService', () => {
});
describe('listAccountDelegates(options)', () => {
- it('returns $peers.sendRequestPromise(\'accounts/delegates\', options);', () => {
+ it('returns Peers.sendRequestPromise(\'accounts/delegates\', options);', () => {
const options = {
account: {},
};
@@ -44,7 +44,7 @@ describe('Factory: delegateService', () => {
});
describe('listDelegates(options)', () => {
- it('returns $peers.sendRequestPromise(\'delegates\', options);', () => {
+ it('returns Peers.sendRequestPromise(\'delegates\', options);', () => {
const options = {
username: 'genesis_42',
};
@@ -57,7 +57,7 @@ describe('Factory: delegateService', () => {
});
describe('getDelegate(options)', () => {
- it('returns $peers.sendRequestPromise(\'delegates/get\', options);', () => {
+ it('returns Peers.sendRequestPromise(\'delegates/get\', options);', () => {
const options = {
username: 'genesis_42',
};
@@ -70,7 +70,7 @@ describe('Factory: delegateService', () => {
});
describe('vote(options)', () => {
- it('returns $peers.sendRequestPromise(\'accounts/delegates\', options);', () => {
+ it('returns Peers.sendRequestPromise(\'accounts/delegates\', options);', () => {
const options = {
secret: '',
publicKey: '',
@@ -91,7 +91,7 @@ describe('Factory: delegateService', () => {
});
describe('voteAutocomplete(username, votedDict)', () => {
- it('returns $peers.sendRequestPromise(\'delegates/search\', {q: username}) delegates filtered by not in voteDialog);', () => {
+ it('returns Peers.sendRequestPromise(\'delegates/search\', {q: username}) delegates filtered by not in voteDialog);', () => {
const username = 'genesis_4';
const votedDict = {
genesis_44: {
diff --git a/src/test/services/forgingService.spec.js b/src/test/services/api/forgingApi.spec.js
similarity index 78%
rename from src/test/services/forgingService.spec.js
rename to src/test/services/api/forgingApi.spec.js
index 73e69c673..5b49ac5f8 100644
--- a/src/test/services/forgingService.spec.js
+++ b/src/test/services/api/forgingApi.spec.js
@@ -6,7 +6,7 @@ const expect = chai.expect;
chai.use(sinonChai);
describe('Factory: forgingService', () => {
- let $peers;
+ let Peers;
let $q;
let forgingService;
let mock;
@@ -14,15 +14,15 @@ describe('Factory: forgingService', () => {
beforeEach(angular.mock.module('app'));
- beforeEach(inject((_$peers_, _$q_, _forgingService_) => {
- $peers = _$peers_;
+ beforeEach(inject((_Peers_, _$q_, _forgingService_) => {
+ Peers = _Peers_;
$q = _$q_;
forgingService = _forgingService_;
}));
beforeEach(() => {
deffered = $q.defer();
- mock = sinon.mock($peers);
+ mock = sinon.mock(Peers);
});
afterEach(() => {
@@ -31,7 +31,7 @@ describe('Factory: forgingService', () => {
});
describe('getDelegate()', () => {
- it('returns $peers.sendRequestPromise(\'delegates/get\');', () => {
+ it('returns Peers.sendRequestPromise(\'delegates/get\');', () => {
mock.expects('sendRequestPromise').withArgs('delegates/get').returns(deffered.promise);
const promise = forgingService.getDelegate();
@@ -41,7 +41,7 @@ describe('Factory: forgingService', () => {
});
describe('getForgedBlocks(limit, offset)', () => {
- it('returns $peers.sendRequestPromise(\'blocks\');', () => {
+ it('returns Peers.sendRequestPromise(\'blocks\');', () => {
mock.expects('sendRequestPromise').withArgs('blocks').returns(deffered.promise);
const promise = forgingService.getForgedBlocks();
@@ -51,7 +51,7 @@ describe('Factory: forgingService', () => {
});
describe('getForgedStats(startMoment)', () => {
- it('returns $peers.sendRequestPromise(\'delegates/forging/getForgedByAccount\');', () => {
+ it('returns Peers.sendRequestPromise(\'delegates/forging/getForgedByAccount\');', () => {
mock.expects('sendRequestPromise').withArgs('delegates/forging/getForgedByAccount').returns(deffered.promise);
const promise = forgingService.getForgedStats();
diff --git a/src/test/services/peers/peers.spec.js b/src/test/services/api/peers.spec.js
similarity index 59%
rename from src/test/services/peers/peers.spec.js
rename to src/test/services/api/peers.spec.js
index 7ca782b6e..8af407e72 100644
--- a/src/test/services/peers/peers.spec.js
+++ b/src/test/services/api/peers.spec.js
@@ -5,30 +5,30 @@ const sinonChai = require('sinon-chai');
const expect = chai.expect;
chai.use(sinonChai);
-describe('Factory: $peers', () => {
- let $peers;
+describe('Factory: Peers', () => {
+ let Peers;
let $q;
let $rootScope;
beforeEach(angular.mock.module('app'));
- beforeEach(inject((_$peers_, _$q_, _$rootScope_) => {
- $peers = _$peers_;
+ beforeEach(inject((_Peers_, _$q_, _$rootScope_) => {
+ Peers = _Peers_;
$q = _$q_;
$rootScope = _$rootScope_;
}));
describe('setActive(account)', () => {
- it('sets $peers.active to a random active official peer', () => {
+ it('sets Peers.active to a random active official peer', () => {
const account = {
network: {
address: 'http://localhost:8000',
},
};
- expect($peers.active).to.equal(undefined);
- $peers.setActive(account);
- expect($peers.active).not.to.equal(undefined);
- expect($peers.active.currentPeer).not.to.equal(undefined);
+ expect(Peers.active).to.equal(undefined);
+ Peers.setActive(account);
+ expect(Peers.active).not.to.equal(undefined);
+ expect(Peers.active.currentPeer).not.to.equal(undefined);
});
});
@@ -38,9 +38,9 @@ describe('Factory: $peers', () => {
beforeEach(() => {
deffered = $q.defer();
- mock = sinon.mock($peers);
- mock.expects('getStatusPromise').returns(deffered.promise);
- $peers.active = {};
+ mock = sinon.mock(Peers);
+ mock.expects('getStatus').returns(deffered.promise);
+ Peers.active = {};
});
afterEach(() => {
@@ -49,17 +49,17 @@ describe('Factory: $peers', () => {
});
it('checks active peer status and if that succeeds then sets this.online = true', () => {
- $peers.check();
+ Peers.check();
deffered.resolve();
$rootScope.$apply();
- expect($peers.online).to.equal(true);
+ expect(Peers.online).to.equal(true);
});
it('checks active peer status and if that fails then sets this.online = false', () => {
- $peers.check();
+ Peers.check();
deffered.reject();
$rootScope.$apply();
- expect($peers.online).to.equal(false);
+ expect(Peers.online).to.equal(false);
});
});
});
diff --git a/src/test/test.js b/src/test/test.js
index bae1e8654..d2f3a458b 100644
--- a/src/test/test.js
+++ b/src/test/test.js
@@ -7,8 +7,8 @@ require('./components/login/passphrase.spec');
require('./components/main/main.spec');
require('./components/main/setSecondPassDirective.spec');
require('./components/main/setSecondPassService.spec');
-require('./components/send/send.spec');
-require('./components/send/sendModalDirective.spec');
+require('./components/transfer/transfer.spec');
+require('./components/transfer/transferModalDirective.spec');
require('./components/top/top.spec');
require('./components/timestamp/timestamp.spec');
require('./components/transactions/transactions.spec');
@@ -16,12 +16,15 @@ require('./components/sign-verify/sign-message.spec');
require('./components/sign-verify/verify-message.spec');
require('./components/delegate-registration/delegateRegistration.spec.js');
-require('./services/account.spec');
-require('./services/peers/peers.spec');
require('./services/passphrase.spec');
require('./services/sign-verify.spec');
require('./services/lsk.spec');
-require('./services/delegateService.spec');
-require('./services/forgingService.spec');
+require('./services/api/peers.spec');
+require('./services/api/delegateApi.spec');
+require('./services/api/forgingApi.spec');
+require('./services/api/accountApi.spec');
+require('./services/account.spec');
+
+require('./run.spec');
require('./util/animateOnChange/animateOnChange.spec');