Skip to content

Commit 5a3183d

Browse files
refactor(rn_cli_wallet): simplify payment flow with centralized store
Migrate payment state from local useReducer to centralized Valtio PaymentStore, reducing PaymentOptionsModal from 573 to 203 lines. Remove IntroView, CollectDataView, and reducer.ts. Add theme support for WebView data collection and improve deep link debugging. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9233fa3 commit 5a3183d

File tree

17 files changed

+543
-999
lines changed

17 files changed

+543
-999
lines changed

wallets/rn_cli_wallet/AGENTS.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ rn_cli_wallet/
8181
│ ├── store/
8282
│ │ ├── SettingsStore.ts # App state (addresses, sessions)
8383
│ │ ├── ModalStore.ts # Modal state
84-
│ │ └── PayStore.ts # Payment state
84+
│ │ └── PaymentStore.ts # Payment state
8585
│ ├── lib/ # Chain-specific wallet implementations
8686
│ │ ├── EIP155Lib.ts # Ethereum wallet (ethers.js)
8787
│ │ ├── SuiLib.ts # Sui wallet
@@ -117,7 +117,7 @@ Uses **Valtio** (proxy-based reactive state):
117117

118118
- **SettingsStore**: Wallet addresses, sessions, chain settings, device ID
119119
- **ModalStore**: Modal visibility and request data
120-
- **PayStore**: WalletConnect Pay state
120+
- **PaymentStore**: WalletConnect Pay state
121121

122122
### Navigation
123123

@@ -345,5 +345,5 @@ npx tsc --noEmit # Check for TypeScript errors
345345
- Use path aliases (`@/`) for imports
346346
- Handle all blockchain errors gracefully
347347
- Show toast notifications for user feedback
348-
- Log important events via `useLogs` hook
348+
- Log important events via `LogStore` (e.g., `LogStore.log()`, `LogStore.warn()`, `LogStore.error()`)
349349
- Test signing flows on testnets before mainnet

