Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 56 additions & 72 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,27 +561,20 @@
}

function hydrateBakedDemoRuntimeIfNeeded() {
if (!SATOSHI_BAKED_SNAPSHOT || !isFreshSatoshiDemoVault()) {
const demoGroupId = getBundledSatoshiDemoGroupId();
if (!SATOSHI_BAKED_SNAPSHOT || !demoGroupId) {
return false;
}

const bakedRuntime = SATOSHI_BAKED_SNAPSHOT.runtimeCache;
const bakedEntries = state.addresses.filter((entry) =>
Object.prototype.hasOwnProperty.call(SATOSHI_BAKED_SNAPSHOT.balancesByAddress, entry.address)
);
const bakedEntries = state.addresses.filter((entry) => entry.groupId === demoGroupId);
if (!bakedEntries.length) {
return false;
}

const shouldUseBakedDetails =
bakedRuntime &&
(!hasCompleteCachedCoverage(bakedEntries) ||
!hasCompleteDetailCoverage(bakedRuntime.historyScope, bakedEntries));
if (runtime.addressSnapshots.length && !shouldUseBakedDetails) {
return false;
}

const currentPriceUsd = Number.isFinite(bakedRuntime?.currentPriceUsd)
const currentPriceUsd = Number.isFinite(runtime.currentPriceUsd)
? runtime.currentPriceUsd
: Number.isFinite(bakedRuntime?.currentPriceUsd)
? bakedRuntime.currentPriceUsd
: SATOSHI_BAKED_SNAPSHOT.currentPriceUsd;
const timelineStart = Number.isFinite(bakedRuntime?.timelineStart)
Expand All @@ -596,6 +589,7 @@
const intradayEnd = Number.isFinite(bakedRuntime?.intradayEnd)
? bakedRuntime.intradayEnd
: null;
const existingById = getSnapshotsById();
const snapshots = bakedEntries.map((entry) => {
const bakedSnapshot = bakedRuntime?.snapshotsByAddress.get(entry.address);
if (!bakedSnapshot) {
Expand Down Expand Up @@ -637,31 +631,40 @@
approximate: bakedSnapshot.approximate,
detailScope: bakedSnapshot.detailScope,
};
}).filter((baked) => {
const existing = existingById.get(baked.entry.id);
if (!existing || !hasRequiredDetailScope(existing, baked.detailScope)) return true;
const savedCoverage = getCommonReliableDailyCoverage([existing]);
const bundledCoverage = getCommonReliableDailyCoverage([baked]);
// Only repair the public demo when its saved history cannot supply the
// month that the bundled data covers. Keep healthy, newer demo caches.
return bundledCoverage && (!savedCoverage || (
savedCoverage.end - savedCoverage.start < 29 * DAY_MS &&
bundledCoverage.end - bundledCoverage.start >= 29 * DAY_MS
));
});

if (!snapshots.length) {
return false;
}

replaceAddressSnapshots(snapshots);
runtime = {
...runtime,
hasLoadedOnce: true,
historyScope: bakedRuntime?.historyScope || "SUMMARY",
historyScope: pickHigherHistoryScope(runtime.historyScope, bakedRuntime?.historyScope),
currentPriceUsd,
fiatExchangeRates: bakedRuntime?.fiatExchangeRates || runtime.fiatExchangeRates,
priceHistory: bakedRuntime?.priceHistory || runtime.priceHistory,
intradayPriceHistory: bakedRuntime?.intradayPriceHistory || runtime.intradayPriceHistory,
fiatExchangeRates: mergeFiatExchangeRates(runtime.fiatExchangeRates, bakedRuntime?.fiatExchangeRates),
priceHistory: mergeNumberMaps(bakedRuntime?.priceHistory, runtime.priceHistory),
intradayPriceHistory: mergeNumberMaps(bakedRuntime?.intradayPriceHistory, runtime.intradayPriceHistory),
historyAvailable: bakedRuntime?.historyAvailable ?? runtime.historyAvailable,
historyMissingDays: bakedRuntime?.historyMissingDays ?? runtime.historyMissingDays,
addressSnapshots: snapshots,
partialFailures: [],
approximationMode:
Boolean(bakedRuntime?.approximationMode) || snapshots.some((snapshot) => snapshot.approximate),
timelineStart,
timelineEnd,
intradayStart,
intradayEnd,
banner: null,
Boolean(bakedRuntime?.approximationMode) || runtime.addressSnapshots.some((snapshot) => snapshot.approximate),
timelineStart: Number.isFinite(timelineStart) ? Math.min(runtime.timelineStart ?? timelineStart, timelineStart) : runtime.timelineStart,
timelineEnd: Number.isFinite(timelineEnd) ? Math.max(runtime.timelineEnd ?? timelineEnd, timelineEnd) : runtime.timelineEnd,
intradayStart: runtime.intradayStart ?? intradayStart,
intradayEnd: runtime.intradayEnd ?? intradayEnd,
};

StorageLayer.saveRuntimeCache(runtime);
Expand Down Expand Up @@ -2395,16 +2398,14 @@
: coverage.start,
end: coverage.end,
};
})
.filter(Boolean);
return getCommonCoverage(coverages);
});
return coverages.some((coverage) => !coverage) ? null : getCommonCoverage(coverages);
}

