Status Tracking
Monitor the lifecycle of your cross-chain orders with real-time status tracking. The Aori SDK provides powerful tools to check order status and poll for updates until completion.
OrderStatus
type
The OrderStatus
type represents the different states an order can be in during its cross-chain lifecycle. Each status contains specific data relevant to that stage of execution.
pending
{
"status": "pending",
"timestamp": 1703001600
}
received
{
"status": "received",
"txHash": "0xabc123...",
"txUrl": "https://etherscan.io/tx/0xabc123...",
"timestamp": 1703001650
}
completed
{
"status": "completed",
"txHash": "0xdef456...",
"txUrl": "https://arbiscan.io/tx/0xdef456...",
"timestamp": 1703001780
}
failed
{
"status": "failed",
"error": "Insufficient liquidity",
"timestamp": 1703001720
}
OrderStatus Type Definition
type OrderStatus =
| { status: 'pending'; timestamp: number }
| { status: 'received'; txHash: string; txUrl: string; timestamp: number }
| { status: 'completed'; txHash: string; txUrl: string; timestamp: number }
| { status: 'failed'; error: string; timestamp: number };
getOrderStatus
function
Get the current status of an order by its hash. This function returns a snapshot of the order's current state.
- Name
orderHash
- Type
- string
- Description
The unique identifier of the order
- Name
apiUrl
- Type
- string
- Description
The Aori API endpoint URL
Returns: Promise<OrderStatus>
Basic Usage
import { getOrderStatus } from '@aori/aori-ts';
const status = await getOrderStatus(
'0x1234567890abcdef1234567890abcdef12345678',
'https://api.aori.io'
);
console.log(`Order status: ${status.status}`);
Error Handling
try {
const status = await getOrderStatus(orderHash, apiUrl);
if (status.status === 'failed') {
console.error('Order failed:', status.error);
} else if (status.status === 'completed') {
console.log('Order completed successfully!');
}
} catch (error) {
console.error('Failed to get order status:', error);
}
pollOrderStatus
function
Poll an order status until it reaches a final state (completed or failed). This function automatically retries at intervals and provides callbacks for status updates.
- Name
orderHash
- Type
- string
- Description
The unique identifier of the order
- Name
apiUrl
- Type
- string
- Description
The Aori API endpoint URL
- Name
options
- Type
- PollOrderStatusOptions
- Description
Configuration options for polling behavior
Returns: Promise<OrderStatus>
PollOrderStatusOptions
- Name
onStatusChange
- Type
- (status: OrderStatus) => void
- Description
Callback fired when status changes
- Name
onComplete
- Type
- (status: OrderStatus) => void
- Description
Callback fired when order reaches final state
- Name
interval
- Type
- number
- Description
Polling interval in milliseconds (default: 5000)
- Name
timeout
- Type
- number
- Description
Maximum time to poll in milliseconds (default: 300000)
Basic Polling
import { pollOrderStatus } from '@aori/aori-ts';
const finalStatus = await pollOrderStatus(
orderHash,
'https://api.aori.io',
{
onStatusChange: (status) => {
console.log(`Status updated: ${status.status}`);
},
interval: 3000, // Poll every 3 seconds
timeout: 600000 // 10 minute timeout
}
);
console.log('Final status:', finalStatus);
React Integration
import { useState, useEffect } from 'react';
import { pollOrderStatus } from '@aori/aori-ts';
function OrderTracker({ orderHash }) {
const [status, setStatus] = useState(null);
const [isPolling, setIsPolling] = useState(true);
useEffect(() => {
pollOrderStatus(orderHash, 'https://api.aori.io', {
onStatusChange: setStatus,
onComplete: (finalStatus) => {
setStatus(finalStatus);
setIsPolling(false);
}
}).catch(console.error);
}, [orderHash]);
return (
<div>
{status && (
<div>
Status: {status.status}
{isPolling && <span> (polling...)</span>}
</div>
)}
</div>
);
}
Best Practices
Handling Status Updates
function handleOrderStatus(status: OrderStatus) {
switch (status.status) {
case 'pending':
console.log('⏳ Order is pending execution...');
break;
case 'received':
console.log(`✅ Order received on source chain: ${status.txUrl}`);
break;
case 'completed':
console.log(`🎉 Order completed successfully: ${status.txUrl}`);
break;
case 'failed':
console.error(`❌ Order failed: ${status.error}`);
break;
}
}
Always implement proper error handling when tracking order status:
Error Handling
async function trackOrder(orderHash: string) {
try {
const finalStatus = await pollOrderStatus(orderHash, 'https://api.aori.io', {
onStatusChange: (status) => {
// Update UI with current status
updateOrderUI(status);
},
timeout: 600000 // 10 minutes
});
if (finalStatus.status === 'completed') {
// Handle successful completion
showSuccessMessage(finalStatus.txUrl);
} else if (finalStatus.status === 'failed') {
// Handle failure
showErrorMessage(finalStatus.error);
}
} catch (error) {
// Handle polling errors (network issues, timeouts, etc.)
console.error('Order tracking failed:', error);
showErrorMessage('Unable to track order status');
}
}
Performance Considerations
const pollOptions = {
interval: 5000, // 5 seconds - good balance of responsiveness and API load
timeout: 900000, // 15 minutes - reasonable for cross-chain operations
onStatusChange: (status) => {
// Update progress indicator
updateProgressBar(status);
// Show transaction links when available
if (status.status === 'received' || status.status === 'completed') {
showTransactionLink(status.txUrl);
}
}
};
- Use appropriate polling intervals based on your use case
- Implement exponential backoff for failed requests
- Set reasonable timeouts to avoid indefinite polling
- Consider using WebSocket connections for real-time updates in high-frequency applications