Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 33 additions & 44 deletions src/components/wallet/Wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,18 @@ export async function WalletComponent(container) {
async function updateBalance(useCache = false) {
try {
// Use cached data if requested
if (useCache && cached && cached.balance) {
content.querySelector('#regular-balance').textContent =
satsToBtc(cached.balance.regular) + ' BTC';
content.querySelector('#swap-balance').textContent =
satsToBtc(cached.balance.swap) + ' BTC';
content.querySelector('#contract-balance').textContent =
satsToBtc(cached.balance.contract) + ' BTC';
content.querySelector('#spendable-balance').textContent =
satsToBtc(cached.balance.spendable) + ' BTC';
console.log('✅ Balance loaded from cache');
if (useCache) {
if (cached && cached.balance) {
content.querySelector('#regular-balance').textContent =
satsToBtc(cached.balance.regular) + ' BTC';
content.querySelector('#swap-balance').textContent =
satsToBtc(cached.balance.swap) + ' BTC';
content.querySelector('#contract-balance').textContent =
satsToBtc(cached.balance.contract) + ' BTC';
content.querySelector('#spendable-balance').textContent =
satsToBtc(cached.balance.spendable) + ' BTC';
console.log('✅ Balance loaded from cache');
}
return;
}

Expand Down Expand Up @@ -255,11 +257,13 @@ export async function WalletComponent(container) {

try {
// Use cached data if requested
if (useCache && cached && cached.transactions) {
transactionsContainer.innerHTML = renderTransactions(
cached.transactions
);
console.log('✅ Transactions loaded from cache');
if (useCache) {
if (cached && cached.transactions) {
transactionsContainer.innerHTML = renderTransactions(
cached.transactions
);
console.log('✅ Transactions loaded from cache');
}
return;
}

Expand Down Expand Up @@ -310,9 +314,11 @@ export async function WalletComponent(container) {

try {
// Use cached data if requested
if (useCache && cached && cached.utxos) {
utxoTableBody.innerHTML = renderUtxos(cached.utxos);
console.log('✅ UTXOs loaded from cache');
if (useCache) {
if (cached && cached.utxos) {
utxoTableBody.innerHTML = renderUtxos(cached.utxos);
console.log('✅ UTXOs loaded from cache');
}
return;
}

Expand Down Expand Up @@ -507,32 +513,15 @@ export async function WalletComponent(container) {
});
}

// Initialize data
updateBalance();
updateTransactions();
updateUtxos();

// ✅ SMART INITIALIZATION
if (shouldFetchFresh) {
console.log('🔄 Fetching fresh data...');
// Fetch fresh data
const [balance, transactions, utxos] = await Promise.all([
updateBalance(false),
updateTransactions(false),
updateUtxos(false),
]);

// Save to cache
if (balance && transactions && utxos) {
saveWalletToCache(balance, transactions, utxos);
}
// ✅ LOAD CACHED DATA ONLY (No Auto-Fetch)
if (cached) {
console.log('⚡ Loading cached data');
updateBalance(true);
updateTransactions(true);
updateUtxos(true);
} else {
console.log('⚡ Using cached data (still fresh)');
// Just use cache
await Promise.all([
updateBalance(true),
updateTransactions(true),
updateUtxos(true),
]);
// If no cache, we show empty state (already default in HTML or could be set here)
// User must click "Refresh" to get data.
console.log('Waiting for user to refresh...');
}
}