Skip to content
AstrosDocs
Open app
Skip to Content
UI SDK

Swap panel reference

Connect a wallet, sign transactions, and control the swap panel.

Swap Panel

This reference describes the published client in navi-web-component@0.0.27. Its hosted panel returned HTTP 404 on November 25, 2026. Check panel availability before testing the flow.

Usage


Import the component

import { SwapPanelClient } from 'navi-web-component'

Create the browser client

const swapPanelClient = SwapPanelClient.getInstance()

The component uses the singleton pattern, so multiple calls to getInstance return the same instance.

Register the onSignTransaction method for transaction signing.

Use the signing function from your wallet adapter. Return the signed transaction bytes and signature in the shape expected by the client.

swapPanelClient.onSignTransaction = async (txb) => {
  // run sign transaction logic in your app
  // after signed, return the signature and bytes
  const resp = await signTransaction({
    transaction: txb,
  })
  return {
    signature: resp.signature,
    bytes: resp.bytes,
  }
}

Handle a connection request

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.

swapPanelClient.events.on('clickConnect', () => {
  openWalletSelector() // supplied by your application
})

Sync the selected wallet address

After a successful connection or account change, pass the address supplied by your wallet adapter. Clear it on disconnect.

// wallet connected
swapPanelClient.setUserAddress(connectedAccount.address)
// wallet disconnected
swapPanelClient.setUserAddress('')

Call show() to open the panel. Wait for ready before applying token or amount settings.

Methods


show()

Displays the swap panel.

swapPanelClient.show()

hide()

Hides the swap panel.

swapPanelClient.hide()

setTokenFrom(coinType: string): Promise<boolean>

Sets the token to swap from.

swapPanelClient.setTokenFrom('0xa99b8952d4f7d947ea77fe0ecdcc9e5fc0bcab2841d6e2a5aa00c3044e5544b5::navx::NAVX')

setTokenTo(coinType: string): Promise<boolean>

Sets the token to swap to.

swapPanelClient.setTokenTo('0x2::sui::SUI')

setTokenFromAmount(amount: string): Promise<boolean>

Sets the sell amount in display units, as if the user had entered it in the panel.

swapPanelClient.setTokenFromAmount('1000')

changeTheme(theme: string): Promise<unknown>

Pass dark or light. The published TypeScript declaration returns Promise<unknown>.

swapPanelClient.changeTheme('dark')
swapPanelClient.changeTheme('light')

Events

Use the events property to listen for specific swap panel events.


Event nameDescription
readytrigger when swap panel is ready
clickConnecttrigger when connect button is clicked.
swapSuccesstrigger when swap success
showtrigger when swap panel show
hidetrigger when swap panel hide
swapPanelClient.events.on(eventName, callback)

On this page