Show time estimate

This commit is contained in:
2023-07-06 22:21:30 +01:00
parent 6358c08246
commit 2eb0d7e7f9
3 changed files with 18 additions and 2 deletions

View File

@ -37,6 +37,16 @@ export function NostrProviderDialog({ provider, ...others }: { provider: StreamP
}} /> }} />
} }
function calcEstimate() {
if (!info?.rate || !info?.unit || !info?.balance || !info.balance) return;
const raw = Math.max(0, info.balance / info.rate);
if (info.unit === "min" && raw > 60) {
return `${(raw / 60).toFixed(0)} hour`
}
return `${raw.toFixed(0)} ${info.unit}`
}
const streamEvent = others.ev ?? info.publishedEvent ?? DummyEvent; const streamEvent = others.ev ?? info.publishedEvent ?? DummyEvent;
return <> return <>
<div> <div>
@ -66,6 +76,7 @@ export function NostrProviderDialog({ provider, ...others }: { provider: StreamP
Topup Topup
</button> </button>
</div> </div>
<small>About {calcEstimate()} @ {info.rate} sats/{info.unit}</small>
</div> </div>
{streamEvent && <StreamEditor onFinish={(ex) => { {streamEvent && <StreamEditor onFinish={(ex) => {
provider.updateStreamInfo(ex); provider.updateStreamInfo(ex);

View File

@ -48,6 +48,8 @@ export interface StreamProviderInfo {
ingressKey?: string ingressKey?: string
balance?: number balance?: number
publishedEvent?: NostrEvent publishedEvent?: NostrEvent
rate?: number
unit?: string
} }
export class ProviderStore extends ExternalStore<Array<StreamProvider>> { export class ProviderStore extends ExternalStore<Array<StreamProvider>> {

View File

@ -29,7 +29,9 @@ export class Nip103StreamProvider implements StreamProvider {
ingressUrl: rsp.url, ingressUrl: rsp.url,
ingressKey: rsp.key, ingressKey: rsp.key,
balance: rsp.quota.remaining, balance: rsp.quota.remaining,
publishedEvent: rsp.event publishedEvent: rsp.event,
rate: rsp.quota.rate,
unit: rsp.quota.unit
} as StreamProviderInfo } as StreamProviderInfo
} }
@ -45,8 +47,9 @@ export class Nip103StreamProvider implements StreamProvider {
const summary = findTag(ev, "summary"); const summary = findTag(ev, "summary");
const image = findTag(ev, "image"); const image = findTag(ev, "image");
const tags = ev?.tags.filter(a => a[0] === "t").map(a => a[1]); const tags = ev?.tags.filter(a => a[0] === "t").map(a => a[1]);
const contentWarning = findTag(ev, "content-warning");
await this.#getJson("PATCH", "event", { await this.#getJson("PATCH", "event", {
title, summary, image, tags title, summary, image, tags, content_warning: contentWarning
}); });
} }