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
6 changes: 4 additions & 2 deletions crates/webzjs-wallet/src/bindgen/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions packages/web-wallet/src/hooks/useWebzjsActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,15 +488,15 @@ 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
}

// 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));
}
}
Expand Down
9 changes: 7 additions & 2 deletions packages/web-wallet/src/utils/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Loading