From cb4f471417e7f1e3f2bcf082a76299d17363c1a4 Mon Sep 17 00:00:00 2001 From: PEDZEO Date: Tue, 20 Jan 2026 17:30:44 +0300 Subject: [PATCH] Refactor TopUpModal for improved code clarity and structure - Consolidated content rendering into a single JSX variable for better readability. - Simplified modal rendering logic by removing nested components and using a single conditional return. - Enhanced mobile and desktop modal handling for clearer separation of concerns. --- src/components/TopUpModal.tsx | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/components/TopUpModal.tsx b/src/components/TopUpModal.tsx index a52ddd8..4bf5d16 100644 --- a/src/components/TopUpModal.tsx +++ b/src/components/TopUpModal.tsx @@ -258,7 +258,8 @@ export default function TopUpModal({ method, onClose, initialAmountRubles }: Top // Calculate display amount for preview const displayAmount = amount && parseFloat(amount) > 0 ? parseFloat(amount) : 0 - const renderContent = () => ( + // Content JSX - shared between mobile and desktop + const contentJSX = (
{/* Header icon and method */}
@@ -403,8 +404,8 @@ export default function TopUpModal({ method, onClose, initialAmountRubles }: Top
) - // Mobile bottom sheet - const MobileModal = () => ( + // Render modal based on screen size - NO nested components! + const modalContent = isMobileScreen ? ( <> {/* Backdrop */}
- {renderContent()} + {contentJSX}
- ) - - // Desktop modal - positioned higher - const DesktopModal = () => ( + ) : (
- {renderContent()} + {contentJSX}
) - const content = isMobileScreen ? : - if (typeof document !== 'undefined') { - return createPortal(content, document.body) + return createPortal(modalContent, document.body) } - return content + return modalContent }