Skip to content

Commit 362f793

Browse files
committed
fix: display active coin currency units
1 parent b52d45a commit 362f793

5 files changed

Lines changed: 46 additions & 24 deletions

File tree

app/currencies.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
1+
const config = require("./config.js");
2+
const coins = require("./coins.js");
3+
4+
const coinConfig = coins[config.coin];
5+
6+
// Keep the internal "btc" and "sat" setting keys for compatibility with
7+
// existing sessions, while deriving their display units from the active coin.
18
global.currencyTypes = {
29
"btc": {
310
id: "btc",
411
type:"native",
5-
name:"BTC",
6-
multiplier:1,
12+
name:coinConfig.defaultCurrencyUnit.name,
13+
multiplier:coinConfig.defaultCurrencyUnit.multiplier,
714
default:true,
8-
decimalPlaces:8
15+
decimalPlaces:coinConfig.defaultCurrencyUnit.decimalPlaces
916
},
1017
"sat": {
1118
id: "sat",
1219
type:"native",
13-
name:"sat",
14-
multiplier:100000000,
15-
decimalPlaces:0
20+
name:coinConfig.baseCurrencyUnit.name,
21+
multiplier:coinConfig.baseCurrencyUnit.multiplier,
22+
decimalPlaces:coinConfig.baseCurrencyUnit.decimalPlaces
1623
},
1724
"usd": {
1825
id: "usd",
@@ -40,9 +47,18 @@ global.currencyTypes = {
4047
},
4148
};
4249

50+
coinConfig.currencyUnits.forEach(function(unit) {
51+
const aliases = [unit.name].concat(unit.values || []);
52+
aliases.filter(Boolean).forEach(function(alias) {
53+
global.currencyTypes[alias.toLowerCase()] = Object.assign({
54+
id: alias.toLowerCase()
55+
}, unit);
56+
});
57+
});
58+
4359
global.currencySymbols = {
44-
"btc": "₿",
60+
"btc": coinConfig.ticker == "BTC" ? "₿" : coinConfig.ticker,
4561
"usd": "$",
4662
"eur": "€",
4763
"gbp": "£"
48-
};
64+
};

test/qbit.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
const assert = require("assert");
44

5+
process.env.BTCEXP_COIN = "QBT";
6+
57
const coins = require("../app/coins.js");
68
const utils = require("../app/utils.js");
9+
require("../app/currencies.js");
710

811
const qbit = coins.QBT;
912

