Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/claude-code-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
id: claude-review
uses: anthropics/claude-code-action@v1
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
github_token: ${{ secrets.GITHUB_TOKEN }}
# Allow workflow to run for all users, including those without write access
# ⚠️ Security Note: This bypasses the write permission requirement check.
Expand Down
27 changes: 19 additions & 8 deletions api1.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,13 +375,22 @@ function registerTakerHandlers() {
);

if (fs.existsSync(offerbookPath)) {
console.log('🗑️ Deleting old offerbook.json...');
fs.unlinkSync(offerbookPath);
try {
const content = fs.readFileSync(offerbookPath, 'utf8');
JSON.parse(content); // Test if valid
console.log('✅ Existing offerbook is valid');
} catch (parseError) {
console.log('⚠️ Corrupted offerbook detected, recreating...');
fs.writeFileSync(
offerbookPath,
JSON.stringify({ makers: [] }),
'utf8'
);
}
} else {
console.log('📝 Creating initial offerbook.json...');
fs.writeFileSync(offerbookPath, JSON.stringify({ makers: [] }), 'utf8');
}

console.log('📝 Creating fresh empty offerbook.json...');
fs.writeFileSync(offerbookPath, '[]', 'utf8');

api1State.activeSyncs.set(syncId, {
status: 'syncing',
startedAt: Date.now(),
Expand Down Expand Up @@ -528,7 +537,7 @@ function registerTakerHandlers() {
}
}
},
5 * 60 * 1000 // 5 minutes
15 * 60 * 1000 // 15 minutes
);
}

Expand Down Expand Up @@ -831,7 +840,9 @@ function registerTakerHandlers() {
if (!api1State.coinswapNapi) {
await initNAPI();
if (!api1State.coinswapNapi) {
console.error('coinswap-napi not loaded for isWalletEncrypted check');
console.error(
'coinswap-napi not loaded for isWalletEncrypted check'
);
return false;
}
}
Expand Down
30 changes: 17 additions & 13 deletions src/components/market/Market.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,12 @@ export function Market(container) {
refreshBtn.disabled = true;
refreshBtn.innerHTML = '<span class="animate-pulse">Syncing...</span>';

// ✅ SHOW LOADER IMMEDIATELY
isLoading = true;
// ✅ Show sync progress bar ONLY
syncProgress = {
percent: 50,
status: 'syncing',
message: 'Syncing market data...',
};
updateUI();

try {
Expand All @@ -292,10 +296,10 @@ export function Market(container) {
console.log('📡 Sync started:', syncId);
localStorage.setItem('active_sync_id', syncId);

// ✅ SIMPLE: Just poll isOfferbookSyncing() until it's false
// Poll until sync completes
let isSyncing = true;
while (isSyncing) {
await new Promise((resolve) => setTimeout(resolve, 1000)); // Check every second
await new Promise((resolve) => setTimeout(resolve, 1000));

const statusResult = await window.api.taker.isOfferbookSyncing();
if (statusResult.success) {
Expand All @@ -306,22 +310,25 @@ export function Market(container) {
}
}

// Sync is done - wait 2 more seconds for file write
// Sync is done - wait for file write
console.log('✅ Offerbook synced - waiting for file write...');
await new Promise((resolve) => setTimeout(resolve, 2000));

// ✅ NOW fetch makers
console.log('✅ Now fetching makers...');
// Clear sync progress
syncProgress = null;

// NOW fetch fresh makers
console.log('✅ Now fetching fresh makers...');
localStorage.removeItem('active_sync_id');
await fetchMakers(); // This sets isLoading = false
await fetchMakers(); // This sets isLoading = false and updates UI

refreshBtn.innerHTML = '✅ Synced!';
setTimeout(() => {
refreshBtn.disabled = false;
refreshBtn.innerHTML = originalText;
}, 2000);
} catch (error) {
isLoading = false;
syncProgress = null;
updateUI();
refreshBtn.innerHTML = '❌ Failed';
showError(error.message);
Expand All @@ -331,6 +338,7 @@ export function Market(container) {
}, 3000);
}
}

async function initialize() {
// Get protocol version
const protocolResult = await window.api.taker.getProtocol();
Expand Down Expand Up @@ -609,7 +617,6 @@ export function Market(container) {
document.body.appendChild(modal);
};


function updateUI() {
const stats = calculateStats();
const tableBody = content.querySelector('#maker-table-body');
Expand Down Expand Up @@ -790,8 +797,6 @@ export function Market(container) {
`
)
.join('');


}
}
}
Expand All @@ -809,7 +814,6 @@ export function Market(container) {
).length;
footer.innerHTML = `Showing ${displayedCount} ${currentMakerStatus} offers • ${timeStr}`;
}

}

content.innerHTML = `
Expand Down
4 changes: 2 additions & 2 deletions src/components/swap/Swap.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { SwapStateManager, formatRelativeTime } from './SwapStateManager.js';

// ✅ ADD CACHE CONSTANTS
const SWAP_DATA_CACHE_KEY = 'swap_data_cache';
const CACHE_DURATION = 300 * 1000; // 5 mins
const CACHE_DURATION = 15 * 60 * 1000; // 15 minutes

// ✅ ADD CACHE FUNCTIONS
function loadSwapDataFromCache() {
Expand Down Expand Up @@ -67,7 +67,7 @@ export async function SwapComponent(container) {
// If there's an active swap in progress, redirect to coinswap progress
if (activeSwap && activeSwap.status === 'configured') {
const age = Date.now() - activeSwap.createdAt;
if (age > 5 * 60 * 1000) {
if (age > 15 * 60 * 1000) {
console.log('🧹 Clearing stale configured swap');
await SwapStateManager.clearSwapData();
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/components/swap/SwapStateManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const SwapStateManager = {
// Check if configured swap is stale (older than 5 minutes)
if (activeSwap.status === 'configured') {
const age = Date.now() - activeSwap.createdAt;
if (age > 5 * 60 * 1000) {
if (age > 15 * 60 * 1000) {
console.log(
'🧹 Clearing stale configured swap from hasActiveSwap check'
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/wallet/Wallet.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const WALLET_CACHE_KEY = 'wallet_data_cache';
const CACHE_DURATION = 90 * 1000; // 90 seconds
const CACHE_DURATION = 15 * 60 * 1000; // 15 minutes

function loadWalletFromCache() {
try {
Expand Down
Loading