diff --git a/src/services/service.ts b/src/services/service.ts index 5737827..ea1d907 100755 --- a/src/services/service.ts +++ b/src/services/service.ts @@ -832,13 +832,13 @@ export default class Services { current_block: this.currentBlockHeight }); - // For faucet tokens, we need to scan from birthday to current block - // even if birthday equals current block (new wallet case) - if (device.sp_wallet.birthday <= this.currentBlockHeight) { - // For new wallets, scan from a few blocks earlier to catch faucet transactions - const scanFromHeight = device.sp_wallet.birthday === this.currentBlockHeight - ? Math.max(0, this.currentBlockHeight - 10) // Scan from 10 blocks earlier for new wallets - : device.sp_wallet.birthday; + // For faucet tokens, we need to scan from birthday to current block + // even if birthday equals current block (new wallet case) + if (device.sp_wallet.birthday <= this.currentBlockHeight) { + // For new wallets, scan from much earlier to catch faucet transactions + const scanFromHeight = device.sp_wallet.birthday === this.currentBlockHeight + ? Math.max(0, this.currentBlockHeight - 100) // Scan from 100 blocks earlier for new wallets + : device.sp_wallet.birthday; console.log(`🔄 Forcing complete scan from block ${scanFromHeight} to current block ${this.currentBlockHeight}...`); await this.sdkClient.scan_blocks(this.currentBlockHeight, BLINDBITURL); @@ -1258,12 +1258,12 @@ export default class Services { }); // Force scan from birthday to current block height - // For faucet tokens, we need to scan even if birthday equals current block - if (device.sp_wallet.birthday <= this.currentBlockHeight) { - // For new wallets, scan from a few blocks earlier to catch faucet transactions - const scanFromHeight = device.sp_wallet.birthday === this.currentBlockHeight - ? Math.max(0, this.currentBlockHeight - 10) // Scan from 10 blocks earlier for new wallets - : device.sp_wallet.birthday; + // For faucet tokens, we need to scan even if birthday equals current block + if (device.sp_wallet.birthday <= this.currentBlockHeight) { + // For new wallets, scan from much earlier to catch faucet transactions + const scanFromHeight = device.sp_wallet.birthday === this.currentBlockHeight + ? Math.max(0, this.currentBlockHeight - 100) // Scan from 100 blocks earlier for new wallets + : device.sp_wallet.birthday; console.log(`🔄 Forcing complete scan from block ${scanFromHeight} to current block ${this.currentBlockHeight}...`); await this.sdkClient.scan_blocks(this.currentBlockHeight, BLINDBITURL); @@ -1699,6 +1699,23 @@ export default class Services { try { const amount = this.sdkClient.get_available_amount(); console.log(`💰 SDK get_available_amount() returned: ${amount}`); + + // Additional debugging: check wallet state + try { + const device = this.dumpDeviceFromMemory(); + if (device && device.sp_wallet) { + console.log(`🔍 Wallet debugging info:`, { + birthday: device.sp_wallet.birthday, + last_scan: device.sp_wallet.last_scan, + current_block: this.currentBlockHeight, + has_spend_key: !!device.sp_wallet.spend_key, + has_scan_key: !!device.sp_wallet.scan_key + }); + } + } catch (error) { + console.warn('⚠️ Error getting wallet debugging info:', error); + } + return amount; } catch (error) { console.error('❌ Error calling get_available_amount():', error); @@ -1940,11 +1957,12 @@ export default class Services { throw new Error('Birthday not found'); } - if (birthday === 0) { - // This is a new device, set birthday to a few blocks earlier to allow scanning for faucet transactions - device.sp_wallet.birthday = Math.max(0, this.currentBlockHeight - 10); - // We also set last_scan to the same value initially - device.sp_wallet.last_scan = device.sp_wallet.birthday; + 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 + 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);