@@ -16,6 +19,9 @@ assert.strictEqual(qbit.blockRewardFunction(150, "regtest").toString(), "200.928
1619
assert.strictEqual(qbit.blockRewardFunction(43200 * 480, "main").toString(), "0");
1720
assert.strictEqual(qbit.currencyUnitsByName.bits.multiplier, 100000000);
1821
assert.strictEqual(qbit.currencyUnitsByName["µQBT"].multiplier, 1000000);
22+
assert.strictEqual(global.currencyTypes.btc.name, "QBT");
23+
assert.strictEqual(global.currencyTypes.sat.name, "bits");
24+
assert.strictEqual(utils.formatCurrencyAmount(210, "btc").currencyUnit, "QBT");
1925

2026
const p2mrAddress = "qb1z2dywzkum67x0r8kl3kx43wn3gnqrvs5ara8x9hws6x98xx4pe83s363m8e";
2127
assert.deepStrictEqual(utils.getVoutAddresses({

views/includes/shared-mixins.pug

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ mixin _valueDisplaySat(val, summarizeMin=Infinity, summarizeDecimals=3)
408408
span #{largeNumberData[1].abbreviation}
409409

410410
else
411-
span(class=(localCurrencyDisplay ? "border-dotted" : false), title=(localCurrencyDisplay ? `${utils.formatCurrencyAmount(val, coinConfig.defaultCurrencyUnit.name.toLowerCase()).simpleVal} BTC` : false), data-bs-toggle=(localCurrencyDisplay ? "tooltip" : false)) #{parts.intVal.toLocaleString()}
411+
span(class=(localCurrencyDisplay ? "border-dotted" : false), title=(localCurrencyDisplay ? `${utils.formatCurrencyAmount(val, coinConfig.defaultCurrencyUnit.name.toLowerCase()).simpleVal} ${coinConfig.defaultCurrencyUnit.name}` : false), data-bs-toggle=(localCurrencyDisplay ? "tooltip" : false)) #{parts.intVal.toLocaleString()}
412412

413413

414414
if (exchangeRates)
@@ -431,12 +431,12 @@ mixin _valueDisplayLocal(val, summarizeMin=Infinity, summarizeDecimals=3)
431431
if (Math.abs(parts.intVal) >= summarizeMin)
432432
- var largeNumberData = utils.formatLargeNumberSignificant(parts.intVal, summarizeDecimals >= 0 ? summarizeDecimals : 3);
433433
//span #{JSON.stringify(largeNumberData)} #{parts.intVal}
434-
span.border-dotted(title=`${global.currencySymbols[userSettings.localCurrency]}${parts.intVal.toLocaleString()}<br/>${utils.formatCurrencyAmount(val, coinConfig.defaultCurrencyUnit.name.toLowerCase()).simpleVal} BTC`, data-bs-toggle="tooltip", data-bs-html="true")
434+
span.border-dotted(title=`${global.currencySymbols[userSettings.localCurrency]}${parts.intVal.toLocaleString()}<br/>${utils.formatCurrencyAmount(val, coinConfig.defaultCurrencyUnit.name.toLowerCase()).simpleVal} ${coinConfig.defaultCurrencyUnit.name}`, data-bs-toggle="tooltip", data-bs-html="true")
435435
span #{largeNumberData[0]}
436436
span.ms-1 #{largeNumberData[1].textDesc}
437437

438438
else
439-
span.border-dotted(title=`${utils.formatCurrencyAmount(val, coinConfig.defaultCurrencyUnit.name.toLowerCase()).simpleVal} BTC`, data-bs-toggle="tooltip") #{parts.val}
439+
span.border-dotted(title=`${utils.formatCurrencyAmount(val, coinConfig.defaultCurrencyUnit.name.toLowerCase()).simpleVal} ${coinConfig.defaultCurrencyUnit.name}`, data-bs-toggle="tooltip") #{parts.val}
440440

441441

442442
mixin valueDisplaySpecial(val, maxDecimals=-1, summarizeAlways=false, summarizeMin=Infinity, summarizeDecimals=-1)
@@ -462,16 +462,16 @@ mixin valueDisplaySpecial(val, maxDecimals=-1, summarizeAlways=false, summarizeM
462462
//span #{JSON.stringify(parts)}
463463
- var largeNumberData = utils.formatLargeNumberSignificant(parts.intVal, summarizeDecimals >= 0 ? summarizeDecimals : 2);
464464
//span #{JSON.stringify(largeNumberData)} #{parts.intVal}
465-
span(class=(localCurrencyDisplay ? "border-dotted" : false), title=(localCurrencyDisplay ? `${utils.formatCurrencyAmount(val, coinConfig.defaultCurrencyUnit.name.toLowerCase()).simpleVal} BTC` : false), data-bs-toggle=(localCurrencyDisplay ? "tooltip" : false)) #{largeNumberData[0]} #{largeNumberData[1].textDesc}
465+
span(class=(localCurrencyDisplay ? "border-dotted" : false), title=(localCurrencyDisplay ? `${utils.formatCurrencyAmount(val, coinConfig.defaultCurrencyUnit.name.toLowerCase()).simpleVal} ${coinConfig.defaultCurrencyUnit.name}` : false), data-bs-toggle=(localCurrencyDisplay ? "tooltip" : false)) #{largeNumberData[0]} #{largeNumberData[1].textDesc}
466466

467467
else if (maxDecimals == 0)
468-
span(class=(localCurrencyDisplay ? "border-dotted" : false), title=(localCurrencyDisplay ? `${utils.formatCurrencyAmount(val, coinConfig.defaultCurrencyUnit.name.toLowerCase()).simpleVal} BTC` : false), data-bs-toggle=(localCurrencyDisplay ? "tooltip" : false)) #{parts.intVal.toLocaleString()}
468+
span(class=(localCurrencyDisplay ? "border-dotted" : false), title=(localCurrencyDisplay ? `${utils.formatCurrencyAmount(val, coinConfig.defaultCurrencyUnit.name.toLowerCase()).simpleVal} ${coinConfig.defaultCurrencyUnit.name}` : false), data-bs-toggle=(localCurrencyDisplay ? "tooltip" : false)) #{parts.intVal.toLocaleString()}
469469

470470
else if (maxDecimals > 0)
471-
span(class=(localCurrencyDisplay ? "border-dotted" : false), title=(localCurrencyDisplay ? `${utils.formatCurrencyAmount(val, coinConfig.defaultCurrencyUnit.name.toLowerCase()).simpleVal} BTC` : false), data-bs-toggle=(localCurrencyDisplay ? "tooltip" : false)) #{parts.val}
471+
span(class=(localCurrencyDisplay ? "border-dotted" : false), title=(localCurrencyDisplay ? `${utils.formatCurrencyAmount(val, coinConfig.defaultCurrencyUnit.name.toLowerCase()).simpleVal} ${coinConfig.defaultCurrencyUnit.name}` : false), data-bs-toggle=(localCurrencyDisplay ? "tooltip" : false)) #{parts.val}
472472

473473
else
474-
span(class=(localCurrencyDisplay ? "border-dotted" : false), title=(localCurrencyDisplay ? `${utils.formatCurrencyAmount(val, coinConfig.defaultCurrencyUnit.name.toLowerCase()).simpleVal} BTC` : false), data-bs-toggle=(localCurrencyDisplay ? "tooltip" : false)) #{parts.val}
474+
span(class=(localCurrencyDisplay ? "border-dotted" : false), title=(localCurrencyDisplay ? `${utils.formatCurrencyAmount(val, coinConfig.defaultCurrencyUnit.name.toLowerCase()).simpleVal} ${coinConfig.defaultCurrencyUnit.name}` : false), data-bs-toggle=(localCurrencyDisplay ? "tooltip" : false)) #{parts.val}
475475
if (parts.lessSignificantDigits)
476476
span.text-small.text-muted.ms-1 #{parts.lessSignificantDigits}
477477

views/layout-iframe.pug

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ html(lang="en")
3838
link(rel="manifest", href="./img/network-mainnet/site.webmanifest")
3939
link(rel="mask-icon", href="./img/network-mainnet/safari-pinned-tab.svg", color="#f7931a")
4040
link(rel="shortcut icon", href="./img/network-mainnet/favicon.ico")
41-
meta(name="apple-mobile-web-app-title", content="BTC Explorer")
42-
meta(name="application-name", content="BTC Explorer")
41+
meta(name="apple-mobile-web-app-title", content=`${coinConfig.ticker} Explorer`)
42+
meta(name="application-name", content=`${coinConfig.ticker} Explorer`)
4343
meta(name="msapplication-TileColor", content="#022e70")
4444
meta(name="msapplication-config", content="./img/network-mainnet/browserconfig.xml")
4545
meta(name="theme-color" content="#022e70")

views/layout.pug

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ html(lang="en")
4242
link(rel="manifest", href=`./img/network-${network}/site.webmanifest`)
4343
link(rel="mask-icon", href=`./img/network-${network}/safari-pinned-tab.svg`, color="#f7931a")
4444
link(rel="shortcut icon", href=assetUrl(`./img/network-${network}/favicon.ico`))
45-
meta(name="apple-mobile-web-app-title", content="BTC Explorer")
46-
meta(name="application-name", content="BTC Explorer")
45+
meta(name="apple-mobile-web-app-title", content=`${coinConfig.ticker} Explorer`)
46+
meta(name="application-name", content=`${coinConfig.ticker} Explorer`)
4747
meta(name="msapplication-TileColor", content="#022e70")
4848
meta(name="msapplication-config", content=`./img/network-${network}/browserconfig.xml`)
4949
meta(name="theme-color" content="#022e70")
@@ -136,17 +136,17 @@ html(lang="en")
136136
.dropdown-menu.dropdown-menu-end.shadow(aria-labelledby="navbarDropdown")
137137
span.dropdown-header Display Currency
138138

139-
- var items = ["BTC", "sat"];
139+
- var items = [{ label: coinConfig.defaultCurrencyUnit.name, value: "btc" }, { label: coinConfig.baseCurrencyUnit.name, value: "sat" }];
140140
if (config.queryExchangeRates && global.exchangeRates)
141-
- items.push("local");
141+
- items.push({ label: "local", value: "local" });
142142

143143
.btn-group.ms-3
144144
each item in items
145-
if (userSettings.displayCurrency == item.toLowerCase())
146-
span.btn.btn-primary.btn-sm #{item}
145+
if (userSettings.displayCurrency == item.value)
146+
span.btn.btn-primary.btn-sm #{item.label}
147147

148148
else
149-
a.btn.btn-outline-primary.btn-sm(href=`./changeSetting?name=displayCurrency&value=${item.toLowerCase()}`) #{item}
149+
a.btn.btn-outline-primary.btn-sm(href=`./changeSetting?name=displayCurrency&value=${item.value}`) #{item.label}
150150

151151
if (config.queryExchangeRates && global.exchangeRates)
152152
hr.dropdown-divider.mt-3.mb-1

0 commit comments

Comments
 (0)