diff --git a/src/app/components/delegates/delegates.js b/src/app/components/delegates/delegates.js
index 1f29a870c..6ef30f4d4 100644
--- a/src/app/components/delegates/delegates.js
+++ b/src/app/components/delegates/delegates.js
@@ -10,14 +10,14 @@ app.component('delegates', {
},
controller: class delegates {
constructor($scope, $rootScope, $peers, $mdDialog, $mdMedia,
- $mdToast, $timeout, delegateService, Account) {
+ dialog, $timeout, delegateService, Account) {
this.$scope = $scope;
this.$rootScope = $rootScope;
this.$peers = $peers;
this.delegateService = delegateService;
this.$mdDialog = $mdDialog;
this.$mdMedia = $mdMedia;
- this.$mdToast = $mdToast;
+ this.dialog = dialog;
this.$timeout = $timeout;
this.account = Account;
@@ -208,10 +208,7 @@ app.component('delegates', {
this.usernameInput = '';
this.openVoteDialog();
} else {
- const toast = this.$mdToast.simple();
- toast.toastClass('lsk-toast-error');
- toast.textContent('No delegate usernames could be parsed from the input');
- this.$mdToast.show(toast);
+ this.dialog.errorToast('No delegate usernames could be parsed from the input');
}
}
@@ -250,24 +247,19 @@ app.component('delegates', {
this.$mdDialog.show({
controllerAs: '$ctrl',
controller: class voteDialog {
- constructor($scope, account, passphrase, voteList, unvoteList) {
+ constructor($scope, voteList, unvoteList) {
this.$scope = $scope;
- this.$scope.account = account;
- this.$scope.passphrase = passphrase;
this.$scope.voteList = voteList;
this.$scope.unvoteList = unvoteList;
}
},
template:
'' +
- '' +
+ '' +
'' +
'',
fullscreen: (this.$mdMedia('sm') || this.$mdMedia('xs')) && this.$scope.customFullscreen,
locals: {
- account: this.account.get(),
- passphrase: this.account.get().passphrase,
voteList: this.voteList,
unvoteList: this.unvoteList,
},
diff --git a/src/app/components/delegates/delegates.pug b/src/app/components/delegates/delegates.pug
index 37ba74e9d..475d9e27a 100644
--- a/src/app/components/delegates/delegates.pug
+++ b/src/app/components/delegates/delegates.pug
@@ -10,7 +10,7 @@ div.offline-hide
span.pull-right
md-button(ng-click='$ctrl.parseVoteListFromInput("voteList")', ng-disabled='$ctrl.pendingRequests || !$ctrl.usernameInput')
span Add to vote list
- md-button(ng-click='$ctrl.parseUnvoteListFromInput(")', ng-disabled='$ctrl.pendingRequests || !$ctrl.usernameInput')
+ md-button(ng-click='$ctrl.parseUnvoteListFromInput("unvoteList")', ng-disabled='$ctrl.pendingRequests || !$ctrl.usernameInput')
span Add to unvote list
md-progress-linear(md-mode='indeterminate', ng-show='$ctrl.pendingRequests')
md-card(flex-gt-xs=100)
diff --git a/src/app/components/delegates/vote.js b/src/app/components/delegates/vote.js
index e2f687b2d..ec1a0971c 100644
--- a/src/app/components/delegates/vote.js
+++ b/src/app/components/delegates/vote.js
@@ -7,9 +7,9 @@ app.component('vote', {
unvoteList: '=',
},
controller: class vote {
- constructor($scope, $mdDialog, $mdToast, delegateService, $rootScope, Account) {
+ constructor($scope, $mdDialog, dialog, delegateService, $rootScope, Account) {
this.$mdDialog = $mdDialog;
- this.$mdToast = $mdToast;
+ this.dialog = dialog;
this.delegateService = delegateService;
this.$rootScope = $rootScope;
this.account = Account;
@@ -18,7 +18,7 @@ app.component('vote', {
this.votedList = [];
this.delegateService.listAccountDelegates({
- address: this.account.address,
+ address: this.account.get().address,
}).then((data) => {
this.votedList = data.delegates || [];
this.votedList.forEach((delegate) => {
@@ -37,15 +37,9 @@ app.component('vote', {
unvoteList: this.unvoteList,
}).then(() => {
this.$mdDialog.hide(this.voteList, this.unvoteList);
- const toast = this.$mdToast.simple();
- toast.toastClass('lsk-toast-success');
- toast.textContent('Voting succesfull');
- this.$mdToast.show(toast);
+ this.dialog.successToast('Voting successful');
}).catch((response) => {
- const toast = this.$mdToast.simple();
- toast.toastClass('lsk-toast-error');
- toast.textContent(response.message || 'Voting failed');
- this.$mdToast.show(toast);
+ this.dialog.errorToast(response.message || 'Voting failed');
}).finally(() => {
this.votingInProgress = false;
});
diff --git a/src/app/components/main/main.js b/src/app/components/main/main.js
index 573d64126..17923608c 100644
--- a/src/app/components/main/main.js
+++ b/src/app/components/main/main.js
@@ -7,13 +7,13 @@ app.component('main', {
controllerAs: '$ctrl',
controller: class main {
constructor($scope, $rootScope, $timeout, $q, $state, $peers,
- error, SendModal, Account) {
+ dialog, SendModal, Account) {
this.$scope = $scope;
this.$rootScope = $rootScope;
this.$timeout = $timeout;
this.$q = $q;
this.$peers = $peers;
- this.error = error;
+ this.dialog = dialog;
this.sendModal = SendModal;
this.$state = $state;
this.account = Account;
@@ -43,7 +43,7 @@ app.component('main', {
if (attempts < 10) {
this.$timeout(() => this.init(attempts + 1), 1000);
} else {
- this.error.dialog({ text: 'No peer connection' });
+ this.dialog.errorAlert({ text: 'No peer connection' });
this.$rootScope.logout();
}
});
diff --git a/src/app/components/main/setSecondPassDirective.js b/src/app/components/main/setSecondPassDirective.js
index 39001cc5f..777345110 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, $peers, $rootScope, success, error) => {
+app.directive('setSecondPass', (setSecondPass, $peers, $rootScope, dialog) => {
/* eslint no-param-reassign: ["error", { "props": false }] */
const SetSecondPassLink = function (scope, element, attrs) {
element.bind('click', () => {
@@ -10,7 +10,7 @@ app.directive('setSecondPass', (setSecondPass, $peers, $rootScope, success, erro
scope.passConfirmSubmit = (secondsecret) => {
$peers.active.setSignature(secondsecret, attrs.publicKey, attrs.passphrase)
.then(() => {
- success.dialog('Your second passphrase was successfully registered.');
+ dialog.successAlert('Your second passphrase was successfully registered.');
})
.catch((err) => {
let text = '';
@@ -21,7 +21,7 @@ app.directive('setSecondPass', (setSecondPass, $peers, $rootScope, success, erro
} else {
text = 'An error occurred while registering your second passphrase. Please try again.';
}
- error.dialog({ text });
+ dialog.errorAlert({ text });
});
};
diff --git a/src/app/components/send/send.js b/src/app/components/send/send.js
index a617c991c..8446e6080 100644
--- a/src/app/components/send/send.js
+++ b/src/app/components/send/send.js
@@ -10,11 +10,10 @@ app.component('send', {
transferAmount: '<',
},
controller: class send {
- constructor($scope, $peers, lsk, success, error, $mdDialog, $q, $rootScope, Account) {
+ constructor($scope, $peers, lsk, dialog, $mdDialog, $q, $rootScope, Account) {
this.$scope = $scope;
this.$peers = $peers;
- this.success = success;
- this.error = error;
+ this.dialog = dialog;
this.$mdDialog = $mdDialog;
this.$q = $q;
this.$rootScope = $rootScope;
@@ -97,13 +96,13 @@ app.component('send', {
fee: 10000000,
};
this.$rootScope.$broadcast('transaction-sent', transaction);
- return this.success.dialog({ text: `${this.amount.value} sent to ${this.recipient.value}` })
+ return this.dialog.successAlert({ text: `${this.amount.value} sent to ${this.recipient.value}` })
.then(() => {
this.reset();
});
},
(res) => {
- this.error.dialog({ 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 sending the transaction.' });
},
)
.finally(() => {
diff --git a/src/app/lisk-nano.js b/src/app/lisk-nano.js
index 02ccc8cc4..bd06ec619 100644
--- a/src/app/lisk-nano.js
+++ b/src/app/lisk-nano.js
@@ -23,8 +23,7 @@ import './components/sign-verify/verify-message';
import './services/peers/peers';
import './services/lsk';
-import './services/success';
-import './services/error';
+import './services/dialog';
import './services/passphrase';
import './services/sign-verify';
import './services/account';
diff --git a/src/app/services/dialog.js b/src/app/services/dialog.js
new file mode 100644
index 000000000..6f85e5ee3
--- /dev/null
+++ b/src/app/services/dialog.js
@@ -0,0 +1,50 @@
+app.factory('dialog', ($mdDialog, $mdToast, $mdMedia) => ({
+
+ errorToast(text) {
+ return this.toast({ success: false, text });
+ },
+
+ successToast(text) {
+ return this.toast({ success: true, text });
+ },
+
+ toast({ success = false, text, toastClass }) {
+ toastClass = toastClass || (success ? 'lsk-toast-success' : 'lsk-toast-error');
+ $mdToast.show(
+ $mdToast.simple()
+ .textContent(text)
+ .toastClass(toastClass)
+ .position('bottom right'),
+ );
+ },
+
+ errorAlert({ title, text, button }) {
+ return this.alert({ success: false, title, text, button });
+ },
+
+ successAlert({ title, text, button }) {
+ return this.alert({ success: true, title, text, button });
+ },
+
+ alert({ title = '', success = false, text, button = 'OK' }) {
+ title = title || (success ? 'Success' : 'Error');
+ return $mdDialog.show(
+ $mdDialog.alert()
+ .title(title)
+ .textContent(text)
+ .ok(button),
+ );
+ },
+
+ modal(options) {
+ options.fullscreen = ($mdMedia('sm') || $mdMedia('xs'));
+ if (options.template) {
+ options.template =
+ `${
+ options.template
+ }`;
+ }
+ return $mdDialog.show(options);
+ },
+}));
+
diff --git a/src/app/services/error.js b/src/app/services/error.js
deleted file mode 100644
index e4dfcdabf..000000000
--- a/src/app/services/error.js
+++ /dev/null
@@ -1,17 +0,0 @@
-app.factory('error', ($mdDialog, $mdToast) => ({
- toast({ text }) {
- return $mdToast.show(
- $mdToast.simple()
- .textContent(text)
- .position('bottom right'),
- );
- },
- dialog({ title = 'Error', text, button = 'OK' }) {
- return $mdDialog.show(
- $mdDialog.alert()
- .title(title)
- .textContent(text)
- .ok(button),
- );
- },
-}));
diff --git a/src/app/services/success.js b/src/app/services/success.js
deleted file mode 100644
index 28b0317a6..000000000
--- a/src/app/services/success.js
+++ /dev/null
@@ -1,17 +0,0 @@
-app.factory('success', ($mdDialog, $mdToast) => ({
- toast({ text }) {
- $mdToast.show(
- $mdToast.simple()
- .textContent(text)
- .position('bottom right'),
- );
- },
- dialog({ title = 'Success', text, button = 'OK' }) {
- return $mdDialog.show(
- $mdDialog.alert()
- .title(title)
- .textContent(text)
- .ok(button),
- );
- },
-}));
diff --git a/src/test/components/delegates/delegates.spec.js b/src/test/components/delegates/delegates.spec.js
index fcd8d9ebf..3f1638ac1 100644
--- a/src/test/components/delegates/delegates.spec.js
+++ b/src/test/components/delegates/delegates.spec.js
@@ -291,7 +291,7 @@ describe('delegates component controller', () => {
const username = 'invalid_name';
const deffered = $q.defer();
delegateServiceMock.expects('getDelegate').withArgs(username).returns(deffered.promise);
- const toastSpy = sinon.spy(controller.$mdToast, 'show');
+ const toastSpy = sinon.spy(controller.dialog, 'errorToast');
const dialogSpy = sinon.spy(controller, 'openVoteDialog');
controller.usernameInput = username;
controller.voteList = [];
diff --git a/src/test/components/delegates/vote.spec.js b/src/test/components/delegates/vote.spec.js
index f0936d475..8ec857952 100644
--- a/src/test/components/delegates/vote.spec.js
+++ b/src/test/components/delegates/vote.spec.js
@@ -97,27 +97,28 @@ describe('Vote component controller', () => {
describe('vote()', () => {
let deffered;
- let mdToastMock;
+ let dilaogServiceMock;
beforeEach(() => {
deffered = $q.defer();
delegateServiceMock.expects('vote').returns(deffered.promise);
- mdToastMock = sinon.mock(controller.$mdToast);
- mdToastMock.expects('show');
+ dilaogServiceMock = sinon.mock(controller.dialog);
});
afterEach(() => {
- mdToastMock.verify();
+ dilaogServiceMock.verify();
delegateServiceMock.verify();
});
- it('shows an error $mdToast if request fails', () => {
+ it('shows an error toast if request fails', () => {
+ dilaogServiceMock.expects('errorToast');
controller.vote();
deffered.reject({ success: false });
$scope.$apply();
});
- it('shows a success $mdToast if request succeeds', () => {
+ it('shows a success toast if request succeeds', () => {
+ dilaogServiceMock.expects('successToast');
controller.vote();
deffered.resolve({ success: true });
$scope.$apply();
diff --git a/src/test/components/main/main.spec.js b/src/test/components/main/main.spec.js
index f893f6afa..734702948 100644
--- a/src/test/components/main/main.spec.js
+++ b/src/test/components/main/main.spec.js
@@ -87,8 +87,8 @@ describe('main component controller', () => {
expect(spy).to.have.been.calledWith();
});
- it('calls this.update() and if that fails and attempts >= 10, then show error dialog', () => {
- const spy = sinon.spy(controller.error, 'dialog');
+ it('calls this.update() and if that fails and attempts >= 10, then show error alert dialog', () => {
+ const spy = sinon.spy(controller.dialog, 'errorAlert');
controller.init(10);
deffered.reject();
diff --git a/src/test/components/main/setSecondPassDirective.spec.js b/src/test/components/main/setSecondPassDirective.spec.js
index 5f2697567..8819d3f6b 100644
--- a/src/test/components/main/setSecondPassDirective.spec.js
+++ b/src/test/components/main/setSecondPassDirective.spec.js
@@ -13,8 +13,7 @@ describe('setSecondPass Directive', () => {
let $peers;
let setSecondPass;
let $q;
- let success;
- let error;
+ let dialog;
beforeEach(() => {
// Load the myApp module, which contains the directive
@@ -22,15 +21,14 @@ describe('setSecondPass Directive', () => {
// Store references to $rootScope and $compile
// so they are available to all tests in this describe block
- inject((_$compile_, _$rootScope_, _setSecondPass_, _$peers_, _$q_, _success_, _error_) => {
+ inject((_$compile_, _$rootScope_, _setSecondPass_, _$peers_, _$q_, _dialog_) => {
// The injector unwraps the underscores (_) from around the parameter names when matching
$compile = _$compile_;
$rootScope = _$rootScope_;
setSecondPass = _setSecondPass_;
$peers = _$peers_;
$q = _$q_;
- success = _success_;
- error = _error_;
+ dialog = _dialog_;
$scope = $rootScope.$new();
});
@@ -46,7 +44,7 @@ describe('setSecondPass Directive', () => {
const deffered = $q.defer();
mock.expects('setSignature').returns(deffered.promise);
- const spy = sinon.spy(success, 'dialog');
+ const spy = sinon.spy(dialog, 'successAlert');
$scope.$broadcast('onAfterSignup', {
passphrase: 'TEST_VALUE',
@@ -75,7 +73,7 @@ describe('setSecondPass Directive', () => {
const deffered = $q.defer();
mock.expects('setSignature').returns(deffered.promise);
- const spy = sinon.spy(success, 'dialog');
+ const spy = sinon.spy(dialog, 'successAlert');
$scope.passConfirmSubmit();
deffered.resolve({});
@@ -90,7 +88,7 @@ describe('setSecondPass Directive', () => {
const deffered = $q.defer();
mock.expects('setSignature').returns(deffered.promise);
- const spy = sinon.spy(error, 'dialog');
+ const spy = sinon.spy(dialog, 'errorAlert');
$scope.passConfirmSubmit();
deffered.reject({ message: 'Missing sender second signature' });
@@ -112,7 +110,7 @@ describe('setSecondPass Directive', () => {
const deffered = $q.defer();
mock.expects('setSignature').returns(deffered.promise);
- const spy = sinon.spy(error, 'dialog');
+ const spy = sinon.spy(dialog, 'errorAlert');
$scope.passConfirmSubmit();
deffered.reject({ message: 'Missing sender second signature' });
@@ -126,7 +124,7 @@ describe('setSecondPass Directive', () => {
const deffered = $q.defer();
mock.expects('setSignature').returns(deffered.promise);
- const spy = sinon.spy(error, 'dialog');
+ const spy = sinon.spy(dialog, 'errorAlert');
$scope.passConfirmSubmit();
deffered.reject({ message: 'Other messages' });
diff --git a/src/test/components/send/send.spec.js b/src/test/components/send/send.spec.js
index 2825c9089..eab5e7918 100644
--- a/src/test/components/send/send.spec.js
+++ b/src/test/components/send/send.spec.js
@@ -61,10 +61,10 @@ describe('Send component', () => {
describe('send transaction', () => {
let $q;
let $peers;
- let success;
+ let dialog;
- beforeEach(inject((_success_, _$q_, _$peers_) => {
- success = _success_;
+ beforeEach(inject((_dialog_, _$q_, _$peers_) => {
+ dialog = _dialog_;
$q = _$q_;
$peers = _$peers_;
}));
@@ -78,7 +78,7 @@ describe('Send component', () => {
const deffered = $q.defer();
mock.expects('sendLSKPromise').returns(deffered.promise);
- const spy = sinon.spy(success, 'dialog');
+ const spy = sinon.spy(dialog, 'successAlert');
element.find('form input[name="amount"]').val(AMOUNT).trigger('input');
element.find('form input[name="recipient"]').val(RECIPIENT_ADDRESS).trigger('input');
@@ -100,7 +100,7 @@ describe('Send component', () => {
const deffered = $q.defer();
mock.expects('sendLSKPromise').returns(deffered.promise);
- const spy = sinon.spy(success, 'dialog');
+ const spy = sinon.spy(dialog, 'successAlert');
element.find('md-menu-item button').click();
element.find('form input[name="recipient"]').val(RECIPIENT_ADDRESS).trigger('input');
@@ -182,14 +182,14 @@ describe('send component controller', () => {
expect(spy).to.have.been.calledWith();
});
- it('calls this.$peers.active.sendLSKPromise() and success.dialog on success', () => {
+ it('calls this.$peers.active.sendLSKPromise() and dialog.successAlert on success', () => {
controller.$peers = { active: { sendLSKPromise() {} } };
const mock = sinon.mock(controller.$peers.active);
const deffered = $q.defer();
mock.expects('sendLSKPromise').returns(deffered.promise);
controller.go();
- const spy = sinon.spy(controller.success, 'dialog');
+ const spy = sinon.spy(controller.dialog, 'successAlert');
deffered.resolve({});
$scope.$apply();
expect(spy).to.have.been.calledWith({
@@ -204,7 +204,7 @@ describe('send component controller', () => {
mock.expects('sendLSKPromise').returns(deffered.promise);
controller.go();
- const spy = sinon.spy(controller.error, 'dialog');
+ const spy = sinon.spy(controller.dialog, 'errorAlert');
const response = {
message: 'error',
};