6.3.0 • Published 11 days ago

@wert-io/widget-initializer v6.3.0

Weekly downloads
-
License
ISC
Repository
github
Last release
11 days ago

WertWidget initializer

@wert-io/widget-initializer is a helper that assists you with integrating the Wert widget into your web app.

Installation

npm install @wert-io/widget-initializer

Usage

import WertWidget from '@wert-io/widget-initializer';

First of all, you need to create a widget class:

const wertWidget = new WertWidget(options);

Options

General options

Smart contract options

Pre-filling user data

Appearance and restrictions

Extra object structure

The extra object is an optional object that can contain some additional data.

extra: {
  item_info: Object,
  wallets: Array,
}

Adding NFT information

You can add the following parameters to the item_info to display your NFT's name, image, the author’s avatar, the author’s name and the seller’s name in the widget.

PropertyTypeDescription
author_image_urlStringThe URL of the author's avatar. Example: https://something.com/images/image.jpg
authorStringThe name of the author
image_urlStringThe URL of the NFT's image
nameStringThe name of the NFT
categoryStringThe category of the NFT
sellerStringThe name of the NFT's seller
headerStringThe header to be shown instead of 'Buy token'

Adding default wallets

You can define the array of default wallets that will be prefilled when the user changes cryptocurrency. Non-valid addresses will be ignored.

The wallet object structure:

PropertyTypeDescription
nameStringExample: ETH. See the list of supported currencies.
networkStringExample: ethereum. See the list of supported currencies.
addressStringThe wallet address. Non-valid addresses will be ignored.

Listeners

Initial event listeners

Simply include the listeners object in the following format, where the key is the event type and the value is your callback.

const widget = new WertWidget({
  ...options,
  listeners: {
    position: data => console.log('step:', data.step),
  },
});

Events

{
  name: String
  message: String
}
{ 
  status: String
  payment_id: String 
  order_id: String
  tx_id: String // if available
}
{
  step: String
}
{ 
  ticker: String, 
  fee_percent: String,
  currency_amount: String,
  fee_amount: String,
  commodity_amount: String,
  purchase_amount: String,
  miner_fee: String,
  currency_miner_fee: String
}

Widget class methods

MethodDescription
openMounts module in DOM and makes it visible
updateThemeSwitches the theme without reload
addEventListenersAdds event listeners
removeEventListenersRemoves event listeners
closeCloses the widget

Showing the module

After creating an instance of the widget class, you can call the open method to show the module to the user:

wertWidget.open();

Closing the module

You can call the close method to close and remove the widget modal at any time:

wertWidget.close();

Switching themes without reload

To switch to another theme without reloading the whole widget you can use the updateTheme method:

wertWidget.updateTheme({
  theme: 'dark', // undefined — for the default light theme 
  colors: {
    // supported colors listed in options table above 
    color_buttons: 'red',
  },
});

Please note that this method should be called only after the widget is fully loaded.

Adding event listeners

If you want to listen to the widget events, you can use the addEventListeners method. Pass an object of listeners to add listeners, potentially rewriting the existing listeners of the same type:

wertWidget.addEventListeners({
  position: data => console.log('step:', data.step),
});

Removing event listeners

If you want to stop listening to the widget events, you can use the removeEventListeners method. Pass an event type, array of the event types or nothing to remove a listener, multiple listeners or all listeners:

wertWidget.removeEventListeners('rate-update');

or

wertWidget.removeEventListeners([ 'rate-update', 'payment-status' ]);

or

wertWidget.removeEventListeners();

Additional notes

Additional information about the library usage

Boolean usage

Please note that any value passed to the property with the boolean type will be considered true. Example: is_crypto_hidden: "test" will be equal to is_crypto_hidden: true.

6.3.0

11 days ago

6.3.0-beta.0

14 days ago

6.2.0

30 days ago

6.1.1

1 month ago

6.2.0-beta.0

1 month ago

6.1.1-beta.0

2 months ago

6.1.0

2 months ago

6.1.0-beta.1

2 months ago

6.1.0-beta.0

2 months ago

6.0.0

2 months ago

6.0.0-beta.0

3 months ago

5.2.0

4 months ago

5.2.0-beta.1

4 months ago

5.2.0-beta.0

4 months ago

5.1.0

5 months ago

5.1.0-beta.0

5 months ago

5.0.0-beta.1

5 months ago

5.0.0

5 months ago

5.0.0-beta.0

5 months ago

4.0.1

6 months ago

4.0.2

6 months ago

4.0.1-beta.0

6 months ago

3.1.0

1 year ago

4.0.0-beta.4

1 year ago

4.0.0-beta.3

1 year ago

4.0.0-beta.2

1 year ago

4.0.0-beta.1

1 year ago

3.0.0

1 year ago

4.0.0

12 months ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.2.2-beta.7

2 years ago

1.0.0

2 years ago

1.2.2-beta.6

2 years ago

1.2.2-beta.5

2 years ago

1.2.2-beta.4

2 years ago

1.2.2-beta.3

2 years ago

1.2.2-beta.2

2 years ago

2.0.4-beta.1

1 year ago

1.2.2-beta.1

2 years ago

2.0.4-beta.2

1 year ago

2.0.4-beta.0

1 year ago

1.2.1

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

1.2.0-beta.1

2 years ago

1.2.0-beta.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.0-beta.2

2 years ago

1.0.1-beta.1

2 years ago

1.0.0-beta.1

2 years ago

1.1.0-beta.1

2 years ago

0.3.0

2 years ago

0.3.0-beta.0

2 years ago

0.2.1

2 years ago

0.3.0-beta.1

2 years ago

0.2.0

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago