feat: похуйу

This commit is contained in:
2026-05-12 23:14:45 +03:00
parent 2bea3f5eea
commit 35e537933e
8 changed files with 115 additions and 29 deletions

View File

@@ -0,0 +1,46 @@
import { getCsrfToken } from '@shared/api/csrf'
const PAYMENT_API_URL = 'https://app.payment.elcsa.ru'
export interface PaymentConfig {
status_code: number
usdt_exchange_rate: string
gas_fee: string
service_fee_rate: string
one_usdt_service_fee: string
one_usdt_total_price: string
created_at: string
}
export interface PaymentQuote {
status_code: number
usdt_amount: string
usdt_exchange_rate: string
gas_fee: string
service_fee: string
total_price: string
service_fee_rate: string
created_at: string
}
export async function getPaymentConfig(): Promise<PaymentConfig> {
const csrf = await getCsrfToken()
const res = await fetch(`${PAYMENT_API_URL}/config`, {
credentials: 'include',
headers: { 'X-CSRF-Token': csrf },
})
const data = await res.json()
if (!res.ok) throw data
return data
}
export async function getPaymentQuote(usdtAmount: number): Promise<PaymentQuote> {
const csrf = await getCsrfToken()
const res = await fetch(`${PAYMENT_API_URL}/payment/quote?usdt_amount=${usdtAmount}`, {
credentials: 'include',
headers: { 'X-CSRF-Token': csrf },
})
const data = await res.json()
if (!res.ok) throw data
return data
}

View File

@@ -0,0 +1,11 @@
import { useQuery } from '@tanstack/react-query'
import { getPaymentConfig } from '../api/paymentApi'
import type { PaymentConfig } from '../api/paymentApi'
export function usePaymentConfig() {
return useQuery<PaymentConfig>({
queryKey: ['payment', 'config'],
queryFn: getPaymentConfig,
staleTime: 60_000,
})
}

View File

@@ -0,0 +1,12 @@
import { useQuery } from '@tanstack/react-query'
import { getPaymentQuote } from '../api/paymentApi'
import type { PaymentQuote } from '../api/paymentApi'
export function usePaymentQuote(usdtAmount: number) {
return useQuery<PaymentQuote>({
queryKey: ['payment', 'quote', usdtAmount],
queryFn: () => getPaymentQuote(usdtAmount),
enabled: usdtAmount > 0,
staleTime: 30_000,
})
}

View File

@@ -0,0 +1,3 @@
export { usePaymentConfig } from './hooks/usePaymentConfig'
export { usePaymentQuote } from './hooks/usePaymentQuote'
export type { PaymentConfig, PaymentQuote } from './api/paymentApi'