Files
Ten31-Portal/frontend/public/sw.js
T
Jonathan Kirkwood 1dabbc3073 0.2.44: bitcoin terms value paid-in capital call by call
The LP portal's 'In bitcoin terms' box converted ALL paid-in capital at
the fund close date's BTC price, mispricing every mid-life capital call.
It now walks the statement history: the first statement's contributions
at the close-date entry mark, each later quarter's new contributions at
that statement date's price, and distributions at the price when
received. A dollar called later is no longer credited with bitcoin it
could never have bought. Funds with a single statement (and files
predating the uploaded price range) fall back to the close-date price.
Frontend only; shared by the LP portal and the admin Investor View.
2026-08-11 12:52:01 -05:00

57 lines
1.7 KiB
JavaScript

// Ten31 Portal service worker. Deliberately conservative so it never serves a stale app:
// - navigations are network-first (always get the latest index.html), cache only as offline fallback
// - content-hashed /assets/* are cache-first (immutable, safe forever)
// - /api/* is never cached
// Bump CACHE on each release so old entries are purged.
const CACHE = 'ten31-portal-0.2.44'
self.addEventListener('install', () => self.skipWaiting())
self.addEventListener('activate', (event) => {
event.waitUntil(
(async () => {
const keys = await caches.keys()
await Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k)))
await self.clients.claim()
})(),
)
})
self.addEventListener('fetch', (event) => {
const req = event.request
if (req.method !== 'GET') return
const url = new URL(req.url)
if (url.origin !== self.location.origin) return
if (url.pathname.startsWith('/api/')) return
if (req.mode === 'navigate') {
event.respondWith(
(async () => {
try {
const fresh = await fetch(req)
const cache = await caches.open(CACHE)
cache.put('/', fresh.clone())
return fresh
} catch {
const cache = await caches.open(CACHE)
return (await cache.match('/')) || Response.error()
}
})(),
)
return
}
if (url.pathname.startsWith('/assets/')) {
event.respondWith(
(async () => {
const cache = await caches.open(CACHE)
const hit = await cache.match(req)
if (hit) return hit
const res = await fetch(req)
if (res.ok) cache.put(req, res.clone())
return res
})(),
)
}
})