global: snapshot

This commit is contained in:
nym21
2025-05-27 15:19:53 +02:00
parent 34919aba05
commit 93e01902e3
84 changed files with 2445 additions and 1394 deletions
+206 -92
View File
@@ -45,10 +45,17 @@
* "cagr" |
* "vB" |
* "performance" |
* "zscore"
* "sd" |
* "Epoch" |
* "Height" |
* "Type" |
* "zscore" |
* "Bytes"
* } Unit
*/
const localhost = window.location.hostname === "localhost";
function initPackages() {
const imports = {
async signals() {
@@ -682,110 +689,217 @@ function createUtils() {
});
}
const thoroughUnitCheck = localhost;
/**
* @param {VecId} id
*/
function vecidToUnit(id) {
/** @type {Unit} */
/** @type {Unit | undefined} */
let unit;
if (id.endsWith("zscore")) {
unit = "zscore";
} else if (id.endsWith("cagr")) {
unit = "cagr";
} else if (id.endsWith("returns")) {
unit = "performance";
} else if (id === "drawdown" || id.endsWith("oscillator")) {
unit = "percentage";
} else if (id.endsWith("-as-price")) {
unit = "USD";
} else if (id.includes("type")) {
unit = "Type";
} else if (id.includes("days-")) {
unit = "Days";
} else if (id.includes("years-")) {
unit = "Years";
} else if (id === "rawlocktime") {
unit = "Locktime";
} else if (id.startsWith("is-")) {
unit = "Bool";
} else if (
id.includes("bytes") ||
id.includes("hash") ||
id.includes("address") ||
id.includes("txid")
if (
(!unit || thoroughUnitCheck) &&
(id.includes("in-sats") ||
id.endsWith("supply") ||
id.endsWith("stack") ||
id.endsWith("value") ||
((id.includes("coinbase") ||
id.includes("fee") ||
id.includes("subsidy") ||
id.includes("rewards")) &&
!(
id.startsWith("is-") ||
id.includes("in-btc") ||
id.includes("in-usd")
)))
) {
unit = "Hash";
} else if (id.includes("interval")) {
unit = "Seconds";
} else if (id.includes("feerate")) {
unit = "sat/vB";
} else if (id.includes("in-cents")) {
unit = "Cents";
} else if (id.includes("in-usd")) {
unit = "USD";
} else if (id.includes("ratio")) {
unit = "Ratio";
} else if (id.includes("in-btc")) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "Sats";
}
if ((!unit || thoroughUnitCheck) && id.includes("in-btc")) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "BTC";
} else if (
id.includes("in-sats") ||
id.startsWith("sats-") ||
id.includes("input-value") ||
id.includes("output-value") ||
id.includes("fee") ||
id.includes("coinbase") ||
id.includes("subsidy") ||
id.endsWith("stack") ||
id.includes("supply") ||
id.includes("rewards") ||
id.includes("realized-cap")
) {
unit = "Sats";
} else if (
id.includes("open") ||
id.includes("high") ||
id.includes("low") ||
id.includes("close") ||
id.includes("ohlc") ||
id.includes("marketcap") ||
id.includes("ath") ||
id.includes("-sma") ||
id.endsWith("-price") ||
id.startsWith("price-") ||
id.startsWith("realized-")
}
if (
(!unit || thoroughUnitCheck) &&
(id === "high" ||
id === "ohlc" ||
id === "low" ||
id === "close" ||
id === "open" ||
id === "marketcap" ||
id.startsWith("price") ||
id.endsWith("price") ||
id.endsWith("value-created") ||
id.endsWith("value-destroyed") ||
id.endsWith("realized-cap") ||
id.endsWith("realized-loss") ||
id.endsWith("realized-loss-sum") ||
id.endsWith("realized-profit") ||
id.endsWith("realized-profit-sum") ||
id.includes("in-usd") ||
(!id.includes("ratio") && id.endsWith("sma")) ||
id.endsWith("ath"))
) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "USD";
} else if (id.includes("count") || id.match(/v[1-3]/g)) {
unit = "Count";
} else if (id.includes("date")) {
unit = "Date";
} else if (id.includes("timestamp")) {
unit = "Timestamp";
} else if (
id.includes("index") ||
id.includes("height") ||
id.includes("epoch")
}
if ((!unit || thoroughUnitCheck) && id.endsWith("cents")) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "Cents";
}
if (
(!unit || thoroughUnitCheck) &&
(id.endsWith("ratio") ||
(id.includes("ratio") &&
(id.endsWith("-sma") ||
id.endsWith("-1w-sma") ||
id.endsWith("-1m-sma") ||
id.endsWith("-1y-sma"))) ||
id.endsWith("1sd") ||
id.endsWith("2sd") ||
id.endsWith("3sd") ||
id.endsWith("p0-1") ||
id.endsWith("p0-5") ||
id.endsWith("p1") ||
id.endsWith("p99") ||
id.endsWith("p99-5") ||
id.endsWith("p99-9"))
) {
unit = "Index";
} else if (id === "0" || id === "1" || id === "50" || id === "100") {
unit = "constant";
} else if (id.includes("difficulty")) {
unit = "Difficulty";
} else if (id.includes("-size")) {
unit = "mb";
} else if (id.includes("weight")) {
unit = "WU";
} else if (id.includes("vbytes") || id.includes("vsize")) {
unit = "vB";
} else if (id.includes("version")) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "Ratio";
}
if (
(!unit || thoroughUnitCheck) &&
(id === "drawdown" || id.endsWith("oscillator"))
) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "percentage";
}
if (
(!unit || thoroughUnitCheck) &&
(id.endsWith("count") ||
id.includes("-count-") ||
id.startsWith("block-count") ||
id.includes("tx-v"))
) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "Count";
}
if ((!unit || thoroughUnitCheck) && id.startsWith("is-")) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "Bool";
}
if ((!unit || thoroughUnitCheck) && id.endsWith("type")) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "Type";
}
if (
(!unit || thoroughUnitCheck) &&
(id === "interval" || id.startsWith("block-interval"))
) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "Seconds";
}
if ((!unit || thoroughUnitCheck) && id.endsWith("returns")) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "performance";
}
if ((!unit || thoroughUnitCheck) && id.endsWith("zscore")) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "zscore";
}
if ((!unit || thoroughUnitCheck) && id.endsWith("locktime")) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "Locktime";
}
if ((!unit || thoroughUnitCheck) && id.endsWith("cagr")) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "cagr";
}
if ((!unit || thoroughUnitCheck) && id.endsWith("version")) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "Version";
} else if (id === "value") {
unit = "Sats";
} else {
}
if (
(!unit || thoroughUnitCheck) &&
(id === "txid" || (id.endsWith("bytes") && !id.endsWith("vbytes")))
) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "Bytes";
}
if ((!unit || thoroughUnitCheck) && id.endsWith("standard-deviation")) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "sd";
}
if (
(!unit || thoroughUnitCheck) &&
(id.endsWith("-size") || id.endsWith("-size-sum"))
) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "mb";
}
if (
(!unit || thoroughUnitCheck) &&
(id.endsWith("vsize") ||
id.endsWith("vbytes") ||
id.endsWith("-vbytes-sum"))
) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "vB";
}
if ((!unit || thoroughUnitCheck) && id.includes("weight")) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "WU";
}
if ((!unit || thoroughUnitCheck) && id.endsWith("index")) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "Index";
}
if (
(!unit || thoroughUnitCheck) &&
(id === "date" || id === "date-fixed")
) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "Date";
}
if (
(!unit || thoroughUnitCheck) &&
(id === "timestamp" || id === "timestamp-fixed")
) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "Timestamp";
}
if ((!unit || thoroughUnitCheck) && id.endsWith("height")) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "Height";
}
if ((!unit || thoroughUnitCheck) && id.endsWith("epoch")) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "Epoch";
}
if ((!unit || thoroughUnitCheck) && id === "difficulty") {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "Difficulty";
}
if ((!unit || thoroughUnitCheck) && id === "blockhash") {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "Hash";
}
if (
(!unit || thoroughUnitCheck) &&
(id === "0" || id === "1" || id === "50" || id === "100")
) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "constant";
}
if (!unit) {
console.log();
throw Error(`Unit not set for "${id}"`);
}
return unit;
return /** @type {Unit} */ (unit);
}
const locale = {
@@ -1476,7 +1590,7 @@ function initEnv() {
iphone,
ipad,
ios,
localhost: window.location.hostname === "localhost",
localhost,
};
}
/** @typedef {ReturnType<typeof initEnv>} Env */
File diff suppressed because it is too large Load Diff
+9 -9
View File
@@ -720,13 +720,13 @@ export function init({
{
title: "Dollars Converted",
type: "Line",
color: colors.dollars,
color: colors.green,
data: totalInvestedAmountData,
},
{
title: "Dollars Left",
type: "Line",
color: colors.offDollars,
color: colors.emerald,
data: dollarsLeftData,
defaultActive: false,
},
@@ -758,7 +758,7 @@ export function init({
{
title: "Bitcoin Stack",
type: "Line",
color: colors.bitcoin,
color: colors.orange,
data: bitcoinData,
},
],
@@ -788,7 +788,7 @@ export function init({
{
title: "Average Price Paid",
type: "Line",
color: colors.lightDollars,
color: colors.lime,
data: averagePricePaidData,
},
],
@@ -1074,14 +1074,14 @@ export function init({
*/
const c = (c, t) => createColoredSpan({ color: c, text: t });
const serInvestedAmount = c("dollars", fd(investedAmount));
const serInvestedAmount = c("green", fd(investedAmount));
const serDaysCount = c("sky", f(daysCount));
const serSats = c("orange", f(sats));
const serBitcoin = c("orange", `~${f(bitcoin)}`);
const serBitcoinValue = c("amber", fd(bitcoinValue));
const serAveragePricePaid = c("lightDollars", fd(averagePricePaid));
const serAveragePricePaid = c("lime", fd(averagePricePaid));
const serRoi = c("yellow", fp(roi / 100));
const serDollars = c("offDollars", fd(dollars));
const serDollars = c("emerald", fd(dollars));
const serTotalFeesPaid = c("rose", fd(totalFeesPaid));
p1.innerHTML = `After exchanging ${serInvestedAmount} in the span of ${serDaysCount} days, you would have accumulated ${serSats} Satoshis (${serBitcoin} Bitcoin) worth today ${serBitcoinValue} at an average price of ${serAveragePricePaid} per Bitcoin with a return of investment of ${serRoi}, have ${serDollars} left and paid a total of ${serTotalFeesPaid} in fees.`;
@@ -1089,8 +1089,8 @@ export function init({
const dayDiff = Math.floor(
utils.date.differenceBetween(new Date(), lastInvestDay),
);
const serDailyInvestment = c("offDollars", fd(dailyInvestment));
const setLastSatsAdded = c("bitcoin", f(lastSatsAdded));
const serDailyInvestment = c("emerald", fd(dailyInvestment));
const setLastSatsAdded = c("orange", f(lastSatsAdded));
p2.innerHTML = `You would've last bought ${c("blue", dayDiff ? `${f(dayDiff)} ${dayDiff > 1 ? "days" : "day"} ago` : "today")} and exchanged ${serDailyInvestment} for approximately ${setLastSatsAdded} Satoshis`;
const serProfitableDaysRatio = c("green", fp(profitableDaysRatio));
File diff suppressed because it is too large Load Diff