Skip to main content

Events

The <treasures-swap> element re-dispatches what happens in the widget as DOM events named treasures:<type>, with the details in event.detail. Listen on the element:

const widget = document.querySelector('treasures-swap');

widget.addEventListener('treasures:trade_filled', (event) => {
const { trade_id, side, ticker } = event.detail;
analytics.track('Stock trade filled', { trade_id, side, ticker });
});

Events say what happened, never who: no event carries a wallet address, a balance or a transaction hash. The widget sends them only to your page's own origin.

Event types​

Eventevent.detailWhen
treasures:ready{ integrator_recognized }The widget has loaded. integrator_recognized is false when you set no integrator ID or one that isn't an ID's shape, and null while a well-formed ID is still unchecked (the integrator event answers it)
treasures:integrator{ recognized }After the first quote: whether your integrator ID is a registered, active integrator's. See Integrator ID and Fees
treasures:resize{ height }The widget's content height in CSS pixels changed. The element resizes the frame for you unless you set height
treasures:connected{ ecosystems }The connected wallet types changed: an array holding "evm" and/or "solana", empty after the last disconnect
treasures:connect_requested{ ecosystem }With wallet="host": the user clicked Connect for a wallet type your page owns but hasn't passed in. "evm", "solana" or null (either). Open your own connect. See Use your page's wallet
treasures:popup{ open }A dialog opened (true, for each one, even over another) or the last open one closed (false)
treasures:trade_submitted{ trade_id, side, ticker, amount_usd }The user signed a trade and it went out. side is "buy" or "sell"; amount_usd is a decimal string, or null when unknown
treasures:trade_filled{ trade_id, side, ticker }The trade filled. Sent even if the user closed the review before the fill
treasures:trade_failed{ trade_id, code }The trade failed. code is the API's error code (as listed per route in the API Reference), network_error when no answer came back, or client_error. trade_id is null when the failure came before a quote
treasures:bridge{ pending }A cross-chain top-up started (true) or finished (false). See Bridges in flight

trade_id is a random ID the widget makes up for one trade. It is the same in the trade_submitted event and the trade_filled or trade_failed that ends it, so you can pair them. It is not a Treasures quote or trade ID and can't be looked up in the API.

Bridges in flight​

Some buys first move the user's stablecoin to the stock's chain in a separate bridge step, then buy once it lands. While that bridge is in flight the element's bridgePending property is true. Warn before your page navigates away or removes the widget:

window.addEventListener('beforeunload', (event) => {
if (widget.bridgePending) event.preventDefault();
});