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