Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit c01ff06

Browse files
committed
more work
- moved function to app.js - applied to purchasing flow
1 parent 737574f commit c01ff06

File tree

8 files changed

+25
-19
lines changed

8 files changed

+25
-19
lines changed

js/App.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ App.prototype.setUnreadChatMessageCount = function(count) {
136136
}
137137
};
138138

139+
App.prototype.intlNumFormat = function(numberToFormat, maxDigits){
140+
return new Intl.NumberFormat(window.lang, {maximumFractionDigits: maxDigits}).format(numberToFormat);
141+
};
142+
139143
App.getApp = function() {
140144
if (!_app) {
141145
throw new Error('The app instance was never instantiated and is therefore not available.');

js/templates/buyAddresses.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<% } else { %>
3131
<%= ob.displayDomesticShipping %>
3232
<% if(ob.userCurrencyCode != 'BTC'){ %>
33-
<div class="textOpacity75 textSize12px letterSpacing02">(<%= Number(ob.domesticShippingBTC.toFixed(4)) %> BTC)</div>
33+
<div class="textOpacity75 textSize12px letterSpacing02">(<%= ob.intlNumFormat(ob.domesticShippingBTC, 4) %> BTC)</div>
3434
<% } %>
3535
<% } %>
3636
<% } else { %>
@@ -39,7 +39,7 @@
3939
<% } else { %>
4040
<%= ob.displayInternationalShipping %>
4141
<% if(ob.userCurrencyCode != 'BTC'){ %>
42-
<div class="textOpacity75 textSize12px letterSpacing02">(<%= Number(ob.internationalShippingBTC.toFixed(4)) %> BTC)</div>
42+
<div class="textOpacity75 textSize12px letterSpacing02">(<%= ob.intlNumFormat(ob.internationalShippingBTC, 4) %> BTC)</div>
4343
<% } %>
4444
<% } %>
4545
<% } %>

