bot-me / src /bots /services /CryptoService.ts
Mohammed Foud
all
d16c049
import { BotContext } from '../types/botTypes';
import { createLogger } from '../../utils/logger';
import { supabase } from '../../db/supabase';
const logger = createLogger('CryptoService');
export class CryptoService {
private static instance: CryptoService;
private readonly cryptoAddress: string;
private constructor(ctx: BotContext) {
this.cryptoAddress = ctx.botData?.crypto_wallet_address || '';
}
public static getInstance(ctx: BotContext): CryptoService {
if (!CryptoService.instance) {
CryptoService.instance = new CryptoService(ctx);
}
return CryptoService.instance;
}
async getPaymentAddress(userId: string, amount: number): Promise<string> {
try {
// Create payment record in database
const { data: payment, error } = await supabase
.from('payments')
.insert({
user_id: userId,
amount: amount,
status: 'PENDING',
payment_method: 'CRYPTO'
})
.select()
.single();
if (error) throw error;
return this.cryptoAddress;
} catch (error) {
logger.error('Error creating crypto payment:', error);
throw error;
}
}
}