Skip to content

Commit 7a9e5bf

Browse files
committed
Fix same-chain tx ws cleanup
1 parent edfc756 commit 7a9e5bf

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

packages/sdk/src/utils/executeSteps/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@ export async function executeSteps(
281281
stepItems,
282282
onWebsocketFailed: statusControl.websocketActive
283283
? onWebsocketFailed
284-
: null
284+
: null,
285+
statusControl
285286
})
286287
break
287288
}

packages/sdk/src/utils/executeSteps/transactionStep.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ export async function handleTransactionStepItem({
2424
isAtomicBatchSupported,
2525
incompleteStepItemIndex,
2626
stepItems,
27-
onWebsocketFailed
27+
onWebsocketFailed,
28+
statusControl
2829
}: {
2930
stepItem: TransactionStepItem
3031
step: Execute['steps'][0]
@@ -38,6 +39,7 @@ export async function handleTransactionStepItem({
3839
incompleteStepItemIndex: number
3940
stepItems: Execute['steps'][0]['items']
4041
onWebsocketFailed: (() => Promise<void>) | null
42+
statusControl?: { lastKnownStatus?: string }
4143
}): Promise<void> {
4244
if (!stepItem.data) {
4345
throw `Step item is missing data`
@@ -131,6 +133,7 @@ export async function handleTransactionStepItem({
131133
details: json?.details
132134
})
133135
}
134-
}
136+
},
137+
statusControl
135138
)
136139
}

packages/sdk/src/utils/executeSteps/websocketHandlers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function handleWebSocketUpdate({
3131
// Handle terminal states
3232
if (isTerminalStatus(data.status)) {
3333
client.log(
34-
['WebSocket received terminal status', data.status],
34+
['WebSocket received terminal status: ', data.status],
3535
LogLevel.Verbose
3636
)
3737
statusControl.closeWebSocket?.()

packages/sdk/src/utils/transaction.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ export async function sendTransactionSafely(
5151
setReceipt?: (receipt: TransactionReceipt | SvmReceipt | SuiReceipt) => void,
5252
setCheckStatus?: (
5353
checkStatus: NonNullable<Execute['steps'][0]['items']>[0]['checkStatus']
54-
) => void
54+
) => void,
55+
statusControl?: { lastKnownStatus?: string }
5556
) {
5657
const client = getClient()
5758
try {
@@ -197,11 +198,8 @@ export async function sendTransactionSafely(
197198
const pollForConfirmation = async (receiptController?: AbortController) => {
198199
isValidating?.()
199200

200-
console.log('onWebsocketFailed', onWebsocketFailed)
201-
202201
// If websocket is enabled, wait for it to fail before falling back to polling
203202
if (onWebsocketFailed) {
204-
console.log('waiting for websocket to fail')
205203
try {
206204
await onWebsocketFailed()
207205
client.log(['WebSocket failed, starting polling'], LogLevel.Verbose)
@@ -214,8 +212,6 @@ export async function sendTransactionSafely(
214212
}
215213
}
216214

217-
client.log(['Polling for confirmation'], LogLevel.Verbose)
218-
219215
// Start polling
220216
while (
221217
waitingForConfirmation &&
@@ -227,6 +223,8 @@ export async function sendTransactionSafely(
227223
return
228224
}
229225

226+
client.log(['Polling for confirmation'], LogLevel.Verbose)
227+
230228
let res: AxiosResponse<any, any> | undefined
231229
if (check?.endpoint && !request?.data?.useExternalLiquidity) {
232230
let endpoint = check?.endpoint
@@ -437,6 +435,10 @@ export async function sendTransactionSafely(
437435
await confirmationPromise
438436
} else {
439437
waitingForConfirmation = false
438+
// For same chain transactions, mark as complete to prevent WebSocket polling fallback
439+
if (statusControl) {
440+
statusControl.lastKnownStatus = 'success'
441+
}
440442
}
441443
}
442444

0 commit comments

Comments
 (0)