diff --git a/components/WalletBindComponents.tsx b/components/WalletBindComponents.tsx index 3b6a9f3..a1ef936 100644 --- a/components/WalletBindComponents.tsx +++ b/components/WalletBindComponents.tsx @@ -61,7 +61,7 @@ export class MobikwikPersonalTokenBind extends Component<{ } } -/** Mobikwik App OTP bind */ +/** Mobikwik Web OTP bind */ export class MobikwikPersonalOTPBind extends Component<{ onRequestOTP: (walletType: WalletType, params: any) => Promise; onVerifyOTP: (walletType: WalletType, params: any) => Promise; @@ -75,7 +75,7 @@ export class MobikwikPersonalOTPBind extends Component<{ { this.setState({ loadingWallets: true }); try { const wallets = await Api.instance.listWallets(); - this.setState({ wallets }); + const enriched = await Promise.all(wallets.map(async (w) => { + try { + const account = await Api.instance.getAccountInfo(w.id); + return { + ...w, + upi: account.vpa ?? w.upi, + phone: account.phone ?? w.phone, + }; + } catch { + return w; + } + })); + this.setState({ wallets: enriched }); } catch (e) { console.log('[fetchWallets]', e); } finally { @@ -385,10 +397,14 @@ export default class HomeScreen extends Component { }; openVpaModal = async (item: WalletItem) => { - this.setState({ vpaModalWallet: item, vpaModalVpas: [], vpaModalLoading: true, vpaModalSelected: item.upi ?? '' }); + this.setState({ vpaModalWallet: item, vpaModalVpas: [], vpaModalLoading: true, vpaModalSelected: '' }); try { - const vpas = await Api.instance.getWalletVpas(item.id); - this.setState({ vpaModalVpas: vpas, vpaModalLoading: false }); + const account = await Api.instance.getAccountInfo(item.id); + this.setState({ + vpaModalVpas: account.vpas ?? [], + vpaModalSelected: account.vpa ?? '', + vpaModalLoading: false, + }); } catch { this.setState({ vpaModalLoading: false }); } @@ -403,12 +419,8 @@ export default class HomeScreen extends Component { if (idx < 0) return; try { await Api.instance.setCurrentVpa(vpaModalWallet.id, idx); - const walletId = vpaModalWallet.id; - const vpa = vpaModalSelected; - this.setState((s) => ({ - vpaModalWallet: null, - wallets: s.wallets.map((w) => (w.id === walletId ? { ...w, upi: vpa } : w)), - })); + this.setState({ vpaModalWallet: null }); + this.fetchWallets(); } catch (e) { Alert.alert('Set Failed', (e as Error).message); } diff --git a/servers/walletman b/servers/walletman index 7d4506f..4ec9fb0 160000 --- a/servers/walletman +++ b/servers/walletman @@ -1 +1 @@ -Subproject commit 7d4506f993eca39c9d2ef534275e00b4a3a440d0 +Subproject commit 4ec9fb0f54bf4dac5868b0cbd93f879f17482e64 diff --git a/services/api.ts b/services/api.ts index 9d3e0bb..6884f65 100644 --- a/services/api.ts +++ b/services/api.ts @@ -152,13 +152,18 @@ class Api { return data.data?.wallets ?? []; } - public async getWalletVpas(walletId: string): Promise { - const res = await fetch(`${Api.BASE_URL}/wallet/vpas?walletId=${encodeURIComponent(walletId)}`, { + public async getAccountInfo(walletId: string): Promise<{ vpa?: string; vpas?: string[]; phone?: string }> { + const res = await fetch(`${Api.BASE_URL}/account-info?walletId=${encodeURIComponent(walletId)}`, { headers: this.headers(), }); const data = await res.json(); if (!data.success) throw new Error(data.message); - return data.data?.vpas ?? []; + return data.data?.account ?? {}; + } + + public async getWalletVpas(walletId: string): Promise { + const account = await this.getAccountInfo(walletId); + return account.vpas ?? []; } public async setCurrentVpa(walletId: string, vpaIndex: number): Promise {