diff --git a/src/routes/admin/search/+page.svelte b/src/routes/admin/search/+page.svelte index 23863c94..3169136f 100644 --- a/src/routes/admin/search/+page.svelte +++ b/src/routes/admin/search/+page.svelte @@ -194,6 +194,11 @@ async function updateWallet(field: string, value: any) { if (!wallet) return; + // Preserve current wallet data before update + const currentTransactions = wallet.transactions || []; + const currentCut = wallet.cut; + const currentBalance = wallet.balance; + try { await patchIdByWalletsByAdmin({ path: { id: wallet._id }, @@ -207,7 +212,23 @@ headers: getAuthHeaders(), }); if (response.data) { - wallet = response.data as AdminWallet; + const updatedWallet = response.data as AdminWallet; + + // Preserve critical fields if the response doesn't include them + // This prevents frontend data loss even if backend response is incomplete + if (!updatedWallet.transactions || updatedWallet.transactions.length === 0) { + updatedWallet.transactions = currentTransactions; + } + + if (updatedWallet.cut === undefined || updatedWallet.cut === null) { + updatedWallet.cut = currentCut; + } + + if (!updatedWallet.balance) { + updatedWallet.balance = currentBalance; + } + + wallet = updatedWallet; } } catch { toast.show('Failed to update wallet', 'error');