Versie 0.2.0
This commit is contained in:
commit
e77d8fd373
495 files changed
+81026
No files matched your search
@@ -0,0 +1,30 @@
|
||||
// Generated, do not edit. sha256:7227a0859017790e220d3094fb16cfe6c1e290c2297569d78de93f970684ea0d
|
||||
import { intradaySeries } from '../data/market.js';
|
||||
import { currentRate } from './providers.js';
|
||||
import { t } from '../i18n/index.js';
|
||||
|
||||
const FRESH_MS = 60_000;
|
||||
const memo = new Map();
|
||||
const NONE = Object.freeze({ points: null });
|
||||
|
||||
async function toBase(r) {
|
||||
if (r.status !== 'ok') return NONE;
|
||||
const rate = await currentRate(r.currency);
|
||||
if (rate == null) return NONE;
|
||||
const named = src => t('marketService.sourceLive', { source: src });
|
||||
const src = r.sourceLabel || r.source;
|
||||
const source = src ? named(src) : t('connections.kindMarket');
|
||||
const sources = new Map();
|
||||
for (const [ms, , own] of r.points) if (own) sources.set(ms, named(own));
|
||||
return { points: r.points.map(([ms, p]) => [ms, p * rate]), source, sources };
|
||||
}
|
||||
|
||||
export async function loadIntraday(assetId, sinceMs) {
|
||||
const hit = memo.get(assetId);
|
||||
if (hit && hit.since === sinceMs && Date.now() - hit.at < FRESH_MS) return hit.result;
|
||||
let result;
|
||||
try { result = await toBase(await intradaySeries(assetId, sinceMs)); }
|
||||
catch { result = NONE; }
|
||||
memo.set(assetId, { at: Date.now(), since: sinceMs, result });
|
||||
return result;
|
||||
}
|
||||
Reference in new issue
Block a user