test 优化

This commit is contained in:
2026-03-24 16:47:37 +08:00
parent f0e21a2715
commit 9c220f1322
16 changed files with 669 additions and 603 deletions

View File

@@ -1,6 +1,14 @@
import { WalletType } from 'rnwalletman';
import AsyncStorage from '@react-native-async-storage/async-storage';
export interface WalletItem {
id: string;
walletType: string;
upi?: string;
phone?: string;
status?: string;
}
const DEFAULT_DOMAIN = 'aa.pfgame.org';
const STORAGE_KEY = 'server_domain';
const HTTPS_KEY = 'server_https';
@@ -117,6 +125,44 @@ class Api {
if (!data.success) throw new Error(data.message);
return data;
}
public async listWallets(): Promise<WalletItem[]> {
const res = await fetch(`${Api.BASE_URL}/wallets`, { headers: this.headers() });
const data = await res.json();
if (!data.success) throw new Error(data.message);
return data.data?.wallets ?? [];
}
public async getWalletVpas(walletId: string): Promise<string[]> {
const res = await fetch(`${Api.BASE_URL}/wallet/vpas?walletId=${encodeURIComponent(walletId)}`, {
headers: this.headers(),
});
const data = await res.json();
if (!data.success) throw new Error(data.message);
return data.data?.vpas ?? [];
}
public async setCurrentVpa(walletId: string, vpaIndex: number): Promise<string> {
const res = await fetch(`${Api.BASE_URL}/wallet/set-vpa`, {
method: 'POST',
headers: this.headers(),
body: JSON.stringify({ walletId, vpaIndex }),
});
const data = await res.json();
if (!data.success) throw new Error(data.message);
return data.data?.vpa ?? '';
}
public async generateLink(walletId: string, amount: string): Promise<{ link: string; orderId: string }> {
const res = await fetch(`${Api.BASE_URL}/generate-link`, {
method: 'POST',
headers: this.headers(),
body: JSON.stringify({ walletId, amount }),
});
const data = await res.json();
if (!data.success) throw new Error(data.message);
return { link: data.data?.link, orderId: data.data?.orderId };
}
}
export default Api;