Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/CheckoutModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ function CheckoutModal({
}) {
const [tab, setTab] = useState<'wallet' | 'qr'>('wallet')
const [copied, setCopied] = useState(false)
const [solPrice, setSolPrice] = useState<number>(165)
const [solPrice, setSolPrice] = useState<number | null>(null)
const [selectedToken, setSelectedToken] = useState<Token>('SOL')
const { payment, error } = usePaymentStatus(paymentId, config)
const { display: timerDisplay } = useCountdown(payment?.expires_at ?? null)
Expand All @@ -388,15 +388,23 @@ function CheckoutModal({
const isProcessing = ['detected', 'swapping'].includes(payment?.status ?? '')
const showActions = !isTerminal && !isProcessing

// Prefer the price the backend already attached to the payment object
// (no extra HTTP roundtrip, and matches the price used at payment creation).
// Fall back to GET /api/price/sol once for backends that don't yet return it.
useEffect(() => {
if (payment?.sol_price_usd && payment.sol_price_usd > 0) {
setSolPrice(payment.sol_price_usd)
return
}
if (solPrice != null) return
fetch(`${config.apiUrl}/api/price/sol`, { headers: { 'x-api-key': config.apiKey } })
.then(r => r.json())
.then(d => { if (d.sol_usd) setSolPrice(d.sol_usd) })
.catch(() => { })
}, [])
}, [payment?.sol_price_usd])

const amountUsdc = payment ? Number(payment.amount_usdc) : 0
const amountSol = amountUsdc / solPrice
const amountSol = solPrice && solPrice > 0 ? amountUsdc / solPrice : 0

const copyAddress = () => {
if (!payment?.deposit_address) return
Expand Down
6 changes: 6 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ export interface Payment {
status: PaymentStatus
expires_at: string
created_at: string
/**
* Live SOL/USD price the backend used at the time this payment object
* was returned. Cached server-side (30s TTL). Optional for
* compatibility with older backends that don't return it.
*/
sol_price_usd?: number
}

export interface FluxPayConfig {
Expand Down