加入服务器的配置设置,可以设置服务器的url+port

This commit is contained in:
2026-03-14 14:10:29 +08:00
parent 0709c07bec
commit 83ce361404
5 changed files with 94 additions and 8 deletions

View File

@@ -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<string> {
const saved = await AsyncStorage.getItem(STORAGE_KEY);
if (saved) _domain = saved;
return _domain;
}
export async function saveServerDomain(domain: string): Promise<void> {
_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;