function getCommonTimelineCoverage(snapshots, timelineKey) {
const coverages = (Array.isArray(snapshots) ? snapshots : [])
.map((snapshot) => getTimelineCoverage(snapshot?.[timelineKey]))
.filter(Boolean);
return getCommonCoverage(coverages);
.map((snapshot) => getTimelineCoverage(snapshot?.[timelineKey]));
return coverages.some((coverage) => !coverage) ? null : getCommonCoverage(coverages);
}

function getTimelineCoverage(points) {
Expand Down Expand Up @@ -3294,10 +3295,11 @@
let dailyTimeline = [];
let reliableTimelineStart = null;
let hasReliableDailyTimeline = false;
if (hasDetailData && Number.isFinite(runtime.timelineStart) && Number.isFinite(runtime.timelineEnd)) {
const dailyCoverage = getCommonReliableDailyCoverage(detailSnapshots);
if (hasDetailData && dailyCoverage) {
reliableTimelineStart = getReliableTimelineStartForSnapshots(
detailSnapshots,
runtime.timelineStart,
dailyCoverage.start,
{
trimToFirstTransaction: requiredDetailScope === "ALL",
}
Expand All @@ -3306,7 +3308,7 @@
detailSnapshots,
runtime.priceHistory,
reliableTimelineStart,
runtime.timelineEnd
dailyCoverage.end
);
hasReliableDailyTimeline = dailyTimeline.length >= 2;
}
Expand All @@ -3319,13 +3321,14 @@

let intradayTimeline = [];
let hasReliableIntradayTimeline = false;
if (hasDetailData && Number.isFinite(runtime.intradayStart) && Number.isFinite(runtime.intradayEnd)) {
const intradayCoverage = getCommonTimelineCoverage(detailSnapshots, "hourlyBalanceTimeline");
if (hasDetailData && intradayCoverage) {
intradayTimeline = combineSnapshotTimelines(
detailSnapshots,
"hourlyBalanceTimeline",
runtime.intradayPriceHistory,
runtime.intradayStart,
runtime.intradayEnd,
intradayCoverage.start,
intradayCoverage.end,
{
stepMs: HOUR_MS,
alignTime: startOfUtcHour,
Expand Down Expand Up @@ -3398,10 +3401,11 @@
let dailyTimeline = [];
let reliableTimelineStart = null;
let hasReliableDailyTimeline = false;
if (hasDetailData && Number.isFinite(runtime.timelineStart) && Number.isFinite(runtime.timelineEnd)) {
const dailyCoverage = getCommonReliableDailyCoverage(snapshots);
if (hasDetailData && dailyCoverage) {
reliableTimelineStart = getReliableTimelineStartForSnapshots(
snapshots,
runtime.timelineStart,
dailyCoverage.start,
{
trimToFirstTransaction: requiredDetailScope === "ALL",
}
Expand All @@ -3410,7 +3414,7 @@
snapshots,
runtime.priceHistory,
reliableTimelineStart,
runtime.timelineEnd
dailyCoverage.end
);
hasReliableDailyTimeline = dailyTimeline.length >= 2;
}
Expand All @@ -3423,13 +3427,14 @@

let intradayTimeline = [];
let hasReliableIntradayTimeline = false;
if (hasDetailData && Number.isFinite(runtime.intradayStart) && Number.isFinite(runtime.intradayEnd)) {
const intradayCoverage = getCommonTimelineCoverage(snapshots, "hourlyBalanceTimeline");
if (hasDetailData && intradayCoverage) {
intradayTimeline = combineSnapshotTimelines(
snapshots,
"hourlyBalanceTimeline",
runtime.intradayPriceHistory,
runtime.intradayStart,
runtime.intradayEnd,
intradayCoverage.start,
intradayCoverage.end,
{
stepMs: HOUR_MS,
alignTime: startOfUtcHour,
Expand Down Expand Up @@ -3853,7 +3858,10 @@
balanceTimeline: buildDailyBalanceTimeline(
balanceSats,
txEvents,
timelineStart,
Math.min(...[
getTimelineStartTimestamp(currentSnapshot.balanceTimeline),
getOldestKnownTransactionTimestamp({ txEvents }),
].filter(Number.isFinite), endTimestamp),
endTimestamp
),
hourlyBalanceTimeline: buildIntervalBalanceTimeline(
Expand Down Expand Up @@ -5852,24 +5860,10 @@

let timeline = [];
if (dailySnapshots.length === addressCount) {
const latestSnapshotTimestamp = Math.max(
...dailySnapshots
.map((snapshot) => snapshot.balanceTimeline[snapshot.balanceTimeline.length - 1]?.timestamp)
.filter(Number.isFinite)
);
const endTimestamp = Number.isFinite(runtime.timelineEnd)
? runtime.timelineEnd
: latestSnapshotTimestamp;
const oldestSnapshotTimestamp = Math.min(
...dailySnapshots
.map((snapshot) => snapshot.balanceTimeline[0]?.timestamp)
.filter(Number.isFinite)
);
const timelineStart = Number.isFinite(runtime.timelineStart)
? runtime.timelineStart
: oldestSnapshotTimestamp;
const reliableTimelineStart = Number.isFinite(timelineStart)
? getReliableTimelineStartForSnapshots(dailySnapshots, timelineStart, {
const coverage = getCommonReliableDailyCoverage(dailySnapshots);
const endTimestamp = coverage?.end;
const reliableTimelineStart = coverage
? getReliableTimelineStartForSnapshots(dailySnapshots, coverage.start, {
trimToFirstTransaction: true,
})
: null;
Expand Down Expand Up @@ -7122,16 +7116,6 @@
return typeof value === "string" ? value.trim().replace(/\s+/g, " ").slice(0, 32) : "";
}

function isFreshSatoshiDemoVault() {
if (state.lastUpdated || state.addresses.length !== SATOSHI_DEMO_ADDRESSES.length) {
return false;
}

return state.addresses.every((entry) =>
SATOSHI_DEMO_ADDRESS_KEYS.has(normalizeBitcoinAddress(entry.address))
);
}

function formatBootstrapTimestamp(value) {
if (!value || Number.isNaN(Date.parse(value))) {
return "recently";
Expand Down
19 changes: 16 additions & 3 deletions assets/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,15 +396,28 @@
return false;
}

// A refresh of another wallet used to overwrite the shared bounds. Recover
// each all-history snapshot from its own transactions, even if its saved
// daily curve is non-flat but contains only a couple of days.
const dailyTimes = snapshot.balanceTimeline.map((point) => point.timestamp);
let dailyStart = dailyTimes.length ? Math.min(...dailyTimes) : timelineStart;
const dailyEnd = dailyTimes.length ? Math.max(...dailyTimes) : (snapshot.refreshedAt ?? timelineEnd);
const eventTimes = snapshot.txEvents.filter((event) => event.confirmed).map((event) => event.timestamp);
if (snapshot.detailScope === "ALL" && eventTimes.length) {
const oldestDay = Math.floor(Math.min(...eventTimes) / (24 * HOUR_MS)) * 24 * HOUR_MS;
dailyStart = Number.isFinite(dailyStart) ? Math.min(dailyStart, oldestDay) : oldestDay;
}

let rebuilt = false;
if (
shouldRebuildCachedTimeline(snapshot.balanceTimeline, snapshot.txEvents, timelineStart, timelineEnd)
(dailyTimes.length && Number.isFinite(dailyStart) && dailyStart < Math.min(...dailyTimes)) ||
shouldRebuildCachedTimeline(snapshot.balanceTimeline, snapshot.txEvents, dailyStart, dailyEnd)
) {
snapshot.balanceTimeline = buildDailyBalanceTimeline(
snapshot.balanceSats,
snapshot.txEvents,
timelineStart,
timelineEnd
dailyStart,
dailyEnd
);
rebuilt = true;
}
Expand Down
2 changes: 1 addition & 1 deletion docs/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Requests omit credentials and referrers, bypass the browser HTTP cache, and reje

## Satoshi Demo Snapshot

The bundled Satoshi demo wallet ships with bounded all-time per-address history and market data so a new browser can render the demo immediately.
The bundled Satoshi demo wallet ships with bounded all-time per-address history and market data so a new browser can render the demo immediately. Existing browsers rebuild shortened daily charts from their cached transactions on reload. If the public demo still lacks the month covered by the bundled snapshot, only its deficient address snapshots are restored; personal wallets and healthy demo caches are retained. Chart ranges and incremental demo refreshes use each address's own history bounds.

Regenerate the release asset with:

Expand Down
22 changes: 11 additions & 11 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
<link rel="apple-touch-icon" href="apple-touch-icon.png" sizes="180x180" />
<link rel="manifest" href="site.webmanifest" />
<title>Bitkit Watch</title>
<link rel="stylesheet" href="styles.css?v=0.1.5" />
<script src="assets/market-history.js?v=0.1.5" defer></script>
<script src="assets/api-validation.js?v=0.1.5" defer></script>
<script src="assets/satoshi-demo-snapshot.js?v=0.1.5" defer></script>
<script src="assets/bitcoin-facts.js?v=0.1.5" defer></script>
<script src="assets/storage.js?v=0.1.5" defer></script>
<script src="assets/api.js?v=0.1.5" defer></script>
<script src="assets/portfolio.js?v=0.1.5" defer></script>
<script src="assets/charts.js?v=0.1.5" defer></script>
<script src="app.js?v=0.1.5" defer></script>
<link rel="stylesheet" href="styles.css?v=0.1.6" />
<script src="assets/market-history.js?v=0.1.6" defer></script>
<script src="assets/api-validation.js?v=0.1.6" defer></script>
<script src="assets/satoshi-demo-snapshot.js?v=0.1.6" defer></script>
<script src="assets/bitcoin-facts.js?v=0.1.6" defer></script>
<script src="assets/storage.js?v=0.1.6" defer></script>
<script src="assets/api.js?v=0.1.6" defer></script>
<script src="assets/portfolio.js?v=0.1.6" defer></script>
<script src="assets/charts.js?v=0.1.6" defer></script>
<script src="app.js?v=0.1.6" defer></script>
</head>
<body>
<div class="app-shell">
Expand Down Expand Up @@ -371,7 +371,7 @@ <h2 id="faqTitle">
</div>
<div class="app-footer-content">
<p class="app-footer-copy">
<span>Bitkit Watch was built by Synonym Software, S.A. DE C.V. ©2026. All rights reserved. <span id="appVersion">v0.1.5</span> - <a href="https://github.com/synonymdev/bitkit-watch" target="_blank" rel="noopener noreferrer">Github</a>.</span>
<span>Bitkit Watch was built by Synonym Software, S.A. DE C.V. ©2026. All rights reserved. <span id="appVersion">v0.1.6</span> - <a href="https://github.com/synonymdev/bitkit-watch" target="_blank" rel="noopener noreferrer">Github</a>.</span>
<span class="app-footer-legal">
By using Bitkit Watch you declare that you have read and accept the
<a href="terms-of-use.html">terms of use</a> and
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bitkit-watch",
"version": "0.1.5",
"version": "0.1.6",
"private": true,
"description": "Static, watch-only Bitcoin portfolio. Dependencies are development tools only.",
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion privacy-policy.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<link rel="icon" href="favicon-16x16.png" sizes="16x16" type="image/png" />
<link rel="apple-touch-icon" href="apple-touch-icon.png" sizes="180x180" />
<title>Privacy Policy | Bitkit Watch</title>
<link rel="stylesheet" href="styles.css?v=0.1.5" />
<link rel="stylesheet" href="styles.css?v=0.1.6" />
</head>
<body class="legal-page">
<div class="app-shell">
Expand Down
2 changes: 1 addition & 1 deletion terms-of-use.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<link rel="icon" href="favicon-16x16.png" sizes="16x16" type="image/png" />
<link rel="apple-touch-icon" href="apple-touch-icon.png" sizes="180x180" />
<title>Terms of Use | Bitkit Watch</title>
<link rel="stylesheet" href="styles.css?v=0.1.5" />
<link rel="stylesheet" href="styles.css?v=0.1.6" />
</head>
<body class="legal-page">
<div class="app-shell">
Expand Down
Loading
Loading