diff --git a/src/js/controllers/confirm.js b/src/js/controllers/confirm.js index fc92a2287..55b94446c 100644 --- a/src/js/controllers/confirm.js +++ b/src/js/controllers/confirm.js @@ -287,7 +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 = parts[0]; + tx.alternativeAmountUnitStr = (parts.length > 0) ? parts[1] : ''; }); } @@ -426,6 +429,8 @@ angular.module('copayApp.controllers').controller('confirmController', function( function showSendMaxWarning(wallet, sendMaxInfo) { + var feeAlternative = '', + msg = ''; function verifyExcludedUtxos() { var warningMsg = []; @@ -443,9 +448,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 { + msg = 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/controllers/tab-receive.js b/src/js/controllers/tab-receive.js index e4f7388d6..cfdcc5de9 100644 --- a/src/js/controllers/tab-receive.js +++ b/src/js/controllers/tab-receive.js @@ -143,6 +143,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 = ''; // 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/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, diff --git a/src/js/services/txFormatService.js b/src/js/services/txFormatService.js index 5817c1a27..ebcb3886a 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..c67e86f21 --- /dev/null +++ b/src/js/services/txFormatService.spec.js @@ -0,0 +1,68 @@ +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('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'); + }); + + 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 diff --git a/src/sass/views/includes/txp-details.scss b/src/sass/views/includes/txp-details.scss index c32faaacd..240ee444b 100644 --- a/src/sass/views/includes/txp-details.scss +++ b/src/sass/views/includes/txp-details.scss @@ -36,6 +36,11 @@ .amount-label{ line-height: 30px; .amount{ + font-size: 16px; + color: #9B9B9B; + font-family: "Roboto-Light"; + } + .alternative { font-size: 38px; margin-bottom: .5rem; @@ -43,11 +48,6 @@ font-family: "Roboto-Light"; } } - .alternative { - font-size: 16px; - font-family: "Roboto-Light"; - color: #9B9B9B; - } } } .item { diff --git a/www/views/confirm.html b/www/views/confirm.html index 443043d49..e54837f34 100644 --- a/www/views/confirm.html +++ b/www/views/confirm.html @@ -16,8 +16,8 @@ Sending maximum amount
+
{{tx.alternativeAmountValueStr || '...'}} {{tx.alternativeAmountUnitStr}}
{{tx.amountValueStr || '...'}} {{tx.amountUnitStr}}
-
{{tx.alternativeAmountStr || '...'}}
@@ -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 diff --git a/www/views/tab-receive.html b/www/views/tab-receive.html index 3dd8ce94a..1ddc65e0a 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