feat: balance history
This commit is contained in:
parent
171ace38bd
commit
bd312f553f
@ -56,6 +56,7 @@ export function NewStream({ ev, onFinish }: Omit<StreamEditorProps, "onFinish">
|
|||||||
showEndpoints={false}
|
showEndpoints={false}
|
||||||
showEditor={true}
|
showEditor={true}
|
||||||
showForwards={false}
|
showForwards={false}
|
||||||
|
showBalanceHistory={false}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
25
src/element/provider/nostr/history.tsx
Normal file
25
src/element/provider/nostr/history.tsx
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { BalanceHistoryResult, NostrStreamProvider } from "@/providers/zsz";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { FormattedMessage } from "react-intl";
|
||||||
|
|
||||||
|
export default function BalanceHistory({ provider }: { provider?: NostrStreamProvider }) {
|
||||||
|
const [page,] = useState(0);
|
||||||
|
const [rows, setRows] = useState<BalanceHistoryResult>();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!provider) return;
|
||||||
|
provider.history(page)
|
||||||
|
.then(setRows);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return <div className="grid auto-rows-auto grid-cols-3 gap-1">
|
||||||
|
<div><FormattedMessage defaultMessage="Time" /></div>
|
||||||
|
<div><FormattedMessage defaultMessage="Description" /></div>
|
||||||
|
<div><FormattedMessage defaultMessage="Amount" /></div>
|
||||||
|
{rows?.items.map(a => <>
|
||||||
|
<div>{new Date(a.created * 1000).toLocaleString()}</div>
|
||||||
|
<div>{a.desc}</div>
|
||||||
|
<div>{a.type === 0 ? "+" : "-"}{a.amount}</div>
|
||||||
|
</>)}
|
||||||
|
</div>
|
||||||
|
}
|
@ -14,18 +14,21 @@ import { AddForwardInputs } from "./fowards";
|
|||||||
import StreamKey from "./stream-key";
|
import StreamKey from "./stream-key";
|
||||||
import AccountTopup from "./topup";
|
import AccountTopup from "./topup";
|
||||||
import AccountWithdrawl from "./withdraw";
|
import AccountWithdrawl from "./withdraw";
|
||||||
|
import BalanceHistory from "./history";
|
||||||
|
|
||||||
export default function NostrProviderDialog({
|
export default function NostrProviderDialog({
|
||||||
provider,
|
provider,
|
||||||
showEndpoints,
|
showEndpoints,
|
||||||
showEditor,
|
showEditor,
|
||||||
showForwards,
|
showForwards,
|
||||||
|
showBalanceHistory,
|
||||||
...others
|
...others
|
||||||
}: {
|
}: {
|
||||||
provider: NostrStreamProvider;
|
provider: NostrStreamProvider;
|
||||||
showEndpoints: boolean;
|
showEndpoints: boolean;
|
||||||
showEditor: boolean;
|
showEditor: boolean;
|
||||||
showForwards: boolean;
|
showForwards: boolean;
|
||||||
|
showBalanceHistory: boolean;
|
||||||
} & StreamEditorProps) {
|
} & StreamEditorProps) {
|
||||||
const system = useContext(SnortContext);
|
const system = useContext(SnortContext);
|
||||||
const [topup, setTopup] = useState(false);
|
const [topup, setTopup] = useState(false);
|
||||||
@ -257,11 +260,27 @@ export default function NostrProviderDialog({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function balanceHist() {
|
||||||
|
if (!info || !showBalanceHistory) return;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col gap-4">
|
||||||
|
<h3>
|
||||||
|
<FormattedMessage defaultMessage="Balance History" />
|
||||||
|
</h3>
|
||||||
|
<div className="flex flex-col gap-1">
|
||||||
|
<BalanceHistory provider={provider}/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{showEndpoints && streamEndpoints()}
|
{showEndpoints && streamEndpoints()}
|
||||||
{streamEditor()}
|
{streamEditor()}
|
||||||
{forwardInputs()}
|
{forwardInputs()}
|
||||||
|
{balanceHist()}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ export function DashboardSettingsButton({ ev }: { ev?: TaggedNostrEvent }) {
|
|||||||
showEndpoints={true}
|
showEndpoints={true}
|
||||||
showForwards={true}
|
showForwards={true}
|
||||||
showEditor={false}
|
showEditor={false}
|
||||||
|
showBalanceHistory={false}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
@ -17,6 +17,7 @@ export function StreamSettingsTab() {
|
|||||||
showEndpoints={true}
|
showEndpoints={true}
|
||||||
showEditor={false}
|
showEditor={false}
|
||||||
showForwards={true}
|
showForwards={true}
|
||||||
|
showBalanceHistory={true}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
@ -92,7 +92,7 @@ export class NostrStreamProvider implements StreamProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async withdraw(invoice: string) {
|
async withdraw(invoice: string) {
|
||||||
return await this.#getJson<{ fee: number; preimage: string }>("POST", `withdraw?invoice=${invoice}`);
|
return await this.#getJson<{ fee: number; preimage: string, error?: string }>("POST", `withdraw?invoice=${invoice}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async acceptTos(): Promise<void> {
|
async acceptTos(): Promise<void> {
|
||||||
@ -144,6 +144,10 @@ export class NostrStreamProvider implements StreamProvider {
|
|||||||
return `${this.url}clip/${id}/${clipId}`;
|
return `${this.url}clip/${id}/${clipId}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async history(page = 0, pageSize = 100) {
|
||||||
|
return await this.#getJson<BalanceHistoryResult>("GET", `history?page=${page}&pageSize=${pageSize}`);
|
||||||
|
}
|
||||||
|
|
||||||
async #getJson<T>(method: "GET" | "POST" | "PATCH" | "DELETE", path: string, body?: unknown): Promise<T> {
|
async #getJson<T>(method: "GET" | "POST" | "PATCH" | "DELETE", path: string, body?: unknown): Promise<T> {
|
||||||
const pub = (() => {
|
const pub = (() => {
|
||||||
if (this.#publisher) {
|
if (this.#publisher) {
|
||||||
@ -205,3 +209,14 @@ interface IngestEndpoint {
|
|||||||
interface TopUpResponse {
|
interface TopUpResponse {
|
||||||
pr: string;
|
pr: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface BalanceHistoryResult {
|
||||||
|
items: Array<{
|
||||||
|
created: number,
|
||||||
|
type: number,
|
||||||
|
amount: number,
|
||||||
|
desc?: string
|
||||||
|
}>
|
||||||
|
page: number,
|
||||||
|
pageSize: number
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user