đ °ī¸Aggregator Components
Swap Panel
Provides a complete Swap transaction process, including pair selection, intelligent routing, constructing transactions, submitting transactions, and displaying transaction results.
Usage
Import the component
Instantiating Component
The component uses the singleton pattern, so multiple calls to getInstance return the same instance.
Register the onSignTransaction method for transaction signing.
The user executing swap needs the wallet to sign the transaction. the DApp needs to register a callback function to implement the wallet signing logic.
Listen connect event
If the user uses the Swap component within the DApp without connecting to the wallet, the component displays a button to connect to the wallet. Clicking on the button by the user triggers the connect event, which the DApp needs to listen to and enter the wallet connection flow.
Sync user address
DApp needs to pass the address of the currently connected wallet to the component.
Calling the methods of instance
Methods
show()
Displays the swap panel.
hide()
Hides the swap panel.
setTokenFrom(coinType: string): Promise<boolean>
Sets the token to swap from.
setTokenTo(coinType: string): Promise<boolean>
Sets the token to swap to.
setTokenFromAmount(amount: string): Promise<boolean>
Sets the amount for the token to swap from.
changeTheme(theme: 'dark' | 'light'): Promise<boolean>
Sets the UI theme.
Events
Use the events
property to listen for specific swap panel events.
ready
trigger when swap panel is ready
clickConnect
trigger when connect button is clicked.
swapSuccess
trigger when swap success
show
trigger when swap panel show
hide
trigger when swap panel hide
Last updated