-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(gitbook): integrate GitBook documentation (#285)
* docs(gitbook): add .gitbook.yaml configuration file * docs(gitbook): Update Supported Wallets * chore(config): ignore docs folder in Prettier and ESLint
- Loading branch information
Showing
25 changed files
with
1,536 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ node_modules | |
dist | ||
.env | ||
*.code-workspace | ||
docs/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
root: ./docs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
**/.output | ||
pnpm-lock.yaml | ||
*.code-workspace | ||
docs/** |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
description: A framework agnostic wallet integration library for Algorand dApps | ||
--- | ||
|
||
# 👋 Welcome to use-wallet! | ||
|
||
## Overview | ||
|
||
Use-wallet is a comprehensive wallet management solution for Algorand/AVM dApps. It reduces the complexity of wallet integrations, letting developers focus on core application logic. | ||
|
||
Version 3.x is a framework-agnostic rewrite that can be used in any modern frontend stack. The library currently ships with adapters for React, Vue, and Solid.js.  | ||
|
||
{% embed url="https://github.com/TxnLab/use-wallet" %} | ||
[https://github.com/TxnLab/use-wallet](https://github.com/TxnLab/use-wallet) | ||
{% endembed %} | ||
|
||
## Get Started | ||
|
||
We've put together some helpful guides for you to get setup quickly and easily. | ||
|
||
{% content-ref url="fundamentals/get-started/" %} | ||
[get-started](fundamentals/get-started/) | ||
{% endcontent-ref %} | ||
|
||
{% content-ref url="fundamentals/get-started/configuration.md" %} | ||
[configuration.md](fundamentals/get-started/configuration.md) | ||
{% endcontent-ref %} | ||
|
||
{% content-ref url="fundamentals/get-started/start-building.md" %} | ||
[start-building.md](fundamentals/get-started/start-building.md) | ||
{% endcontent-ref %} | ||
|
||
{% content-ref url="guides/migrating-from-v2.x.md" %} | ||
[migrating-from-v2.x.md](guides/migrating-from-v2.x.md) | ||
{% endcontent-ref %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Table of contents | ||
|
||
* [👋 Welcome to use-wallet!](README.md) | ||
|
||
## Overview | ||
|
||
* [✨ Features](overview/features.md) | ||
* [💡 Motivation for v3.x](overview/motivation-for-v3.x.md) | ||
|
||
## Fundamentals | ||
|
||
* [🛠️ Get Started](fundamentals/get-started/README.md) | ||
* [⚙️ Configuration](fundamentals/get-started/configuration.md) | ||
* [👩🔧 Start Building](fundamentals/get-started/start-building.md) | ||
* [☑️ Supported Wallets](fundamentals/supported-wallets.md) | ||
* [🧪 Custom Provider](fundamentals/custom-provider.md) | ||
* [🗃️ WalletManager API](fundamentals/walletmanager-api.md) | ||
* [📂 BaseWallet API](fundamentals/basewallet-api.md) | ||
|
||
## Guides | ||
|
||
* [⚡ React Quick Start](guides/react-quick-start.md) | ||
* [⚡ Vue Quick Start](guides/vue-quick-start.md) | ||
* [⚡ Solid.js Quick Start](guides/solid.js-quick-start.md) | ||
* [🚣 Migrating from v2.x](guides/migrating-from-v2.x.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
--- | ||
description: Public methods and properties of the BaseWallet abstract class | ||
--- | ||
|
||
# 📂 BaseWallet API | ||
|
||
The `BaseWallet` class is an abstract class that defines the interface for wallet implementations. Wallet providers all extend this class and implement its required methods. | ||
|
||
```typescript | ||
abstract class BaseWallet { | ||
constructor({ | ||
id, | ||
metadata, | ||
store, | ||
subscribe, | ||
getAlgodClient | ||
}: WalletConstructor<WalletId>) | ||
} | ||
``` | ||
|
||
*** | ||
|
||
## Public Methods | ||
|
||
### connect | ||
|
||
```typescript | ||
connect(): Promise<WalletAccount[]> | ||
``` | ||
|
||
Connects the wallet to the dApp. | ||
|
||
### disconnect | ||
|
||
```typescript | ||
disconnect(): Promise<void> | ||
``` | ||
|
||
Disconnects the wallet from the dApp. | ||
|
||
### resumeSession | ||
|
||
```typescript | ||
resumeSession(): Promise<void> | ||
``` | ||
|
||
Re-initializes the connected wallet from persisted storage when the application mounts. | ||
|
||
### setActive | ||
|
||
```typescript | ||
setActive(): void | ||
``` | ||
|
||
Sets the wallet as the active wallet. | ||
|
||
### setActiveAccount | ||
|
||
```typescript | ||
setActiveAccount(account: string): void | ||
``` | ||
|
||
Sets the active account. | ||
|
||
* `account`: The account address to be set as active. | ||
|
||
### signTransactions | ||
|
||
```typescript | ||
signTransactions<T extends algosdk.Transaction[] | Uint8Array[]>( | ||
txnGroup: T | T[], | ||
indexesToSign?: number[] | ||
): Promise<(Uint8Array | null)[]> | ||
``` | ||
|
||
Signs transactions of an atomic transaction group with this wallet provider. Transactions can be signed by any connected account in the wallet. | ||
|
||
* `txnGroup`: An atomic transaction group of either `algosdk.Transaction` objects or their serialized bytes, or an array of atomic transaction groups. | ||
* `indexesToSign`: An optional array of indexes in the atomic transaction group that should be signed. | ||
|
||
### transactionSigner | ||
|
||
```typescript | ||
transactionSigner( | ||
txnGroup: algosdk.Transaction[], | ||
indexesToSign: number[] | ||
): Promise<Uint8Array[]> | ||
``` | ||
|
||
A typed [`TransactionSigner`](https://github.com/algorand/js-algorand-sdk/blob/v2.8.0/src/signer.ts#L7-L18) function that signs transactions of an atomic transaction group with this wallet provider. It can be used with `AtomicTransactionComposer` - see [https://developer.algorand.org/docs/get-details/atc/](https://developer.algorand.org/docs/get-details/atc/) | ||
|
||
* `txnGroup`: An atomic transaction group of `algosdk.Transaction` objects. | ||
* `indexesToSign`: An array of indexes in the atomic transaction group that should be signed. | ||
|
||
### subscribe | ||
|
||
```typescript | ||
subscribe(callback: (state: State) => void): (() => void) | ||
``` | ||
|
||
Subscribes to state changes. | ||
|
||
* `callback`: The function to be executed when state changes. | ||
|
||
*** | ||
|
||
## Public Properties | ||
|
||
### id | ||
|
||
```typescript | ||
id: WalletId | ||
``` | ||
|
||
The wallet's ID. | ||
|
||
### metadata | ||
|
||
```typescript | ||
metadata: WalletMetadata | ||
``` | ||
|
||
The wallet's metadata. An object containing the wallet's display `name` and `icon` expressed as a base64 data URI. | ||
|
||
### name | ||
|
||
```typescript | ||
name: string | ||
``` | ||
|
||
The wallet's name (in uppercase). | ||
|
||
### accounts | ||
|
||
```typescript | ||
accounts: WalletAccount[] | ||
``` | ||
|
||
The wallet's connected accounts. | ||
|
||
### addresses | ||
|
||
```typescript | ||
addresses: string[] | ||
``` | ||
|
||
The wallet's connected account addresses. | ||
|
||
### activeAccount | ||
|
||
```typescript | ||
activeAccount: WalletAccount | null | ||
``` | ||
|
||
The currently active account. | ||
|
||
### activeAddress | ||
|
||
```typescript | ||
activeAddress: string | null | ||
``` | ||
|
||
The currently active account's address. | ||
|
||
### activeNetwork | ||
|
||
```typescript | ||
activeNetwork: NetworkId | ||
``` | ||
|
||
The currently active network. | ||
|
||
### isConnected | ||
|
||
```typescript | ||
isConnected: boolean | ||
``` | ||
|
||
Whether the wallet provider is connected. | ||
|
||
### isActive | ||
|
||
```typescript | ||
isActive: boolean | ||
``` | ||
|
||
Whether the wallet provider is active. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
--- | ||
description: Detailed guide for creating and implementing a custom provider | ||
--- | ||
|
||
# 🧪 Custom Provider | ||
|
||
While `@txnlab/use-wallet` supports a wide range of Algorand wallets, you may need to integrate a wallet that isn't included in the library or implement additional custom interactions. The Custom Provider feature allows you to do just that. | ||
|
||
## Creating a Custom Provider | ||
|
||
To create a custom provider, follow these steps: | ||
|
||
1. Create a new class that implements the `CustomProvider` type. | ||
2. Add the provider to the `WalletManager` configuration. | ||
|
||
### Step 1: Implement CustomProvider | ||
|
||
Create a new class that implements the `CustomProvider` type. This class should include methods for connecting, disconnecting, and signing transactions. | ||
|
||
```typescript | ||
import { CustomProvider, WalletAccount } from '@txnlab/use-wallet' // Or any framework adapter | ||
class ExampleProvider implements CustomProvider { | ||
/* Required */ | ||
async connect(args?: Record<string, any>): Promise<WalletAccount[]> { | ||
// Must return an array of connected accounts | ||
// Optional `args` parameter can be used to pass any additional configuration | ||
} | ||
|
||
/* Optional */ | ||
async disconnect(): Promise<void> { | ||
// Disconnect from the wallet provider, if necessary | ||
} | ||
|
||
/* Optional */ | ||
async resumeSession(): Promise<WalletAccount[] | void> { | ||
// Reconnect to the wallet provider when the app mounts, if necessary | ||
// If an array of accounts is returned, they are checked against the stored accounts | ||
// The stored accounts are updated if they differ | ||
} | ||
|
||
/* The two signing methods are optional, but you'll want to define at least one! */ | ||
|
||
async signTransactions<T extends algosdk.Transaction[] | Uint8Array[]>( | ||
txnGroup: T | T[], | ||
indexesToSign?: number[] | ||
): Promise<(Uint8Array | null)[]> { | ||
// Sign transactions with the wallet | ||
// Return array matching length of `txnGroup` with signed transactions or null if unsigned | ||
} | ||
|
||
async transactionSigner( | ||
txnGroup: algosdk.Transaction[], | ||
indexesToSign: number[] | ||
): Promise<Uint8Array[]> { | ||
// Sign an array of transaction objects with the wallet | ||
// Return signed transactions only | ||
// Compatible with algosdk's Atomic Transaction Composer | ||
} | ||
} | ||
``` | ||
|
||
### Step 2: Add to WalletManager Configuration | ||
|
||
Once you've created your custom provider, add it to the `WalletManager` configuration: | ||
|
||
```typescript | ||
const walletManager = new WalletManager({ | ||
wallets: [ | ||
// Include the custom provider in the wallets array | ||
{ | ||
id: WalletId.CUSTOM, | ||
options: { | ||
provider: new ExampleProvider() | ||
}, | ||
metadata: { | ||
name: 'Example Wallet', | ||
icon: 'data:image/svg+xml;base64,...' | ||
} | ||
} | ||
], | ||
network: NetworkId.TESTNET | ||
}) | ||
``` | ||
|
||
## Key Considerations | ||
|
||
* The `connect` method is required and must return an array of connected accounts. | ||
* While `disconnect` and `resumeSession` are optional, implementing them can improve the user experience. | ||
* At least one of the signing methods (`signTransactions` or `transactionSigner`) should be implemented to enable transaction signing. | ||
* The `transactionSigner` method is compatible with algosdk's Atomic Transaction Composer, which is the recommended way to handle transactions. | ||
|
||
By following these steps, you can create and integrate a custom wallet provider into your application using `@txnlab/use-wallet`. This flexibility allows you to support unique wallet implementations or add custom functionality tailored to your specific needs. |
Oops, something went wrong.