📘Widget API Reference
There are two props you can pass to XY Finance Widget
:
config
: This property allows you to specify the configuration for the widget. It must be an object that follows the structure of theConfig
interface.theme
: This property lets you specify a custom UI theme for the widget. It must be an object that follows the structure of theTheme
interface.
These two properties are optional. If not provided, they will default to predefined values.
Here's an example of how to use these properties in TypeScript
:
Theme
mode
mode
type:
'light'
|'dark'
default:
'light'
This option allows you to toggle the widget's mode between light and dark, depending on your preference.
fontFamily
fontFamily
type:
string
default:
'ui-sans-serif, system-ui, -apple-system'
This option sets the font display for the widget, and works in compatibility with css font-family property.
Please note that you need to install the font that you want to use in your frontend project by yourself, such as:
borderRadius
borderRadius
type:
IBorderRadius
default:
This option controls the border radius of certain components. You can specify the radius in pixels.
colors
colors
type:
IColors
default:
This option defines the colors used in this widget. You can specify the color using valid color strings such as RGBA, Hex, or HSL values.
gradient[0]
represents the initial color, while gradient[1]
signifies the final color in the gradient.
components
components
type:
IComponents
default:
This option controls the behavior and appearance of the components.
This option will be expanded over time as we extend our support.
Config
disabledChains
disabledChains
type:
Array<string>
default:
[]
You can hide chains that you don't want to display. Here's our current list of supported chains.
For example, if you wish to disable BNB
and Polygon
from appearing in your widget, you can set:
For security purposes, Ethereum
cannot be disabled.
slippage
slippage
type:
string
default:
'1'
This option allows you to set the slippage rate for swapping, which can only be set to values with two decimal places between 0.01 and 49.99.
If the difference between the estimated quote and execution price exceeds the default rate of 1%, the transaction will be cancelled.
referrer
referrer
type:
string
default:
'0xFD19727868A8197F42e7a52d024374598F62953B'
This option requires you to provide a web3 wallet address or smart contract address. Please complete the form. If the commissionRate
is not configured, the referrer parameter will solely be utilized for tracking the traffic linked to your account.
commissionRate
commissionRate
type:
number
default:
0
min:
0
max:
20000
Setting the commissionRate will collect a fee percentage from the user's swap amount, which is then directly distributed to the specified wallet address. XY Finance will receive a share of these fees, varying according to the use case and transaction volume.
commissionRate
represents the fee you wish to collect. It is an integer between 0 and 20,000. In this range, 20,000 corresponds to 2%, 1,000 represents 0.1%, and so on in a similar fashion.referrer
parameter represents the address where you want to receive the fees. The collected fee in every transaction will be directly transferred to this address. Before proceeding, please ensure that the provided address is under your management and capable of receiving assets correctly.
fromInput
fromInput
type:
string
default:
''
This option sets the initial value in your widget's source chain input.
For example, if you want to set the initial value to be 100.99
, you can use the following code snippet:
fromToken
fromToken
type:
{ chainId: string, address: string }
|null
default:
null
This option allows you to set the initial token for the source chain section of your widget.
For example, if you want to set your source chain token as ETH
on the Ethereum network, you can use the following code snippet:
You should use 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
as the address for a native token in your configuration. Alternatively, you can also import NATIVE_TOKEN_ADDRESS
from the widget package and use it as follows:
This allows you to use a constant value for the native token address in your code, which can make it easier to manage and modify in the future.
toToken
toToken
type:
{ chainId: string, address: string }
|null
default:
null
This option allows you to set the initial token for the destination chain section of your widget.
For example, if you want to set your destination chain token as BNB
on the BNB chain, you can use the following code snippet:
featuredTokens
featuredTokens
type:
Array<{ chainId: string, address: string }>
default:
[]
This option highlights the tokens that you provide in the token selection page.
For example, if you want to highlight USDT
on Ethereum and USDC
on Polygon, you can use the following code snippet:
Please remember to fill out the form provided if you would like to highlight a token that is not listed in our token list. This will allow us to add it and ensure that the token icon is displayed correctly.
disabledTokens
disabledTokens
type:
Array<{ chainId: string, address: string }>
default:
[]
This option allows you to hide specific tokens from the token selection page. This can be useful if you want to limit the number of tokens available to the user.
For example, if you want to hide USDT
on Ethereum and USDC
on Polygon, you can use the following code snippet:
It's important to note that for safety reasons, native tokens cannot be disabled. Furthermore, please keep in mind that the disabledTokens
option takes priority over the featuredTokens
option. If a token is listed in both options, it will be hidden.
disableTokenSelection
disableTokenSelection
type:
'from'
|'to'
|'both'
|'none'
default:
'none'
This option allows you to disable the swap token selection, which can be helpful if you want to limit your users to swapping tokens with a specific token.
enableReport
enableReport
type:
boolean
default:
true
Enabling the enableReport
feature allows us to collect and analyze error messages from users on our server. This helps us to identify and resolve potential issues with the widget, ensuring a better user experience.
Examples
Check out our examples repository.
Last updated