📘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 theConfiginterface.theme: This property lets you specify a custom UI theme for the widget. It must be an object that follows the structure of theThemeinterface.
Here's an example of how to use these properties in TypeScript:
import { Widget, Config, Theme } from '@xyfinance/widget'
const config: Config = {
disabledChains: ['137', '42161'],
slippage: '1',
fromInput: '0.1',
...
}
const theme: Theme = {
mode: 'light',
fontFamily: 'proxima-nove, ui-sans-serif, system-ui, -apple-system',
borderRadius: {
container: '12px',
inner: '8px',
button: '32px'
},
colors: {
primary: '#277EEC',
gradient: ['#277EEC', '#1499E4']
},
components: {
button: {
variant: 'gradient'
}
}
}
function App() {
return (
<div>
<Widget theme={theme} config={config} />
</div>
)
}Theme
mode
modetype:
'light'|'dark'default:
'light'
This option allows you to toggle the widget's mode between light and dark, depending on your preference.
fontFamily
fontFamilytype:
stringdefault:
'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
borderRadiustype:
IBorderRadius
default:
This option controls the border radius of certain components. You can specify the radius in pixels.
colors
colorstype:
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.
components
componentstype:
IComponents
default:
This option controls the behavior and appearance of the components.
Config
disabledChains
disabledChainstype:
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:
slippage
slippagetype:
stringdefault:
'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
referrertype:
stringdefault:
'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
commissionRatetype:
numberdefault:
0min:
0max:
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.
commissionRaterepresents 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.referrerparameter 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
fromInputtype:
stringdefault:
''
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
fromTokentype:
{ chainId: string, address: string }|nulldefault:
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
toTokentype:
{ chainId: string, address: string }|nulldefault:
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
featuredTokenstype:
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:
disabledTokens
disabledTokenstype:
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:
disableTokenSelection
disableTokenSelectiontype:
'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
enableReporttype:
booleandefault:
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
Was this helpful?