npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@wert-io/widget-initializer

v6.3.0

Published

WertWidget helper

Downloads

7,944

Readme

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.

| Property | Type | Description | |---------------------|--------|----------------------------------------------------------------------------------------| | author_image_url | String | The URL of the author's avatar. Example: https://something.com/images/image.jpg | | author | String | The name of the author | | image_url | String | The URL of the NFT's image | | name | String | The name of the NFT | | category | String | The category of the NFT | | seller | String | The name of the NFT's seller | | header | String | The 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:

| Property | Type | Description | |----------|--------|-------------------------------------------------------------------------------------------------------------------------| | name | String | Example: ETH. See the list of supported currencies. | | network | String | Example: ethereum. See the list of supported currencies. | | address | String | The 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

| Method | Description | |--------------------------|-------------------------------------------| | open | Mounts module in DOM and makes it visible | | updateTheme | Switches the theme without reload | | addEventListeners | Adds event listeners | | removeEventListeners | Removes event listeners | | close | Closes 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.