Update api
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import { NostrEvent } from "@snort/system";
|
||||
import { StreamProvider, StreamProviderInfo } from "providers";
|
||||
import { StreamProvider, StreamProviderEndpoint, StreamProviderInfo } from "providers";
|
||||
import { useEffect, useState } from "react";
|
||||
import { SendZaps } from "./send-zap";
|
||||
import { StreamEditor, StreamEditorProps } from "./stream-editor";
|
||||
@ -11,9 +11,13 @@ const DummyEvent = { content: "", id: "", pubkey: "", sig: "", kind: LIVE_STREAM
|
||||
export function NostrProviderDialog({ provider, ...others }: { provider: StreamProvider } & StreamEditorProps) {
|
||||
const [topup, setTopup] = useState(false);
|
||||
const [info, setInfo] = useState<StreamProviderInfo>();
|
||||
const [ep, setEndpoint] = useState<StreamProviderEndpoint>();
|
||||
|
||||
useEffect(() => {
|
||||
provider.info().then(v => setInfo(v));
|
||||
provider.info().then(v => {
|
||||
setInfo(v);
|
||||
setEndpoint(v.endpoints[0]);
|
||||
});
|
||||
}, [provider]);
|
||||
|
||||
if (!info) {
|
||||
@ -38,30 +42,39 @@ export function NostrProviderDialog({ provider, ...others }: { provider: StreamP
|
||||
}
|
||||
|
||||
function calcEstimate() {
|
||||
if (!info?.rate || !info?.unit || !info?.balance || !info.balance) return;
|
||||
if (!ep?.rate || !ep?.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`
|
||||
const raw = Math.max(0, info.balance / ep.rate);
|
||||
if (ep.unit === "min" && raw > 60) {
|
||||
return `${(raw / 60).toFixed(0)} hour @ ${ep.rate} sats/${ep.unit}`
|
||||
}
|
||||
return `${raw.toFixed(0)} ${info.unit}`
|
||||
return `${raw.toFixed(0)} ${ep.unit} @ ${ep.rate} sats/${ep.unit}`
|
||||
}
|
||||
|
||||
const streamEvent = others.ev ?? info.publishedEvent ?? DummyEvent;
|
||||
return <>
|
||||
{info.endpoints.length > 1 && <div>
|
||||
<p>Endpoint</p>
|
||||
<div className="flex g12">
|
||||
{info.endpoints.map(a => <span className={`pill${ep?.name === a.name ? " active" : ""}`}
|
||||
onClick={() => setEndpoint(a)}>
|
||||
{a.name}
|
||||
</span>)}
|
||||
</div>
|
||||
</div>}
|
||||
<div>
|
||||
<p>Stream Url</p>
|
||||
<div className="paper">
|
||||
<input type="text" value={info.ingressUrl} disabled />
|
||||
<input type="text" value={ep?.url} disabled />
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<p>Stream Key</p>
|
||||
<div className="flex g12">
|
||||
<div className="paper f-grow">
|
||||
<input type="password" value={info.ingressKey} disabled />
|
||||
<input type="password" value={ep?.key} disabled />
|
||||
</div>
|
||||
<button className="btn btn-primary" onClick={() => window.navigator.clipboard.writeText(info.ingressKey ?? "")}>
|
||||
<button className="btn btn-primary" onClick={() => window.navigator.clipboard.writeText(ep?.key ?? "")}>
|
||||
Copy
|
||||
</button>
|
||||
</div>
|
||||
@ -76,7 +89,7 @@ export function NostrProviderDialog({ provider, ...others }: { provider: StreamP
|
||||
Topup
|
||||
</button>
|
||||
</div>
|
||||
<small>About {calcEstimate()} @ {info.rate} sats/{info.unit}</small>
|
||||
<small>About {calcEstimate()}</small>
|
||||
</div>
|
||||
{streamEvent && <StreamEditor onFinish={(ex) => {
|
||||
provider.updateStreamInfo(ex);
|
||||
|
Reference in New Issue
Block a user