Skip to content

Commit 7d1effc

Browse files
committed
assorted fixes and refactors
1 parent 2d12081 commit 7d1effc

8 files changed

Lines changed: 79 additions & 68 deletions

File tree

assets/js/bitrequest/bip39.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,11 @@ function bip39(dat) {
553553
</div>\
554554
</div>\
555555
</div>").data(dialog_data);
556+
// hasbip but no readable phrase = decrypt failed; refuse rather than fabricate a new seed
557+
if (glob_let.hasbip && !is_restore && !saved_phrase) {
558+
topnotify(tl("seederror"));
559+
return
560+
}
556561
if (inj(ui_state)) return // xss filter
557562
$("#sd_panel").html(markup).addClass(ui_state);
558563
glob_const.body.addClass("seed_dialog");

assets/js/bitrequest/fetchblocks.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,9 +2030,11 @@ function electrum_scan_data(data, setconfirmations, ccsymbol, script_pub, latest
20302030
height = data.height || 0,
20312031
timestamp = data.timestamp,
20322032
now = now_utc(),
2033-
now_correction = parseInt(now / 1000) - 8640,
2034-
time_correction = timestamp < now_correction ? now : timestamp, // correct weird timestamp in mempool with current timestamp
2035-
transactiontime = normalize_timestamp(time_correction) - 3000,
2033+
// Confirmed txs (height > 0) carry a real block time — use it.
2034+
// Fall back to "now" only for mempool/unconfirmed (height 0 or -1)
2035+
// or a missing/zero timestamp.
2036+
time_correction = (height > 0 && timestamp > 0) ? timestamp : now,
2037+
transactiontime = normalize_timestamp(time_correction),
20362038
confirmations = latest_block ? get_block_confirmations(height, latest_block) : height;
20372039
let outputsum = 0;
20382040
if (outputs) {

assets/js/bitrequest/lang_controller.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,37 @@ function systemlang() { // get system language
6262
(tl_short) ? lang_single : "en";
6363
}
6464

65+
const tl_cache = {}; // resolved no-data strings, keyed "langcode:id" (langcode is const per session)
66+
6567
function tl(id, dat) {
66-
const data = (dat) ? dat : {};
6768
if (id === "obj") {
6869
const languages = {};
6970
$.each(LANG_META, function(code, meta) {
7071
const fn = window[meta.fn];
7172
languages[code] = {
7273
"lang": meta.lang,
7374
"flag": meta.flag,
74-
"obj": typeof fn === "function" ? fn(id, data) : null
75+
"obj": typeof fn === "function" ? fn(id, dat || {}) : null
7576
};
7677
});
7778
return languages;
7879
}
79-
// Fast path: only the selected language + English fallback.
80+
// No-data lookups are deterministic per language — memoize so each lang function
81+
// (which rebuilds its full ~500-key object per call) runs at most once per id
82+
// instead of on every call. Calls WITH data interpolate and bypass the cache.
83+
if (!dat) {
84+
const key = langcode + ":" + id,
85+
cached = tl_cache[key];
86+
if (cached !== undefined) {
87+
return cached;
88+
}
89+
return tl_cache[key] = tl_resolve(id, {});
90+
}
91+
return tl_resolve(id, dat);
92+
}
93+
94+
// Resolve via the selected language, fall back to English, then the raw id.
95+
function tl_resolve(id, data) {
8096
try {
8197
const selected_meta = LANG_META[langcode],
8298
selected_fn = selected_meta && window[selected_meta.fn],

assets/js/bitrequest/lang_meta.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
const LANG_META = {
44
"en": {
55
"lang": "English",
6-
"flag": "🇺🇲",
6+
"flag": "🇺🇸",
77
"fn": "lang_en"
88
},
99
"nl": {
1010
"lang": "Dutch",
11-
"flag": "🇾🇪",
11+
"flag": "🇳🇱",
1212
"fn": "lang_nl"
1313
},
1414
"fr": {
@@ -51,4 +51,31 @@ const LANG_META = {
5151
"flag": "👾",
5252
"fn": "lang_ai2"
5353
}
54-
};
54+
};
55+
56+
// Pick saved/system language and synchronously inject the matching script tag.
57+
// Runs here (parser-blocking, after LANG_META) so document.write lands before the
58+
// deferred app bundle that calls tl().
59+
(function() {
60+
const SUPPORTED = Object.keys(LANG_META);
61+
function pick_lang() {
62+
try {
63+
const cache = localStorage.getItem("bitrequest_settings");
64+
if (cache) {
65+
const parsed = JSON.parse(cache),
66+
saved = parsed && parsed[2] && parsed[2].selected;
67+
if (saved && saved.length > 0 && saved.length < 7 && SUPPORTED.indexOf(saved) > -1) {
68+
return saved;
69+
}
70+
}
71+
} catch (e) {}
72+
const nav_lang = (navigator.language || navigator.userLanguage || "en").toLowerCase();
73+
if (SUPPORTED.indexOf(nav_lang) > -1) return nav_lang;
74+
const short = nav_lang.split("-")[0];
75+
return SUPPORTED.indexOf(short) > -1 ? short : "en";
76+
}
77+
const lang = pick_lang();
78+
if (lang !== "en") {
79+
document.write('<script src="assets/js/bitrequest/lang/' + lang.replace(/-/g, "_") + '.js"><\/script>');
80+
}
81+
})();

assets/js/bitrequest/monitors.js

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -252,28 +252,17 @@ function route_api_request(rd, api_data, rdo) {
252252
}
253253

254254
// Routes cryptocurrency requests to specific API endpoints based on provider capabilities.
255+
// Invariant: CRYPTO_API_DISPATCH_BY_PROVIDER (keyed on api_data.name) and
256+
// CRYPTO_API_DISPATCH_BY_PAYMENT (keyed on rd.payment) have disjoint keyspaces — the
257+
// payment-routed coins (nimiq/kaspa/monero) use bespoke providers absent from the
258+
// provider table, so no request resolves in both. The provider-first || precedence is
259+
// therefore unambiguous. If a payment-routed coin ever also gains a provider-table
260+
// provider, that precedence becomes load-bearing — add an explicit handler key then.
255261
function route_crypto_api(rd, api_data, rdo) {
256-
// First seven provider checks (mempool.space → blockchair).
257-
const provider_order_1 = ["mempool.space", "blockchain.info", "blockcypher",
258-
"etherscan", "alchemy", "ethplorer", "blockchair"
259-
];
260-
if (provider_order_1.indexOf(api_data.name) > -1) {
261-
CRYPTO_API_DISPATCH_BY_PROVIDER[api_data.name](rd, api_data, rdo);
262-
return
263-
}
264-
// nimiq sits between blockchair and dash.org — preserved.
265-
if (rd.payment === "nimiq") {
266-
CRYPTO_API_DISPATCH_BY_PAYMENT.nimiq(rd, api_data, rdo);
267-
return
268-
}
269-
if (api_data.name === "dash.org") {
270-
CRYPTO_API_DISPATCH_BY_PROVIDER["dash.org"](rd, api_data, rdo);
271-
return
272-
}
273-
// Remaining payment checks (kaspa, monero).
274-
const by_payment = CRYPTO_API_DISPATCH_BY_PAYMENT[rd.payment];
275-
if (by_payment) {
276-
by_payment(rd, api_data, rdo);
262+
const handler = CRYPTO_API_DISPATCH_BY_PROVIDER[api_data.name]
263+
|| CRYPTO_API_DISPATCH_BY_PAYMENT[rd.payment];
264+
if (handler) {
265+
handler(rd, api_data, rdo);
277266
return
278267
}
279268
finalize_request_state(rdo);

assets/js/bitrequest/sockets.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -166,17 +166,14 @@ function init_socket(socket_node, wallet_address, retry, foreground) {
166166
}
167167
glob_let.socket_attempt[sha_sub(socket_node.url || node_name, 15)] = true;
168168

169-
// Original branch order is monero → ethereum/erc20 → other coins.
170-
// Preserve that explicitly so payment_type="monero" + erc20=true still
171-
// routes to monero (matches pre-refactor behavior).
172-
let handler;
173-
if (payment_type === "monero") {
174-
handler = SOCKET_HANDLERS.monero;
175-
} else if (payment_type === "ethereum" || request.erc20) {
176-
handler = SOCKET_HANDLERS.ethereum;
177-
} else {
178-
handler = SOCKET_HANDLERS[payment_type];
179-
}
169+
// erc20 is a cross-cutting flag, not a payment key: an ERC20 token's
170+
// payment_type isn't "ethereum", so the flag must override the table lookup
171+
// and route it to the ethereum socket. That precedence is the one piece of
172+
// ordering here that does real work; everything else is a plain table lookup
173+
// (monero included — SOCKET_HANDLERS.monero is reached via the fallback).
174+
const handler = (payment_type === "ethereum" || request.erc20)
175+
? SOCKET_HANDLERS.ethereum
176+
: SOCKET_HANDLERS[payment_type];
180177
if (handler) handler(socket_node, wallet_address, retry);
181178
}
182179

assets/js/lib/global_queries.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const br_bipobj = br_get_local("bpdat", true),
6464
glob_const = {
6565
// --- App metadata ---
6666
"apptitle": "Bitrequest",
67-
"proxy_version": "0.034",
67+
"proxy_version": "0.035",
6868
"androidpackagename": br_androidpackagename,
6969
"approot": br_approot,
7070
"hostname": br_hostname,

index.html

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<!DOCTYPE html>
22
<html class="firstload">
33
<head>
4+
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' data: https://fonts.gstatic.com; img-src 'self' data: blob: https:; connect-src * ws: wss:; worker-src 'self' blob:; media-src 'self'; object-src 'none'; base-uri 'self'" />
45
<meta name="robots" content="noindex" />
56
<meta charset="utf-8" />
67
<meta name="google" content="notranslate" />
@@ -19,32 +20,6 @@
1920
<meta name="theme-color" content="#4D5359" />
2021
<meta name="color-scheme" content="light only" />
2122
<script src="assets/js/bitrequest/lang_meta.js"></script>
22-
<script>
23-
// Pick saved/system language and synchronously inject the matching script tag.
24-
(function() {
25-
const SUPPORTED = Object.keys(LANG_META);
26-
function pick_lang() {
27-
try {
28-
const cache = localStorage.getItem("bitrequest_settings");
29-
if (cache) {
30-
const parsed = JSON.parse(cache),
31-
saved = parsed && parsed[2] && parsed[2].selected;
32-
if (saved && saved.length > 0 && saved.length < 7 && SUPPORTED.indexOf(saved) > -1) {
33-
return saved;
34-
}
35-
}
36-
} catch (e) {}
37-
const nav_lang = (navigator.language || navigator.userLanguage || "en").toLowerCase();
38-
if (SUPPORTED.indexOf(nav_lang) > -1) return nav_lang;
39-
const short = nav_lang.split("-")[0];
40-
return SUPPORTED.indexOf(short) > -1 ? short : "en";
41-
}
42-
const lang = pick_lang();
43-
if (lang !== "en") {
44-
document.write('<script src="assets/js/bitrequest/lang/' + lang.replace(/-/g, "_") + '.js"><\/script>');
45-
}
46-
})();
47-
</script>
4823
<link rel="icon" type="image/x-icon" href="https://bitrequest.github.io/favicon.ico">
4924
<link rel="apple-touch-icon" sizes="180x180" href="assets/img/icons/apple-touch-icon.png">
5025
<link rel="shortcut icon" type="image/png" sizes="32x32" href="assets/img/icons/favicon-32x32.png">

0 commit comments

Comments
 (0)