From 5f995544788b742f0b7c13bf8b53b99f4bc7016e Mon Sep 17 00:00:00 2001 From: Gustavo Cortez Date: Thu, 26 Jun 2014 16:11:40 -0300 Subject: [PATCH] New Angular filter for correct the formatting issue of the currency value --- index.html | 84 ++++++++++++++++++++++++++++----------------------- js/filters.js | 26 +++++++++++++++- 2 files changed, 72 insertions(+), 38 deletions(-) diff --git a/index.html b/index.html index e7825c84c..d94c45b70 100644 --- a/index.html +++ b/index.html @@ -36,7 +36,12 @@ - {{totalBalance || 0 |number}} {{$root.unitName}} + {{totalBalance || 0 + |noFractionNumber:4}} {{$root.unitName}}
@@ -44,7 +49,11 @@ - {{availableBalance || 0|number}} {{$root.unitName}} + {{availableBalance || 0|noFractionNumber:4}} {{$root.unitName}}
@@ -167,8 +176,8 @@
- {{$root.wallet.getName()}} - {{$root.wallet.requiredCopayers}}-of-{{$root.wallet.totalCopayers}} + {{$root.wallet.getName()}} + {{$root.wallet.requiredCopayers}}-of-{{$root.wallet.totalCopayers}} [LIVENET] [TESTNET]
@@ -180,7 +189,7 @@
- {{$root.wallet.getName()}} + {{$root.wallet.getName()}}
{{$root.wallet.requiredCopayers}}-of-{{$root.wallet.totalCopayers}} wallet @@ -190,7 +199,7 @@
Copay v{{version}}
- + @@ -404,11 +413,11 @@ - {{$root.balanceByAddr[addr.address] || 0|number}} {{$root.unitName}} + {{$root.balanceByAddr[addr.address] || 0|noFractionNumber:4}} {{$root.unitName}} - {{addr.balance || 0|number}} {{$root.unitName}} + {{addr.balance || 0|noFractionNumber:4}} {{$root.unitName}} @@ -426,12 +435,12 @@ - {{balanceByAddr[selectedAddr.address] || 0 | number}} + {{balanceByAddr[selectedAddr.address] || 0 | noFractionNumber:4}} {{selectedAddr.address}}
- {{selectedAddr.balance || 0|number}} {{$root.unitName}} + {{selectedAddr.balance || 0|noFractionNumber:4}} {{$root.unitName}}

@@ -462,7 +471,8 @@
-
{{out.value | number}} {{$root.unitName}}
+
+ {{out.value | noFractionNumber:4}} {{$root.unitName}}
@@ -546,7 +556,7 @@

{{tx.missingSignatures}} signatures missing

- Fee: {{tx.fee|number}} {{$root.unitName}} + Fee: {{tx.fee|noFractionNumber:4}} {{$root.unitName}} Proposal ID: {{tx.ntxid}}
@@ -593,7 +603,7 @@
- {{vin.value| number}} {{$root.unitName}} + {{vin.value| noFractionNumber:4}} {{$root.unitName}}

@@ -604,7 +614,7 @@
- {{vout.value| number}} {{$root.unitName}} + {{vout.value| noFractionNumber:4}} {{$root.unitName}}

@@ -614,9 +624,9 @@
-
Fees: {{btx.fees | number}} {{$root.unitName}}
+
Fees: {{btx.fees | noFractionNumber:4}} {{$root.unitName}}
Confirmations: {{btx.confirmations || 0}}
-
Total: {{btx.valueOut| number}} {{$root.unitName}}
+
Total: {{btx.valueOut| noFractionNumber:4}} {{$root.unitName}}
@@ -699,16 +709,16 @@
- Total amount for this transaction: + Total amount for this transaction:
- {{amount + defaultFee |number}} {{$root.unitName}} + {{amount + defaultFee |noFractionNumber:4}} {{$root.unitName}} - {{ ((amount + defaultFee) * unitToBtc) |number}} BTC + {{ ((amount + defaultFee) * unitToBtc) |noFractionNumber:4}} BTC
- Including fee of {{defaultFee|number}} {{$root.unitName}} + Including fee of {{defaultFee|noFractionNumber:4}} {{$root.unitName}}
@@ -771,23 +781,23 @@ diff --git a/js/filters.js b/js/filters.js index 9668c71bf..14069d27d 100644 --- a/js/filters.js +++ b/js/filters.js @@ -30,4 +30,28 @@ angular.module('copayApp.filters', []) return addrs; }; - }); + }) + .filter('noFractionNumber', + [ '$filter', '$locale', + function(filter, locale) { + var numberFilter = filter('number'); + var formats = locale.NUMBER_FORMATS; + return function(amount, fraction) { + var value = numberFilter(amount, fraction); + var sep = value.indexOf(formats.DECIMAL_SEP); + var group = value.indexOf(formats.GROUP_SEP); + if(amount >= 0) { + if (group > 0) { + return value.substring(0, sep); + } + else { + value = parseFloat(value); + if(value % 1 === 0) { + value = value.toFixed(0); + } + return value; + } + } + return 0; + }; + } ]);