2.1.1 • Published 15 days ago

@wert-io/module-react-component v2.1.1

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

Wert Module React component

This is the wrapped Wert widget-initializer helper for React projects.

Installation

yarn add @wert-io/module-react-component

or

npm install @wert-io/module-react-component

Usage example

import { useState } from 'React';
import { useWertWidget } from '@wert-io/module-react-component';
import type { GeneralOptions, ReactiveOptions } from '@wert-io/module-react-component';

export default function WertWidgetButton () {
    const options: GeneralOptions = {
        partner_id: 'YOUR_PARTNER_ID',
        // ...
    };
    const [reactiveOptions, setReactiveOptions] = useState<ReactiveOptions>({
        theme: 'dark',
        listeners: {
            'loaded': () => console.log(loaded),
        },
    });

    const { open: openWertWidget, isWidgetOpen } = useWertWidget(reactiveOptions);

    return <button
        onClick={() => {
            openWertWidget({ options });
            console.log(isWidgetOpen);
        }}
    >
        Make A Purchase
    </button>
}

Options

The useWertWidget function expects a single optional argument - an object with reactive options (listeners and theme-related parameters).

You should pass all static options (including optional smart contract related ones) to the open method. The open method expects an object of the following type:

interface StaticOptions {
  options: GeneralOptions;
  smartContractOptions?: SmartContractOptions;
}

You can find the full list of the options that can be passed to the widget here.

Adding smart contract options

We've added @wert-io/widget-sc-signer to simplify the data signing process for executing smart contracts. Just pass the smartContractOptions object to the open function with the following options:

Field NameData TypeRequired
addressstringrequired
commoditystringrequired
commodity_amountnumberrequired
networkstringrequired
sc_addressstringrequired
sc_input_datastringrequired
private_keystringrequired
import { useWertWidget } from '@wert-io/module-react-component';
import type { GeneralOptions, SmartContractOptions } from '@wert-io/module-react-component';

// ...

const options: GeneralOptions = {
    partner_id: 'YOUR_PARTNER_ID',
};
const smartContractOptions: SmartContractOptions = {
    address: 'FALLBACK_ADDRESS',
    commodity: 'ETH',
    network: 'goerli',
    commodity_amount: 0.005,
    sc_address: 'SMART_CONTRACT_ADDRESS',
    sc_input_data: 'SMART_CONTRACT_EXECUTION_DATA',
    private_key: 'YOUR_PRIVATE_KEY', // We advise you not to store the private key on the frontend
}
const { open } = useWertWidget();

const openWidget = () => open({ options, smartContractOptions });

You can find more information on how the signer works and its' options here.

2.1.1

15 days ago

2.1.1-beta.0

1 month ago

2.1.0

2 months ago

2.1.0-beta.0

2 months ago

2.0.1

2 months ago

2.0.1-beta.0

2 months ago

2.0.0-beta.2

4 months ago

2.0.0-beta.1

4 months ago

2.0.0

4 months ago

2.0.0-beta.0

4 months ago

1.0.0

1 year ago

1.0.0-beta.0

1 year ago

1.0.0-beta.1

1 year ago

0.2.0

2 years ago

0.1.0

2 years ago