diff --git a/crates/webzjs-wallet/src/bindgen/wallet.rs b/crates/webzjs-wallet/src/bindgen/wallet.rs index 2d9f6b83..7b29651b 100644 --- a/crates/webzjs-wallet/src/bindgen/wallet.rs +++ b/crates/webzjs-wallet/src/bindgen/wallet.rs @@ -297,7 +297,7 @@ impl WebWallet { match sync_handler.await { Ok(Ok(())) => Ok(()), Ok(Err(err_string)) => { - tracing::error!("Sync error: {}", err_string); + tracing::warn!("Sync error (will be retried by caller): {}", err_string); Err(Error::Sync(err_string)) } Err(panic_error) => { @@ -396,7 +396,9 @@ impl WebWallet { }) .unwrap_throw() .join_async(); - let txids = sync_handler.await.unwrap(); + let txids = sync_handler.await.map_err(|e| { + Error::Generic(format!("Transaction creation thread panicked: {:?}", e)) + })?; let flattened_txid_bytes = txids.iter().flat_map(|&x| x.as_ref().clone()).collect(); Ok(flattened_txid_bytes) diff --git a/packages/web-wallet/src/hooks/useWebzjsActions.ts b/packages/web-wallet/src/hooks/useWebzjsActions.ts index c155b4f9..2217bdf7 100644 --- a/packages/web-wallet/src/hooks/useWebzjsActions.ts +++ b/packages/web-wallet/src/hooks/useWebzjsActions.ts @@ -488,7 +488,7 @@ export function useWebZjsActions(): WebzjsActions { } } catch (syncErr) { consecutiveFailures++; - console.warn(`Full resync: sync round ${round} failed (${consecutiveFailures}/${MAX_CONSECUTIVE_FAILURES}):`, syncErr); + console.debug(`Full resync: sync round ${round} failed (${consecutiveFailures}/${MAX_CONSECUTIVE_FAILURES}):`, syncErr); if (consecutiveFailures >= MAX_CONSECUTIVE_FAILURES) { throw syncErr; // give up after too many consecutive failures @@ -496,7 +496,7 @@ export function useWebZjsActions(): WebzjsActions { // Back off longer after failures const backoff = SYNC_ROUND_DELAY * Math.pow(2, consecutiveFailures - 1); - console.info(`Full resync: backing off ${backoff}ms before retry`); + console.debug(`Full resync: backing off ${backoff}ms before retry`); await new Promise(r => setTimeout(r, backoff)); } } diff --git a/packages/web-wallet/src/utils/balance.ts b/packages/web-wallet/src/utils/balance.ts index 4dafbc32..d850652e 100644 --- a/packages/web-wallet/src/utils/balance.ts +++ b/packages/web-wallet/src/utils/balance.ts @@ -7,12 +7,17 @@ function zatsToZec(zats: number): number { } function zecToZats(zecAmount: string): bigint { + const trimmed = zecAmount.trim(); - if (!/^\d+(\.\d+)?$/.test(zecAmount)) { + if (!/^(\d+\.?\d*|\.\d+)$/.test(trimmed)) { throw new Error('Invalid ZEC format: must be positive number'); } - const amount = new Decimal(zecAmount); + const amount = new Decimal(trimmed); + + if (!amount.isPositive() || amount.isZero()) { + throw new Error('Invalid ZEC format: must be positive number'); + } if (amount.decimalPlaces() > 8) { throw new Error('Maximum 8 decimal places allowed');