@kingdomchain/wallet-client 0.6.1 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -3352,14 +3352,33 @@ function citizenTxErrorMessage(code) {
3352
3352
  return "The transaction could not be completed. Please try again.";
3353
3353
  }
3354
3354
  }
3355
+ function withTimeout(promise, ms, label) {
3356
+ let timer;
3357
+ const timeout = new Promise((_, reject) => {
3358
+ timer = setTimeout(
3359
+ () => reject(new Error(`[citizenTx] ${label} did not respond within ${ms}ms`)),
3360
+ ms
3361
+ );
3362
+ });
3363
+ return Promise.race([promise, timeout]).finally(() => clearTimeout(timer));
3364
+ }
3355
3365
  async function broadcastAndConfirmTx(client, signerAddress, messages, fee, memo = "", options = {}) {
3356
3366
  const pollIntervalMs = options.pollIntervalMs ?? 1500;
3357
3367
  const timeoutMs = options.timeoutMs ?? 9e4;
3358
3368
  let deliverTx;
3359
3369
  try {
3360
- deliverTx = await client.signAndBroadcast(signerAddress, messages, fee, memo);
3370
+ console.log("[citizenTx] signAndBroadcast: starting", { signerAddress, messages });
3371
+ deliverTx = await withTimeout(
3372
+ client.signAndBroadcast(signerAddress, messages, fee, memo),
3373
+ 2e4,
3374
+ "signAndBroadcast"
3375
+ );
3376
+ console.log("[citizenTx] signAndBroadcast: settled", {
3377
+ code: deliverTx.code,
3378
+ hash: deliverTx.transactionHash
3379
+ });
3361
3380
  } catch (err) {
3362
- console.error("[citizenTx] broadcast threw before inclusion:", err);
3381
+ console.error("[citizenTx] broadcast threw or timed out before inclusion:", err);
3363
3382
  const message = err instanceof Error ? err.message : String(err);
3364
3383
  if (message.toLowerCase().includes("insufficient")) {
3365
3384
  throw new CitizenTxError(citizenTxErrorMessage("INSUFFICIENT_FEE"), "INSUFFICIENT_FEE", err);
@@ -3377,7 +3396,8 @@ async function broadcastAndConfirmTx(client, signerAddress, messages, fee, memo
3377
3396
  const hash = deliverTx.transactionHash;
3378
3397
  const deadline = Date.now() + timeoutMs;
3379
3398
  while (Date.now() < deadline) {
3380
- const indexed = await client.getTx(hash);
3399
+ console.log("[citizenTx] getTx poll: checking", { hash });
3400
+ const indexed = await withTimeout(client.getTx(hash), 15e3, `getTx(${hash})`);
3381
3401
  if (indexed) {
3382
3402
  if (indexed.code !== 0) {
3383
3403
  console.error("[citizenTx] indexed tx failed:", {