How rainbow-me/rainbow works
Main Components
a. User Interface (UI) Layer:
• The core visual layer is implemented in React Native. It is divided into multiple sections such as “screens” (for different wallet functionalities like Send, Swap, Settings, etc.), “components” (reusable UI elements), and a dedicated “design-system” module that holds all themed styles, layout components, typography, and reusable primitives.
b. Business Logic and State Management Layer:
• There is robust state management with folders like “src/state”, “src/redux”, and also hooks in “src/hooks”. This layer handles wallet data, transaction states, pending operations, user preferences, and synchronizes with external blockchain data.
c. Native and Platform-specific Integration:
• The project contains separate directories for Android and iOS which house native code, build scripts, CocoaPods files, and additional configurations for wallet-specific native modules. Additionally, a browser extension exists with assets in “src/browser” and “src/browserMessaging”.
d. Network, API, and External Services Layer:
• This includes modules interfacing with Ethereum networks (using Infura, Etherscan, ETH Gas Station), GraphQL queries in “src/graphql”, WalletConnect integrations in “src/walletConnect”, and asset fetching (using Imgix for images).
e. Utilities and Helpers:
• These are spread across “src/helpers”, “src/utils”, “src/raps”, and others. They contain functions to build transactions, format dates and numbers, manage encryption and keychain access, and handle third‐party API responses.
f. Persistence and Migration:
• Storage modules in “src/storage” and “src/migrations” take care of local persistence (such as MMKV and legacy migrations) ensuring user wallet data and settings persist between sessions.
g. Analytics & Performance:
• The application tracks performance (e.g., via “src/performance”) and user events (in “src/analytics”) to feed data to backend analytics and Sentry error tracking.
h. External Dependencies & Environment Configuration:
• Configuration files such as .env.example, yarn scripts, and platform-specific configuration files integrate external services (Firebase, Google services, etc.) and environment keys.
Component Interactions
• Native modules in the “android” and “ios” directories expose integrations for device-specific functionalities (camera access, fingerprint/faceID, secure storage, etc.).
• Persistence modules and migration routines ensure that state changes are saved locally and are up-to-date on subsequent launches.
Architectural Patterns & Design Principles
• Separation of concerns is applied vigorously: UI components are decoupled from business logic; state management and hooks abstract away data manipulation and API calls.
• The design-system enables reusable and themed components ensuring consistency across the multi-platform UI.
• Modularization is reflected through discrete folders (e.g., “src/components”, “src/hooks”, “src/state”) – each with a well-defined responsibility.
• Use of dependency injection and contexts (as seen in “src/helpers/RainbowContext.tsx” and “src/design-system/context”) fosters loose coupling and testability.
• Emphasis is placed on performance: state synchronization, reanimated worklets, and memoized hooks help maintain responsive interactions on mobile devices.
Relevant Technologies & Frameworks
• React Native for mobile UI with platform-specific native code.
• Yarn for dependency management, with scripts that set up bundles and pods.
• Node.js 16 (with NVM) as the development runtime.
• State management approaches with Redux, Recoil, and React Query.
• GraphQL for querying blockchain-related data.
• External APIs: Infura, Etherscan, Imgix, Firebase.
• Tools like Watchman, CocoaPods, and Xcode are used in native building pipelines.