From 0fe477863785e4fcacc99aa0a2bd30ae69359118 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Wed, 3 Sep 2014 16:24:25 -0300 Subject: [PATCH] settings: fix references to unitName --- config.js | 1 + js/controllers/send.js | 32 +++++++------ js/filters.js | 73 +++++++++++++++--------------- views/addresses.html | 48 ++++++++++---------- views/includes/sidebar-mobile.html | 4 +- views/includes/sidebar.html | 4 +- views/includes/transaction.html | 31 ++++++------- views/modals/qr-address.html | 2 +- views/send.html | 8 ++-- views/transactions.html | 24 +++++----- 10 files changed, 113 insertions(+), 114 deletions(-) diff --git a/config.js b/config.js index f9ca1170d..ab1beb0a8 100644 --- a/config.js +++ b/config.js @@ -30,6 +30,7 @@ var defaultConfig = { settings: { unitName: 'bits', unitToSatoshi: 100, + unitDecimals: 2, alternativeName: 'US Dollar', alternativeIsoCode: 'USD', } diff --git a/js/controllers/send.js b/js/controllers/send.js index 788217edf..01e547ada 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -5,13 +5,13 @@ angular.module('copayApp.controllers').controller('SendController', function($scope, $rootScope, $window, $timeout, $anchorScroll, $modal, isMobile, notification, controllerUtils, rateService) { $scope.title = 'Send'; $scope.loading = false; - var satToUnit = 1 / config.unitToSatoshi; + var satToUnit = 1 / $rootScope.wallet.settings.unitToSatoshi; $scope.defaultFee = bitcore.TransactionBuilder.FEE_PER_1000B_SAT * satToUnit; - $scope.unitToBtc = config.unitToSatoshi / bitcore.util.COIN; - $scope.unitToSatoshi = config.unitToSatoshi; + $scope.unitToBtc = $rootScope.wallet.settings.unitToSatoshi / bitcore.util.COIN; + $scope.unitToSatoshi = $rootScope.wallet.settings.unitToSatoshi; - $scope.alternativeName = config.alternativeName; - $scope.alternativeIsoCode = config.alternativeIsoCode; + $scope.alternativeName = $rootScope.wallet.settings.alternativeName; + $scope.alternativeIsoCode = $rootScope.wallet.settings.alternativeIsoCode; $scope.isRateAvailable = false; $scope.rateService = rateService; @@ -36,7 +36,7 @@ angular.module('copayApp.controllers').controller('SendController', this._alternative = newValue; if (typeof(newValue) === 'number' && $scope.isRateAvailable) { this._amount = parseFloat( - (rateService.fromFiat(newValue, config.alternativeIsoCode) * satToUnit).toFixed(config.unitDecimals), 10); + (rateService.fromFiat(newValue, $rootScope.wallet.settings.alternativeIsoCode) * satToUnit).toFixed($rootScope.wallet.settings.unitDecimals), 10); } else { this._amount = 0; } @@ -53,7 +53,7 @@ angular.module('copayApp.controllers').controller('SendController', this._amount = newValue; if (typeof(newValue) === 'number' && $scope.isRateAvailable) { this._alternative = parseFloat( - (rateService.toFiat(newValue * config.unitToSatoshi, config.alternativeIsoCode)).toFixed(2), 10); + (rateService.toFiat(newValue * $rootScope.wallet.settings.unitToSatoshi, $rootScope.wallet.settings.alternativeIsoCode)).toFixed(2), 10); } else { this._alternative = 0; } @@ -91,7 +91,7 @@ angular.module('copayApp.controllers').controller('SendController', if ($rootScope.pendingPayment) { var pp = $rootScope.pendingPayment; $scope.address = pp.address + ''; - var amount = pp.data.amount / config.unitToSatoshi * 100000000; + var amount = pp.data.amount / $rootScope.wallet.settings.unitToSatoshi * 100000000; $scope.amount = amount; $scope.commentText = pp.data.message; } @@ -113,7 +113,7 @@ angular.module('copayApp.controllers').controller('SendController', $scope.loading = true; var address = form.address.$modelValue; - var amount = parseInt((form.amount.$modelValue * config.unitToSatoshi).toFixed(0)); + var amount = parseInt((form.amount.$modelValue * $rootScope.wallet.settings.unitToSatoshi).toFixed(0)); var commentText = form.comment.$modelValue; var w = $rootScope.wallet; @@ -403,7 +403,7 @@ angular.module('copayApp.controllers').controller('SendController', }; $scope.getAvailableAmount = function() { - var amount = ((($rootScope.availableBalance * config.unitToSatoshi).toFixed(0) - bitcore.TransactionBuilder.FEE_PER_1000B_SAT) / config.unitToSatoshi); + var amount = ((($rootScope.availableBalance * $rootScope.wallet.settings.unitToSatoshi).toFixed(0) - bitcore.TransactionBuilder.FEE_PER_1000B_SAT) / $rootScope.wallet.settings.unitToSatoshi); return amount > 0 ? amount : 0; }; @@ -497,7 +497,7 @@ angular.module('copayApp.controllers').controller('SendController', // Payment Protocol URI (BIP-72) scope.wallet.fetchPaymentTx(uri.merchant, function(err, merchantData) { var balance = $rootScope.availableBalance; - var available = +(balance * config.unitToSatoshi).toFixed(0); + var available = +(balance * $rootScope.wallet.settings.unitToSatoshi).toFixed(0); if (merchantData && available < +merchantData.total) { err = new Error('No unspent outputs available.'); @@ -508,7 +508,7 @@ angular.module('copayApp.controllers').controller('SendController', scope.sendForm.address.$isValid = false; if (err.amount) { - scope.sendForm.amount.$setViewValue(+err.amount / config.unitToSatoshi); + scope.sendForm.amount.$setViewValue(+err.amount / $rootScope.wallet.settings.unitToSatoshi); scope.sendForm.amount.$render(); scope.sendForm.amount.$isValid = false; scope.notEnoughAmount = true; @@ -538,7 +538,7 @@ angular.module('copayApp.controllers').controller('SendController', var url = merchantData.request_url; var domain = /^(?:https?)?:\/\/([^\/:]+).*$/.exec(url)[1]; - merchantData.unitTotal = (+merchantData.total / config.unitToSatoshi) + ''; + merchantData.unitTotal = (+merchantData.total / $rootScope.wallet.settings.unitToSatoshi) + ''; merchantData.expiration = new Date( merchantData.pr.pd.expires * 1000).toISOString(); merchantData.domain = domain; @@ -587,8 +587,10 @@ angular.module('copayApp.controllers').controller('SendController', } notification.info('Payment Request', - 'Server is requesting ' + merchantData.unitTotal + ' ' + config.unitName + '.' + ' Message: ' + merchantData.pr.pd.memo); + 'Server is requesting ' + merchantData.unitTotal + + ' ' + $rootScope.wallet.settings.unitName + + '.' + ' Message: ' + merchantData.pr.pd.memo); }); }; - }); \ No newline at end of file + }); diff --git a/js/filters.js b/js/filters.js index 68f014027..9ed43cd72 100644 --- a/js/filters.js +++ b/js/filters.js @@ -44,43 +44,42 @@ angular.module('copayApp.filters', []) return addrs; }; }) - .filter('noFractionNumber', - [ '$filter', '$locale', '$rootScope', - function(filter, locale, $rootScope) { - var numberFilter = filter('number'); - var formats = locale.NUMBER_FORMATS; - return function(amount, n) { - var fractionSize = (typeof(n) != 'undefined') ? n : $rootScope.wallet.settings.unitToSatoshi.toString().length - 1; - var value = numberFilter(amount, fractionSize); - var sep = value.indexOf(formats.DECIMAL_SEP); - var group = value.indexOf(formats.GROUP_SEP); - if(amount >= 0) { - if (group > 0) { - if (sep < 0) { + .filter('noFractionNumber', ['$filter', '$locale', '$rootScope', + function(filter, locale, $rootScope) { + var numberFilter = filter('number'); + var formats = locale.NUMBER_FORMATS; + return function(amount, n) { + var fractionSize = (typeof(n) !== 'undefined') ? + n : $rootScope.wallet.settings.unitToSatoshi.toString().length - 1; + var value = numberFilter(amount, fractionSize); + var sep = value.indexOf(formats.DECIMAL_SEP); + var group = value.indexOf(formats.GROUP_SEP); + if (amount >= 0) { + if (group > 0) { + if (sep < 0) { + return value; + } + var intValue = value.substring(0, sep); + var floatValue = parseFloat(value.substring(sep)); + if (floatValue === 0) { + floatValue = ''; + } else { + if (floatValue % 1 === 0) { + floatValue = floatValue.toFixed(0); + } + floatValue = floatValue.toString().substring(1); + } + var finalValue = intValue + floatValue; + return finalValue; + } else { + value = parseFloat(value); + if (value % 1 === 0) { + value = value.toFixed(0); + } return value; } - var intValue = value.substring(0, sep); - var floatValue = parseFloat(value.substring(sep)); - if (floatValue === 0) { - floatValue = ''; - } - else { - if(floatValue % 1 === 0) { - floatValue = floatValue.toFixed(0); - } - floatValue = floatValue.toString().substring(1); - } - var finalValue = intValue + floatValue; - return finalValue; } - else { - value = parseFloat(value); - if(value % 1 === 0) { - value = value.toFixed(0); - } - return value; - } - } - return 0; - }; - } ]); + return 0; + }; + } + ]); diff --git a/views/addresses.html b/views/addresses.html index 14f3d7cde..499306ea9 100644 --- a/views/addresses.html +++ b/views/addresses.html @@ -4,39 +4,39 @@ Addresses - +
-
-
-
-
-   - +
+
+
+
+   + - - change -
-
- -
- - - - - {{addr.balance || 0|noFractionNumber}} {{$root.unitName}} - + + change
- - Show all - Show less - +
+ + + + + {{addr.balance || 0|noFractionNumber}} {{$root.wallet.settings.unitName}} + +
+
+ + + + Show all + Show less +
- diff --git a/views/includes/sidebar-mobile.html b/views/includes/sidebar-mobile.html index acb540d3c..a77d6d841 100644 --- a/views/includes/sidebar-mobile.html +++ b/views/includes/sidebar-mobile.html @@ -19,7 +19,7 @@ tooltip="{{totalBalanceBTC |noFractionNumber:8}} BTC" tooltip-trigger="mouseenter" tooltip-placement="bottom">{{totalBalance || 0 - |noFractionNumber}} {{$root.unitName}} + |noFractionNumber}} {{$root.wallet.settings.unitName}}
@@ -31,7 +31,7 @@ data-options="disable_for_touch:true" tooltip="{{lockedBalanceBTC |noFractionNumber:8}} BTC" tooltip-trigger="mouseenter" - tooltip-placement="bottom">{{lockedBalance || 0|noFractionNumber}} {{$root.unitName}} + tooltip-placement="bottom">{{lockedBalance || 0|noFractionNumber}} {{$root.wallet.settings.unitName}}  
diff --git a/views/includes/sidebar.html b/views/includes/sidebar.html index 86c6f7a96..0bd5b8263 100644 --- a/views/includes/sidebar.html +++ b/views/includes/sidebar.html @@ -26,7 +26,7 @@ tooltip-popup-delay='500' tooltip="{{totalBalanceAlternative |noFractionNumber:2}} {{alternativeIsoCode}}" tooltip-trigger="mouseenter" - tooltip-placement="bottom">{{totalBalance || 0 |noFractionNumber}} {{$root.unitName}} + tooltip-placement="bottom">{{totalBalance || 0 |noFractionNumber}} {{$root.wallet.settings.unitName}}
Locked   @@ -39,7 +39,7 @@ tooltip-popup-delay='500' tooltip="{{lockedBalanceAlternative |noFractionNumber:2}} {{alternativeIsoCode}}" tooltip-trigger="mouseenter" - tooltip-placement="bottom">{{lockedBalance || 0|noFractionNumber}} {{$root.unitName}} + tooltip-placement="bottom">{{lockedBalance || 0|noFractionNumber}} {{$root.wallet.settings.unitName}}  
diff --git a/views/includes/transaction.html b/views/includes/transaction.html index 5c58a9416..016465c5e 100644 --- a/views/includes/transaction.html +++ b/views/includes/transaction.html @@ -8,20 +8,19 @@
-

- {{tx.comment}} - - {{$root.wallet.publicKeyRing.nicknameForCopayer(tx.creator)}} +

+ {{tx.comment}} - {{$root.wallet.publicKeyRing.nicknameForCopayer(tx.creator)}}

-

{{out.value | noFractionNumber}} {{$root.unitName}}

-

{{out.value | noFractionNumber}} {{$root.unitName}}

+

{{out.value | noFractionNumber}} {{$root.wallet.settings.unitName}}

+

{{out.value | noFractionNumber}} {{$root.wallet.settings.unitName}}

-
+
- +
@@ -37,25 +36,25 @@
- + - + - + - + - +
@@ -100,7 +99,7 @@
- Sent + Sent
Transaction ID: @@ -110,12 +109,12 @@

- One signature missing + One signature missing

- {{tx.missingSignatures}} signatures missing

+ {{tx.missingSignatures}} signatures missing

- Fee: {{tx.fee|noFractionNumber}} {{$root.unitName}} + Fee: {{tx.fee|noFractionNumber}} {{$root.wallet.settings.unitName}} Proposal ID: {{tx.ntxid}}
diff --git a/views/modals/qr-address.html b/views/modals/qr-address.html index c30b86096..13d5635fc 100644 --- a/views/modals/qr-address.html +++ b/views/modals/qr-address.html @@ -7,7 +7,7 @@

- {{address.balance || 0|noFractionNumber}} {{$root.unitName}} + {{address.balance || 0|noFractionNumber}} {{$root.wallet.settings.unitName}}