0.2.44 • Published 16 days ago

woofi-swap-widget v0.2.44

Weekly downloads
-
License
MIT
Repository
-
Last release
16 days ago

Woofi Swap Widget

Quick Start

Installation

npm add woofi-swap-widget

or

yarn add woofi-swap-widget

Usage

Initialize the Library with default wallet library(web3-onboard)

Use the minimum required config. There are more options available as detailed in the initialization section

//  main.js or index.js or other import file which will be called once
 import { init } from 'woofi-swap-widget'
 init()

Render the Library

// while target element is mounted, call the 'render' function
// component file
<template>
    <div id="swap" />
</template>
<script>
import { render } from 'woofi-swap-widget'
import 'woofi-swap-widget/dist/style.css' // import css
// on mounted lifecycle
onMounted(() => {
    render('#swap')
})
// or 
useEffect(() => {
    render('#swap') // render(el: string)
}, [])
</script>

Init Configuration

import { init } from 'woofi-swap-widget'
const options = {/** some options*/}
init(options)

Options

nametyperequireddefaultvaluesdescription
useUserWalletBooleannofalsetrue/falseuse user custom wallet, if it is true, will call the connectWallet and disconnectWallet function
userAddressStringno'''0x11...111'connected wallet address
chainIdHex Stringno'''0x123'connected chain id
providerHttpProvidernoconnected http provider
titleStringnoSwap'Swap'widget's title
allowChainsArraynoethereum,avax, bsc, fantom,polygon,allow chains to swap
classNameStringno''
widgetExtraFeeRateStringno0
widgetExtraFeeAddrStringno''
connectWallet() => voidPromise;nocustom connect wallet function
disconnectWallet() => voidPromise;nocustom disconnect wallet function
onSuccessNotifyfunctionnoSuccessful Notification function
onErrorNotifyfunctionnoError Notification function

API

init: init(option)

render: render(el: string)

updateAddressAndProvider: (address: Address, provider: Provider, isForce?: boolean) => Promise;

updateConnectWallet: (connectWalletHandler) => void

updateDisconnectWallet: (disconnectWalletHandler) => void

Using the Library with custom wallet

First set the option useUserWallet into true, if custom connectWallet or custom disconnectWallet handler is ready, users can also set into options, like the below example:

import { init,render, updateConnectWallet, updateDisconnectWallet updateAddressAndProvider, } from 'woofi-swap-widget'
init({
    useUserWallet: true,
    connectWallet: () => {}
    disconnectWalet: () => {}
})

onMounted(() => {
    render('#swap')
})

while address and provider is ready()

watch(address, () => {
    if (address) {
     const provider = getProvider() // HttpProvider
     updateAddressAndProvider(address, provider)
    }
})

while functionconnectWallet and functiondisconnectWallet is ready

updateConnectWallet(connectWalletHandler)

updateDisconnectWallet(disconnectWalletHandler)

Style

There are provider some css variable for customize styles

Font
 --font-family: "DIN", "Helvetica Neue", Helvetica, system-ui, Arial,sans-serif;
Text
  --swap-text-primary-color: #73bef4;
  --swap-text-main-color: #ffffff;
  --swap-text-second-color: rgba(255, 255, 255, 0.8);
  --swap-text-three-color: #a8a8a8;
Btn
  --swap-btn-bg-color: linear-gradient(270deg, #59b0fe 0%, #26fefe 100%);
  --swap-btn-text-color: #282e3a;
Background
 --swap-bg-main-color: #1b2028;
  --swap-bg-second-color: #15181d;
  --swap-bg-three-color: #212630;
  --swap-bg-four-color: #282e3a;
Width
  --swap-wrapper-width: 470px;

Demo

More detail can see the demo

0.2.44

16 days ago

0.2.43

4 months ago

0.2.42

4 months ago

0.2.27

7 months ago

0.2.26

7 months ago

0.2.25

7 months ago

0.2.24

7 months ago

0.2.23

7 months ago

0.2.22

7 months ago

0.2.21

7 months ago

0.2.19

7 months ago

0.2.18

7 months ago

0.2.17

7 months ago

0.2.16

7 months ago

0.2.15

7 months ago

0.2.14

7 months ago

0.2.13

7 months ago

0.2.12

7 months ago

0.2.11

7 months ago

0.2.10

7 months ago

0.1.2

7 months ago

0.1.4

7 months ago

0.1.3

7 months ago

0.1.5

7 months ago

0.2.41

6 months ago

0.2.40

6 months ago

0.2.39

6 months ago

0.2.30

7 months ago

0.2.38

6 months ago

0.2.37

6 months ago

0.2.36

6 months ago

0.2.35

6 months ago

0.2.34

6 months ago

0.2.33

6 months ago

0.2.32

6 months ago

0.2.31

7 months ago

0.2.1

7 months ago

0.2.0

7 months ago

0.2.29

7 months ago

0.2.28

7 months ago

0.2.7

7 months ago

0.2.6

7 months ago

0.2.9

7 months ago

0.2.8

7 months ago

0.2.3

7 months ago

0.2.2

7 months ago

0.2.5

7 months ago

0.2.4

7 months ago

0.1.1

7 months ago

0.1.0

7 months ago

0.0.5

7 months ago

0.0.4

8 months ago

0.0.3

8 months ago

0.0.2

8 months ago

0.0.1

8 months ago

0.0.0

8 months ago