Permalink
Browse files

fix(validation): add fee amount validation on client

  • Loading branch information...
1 parent dca691a commit a11c7afc3bbb796b921423e7362b057f03fe0e1e @beregovoy68 beregovoy68 committed Nov 28, 2016
Showing with 36 additions and 4 deletions.
  1. +36 −4 src/js/tokens/token.create.controller.js
@@ -7,11 +7,21 @@
var TOKEN_DECIMALS_MAX = 8;
var FIXED_ISSUE_FEE = new Money(1, Currency.WAV);
- function TokenCreateController(constants, applicationContext, assetService, dialogService, apiService,
- notificationService, formattingService) {
+ function TokenCreateController($scope, $interval, constants, applicationContext, assetService, dialogService,
+ apiService, notificationService, formattingService) {
+ var refreshPromise;
+ var refreshDelay = 15 * 1000;
var transaction;
var ctrl = this;
+ $scope.$on('$destroy', function () {
+ if (angular.isDefined(refreshPromise)) {
+ $interval.cancel(refreshPromise);
+ refreshPromise = undefined;
+ }
+ });
+
+ ctrl.wavesBalance = new Money(0, Currency.WAV);
ctrl.issuanceValidationOptions = {
rules: {
assetName: {
@@ -64,6 +74,7 @@
ctrl.broadcastIssueTransaction = broadcastIssueTransaction;
ctrl.assetIssueConfirmation = assetIssueConfirmation;
+ loadDataFromBackend();
resetIssueAssetForm();
function assetIssueConfirmation(form, event) {
@@ -72,6 +83,12 @@
if (!form.validate())
return;
+ if (ctrl.asset.fee.greaterThan(ctrl.wavesBalance)) {
+ notificationService.error('Not enough funds for the issue transaction fee');
+
+ return;
+ }
+
var asset = {
name: ctrl.asset.name,
description: ctrl.asset.description,
@@ -135,10 +152,25 @@
ctrl.asset.decimalPlaces = '0';
ctrl.asset.reissuable = false;
}
+
+ function loadDataFromBackend() {
+ refreshBalance();
+
+ refreshPromise = $interval(function() {
+ refreshBalance();
+ }, refreshDelay);
+ }
+
+ function refreshBalance() {
+ apiService.address.balance(applicationContext.account.address)
+ .then(function (response) {
+ ctrl.wavesBalance = Money.fromCoins(response.balance, Currency.WAV);
+ });
+ }
}
- TokenCreateController.$inject = ['constants.ui', 'applicationContext', 'assetService', 'dialogService',
- 'apiService', 'notificationService', 'formattingService'];
+ TokenCreateController.$inject = ['$scope', '$interval', 'constants.ui', 'applicationContext', 'assetService',
+ 'dialogService', 'apiService', 'notificationService', 'formattingService'];
angular
.module('app.tokens')

0 comments on commit a11c7af

Please sign in to comment.