fix(rcart): infer Transak fiat amount from crypto amount for stablecoins
When fiatAmount wasn't explicitly set on a payment request, Transak defaulted to 300 USD. Now for USDC/USDT/DAI/cUSDC, the fiat amount is inferred from the crypto amount (1:1 peg) so the widget opens with the correct payment amount. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
4d06156e5f
commit
15990cc147
|
|
@ -32,6 +32,9 @@ import {
|
|||
import { extractProductFromUrl } from './extract';
|
||||
import { createSecureWidgetUrl, extractRootDomain, getTransakApiKey, getTransakEnv } from '../../shared/transak';
|
||||
import { createMoonPayPaymentUrl, getMoonPayApiKey, getMoonPayEnv } from '../../shared/moonpay';
|
||||
|
||||
/** Tokens pegged 1:1 to USD — fiat amount can be inferred from crypto amount */
|
||||
const USD_STABLECOINS = ['USDC', 'USDT', 'DAI', 'cUSDC'];
|
||||
import QRCode from 'qrcode';
|
||||
import { createTransport, type Transporter } from "nodemailer";
|
||||
import {
|
||||
|
|
@ -1781,14 +1784,16 @@ routes.post("/api/payments/:id/transak-session", async (c) => {
|
|||
hideMenu: 'true',
|
||||
};
|
||||
|
||||
// Pre-fill fiat amount/currency so user sees the total immediately
|
||||
if (p.fiatAmount) {
|
||||
widgetParams.fiatAmount = p.fiatAmount;
|
||||
widgetParams.defaultFiatAmount = p.fiatAmount;
|
||||
// Derive fiat amount: use explicit fiatAmount, or infer from crypto amount for stablecoins
|
||||
const inferredFiat = p.fiatAmount || (USD_STABLECOINS.includes(p.token) ? effectiveAmount : null);
|
||||
if (inferredFiat) {
|
||||
widgetParams.fiatAmount = inferredFiat;
|
||||
widgetParams.defaultFiatAmount = inferredFiat;
|
||||
}
|
||||
if (p.fiatCurrency) {
|
||||
widgetParams.fiatCurrency = p.fiatCurrency;
|
||||
widgetParams.defaultFiatCurrency = p.fiatCurrency;
|
||||
const fiatCcy = p.fiatCurrency || (USD_STABLECOINS.includes(p.token) ? 'USD' : null);
|
||||
if (fiatCcy) {
|
||||
widgetParams.fiatCurrency = fiatCcy;
|
||||
widgetParams.defaultFiatCurrency = fiatCcy;
|
||||
}
|
||||
|
||||
const widgetUrl = await createSecureWidgetUrl(widgetParams);
|
||||
|
|
@ -1855,13 +1860,18 @@ routes.post("/api/payments/:id/card-session", async (c) => {
|
|||
themeColor: '6366f1',
|
||||
hideMenu: 'true',
|
||||
};
|
||||
if (p.fiatAmount) {
|
||||
widgetParams.fiatAmount = p.fiatAmount;
|
||||
widgetParams.defaultFiatAmount = p.fiatAmount;
|
||||
}
|
||||
if (p.fiatCurrency) {
|
||||
widgetParams.fiatCurrency = p.fiatCurrency;
|
||||
widgetParams.defaultFiatCurrency = p.fiatCurrency;
|
||||
// Derive fiat amount: use explicit fiatAmount, or infer from crypto amount for stablecoins
|
||||
{
|
||||
const inferredFiat = p.fiatAmount || (USD_STABLECOINS.includes(p.token) ? effectiveAmount : null);
|
||||
if (inferredFiat) {
|
||||
widgetParams.fiatAmount = inferredFiat;
|
||||
widgetParams.defaultFiatAmount = inferredFiat;
|
||||
}
|
||||
const fiatCcy = p.fiatCurrency || (USD_STABLECOINS.includes(p.token) ? 'USD' : null);
|
||||
if (fiatCcy) {
|
||||
widgetParams.fiatCurrency = fiatCcy;
|
||||
widgetParams.defaultFiatCurrency = fiatCcy;
|
||||
}
|
||||
}
|
||||
|
||||
const widgetUrl = await createSecureWidgetUrl(widgetParams);
|
||||
|
|
|
|||
Loading…
Reference in New Issue