Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/docs update #52

Merged
merged 5 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module.exports = {
"guides/fa2-transfer",
"guides/contract-error-handling",
"guides/subscribe-to-event",
"guides/WC-events",
"guides/standalone-delegation",
"guides/metrics",
"guides/bug-report",
Expand Down
4 changes: 4 additions & 0 deletions src/docs/getting-started/first-dapp.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@ if (!activeAccount) {
</TabItem>
</Tabs>

## Disconnect

Please refer to our dedicated [page](/guides/disconnecting-a-wallet) on how to disconnect your dApp based on your needs.

## User Interaction Best Practice

Take a look a the [best practice](/getting-started/best-practices) for recommendations on Beacon user interface components.
36 changes: 36 additions & 0 deletions src/docs/guides/WC-events.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
title: WalletConnect events
---

#### Overview

In Beacon we use [signClient](https://www.npmjs.com/package/@walletconnect/sign-client) to manage all WalletConnect's connections.

`signClient` manages the lifecycle and communication of sessions between a dApp and
a wallet.

This page outlines the various events that Beacon handles through `signClient`.

#### Session Events

1. **session_event**: Triggered by any significant occurrence within a session not explicitly covered by more specific events. It can be used for logging, debugging, or extending functionality.

In Beacon we use this event to acknowledge requests sent to a wallet.

2. **session_update**: Occurs when a session's state changes, such as updating permissions, accounts, or chain information. This is crucial for dApps to adjust their state in response to changes in the session parameters.

3. **session_expire**: Fired when a session reaches its expiry time and is no longer valid. This event is critical for managing session lifecycle and ensuring that expired sessions are refreshed or terminated as needed.

4. **session_delete**: This event is fired when a session is terminated either by the user, the dApp, or due to external factors leading to a disconnection.

# Pairing Events

1. **pairing_delete**: This event is triggered when a pairing is intentionally deleted, either by user action or programmatically by the dApp or wallet. This is used to manage the list of available pairings, ensuring that only valid or required pairings are maintained.

2. **pairing_expire**: Occurs when a pairing reaches its defined expiry time. Since pairings are typically temporary connections before establishing a full session, this event handles the automatic cleanup of these temporary states.

### References

1. [Session Events](https://specs.walletconnect.com/2.0/specs/clients/sign/session-events): This document outlines the various session events that can be handled by WalletConnect's `signClient`, providing details on each event's significance and usage.

2. [Pairing API](https://docs.walletconnect.com/api/core/pairing): A guide to understanding the pairing process within WalletConnect, explaining how dApps can establish preliminary connections with wallets before initiating a full session.
47 changes: 40 additions & 7 deletions src/docs/guides/disconnecting-a-wallet.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,49 @@
title: Disconnecting from a Wallet
---

The follwing examples show how to properly disconnect from a wallet.
This section explains all the available ways to disconnect a dApp in Beacon.

:::warning
If you are using the P2P transport, it is not recommended to manually disconnect from the transport. Doing so may interrupt the syncing process, resulting in an error message indicating "Syncing stopped manually."
:::
## Disconnect

`disconnect` will only work while connected to a wallet, otherwise appropriate errors are thrown.
It clears all transport references ensuring a clean and complete disconnection from the wallet.

### Errors

Namely there are 3 errors that `disconnect` can throw which are:

- `"Syncing stopped manually."`: This happens while disconnecting a P2P connection
- `"No transport available."`: This happens when the transport hasn't resolved yet (likely because your dApp is not connected yet to a wallet)
- `"Not connected."`: This error is thrown to prevent dApps from disconnecting multiple times.

import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";

```ts live
// beacon disconnect wallet
import { DAppClient } from "@airgap/beacon-sdk";
const dAppClient = new DAppClient({ name: "Beacon Docs" });

dAppClient
.disconnect()
.then(() => {
console.log("Disconnected.");
})
.catch((err) => console.error(err.message));
```

## ClearActiveAccount

`clearActiveAccount` manages the process of clearing the currently active account and only its associated active transport.
This method ensures that all data linked to the active account is removed, and the active transport connection is terminated.

`clearActiveAccount` gets also invoked when calling:

1. `removeAccount`: if the argument `accountIdentifier` matches the active account
2. `removeAllAccounts`: always

> Note: Only for WalletConnect, `clearActiveAccount` will also resets all transport refreneces behaving similarly to `disconnect`

<Tabs
groupId="beaconOrTaquitoDAW"
defaultValue="beacon"
Expand All @@ -19,16 +53,15 @@ import TabItem from "@theme/TabItem";
{ label: "Taquito", value: "taquito" },
]}
>
<TabItem value="beacon">
<TabItem value="beacon">

```ts live
// beacon disconnect wallet
import { DAppClient } from "@airgap/beacon-sdk";
const dAppClient = new DAppClient({ name: "Beacon Docs" });

dAppClient
.disconnect()
.then(() => {
.clearActiveAccount(() => {
const account = await dAppClient.getActiveAccount();
console.log("Active Account", account);
})
Expand Down
Loading