test 优化
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user