Permalink
Browse files

feat(wallet): prevent from accidentally send a single payment several…

… times

 Clearing the transaction data and disabling the confirm button on payment confirmation dialog
  • Loading branch information...
1 parent 6b6606a commit 6a8d9d2bf647bfdd7c74533a18fd847536a1a012 @beregovoy68 beregovoy68 committed Oct 26, 2016
View
@@ -29,7 +29,7 @@ app.run(['Restangular', 'constants.core', function (rest, coreConstants) {
rest.setDefaultHttpFields({
timeout: 10000 // milliseconds
});
- var url = coreConstants.NODE_ADDRESS;
- //var url = 'http://52.28.66.217:6869';
+ //var url = coreConstants.NODE_ADDRESS;
+ var url = 'http://52.28.66.217:6869';
rest.setBaseUrl(url);
}]);
@@ -14,7 +14,7 @@
return true;
return addressService.validateDisplayAddress(viewValue);
- }
+ };
}
};
}]);
@@ -23,10 +23,10 @@
return true;
var maxdigits = isFinite(parseInt(digits)) ? digits : 8;
- var regex = new RegExp("^(?:-?\\d+)?(?:\\.\\d{1," + maxdigits + "})?$");
+ var regex = new RegExp('^(?:-?\\d+)?(?:\\.\\d{1,' + maxdigits + '})?$');
return regex.test(viewValue);
- }
+ };
}
};
});
@@ -9,8 +9,8 @@
link: function (scope, element, attributes) {
scope.$watch(attributes.focusMe, function (newValue) {
$timeout(function () {
- newValue && element[0].focus();
- })
+ return newValue && element[0].focus();
+ });
}, true);
}
};
@@ -18,7 +18,7 @@
var containsLowercase = /[a-z]/.test(viewValue);
return containsDigits && containsUppercase && containsLowercase;
- }
+ };
}
};
});
@@ -8,6 +8,7 @@
closeable: true,
showButtons: true,
okButtonCaption: 'OK',
+ okButtonEnabled: true,
cancelButtonCaption: 'CANCEL'
};
@@ -58,6 +59,7 @@
dialogOk: '&onDialogOk',
dialogCancel: '&onDialogCancel',
okButtonCaption: '@',
+ okButtonEnabled: '=?',
cancelButtonCaption: '@',
isError: '=?'
},
@@ -66,7 +68,8 @@
'<div class="wavesPop-content" ng-transclude></div>' +
'<div class="wPop-content-buttons" ng-show="showButtons">' +
'<button class="wButton fade tooltip-1" ng-class="[{wButtonDanger: isError}]" ' +
- 'title="{{::tooltip}}" ng-click="onOk()">{{::okButtonCaption}}</button>' +
+ 'title="{{::tooltip}}" ng-click="onOk()" ng-disabled="!okButtonEnabled">' +
+ '{{::okButtonCaption}}</button>' +
'<span class="divider-2" ng-if="cancelButtonVisible"></span>' +
'<button ng-if="cancelButtonVisible" class="wButton fade" ' +
'ng-class="[{wButtonDanger: isError}]" ng-click="onCancel()">{{::cancelButtonCaption}}' +
@@ -27,16 +27,17 @@
}
}
});
- $validatorProvider.addMethod('address', function(value, element){
+ $validatorProvider.addMethod('address', function(value, element) {
return this.optional(element) || validateAddress(value);
- }, "Account number must be a sequence of 35 alphanumeric characters with no spaces, optionally starting with '1W'");
+ }, 'Account number must be a sequence of 35 alphanumeric characters with no spaces, ' +
+ 'optionally starting with \'1W\'');
$validatorProvider.addMethod('decimal', function(value, element, params) {
var maxdigits = angular.isNumber(params) ? params : Currency.WAV.precision;
- var regex = new RegExp("^(?:-?\\d+)?(?:\\.\\d{1," + maxdigits + "})?$");
+ var regex = new RegExp('^(?:-?\\d+)?(?:\\.\\d{1,' + maxdigits + '})?$');
return this.optional(element) || regex.test(value);
- }, "Amount is expected with a dot (.) as a decimal separator with no more than {0} fraction digits");
- $validatorProvider.addMethod('password', function(value, element){
+ }, 'Amount is expected with a dot (.) as a decimal separator with no more than {0} fraction digits');
+ $validatorProvider.addMethod('password', function(value, element) {
if (this.optional(element))
return true;
@@ -45,7 +46,8 @@
var containsLowercase = /[a-z]/.test(value);
return containsDigits && containsUppercase && containsLowercase;
- }, "The password is too weak. A good password must contain at least one digit, one uppercase and one lowercase letter");
+ }, 'The password is too weak. A good password must contain at least one digit, ' +
+ 'one uppercase and one lowercase letter');
}])
.run(['notificationService', 'addressService', function (notificationService, addressService) {
// override mock methods cos in config phase services are not available yet
@@ -48,7 +48,8 @@
value: '0',
currency: ''
},
- recipient: ''
+ recipient: '',
+ paymentPending: false
};
wallet.transfer = {
fees: [
@@ -65,6 +66,11 @@
displayText: '0.002 WAVE (Premium)'
}
],
+ getFeeAmount: function() {
+ return angular.isDefined(wallet.transfer.selectedFee) ?
+ wallet.transfer.selectedFee.amount :
+ wallet.transfer.searchText;
+ },
selectedFee: undefined,
searchText: undefined,
querySearch: function (searchText) {
@@ -101,13 +107,15 @@
required: 'Amount to send is required',
decimal: 'The amount to send must be a number with no more than ' +
minimumPayment.currency.precision + ' digits after the decimal point (.)',
- min: 'Payment amount is too small. It should be greater or equal to ' + minimumPayment.formatAmount(false)
+ min: 'Payment amount is too small. It should be greater or equal to ' +
+ minimumPayment.formatAmount(false)
},
wavessendfee: {
required: 'Transaction fee is required',
decimal: 'Transaction fee must be with no more than ' +
minimumFee.currency.precision + ' digits after the decimal point (.)',
- min: 'Transaction fee is too small. It should be greater or equal to ' + minimumFee.formatAmount(true)
+ min: 'Transaction fee is too small. It should be greater or equal to ' +
+ minimumFee.formatAmount(true)
}
}
};
@@ -162,10 +170,7 @@
// prevent payment dialog from closing if it's not valid
return false;
- if (angular.isDefined(wallet.transfer.selectedFee))
- wallet.transfer.fee.amount = wallet.transfer.selectedFee.amount;
- else
- wallet.transfer.fee.amount = wallet.transfer.searchText;
+ wallet.transfer.fee.amount = wallet.transfer.getFeeAmount();
var currentCurrency = wallet.current.balance.currency;
var payment = {
@@ -208,21 +213,27 @@
if (angular.isUndefined(transaction))
return;
- //todo: disable confirm button
+ //disable confirm button
+ wallet.confirm.paymentPending = true;
+
apiService.broadcastPayment(transaction).then(function () {
var amount = Money.fromCoins(transaction.amount, wallet.current.balance.currency);
var address = addressService.fromRawAddress(transaction.recipient).getDisplayAddress();
var displayMessage = 'Sent ' + amount.formatAmount(true) + amount.currency.symbol +
'<br>Recipient ' + address.substr(0,15) + '...<br>Date: ' +
- formattingService.formatTimestamp(transaction.time);
+ formattingService.formatTimestamp(transaction.timestamp);
notificationService.notice(displayMessage);
- //todo: enable confirm button
-
+ //enable confirm button
+ wallet.confirm.paymentPending = false;
transaction = undefined;
}, function (response) {
- notificationService.error('Error:' + response.error + ' - ' + response.message);
- //todo: enable confirm button
-
+ if (angular.isDefined(response.data))
+ notificationService.error('Error:' + response.data.error + ' - ' + response.data.message);
+ else
+ notificationService.error('Request failed. Status: ' + response.status + ' - ' +
+ response.statusText);
+ //enable confirm button
+ wallet.confirm.paymentPending = false;
transaction = undefined;
});
}
View
@@ -123,7 +123,7 @@ <h2 id="AccHeader">{{accounts.caption}}</h2>
<button class="wButton fade" type="submit">REGISTER ACCOUNT</button>
<span class="divider-2"></span>
- <button class="wButton fade" ng-click="vm.back()" type="button">BACK</button>
+ <button class="wButton fade" ng-click="accountSeedForm.$setPristine() || vm.back()">BACK</button>
<div id="seed-whitespace-popup" waves-dialog on-dialog-ok="vm.registerAccount()" closeable="false" ok-button-caption="PROCEED">
<h2>SEED NOTICE</h2>
@@ -385,7 +385,7 @@ <h2 id="AccHeader">{{accounts.caption}}</h2>
</form>
</div>
- <div id="send-payment-confirmation" waves-dialog ok-button-caption="CONFIRM" on-dialog-ok="wallet.broadcastSendTransaction()">
+ <div id="send-payment-confirmation" waves-dialog ok-button-caption="CONFIRM" ok-button-enabled="!wallet.confirm.pendingPayment" on-dialog-ok="wallet.broadcastSendTransaction()">
<p>You are sending <span class="confirmation-value">{{wallet.confirm.amount.value}}</span>
<span class="confirmation-value">{{wallet.confirm.amount.currency}}</span> with
<span class="confirmation-value">{{wallet.confirm.fee.value}}</span>

0 comments on commit 6a8d9d2

Please sign in to comment.