Fix: Ubercoin balance display and refresh issues

- Profile page: Add cache: 'no-store' to always fetch fresh balance data
- Profile page: Update balance immediately after tip using transaction result
  to avoid race conditions where DB hasn't committed yet
- Profile page: Reload profile after 500ms delay for data consistency
- UbercoinTipModal: Clarify "Your balance" to avoid confusion with recipient's

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
doomtube 2026-01-06 04:52:41 -05:00
parent 0fc49d0032
commit 01bd631af8
2 changed files with 18 additions and 6 deletions

View file

@ -407,7 +407,7 @@
<div class="balance-row">
<span class="coin-icon">Ü</span>
<span>Balance: <strong>{formatUbercoin($ubercoinBalance)}</strong></span>
<span>Your balance: <strong>{formatUbercoin($ubercoinBalance)}</strong></span>
</div>
<div class="input-group">

View file

@ -32,8 +32,11 @@
async function loadProfile(username) {
try {
// Public endpoint - no auth header needed
const response = await fetch(`/api/users/${username}`);
// Add cache: 'no-store' to always get fresh data
const response = await fetch(`/api/users/${username}`, {
cache: 'no-store'
});
if (response.ok) {
const data = await response.json();
profile = data.profile;
@ -114,11 +117,20 @@
showTipModal = false;
}
function handleTipSent(event) {
async function handleTipSent(event) {
showTipModal = false;
// Optionally refresh profile to show updated balance
const result = event.detail;
// Update profile balance immediately based on the transaction result
// This avoids race conditions where the DB hasn't committed yet
if (profile && result && result.received !== undefined) {
profile.ubercoinBalance = (profile.ubercoinBalance || 0) + result.received;
profile = profile; // Trigger reactivity
}
// Also reload from server after a short delay to ensure data consistency
if (profile) {
loadProfile(profile.username);
setTimeout(() => loadProfile(profile.username), 500);
}
}