// For Auto routes (using requestHash from submission)
let status;
const terminalStates = [3, 4, 5, 6, 7]; // FULFILLED, SETTLED, EXPIRED, CANCELLED, REFUNDED
do {
await new Promise((resolve) => setTimeout(resolve, 5000)); // Wait 5 seconds between checks
console.log("Checking status...");
try {
status = await checkStatus(submitResult.requestHash);
console.log("Status details:", status.bungeeStatusCode);
} catch (error) {
console.error("Failed to check status:", error?.message || "Unknown error");
}
} while (!status || !terminalStates.includes(status.bungeeStatusCode));
// Handle terminal states
if (status) {
const code = status.bungeeStatusCode;
if (code === 3) {
// FULFILLED
console.log(
"Transaction complete:",
"\n- Hash:",
status.destinationData?.txHash || "Transaction hash not available"
);
} else if (code === 4) {
// SETTLED
console.log("Transaction settled:", status.destinationData?.txHash || "Transaction hash not available");
} else if (code === 5) {
// EXPIRED
console.log("Request expired. The request was not processed within the time limit.");
} else if (code === 6) {
// CANCELLED
console.log("Request cancelled.");
} else if (code === 7) {
// REFUNDED
console.log("Request refunded:", status.refund?.txHash || "Refund transaction hash not available");
}
}