From 7d48b36be8c9626820157e7ecc407630a5597436 Mon Sep 17 00:00:00 2001 From: 9qeklajc Date: Fri, 13 Mar 2026 22:23:50 +0100 Subject: [PATCH] add missing refund button --- ui/components/provider-card.tsx | 78 ++++++++++++++++++++++++++++++--- 1 file changed, 73 insertions(+), 5 deletions(-) diff --git a/ui/components/provider-card.tsx b/ui/components/provider-card.tsx index 480d4d1c..b48dc64b 100644 --- a/ui/components/provider-card.tsx +++ b/ui/components/provider-card.tsx @@ -19,11 +19,15 @@ import { Pencil, Trash2, Key, + RotateCcw, } from 'lucide-react'; import { ProviderBalance } from '@/components/provider-balance'; import { ProviderModelsPanel } from '@/components/provider-models-panel'; import { RoutstrCreateKeySection } from '@/components/providers/RoutstrCreateKeySection'; +import { RoutstrProviderService } from '@/lib/api/services/routstr-provider'; +import { useMutation, useQueryClient } from '@tanstack/react-query'; import { useState } from 'react'; +import { toast } from 'sonner'; import { cn } from '@/lib/utils'; import { Dialog, @@ -71,8 +75,28 @@ export function ProviderCard({ onOverrideModel, onUpdateApiKey, }: ProviderCardProps) { + const queryClient = useQueryClient(); const [isKeyModalOpen, setIsKeyModalOpen] = useState(false); const hasDetails = Boolean(provider.api_version) || isExpanded; + const isRoutstr = provider.provider_type === 'routstr'; + + const refundMutation = useMutation({ + mutationFn: () => RoutstrProviderService.refundBalance(provider.id), + onSuccess: (data) => { + if (data.ok) { + toast.success('Refund successful', { description: data.message }); + queryClient.invalidateQueries({ + queryKey: ['provider-balance', provider.id], + }); + queryClient.invalidateQueries({ queryKey: ['balances'] }); + } else { + toast.error('Refund failed', { description: data.message }); + } + }, + onError: (error: Error) => { + toast.error(`Refund error: ${error.message}`); + }, + }); return ( @@ -112,7 +136,7 @@ export function ProviderCard({ )} - {provider.provider_type === 'routstr' && ( + {isRoutstr && ( + )} +