@swype-org/react-sdk 0.2.220 → 0.2.221

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
@@ -962,7 +962,8 @@ function sanitizeAdvertisedWallets(value) {
962
962
  }
963
963
  var STATIC_BRIDGE_DEDUPE_RDNS = /* @__PURE__ */ new Set([
964
964
  "com.coinbase.wallet",
965
- "io.metamask"
965
+ "io.metamask",
966
+ "app.phantom"
966
967
  ]);
967
968
  function buildBridgedConnector(wallet) {
968
969
  return injected({
@@ -3472,8 +3473,54 @@ function isUserRejection(msg) {
3472
3473
  const lower = msg.toLowerCase();
3473
3474
  return lower.includes("rejected") || lower.includes("denied");
3474
3475
  }
3475
- function isTrustWalletAccount(account) {
3476
- return connectorMatchesWallet(account?.connector, { providerName: "trust" });
3476
+ function requiresExplicitEvmNonce(account) {
3477
+ return connectorMatchesWallet(account?.connector, { providerName: "trust" }) || connectorMatchesWallet(account?.connector, { providerName: "phantom" });
3478
+ }
3479
+ function getEvmNonceTrackerKey(sender, chainId) {
3480
+ return `${chainId ?? "unknown"}:${sender.toLowerCase()}`;
3481
+ }
3482
+ async function snapshotExplicitEvmNonce(params) {
3483
+ const {
3484
+ walletClient,
3485
+ sender,
3486
+ chainId,
3487
+ nonceTracker,
3488
+ logContext,
3489
+ actionId,
3490
+ extraDebug
3491
+ } = params;
3492
+ const trackerKey = getEvmNonceTrackerKey(sender, chainId);
3493
+ const trackedNonce = nonceTracker?.get(trackerKey) ?? null;
3494
+ try {
3495
+ const providerPendingNonce = await fetchLatestNonce(walletClient, sender, "pending");
3496
+ const nonce = trackedNonce == null ? providerPendingNonce : Math.max(providerPendingNonce, trackedNonce);
3497
+ appendDebug("info", `${logContext}: explicit nonce snapshot`, {
3498
+ actionId,
3499
+ sender,
3500
+ chainId: chainId ?? null,
3501
+ providerPendingNonce,
3502
+ trackedNonce,
3503
+ selectedNonce: nonce,
3504
+ ...extraDebug ?? {}
3505
+ });
3506
+ return { nonce, trackerKey };
3507
+ } catch (err) {
3508
+ appendDebug(trackedNonce == null ? "warn" : "info", `${logContext}: pre-send nonce snapshot failed`, {
3509
+ actionId,
3510
+ sender,
3511
+ chainId: chainId ?? null,
3512
+ trackedNonce,
3513
+ selectedNonce: trackedNonce,
3514
+ error: err instanceof Error ? err.message : String(err),
3515
+ ...extraDebug ?? {}
3516
+ });
3517
+ return { nonce: trackedNonce, trackerKey: trackedNonce == null ? null : trackerKey };
3518
+ }
3519
+ }
3520
+ function advanceTrackedEvmNonce(nonceTracker, trackerKey, nextNonce) {
3521
+ if (!nonceTracker || !trackerKey) return;
3522
+ const current = nonceTracker.get(trackerKey);
3523
+ nonceTracker.set(trackerKey, current == null ? nextNonce : Math.max(current, nextNonce));
3477
3524
  }
3478
3525
  async function waitForWalletClient(wagmiConfig, params = {}) {
3479
3526
  for (let i = 0; i < WALLET_CLIENT_MAX_ATTEMPTS; i++) {
@@ -4225,10 +4272,11 @@ function failBothActions(approveAction, bridgeAction, message) {
4225
4272
  ]
4226
4273
  };
4227
4274
  }
4228
- async function executeApprovePermit2(action, wagmiConfig) {
4275
+ async function executeApprovePermit2(action, wagmiConfig, options = {}) {
4229
4276
  let walletClient = null;
4230
4277
  let sender = null;
4231
4278
  let preSendNonce = null;
4279
+ let nonceTrackerKey = null;
4232
4280
  try {
4233
4281
  walletClient = await waitForWalletClient(wagmiConfig);
4234
4282
  const account = getAccount(wagmiConfig);
@@ -4252,19 +4300,20 @@ async function executeApprovePermit2(action, wagmiConfig) {
4252
4300
  "APPROVE_PERMIT2 metadata is missing transaction parameters (to, data)."
4253
4301
  );
4254
4302
  }
4255
- const shouldSnapshotPreSendNonce = isTrustWalletAccount(account);
4256
- if (shouldSnapshotPreSendNonce) {
4257
- try {
4258
- preSendNonce = await fetchLatestNonce(walletClient, sender, "pending");
4259
- } catch (err) {
4260
- appendDebug("warn", "APPROVE_PERMIT2: pre-send nonce snapshot failed", {
4261
- actionId: action.id,
4262
- sender,
4263
- error: err instanceof Error ? err.message : String(err)
4264
- });
4265
- }
4303
+ const shouldUseExplicitNonce = requiresExplicitEvmNonce(account);
4304
+ if (shouldUseExplicitNonce) {
4305
+ const snapshot = await snapshotExplicitEvmNonce({
4306
+ walletClient,
4307
+ sender,
4308
+ chainId: account.chainId,
4309
+ nonceTracker: options.nonceTracker,
4310
+ logContext: "APPROVE_PERMIT2",
4311
+ actionId: action.id
4312
+ });
4313
+ preSendNonce = snapshot.nonce;
4314
+ nonceTrackerKey = snapshot.trackerKey;
4266
4315
  }
4267
- const useExplicitNonce = shouldSnapshotPreSendNonce && preSendNonce != null;
4316
+ const useExplicitNonce = shouldUseExplicitNonce && preSendNonce != null;
4268
4317
  const txParams = {
4269
4318
  from: sender,
4270
4319
  to,
@@ -4294,6 +4343,9 @@ async function executeApprovePermit2(action, wagmiConfig) {
4294
4343
  ),
4295
4344
  approveLabel
4296
4345
  );
4346
+ if (preSendNonce != null) {
4347
+ advanceTrackedEvmNonce(options.nonceTracker, nonceTrackerKey, preSendNonce + 1);
4348
+ }
4297
4349
  appendDebug("info", "APPROVE_PERMIT2: tx sent, awaiting settlement", {
4298
4350
  actionId: action.id,
4299
4351
  txHash,
@@ -4384,6 +4436,7 @@ async function executeApprovePermit2(action, wagmiConfig) {
4384
4436
  actionId: action.id
4385
4437
  });
4386
4438
  if (recovery) {
4439
+ advanceTrackedEvmNonce(options.nonceTracker, nonceTrackerKey, recovery.latestNonce);
4387
4440
  return actionRecovery(
4388
4441
  action,
4389
4442
  "Approval transaction was submitted but the wallet did not return a confirmation. Verifying on-chain\u2026",
@@ -4570,10 +4623,11 @@ async function executeSignPermit2(action, wagmiConfig, apiBaseUrl, sessionId) {
4570
4623
  );
4571
4624
  }
4572
4625
  }
4573
- async function executeExecuteBridge(action, wagmiConfig) {
4626
+ async function executeExecuteBridge(action, wagmiConfig, options = {}) {
4574
4627
  let walletClient = null;
4575
4628
  let sender = null;
4576
4629
  let lastPreSendNonce = null;
4630
+ let lastNonceTrackerKey = null;
4577
4631
  try {
4578
4632
  walletClient = await waitForWalletClient(wagmiConfig);
4579
4633
  const account = getAccount(wagmiConfig);
@@ -4594,22 +4648,25 @@ async function executeExecuteBridge(action, wagmiConfig) {
4594
4648
  for (let i = 0; i < calls.length; i++) {
4595
4649
  const call = calls[i];
4596
4650
  const isIntermediateCall = i < calls.length - 1;
4597
- const shouldSnapshotPreSendNonce = isTrustWalletAccount(account);
4651
+ const shouldUseExplicitNonce = requiresExplicitEvmNonce(account);
4598
4652
  let preSendNonce = null;
4599
- if (shouldSnapshotPreSendNonce) {
4600
- try {
4601
- preSendNonce = await fetchLatestNonce(walletClient, sender, "pending");
4602
- lastPreSendNonce = preSendNonce;
4603
- } catch (err) {
4604
- appendDebug("warn", "EXECUTE_BRIDGE: pre-send nonce snapshot failed", {
4605
- actionId: action.id,
4606
- callIndex: i,
4607
- sender,
4608
- error: err instanceof Error ? err.message : String(err)
4609
- });
4610
- }
4653
+ let nonceTrackerKey = null;
4654
+ if (shouldUseExplicitNonce) {
4655
+ const snapshot = await snapshotExplicitEvmNonce({
4656
+ walletClient,
4657
+ sender,
4658
+ chainId: account.chainId,
4659
+ nonceTracker: options.nonceTracker,
4660
+ logContext: "EXECUTE_BRIDGE",
4661
+ actionId: action.id,
4662
+ extraDebug: { callIndex: i }
4663
+ });
4664
+ preSendNonce = snapshot.nonce;
4665
+ nonceTrackerKey = snapshot.trackerKey;
4666
+ lastPreSendNonce = preSendNonce;
4667
+ lastNonceTrackerKey = nonceTrackerKey;
4611
4668
  }
4612
- const useExplicitNonce = shouldSnapshotPreSendNonce && preSendNonce != null;
4669
+ const useExplicitNonce = shouldUseExplicitNonce && preSendNonce != null;
4613
4670
  const txParams = {
4614
4671
  from: sender,
4615
4672
  to: call.to,
@@ -4638,6 +4695,9 @@ async function executeExecuteBridge(action, wagmiConfig) {
4638
4695
  ),
4639
4696
  watchdogLabel
4640
4697
  );
4698
+ if (preSendNonce != null) {
4699
+ advanceTrackedEvmNonce(options.nonceTracker, nonceTrackerKey, preSendNonce + 1);
4700
+ }
4641
4701
  appendDebug("info", "EXECUTE_BRIDGE: tx sent", {
4642
4702
  actionId: action.id,
4643
4703
  callIndex: i,
@@ -4723,6 +4783,7 @@ async function executeExecuteBridge(action, wagmiConfig) {
4723
4783
  actionId: action.id
4724
4784
  });
4725
4785
  if (recovery) {
4786
+ advanceTrackedEvmNonce(options.nonceTracker, lastNonceTrackerKey, recovery.latestNonce);
4726
4787
  return actionRecovery(
4727
4788
  action,
4728
4789
  "Bridge transaction was submitted but the wallet did not return a confirmation. Verifying on-chain\u2026",
@@ -5267,6 +5328,7 @@ function useAuthorizationExecutor(options) {
5267
5328
  const walletConnectRuntimeRef = useRef(/* @__PURE__ */ new Map());
5268
5329
  const activeWalletConnectRuntimeKeyRef = useRef(void 0);
5269
5330
  const activeEvmTransportRef = useRef("wagmi");
5331
+ const evmNonceTrackerRef = useRef(/* @__PURE__ */ new Map());
5270
5332
  const [batchTxHash, setBatchTxHash] = useState(null);
5271
5333
  const externalAuthorizationAvailableRef = useRef(false);
5272
5334
  const setExternalAuthorizationAvailable = useCallback((available) => {
@@ -5322,6 +5384,7 @@ function useAuthorizationExecutor(options) {
5322
5384
  setApproveSplConfirming(null);
5323
5385
  activeEvmTransportRef.current = "wagmi";
5324
5386
  activeWalletConnectRuntimeKeyRef.current = void 0;
5387
+ evmNonceTrackerRef.current.clear();
5325
5388
  setExecuting(false);
5326
5389
  executingRef.current = false;
5327
5390
  }, []);
@@ -5347,6 +5410,7 @@ function useAuthorizationExecutor(options) {
5347
5410
  if (result2.status === "success" && result2.data?.transport === "wagmi") {
5348
5411
  activeEvmTransportRef.current = "wagmi";
5349
5412
  activeWalletConnectRuntimeKeyRef.current = void 0;
5413
+ evmNonceTrackerRef.current.clear();
5350
5414
  if (action.metadata?.chainFamily !== "svm") {
5351
5415
  walletCapabilitiesRef.current = await refreshWalletCapabilities(
5352
5416
  wagmiConfig,
@@ -5359,6 +5423,7 @@ function useAuthorizationExecutor(options) {
5359
5423
  walletCapabilitiesRef.current = {};
5360
5424
  walletCapabilitiesRefreshedRef.current = true;
5361
5425
  batchCapabilityDecisionRef.current = null;
5426
+ evmNonceTrackerRef.current.clear();
5362
5427
  }
5363
5428
  return result2;
5364
5429
  }
@@ -5368,6 +5433,7 @@ function useAuthorizationExecutor(options) {
5368
5433
  externalAuthorizationAvailable: externalAuthorizationAvailableRef.current
5369
5434
  });
5370
5435
  if (result.status === "success" && action.metadata?.chainFamily !== "svm") {
5436
+ evmNonceTrackerRef.current.clear();
5371
5437
  walletCapabilitiesRef.current = await refreshWalletCapabilities(
5372
5438
  wagmiConfig,
5373
5439
  "open-provider"
@@ -5391,11 +5457,13 @@ function useAuthorizationExecutor(options) {
5391
5457
  walletCapabilitiesRef.current = {};
5392
5458
  walletCapabilitiesRefreshedRef.current = true;
5393
5459
  batchCapabilityDecisionRef.current = null;
5460
+ evmNonceTrackerRef.current.clear();
5394
5461
  }
5395
5462
  return result2;
5396
5463
  }
5397
5464
  const result = await executeSwitchChain(action, wagmiConfig, switchChainAsync);
5398
5465
  if (result.status === "success" && action.metadata?.chainFamily !== "svm") {
5466
+ evmNonceTrackerRef.current.clear();
5399
5467
  walletCapabilitiesRef.current = await refreshWalletCapabilities(
5400
5468
  wagmiConfig,
5401
5469
  "switch-chain"
@@ -5413,7 +5481,9 @@ function useAuthorizationExecutor(options) {
5413
5481
  dispatchOptions?.onWalletConnectDisplayUri
5414
5482
  );
5415
5483
  }
5416
- return executeApprovePermit2(action, wagmiConfig);
5484
+ return executeApprovePermit2(action, wagmiConfig, {
5485
+ nonceTracker: evmNonceTrackerRef.current
5486
+ });
5417
5487
  case "DEPLOY_SMART_ACCOUNT":
5418
5488
  return actionSuccess(action, "Smart account deployment acknowledged.");
5419
5489
  case "SIGN_PERMIT2": {
@@ -5472,7 +5542,9 @@ function useAuthorizationExecutor(options) {
5472
5542
  dispatchOptions?.onWalletConnectDisplayUri
5473
5543
  );
5474
5544
  }
5475
- return executeExecuteBridge(action, wagmiConfig);
5545
+ return executeExecuteBridge(action, wagmiConfig, {
5546
+ nonceTracker: evmNonceTrackerRef.current
5547
+ });
5476
5548
  default:
5477
5549
  return actionError(action, `Unsupported action type: ${action.type}`);
5478
5550
  }
@@ -5625,6 +5697,7 @@ function useAuthorizationExecutor(options) {
5625
5697
  setError(null);
5626
5698
  setBatchTxHash(null);
5627
5699
  setApproveSplConfirming(null);
5700
+ evmNonceTrackerRef.current.clear();
5628
5701
  return true;
5629
5702
  }, []);
5630
5703
  const endExecution = useCallback(() => {
@@ -5633,6 +5706,7 @@ function useAuthorizationExecutor(options) {
5633
5706
  setApproveSplConfirming(null);
5634
5707
  activeEvmTransportRef.current = "wagmi";
5635
5708
  activeWalletConnectRuntimeKeyRef.current = void 0;
5709
+ evmNonceTrackerRef.current.clear();
5636
5710
  setExecuting(false);
5637
5711
  executingRef.current = false;
5638
5712
  }, []);