Smart Contract UI System
The smart contract UI system provides the primary user interface for interacting with Colored Key NFTs in RitoSwap. This sophisticated collection of React components orchestrates blockchain transactions, manages visual state transitions, and delivers a seamless experience across all stages of NFT ownership. The system handles complex state management scenarios while maintaining smooth animations and responsive feedback throughout the user journey.
System Overview
The smart contract UI represents the culmination of RitoSwap’s technical architecture, where blockchain data management meets user experience design. These components work in concert to provide real-time NFT visualization, transaction orchestration, and state-aware interface updates that respond instantly to blockchain events and wallet changes.
Core Architecture Components
The system comprises five essential components that together create the complete NFT interaction experience:
- MintPageWrapper - The orchestration layer that coordinates all child components and manages global state transitions
- TokenStatus - Dynamic status display that communicates the current NFT ownership state through elegant text transitions
- NFTScreen - Visual representation of the NFT that smoothly animates between different ownership states
- ButtonSection - Action interface that adapts based on connection status and NFT ownership
- ProcessingModal - Transaction feedback system that guides users through wallet interactions
This modular architecture ensures each component maintains a single responsibility while contributing to the cohesive user experience.

State Management Philosophy
The UI system implements a sophisticated state machine that handles four primary states with numerous transitional substates:
State | Description | UI Presentation |
---|---|---|
Not Connected | User has not connected their wallet | Lock icon (NFTScreen), connect wallet button (ButtonSection) |
Connected, No NFT | Wallet connected but no Colored Key owned | Default white key, mint button |
Connected, Unused NFT | Owns NFT that hasn’t accessed token gate | Colored key, gate access + burn options |
Connected, Used NFT | Owns NFT that has been used at token gate | Colored key, burn button only |
Smooth State Transitions
One of the defining characteristics of the smart contract UI system is its emphasis on smooth, non-jarring state transitions. The components implement several strategies to achieve this:
Debounced State Changes - Components implement various delays to prevent rapid flickering during initial data fetching. NFTScreen uses a 300ms initialization delay and 200ms state transition debouncing. TokenStatus implements a 500ms fade-out followed by a 50ms pause and 500ms fade-in for text changes.
Transition Animations - All state changes animate smoothly using CSS transitions, with carefully timed opacity and transform effects. Key transitions include NFTScreen’s 0.5s wrapper transitions, TokenStatus’s 1s total text transition cycle, ButtonSection’s 0.3s container fades, and ProcessingModal’s 1s overlay fade.
Loading State Preservation - During asynchronous operations, the UI maintains its current visual state rather than showing global loading spinners. This approach reduces perceived latency, though certain components like ButtonSection display contextual loading indicators such as a “Loading…” button during initial mount, and TokenStatus shows “Loading…” text until blockchain data arrives.
Account Switch Handling - The system implements sophisticated logic to preserve visual continuity during wallet switches. MintPageWrapper calls startAccountSwitch() to trigger state preservation, while NFTScreen renders previousData from the store when isSwitchingAccount is true, ensuring users never see jarring transitions between accounts.
User Experience Flow
Understanding the typical user journey helps illustrate how these components work together:
Step 1: Initial Connection
User arrives at the mint page and sees the lock icon (NFTScreen) with “You are not signed in” text (TokenStatus). The ButtonSection displays the connect wallet button.
Step 2: Wallet Connection
Upon connecting, the UI smoothly transitions. The lock fades out as a white key fades in. Text updates to “You don’t have a key yet” and the mint button appears.
Step 3: Minting Process
Clicking mint triggers the ProcessingModal while the transaction processes. Toast notifications and browser notifications keep the user informed of progress.
Step 4: NFT Ownership
Once minted, the white key transforms to display the algorithmically generated colors. The text changes to “You have an unused key!” and both gate access and burn buttons appear.
Step 5: Post-Token Gate / Burning
After using the token at the gate (tracked in PostgreSQL Prisma), the UI updates to show “You have a used key…” and only the burn button is available which can be used to allow the user to mint a new token afterwards.
Integration with Blockchain Layer
The UI components rely heavily on the smart contract data layer for real-time information:
Data Dependencies
- useNFTData Hook - Provides automatic blockchain state synchronization
- NFT Store - Maintains current ownership and visual state
- Contract Events - Real-time updates via Transfer event monitoring
- Network Validation - Ensures transactions occur on the correct chain
Transaction Orchestration
The ButtonSection component exemplifies proper blockchain interaction patterns:
const handleMint = () => {
setLoading(true)
executeWithNetworkCheck(() => {
mint({
address: KEY_TOKEN_ADDRESS,
abi: fullKeyTokenAbi,
functionName: 'mint',
})
if (displayUri) openWallet()
})
}
This pattern ensures network validation, loading state management, and mobile wallet deep-linking all occur seamlessly.
Notification System
The UI system implements a dual notification strategy to ensure users never miss important updates:
Toast Notifications
React Hot Toast provides immediate in-app feedback for all blockchain events. These lightweight notifications appear consistently styled and auto-dismiss after a reasonable duration.
Browser Notifications
For supported browsers, the system requests permission to send native notifications. These persist in the system tray and ensure users are informed even when the tab is not active:
- NFT Minted
- NFT Burned
- NFT Received (via transfer)
- NFT Transferred
- Token Gate Unlocked
- Message Recorded
Browser notifications require user permission and may not be available in all environments. The system gracefully falls back to toast-only notifications when native notifications are unavailable.
Mobile Optimization
The smart contract UI system includes specific optimizations for mobile devices:
Touch-Optimized Interactions - Larger tap targets and appropriate spacing ensure easy interaction on touch devices.
Wallet Deep-Linking - The ProcessingModal includes an “Open Wallet” button on mobile that triggers deep links to installed wallet apps.
Responsive Layouts - All components adapt their layout and sizing for optimal mobile viewing without sacrificing functionality.
Device Detection - The isMobileDevice()
utility accurately identifies mobile contexts using multiple detection strategies.
Performance Characteristics
The UI system implements several performance optimizations:
Minimal Re-renders - Components use selective store subscriptions to prevent unnecessary React re-renders.
CSS-Based Animations - All transitions use GPU-accelerated CSS properties rather than JavaScript animations.
Lazy State Updates - Visual updates are debounced to prevent rapid state changes during blockchain query resolution.
Optimized Asset Loading - The lock icon uses Next.js Image optimization with priority loading to ensure immediate display.
Customization Considerations
While the current implementation is tightly coupled to Colored Key NFTs, the architecture supports customization:
Visual Customization
The NFTScreen component currently hardcodes the key SVG for performance reasons. To support different NFT collections, developers would need to:
- Replace the hardcoded SVG with dynamic image loading
- Modify the color application logic for non-algorithmic NFTs
- Update the visual transition effects for different asset types
State Machine Extensions
Additional states could be added to support more complex NFT interactions:
- Multi-token ownership scenarios
- Time-locked or conditional access states
- Marketplace listing states
- Staking or delegation states
Network Expansion
The current system supports multi-chain deployment through environment configuration. Adding new networks requires updating the contract configuration and ensuring proper RPC endpoints.
Error Handling and Recovery
The UI system implements comprehensive error handling:
Transaction Failures - Toast notifications clearly communicate transaction errors with actionable messages.
Network Mismatches - The network check hook prevents transactions on incorrect chains and guides users to switch.
Wallet Disconnections - State automatically resets when wallets disconnect, preventing stale data display.
Recovery Mechanisms - The ProcessingModal’s cancel button allows users to reset transaction state and retry operations.
Best Practices
When working with the smart contract UI components, follow these guidelines:
State Consistency - Always use the centralized NFT store for state management rather than component-local state for NFT data.
Animation Timing - Maintain consistent transition durations across components (typically 300-500ms for state changes).
Loading States - Prefer maintaining current visual state over showing loading indicators during data fetches.
Error Communication - Use toast notifications for errors but avoid technical jargon in user-facing messages.
Mobile Testing - Always test wallet interactions on actual mobile devices as desktop browser emulation may not accurately represent deep-linking behavior.
Summary
The smart contract UI system represents a carefully orchestrated collection of components that transform complex blockchain interactions into intuitive user experiences. Through sophisticated state management, smooth animations, comprehensive notifications, and mobile optimization, it delivers a professional interface that makes NFT ownership accessible to users of all technical levels. The modular architecture ensures maintainability while the emphasis on visual polish creates an engaging experience that showcases the potential of Web3 applications.