import { z } from 'zod'; import { apiClient } from '../client'; // Schema for redeeming tokens export const RedeemTokenRequestSchema = z.object({ token: z.string().min(1), }); export const RedeemTokenResponseSchema = z.object({ success: z.boolean(), amount: z.number().optional(), message: z.string().optional(), }); // Schema for sending tokens export const SendTokenRequestSchema = z.object({ amount: z.number().positive(), offline: z.boolean().optional(), }); export const SendTokenResponseSchema = z.object({ token: z.string(), balance: z.number(), npub: z.string().optional(), }); export type RedeemTokenRequest = z.infer; export type RedeemTokenResponse = z.infer; export type SendTokenRequest = z.infer; export type SendTokenResponse = z.infer; export class WalletService { static async redeemToken(token: string): Promise { try { const response = await apiClient.post( '/api/wallet/redeem', { token } ); return response; } catch (error) { console.error('Error redeeming token:', error); return { success: false, message: 'Failed to redeem token. Please try again.', }; } } static async sendToken(amount: number): Promise { try { const response = await apiClient.post( '/api/wallet/send', { amount } ); return response; } catch (error) { console.error('Error generating token:', error); throw new Error('Failed to generate token. Please try again.'); } } static async getBalance(): Promise<{ balance: number }> { try { const response = await apiClient.get<{ balance: number }>( '/api/wallet/balance' ); return response; } catch (error) { console.error('Error fetching balance:', error); throw error; } } static async getDetailedBalances(): Promise { try { const response = await apiClient.get( '/admin/api/balances' ); return response; } catch (error) { console.error('Error fetching detailed balances:', error); throw error; } } static async withdraw( amount: number, mintUrl?: string, unit: string = 'sat' ): Promise { try { const response = await apiClient.post( '/admin/withdraw', { amount, mint_url: mintUrl, unit, } ); return response; } catch (error) { console.error('Error withdrawing funds:', error); throw error; } } } export interface BalanceDetail { mint_url: string; unit: string; wallet_balance: number; user_balance: number; owner_balance: number; error?: string; } export interface WithdrawResponse { token: string; }