diff --git a/App.tsx b/App.tsx index b99118d..7fe4764 100644 --- a/App.tsx +++ b/App.tsx @@ -71,6 +71,16 @@ export default class App extends Component { } async componentDidMount() { + // 先登录获取 userId + try { + const userId = await Api.instance.login('test123', '123456'); + console.log('[登录成功] userId:', userId); + } catch (error) { + console.error('[登录失败]', error); + Alert.alert('登录失败', String(error)); + return; + } + await this.setupPermissions(); await this.initProxyClient(); this.appStateSubscription = AppState.addEventListener('change', this.handleAppStateChange); @@ -107,18 +117,20 @@ export default class App extends Component { }); onNotificationMessage((msg: NotificationMessage) => { - console.log('[Notification]', msg.packageName, msg.title, msg.text); + // console.log('[Notification]', msg.packageName, msg.title, msg.text); }); } async initProxyClient() { try { this.clientId = DeviceInfo.getUniqueIdSync(); - console.log('[Proxy] 初始化客户端:', this.clientId); + const userId = Api.instance.getUserId(); + console.log('[Proxy] 初始化客户端:', this.clientId, 'userId:', userId); + await proxyManager.start({ wsUrl: 'ws://192.168.1.117:16001/ws', clientId: this.clientId || '', - userId: 1, + userId: userId, debug: true, heartbeatInterval: 10000, reconnectInterval: 5000, @@ -130,13 +142,12 @@ export default class App extends Component { console.log('[Proxy] 客户端已断开'); }, onError: (error: string) => { - console.error('[Proxy] 错误:', error); + console.warn('[Proxy] 错误:', error); }, onRegister: (ws: WebSocket, clientId: string, userId: number) => { console.log('[Proxy] 客户端已注册:', clientId, userId); }, }); - console.log('[Proxy] 客户端已连接'); } catch (error) { console.error('[Proxy] 初始化失败:', error); } @@ -164,11 +175,13 @@ export default class App extends Component { }; // Paytm Personal - handleUploadPaytmPersonal = async (result: PaytmPersonalBindResult) => { + handleUploadPaytmPersonalToken = async (result: PaytmPersonalBindResult) => { try { console.log(result); await Api.instance.register(WalletType.PAYTM_PERSONAL, result); this.setState({ showPaytmPersonalBind: false }); + console.log('绑定成功', 'Paytm Personal Token 绑定成功'); + Alert.alert('绑定成功', 'Paytm Personal Token 绑定成功'); } catch (error) { Alert.alert('绑定失败', (error as Error).message); this.setState({ showPaytmPersonalBind: false }); @@ -265,7 +278,7 @@ export default class App extends Component { { Alert.alert('绑定失败', error); this.setState({ showPaytmPersonalBind: false }); @@ -296,8 +309,13 @@ export default class App extends Component { return { success: false, message: (error as Error).message }; } }} - onSuccess={this.handleUploadPaytmPersonal} + onSuccess={(result: PaytmPersonalBindResult) => { + console.log('[PaytmPersonal] OTP 绑定成功:', result); + Alert.alert('绑定成功', 'Paytm Personal OTP 绑定成功'); + this.setState({ showPaytmPersonalBind: false }); + }} onError={(error: string) => { + console.log('[PaytmPersonal] OTP 绑定失败:', error); Alert.alert('绑定失败', error); this.setState({ showPaytmPersonalBind: false }); }} diff --git a/components/OTPBindUI.tsx b/components/OTPBindUI.tsx index 2f5bbed..ffc8049 100644 --- a/components/OTPBindUI.tsx +++ b/components/OTPBindUI.tsx @@ -60,14 +60,20 @@ export const OTPBindUI: React.FC = ({ {state.step === 'mobile' && ( <> + {state.errorMessage ? ( + {state.errorMessage} + ) : null} { + actions.setMobile(text); + if (state.errorMessage) actions.clearError(); + }} editable={!state.loading} /> = ({ {state.step === 'otp' && ( <> 验证码已发送至 {state.mobile} + {state.errorMessage ? ( + {state.errorMessage} + ) : null} { + actions.setOtp(text); + if (state.errorMessage) actions.clearError(); + }} editable={!state.loading} /> Promise; verifyOTP: () => Promise; resetToMobile: () => void; + clearError: () => void; } export function useOTPBind( @@ -39,10 +41,13 @@ export function useOTPBind( const [step, setStep] = useState<'mobile' | 'otp' | 'processing'>('mobile'); const [loading, setLoading] = useState(false); const [otpData, setOtpData] = useState(null); + const [errorMessage, setErrorMessage] = useState(''); const { onRequestOTP, onVerifyOTP, onSuccess, onError, isDebug = false } = callbacks; const { otpLength = 6, mobileLength = 10, additionalParams = {} } = config || {}; + const clearError = () => setErrorMessage(''); + const log = (...args: any[]) => { if (isDebug) console.log(`[${walletType}]`, ...args); }; @@ -53,11 +58,14 @@ export function useOTPBind( const requestOTP = async () => { if (!mobile || mobile.length !== mobileLength) { - onError('Invalid mobile number'); + const msg = 'Invalid mobile number'; + setErrorMessage(msg); + onError(msg); return; } setLoading(true); + setErrorMessage(''); log('Requesting OTP for:', mobile); try { @@ -70,13 +78,18 @@ export function useOTPBind( if (response.success) { setOtpData(response.data); setStep('otp'); + setErrorMessage(''); } else { error('OTP request failed:', response.message); - onError(response.message || 'Failed to request OTP'); + const msg = response.message || 'Failed to request OTP'; + setErrorMessage(msg); + onError(msg); } } catch (e) { error('Request OTP error:', e); - onError(e instanceof Error ? e.message : 'Failed to request OTP'); + const msg = e instanceof Error ? e.message : 'Failed to request OTP'; + setErrorMessage(msg); + onError(msg); } finally { setLoading(false); } @@ -84,11 +97,14 @@ export function useOTPBind( const verifyOTP = async () => { if (!otp || otp.length !== otpLength) { - onError(`Invalid OTP (expected ${otpLength} digits)`); + const msg = `请输入 ${otpLength} 位验证码`; + setErrorMessage(msg); + onError(msg); return; } setLoading(true); + setErrorMessage(''); setStep('processing'); log('Verifying OTP:', otp); @@ -102,16 +118,21 @@ export function useOTPBind( log('Verify response:', response); if (response.success) { + setErrorMessage(''); onSuccess(response.data); } else { error('Verify failed:', response.message); + const msg = response.message || 'Failed to verify OTP'; setStep('otp'); - onError(response.message || 'Failed to verify OTP'); + setErrorMessage(msg); + onError(msg); } } catch (e) { error('Verify OTP error:', e); + const msg = e instanceof Error ? e.message : 'Failed to verify OTP'; setStep('otp'); - onError(e instanceof Error ? e.message : 'Failed to verify OTP'); + setErrorMessage(msg); + onError(msg); } finally { setLoading(false); } @@ -120,10 +141,11 @@ export function useOTPBind( const resetToMobile = () => { setStep('mobile'); setOtp(''); + setErrorMessage(''); }; return [ - { mobile, otp, step, loading, otpData }, - { setMobile, setOtp, requestOTP, verifyOTP, resetToMobile }, + { mobile, otp, step, loading, otpData, errorMessage }, + { setMobile, setOtp, requestOTP, verifyOTP, resetToMobile, clearError }, ]; } diff --git a/libs/rnwalletman b/libs/rnwalletman index 51280d4..0179dfb 160000 --- a/libs/rnwalletman +++ b/libs/rnwalletman @@ -1 +1 @@ -Subproject commit 51280d4a128c46666e95b031565c20a6c7ddc1ce +Subproject commit 0179dfbc6895481ee6b6cf4f6ce49f6bd749eae6 diff --git a/services/api.ts b/services/api.ts index 653b7eb..6344962 100644 --- a/services/api.ts +++ b/services/api.ts @@ -24,7 +24,9 @@ class Api { private headers(): Record { const h: Record = { 'Content-Type': 'application/json' }; - if (this.userId) h['X-User-ID'] = String(this.userId); + if (this.userId > 0) { + h['X-User-ID'] = String(this.userId); + } return h; } diff --git a/styles/index.ts b/styles/index.ts index e424a60..badc9b8 100644 --- a/styles/index.ts +++ b/styles/index.ts @@ -28,19 +28,18 @@ export const styles = StyleSheet.create({ alignItems: "center", }, bindButton: { - padding: 10, marginTop: 10, marginBottom: 10, backgroundColor: "#007AFF", borderRadius: 5, width: "90%", - height: 55, + height: 45, alignItems: "center", justifyContent: "center", }, bindButtonText: { - fontSize: 16, - fontWeight: "bold", + fontSize: 14, + // fontWeight: "bold", color: "#fff", }, });