diff --git a/playground/nextjs-app-router/components/DemoOptions.tsx b/playground/nextjs-app-router/components/DemoOptions.tsx index da71b55d4b..3ac610ec64 100644 --- a/playground/nextjs-app-router/components/DemoOptions.tsx +++ b/playground/nextjs-app-router/components/DemoOptions.tsx @@ -11,74 +11,76 @@ import { SwapConfig } from './form/swap-config'; import { TransactionOptions } from './form/transaction-options'; import { WalletType } from './form/wallet-type'; +const COMMON_OPTIONS = [ + ActiveComponent, + ComponentMode, + ComponentTheme, + WalletType, +]; + +const COMPONENT_CONFIG: Partial< + Record React.JSX.Element)[]> +> = { + [OnchainKitComponent.Checkout]: [ + Chain, + PaymasterUrl, + IsSponsored, + CheckoutOptions, + ], + [OnchainKitComponent.Swap]: [Chain, PaymasterUrl, IsSponsored, SwapConfig], + [OnchainKitComponent.SwapDefault]: [ + Chain, + PaymasterUrl, + IsSponsored, + SwapConfig, + ], + [OnchainKitComponent.Transaction]: [ + Chain, + PaymasterUrl, + IsSponsored, + TransactionOptions, + ], + [OnchainKitComponent.TransactionDefault]: [ + Chain, + PaymasterUrl, + IsSponsored, + TransactionOptions, + ], + [OnchainKitComponent.NFTCard]: [Chain, NFTOptions], + [OnchainKitComponent.NFTCardDefault]: [Chain, NFTOptions], + [OnchainKitComponent.NFTMintCard]: [ + Chain, + PaymasterUrl, + IsSponsored, + NFTOptions, + ], + [OnchainKitComponent.NFTMintCardDefault]: [ + Chain, + PaymasterUrl, + IsSponsored, + NFTOptions, + ], +}; + export default function DemoOptions({ component, }: { component?: OnchainKitComponent; }) { - const commonOptions = ( + const commonElements = COMMON_OPTIONS.map((Component) => ( + + )); + + const specificElements = component + ? (COMPONENT_CONFIG[component] || []).map((Component) => ( + + )) + : []; + + return ( <> - - - - + {commonElements} + {specificElements} ); - - switch (component) { - case OnchainKitComponent.Checkout: - return ( - <> - {commonOptions} - - - - - - ); - case OnchainKitComponent.Swap: - case OnchainKitComponent.SwapDefault: - return ( - <> - {commonOptions} - - - - - - ); - case OnchainKitComponent.Transaction: - case OnchainKitComponent.TransactionDefault: - return ( - <> - {commonOptions} - - - - - - ); - case OnchainKitComponent.NFTCard: - case OnchainKitComponent.NFTCardDefault: - return ( - <> - {commonOptions} - - - - ); - case OnchainKitComponent.NFTMintCard: - case OnchainKitComponent.NFTMintCardDefault: - return ( - <> - {commonOptions} - - - - - - ); - default: - return commonOptions; - } } diff --git a/playground/nextjs-app-router/components/form/checkout-options.tsx b/playground/nextjs-app-router/components/form/checkout-options.tsx index fed28b84f0..53781c1677 100644 --- a/playground/nextjs-app-router/components/form/checkout-options.tsx +++ b/playground/nextjs-app-router/components/form/checkout-options.tsx @@ -3,11 +3,10 @@ import { Label } from '@/components/ui/label'; import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group'; import { useContext } from 'react'; import { useState } from 'react'; -import { AppContext, CheckoutTypes, OnchainKitComponent } from '../AppProvider'; +import { AppContext, CheckoutTypes } from '../AppProvider'; export function CheckoutOptions() { const { - activeComponent, checkoutTypes, setCheckoutTypes, checkoutOptions, @@ -24,77 +23,75 @@ export function CheckoutOptions() { }); return ( - activeComponent === OnchainKitComponent.Checkout && ( -
- - setCheckoutTypes?.(value as CheckoutTypes)} - > -
- - -
-
- - {checkoutTypes === CheckoutTypes.ChargeID && ( -
- - { - setProductOptions({ - ...productOptions, - chargeId: e.target.value, - }); - setCheckoutOptions?.({ - ...checkoutOptions, - chargeId: e.target.value, - }); - }} +
+ + setCheckoutTypes?.(value as CheckoutTypes)} + > +
+
- )} - {checkoutTypes === CheckoutTypes.ProductID && ( -
- - { - setProductId(e.target.value); - setCheckoutOptions?.({ - ...checkoutOptions, - productId: e.target.value, - }); - }} + Product ID + +
- )} -
- ) + Charge ID + +
+ + + {checkoutTypes === CheckoutTypes.ChargeID && ( +
+ + { + setProductOptions({ + ...productOptions, + chargeId: e.target.value, + }); + setCheckoutOptions?.({ + ...checkoutOptions, + chargeId: e.target.value, + }); + }} + /> +
+ )} + {checkoutTypes === CheckoutTypes.ProductID && ( +
+ + { + setProductId(e.target.value); + setCheckoutOptions?.({ + ...checkoutOptions, + productId: e.target.value, + }); + }} + /> +
+ )} +
); } diff --git a/playground/nextjs-app-router/components/form/transaction-options.tsx b/playground/nextjs-app-router/components/form/transaction-options.tsx index 3cacbaf8e9..c6574676b7 100644 --- a/playground/nextjs-app-router/components/form/transaction-options.tsx +++ b/playground/nextjs-app-router/components/form/transaction-options.tsx @@ -7,50 +7,40 @@ import { SelectValue, } from '@/components/ui/select'; import { useContext } from 'react'; -import { - AppContext, - OnchainKitComponent, - TransactionTypes, -} from '../AppProvider'; +import { AppContext, TransactionTypes } from '../AppProvider'; export function TransactionOptions() { - const { activeComponent, transactionType, setTransactionType } = - useContext(AppContext); + const { transactionType, setTransactionType } = useContext(AppContext); return ( - (activeComponent === OnchainKitComponent.Transaction || - activeComponent === OnchainKitComponent.TransactionDefault) && ( -
- - -
- ) +
+ + +
); }