Liquidswap Widget

A web component custom element that can be embedded in any frontend application, or even plain HTML/JS/CSS. Using the full strength of the SDK, the widget can provide swap operations from any other custom dApp, wallet, etc.

Installation

yarn add @pontem/liquidswap-widget

or

npm install @pontem/liquidswap-widget

Usage

Function loadWidget accepts widget HTML tag name as string. It can be custom name but must be in kebab case. We recommend to use liquidswap-widget name. Passed name must be exactly the same as tag name.

  • React

    import React, { useLayoutEffect } from 'react';
    import { loadWidget } from '@pontem/liquidswap-widget';
    
    export const Widget = () => {
      useLayoutEffect(() => {
        loadWidget('liquidswap-widget');
      }, []);
      return (
        <div className="'Your Wrapper className'">
          <liquidswap-widget/>
        </div>
      );
    };
  • Vue

    <template>
      <div class="'Your Wrapper class name'">
        <liquidswap-widget>
      </div>
    </template>
    
    <script setup lang="ts">
      import { loadWidget } from '@pontem/liquidswap-widget';
      loadWidget('liquidswap-widget');
    </script>
  • Any other framework / lib

    1. Make sure you added html tag liquidswap-widget into app.

    <liquidswap-widget></liquidswap-widget>
    1. Import loadWidget function from npm and run with passing html tag name in kebab case;

    import { loadWidget } from '@pontem/liquidswap-widget';loadWidget('liquidswap-widget');

When Loaded

You can listen widget and add some logic (if necessary) when widget is embedded:

Live Example

Widget example published to github pages:

https://pontem-network.github.io/liquidswap-widget/

Liquidswap Widget as Dapp (native wallet application)

Liquidswap Widget could be used as Dapp inside wallet.

In that case web-custom-element needs several properties:

  • Account address of wallet;

  • Network information: name and chainId;

  • Transaction info: status and hash;

  • Properties should be passed as strings (data-attributes), so to pass Object variable you need to use JSON.stringify() on passing Object.

  • Properties will be extruded with JSON.parse() inside widget;

  • Properties are reactive, so any change to props will update widget’s internal store;

Also, widget will dispatch to Custom Events:

  1. signAndSubmitTransaction’ - this event will return CustomEvent with ‘detail’ property containing ready for wallet transaction payload. Just accept props inside handler and you will find prop ‘detail’ with full transaction payload;

  2. transactionProcessed’ - this event will be fired after widget accepts hash and status of transaction and correctly resolves it with.

Example in React-JSX

Note: When this properties are passed to widget - it treats Parent element as ‘wallet environment’, so connect / disconnect wallet flow will be skipped / hidden.

Last updated