@swype-org/react-sdk 0.2.220 → 0.2.222
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.cjs +108 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +108 -34
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -986,7 +986,8 @@ function sanitizeAdvertisedWallets(value) {
|
|
|
986
986
|
}
|
|
987
987
|
var STATIC_BRIDGE_DEDUPE_RDNS = /* @__PURE__ */ new Set([
|
|
988
988
|
"com.coinbase.wallet",
|
|
989
|
-
"io.metamask"
|
|
989
|
+
"io.metamask",
|
|
990
|
+
"app.phantom"
|
|
990
991
|
]);
|
|
991
992
|
function buildBridgedConnector(wallet) {
|
|
992
993
|
return connectors.injected({
|
|
@@ -3496,8 +3497,54 @@ function isUserRejection(msg) {
|
|
|
3496
3497
|
const lower = msg.toLowerCase();
|
|
3497
3498
|
return lower.includes("rejected") || lower.includes("denied");
|
|
3498
3499
|
}
|
|
3499
|
-
function
|
|
3500
|
-
return connectorMatchesWallet(account?.connector, { providerName: "trust" });
|
|
3500
|
+
function requiresExplicitEvmNonce(account) {
|
|
3501
|
+
return connectorMatchesWallet(account?.connector, { providerName: "trust" }) || connectorMatchesWallet(account?.connector, { providerName: "phantom" });
|
|
3502
|
+
}
|
|
3503
|
+
function getEvmNonceTrackerKey(sender, chainId) {
|
|
3504
|
+
return `${chainId ?? "unknown"}:${sender.toLowerCase()}`;
|
|
3505
|
+
}
|
|
3506
|
+
async function snapshotExplicitEvmNonce(params) {
|
|
3507
|
+
const {
|
|
3508
|
+
walletClient,
|
|
3509
|
+
sender,
|
|
3510
|
+
chainId,
|
|
3511
|
+
nonceTracker,
|
|
3512
|
+
logContext,
|
|
3513
|
+
actionId,
|
|
3514
|
+
extraDebug
|
|
3515
|
+
} = params;
|
|
3516
|
+
const trackerKey = getEvmNonceTrackerKey(sender, chainId);
|
|
3517
|
+
const trackedNonce = nonceTracker?.get(trackerKey) ?? null;
|
|
3518
|
+
try {
|
|
3519
|
+
const providerPendingNonce = await fetchLatestNonce(walletClient, sender, "pending");
|
|
3520
|
+
const nonce = trackedNonce == null ? providerPendingNonce : Math.max(providerPendingNonce, trackedNonce);
|
|
3521
|
+
appendDebug("info", `${logContext}: explicit nonce snapshot`, {
|
|
3522
|
+
actionId,
|
|
3523
|
+
sender,
|
|
3524
|
+
chainId: chainId ?? null,
|
|
3525
|
+
providerPendingNonce,
|
|
3526
|
+
trackedNonce,
|
|
3527
|
+
selectedNonce: nonce,
|
|
3528
|
+
...extraDebug ?? {}
|
|
3529
|
+
});
|
|
3530
|
+
return { nonce, trackerKey };
|
|
3531
|
+
} catch (err) {
|
|
3532
|
+
appendDebug(trackedNonce == null ? "warn" : "info", `${logContext}: pre-send nonce snapshot failed`, {
|
|
3533
|
+
actionId,
|
|
3534
|
+
sender,
|
|
3535
|
+
chainId: chainId ?? null,
|
|
3536
|
+
trackedNonce,
|
|
3537
|
+
selectedNonce: trackedNonce,
|
|
3538
|
+
error: err instanceof Error ? err.message : String(err),
|
|
3539
|
+
...extraDebug ?? {}
|
|
3540
|
+
});
|
|
3541
|
+
return { nonce: trackedNonce, trackerKey: trackedNonce == null ? null : trackerKey };
|
|
3542
|
+
}
|
|
3543
|
+
}
|
|
3544
|
+
function advanceTrackedEvmNonce(nonceTracker, trackerKey, nextNonce) {
|
|
3545
|
+
if (!nonceTracker || !trackerKey) return;
|
|
3546
|
+
const current = nonceTracker.get(trackerKey);
|
|
3547
|
+
nonceTracker.set(trackerKey, current == null ? nextNonce : Math.max(current, nextNonce));
|
|
3501
3548
|
}
|
|
3502
3549
|
async function waitForWalletClient(wagmiConfig, params = {}) {
|
|
3503
3550
|
for (let i = 0; i < WALLET_CLIENT_MAX_ATTEMPTS; i++) {
|
|
@@ -4249,10 +4296,11 @@ function failBothActions(approveAction, bridgeAction, message) {
|
|
|
4249
4296
|
]
|
|
4250
4297
|
};
|
|
4251
4298
|
}
|
|
4252
|
-
async function executeApprovePermit2(action, wagmiConfig) {
|
|
4299
|
+
async function executeApprovePermit2(action, wagmiConfig, options = {}) {
|
|
4253
4300
|
let walletClient = null;
|
|
4254
4301
|
let sender = null;
|
|
4255
4302
|
let preSendNonce = null;
|
|
4303
|
+
let nonceTrackerKey = null;
|
|
4256
4304
|
try {
|
|
4257
4305
|
walletClient = await waitForWalletClient(wagmiConfig);
|
|
4258
4306
|
const account = core.getAccount(wagmiConfig);
|
|
@@ -4276,19 +4324,20 @@ async function executeApprovePermit2(action, wagmiConfig) {
|
|
|
4276
4324
|
"APPROVE_PERMIT2 metadata is missing transaction parameters (to, data)."
|
|
4277
4325
|
);
|
|
4278
4326
|
}
|
|
4279
|
-
const
|
|
4280
|
-
if (
|
|
4281
|
-
|
|
4282
|
-
|
|
4283
|
-
|
|
4284
|
-
|
|
4285
|
-
|
|
4286
|
-
|
|
4287
|
-
|
|
4288
|
-
|
|
4289
|
-
|
|
4327
|
+
const shouldUseExplicitNonce = requiresExplicitEvmNonce(account);
|
|
4328
|
+
if (shouldUseExplicitNonce) {
|
|
4329
|
+
const snapshot = await snapshotExplicitEvmNonce({
|
|
4330
|
+
walletClient,
|
|
4331
|
+
sender,
|
|
4332
|
+
chainId: account.chainId,
|
|
4333
|
+
nonceTracker: options.nonceTracker,
|
|
4334
|
+
logContext: "APPROVE_PERMIT2",
|
|
4335
|
+
actionId: action.id
|
|
4336
|
+
});
|
|
4337
|
+
preSendNonce = snapshot.nonce;
|
|
4338
|
+
nonceTrackerKey = snapshot.trackerKey;
|
|
4290
4339
|
}
|
|
4291
|
-
const useExplicitNonce =
|
|
4340
|
+
const useExplicitNonce = shouldUseExplicitNonce && preSendNonce != null;
|
|
4292
4341
|
const txParams = {
|
|
4293
4342
|
from: sender,
|
|
4294
4343
|
to,
|
|
@@ -4318,6 +4367,9 @@ async function executeApprovePermit2(action, wagmiConfig) {
|
|
|
4318
4367
|
),
|
|
4319
4368
|
approveLabel
|
|
4320
4369
|
);
|
|
4370
|
+
if (preSendNonce != null) {
|
|
4371
|
+
advanceTrackedEvmNonce(options.nonceTracker, nonceTrackerKey, preSendNonce + 1);
|
|
4372
|
+
}
|
|
4321
4373
|
appendDebug("info", "APPROVE_PERMIT2: tx sent, awaiting settlement", {
|
|
4322
4374
|
actionId: action.id,
|
|
4323
4375
|
txHash,
|
|
@@ -4408,6 +4460,7 @@ async function executeApprovePermit2(action, wagmiConfig) {
|
|
|
4408
4460
|
actionId: action.id
|
|
4409
4461
|
});
|
|
4410
4462
|
if (recovery) {
|
|
4463
|
+
advanceTrackedEvmNonce(options.nonceTracker, nonceTrackerKey, recovery.latestNonce);
|
|
4411
4464
|
return actionRecovery(
|
|
4412
4465
|
action,
|
|
4413
4466
|
"Approval transaction was submitted but the wallet did not return a confirmation. Verifying on-chain\u2026",
|
|
@@ -4594,10 +4647,11 @@ async function executeSignPermit2(action, wagmiConfig, apiBaseUrl, sessionId) {
|
|
|
4594
4647
|
);
|
|
4595
4648
|
}
|
|
4596
4649
|
}
|
|
4597
|
-
async function executeExecuteBridge(action, wagmiConfig) {
|
|
4650
|
+
async function executeExecuteBridge(action, wagmiConfig, options = {}) {
|
|
4598
4651
|
let walletClient = null;
|
|
4599
4652
|
let sender = null;
|
|
4600
4653
|
let lastPreSendNonce = null;
|
|
4654
|
+
let lastNonceTrackerKey = null;
|
|
4601
4655
|
try {
|
|
4602
4656
|
walletClient = await waitForWalletClient(wagmiConfig);
|
|
4603
4657
|
const account = core.getAccount(wagmiConfig);
|
|
@@ -4618,22 +4672,25 @@ async function executeExecuteBridge(action, wagmiConfig) {
|
|
|
4618
4672
|
for (let i = 0; i < calls.length; i++) {
|
|
4619
4673
|
const call = calls[i];
|
|
4620
4674
|
const isIntermediateCall = i < calls.length - 1;
|
|
4621
|
-
const
|
|
4675
|
+
const shouldUseExplicitNonce = requiresExplicitEvmNonce(account);
|
|
4622
4676
|
let preSendNonce = null;
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
|
|
4633
|
-
|
|
4634
|
-
|
|
4677
|
+
let nonceTrackerKey = null;
|
|
4678
|
+
if (shouldUseExplicitNonce) {
|
|
4679
|
+
const snapshot = await snapshotExplicitEvmNonce({
|
|
4680
|
+
walletClient,
|
|
4681
|
+
sender,
|
|
4682
|
+
chainId: account.chainId,
|
|
4683
|
+
nonceTracker: options.nonceTracker,
|
|
4684
|
+
logContext: "EXECUTE_BRIDGE",
|
|
4685
|
+
actionId: action.id,
|
|
4686
|
+
extraDebug: { callIndex: i }
|
|
4687
|
+
});
|
|
4688
|
+
preSendNonce = snapshot.nonce;
|
|
4689
|
+
nonceTrackerKey = snapshot.trackerKey;
|
|
4690
|
+
lastPreSendNonce = preSendNonce;
|
|
4691
|
+
lastNonceTrackerKey = nonceTrackerKey;
|
|
4635
4692
|
}
|
|
4636
|
-
const useExplicitNonce =
|
|
4693
|
+
const useExplicitNonce = shouldUseExplicitNonce && preSendNonce != null;
|
|
4637
4694
|
const txParams = {
|
|
4638
4695
|
from: sender,
|
|
4639
4696
|
to: call.to,
|
|
@@ -4662,6 +4719,9 @@ async function executeExecuteBridge(action, wagmiConfig) {
|
|
|
4662
4719
|
),
|
|
4663
4720
|
watchdogLabel
|
|
4664
4721
|
);
|
|
4722
|
+
if (preSendNonce != null) {
|
|
4723
|
+
advanceTrackedEvmNonce(options.nonceTracker, nonceTrackerKey, preSendNonce + 1);
|
|
4724
|
+
}
|
|
4665
4725
|
appendDebug("info", "EXECUTE_BRIDGE: tx sent", {
|
|
4666
4726
|
actionId: action.id,
|
|
4667
4727
|
callIndex: i,
|
|
@@ -4747,6 +4807,7 @@ async function executeExecuteBridge(action, wagmiConfig) {
|
|
|
4747
4807
|
actionId: action.id
|
|
4748
4808
|
});
|
|
4749
4809
|
if (recovery) {
|
|
4810
|
+
advanceTrackedEvmNonce(options.nonceTracker, lastNonceTrackerKey, recovery.latestNonce);
|
|
4750
4811
|
return actionRecovery(
|
|
4751
4812
|
action,
|
|
4752
4813
|
"Bridge transaction was submitted but the wallet did not return a confirmation. Verifying on-chain\u2026",
|
|
@@ -5291,6 +5352,7 @@ function useAuthorizationExecutor(options) {
|
|
|
5291
5352
|
const walletConnectRuntimeRef = react.useRef(/* @__PURE__ */ new Map());
|
|
5292
5353
|
const activeWalletConnectRuntimeKeyRef = react.useRef(void 0);
|
|
5293
5354
|
const activeEvmTransportRef = react.useRef("wagmi");
|
|
5355
|
+
const evmNonceTrackerRef = react.useRef(/* @__PURE__ */ new Map());
|
|
5294
5356
|
const [batchTxHash, setBatchTxHash] = react.useState(null);
|
|
5295
5357
|
const externalAuthorizationAvailableRef = react.useRef(false);
|
|
5296
5358
|
const setExternalAuthorizationAvailable = react.useCallback((available) => {
|
|
@@ -5346,6 +5408,7 @@ function useAuthorizationExecutor(options) {
|
|
|
5346
5408
|
setApproveSplConfirming(null);
|
|
5347
5409
|
activeEvmTransportRef.current = "wagmi";
|
|
5348
5410
|
activeWalletConnectRuntimeKeyRef.current = void 0;
|
|
5411
|
+
evmNonceTrackerRef.current.clear();
|
|
5349
5412
|
setExecuting(false);
|
|
5350
5413
|
executingRef.current = false;
|
|
5351
5414
|
}, []);
|
|
@@ -5371,6 +5434,7 @@ function useAuthorizationExecutor(options) {
|
|
|
5371
5434
|
if (result2.status === "success" && result2.data?.transport === "wagmi") {
|
|
5372
5435
|
activeEvmTransportRef.current = "wagmi";
|
|
5373
5436
|
activeWalletConnectRuntimeKeyRef.current = void 0;
|
|
5437
|
+
evmNonceTrackerRef.current.clear();
|
|
5374
5438
|
if (action.metadata?.chainFamily !== "svm") {
|
|
5375
5439
|
walletCapabilitiesRef.current = await refreshWalletCapabilities(
|
|
5376
5440
|
wagmiConfig,
|
|
@@ -5383,6 +5447,7 @@ function useAuthorizationExecutor(options) {
|
|
|
5383
5447
|
walletCapabilitiesRef.current = {};
|
|
5384
5448
|
walletCapabilitiesRefreshedRef.current = true;
|
|
5385
5449
|
batchCapabilityDecisionRef.current = null;
|
|
5450
|
+
evmNonceTrackerRef.current.clear();
|
|
5386
5451
|
}
|
|
5387
5452
|
return result2;
|
|
5388
5453
|
}
|
|
@@ -5392,6 +5457,7 @@ function useAuthorizationExecutor(options) {
|
|
|
5392
5457
|
externalAuthorizationAvailable: externalAuthorizationAvailableRef.current
|
|
5393
5458
|
});
|
|
5394
5459
|
if (result.status === "success" && action.metadata?.chainFamily !== "svm") {
|
|
5460
|
+
evmNonceTrackerRef.current.clear();
|
|
5395
5461
|
walletCapabilitiesRef.current = await refreshWalletCapabilities(
|
|
5396
5462
|
wagmiConfig,
|
|
5397
5463
|
"open-provider"
|
|
@@ -5415,11 +5481,13 @@ function useAuthorizationExecutor(options) {
|
|
|
5415
5481
|
walletCapabilitiesRef.current = {};
|
|
5416
5482
|
walletCapabilitiesRefreshedRef.current = true;
|
|
5417
5483
|
batchCapabilityDecisionRef.current = null;
|
|
5484
|
+
evmNonceTrackerRef.current.clear();
|
|
5418
5485
|
}
|
|
5419
5486
|
return result2;
|
|
5420
5487
|
}
|
|
5421
5488
|
const result = await executeSwitchChain(action, wagmiConfig, switchChainAsync);
|
|
5422
5489
|
if (result.status === "success" && action.metadata?.chainFamily !== "svm") {
|
|
5490
|
+
evmNonceTrackerRef.current.clear();
|
|
5423
5491
|
walletCapabilitiesRef.current = await refreshWalletCapabilities(
|
|
5424
5492
|
wagmiConfig,
|
|
5425
5493
|
"switch-chain"
|
|
@@ -5437,7 +5505,9 @@ function useAuthorizationExecutor(options) {
|
|
|
5437
5505
|
dispatchOptions?.onWalletConnectDisplayUri
|
|
5438
5506
|
);
|
|
5439
5507
|
}
|
|
5440
|
-
return executeApprovePermit2(action, wagmiConfig
|
|
5508
|
+
return executeApprovePermit2(action, wagmiConfig, {
|
|
5509
|
+
nonceTracker: evmNonceTrackerRef.current
|
|
5510
|
+
});
|
|
5441
5511
|
case "DEPLOY_SMART_ACCOUNT":
|
|
5442
5512
|
return actionSuccess(action, "Smart account deployment acknowledged.");
|
|
5443
5513
|
case "SIGN_PERMIT2": {
|
|
@@ -5496,7 +5566,9 @@ function useAuthorizationExecutor(options) {
|
|
|
5496
5566
|
dispatchOptions?.onWalletConnectDisplayUri
|
|
5497
5567
|
);
|
|
5498
5568
|
}
|
|
5499
|
-
return executeExecuteBridge(action, wagmiConfig
|
|
5569
|
+
return executeExecuteBridge(action, wagmiConfig, {
|
|
5570
|
+
nonceTracker: evmNonceTrackerRef.current
|
|
5571
|
+
});
|
|
5500
5572
|
default:
|
|
5501
5573
|
return actionError(action, `Unsupported action type: ${action.type}`);
|
|
5502
5574
|
}
|
|
@@ -5649,6 +5721,7 @@ function useAuthorizationExecutor(options) {
|
|
|
5649
5721
|
setError(null);
|
|
5650
5722
|
setBatchTxHash(null);
|
|
5651
5723
|
setApproveSplConfirming(null);
|
|
5724
|
+
evmNonceTrackerRef.current.clear();
|
|
5652
5725
|
return true;
|
|
5653
5726
|
}, []);
|
|
5654
5727
|
const endExecution = react.useCallback(() => {
|
|
@@ -5657,6 +5730,7 @@ function useAuthorizationExecutor(options) {
|
|
|
5657
5730
|
setApproveSplConfirming(null);
|
|
5658
5731
|
activeEvmTransportRef.current = "wagmi";
|
|
5659
5732
|
activeWalletConnectRuntimeKeyRef.current = void 0;
|
|
5733
|
+
evmNonceTrackerRef.current.clear();
|
|
5660
5734
|
setExecuting(false);
|
|
5661
5735
|
executingRef.current = false;
|
|
5662
5736
|
}, []);
|
|
@@ -7218,7 +7292,7 @@ function resolveStickyPhase(state) {
|
|
|
7218
7292
|
if (currentPhase.step === "manual-transfer" && !state.loginRequested) {
|
|
7219
7293
|
return currentPhase;
|
|
7220
7294
|
}
|
|
7221
|
-
if (currentPhase.step === "deposit-options" && !state.loginRequested) {
|
|
7295
|
+
if (currentPhase.step === "deposit-options" && !state.loginRequested && !state.privyAuthenticated) {
|
|
7222
7296
|
return currentPhase;
|
|
7223
7297
|
}
|
|
7224
7298
|
if (!state.loginRequested && state.setupFlowScreen === "one-tap-setup") {
|