From 9c28af7a104b955f248977231326f4bcf6631c4b Mon Sep 17 00:00:00 2001 From: Daniel Schlabach <31226559+dschlabach@users.noreply.github.com> Date: Thu, 14 Nov 2024 15:00:32 -0500 Subject: [PATCH] refactor: refactor active component logic in playground (#1622) --- .../nextjs-app-router/components/Demo.tsx | 82 +++++-------------- 1 file changed, 21 insertions(+), 61 deletions(-) diff --git a/playground/nextjs-app-router/components/Demo.tsx b/playground/nextjs-app-router/components/Demo.tsx index 5175b9ae14..8b58821008 100644 --- a/playground/nextjs-app-router/components/Demo.tsx +++ b/playground/nextjs-app-router/components/Demo.tsx @@ -18,6 +18,23 @@ import TransactionDefaultDemo from './demo/TransactionDefault'; import WalletDemo from './demo/Wallet'; import WalletDefaultDemo from './demo/WalletDefault'; +const activeComponentMapping: Record = { + [OnchainKitComponent.Fund]: FundDemo, + [OnchainKitComponent.Identity]: IdentityDemo, + [OnchainKitComponent.Transaction]: TransactionDemo, + [OnchainKitComponent.Checkout]: CheckoutDemo, + [OnchainKitComponent.Swap]: SwapDemo, + [OnchainKitComponent.SwapDefault]: SwapDefaultDemo, + [OnchainKitComponent.Wallet]: WalletDemo, + [OnchainKitComponent.WalletDefault]: WalletDefaultDemo, + [OnchainKitComponent.TransactionDefault]: TransactionDefaultDemo, + [OnchainKitComponent.NFTMintCard]: NFTMintCardDemo, + [OnchainKitComponent.NFTCard]: NFTCardDemo, + [OnchainKitComponent.NFTMintCardDefault]: NFTMintCardDefaultDemo, + [OnchainKitComponent.NFTCardDefault]: NFTCardDefaultDemo, + [OnchainKitComponent.IdentityCard]: IdentityCardDemo, +}; + function Demo() { const { activeComponent } = useContext(AppContext); const [isDarkMode, setIsDarkMode] = useState(true); @@ -45,66 +62,9 @@ function Demo() { : 'border-gray-300 bg-white text-black hover:bg-gray-100' }`; - // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: TODO: refactor - function renderActiveComponent() { - if (activeComponent === OnchainKitComponent.Fund) { - return ; - } - - if (activeComponent === OnchainKitComponent.Identity) { - return ; - } - - if (activeComponent === OnchainKitComponent.Transaction) { - return ; - } - - if (activeComponent === OnchainKitComponent.Checkout) { - return ; - } - - if (activeComponent === OnchainKitComponent.Swap) { - return ; - } - - if (activeComponent === OnchainKitComponent.SwapDefault) { - return ; - } - - if (activeComponent === OnchainKitComponent.Wallet) { - return ; - } - - if (activeComponent === OnchainKitComponent.WalletDefault) { - return ; - } - - if (activeComponent === OnchainKitComponent.TransactionDefault) { - return ; - } - - if (activeComponent === OnchainKitComponent.NFTMintCard) { - return ; - } - - if (activeComponent === OnchainKitComponent.NFTCard) { - return ; - } - - if (activeComponent === OnchainKitComponent.NFTMintCardDefault) { - return ; - } - - if (activeComponent === OnchainKitComponent.NFTCardDefault) { - return ; - } - - if (activeComponent === OnchainKitComponent.IdentityCard) { - return ; - } - - return <>; - } + const ActiveComponent = activeComponent + ? activeComponentMapping[activeComponent] + : null; return ( <> @@ -159,7 +119,7 @@ function Demo() {
- {renderActiveComponent()} + {ActiveComponent && }