Skip to content

Commit 7569d39

Browse files
feat: onramp (#323)
1 parent 594aba1 commit 7569d39

File tree

156 files changed

+5528
-409
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+5528
-409
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@reown/appkit-scaffold-react-native': minor
3+
'@reown/appkit-common-react-native': minor
4+
'@reown/appkit-core-react-native': minor
5+
'@reown/appkit-siwe-react-native': minor
6+
'@reown/appkit-ui-react-native': minor
7+
'@reown/appkit-auth-ethers-react-native': minor
8+
'@reown/appkit-auth-wagmi-react-native': minor
9+
'@reown/appkit-coinbase-ethers-react-native': minor
10+
'@reown/appkit-coinbase-wagmi-react-native': minor
11+
'@reown/appkit-ethers-react-native': minor
12+
'@reown/appkit-ethers5-react-native': minor
13+
'@reown/appkit-scaffold-utils-react-native': minor
14+
'@reown/appkit-wagmi-react-native': minor
15+
'@reown/appkit-wallet-react-native': minor
16+
---
17+
18+
feat: added onramp feature
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
---
2+
description: This rule gives the overall context of the appkit react native project
3+
globs:
4+
---
5+
React Native SDK Engineering Context:
6+
You are a **world-class Staff Software Engineer** specializing in **React Native SDKs**, with expertise in **performance, modularity, maintainability, and developer experience**.
7+
8+
For every request, you must:
9+
10+
### **1️⃣ Enforce SDK Best Practices**
11+
12+
- **Function-based Component Architecture**: Use functional components with hooks exclusively (e.g., `useState`, `useEffect`) for all UI and logic.
13+
- **TypeScript-first Approach**: Enforce strict TypeScript with `@types/react-native`, adhering to the `tsconfig.json` rules (e.g., `noUncheckedIndexedAccess`, `strict` mode).
14+
- **Valtio or Controller-based State Management**: Use Valtio’s proxy-based reactivity for state management where applicable (e.g., `proxy({ address: '' })`). If using custom controllers (e.g., `AccountController.ts`), document their proxy-based implementation explicitly as the preferred pattern.
15+
- **Follow the SDK package structure**, keeping utilities, controllers, and UI components separate.
16+
17+
### **2️⃣ Optimize for Performance & SDK Usability**
18+
19+
- Ensure efficient rendering with:
20+
- **Efficient Rendering**: Apply `React.memo`, `useCallback`, and `useMemo` to prevent unnecessary re-renders in UI components and hooks.
21+
- **FlatList for Lists**: Use `FlatList` with `keyExtractor` for rendering large datasets (e.g., wallet lists), avoiding array mapping with `map`.
22+
- **Native Animations**: Use React Native’s `Animated` API for animations; avoid external libraries like `react-native-reanimated` to minimize dependencies.
23+
- **Debounce expensive operations** (like API calls) using `lodash.debounce`.
24+
25+
### **3️⃣ Code Consistency & SDK Structure**
26+
27+
- **Directory structure must remain modular**:
28+
```
29+
packages/
30+
core/
31+
src/
32+
controllers/
33+
utils/
34+
index.ts
35+
ui/
36+
src/
37+
components/
38+
hooks/
39+
index.ts
40+
auth/
41+
src/
42+
index.ts
43+
```
44+
- Prefer `@reown/appkit-ui-react-native` components over `react-native` defaults:
45+
- ✅ Use `<Text />` from `@reown/appkit-ui-react-native` instead of `<Text />`
46+
- ✅ Use `<Button />` instead of `<TouchableOpacity />`
47+
- ✅ **Use `FlatList` for rendering lists**, do not wrap it in `<List />`
48+
- **Sort imports**:
49+
1. **External Libraries** (`react`, `valtio`, `viem`)
50+
2. **Internal SDK Modules** (`@reown/appkit-ui-react-native`)
51+
3. **Relative Imports** (`./controllers/RouterController.ts`)
52+
53+
```typescript
54+
import React from 'react';
55+
import { Text } from '@reown/appkit-ui-react-native';
56+
import { RouterController } from './controllers/RouterController';
57+
```
58+
59+
### **4️⃣ Secure & Scalable SDK API**
60+
61+
- Design **developer-friendly APIs** with:
62+
- Strongly typed method signatures (`(config: AppKitConfig) => void`).
63+
- Proper validation on input parameters.
64+
- Error handling to prevent crashes (`try-catch`).
65+
- **Use AsyncStorage sparingly**, only for:
66+
- Caching non-sensitive data (e.g., user preferences, session data).
67+
- Persisting lightweight app settings.
68+
- **Do not store sensitive data in AsyncStorage** (e.g., auth tokens, private keys).
69+
70+
### **5️⃣ Comprehensive Testing & Error Handling**
71+
72+
- **Unit Tests**: Implement tests using Jest and React Native Testing Library for all public APIs, controllers, and UI components, targeting **80%+ coverage**.
73+
74+
```typescript
75+
import { render } from '@testing-library/react-native';
76+
test('renders button', () => {
77+
const { getByText } = render(<Button>Click</Button>);
78+
expect(getByText('Click')).toBeTruthy();
79+
});
80+
```
81+
82+
- **Graceful Failure**: Ensure SDK methods fail safely:
83+
- Use `try-catch` in all async functions (e.g., `connectWallet`).
84+
- Throw `Error` objects with descriptive messages (e.g., `throw new Error('Failed to fetch wallet data')`).
85+
- Leverage `ErrorUtil.ts` for consistent error formatting.
86+
87+
```typescript
88+
import { ErrorUtil } from '../utils/ErrorUtil';
89+
async function connectWallet() {
90+
try {
91+
// Connection logic
92+
} catch (error) {
93+
throw ErrorUtil.formatError(error, 'Wallet connection failed');
94+
}
95+
}
96+
```
97+
98+
### **6️⃣ Maintain High Code Readability & Documentation**
99+
100+
- **Enforce ESLint & Prettier rules** (`.eslintrc.json`).
101+
- **Use JSDoc comments** for:
102+
- Public API methods (`@param`, `@returns`).
103+
- Complex logic explanations.
104+
- **No inline styles**, prefer `@reown/appkit-ui-react-native`’s styling approach.
105+
106+
### **7️⃣ SDK Navigation & Routing**
107+
108+
- **No `react-navigation`** → Use internal SDK router:
109+
- ✅ **Use `RouterController.ts` for navigation**.
110+
- ✅ Use programmatic navigation (`router.push()`, `router.goBack()`).
111+
- ✅ Avoid **deep linking dependencies**.
112+
113+
### **8️⃣ Optimize SDK Extensibility**
114+
115+
- **Make SDK modules easily extendable** via:
116+
- **Hooks & Context API** (`useAccount()`, `useNetwork()`).
117+
- **Custom Configurations** (e.g., passing options in `init()`).
118+
- **Event-driven architecture** (`onConnect`, `onDisconnect`).
119+
- **Separate UI from logic**:
120+
- Business logic → `controllers/`
121+
- UI components → `packages/ui/`
122+
123+
### **🔹 Outcome:**
124+
125+
By following these principles, ensure **a world-class React Native SDK** that is:
126+
✅ Highly performant
127+
✅ Modular & scalable
128+
✅ Secure with blockchain-specific safeguards
129+
✅ Developer-friendly with robust APIs, testing, and documentation
130+
✅ Aligned with AppKit conventions by leveraging its UI kit and controllers.

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"ignorePatterns": ["node_modules/", "build/", "lib/", "dist/", ".turbo", ".expo", "out/"],
55
"rules": {
66
"react/react-in-jsx-scope": 0,
7-
"no-duplicate-imports": "off",
7+
"no-duplicate-imports": "error",
88
"react-hooks/exhaustive-deps": "warn",
99
"no-console": ["error", { "allow": ["warn"] }],
1010
"newline-before-return": "error",

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,14 @@ android.iml
5151

5252
# yarn
5353
.yarn/*
54-
!.yarn/cache
5554
!.yarn/patches
5655
!.yarn/plugins
5756
!.yarn/releases
5857
!.yarn/sdks
5958
!.yarn/versions
6059

6160
# vscode
62-
.vscode/launch.json
61+
.vscode/launch.json
62+
63+
# cursor
64+
.cursor/mcp.json

apps/gallery/utils/PresetUtils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ export const iconOptions: IconType[] = [
129129
'arrowRight',
130130
'arrowTop',
131131
'browser',
132+
'card',
132133
'checkmark',
133134
'chevronBottom',
134135
'chevronLeft',
@@ -142,6 +143,7 @@ export const iconOptions: IconType[] = [
142143
'copy',
143144
'copySmall',
144145
'cursor',
146+
'currencyDollar',
145147
'desktop',
146148
'disconnect',
147149
'discord',
@@ -165,6 +167,7 @@ export const iconOptions: IconType[] = [
165167
'qrCode',
166168
'refresh',
167169
'search',
170+
'settings',
168171
'swapHorizontal',
169172
'swapVertical',
170173
'telegram',

apps/native/App.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { siweConfig } from './src/utils/SiweUtils';
2121

2222
import { AccountView } from './src/views/AccountView';
2323
import { ActionsView } from './src/views/ActionsView';
24-
import { getCustomWallets } from './src/utils/misc';
2524
import { chains } from './src/utils/WagmiUtils';
2625
import { OpenButton } from './src/components/OpenButton';
2726
import { DisconnectButton } from './src/components/DisconnectButton';
@@ -34,9 +33,8 @@ const metadata = {
3433
url: 'https://reown.com/appkit',
3534
icons: ['https://avatars.githubusercontent.com/u/179229932'],
3635
redirect: {
37-
native: 'redirect://',
38-
universal: 'https://appkit-lab.reown.com/rn_appkit',
39-
linkMode: true
36+
native: 'host.exp.exponent://',
37+
universal: 'https://appkit-lab.reown.com/rn_appkit'
4038
}
4139
};
4240

@@ -63,22 +61,20 @@ const wagmiConfig = defaultWagmiConfig({
6361

6462
const queryClient = new QueryClient();
6563

66-
const customWallets = getCustomWallets();
67-
6864
createAppKit({
6965
projectId,
7066
wagmiConfig,
7167
siweConfig,
7268
clipboardClient,
73-
customWallets,
7469
enableAnalytics: true,
7570
metadata,
7671
debug: true,
7772
features: {
7873
email: true,
7974
socials: ['x', 'discord', 'apple'],
8075
emailShowWallets: true,
81-
swaps: true
76+
swaps: true,
77+
onramp: true
8278
}
8379
});
8480

apps/native/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"eas:build": "eas build --platform all",
1414
"eas:build:local": "eas build --local --platform all",
1515
"eas:update": "eas update --branch preview",
16-
"playwright:test": "./scripts/replace-ep-test.sh && playwright test",
16+
"playwright:test": "./scripts/replace-ep-test.sh && playwright test tests/basic-tests.spec.ts && playwright test tests/wallet.spec.ts && playwright test tests/onramp.spec.ts",
1717
"playwright:install": "playwright install chromium",
1818
"deploy": "gh-pages --nojekyll -d dist",
1919
"build:web": "expo export -p web"

0 commit comments

Comments
 (0)