diff --git a/conductor.json b/conductor.json new file mode 100644 index 00000000..016b7c7d --- /dev/null +++ b/conductor.json @@ -0,0 +1,4 @@ +{ + "setupScript": "./scripts/conductor/setup-worktree.sh", + "archiveScript": "./scripts/conductor/cleanup-worktree.sh" +} diff --git a/dapps/W3MWagmi/AGENTS.md b/dapps/W3MWagmi/AGENTS.md new file mode 100644 index 00000000..094405bf --- /dev/null +++ b/dapps/W3MWagmi/AGENTS.md @@ -0,0 +1,220 @@ +# Agent Documentation: W3MWagmi + +This file provides guidance to AI agents when working with code in this repository. + +## Project Overview + +**W3MWagmi** is a React Native sample application demonstrating the **Reown AppKit SDK** for multichain Web3 integration. It showcases wallet connection, signing, and transaction capabilities across multiple blockchain ecosystems: + +- **EVM chains** (Ethereum, Polygon, Arbitrum, Optimism, Base, etc.) +- **Solana** (via Phantom & Solflare wallets) +- **Bitcoin** (PSBT signing) + +This is a reference implementation for developers building dApps with Reown AppKit. + +## Tech Stack + +### Core Technologies +- **React Native**: 0.81.4 +- **React**: 19.1.0 +- **TypeScript**: ^5.8.3 +- **Expo**: 54.0.20 + +### Reown AppKit SDKs +- **@reown/appkit-react-native**: Core AppKit SDK +- **@reown/appkit-wagmi-react-native**: EVM integration via Wagmi +- **@reown/appkit-solana-react-native**: Solana support +- **@reown/appkit-bitcoin-react-native**: Bitcoin support +- **@reown/appkit-coinbase-react-native**: Coinbase wallet integration + +### Blockchain Libraries +- **wagmi**: EVM hooks & utilities +- **viem**: Ethereum JavaScript client +- **@solana/web3.js**: Solana client +- **bitcoinjs-lib**: Bitcoin library + +### Key Libraries +- **@react-navigation**: Navigation (native-stack, bottom-tabs) +- **valtio**: Reactive state management +- **@tanstack/react-query**: Server state management +- **react-native-mmkv**: Fast key-value storage +- **@sentry/react-native**: Error tracking + +## Architecture + +### Project Structure + +``` +W3MWagmi/ +├── src/ +│ ├── App.tsx # Root component with providers +│ ├── screens/ +│ │ ├── Connections/ # Main wallet connection & actions +│ │ │ └── components/ # Chain-specific action views +│ │ │ ├── ActionsView.tsx +│ │ │ ├── WagmiActionsView.tsx # EVM transactions +│ │ │ ├── SolanaActionsView.tsx # Solana actions +│ │ │ ├── BitcoinActionsView.tsx # Bitcoin actions +│ │ │ ├── WalletInfoView.tsx +│ │ │ └── EventsView.tsx +│ │ ├── Settings/ # Device & wallet info +│ │ ├── LogList/ # App activity logs +│ │ └── AppKitLogList/ # AppKit library logs +│ ├── navigators/ +│ │ ├── RootStackNavigator.tsx +│ │ └── HomeTabNavigator.tsx +│ ├── stores/ +│ │ └── SettingsStore.ts # Valtio-based state +│ ├── utils/ +│ │ ├── WagmiUtils.ts # Chain configuration +│ │ ├── BitcoinUtil.ts # Bitcoin helpers +│ │ ├── eip712.ts # EIP-712 signing +│ │ └── ... +│ ├── hooks/ +│ │ ├── useLogs.ts +│ │ ├── useSocketStatus.ts +│ │ └── useTheme.ts +│ └── assets/ +├── android/ +├── ios/ +├── scripts/ +└── package.json +``` + +### State Management + +- **Valtio**: Lightweight reactive proxy-based state (`stores/SettingsStore.ts`) +- **React Query**: Server state and caching for blockchain data + +### Navigation + +Uses **React Navigation** with: +- Bottom tab navigator (4 tabs: Connections, Settings, Logs, AppKit Logs) +- Stack navigator for modal screens + +## Key Features + +### Wallet Connection +- AppKit modal for wallet selection +- Support for 14+ EVM chains +- Solana wallet integration (Phantom, Solflare) +- Bitcoin wallet support +- Coinbase Wallet Mobile SDK +- WalletConnect Link Mode + +### Blockchain Actions + +**EVM (Wagmi)** +- Sign message +- Send transactions +- Estimate gas +- Sign typed data (EIP-712) + +**Solana** +- Sign message +- Sign transaction +- Send transaction + +**Bitcoin** +- Sign message (ECDSA) +- Sign PSBT + +### Developer Features +- Real-time socket status monitoring +- App activity logs +- AppKit library event logs +- Device information display + +## Environment Variables + +Required in `.env`: +```bash +ENV_PROJECT_ID="" # Reown dashboard project ID (required) +ENV_SENTRY_DSN="" # Sentry error tracking (optional) +SENTRY_DISABLE_AUTO_UPLOAD=true # Disable Sentry auto upload for Android builds +``` + +## Development + +### Setup +```bash +yarn install +cp .env.example .env +# Edit .env with your project ID +yarn android # or yarn ios +``` + +### Scripts +- `yarn start`: Start Metro bundler +- `yarn android`: Run on Android (debug) +- `yarn ios`: Run on iOS +- `yarn android:build`: Build release APK +- `yarn lint`: Run ESLint +- `yarn test`: Run Jest tests + +### Build Variants +- **debug**: Local development +- **internal**: Internal testing +- **production**: Release builds + +```bash +yarn run copy:debug # Copy debug config files +yarn run copy:internal # Copy internal config files +yarn run copy:production # Copy production config files +``` + +## Common Patterns + +### AppKit Setup (App.tsx) + +```typescript +import { createAppKit } from '@reown/appkit-react-native'; +import { WagmiProvider } from 'wagmi'; + +// Initialize AppKit with project ID and chains +createAppKit({ + projectId: ENV_PROJECT_ID, + // ... configuration +}); +``` + +### Using Wagmi Hooks + +```typescript +import { useAccount, useSignMessage, useSendTransaction } from 'wagmi'; + +const { address, isConnected } = useAccount(); +const { signMessage } = useSignMessage(); +``` + +### Valtio State + +```typescript +import { proxy, useSnapshot } from 'valtio'; + +const SettingsStore = proxy({ + // state +}); + +// In component +const { value } = useSnapshot(SettingsStore); +``` + +## Code Quality Guidelines + +### After Making Changes + +**Always run these checks and fix any errors before committing:** + +```bash +yarn lint # Check and fix ESLint errors +yarn prettier --write . # Format code with Prettier +npx tsc --noEmit # Check for TypeScript errors +``` + +### Style +- Use TypeScript strict mode +- Follow ESLint + Prettier configuration +- Use path aliases (`@/`) for imports +- Handle errors with toast notifications +- Log important events for debugging diff --git a/dapps/W3MWagmi/CLAUDE.md b/dapps/W3MWagmi/CLAUDE.md new file mode 100644 index 00000000..c3170642 --- /dev/null +++ b/dapps/W3MWagmi/CLAUDE.md @@ -0,0 +1 @@ +AGENTS.md diff --git a/dapps/W3MWagmi/package.json b/dapps/W3MWagmi/package.json index a19143c5..74281685 100644 --- a/dapps/W3MWagmi/package.json +++ b/dapps/W3MWagmi/package.json @@ -2,6 +2,7 @@ "version": "0.0.1", "private": true, "scripts": { + "postinstall": "./scripts/copy-sample-files.sh", "android": "yarn run copy:debug && react-native run-android --appId com.walletconnect.web3modal.rnsample.debug", "android:build": "yarn run copy:production && cd android && ./gradlew clean && ./gradlew assembleRelease -PreactNativeArchitectures=arm64-v8a", "android:build:internal": "yarn run copy:internal && cd android && ./gradlew clean && ./gradlew assembleInternal -PreactNativeArchitectures=arm64-v8a", diff --git a/dapps/W3MWagmi/scripts/copy-sample-files.sh b/dapps/W3MWagmi/scripts/copy-sample-files.sh index 6610604c..efe0e493 100755 --- a/dapps/W3MWagmi/scripts/copy-sample-files.sh +++ b/dapps/W3MWagmi/scripts/copy-sample-files.sh @@ -1,5 +1,21 @@ -# bash script that copies the mock files to the correct location +#!/bin/zsh +# Script that copies mock files to the correct location (skips if file exists) -cp .env.example .env -cp android/app/debug.keystore.mock android/app/debug.keystore -cp android/secrets.properties.mock android/secrets.properties +copy_if_missing() { + local src="$1" + local dest="$2" + if [ ! -f "$src" ]; then + echo "Skipped (source not found): $src" + return + fi + if [ -f "$dest" ]; then + echo "Skipped (exists): $dest" + return + fi + cp "$src" "$dest" + echo "Copied: $dest" +} + +copy_if_missing .env.example .env +copy_if_missing android/app/debug.keystore.mock android/app/debug.keystore +copy_if_missing android/secrets.properties.mock android/secrets.properties diff --git a/dapps/poc-pos-app/AGENTS.md b/dapps/poc-pos-app/AGENTS.md new file mode 100644 index 00000000..69c7c212 --- /dev/null +++ b/dapps/poc-pos-app/AGENTS.md @@ -0,0 +1,148 @@ +# Agent Documentation: PoC POS App + +This file provides guidance to AI agents when working with code in this repository. + +> **Note:** This is a legacy proof-of-concept application. For active development, see `dapps/pos-app`. + +## Project Overview + +**PoC POS App** is a proof-of-concept React Native point-of-sale application for cryptocurrency payments via WalletConnect. It serves as the foundation for the production `pos-app`. The app allows merchants to: + +- Generate QR codes for payment requests +- Accept payments through WalletConnect-compatible wallets +- Print thermal receipts for completed transactions +- Support multiple branded variants (white-labeling) + +The app is built with **Expo** and **React Native**, supporting Android, iOS, and Web platforms. + +## Tech Stack + +### Core Technologies +- **React Native**: 0.81.5 +- **Expo**: ^54.0.23 (with Expo Router for navigation) +- **TypeScript**: ~5.9.2 +- **React**: 19.1.0 + +### Key Libraries +- **@tanstack/react-query**: Data fetching and caching +- **zustand**: State management +- **react-hook-form**: Form handling +- **expo-router**: File-based routing +- **react-native-thermal-pos-printer**: Thermal printer integration +- **react-native-qrcode-skia**: QR code generation +- **@shopify/react-native-skia**: Graphics rendering +- **react-native-mmkv**: Fast key-value storage +- **@sentry/react-native**: Error tracking + +## Architecture + +### Project Structure + +``` +poc-pos-app/ +├── app/ # Expo Router screens (file-based routing) +│ ├── _layout.tsx # Root layout with providers +│ ├── index.tsx # Home screen +│ ├── amount.tsx # Amount input screen +│ ├── scan.tsx # QR code display & payment polling +│ ├── payment-success.tsx # Success screen +│ ├── payment-failure.tsx # Failure screen +│ ├── settings.tsx # Settings & configuration +│ └── logs.tsx # Debug logs viewer +├── components/ # Reusable UI components +├── constants/ # Theme, variants, spacing +├── hooks/ # Custom React hooks +├── store/ # Zustand state stores +├── utils/ # Utility functions +└── assets/ # Images, fonts, icons +``` + +### State Management + +Uses **Zustand** with two main stores: + +1. **`useSettingsStore`** (`store/useSettingsStore.ts`) + - Merchant ID, theme mode, variant selection + - Device ID, PIN protection settings + - Printer connection status + +2. **`useLogsStore`** (`store/useLogsStore.ts`) + - Debug logs for troubleshooting + +### Navigation + +Uses **Expo Router** with file-based routing: +- Routes defined by file structure in `app/` directory +- Navigation via `router.push()`, `router.replace()`, `router.dismiss()` + +## Key Features + +### Payment Flow +1. Home Screen → New Sale button +2. Amount Input → Custom numeric keyboard +3. QR Code Display → Polls payment status +4. Payment Success/Failure → Receipt printing option + +### Variants System +Supports branded variants for white-labeling: +- **default**: Blue accent (#0988F0) +- **solflare**: Yellow/gold (#FFEF46) +- **binance**: Yellow (#FCD533) +- **phantom**: Purple (#AB9FF2) +- **solana**: Purple (#9945FF) + +### Security +- PIN protection with lockout after failed attempts +- Biometric authentication support +- MMKV encrypted storage + +## Environment Variables + +Required in `.env`: +```bash +EXPO_PUBLIC_PROJECT_ID="" # WalletConnect project ID +EXPO_PUBLIC_SENTRY_DSN="" # Sentry error tracking DSN +SENTRY_AUTH_TOKEN="" # Sentry authentication token +EXPO_PUBLIC_API_URL="" # Payment API base URL +EXPO_PUBLIC_GATEWAY_URL="" # WalletConnect gateway URL +EXPO_PUBLIC_MERCHANTS_URL="" # Merchants API URL +``` + +## Development + +### Setup +```bash +npm install +cp .env.example .env +npm run prebuild +npm run android # or ios/web +``` + +### Scripts +- `npm start`: Start Expo dev server +- `npm run android`: Run on Android +- `npm run ios`: Run on iOS +- `npm run web`: Run on web +- `npm run lint`: Run ESLint +- `npm test`: Run Jest tests + +## Code Quality Guidelines + +### Logging +- Use `useLogsStore` for debugging, not `console.log()` +- Remove console statements before committing + +### After Making Changes + +**Always run these checks and fix any errors before committing:** + +```bash +npm run lint # Check and fix ESLint errors +npx prettier --write . # Format code with Prettier +npx tsc --noEmit # Check for TypeScript errors +``` + +### Style +- No trailing whitespace +- Use TypeScript strict mode +- Follow existing code patterns diff --git a/dapps/poc-pos-app/CLAUDE.md b/dapps/poc-pos-app/CLAUDE.md new file mode 100644 index 00000000..c3170642 --- /dev/null +++ b/dapps/poc-pos-app/CLAUDE.md @@ -0,0 +1 @@ +AGENTS.md diff --git a/dapps/pos-app/AGENTS.md b/dapps/pos-app/AGENTS.md index 8f7c8af9..ca925333 100644 --- a/dapps/pos-app/AGENTS.md +++ b/dapps/pos-app/AGENTS.md @@ -192,11 +192,13 @@ All API requests include: Required environment variables (`.env`): ```bash -EXPO_PUBLIC_PROJECT_ID="" # WalletConnect project ID -EXPO_PUBLIC_SENTRY_DSN="" # Sentry error tracking DSN -SENTRY_AUTH_TOKEN="" # Sentry authentication token -EXPO_PUBLIC_API_URL="" # Payment API base URL -EXPO_PUBLIC_GATEWAY_URL="" # WalletConnect gateway URL +EXPO_PUBLIC_PROJECT_ID="" # WalletConnect project ID +EXPO_PUBLIC_SENTRY_DSN="" # Sentry error tracking DSN +SENTRY_AUTH_TOKEN="" # Sentry authentication token +EXPO_PUBLIC_API_URL="" # Payment API base URL +EXPO_PUBLIC_GATEWAY_URL="" # WalletConnect gateway URL +EXPO_PUBLIC_DEFAULT_MERCHANT_ID="" # Default merchant ID (optional) +EXPO_PUBLIC_DEFAULT_MERCHANT_API_KEY="" # Default merchant API key (optional) ``` Copy `.env.example` to `.env` and fill in values. @@ -618,15 +620,25 @@ const apiKey = await secureStorage.getItem(SECURE_STORAGE_KEYS.MERCHANT_API_KEY) - **Production builds**: Console statements can impact performance and expose sensitive information in production builds. +### After Making Changes + +**Always run these checks and fix any errors before committing:** + +```bash +npm run lint # Check and fix ESLint errors +npx prettier --write . # Format code with Prettier +npx tsc --noEmit # Check for TypeScript errors +``` + +Fix any errors found. Pre-existing TypeScript errors in unrelated files can be ignored. + ### Code Style - Follow TypeScript best practices - Use ESLint and Prettier for consistent formatting - Prefer functional components with hooks - Use TypeScript types/interfaces for all props and data structures -- **No trailing whitespace**: New code must not have trailing whitespace at the end of lines. Most editors can be configured to remove trailing whitespace on save. -- **Run lint after changing code**: Always run `npm run lint` after making code changes to ensure code quality and catch any formatting or linting issues before committing. -- **Check TypeScript errors**: Always run `npx tsc --noEmit` after making code changes to check for TypeScript errors. Fix any TypeScript errors in files you've modified before committing. Note: Pre-existing TypeScript errors in other files can be ignored if they're unrelated to your changes. +- No trailing whitespace ## Troubleshooting diff --git a/scripts/conductor/cleanup-worktree.sh b/scripts/conductor/cleanup-worktree.sh new file mode 100755 index 00000000..016b1ea0 --- /dev/null +++ b/scripts/conductor/cleanup-worktree.sh @@ -0,0 +1,63 @@ +#!/bin/zsh + +# Cleanup script for archiving worktrees +# Removes node_modules, build artifacts, and Pods from all projects + +set -e + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color + +# Target directory (Conductor workspace or script location) +if [ -n "$CONDUCTOR_ROOT_PATH" ]; then + REPO_DIR="$CONDUCTOR_ROOT_PATH" +else + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)" + REPO_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" +fi + +echo "Cleaning up worktree: $REPO_DIR" +echo "" + +# Function to remove directory if it exists +remove_dir() { + local dir="$1" + if [ -d "$dir" ]; then + rm -rf "$dir" + echo -e "${GREEN}✓${NC} Removed: ${dir#$REPO_DIR/}" + fi +} + +# Find and remove node_modules directories +echo "Removing node_modules directories..." +while IFS= read -r -d '' dir; do + remove_dir "$dir" +done < <(find "$REPO_DIR" -type d -name "node_modules" -print0 2>/dev/null) +echo "" + +# Find and remove android/build directories +echo "Removing android/build directories..." +while IFS= read -r -d '' dir; do + remove_dir "$dir" +done < <(find "$REPO_DIR" -type d -path "*/android/build" -print0 2>/dev/null) +echo "" + +# Find and remove ios/Pods directories +echo "Removing ios/Pods directories..." +while IFS= read -r -d '' dir; do + remove_dir "$dir" +done < <(find "$REPO_DIR" -type d -path "*/ios/Pods" -print0 2>/dev/null) +echo "" + +# Find and remove ios/build directories +echo "Removing ios/build directories..." +while IFS= read -r -d '' dir; do + remove_dir "$dir" +done < <(find "$REPO_DIR" -type d -path "*/ios/build" -print0 2>/dev/null) +echo "" + +# Calculate freed space (rough estimate by checking current size) +echo -e "${GREEN}Cleanup complete!${NC}" diff --git a/scripts/conductor/setup-worktree.sh b/scripts/conductor/setup-worktree.sh new file mode 100755 index 00000000..13c8b3a0 --- /dev/null +++ b/scripts/conductor/setup-worktree.sh @@ -0,0 +1,71 @@ +#!/bin/zsh + +# Setup script for Conductor workspaces +# Creates symlinks for environment files and sentry.properties from the main repo +# This script runs inside the workspace directory + +set -e + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color + +# Source directory (main repo root via Conductor, or fallback to hardcoded path) +SOURCE_DIR="${CONDUCTOR_ROOT_PATH:-$HOME/projects/react-native-examples}" + +echo "Setting up workspace..." +echo " Source: $SOURCE_DIR" +echo " Workspace: $(pwd)" +echo "" + +# Function to symlink a file if source exists +symlink_file() { + local src="$1" + local dest="$2" + + if [ -f "$src" ]; then + mkdir -p "$(dirname "$dest")" + ln -sf "$src" "$dest" + echo -e "${GREEN}✓${NC} Linked: $dest" + else + echo -e "${YELLOW}⚠${NC} Not found (skipping): $src" + fi +} + +# Projects to setup +PROJECTS=( + "dapps/poc-pos-app" + "dapps/pos-app" + "dapps/W3MWagmi" + "wallets/rn_cli_wallet" +) + +# Symlink env files +echo "Linking environment files..." +for project in "${PROJECTS[@]}"; do + symlink_file "$SOURCE_DIR/$project/.env" "$project/.env" + symlink_file "$SOURCE_DIR/$project/.env.local" "$project/.env.local" +done +echo "" + +# Symlink sentry.properties files +echo "Linking sentry.properties files..." +for project in "${PROJECTS[@]}"; do + symlink_file "$SOURCE_DIR/$project/ios/sentry.properties" "$project/ios/sentry.properties" + symlink_file "$SOURCE_DIR/$project/android/sentry.properties" "$project/android/sentry.properties" +done +echo "" + +# Run copy-sample-files scripts for projects that have them +echo "Running copy-sample-files scripts..." +for project in "dapps/W3MWagmi" "wallets/rn_cli_wallet"; do + if [ -f "$project/scripts/copy-sample-files.sh" ]; then + echo "Running $project/scripts/copy-sample-files.sh" + (cd "$project" && zsh scripts/copy-sample-files.sh) + fi +done +echo "" + +echo -e "${GREEN}Workspace setup complete!${NC}" diff --git a/wallets/rn_cli_wallet/AGENTS.md b/wallets/rn_cli_wallet/AGENTS.md new file mode 100644 index 00000000..78cbb6d2 --- /dev/null +++ b/wallets/rn_cli_wallet/AGENTS.md @@ -0,0 +1,292 @@ +# Agent Documentation: RN CLI Wallet + +This file provides guidance to AI agents when working with code in this repository. + +## Project Overview + +**RN CLI Wallet** (React Native CLI Wallet) is a comprehensive wallet application demonstrating integration with **WalletConnect WalletKit SDK**. It showcases how to build a multi-chain wallet supporting: + +- **EIP155** (Ethereum & 17 EVM-compatible chains) +- **Sui** blockchain +- **TON** blockchain +- **Tron** blockchain + +This is a production-ready reference implementation for developers building wallet applications with WalletConnect. + +## Tech Stack + +### Core Technologies +- **React Native**: 0.82.0 +- **React**: 19.1.1 +- **TypeScript**: ^5.8.3 + +### WalletConnect SDKs +- **@reown/walletkit**: Main WalletConnect wallet SDK +- **@walletconnect/react-native-compat**: React Native compatibility layer +- **@walletconnect/pay**: WalletConnect Pay integration + +### Blockchain Libraries +- **ethers** (5.8.0): Ethereum/EVM interactions +- **@mysten/sui**: Sui blockchain support +- **@ton/core**, **@ton/crypto**, **@ton/ton**: TON blockchain +- **tronweb**: Tron blockchain + +### Key Libraries +- **@react-navigation**: Navigation (stack, bottom-tabs) +- **valtio**: Reactive state management (proxy-based) +- **react-native-mmkv**: Fast key-value storage +- **react-native-quick-crypto**: Cryptographic operations +- **bip39**: Mnemonic seed phrase generation +- **react-native-vision-camera**: QR code scanning +- **@sentry/react-native**: Error tracking + +## Architecture + +### Project Structure + +``` +rn_cli_wallet/ +├── src/ +│ ├── screens/ +│ │ ├── App.tsx # Root component with initialization +│ │ ├── Connections/ # Active wallet connections +│ │ ├── Scan/ # QR code scanning +│ │ ├── SessionDetail/ # Session management +│ │ ├── Settings/ # Wallet & chain settings +│ │ └── LogList/ # Event logging +│ ├── modals/ +│ │ ├── SessionSignModal.tsx +│ │ ├── SessionSendTransactionModal.tsx +│ │ ├── SessionAuthenticateModal.tsx +│ │ ├── ImportWalletModal.tsx +│ │ ├── SessionSuiSignAndExecuteTransactionModal.tsx +│ │ ├── SessionTonSignDataModal.tsx +│ │ ├── SessionTonSendMessageModal.tsx +│ │ ├── SessionSignTronModal.tsx +│ │ ├── PaymentOptionsModal/ # WalletConnect Pay +│ │ └── RequestModal.tsx +│ ├── navigators/ +│ │ ├── RootStackNavigator.tsx +│ │ ├── HomeTabNavigator.tsx +│ │ ├── ConnectionsStack.tsx +│ │ └── SettingsStack.tsx +│ ├── components/ +│ │ ├── Modal/ +│ │ ├── ActionButton.tsx +│ │ ├── Card.tsx +│ │ ├── ConnectButton.tsx +│ │ ├── VerifyInfoBox.tsx # EIP-4361 verification +│ │ └── Text.tsx +│ ├── store/ +│ │ ├── SettingsStore.ts # App state (addresses, sessions) +│ │ ├── ModalStore.ts # Modal state +│ │ └── PayStore.ts # Payment state +│ ├── lib/ # Chain-specific wallet implementations +│ │ ├── EIP155Lib.ts # Ethereum wallet (ethers.js) +│ │ ├── SuiLib.ts # Sui wallet +│ │ ├── TonLib.ts # TON wallet +│ │ └── TronLib.ts # Tron wallet +│ ├── utils/ +│ │ ├── WalletKitUtil.ts # WalletKit initialization +│ │ ├── EIP155RequestHandlerUtil.ts +│ │ ├── SuiRequestHandlerUtil.ts +│ │ ├── TonRequestHandlerUtil.ts +│ │ ├── TronRequestHandlerUtil.ts +│ │ └── ... +│ ├── hooks/ +│ │ ├── useInitializeWalletKit.ts +│ │ ├── useInitializePaySDK.ts +│ │ ├── useWalletKitEventsManager.ts +│ │ └── ... +│ ├── constants/ # Chain definitions +│ │ ├── Eip155.ts # 17 EVM chains +│ │ ├── Sui.ts +│ │ ├── Ton.ts +│ │ └── Tron.ts +│ └── assets/ +├── android/ +├── ios/ +├── scripts/ +└── package.json +``` + +### State Management + +Uses **Valtio** (proxy-based reactive state): + +- **SettingsStore**: Wallet addresses, sessions, chain settings, device ID +- **ModalStore**: Modal visibility and request data +- **PayStore**: WalletConnect Pay state + +### Navigation + +**React Navigation** with: +- Bottom tabs: Connections, Scan, Settings, Logs +- Stack navigators for each tab section +- Modal screens for signing requests + +## Key Features + +### Multi-Chain Support + +**EIP155 (17 chains)** +- Ethereum, Polygon, Arbitrum, Optimism, Base +- Avalanche, BSC, Fantom, zkSync, Gnosis +- Moonbeam, Celo, Aurora, Zora, and more + +**Other Chains** +- Sui (mainnet, testnet, devnet) +- TON (mainnet, testnet) +- Tron + +### Wallet Functionality +- Import wallet via mnemonic or private key +- HD key derivation for multiple accounts +- Transaction signing for all supported chains +- Message signing (personal_sign, eth_signTypedData, etc.) +- Chain switching and dynamic updates + +### WalletConnect Integration +- Session management and pairing via QR code +- Multi-chain session support +- Deep linking (WalletConnect URI parsing) +- WalletConnect Pay SDK +- EIP-4361 (Sign-In with Ethereum) verification + +### Request Handling Modals +- `SessionSignModal`: Message signing +- `SessionSendTransactionModal`: EVM transactions +- `SessionAuthenticateModal`: SIWE authentication +- `SessionSuiSignAndExecuteTransactionModal`: Sui transactions +- `SessionTonSignDataModal` / `SessionTonSendMessageModal`: TON +- `SessionSignTronModal`: Tron signing + +## Environment Variables + +Required in `.env`: +```bash +ENV_PROJECT_ID="" # WalletConnect Project ID (required) +ENV_SENTRY_DSN="" # Sentry error tracking (optional) +ENV_TON_CENTER_API_KEY="" # TON blockchain API key (optional) +ENV_PAY_API_KEY="" # WalletConnect Pay API key (optional) +SENTRY_DISABLE_AUTO_UPLOAD=true # Disable Sentry auto upload for Android builds +``` + +## Development + +### Prerequisites +- Node.js >= 20 +- Yarn 3.8.7 +- Ruby 3.3.0 (for iOS/CocoaPods) +- Xcode & Android Studio + +### Setup +```bash +yarn install +cp .env.example .env +# Edit .env with your project ID +yarn android # or yarn ios +``` + +### Scripts +- `yarn start`: Start Metro bundler +- `yarn android`: Run on Android (debug) +- `yarn ios`: Run on iOS (debug scheme) +- `yarn ios:internal`: Run iOS internal scheme +- `yarn android:build`: Build release APK +- `yarn lint`: Run ESLint +- `yarn test`: Run Jest tests +- `yarn e2e`: Run Maestro E2E tests + +### Build Variants +```bash +yarn run copy:debug # Debug configuration +yarn run copy:internal # Internal testing +yarn run copy:production # Production release +``` + +## Common Patterns + +### WalletKit Initialization + +```typescript +// hooks/useInitializeWalletKit.ts +import { WalletKit } from '@reown/walletkit'; + +const walletKit = await WalletKit.init({ + core, + metadata: { + name: 'RN Wallet', + // ... + }, +}); +``` + +### Handling Session Requests + +```typescript +// utils/EIP155RequestHandlerUtil.ts +export async function approveEIP155Request( + requestEvent: SignClientTypes.EventArguments['session_request'] +) { + const { params, id } = requestEvent; + // Handle different methods: personal_sign, eth_sendTransaction, etc. +} +``` + +### Chain-Specific Libraries + +```typescript +// lib/EIP155Lib.ts +import { Wallet } from 'ethers'; + +class EIP155Lib { + wallet: Wallet; + + signMessage(message: string) { + return this.wallet.signMessage(message); + } + + sendTransaction(transaction: TransactionRequest) { + return this.wallet.sendTransaction(transaction); + } +} +``` + +### Valtio State + +```typescript +import { proxy, useSnapshot } from 'valtio'; + +export const SettingsStore = proxy({ + eip155Address: '', + suiAddress: '', + tonAddress: '', + tronAddress: '', + sessions: [], +}); + +// In component +const { eip155Address } = useSnapshot(SettingsStore); +``` + +## Code Quality Guidelines + +### After Making Changes + +**Always run these checks and fix any errors before committing:** + +```bash +yarn lint # Check and fix ESLint errors +yarn prettier --write . # Format code with Prettier +npx tsc --noEmit # Check for TypeScript errors +``` + +### Style +- Use TypeScript strict mode +- Follow ESLint + Prettier configuration +- Use path aliases (`@/`) for imports +- Handle all blockchain errors gracefully +- Show toast notifications for user feedback +- Log important events via `useLogs` hook +- Test signing flows on testnets before mainnet diff --git a/wallets/rn_cli_wallet/CLAUDE.md b/wallets/rn_cli_wallet/CLAUDE.md new file mode 100644 index 00000000..c3170642 --- /dev/null +++ b/wallets/rn_cli_wallet/CLAUDE.md @@ -0,0 +1 @@ +AGENTS.md diff --git a/wallets/rn_cli_wallet/package.json b/wallets/rn_cli_wallet/package.json index dbda7715..b2ba6c7f 100644 --- a/wallets/rn_cli_wallet/package.json +++ b/wallets/rn_cli_wallet/package.json @@ -3,6 +3,7 @@ "version": "1.0.0", "private": true, "scripts": { + "postinstall": "./scripts/copy-sample-files.sh", "android": "yarn run copy:debug && react-native run-android --mode=debug --appId com.walletconnect.web3wallet.rnsample.debug", "android:build": "yarn run copy:production && cd android && ./gradlew clean && ./gradlew assembleRelease", "android:build:internal": "yarn run copy:internal && cd android && ./gradlew clean && ./gradlew assembleInternal", diff --git a/wallets/rn_cli_wallet/scripts/copy-sample-files.sh b/wallets/rn_cli_wallet/scripts/copy-sample-files.sh index d3ec2e85..7cfeb58f 100755 --- a/wallets/rn_cli_wallet/scripts/copy-sample-files.sh +++ b/wallets/rn_cli_wallet/scripts/copy-sample-files.sh @@ -1,8 +1,23 @@ -# bash script that copies the mock files to the correct location +#!/bin/zsh +# Script that copies mock files to the correct location (skips if file exists) -cp .env.example .env -cp android/app/google-services.mock.json android/app/google-services.json -cp android/app/debug.keystore.mock android/app/debug.keystore -cp android/secrets.properties.mock android/secrets.properties +copy_if_missing() { + local src="$1" + local dest="$2" + if [ ! -f "$src" ]; then + echo "Skipped (source not found): $src" + return + fi + if [ -f "$dest" ]; then + echo "Skipped (exists): $dest" + return + fi + cp "$src" "$dest" + echo "Copied: $dest" +} -cp ios/GoogleService/GoogleService-Info.mock.plist ios/GoogleService/GoogleService-Debug-Info.plist +copy_if_missing .env.example .env +copy_if_missing android/app/google-services.mock.json android/app/google-services.json +copy_if_missing android/app/debug.keystore.mock android/app/debug.keystore +copy_if_missing android/secrets.properties.mock android/secrets.properties +copy_if_missing ios/GoogleService/GoogleService-Info.mock.plist ios/GoogleService/GoogleService-Debug-Info.plist