Skip to main content

Configure Swap Widget with TonConnectUI

To integrate our Swap Widget into your application , follow these steps to configure and set up the widget using the @swapcoffee/ui-sdk and @tonconnect/ui.

1. Create a Configuration File

First, create a configuration file to manage your settings for TonConnect and the Swap Widget. This file will include the manifestUrl for the TonConnect manifest and other configuration parameters. Here’s an example configuration file named config.js:
This configuration file allows you to customize both the TonConnect UI and the Swap Widget. Make sure that the manifestUrl points to the correct location of the TonConnect manifest file in your public folder to ensure proper integration and functionality.

2. createSwapWidget properties (via TonConnect injection mode)

When using the TonConnect injection mode, the createSwapWidget function accepts several configuration properties that allow you to customize the widget’s appearance, behavior, and connection settings.

Container Selector (string):

  • The CSS selector for the HTML element where the Swap Widget will be rendered.
Example: '#swap-widget-component'

Configuration Object (object):

This object contains the settings to customize the Swap Widget:
  • theme (string): Defines the visual theme of the widget.
Options: 'light', 'dark', 'coffee'
  • locale (string): Specifies the language and regional settings for the widget.
Options: 'zh', 'ua', 'ru', 'en', 'es', 'fr', 'fa'
  • tonConnectManifest (object): Configuration for the TonConnect manifest.
    • url (string): The URL pointing to the TonConnect manifest. This manifest contains details about the TonConnect application and its settings.
  • tonConnectUi (TonConnectUI instance): An instance of TonConnectUI for managing wallet connections and interactions.

injectionMode (string):

  • Specifies the connection method to be used for wallet interactions.
Example: 'tonConnect'

3. createSwapWidget usage

Configure Swap Widget with Payload Injection

To integrate our Swap Widget into your application, follow these steps to configure and set up the widget using the @swapcoffee/ui-sdk with Payload Injection Mode.

1. Create a Configuration File

First, create a configuration file to manage your settings for the Swap Widget. This file will include the configuration parameters required for the Payload connection method. Here’s an example configuration file named config.js:
This configuration file allows you to customize the Payload Injection Mode for the Swap Widget. The injectionMode parameter is set to 'payload', indicating that the widget will bypass TonConnect and use a custom method for handling wallet interactions.

2. Payload Connection Configuration Structure for Swap Widget

To configure the Payload connection for the swap.coffee widget, you need to define the payload object. This object contains all necessary parameters for establishing a manual wallet connection.
Here is an example configuration (payload.js):

3. createSwapWidget properties (via payload injection mode)

When using the payload injection mode, the createSwapWidget function accepts several configuration properties that allow you to customize the widget’s appearance, behavior, and connection settings.

Container Selector (string):

  • The CSS selector for the HTML element where the Swap Widget will be rendered.
Example: '#swap-widget-component'

Configuration Object (object):

This object contains the settings to customize the Swap Widget:
  • theme (string): Defines the visual theme of the widget.
Options: 'light', 'dark', 'coffee'
  • locale (string): Specifies the language and regional settings for the widget.
Options: 'zh', 'ua', 'ru', 'en', 'es', 'fr', 'fa'

Payload Object (object):

  • payload (object): The main object for configuring the connection to injectionMode: 'payload' the swap.coffee widget, containing all the necessary parameters to establish the connection through the wallet.
Example: for more information, please refer to section 2 (Payload Connection Configuration Structure for Swap Widget).

injectionMode (string):

  • Specifies the connection method to be used for wallet interactions.
Options: 'payload'

4. createSwapWidget usage