TrustwareWidget manages its own open/closed state. When your app needs to trigger the deposit flow from elsewhere (a button in a nav bar, a checkout step, a game event), you can take control of that state using a ref.
When to use this pattern
Choose this pattern when:- your app needs to open or close the deposit flow from outside the widget
- you want to set the initial step the user lands on
- you need lifecycle callbacks for when the widget opens or closes
Setup
1
Import the ref type
2
Create the ref
3
Pass the ref and configure the widget
Widget props
Using the ref
TrustwareWidgetRef exposes three methods:
The
?. optional chaining guard is important: ref.current is null until the widget mounts. Using widgetRef.current?.open() prevents a runtime error if the button is clicked before the widget renders.Starting on a specific step
UseinitialStep to land the user at a particular point in the flow rather than the home screen. This is useful when you already know the context: for example, if the user has already selected a token elsewhere in your UI.