js/templates/buyDetails.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@
8282
<% } else { %>
8383
<span class="noOverflow fontSize13 js-buyWizardBTCShippingPrice">
8484
<% if(ob.shippingType === "domestic") { %>
85-
<%= ob.domesticShippingBTC.toFixed(8) %> BTC
85+
<%= ob.intlNumFormat(ob.domesticShippingBTC, 8) %> BTC
8686
<% }else{ %>
87-
<%= ob.internationalShippingBTC.toFixed(8) %> BTC
87+
<%= ob.intlNumFormat(ob.internationalShippingBTC, 8) %> BTC
8888
<% } %>
8989
</span>
9090
<span class="noOverflow js-buyWizardShippingPrice textOpacity75 fontSize13">

js/templates/item.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ <h2 class="page-contractTitle noOverflow textOpacity1 marginLeft20 marginBottom8
4141
<ul class="itemMeta">
4242
<li class="alignCenter itemPrice">
4343
<span class="textSize22px textOpacity1 fontWeight500 marginRight2">
44-
<%= Number(ob.vendorBTCPrice.toFixed(4)) %> BTC
44+
<%= ob.intlNumFormat(ob.vendorBTCPrice, 8) %> BTC
4545
</span>
4646
<% if(ob.userCurrencyCode != 'BTC'){ %>
4747
<span class="textSize22px textOpacity65">(<%= ob.displayPrice %>)</span>
@@ -192,9 +192,9 @@ <h3><%= polyglot.t('ShipsFrom2', {country: ob.displayShippingOrigin || ob.userCo
192192
<h3><%= polyglot.t('Local') %></h3>
193193
<div>
194194
<% if(ob.userCurrencyCode != "BTC"){ %>
195-
<%= polyglot.t('Shipping2') %> <%= ob.displayDomesticShipping %> (<%= Number(ob.domesticShippingBTC.toFixed(8)) %> BTC)
195+
<%= polyglot.t('Shipping2') %> <%= ob.displayDomesticShipping %> (<%= ob.intlNumFormat(ob.domesticShippingBTC, 8) %> BTC)
196196
<% } else { %>
197-
<%= polyglot.t('Shipping2') %> <%= Number(ob.domesticShippingBTC.toFixed(8)) %> BTC
197+
<%= polyglot.t('Shipping2') %> <%= ob.intlNumFormat(ob.domesticShippingBTC, 8) %> BTC
198198
<% } %>
199199
</div>
200200
<p><%= polyglot.t('transactions.EstimatedDelivery') %> <%= ob.vendor_offer.listing.shipping.est_delivery.domestic %></p>
@@ -203,9 +203,9 @@ <h3><%= polyglot.t('Local') %></h3>
203203
<h3><%= polyglot.t('International') %></h3>
204204
<div>
205205
<% if(ob.userCurrencyCode != "BTC"){ %>
206-
<%= polyglot.t('Shipping2') %> <%= ob.displayInternationalShipping %> (<%= Number(ob.internationalShippingBTC.toFixed(8)) %> BTC)
206+
<%= polyglot.t('Shipping2') %> <%= ob.displayInternationalShipping %> (<%= ob.intlNumFormat(ob.internationalShippingBTC, 8) %> BTC)
207207
<% } else { %>
208-
<%= polyglot.t('Shipping2') %> <%= Number(ob.internationalShippingBTC.toFixed(8)) %> BTC
208+
<%= polyglot.t('Shipping2') %> <%= ob.intlNumFormat(ob.internationalShippingBTC, 8) %> BTC
209209
<% } %>
210210
</div>
211211
<p><%= polyglot.t('transactions.EstimatedDelivery') %> <%= ob.vendor_offer.listing.shipping.est_delivery.international %></p>

js/templates/itemShort.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<div class="js-item pad8Left <% if(ob.title.length >= 30) { %>tooltip<% } %>" <% if(ob.title.length >= 30) { %>data-tooltip="<%= ob.title.substring(0, 40) %>"<% } %> data-id="<%= ob.contract_hash %>">
1212
<div class="textSize14px noOverflow textOpacity1 js-searchTitle"><%= ob.title %></div>
1313
<div class="textSize13px txt-fade textWeightNormal">
14-
<%= ob.vendorBTCPrice %> BTC
14+
<%= ob.intlNumFormat(ob.vendorBTCPrice, 4) %> BTC
1515
<% if(ob.userCurrencyCode != 'BTC'){ %>
1616
(<%= ob.displayPrice %>)
1717
<% } %>

js/utils/templateHelpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function cssImageUrl(hash, guid, fallback) {
2525
}
2626

2727
function intlNumFormat(numberToFormat, maxDigits){
28-
return new Intl.NumberFormat(window.lang, {maximumFractionDigits: maxDigits}).format(numberToFormat);
28+
return app.intlNumFormat(numberToFormat, maxDigits);
2929
}
3030

3131
module.exports = {

js/views/buyDetailsVw.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var __ = require('underscore'),
22
Backbone = require('backbone'),
33
$ = require('jquery'),
44
numberSpinners = require('../utils/numberSpinners'),
5+
app = require('../App').getApp(),
56
loadTemplate = require('../utils/loadTemplate');
67
Backbone.$ = $;
78

@@ -72,21 +73,21 @@ module.exports = Backbone.View.extend({
7273
moderatorPrice = moderatorPercentage ? totalItemPrice * moderatorPercentage : 0,
7374
moderatorTotal = moderatorPrice * quantity,
7475
totalPrice = totalItemPrice + totalShipping,
75-
newBTCDisplayPrice = Number((this.model.get('vendorBTCPrice') * quantity).toFixed(8)),
76-
newBTCShippingDisplayPrice = Number((this.model.get('currentShippingBTCPrice') * quantity).toFixed(8)),
77-
newDisplayPrice = (userCurrency == "BTC") ? Number(totalItemPrice.toFixed(8)) + " BTC" : new Intl.NumberFormat(window.lang, {
76+
newBTCDisplayPrice = app.intlNumFormat((this.model.get('vendorBTCPrice') * quantity), 8),
77+
newBTCShippingDisplayPrice = app.intlNumFormat((this.model.get('currentShippingBTCPrice') * quantity), 8),
78+
newDisplayPrice = (userCurrency == "BTC") ? app.intlNumFormat(totalItemPrice, 8) + " BTC" : new Intl.NumberFormat(window.lang, {
7879
style: 'currency',
7980
minimumFractionDigits: 2,
8081
maximumFractionDigits: 2,
8182
currency: userCurrency
8283
}).format(totalItemPrice),
83-
newDisplayShippingPrice = (userCurrency == "BTC") ? Number(totalShipping.toFixed(8)) + " BTC" : new Intl.NumberFormat(window.lang, {
84+
newDisplayShippingPrice = (userCurrency == "BTC") ? app.intlNumFormat(totalShipping, 8) + " BTC" : new Intl.NumberFormat(window.lang, {
8485
style: 'currency',
8586
minimumFractionDigits: 2,
8687
maximumFractionDigits: 2,
8788
currency: userCurrency
8889
}).format(totalShipping),
89-
newDisplayModeratorPrice = (userCurrency == "BTC") ? Number(moderatorTotal.toFixed(8)) + " BTC" : new Intl.NumberFormat(window.lang, {
90+
newDisplayModeratorPrice = (userCurrency == "BTC") ? app.intlNumFormat(moderatorTotal, 8) + " BTC" : new Intl.NumberFormat(window.lang, {
9091
style: 'currency',
9192
minimumFractionDigits: 2,
9293
maximumFractionDigits: 2,
@@ -95,7 +96,7 @@ module.exports = Backbone.View.extend({
9596
totalBTCDisplayPrice = (this.model.get('vendorBTCPrice') + this.model.get('currentShippingBTCPrice')) * quantity,
9697
moderatorPriceBTC = moderatorPercentage ? totalBTCDisplayPrice * moderatorPercentage : 0,
9798
moderatorPriceString = this.model.get('userCurrencyCode') == 'BTC' ?
98-
moderatorPriceBTC.toFixed(8) + " BTC" : moderatorPriceBTC.toFixed(8) + " BTC (" + newDisplayModeratorPrice + ")";
99+
app.intlNumFormat(moderatorPriceBTC, 8) + " BTC" : app.intlNumFormat(moderatorPriceBTC, 8) + " BTC (" + newDisplayModeratorPrice + ")";
99100

100101
this.$('.js-buyWizardBTCPrice').html(newBTCDisplayPrice+"BTC");
101102
this.$('.js-buyWizardBTCShippingPrice').html(newBTCShippingDisplayPrice+"BTC");

js/views/buyWizardVw.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var __ = require('underscore'),
1010
saveToAPI = require('../utils/saveToAPI'),
1111
chosen = require('../utils/chosen.jquery.min.js'),
1212
qr = require('qr-encode'),
13+
app = require('../App').getApp(),
1314
clipboard = require('clipboard');
1415
Backbone.$ = $;
1516

@@ -565,14 +566,14 @@ module.exports = baseVw.extend({
565566
var totalPrice = this.model.get('totalPrice'),
566567
totalBTCPrice = this.model.get('totalBTCDisplayPrice'),
567568
userCurrency = this.model.get('userCurrencyCode'),
568-
totalDisplayPrice = (userCurrency == "BTC") ? Number(totalPrice.toFixed(8)) + " BTC" : new Intl.NumberFormat(window.lang, {
569+
totalDisplayPrice = (userCurrency == "BTC") ? app.intlNumFormat(totalPrice, 8) + " BTC" : new Intl.NumberFormat(window.lang, {
569570
style: 'currency',
570571
minimumFractionDigits: 2,
571572
maximumFractionDigits: 2,
572573
currency: userCurrency
573574
}).format(totalPrice);
574575
this.$('.js-buyWizardDetailsTotal').text(totalDisplayPrice);
575-
this.$('.js-buyWizardDetailsBTCTotal').text(Number(totalBTCPrice.toFixed(8)));
576+
this.$('.js-buyWizardDetailsBTCTotal').text(app.intlNumFormat(totalBTCPrice, 8));
576577
},
577578

578579
copyPayAddress: function(){

0 commit comments

Comments
 (0)