Skip to content

Commit dab7335

Browse files
author
Luca Bandini
authored
feat(next-template): route production onramp through vechain/onramp-proxy (#654)
- widgetUrlBuilder speaks both contracts: production uses onramp-proxy (GET, shared VeChain backend), staging keeps the vechain-kit-infra proxy (POST) so the preview env is unchanged - deploy-cloudfront reads NEXT_PUBLIC_TRANSAK_API_URL_PROD
1 parent 8718d6e commit dab7335

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

‎.github/workflows/deploy-cloudfront.yaml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ jobs:
2929
NEXT_PUBLIC_PRIVY_CLIENT_ID: ${{ secrets.NEXT_PUBLIC_PRIVY_CLIENT_ID }}
3030
NEXT_PUBLIC_DELEGATOR_URL: ${{ secrets.NEXT_PUBLIC_DELEGATOR_URL }}
3131
NEXT_PUBLIC_TRANSAK_API_KEY: ${{ secrets.NEXT_PUBLIC_TRANSAK_API_KEY_PROD }}
32-
NEXT_PUBLIC_TRANSAK_API_URL: ${{ secrets.NEXT_PUBLIC_TRANSAK_API_URL }}
32+
# Production talks to vechain/onramp-proxy; the preview deploy
33+
# keeps NEXT_PUBLIC_TRANSAK_API_URL (vechain-kit-infra proxy).
34+
NEXT_PUBLIC_TRANSAK_API_URL: ${{ secrets.NEXT_PUBLIC_TRANSAK_API_URL_PROD }}
3335
NEXT_PUBLIC_TRANSAK_ENVIRONMENT: 'production'
3436
NEXT_PUBLIC_NETWORK_TYPE: 'main'
3537
AWS_REGION: eu-west-1

‎examples/next-template/src/app/providers/VechainKitProviderWrapper.tsx‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,44 @@ export function VechainKitProviderWrapper({ children }: Props) {
134134
}) => {
135135
const apiUrl =
136136
process.env.NEXT_PUBLIC_TRANSAK_API_URL ?? '';
137+
const environment = process.env
138+
.NEXT_PUBLIC_TRANSAK_ENVIRONMENT as
139+
| 'staging'
140+
| 'production'
141+
| undefined;
142+
143+
// Production goes through vechain/onramp-proxy
144+
// (the shared VeChain onramp backend, GET
145+
// contract). Staging keeps the vechain-kit-infra
146+
// proxy: onramp-proxy is production-only.
147+
if (environment === 'production') {
148+
const params = new URLSearchParams({
149+
provider: 'transak',
150+
address: walletAddress,
151+
os: 'web',
152+
theme: 'LIGHT',
153+
currency: fiatCurrency,
154+
referrerDomain:
155+
typeof window !== 'undefined'
156+
? window.location.origin
157+
: '',
158+
});
159+
if (fiatAmount) {
160+
params.set('fiatAmount', fiatAmount);
161+
}
162+
const res = await fetch(
163+
`${apiUrl}/?${params.toString()}`,
164+
);
165+
const json = await res.json();
166+
if (!res.ok || !json?.url) {
167+
throw new Error(
168+
json?.error ??
169+
'Failed to create Transak widget URL',
170+
);
171+
}
172+
return json.url as string;
173+
}
174+
137175
const res = await fetch(
138176
`${apiUrl}/api/transak/widget-url`,
139177
{

0 commit comments

Comments
 (0)