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>
|
||||
|
||||
1
android/.idea/gradle.xml
generated
1
android/.idea/gradle.xml
generated
@@ -22,6 +22,7 @@
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/app" />
|
||||
<option value="$PROJECT_DIR$/../node_modules/@react-native-async-storage/async-storage/android" />
|
||||
<option value="$PROJECT_DIR$/../node_modules/@react-native-cookies/cookies/android" />
|
||||
<option value="$PROJECT_DIR$/../node_modules/@react-native-ml-kit/barcode-scanning/android" />
|
||||
<option value="$PROJECT_DIR$/../node_modules/@react-native/gradle-plugin" />
|
||||
|
||||
Submodule servers/walletman updated: 1f15329fc2...457e14503f
@@ -1,29 +1,48 @@
|
||||
import { WalletType } from 'rnwalletman';
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
|
||||
const DEFAULT_DOMAIN = '192.168.1.198:16000';
|
||||
const DEFAULT_DOMAIN = 'aa.pfgame.org';
|
||||
const STORAGE_KEY = 'server_domain';
|
||||
const HTTPS_KEY = 'server_https';
|
||||
|
||||
let _domain = DEFAULT_DOMAIN;
|
||||
let _useHttps = true;
|
||||
|
||||
export async function loadServerDomain(): Promise<string> {
|
||||
const saved = await AsyncStorage.getItem(STORAGE_KEY);
|
||||
if (saved) _domain = saved;
|
||||
const https = await AsyncStorage.getItem(HTTPS_KEY);
|
||||
if (https !== null) _useHttps = https === 'true';
|
||||
console.log('loadServerDomain', _domain, 'https:', _useHttps);
|
||||
return _domain;
|
||||
}
|
||||
|
||||
export async function saveServerDomain(domain: string): Promise<void> {
|
||||
export async function saveServerDomain(domain: string, useHttps: boolean): Promise<void> {
|
||||
_domain = domain;
|
||||
_useHttps = useHttps;
|
||||
await AsyncStorage.setItem(STORAGE_KEY, domain);
|
||||
await AsyncStorage.setItem(HTTPS_KEY, String(useHttps));
|
||||
}
|
||||
|
||||
export function getServerDomain(): string {
|
||||
return _domain;
|
||||
}
|
||||
|
||||
export function getUseHttps(): boolean {
|
||||
return _useHttps;
|
||||
}
|
||||
|
||||
class Api {
|
||||
public static get BASE_URL() { return `http://${_domain}`; }
|
||||
public static get WS_URL() { return `ws://${_domain}/ws`; }
|
||||
public static get BASE_URL() {
|
||||
const domain = getServerDomain();
|
||||
const scheme = getUseHttps() ? 'https' : 'http';
|
||||
return `${scheme}://${domain}`;
|
||||
}
|
||||
public static get WS_URL() {
|
||||
const domain = getServerDomain();
|
||||
const scheme = getUseHttps() ? 'wss' : 'ws';
|
||||
return `${scheme}://${domain}/ws`;
|
||||
}
|
||||
|
||||
private static _instance: Api | null = null;
|
||||
private userId: number = 0;
|
||||
@@ -54,6 +73,7 @@ class Api {
|
||||
}
|
||||
|
||||
public async login(username: string, password: string): Promise<number> {
|
||||
console.log('login', Api.BASE_URL);
|
||||
const res = await fetch(`${Api.BASE_URL}/login`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
|
||||
Reference in New Issue
Block a user