optm
This commit is contained in:
19
App.tsx
19
App.tsx
@@ -1,5 +1,5 @@
|
||||
import React, { Component } from "react";
|
||||
import { Alert, AppState, AppStateStatus, Modal, Text, TextInput, TouchableOpacity, View } from "react-native";
|
||||
import { Alert, AppState, AppStateStatus, Modal, Switch, Text, TextInput, TouchableOpacity, View } from "react-native";
|
||||
import DeviceInfo from 'react-native-device-info';
|
||||
import {
|
||||
PhonePeBusinessBind,
|
||||
@@ -35,7 +35,7 @@ import {
|
||||
PaytmBusinessOTPBind,
|
||||
} from './components/WalletBindComponents';
|
||||
|
||||
import Api, { loadServerDomain, saveServerDomain, getServerDomain } from './services/api';
|
||||
import Api, { loadServerDomain, saveServerDomain, getServerDomain, getUseHttps } from './services/api';
|
||||
import { AppProps, WalletmanAppState } from './types';
|
||||
import { styles } from './styles';
|
||||
import WebView from "react-native-webview";
|
||||
@@ -65,6 +65,7 @@ export default class App extends Component<AppProps, WalletmanAppState> {
|
||||
showServerSettings: false,
|
||||
settingsHost: '',
|
||||
settingsPort: '',
|
||||
settingsHttps: true,
|
||||
};
|
||||
|
||||
this.deviceId = DeviceInfo.getUniqueIdSync();
|
||||
@@ -639,19 +640,19 @@ export default class App extends Component<AppProps, WalletmanAppState> {
|
||||
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 });
|
||||
this.setState({ showServerSettings: true, settingsHost: host, settingsPort: port, settingsHttps: getUseHttps() });
|
||||
};
|
||||
|
||||
saveDomain = async () => {
|
||||
const { settingsHost, settingsPort } = this.state;
|
||||
const { settingsHost, settingsPort, settingsHttps } = this.state;
|
||||
const domain = settingsPort ? `${settingsHost}:${settingsPort}` : settingsHost;
|
||||
await saveServerDomain(domain);
|
||||
await saveServerDomain(domain, settingsHttps);
|
||||
this.setState({ showServerSettings: false });
|
||||
Alert.alert('已保存', '重启 App 后生效');
|
||||
};
|
||||
|
||||
renderServerSettingsModal() {
|
||||
const { showServerSettings, settingsHost, settingsPort } = this.state;
|
||||
const { showServerSettings, settingsHost, settingsPort, settingsHttps } = this.state;
|
||||
return (
|
||||
<Modal visible={showServerSettings} transparent animationType="fade">
|
||||
<View style={{ flex: 1, backgroundColor: 'rgba(0,0,0,0.5)', justifyContent: 'center', alignItems: 'center' }}>
|
||||
@@ -668,12 +669,16 @@ export default class App extends Component<AppProps, WalletmanAppState> {
|
||||
/>
|
||||
<Text style={{ fontSize: 13, color: '#666', marginBottom: 4 }}>Port</Text>
|
||||
<TextInput
|
||||
style={{ borderWidth: 1, borderColor: '#ddd', borderRadius: 6, paddingHorizontal: 10, paddingVertical: 8, marginBottom: 20, fontSize: 14 }}
|
||||
style={{ borderWidth: 1, borderColor: '#ddd', borderRadius: 6, paddingHorizontal: 10, paddingVertical: 8, marginBottom: 12, fontSize: 14 }}
|
||||
value={settingsPort}
|
||||
onChangeText={t => this.setState({ settingsPort: t })}
|
||||
placeholder="16000"
|
||||
keyboardType="number-pad"
|
||||
/>
|
||||
<View style={{ flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', marginBottom: 20 }}>
|
||||
<Text style={{ fontSize: 13, color: '#666' }}>使用 HTTPS / WSS</Text>
|
||||
<Switch value={settingsHttps} onValueChange={v => this.setState({ settingsHttps: v })} />
|
||||
</View>
|
||||
<View style={{ flexDirection: 'row', justifyContent: 'flex-end' }}>
|
||||
<TouchableOpacity onPress={() => this.setState({ showServerSettings: false })} style={{ paddingHorizontal: 16, paddingVertical: 8, marginRight: 10 }}>
|
||||
<Text style={{ color: '#666' }}>取消</Text>
|
||||
|
||||
Reference in New Issue
Block a user