diff --git a/src/services/service.ts b/src/services/service.ts index 4692099..55fad2c 100755 --- a/src/services/service.ts +++ b/src/services/service.ts @@ -1187,7 +1187,7 @@ export default class Services { // Notify user that a transaction was received this.updateUserStatus('📨 New transaction received from blockchain...'); - + // Mark that we've received a transaction for waitForAmount this.hasReceivedTransaction = true; @@ -1880,9 +1880,20 @@ export default class Services { throw new Error('WebAssembly SDK not initialized - cannot create device'); } // We set birthday later when we have the chain tip from relay + console.log('🔧 Creating new device with birthday 0...'); spAddress = await this.sdkClient.create_new_device(0, 'signet'); + console.log('✅ Device created with address:', spAddress); + const device = this.dumpDeviceFromMemory(); + console.log('🔍 Device details after creation:', { + has_spend_key: !!device.sp_wallet?.spend_key, + has_scan_key: !!device.sp_wallet?.scan_key, + birthday: device.sp_wallet?.birthday, + sp_address: device.sp_address + }); + await this.saveDeviceInDatabase(device); + console.log('✅ Device saved to database'); } catch (e) { console.error('Services ~ Error:', e); } @@ -1924,7 +1935,7 @@ export default class Services { */ public async ensureCompleteInitialScan(): Promise { console.log('🔄 Ensuring complete initial scan...'); - + try { const device = await this.getDeviceFromDatabase(); if (!device || !device.sp_wallet) { @@ -1934,15 +1945,15 @@ export default class Services { // Force a complete scan from birthday to current block height const scanFromHeight = Math.max(0, this.currentBlockHeight - 100); console.log(`🔄 Performing complete scan from block ${scanFromHeight} to ${this.currentBlockHeight}...`); - + await this.sdkClient.scan_blocks(this.currentBlockHeight, BLINDBITURL); console.log('✅ Complete initial scan completed'); - + // Update last_scan to current block height device.sp_wallet.last_scan = this.currentBlockHeight; await this.saveDeviceInDatabase(device); console.log('✅ Wallet scan state updated'); - + } catch (error) { console.error('❌ Error during complete initial scan:', error); throw error; @@ -1976,14 +1987,23 @@ export default class Services { if (birthday === 0) { // This is a new device, set birthday to scan from much earlier to catch faucet transactions // Scan from 100 blocks earlier to ensure we catch all faucet transactions + console.log('🔧 Updating birthday for new device:', { + old_birthday: device.sp_wallet.birthday, + new_birthday: Math.max(0, this.currentBlockHeight - 100), + current_block: this.currentBlockHeight + }); + device.sp_wallet.birthday = Math.max(0, this.currentBlockHeight - 100); // We also set last_scan to the same value initially device.sp_wallet.last_scan = device.sp_wallet.birthday; try { // First set the updated device in memory this.sdkClient.restore_device(device); + console.log('✅ Device restored in memory with updated birthday'); + // Then save it to database await this.saveDeviceInDatabase(device); + console.log('✅ Device saved to database with updated birthday'); // For new wallets, perform initial scan to catch any existing transactions console.log(`🔄 Performing initial scan for new wallet from block ${device.sp_wallet.birthday} to ${this.currentBlockHeight}...`);