Skip to content

Commit 859762b

Browse files
authored
Merge pull request #207 from sh3nk/staging
EW events
2 parents d66ada4 + 176c99c commit 859762b

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

build/12-embedded-wallets-integration.md

+67
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,73 @@ document
594594
</CodeGroupItem>
595595
</CodeGroup>
596596
597+
## SDK events
598+
599+
The SDK uses an event bus for async communication with embedded wallet's UI and for programmatic interface.
600+
The events are exposed on the `events` property of the SDK instance.
601+
These events can be used to make your app more reactive and to offer embedded wallet functionality through your own UI.
602+
603+
Events are implemented with [Mitt](https://github.com/developit/mitt), the API is basically 3 methods: `on`, `emit` and `off`.
604+
605+
### UI events
606+
607+
- `dataUpdated`
608+
Emitted after state data changes, e.g. for keeping track of active account
609+
610+
- `open`
611+
Emit to open or close Embedded wallet UI
612+
613+
- `addToken`
614+
Emit to programmatically add an ERC20 token
615+
616+
```js
617+
wallet.events.emit("addToken", {
618+
address: "0x...",
619+
symbol: "USDC",
620+
decimals: 6,
621+
name: "USD Coin",
622+
});
623+
```
624+
625+
- `addTokenNft`
626+
Emit to programmatically add an NFT token
627+
628+
```js
629+
wallet.events.emit("addTokenNft", {
630+
address: "0x...",
631+
tokenId: 8,
632+
});
633+
```
634+
635+
- `addTokenStatus`
636+
Emitted when `addToken` or `addTokenNft` resolves.
637+
638+
```js
639+
wallet.events.on(
640+
"addTokenStatus",
641+
({ success, info, token, nft }: Events["addTokenStatus"]) => {
642+
console.log(success ? "Success" : "Error", info, token, nft);
643+
}
644+
);
645+
```
646+
647+
### Transaction events
648+
649+
- `signatureRequest`
650+
e.g. display UI with message and approve/decline buttons
651+
652+
- `txApprove`
653+
e.g. display UI with transaction details and approve/decline buttons
654+
655+
- `txSubmitted`
656+
e.g. log the transaction in session storage or own backend
657+
658+
- `txDone`
659+
Emitted by UI after a submitted tx is consisdered done (ethereum provider listener)
660+
661+
- `requestChainChange`
662+
Emitted when tx chainId is different from defaultNetworkId. Must be resolve()'d to continue with the tx execution.
663+
597664
## Create custom UI
598665
599666
All the functionalities of embedded wallets are contained in base package `@apillon/wallet-sdk`. The SDK exposes all the core methods of the wallet and you can create a completely custom UI of the wallet on top of it.

0 commit comments

Comments
 (0)