|
| 1 | +'use client'; |
| 2 | + |
| 3 | +import { Heading, HStack, Text, VStack } from '@chakra-ui/react'; |
| 4 | +import { PayWithTransakButton, useTransakCheckout } from '@vechain/vechain-kit'; |
| 5 | +import { useTranslation } from 'react-i18next'; |
| 6 | +import { DemoSection } from '../../components/demo/DemoSection'; |
| 7 | +import { ConnectGate } from '../../components/demo/ConnectGate'; |
| 8 | + |
| 9 | +const BUTTON_SNIPPET = `import { PayWithTransakButton } from '@vechain/vechain-kit'; |
| 10 | +
|
| 11 | +function BuyVetButton() { |
| 12 | + return ( |
| 13 | + <PayWithTransakButton |
| 14 | + fiatAmount="30" |
| 15 | + fiatCurrency="USD" |
| 16 | + onSuccess={() => console.log('VET purchased!')} |
| 17 | + onError={(err) => console.error(err)} |
| 18 | + /> |
| 19 | + ); |
| 20 | +} |
| 21 | +`; |
| 22 | + |
| 23 | +const HOOK_SNIPPET = `import { useTransakCheckout } from '@vechain/vechain-kit'; |
| 24 | +
|
| 25 | +function BuyVetCustom() { |
| 26 | + const { open, status, widgetReady } = useTransakCheckout( |
| 27 | + () => console.log('done'), |
| 28 | + ); |
| 29 | +
|
| 30 | + return ( |
| 31 | + <button onClick={() => open({ fiatAmount: '30', fiatCurrency: 'USD' })}> |
| 32 | + Buy VET |
| 33 | + </button> |
| 34 | + // status/widgetReady drive your own UI -- see TransakCheckoutModal |
| 35 | + // in the vechain-kit source for a full reference implementation. |
| 36 | + ); |
| 37 | +} |
| 38 | +`; |
| 39 | + |
| 40 | +function CustomHookDemo() { |
| 41 | + const { t } = useTranslation(); |
| 42 | + const { open, status } = useTransakCheckout(); |
| 43 | + |
| 44 | + return ( |
| 45 | + <VStack align="stretch" spacing={3}> |
| 46 | + <Text fontSize="sm"> |
| 47 | + {t( |
| 48 | + 'Same top-up rail, driven directly from useTransakCheckout instead of the pre-built button -- use this when you need your own trigger UI.', |
| 49 | + )} |
| 50 | + </Text> |
| 51 | + <HStack> |
| 52 | + <Text fontSize="xs" opacity={0.6}> |
| 53 | + {t('status')}: {status} |
| 54 | + </Text> |
| 55 | + </HStack> |
| 56 | + <button |
| 57 | + onClick={() => open({ fiatAmount: '30', fiatCurrency: 'USD' })} |
| 58 | + style={{ |
| 59 | + padding: '8px 16px', |
| 60 | + borderRadius: 8, |
| 61 | + border: '1px solid rgba(128,128,128,0.3)', |
| 62 | + cursor: 'pointer', |
| 63 | + }} |
| 64 | + > |
| 65 | + {t('Buy $30 VET (custom trigger)')} |
| 66 | + </button> |
| 67 | + </VStack> |
| 68 | + ); |
| 69 | +} |
| 70 | + |
| 71 | +export default function PaymentsPage() { |
| 72 | + const { t } = useTranslation(); |
| 73 | + |
| 74 | + return ( |
| 75 | + <VStack align="stretch" spacing={6}> |
| 76 | + <VStack align="stretch" spacing={2}> |
| 77 | + <Heading size="lg">{t('Payments')}</Heading> |
| 78 | + <Text opacity={0.7}> |
| 79 | + {t( |
| 80 | + 'Let users top up their wallet with VET bought via card -- no exchange, no bridging. Powered by Transak.', |
| 81 | + )} |
| 82 | + </Text> |
| 83 | + </VStack> |
| 84 | + |
| 85 | + <ConnectGate feature={t('Payments')}> |
| 86 | + <DemoSection |
| 87 | + title={t('Buy VET')} |
| 88 | + description={t( |
| 89 | + 'Drop-in button: opens the Transak widget, tracks order status, and closes itself on success.', |
| 90 | + )} |
| 91 | + hooks={['PayWithTransakButton', 'useTransakCheckout']} |
| 92 | + status="NEW" |
| 93 | + code={BUTTON_SNIPPET} |
| 94 | + aiPrompt={t( |
| 95 | + 'Add a "Buy VET" button to my Next.js app using PayWithTransakButton from @vechain/vechain-kit. Default to $30 USD, and show a toast on success/error. Requires a `transak.widgetUrlBuilder` configured on VeChainKitProvider that mints a Secure Widget URL from a backend -- see the "Fiat onramp" recipe in the vechain-kit docs for a reference proxy implementation.', |
| 96 | + )} |
| 97 | + aiSkills={['vechain-kit']} |
| 98 | + > |
| 99 | + <PayWithTransakButton fiatAmount="30" fiatCurrency="USD" /> |
| 100 | + </DemoSection> |
| 101 | + |
| 102 | + <DemoSection |
| 103 | + title={t('Custom trigger')} |
| 104 | + description={t( |
| 105 | + 'The same flow via the raw hook, for a fully custom button/card instead of the pre-built one.', |
| 106 | + )} |
| 107 | + hooks={['useTransakCheckout']} |
| 108 | + status="NEW" |
| 109 | + code={HOOK_SNIPPET} |
| 110 | + aiPrompt={t( |
| 111 | + 'Build a custom "Top up wallet" card in my app using useTransakCheckout from @vechain/vechain-kit directly (not PayWithTransakButton) so I can fully control the trigger UI. Show the live status (idle/processing/success/error) and disable the button while processing.', |
| 112 | + )} |
| 113 | + aiSkills={['vechain-kit']} |
| 114 | + > |
| 115 | + <CustomHookDemo /> |
| 116 | + </DemoSection> |
| 117 | + </ConnectGate> |
| 118 | + </VStack> |
| 119 | + ); |
| 120 | +} |
0 commit comments