wallets/rn_cli_wallet/android/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ android {
8585
applicationId "com.walletconnect.web3wallet.rnsample"
8686
minSdkVersion rootProject.ext.minSdkVersion
8787
targetSdkVersion rootProject.ext.targetSdkVersion
88-
versionCode 57
88+
versionCode 58
8989
versionName "1.0"
9090
resValue "string", "build_config_package", "com.walletconnect.web3wallet.rnsample"
9191
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
<application>
3+
<activity android:name=".MainActivity">
4+
<intent-filter>
5+
<data android:scheme="rn-web3wallet-debug" />
6+
<action android:name="android.intent.action.VIEW" />
7+
<category android:name="android.intent.category.DEFAULT" />
8+
<category android:name="android.intent.category.BROWSABLE" />
9+
</intent-filter>
10+
<intent-filter android:autoVerify="true">
11+
<data android:scheme="https"/>
12+
<data android:host="lab.reown.com"/>
13+
<data android:pathPrefix="/rn_walletkit_debug"/>
14+
<action android:name="android.intent.action.VIEW" />
15+
<category android:name="android.intent.category.DEFAULT" />
16+
<category android:name="android.intent.category.BROWSABLE" />
17+
</intent-filter>
18+
</activity>
19+
</application>
20+
</manifest>

wallets/rn_cli_wallet/ios/Podfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,7 +1811,7 @@ PODS:
18111811
- React-RCTFBReactNativeSpec
18121812
- ReactCommon/turbomodule/core
18131813
- SocketRocket
1814-
- react-native-compat (2.23.4-canary.3):
1814+
- react-native-compat (2.23.5):
18151815
- boost
18161816
- DoubleConversion
18171817
- fast_float
@@ -3413,7 +3413,7 @@ SPEC CHECKSUMS:
34133413
React-logger: 30adf849117e87cf86e88dca1824bb0f18f87e10
34143414
React-Mapbuffer: 499069c3dcd4b438a70fcc2a65e8a4185ea9170b
34153415
React-microtasksnativemodule: f0238469cb9894fd18c419137d312665b8fc05b3
3416-
react-native-compat: bfee2dc4b6ead87b8095266b2f936fa48000241d
3416+
react-native-compat: 33720a178be8c565138dfdaa5d9d931f59786d2f
34173417
react-native-config: 644074ab88db883fcfaa584f03520ec29589d7df
34183418
react-native-get-random-values: d16467cf726c618e9c7a8c3c39c31faa2244bbba
34193419
react-native-keyboard-controller: f2ed31d12d9d8cb8ad2f9110c18fa5df499b66a3
@@ -3473,4 +3473,4 @@ SPEC CHECKSUMS:
34733473

34743474
PODFILE CHECKSUM: c628b2429557a37c740a92f2f7ffe4c0bbb44669
34753475

3476-
COCOAPODS: 1.16.2
3476+
COCOAPODS: 1.14.3

wallets/rn_cli_wallet/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"scripts": {
66
"postinstall": "./scripts/copy-sample-files.sh",
77
"android": "react-native run-android --mode=debug --appId com.walletconnect.web3wallet.rnsample.debug",
8+
"android:internal": "react-native run-android --mode=debug --appId com.walletconnect.web3wallet.rnsample.internal",
89
"android:build": "cd android && ./gradlew clean && ./gradlew assembleRelease",
910
"android:build:internal": "cd android && ./gradlew clean && ./gradlew assembleInternal",
1011
"ios": "react-native run-ios --scheme 'RNWallet-Debug'",
@@ -66,7 +67,7 @@
6667
"react-native-svg": "15.14.0",
6768
"react-native-toast-message": "2.3.3",
6869
"react-native-vision-camera": "4.7.2",
69-
"react-native-webview": "^13.16.0",
70+
"react-native-webview": "13.16.0",
7071
"react-native-worklets": "^0.7.1",
7172
"stream-browserify": "3.0.0",
7273
"tronweb": "^6.1.1",

wallets/rn_cli_wallet/src/hooks/usePairing.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,23 @@ import { walletKit, isPaymentLink } from '@/utils/WalletKitUtil';
44
import LogStore from '@/store/LogStore';
55
import ModalStore from '@/store/ModalStore';
66
import SettingsStore from '@/store/SettingsStore';
7+
import PaymentStore from '@/store/PaymentStore';
78
import { EIP155_CHAINS } from '@/constants/Eip155';
89

910
export { isPaymentLink };
1011

1112
export function usePairing() {
1213
const handlePaymentLink = useCallback(async (paymentLink: string) => {
13-
ModalStore.open('PaymentOptionsModal', {
14+
PaymentStore.startPayment({
1415
loadingMessage: 'Preparing your payment...',
1516
});
17+
ModalStore.open('PaymentOptionsModal');
18+
1619
await SettingsStore.state.initPromise;
1720

1821
const payClient = walletKit?.pay;
1922
if (!payClient) {
20-
ModalStore.open('PaymentOptionsModal', {
21-
errorMessage: 'Pay SDK not initialized. Please restart the app.',
22-
});
23+
PaymentStore.setError('Pay SDK not initialized. Please restart the app.');
2324
return;
2425
}
2526

@@ -47,11 +48,11 @@ export function usePairing() {
4748
{ paymentOptions },
4849
);
4950

50-
ModalStore.open('PaymentOptionsModal', { paymentOptions });
51+
PaymentStore.setPaymentOptions(paymentOptions);
5152
} catch (error: any) {
52-
ModalStore.open('PaymentOptionsModal', {
53-
errorMessage: error?.message || 'Failed to fetch payment options',
54-
});
53+
PaymentStore.setError(
54+
error?.message || 'Failed to fetch payment options',
55+
);
5556
}
5657
}, []);
5758

wallets/rn_cli_wallet/src/modals/PaymentOptionsModal/CollectDataView.tsx

Lines changed: 0 additions & 142 deletions
This file was deleted.

wallets/rn_cli_wallet/src/modals/PaymentOptionsModal/CollectDataWebView.tsx

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ import { WebView, WebViewNavigation } from 'react-native-webview';
44
import type { ShouldStartLoadRequest } from 'react-native-webview/lib/WebViewTypes';
55
import { btoa } from 'react-native-quick-base64';
66

7+
import { useSnapshot } from 'valtio';
8+
79
import { useTheme } from '@/hooks/useTheme';
810
import { WalletConnectLoading } from '@/components/WalletConnectLoading';
911
import { Spacing } from '@/utils/ThemeUtil';
1012
import LogStore from '@/store/LogStore';
13+
import SettingsStore from '@/store/SettingsStore';
1114

1215
function getBaseUrl(urlString: string): string {
1316
try {
@@ -24,16 +27,27 @@ const PREFILL_DATA = {
2427
dob: '1990-06-15',
2528
};
2629

27-
function buildUrlWithPrefill(baseUrl: string): string {
30+
function buildUrlWithPrefill(
31+
baseUrl: string,
32+
themeMode: 'light' | 'dark',
33+
): string {
2834
const prefillJson = JSON.stringify(PREFILL_DATA);
2935
const prefillBase64 = btoa(prefillJson);
3036

31-
if (baseUrl.includes('prefill=')) {
32-
return baseUrl.replace(/prefill=([^&]*)/, `prefill=${prefillBase64}`);
37+
let result = baseUrl;
38+
39+
if (result.includes('prefill=')) {
40+
result = result.replace(/prefill=([^&]*)/, `prefill=${prefillBase64}`);
41+
} else {
42+
const separator = result.includes('?') ? '&' : '?';
43+
result = `${result}${separator}prefill=${prefillBase64}`;
3344
}
3445

35-
const separator = baseUrl.includes('?') ? '&' : '?';
36-
return `${baseUrl}${separator}prefill=${prefillBase64}`;
46+
// Append theme param based on wallet config
47+
const theme = themeMode === 'dark' ? 'dark' : 'light';
48+
result += `&theme=${theme}`;
49+
50+
return result;
3751
}
3852

3953
interface CollectDataWebViewProps {
@@ -48,18 +62,19 @@ export function CollectDataWebView({
4862
onError,
4963
}: CollectDataWebViewProps) {
5064
const Theme = useTheme();
65+
const { themeMode } = useSnapshot(SettingsStore.state);
5166
const webViewRef = useRef<WebView>(null);
5267
const [isLoading, setIsLoading] = useState(true);
5368
const isMountedRef = useRef(true);
5469

5570
const finalUrl = useMemo(() => {
56-
const urlWithPrefill = buildUrlWithPrefill(url);
71+
const urlWithPrefill = buildUrlWithPrefill(url, themeMode);
5772
LogStore.log('WebView URL with prefill', 'CollectDataWebView', 'finalUrl', {
5873
originalUrl: url,
5974
finalUrl: urlWithPrefill,
6075
});
6176
return urlWithPrefill;
62-
}, [url]);
77+
}, [url, themeMode]);
6378

6479
useEffect(() => {
6580
isMountedRef.current = true;

0 commit comments

Comments
 (0)