TradeWidget exposes callbacks for quote resolution, wallet connections, transaction lifecycle reporting, and error handling.
Example
Supported callbacks
| Callback | When it fires | Payload |
|---|---|---|
onQuote | After a new quote is resolved | TradeWidgetQuotePayload |
onConnect | After a wallet connection succeeds | TradeWidgetConnectPayload |
onApprove | When the widget submits a standalone approval transaction | TradeWidgetTransactionPayload |
onSwap | When the widget submits a swap transaction | TradeWidgetTransactionPayload |
onTxSubmitted | When any approval or swap transaction is submitted | TradeWidgetTransactionPayload |
onTxConfirmed | When a submitted transaction is confirmed | TradeWidgetTransactionPayload |
onError | When metadata, configuration, selection, quote, wallet, balances, execution, or unsupported errors occur | TradeWidgetErrorPayload |
Event behavior notes
onQuoteis deduplicated, so identical resolved quotes are not emitted repeatedlyonQuotecan fire after the initial quote load, a manual refresh, or an auto-refresh when the resolved quote changedonConnectonly reportsnamespace,address, andwalletName; it does not identify whether the connection came from the origin or destination sideonApproveandonSwapare submission hooks, not simple button-click hooksonTxSubmittedis the generic submission event for bothapproveandswaponTxConfirmedis the generic confirmation event for bothapproveandswaponErrorwithsource: "quote"andstatusCode: 429can come either from the Delora API or from the widget’s own local quote cooldown
- successful quotes auto-refresh every 60 seconds while the selection stays stable
- auto-refresh stops after 5 consecutive refresh cycles
- more than 5 quote requests within 5 seconds triggers a local cooldown
- the cooldown lasts 5 seconds
- during that window,
onErrorcan emit a quote error withstatusCode: 429even if the backend did not return 429
Error sources
onError can report the following source values:
metadataconfigurationquoteselectionwalletbalancesexecutionunsupported
status, statusCode, and the original error object.
