NAVI Protocol Developer Docs
  • đŸ–Ĩī¸Build with NAVI Protocol
  • 📖Smart Contract Overview
    • 1ī¸Lending Core
    • 2ī¸Flash Loan
    • 3ī¸Calculator
    • 4ī¸Dynamic Calculator
    • 5ī¸Storage
  • 🕓Decentralized Oracle
    • đŸ’ŊOracle Interface
  • đŸ—ēī¸Contract Configuration
    • 1ī¸âƒŖGet the Latest Package ID
    • 2ī¸âƒŖGet Pools Config and Oracle Price Feeds
    • 3ī¸âƒŖGet Flashloan Config
  • đŸ›Šī¸NAVI SDK
    • 1ī¸Getting Started
    • 2ī¸Retrieve Info & Data
    • 3ī¸Interactions With NAVI
    • 4ī¸PTB Functions
    • 5ī¸Other Ways to Interact with NAVI
    • 6ī¸Demo
  • 📲NAVI UI SDK
    • ⭐Getting Started
    • đŸ…°ī¸Aggregator Components
  • 🎧Contract Integration with NAVI
    • 1ī¸âƒŖRetrieve Pools Info inside Contract
    • 2ī¸âƒŖIntegration with Account Cap
    • 3ī¸âƒŖDemo
  • 🏅NAVI Aggregator
    • 1ī¸âƒŖGetting Started
    • 2ī¸âƒŖAggregator SDK
    • 3ī¸âƒŖAggregator API
    • 🛜Contact Page
  • NAVI Bridge
    • 🚀Quick Start
    • 📄Bridge SDK
  • 📊NAVI Uptime Status Page
  • 📚NAVI API Collection
    • NAVI API
    • afSui, haSui, vSui API
  • ❓FAQ
Powered by GitBook
On this page
  • Swap Panel
  • Usage
  • Methods
  • Events
  1. NAVI UI SDK

Aggregator Components

Swap Panel

Provides a complete Swap transaction process, including pair selection, intelligent routing, constructing transactions, submitting transactions, and displaying transaction results.

Usage


1

Import the component

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

Instantiating Component

const swapPanelClient = SwapPanelClient.getInstance()

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

3

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.

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,
  }
}
4

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.

swapPanelClient.events.on('clickConnect', () => {
  // run connect wallet logic in your app
  // after connected, set user address in swap panel
  swapPanelClient.setUserAddress('0x1234567890123456789012345678901234567890')
})
5

Sync user address

DApp needs to pass the address of the currently connected wallet to the component.

// wallet connected
swapPanelClient.setUserAddress('0x1234567890123456789012345678901234567890')
// wallet disconnected
swapPanelClient.setUserAddress('')
6

Calling the methods of instance

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('0x02::sui::SUI')

setTokenFromAmount(amount: string): Promise<boolean>

Sets the amount for the token to swap from.

swapPanelClient.setTokenFromAmount('1000')

changeTheme(theme: 'dark' | 'light'): Promise<boolean>

Sets the UI theme.

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

Events

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


Event name
Description

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

swapPanelClient.events.on(eventName, callback)
PreviousGetting StartedNextContract Integration with NAVI

Last updated 5 months ago

📲
đŸ…°ī¸