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

Commit be913ba

Browse files
committed
Merge pull request #1440 from OpenBazaar/internationalBTCFormatting
International btc formatting
2 parents 0190060 + 247bcfb commit be913ba

17 files changed

+68
-56
lines changed

css/obBase.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ label.fieldItem {
707707
}
708708

709709
[class |= "flexCol"] > .fieldItem {
710-
margin: 0 -1px -1px 0;
710+
margin: 0 -2px -2px 0; /* prevent collum overflows */
711711
}
712712

713713
.table {

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/languages/en-US.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@
9595
"ReturnPolicyPlaceholder": "Enter return policy...",
9696
"CategoryPlaceholder": "Enter category",
9797
"CategoryHelperText": "Categories are used to group and organize listing within your store.",
98-
"KeywordsHelperText": "Adding tags helps your listing to be discovered in the market. You can only have one of each tag, and a maximum of 10 tags",
98+
"KeywordsPlaceholder": "Enter One or More Tags",
99+
"KeywordsHelperText": "Adding tags helps your listing to be discovered in the market. You can only have one of each tag, and a maximum of 10 tags, separated by commas or the enter key.",
99100
"ExpirationDateHelperText": "Set a date for the listing to automatically be pulled from your store.",
100101
"ClearExpirationDate": "Clear Expiration Date",
101102
"ReturnPolicy": "Return Policy",
@@ -326,7 +327,7 @@
326327
"ServerChangeWarningHeadline": "Caution: Record Your Settings",
327328
"ServerChangeWarning": "We recommend you make a copy of your previous settings, shown below. Your previous username and password will no longer be available beyond this point.",
328329
"ModeratorFee": "Fee:",
329-
"PriceForOne": "Price per single item, file, or service.",
330+
"PriceForOne": "Price per single item, file, or service. Based on the listing's base price and the current exchange rate of BTC. This may not match the order total, which is based on the exchange rate of BTC at the time you purchased this listing.",
330331
"Avatar": "Avatar",
331332
"AdditionalPaymentData": "Additional payment data",
332333
"AdditionalPaymentDataInfo": "Include name of purchase and order number in payment QR code?",

js/models/itemMd.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var __ = require('underscore'),
22
Backbone = require('backbone'),
33
getBTPrice = require('../utils/getBitcoinPrice'),
4+
app = require('../App').getApp(),
45
countriesMd = require('./countriesMd'),
56
autolinker = require( '../utils/customLinker');
67

@@ -246,21 +247,21 @@ module.exports = window.Backbone.Model.extend({
246247
newAttributes.internationalShippingBTC = vendorInternationalShippingInBitCoin;
247248

248249
if(userCCode != 'BTC'){
249-
newAttributes.price = (vendorPrice*vendToUserBTCRatio).toFixed(2);
250+
newAttributes.price = vendorPrice*vendToUserBTCRatio;
250251
newAttributes.displayPrice = new Intl.NumberFormat(window.lang, {
251252
style: 'currency',
252253
minimumFractionDigits: 2,
253254
maximumFractionDigits: 2,
254255
currency: userCCode
255256
}).format(newAttributes.price);
256-
newAttributes.domesticShipping = (vendorDomesticShipping*vendToUserBTCRatio).toFixed(2);
257+
newAttributes.domesticShipping = vendorDomesticShipping*vendToUserBTCRatio;
257258
newAttributes.displayDomesticShipping = new Intl.NumberFormat(window.lang, {
258259
style: 'currency',
259260
minimumFractionDigits: 2,
260261
maximumFractionDigits: 2,
261262
currency: userCCode
262263
}).format(newAttributes.domesticShipping);
263-
newAttributes.internationalShipping = (vendorInternationalShipping*vendToUserBTCRatio).toFixed(2);
264+
newAttributes.internationalShipping = vendorInternationalShipping*vendToUserBTCRatio;
264265
newAttributes.displayInternationalShipping = new Intl.NumberFormat(window.lang, {
265266
style: 'currency',
266267
minimumFractionDigits: 2,
@@ -269,11 +270,11 @@ module.exports = window.Backbone.Model.extend({
269270
}).format(newAttributes.internationalShipping);
270271
} else {
271272
newAttributes.price = vendorPriceInBitCoin;
272-
newAttributes.displayPrice = vendorPriceInBitCoin.toFixed(4) + " BTC";
273+
newAttributes.displayPrice = app.intlNumFormat(vendorPriceInBitCoin, 4) + " BTC";
273274
newAttributes.domesticShipping = vendorDomesticShippingInBitCoin;
274-
newAttributes.displayDomesticShipping = vendorDomesticShippingInBitCoin.toFixed(4) + " BTC";
275+
newAttributes.displayDomesticShipping = app.intlNumFormat(vendorDomesticShippingInBitCoin, 4) + " BTC";
275276
newAttributes.internationalShipping = vendorInternationalShippingInBitCoin;
276-
newAttributes.displayInternationalShipping = vendorInternationalShippingInBitCoin.toFixed(4) + " BTC";
277+
newAttributes.displayInternationalShipping = app.intlNumFormat(vendorInternationalShippingInBitCoin, 4) + " BTC";
277278
}
278279
//set to random so a change event is always fired
279280
newAttributes.priceSet = Math.random();

js/models/itemShortMd.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var __ = require('underscore'),
22
Backbone = require('backbone'),
3+
app = require('../App').getApp(),
34
getBTPrice = require('../utils/getBitcoinPrice');
45

56
module.exports = Backbone.Model.extend({
@@ -50,7 +51,7 @@ module.exports = Backbone.Model.extend({
5051
vendorBitCoinPrice = Number(vendorPrice / btAve);
5152
//if vendor and user currency codes are the same, multiply by one to avoid rounding errors
5253
vendToUserBTCRatio = (userCCode == vendorCCode) ? 1 : window.currentBitcoin/vendorCurrencyInBitcoin;
53-
newAttributes.vendorBTCPrice = vendorBitCoinPrice.toFixed(4);
54+
newAttributes.vendorBTCPrice = vendorBitCoinPrice;
5455

5556
if(userCCode != 'BTC'){
5657
newAttributes.displayPrice = new Intl.NumberFormat(window.lang, {
@@ -60,7 +61,7 @@ module.exports = Backbone.Model.extend({
6061
currency: userCCode
6162
}).format(vendorPrice*vendToUserBTCRatio);
6263
} else {
63-
newAttributes.displayPrice = vendorBitCoinPrice.toFixed(4) + " BTC";
64+
newAttributes.displayPrice = app.intlNumFormat(vendorBitCoinPrice, 4) + " BTC";
6465
}
6566
//set to random so a change event is always fired
6667
newAttributes.priceSet = Math.random();

js/models/orderShortMd.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var __ = require('underscore'),
2-
Backbone = require('backbone');
2+
Backbone = require('backbone'),
3+
app = require('../App').getApp();
34

45
module.exports = window.Backbone.Model.extend({
56
defaults: {
@@ -25,10 +26,7 @@ module.exports = window.Backbone.Model.extend({
2526
maximumFractionDigits: 2,
2627
currency: response.cCode
2728
}).format(response.btc_total*response.btAve);
28-
} else {
29-
response.displayPrice = response.btc_total.toFixed(4) + " BTC";
3029
}
31-
3230
return response;
3331
}
3432
});

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
<% } %>

0 commit comments

Comments
 (0)