Comment on page
📬

Events

Events are available as callback functions in the PoodlApp config object. Each event will provide you with a set of outputs that can then be used in custom functions.
Note that events are fired locally, async functions are therefore not required.

onAccountChange

This event is triggered every time users connect or disconnect their wallet as well as switching between accounts.
/*
* available args
* newAccount: string
* oldAccount: string
*/
onAccountChange: newAccount => {
console.log(newAccount)
}

onChainChange

This event is triggered every time users change newtork (chain).
/*
* available args
* newChainId: chainId
* oldChainId: chainId
*/
onChainChange: newChainId => {
console.log(newChainId)
}

onTokenSelect

This event is triggered every time users change either the input or the output token.
It gives back 2 json objects - inputToken and outputToken
/*
* available args
* inputToken: Token
* outputToken: Token
*/
inputToken : {
address: string,
chainId: number,
decimals: number,
hasTransactonFees: boolean,
logoURI: string,
name: string,
symbol: string
}
outputToken : {
address: string,
chainId: number,
decimals: number,
hasTransactonFees: boolean,
logoURI: string,
name: string,
symbol: string
}
Usage example:
onTokenSelect: inputToken => {
console.log(inputToken.chainId)
console.log(inputToken.decimals)
}

onSuccessSwap

This event is triggered every time users succesfully swap a token through the widget
It gives back a json object - quote
The quote object represent the aggregator quote used to submit the transaction and therefore it includes all the information related to that transaction.
/*
* available args
* quote: aggregatorQuote
*/
quote : {
from: string, //address of the user
chainId: number, // chain where the transaction took place
buyTokenAddress: string, // address of the token to be bought
sellTokenAddress: string, // address of the token to be sold
sellAmount: number, // amount sold
buyAmount: string, // amount bought
}
This is particularly useful for tracking or analytics purposes:
// Database
onSuccessSwap: quote => {
//{code to push to database(quote)}
}
// Google analytics
// {define Google analytics event}
onSuccessSwap: quote => {
//{Google analytics event(quote)}
}