Skip to content

Commit edb035e

Browse files
authored
Merge pull request #208 from Apillon/staging
Staging
2 parents 6351ddb + 859762b commit edb035e

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