From a6d2799510849606d2a88942979ef1e73a78c37f Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Wed, 13 Jun 2018 15:56:39 +1200 Subject: [PATCH 01/10] Display fiat on Payment Received screen, according to preferences. --- src/js/controllers/tab-receive.js | 6 ++++++ www/views/tab-receive.html | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/js/controllers/tab-receive.js b/src/js/controllers/tab-receive.js index c9fa46de9..4d048e22e 100644 --- a/src/js/controllers/tab-receive.js +++ b/src/js/controllers/tab-receive.js @@ -125,6 +125,12 @@ angular.module('copayApp.controllers').controller('tabReceiveController', functi for (var i = 0; i < data.x.out.length; i++) { if (data.x.out[i].addr == watchAddress) { $scope.paymentReceivedAmount = txFormatService.formatAmount(data.x.out[i].value, 'full'); + $scope.paymentReceivedAlternativeAmount = null; // For when a subsequent payment is received. + txFormatService.formatAlternativeStr($scope.wallet.coin, data.x.out[i].value, function(alternativeStr){ + if (alternativeStr) { + $scope.paymentReceivedAlternativeAmount = alternativeStr; + } + }); } } $scope.paymentReceivedCoin = $scope.wallet.coin; diff --git a/www/views/tab-receive.html b/www/views/tab-receive.html index 0eb598096..a6b94b74e 100644 --- a/www/views/tab-receive.html +++ b/www/views/tab-receive.html @@ -61,7 +61,8 @@


Payment Received! - {{ paymentReceivedAmount }} {{ paymentReceivedCoin }} + {{ paymentReceivedAmount }} {{ paymentReceivedCoin }} + {{ paymentReceivedAlternativeAmount }} Return To Address

From a186e4d04f353626e50acedfcb34d82299007c7c Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Thu, 14 Jun 2018 22:16:25 +1200 Subject: [PATCH 02/10] Display fiat on Network Fees popup. Display subcent amounts as '< 0.01'. --- src/js/controllers/confirm.js | 17 ++++-- src/js/services/txFormatService.js | 14 +++-- src/js/services/txFormatService.spec.js | 71 +++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 6 deletions(-) create mode 100644 src/js/services/txFormatService.spec.js diff --git a/src/js/controllers/confirm.js b/src/js/controllers/confirm.js index fc92a2287..53589cf22 100644 --- a/src/js/controllers/confirm.js +++ b/src/js/controllers/confirm.js @@ -426,6 +426,8 @@ angular.module('copayApp.controllers').controller('confirmController', function( function showSendMaxWarning(wallet, sendMaxInfo) { + var feeAlternative, + msg; function verifyExcludedUtxos() { var warningMsg = []; @@ -443,9 +445,18 @@ angular.module('copayApp.controllers').controller('confirmController', function( return warningMsg.join('\n'); }; - var msg = gettextCatalog.getString("{{fee}} will be deducted for bitcoin networking fees.", { - fee: txFormatService.formatAmountStr(wallet.coin, sendMaxInfo.fee) - }); + feeAlternative = txFormatService.formatAlternativeStr(wallet.coin, sendMaxInfo.fee); + if (feeAlternative) { + msg = gettextCatalog.getString("{{feeAlternative}} will be deducted for bitcoin networking fees ({{fee}}).", { + fee: txFormatService.formatAmountStr(wallet.coin, sendMaxInfo.fee), + feeAlternative: feeAlternative + }); + } else { + gettextCatalog.getString("{{fee}} will be deducted for bitcoin networking fees).", { + fee: txFormatService.formatAmountStr(wallet.coin, sendMaxInfo.fee) + }); + } + var warningMsg = verifyExcludedUtxos(); if (!lodash.isEmpty(warningMsg)) diff --git a/src/js/services/txFormatService.js b/src/js/services/txFormatService.js index 5817c1a27..c208857a8 100644 --- a/src/js/services/txFormatService.js +++ b/src/js/services/txFormatService.js @@ -72,11 +72,19 @@ angular.module('copayApp.services').factory('txFormatService', function($filter, var config = configService.getSync().wallet.settings; var val = function() { - var v1 = parseFloat((rateService.toFiat(satoshis, config.alternativeIsoCode, coin)).toFixed(2)); - v1 = $filter('formatFiatAmount')(v1); + var fiatAmount = rateService.toFiat(satoshis, config.alternativeIsoCode, coin); + var roundedStr = fiatAmount.toFixed(2); + var roundedNum = parseFloat(roundedStr); + var subcent = roundedNum === 0 && fiatAmount > 0; + var lessThanPrefix = ''; + if (subcent) { + roundedNum = 0.01; + lessThanPrefix = '< ' + } + var v1 = $filter('formatFiatAmount')(roundedNum); if (!v1) return null; - return v1 + ' ' + config.alternativeIsoCode; + return lessThanPrefix + v1 + ' ' + config.alternativeIsoCode; }; // Async version diff --git a/src/js/services/txFormatService.spec.js b/src/js/services/txFormatService.spec.js new file mode 100644 index 000000000..5ca60210d --- /dev/null +++ b/src/js/services/txFormatService.spec.js @@ -0,0 +1,71 @@ +describe('txFormatService', function(){ + var configServiceMock, + rateServiceMock, + txFormatService; + + beforeEach(function(){ + module('ngLodash'); + module('bwcModule'); + module('copayApp.filters'); + module('copayApp.services'); + + configServiceMock = { + getSync: jasmine.createSpy() + }; + + rateServiceMock = { + isAvailable: jasmine.createSpy(), + toFiat: jasmine.createSpy() + }; + + module(function($provide) { + $provide.value('configService', configServiceMock); + //$provide.value('$log', log); // Handy for debugging test failures + $provide.value('rateService', rateServiceMock); + }); + + inject(function($injector){ + txFormatService = $injector.get('txFormatService'); + }); + + }); + + it('formatAlternativeStr 0.49 cents.', function() { + + configServiceMock.getSync.and.returnValue({ + wallet: { + settings: { + alternativeIsoCode: 'USD' + } + } + }); + + rateServiceMock.isAvailable.and.returnValue(true); + rateServiceMock.toFiat.and.returnValue(0.00499); + + var formatted = txFormatService.formatAlternativeStr('bch', 123); + + expect(formatted).toBe('< 0.01 USD'); + //expect(formatted).toBe('0.00 USD'); + + }); + + it('formatAlternativeStr 0.5 cents.', function() { + + configServiceMock.getSync.and.returnValue({ + wallet: { + settings: { + alternativeIsoCode: 'USD' + } + } + }); + + rateServiceMock.isAvailable.and.returnValue(true); + rateServiceMock.toFiat.and.returnValue(0.005); + + var formatted = txFormatService.formatAlternativeStr('bch', 123); + + expect(formatted).toBe('0.01 USD'); + }); + +}); \ No newline at end of file From 143b39970b55bfb15606a04c591099eaba6a95d6 Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Thu, 14 Jun 2018 22:18:17 +1200 Subject: [PATCH 03/10] Removed some commented out code. --- src/js/services/txFormatService.spec.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/js/services/txFormatService.spec.js b/src/js/services/txFormatService.spec.js index 5ca60210d..c67e86f21 100644 --- a/src/js/services/txFormatService.spec.js +++ b/src/js/services/txFormatService.spec.js @@ -20,7 +20,6 @@ describe('txFormatService', function(){ module(function($provide) { $provide.value('configService', configServiceMock); - //$provide.value('$log', log); // Handy for debugging test failures $provide.value('rateService', rateServiceMock); }); @@ -46,8 +45,6 @@ describe('txFormatService', function(){ var formatted = txFormatService.formatAlternativeStr('bch', 123); expect(formatted).toBe('< 0.01 USD'); - //expect(formatted).toBe('0.00 USD'); - }); it('formatAlternativeStr 0.5 cents.', function() { From 1e73eae4d2db7fdfdc398deb818704d38fc83fad Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Fri, 15 Jun 2018 10:04:15 +1200 Subject: [PATCH 04/10] Bugfix for undefined wallet status on send tab. --- src/js/controllers/tab-send.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/js/controllers/tab-send.js b/src/js/controllers/tab-send.js index 29f1749cb..2282ab878 100644 --- a/src/js/controllers/tab-send.js +++ b/src/js/controllers/tab-send.js @@ -76,8 +76,11 @@ angular.module('copayApp.controllers').controller('tabSendController', function( var walletList = []; lodash.each(walletsToTransfer, function(v) { var displayBalanceAsFiat = - v.status.alternativeBalanceAvailable && - config.wallet.settings.priceDisplay === 'fiat'; + // BD got v.status as undefined here once during development, just + // after creating a new wallet. + v.status && + v.status.alternativeBalanceAvailable && + config.wallet.settings.priceDisplay === 'fiat'; walletList.push({ color: v.color, From e416deec44a66937b1848852ad4a64859c0fb90e Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Fri, 15 Jun 2018 10:06:38 +1200 Subject: [PATCH 05/10] Amount shown confirm screen is now primarily fiat. --- src/sass/views/includes/txp-details.scss | 12 ++++-------- www/views/confirm.html | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/sass/views/includes/txp-details.scss b/src/sass/views/includes/txp-details.scss index c32faaacd..9da0811e0 100644 --- a/src/sass/views/includes/txp-details.scss +++ b/src/sass/views/includes/txp-details.scss @@ -36,17 +36,13 @@ .amount-label{ line-height: 30px; .amount{ - font-size: 38px; + font-size: 16px; margin-bottom: .5rem; - - > .unit { - font-family: "Roboto-Light"; - } + color: #9B9B9B; + font-family: "Roboto-Light"; } .alternative { - font-size: 16px; - font-family: "Roboto-Light"; - color: #9B9B9B; + font-size: 38px; } } } diff --git a/www/views/confirm.html b/www/views/confirm.html index 443043d49..57f3a60e8 100644 --- a/www/views/confirm.html +++ b/www/views/confirm.html @@ -16,8 +16,8 @@ Sending maximum amount
-
{{tx.amountValueStr || '...'}} {{tx.amountUnitStr}}
{{tx.alternativeAmountStr || '...'}}
+
{{tx.amountValueStr || '...'}} {{tx.amountUnitStr}}
From fffbda2458ac9cd860893c31afb97b58a00024a7 Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Fri, 15 Jun 2018 10:14:21 +1200 Subject: [PATCH 06/10] Matched amount formatting on Confirm screen, to previous formatting. --- src/js/controllers/confirm.js | 2 ++ src/sass/views/includes/txp-details.scss | 4 ++++ www/views/confirm.html | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/js/controllers/confirm.js b/src/js/controllers/confirm.js index 53589cf22..cebf9cb3a 100644 --- a/src/js/controllers/confirm.js +++ b/src/js/controllers/confirm.js @@ -288,6 +288,8 @@ angular.module('copayApp.controllers').controller('confirmController', function( tx.amountUnitStr = tx.amountStr.split(' ')[1]; txFormatService.formatAlternativeStr(wallet.coin, tx.toAmount, function(v) { tx.alternativeAmountStr = v; + tx.alternativeAmountValueStr = tx.alternativeAmountStr.split(' ')[0]; + tx.alternativeAmountUnitStr = tx.alternativeAmountStr.split(' ')[1]; }); } diff --git a/src/sass/views/includes/txp-details.scss b/src/sass/views/includes/txp-details.scss index 9da0811e0..ae6c0d218 100644 --- a/src/sass/views/includes/txp-details.scss +++ b/src/sass/views/includes/txp-details.scss @@ -43,6 +43,10 @@ } .alternative { font-size: 38px; + + > .unit { + font-family: "Roboto-Light"; + } } } } diff --git a/www/views/confirm.html b/www/views/confirm.html index 57f3a60e8..ad34e1f08 100644 --- a/www/views/confirm.html +++ b/www/views/confirm.html @@ -16,7 +16,7 @@ Sending maximum amount
-
{{tx.alternativeAmountStr || '...'}}
+
{{tx.alternativeAmountValueStr || '...'}} {{tx.alternativeAmountUnitStr}}
{{tx.amountValueStr || '...'}} {{tx.amountUnitStr}}
From a9a05da07d267fee0f243226e94d61c27acb775c Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Fri, 15 Jun 2018 10:19:46 +1200 Subject: [PATCH 07/10] Fee on confirm screen now shown primarily in fiat. --- www/views/confirm.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/www/views/confirm.html b/www/views/confirm.html index ad34e1f08..e54837f34 100644 --- a/www/views/confirm.html +++ b/www/views/confirm.html @@ -77,9 +77,9 @@
{{'Fee:' | translate}} {{tx.feeLevelName | translate}} - {{tx.txp[wallet.id].feeStr || '...'}} + {{tx.txp[wallet.id].alternativeFeeStr || '...'}} - {{tx.txp[wallet.id].alternativeFeeStr || '...'}}  + {{tx.txp[wallet.id].feeStr || '...'}}  ·   {{tx.txp[wallet.id].feeRatePerStr}} of the sending amount From 901d202f857c07a366d0f1b3c33f711e516f2374 Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Fri, 15 Jun 2018 10:24:00 +1200 Subject: [PATCH 08/10] Bugfix for when alternative string is not available in Network Fees alert. --- src/js/controllers/confirm.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/controllers/confirm.js b/src/js/controllers/confirm.js index cebf9cb3a..cc48bf6b9 100644 --- a/src/js/controllers/confirm.js +++ b/src/js/controllers/confirm.js @@ -454,7 +454,7 @@ angular.module('copayApp.controllers').controller('confirmController', function( feeAlternative: feeAlternative }); } else { - gettextCatalog.getString("{{fee}} will be deducted for bitcoin networking fees).", { + msg = gettextCatalog.getString("{{fee}} will be deducted for bitcoin networking fees).", { fee: txFormatService.formatAmountStr(wallet.coin, sendMaxInfo.fee) }); } From 86be126e951f715d481491564cb55d6ce40e55b1 Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Fri, 15 Jun 2018 15:43:37 +1200 Subject: [PATCH 09/10] Adjust spacing on amount in confirm screen, to match original. --- src/sass/views/includes/txp-details.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sass/views/includes/txp-details.scss b/src/sass/views/includes/txp-details.scss index ae6c0d218..240ee444b 100644 --- a/src/sass/views/includes/txp-details.scss +++ b/src/sass/views/includes/txp-details.scss @@ -37,12 +37,12 @@ line-height: 30px; .amount{ font-size: 16px; - margin-bottom: .5rem; color: #9B9B9B; font-family: "Roboto-Light"; } .alternative { font-size: 38px; + margin-bottom: .5rem; > .unit { font-family: "Roboto-Light"; From ccf2dd45868ce2ee2c5df6b8487c80c96c68c0ba Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Mon, 2 Jul 2018 11:20:34 +1200 Subject: [PATCH 10/10] Changes as requested by PR. --- src/js/controllers/confirm.js | 9 +++++---- src/js/controllers/tab-receive.js | 2 +- src/js/services/txFormatService.js | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/js/controllers/confirm.js b/src/js/controllers/confirm.js index cc48bf6b9..55b94446c 100644 --- a/src/js/controllers/confirm.js +++ b/src/js/controllers/confirm.js @@ -287,9 +287,10 @@ angular.module('copayApp.controllers').controller('confirmController', function( tx.amountValueStr = tx.amountStr.split(' ')[0]; tx.amountUnitStr = tx.amountStr.split(' ')[1]; txFormatService.formatAlternativeStr(wallet.coin, tx.toAmount, function(v) { + var parts = v.split(' '); tx.alternativeAmountStr = v; - tx.alternativeAmountValueStr = tx.alternativeAmountStr.split(' ')[0]; - tx.alternativeAmountUnitStr = tx.alternativeAmountStr.split(' ')[1]; + tx.alternativeAmountValueStr = parts[0]; + tx.alternativeAmountUnitStr = (parts.length > 0) ? parts[1] : ''; }); } @@ -428,8 +429,8 @@ angular.module('copayApp.controllers').controller('confirmController', function( function showSendMaxWarning(wallet, sendMaxInfo) { - var feeAlternative, - msg; + var feeAlternative = '', + msg = ''; function verifyExcludedUtxos() { var warningMsg = []; diff --git a/src/js/controllers/tab-receive.js b/src/js/controllers/tab-receive.js index 4d048e22e..d5b7f1cd1 100644 --- a/src/js/controllers/tab-receive.js +++ b/src/js/controllers/tab-receive.js @@ -125,7 +125,7 @@ angular.module('copayApp.controllers').controller('tabReceiveController', functi for (var i = 0; i < data.x.out.length; i++) { if (data.x.out[i].addr == watchAddress) { $scope.paymentReceivedAmount = txFormatService.formatAmount(data.x.out[i].value, 'full'); - $scope.paymentReceivedAlternativeAmount = null; // For when a subsequent payment is received. + $scope.paymentReceivedAlternativeAmount = ''; // For when a subsequent payment is received. txFormatService.formatAlternativeStr($scope.wallet.coin, data.x.out[i].value, function(alternativeStr){ if (alternativeStr) { $scope.paymentReceivedAlternativeAmount = alternativeStr; diff --git a/src/js/services/txFormatService.js b/src/js/services/txFormatService.js index c208857a8..ebcb3886a 100644 --- a/src/js/services/txFormatService.js +++ b/src/js/services/txFormatService.js @@ -79,7 +79,7 @@ angular.module('copayApp.services').factory('txFormatService', function($filter, var lessThanPrefix = ''; if (subcent) { roundedNum = 0.01; - lessThanPrefix = '< ' + lessThanPrefix = '< '; } var v1 = $filter('formatFiatAmount')(roundedNum); if (!v1) return null;