diff --git a/App.tsx b/App.tsx index 372ff0c..1e67520 100644 --- a/App.tsx +++ b/App.tsx @@ -35,7 +35,7 @@ import { PaytmBusinessOTPBind, } from './components/WalletBindComponents'; -import Api from './services/api'; +import Api, { loadServerDomain, saveServerDomain, getServerDomain } from './services/api'; import { AppProps, WalletmanAppState } from './types'; import { styles } from './styles'; import WebView from "react-native-webview"; @@ -62,6 +62,9 @@ export default class App extends Component { showMobikwikPersonalBind: false, showFreechargePersonalBind: false, proxyStatus: 'idle', + showServerSettings: false, + settingsHost: '', + settingsPort: '', }; this.deviceId = DeviceInfo.getUniqueIdSync(); @@ -69,6 +72,7 @@ export default class App extends Component { } async componentDidMount() { + await loadServerDomain(); await this.setupPermissions(); this.onProxyMessageSub = onProxyMessage((msg) => { @@ -141,7 +145,7 @@ export default class App extends Component { wsUrl: Api.WS_URL, clientId: this.clientId || '', userId: userId, - // debug: true, + debug: true, heartbeatInterval: 10000, reconnectInterval: 5000, reconnectMaxAttempts: Infinity, @@ -630,6 +634,60 @@ export default class App extends Component { return null; } + openServerSettings = () => { + const domain = getServerDomain(); + const colonIdx = domain.lastIndexOf(':'); + const host = colonIdx > 0 ? domain.substring(0, colonIdx) : domain; + const port = colonIdx > 0 ? domain.substring(colonIdx + 1) : ''; + this.setState({ showServerSettings: true, settingsHost: host, settingsPort: port }); + }; + + saveDomain = async () => { + const { settingsHost, settingsPort } = this.state; + const domain = settingsPort ? `${settingsHost}:${settingsPort}` : settingsHost; + await saveServerDomain(domain); + this.setState({ showServerSettings: false }); + Alert.alert('已保存', '重启 App 后生效'); + }; + + renderServerSettingsModal() { + const { showServerSettings, settingsHost, settingsPort } = this.state; + return ( + + + + 服务器设置 + Host + this.setState({ settingsHost: t })} + placeholder="192.168.1.198" + autoCapitalize="none" + keyboardType="default" + /> + Port + this.setState({ settingsPort: t })} + placeholder="16000" + keyboardType="number-pad" + /> + + this.setState({ showServerSettings: false })} style={{ paddingHorizontal: 16, paddingVertical: 8, marginRight: 10 }}> + 取消 + + + 保存 + + + + + + ); + } + render() { return ( @@ -653,6 +711,10 @@ export default class App extends Component { ); })()} {this.renderBindModal()} + {this.renderServerSettingsModal()} + + ⚙ 服务器设置 + { this.setState({ showPaytmPersonalBind: true, paytmPersonalBindType: 'otpMode' }); diff --git a/package.json b/package.json index 69fa693..7e61a9e 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "postinstall": "patch-package" }, "dependencies": { + "@react-native-async-storage/async-storage": "^1.23.1", "@react-native-cookies/cookies": "^6.2.1", "@react-native-ml-kit/barcode-scanning": "^2.0.0", "buffer": "^6.0.3", diff --git a/servers/walletman b/servers/walletman index 248df18..1f15329 160000 --- a/servers/walletman +++ b/servers/walletman @@ -1 +1 @@ -Subproject commit 248df18fcf005856ecc52195252b1a54dcb9fa22 +Subproject commit 1f15329fc2507c85dc87bdc57cd24cf3644fe50f diff --git a/services/api.ts b/services/api.ts index 05efeed..3a2ce0c 100644 --- a/services/api.ts +++ b/services/api.ts @@ -1,12 +1,30 @@ import { WalletType } from 'rnwalletman'; +import AsyncStorage from '@react-native-async-storage/async-storage'; -const DOMAIN = '192.168.1.117:16000'; -const BASE_URL = `http://${DOMAIN}`; -const WS_URL = `ws://${DOMAIN}/ws`; +const DEFAULT_DOMAIN = '192.168.1.198:16000'; +const STORAGE_KEY = 'server_domain'; + +let _domain = DEFAULT_DOMAIN; + +export async function loadServerDomain(): Promise { + const saved = await AsyncStorage.getItem(STORAGE_KEY); + if (saved) _domain = saved; + return _domain; +} + +export async function saveServerDomain(domain: string): Promise { + _domain = domain; + await AsyncStorage.setItem(STORAGE_KEY, domain); +} + +export function getServerDomain(): string { + return _domain; +} class Api { - public static readonly BASE_URL = BASE_URL; - public static readonly WS_URL = WS_URL; + public static get BASE_URL() { return `http://${_domain}`; } + public static get WS_URL() { return `ws://${_domain}/ws`; } + private static _instance: Api | null = null; private userId: number = 0; diff --git a/types.ts b/types.ts index 4b5f4a9..f1afe27 100644 --- a/types.ts +++ b/types.ts @@ -26,4 +26,9 @@ export interface WalletmanAppState { /* Proxy 状态 */ proxyStatus: 'idle' | 'connecting' | 'connected' | 'disconnected' | 'error'; proxyError?: string; + + /* Server 设置 */ + showServerSettings: boolean; + settingsHost: string; + settingsPort: string; }