StakeWise Widget

The package contains a JavaScript class that renders a
widget on an HTML page that allows depositing ETH in
staking and get deposit data.
The package uses JavaScript class from StakeWise-Methods
package.
Create an instance of a class
To create widget instance you need to provide the same
options as for StakeWise-Methods instance, since it will
use that methods inside.
Required options are: ethers provider and wallet address.
import Widget from '@stakewise/widget'
const widget = new Widget({
provider,
sender,
})
You can also provide callbacks to the widget class to
track some events and handle errors.
Callbacks are optional, you can provide only some of
them or not provide them at all.
import Widget from '@stakewise/widget'
const referrer = '0x0000000000000000000000000000000000000000'
const theme = 'light'
const overlay = 'dark'
const customStyles = true
const onSuccess = (amount: BigNumber) => {
console.log(`Deposited: ${BigNumber.toString()}`)
}
const onError = ({ method, error }: { method: string, error: Error }) => {
console.error(`[${method}]: ${error.message}`)
}
const onClose = () => {
console.log('Widget has been closed')
}
const windget = new Widget({
provider,
sender,
referrer,
theme,
overlay,
onSuccess,
onError,
onClose,
})
const windget = new Widget({
provider,
sender,
referrer,
customStyles,
onSuccess,
onError,
onClose,
})
By default, widget renders in Shadow DOM, and all its styles
are encapsulated there and doesn't affect page styles.
Pay attention, with provided customStyles: true it doesn't
use Shadow DOM that allows you to write your own styles but
at the same time it will inherit all page styles if they match
widget CSS classes.
Open widget
This method will create the widget in a modal window on
the page:
windget.open()
Close widget
This method will remove the widget and its modal window
from the page:
windget.close()
If you've provided onClose callback to the widget, it
won't be called in this case, since it is called only
when the widget is closing from the inside.
For example, the callback will be called if a user
clicks on the cross button in the top right corner of
the widget modal which will cause widget closing.