Add invoice payment dialog
This commit is contained in:
@@ -104,6 +104,7 @@ export type Invoice = {
|
||||
id: string
|
||||
tenant: string
|
||||
status: string
|
||||
amount: number
|
||||
created_at: number
|
||||
attempted_at: number
|
||||
error: string
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
updateTenantBilling,
|
||||
type Activity,
|
||||
type CreateRelayInput,
|
||||
type Invoice,
|
||||
type Relay,
|
||||
type Tenant,
|
||||
type UpdateRelayInput,
|
||||
@@ -129,6 +130,11 @@ export const updateRelayPlanById = (id: string, plan: string) => updateRelay(id,
|
||||
|
||||
export const deactivateRelayById = (id: string) => deactivateRelay(id)
|
||||
|
||||
export async function checkPendingInvoice(): Promise<Invoice | undefined> {
|
||||
const invoices = await listTenantInvoices(account()!.pubkey)
|
||||
return invoices.find(inv => inv.status === "pending")
|
||||
}
|
||||
|
||||
export async function getRelayMembers(url: string) {
|
||||
const management = new RelayManagement(new NostrRelay(url), account()!.signer)
|
||||
|
||||
@@ -139,4 +145,4 @@ export async function getRelayMembers(url: string) {
|
||||
}
|
||||
}
|
||||
|
||||
export type { Activity, Relay, Tenant }
|
||||
export type { Activity, Invoice, Relay, Tenant }
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { createSignal } from "solid-js"
|
||||
import { updateRelayById, deactivateRelayById, type Relay } from "@/lib/hooks"
|
||||
import { updateRelayById, deactivateRelayById, checkPendingInvoice, type Invoice, type Relay } from "@/lib/hooks"
|
||||
import { setToastMessage } from "@/components/Toast"
|
||||
import type { PlanId } from "@/lib/api"
|
||||
|
||||
@@ -30,6 +30,7 @@ export default function useRelayToggles(
|
||||
{ refetch, mutate }: RelayActions,
|
||||
) {
|
||||
const [busy, setBusy] = createSignal(false)
|
||||
const [pendingInvoice, setPendingInvoice] = createSignal<Invoice | undefined>()
|
||||
|
||||
async function updateRelay(next: Relay, previous: Relay) {
|
||||
mutate(next)
|
||||
@@ -85,6 +86,11 @@ export default function useRelayToggles(
|
||||
setToastMessage(e instanceof Error ? e.message : "Failed to update relay plan")
|
||||
throw e
|
||||
}
|
||||
|
||||
if (plan !== "free") {
|
||||
const invoice = await checkPendingInvoice()
|
||||
if (invoice) setPendingInvoice(invoice)
|
||||
}
|
||||
}
|
||||
|
||||
const toggles = {
|
||||
@@ -97,5 +103,5 @@ export default function useRelayToggles(
|
||||
onToggleLivekitSupport: () => toggle("livekit_enabled", relay()?.plan !== "free"),
|
||||
}
|
||||
|
||||
return { busy, handleDeactivate, handleUpdatePlan, toggles }
|
||||
return { busy, handleDeactivate, handleUpdatePlan, pendingInvoice, clearPendingInvoice: () => setPendingInvoice(undefined), toggles }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user