feat: похуйу
This commit is contained in:
46
src/features/payment/api/paymentApi.ts
Normal file
46
src/features/payment/api/paymentApi.ts
Normal 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
|
||||
}
|
||||
11
src/features/payment/hooks/usePaymentConfig.ts
Normal file
11
src/features/payment/hooks/usePaymentConfig.ts
Normal 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,
|
||||
})
|
||||
}
|
||||
12
src/features/payment/hooks/usePaymentQuote.ts
Normal file
12
src/features/payment/hooks/usePaymentQuote.ts
Normal 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,
|
||||
})
|
||||
}
|
||||
3
src/features/payment/index.ts
Normal file
3
src/features/payment/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export { usePaymentConfig } from './hooks/usePaymentConfig'
|
||||
export { usePaymentQuote } from './hooks/usePaymentQuote'
|
||||
export type { PaymentConfig, PaymentQuote } from './api/paymentApi'
|
||||
Reference in New Issue
Block a user