|
1 | 1 | # @bitte-ai/react
|
2 | 2 |
|
3 |
| -This package contains React helpers for interacting with Bitte Wallet. |
| 3 | +This package contains React helpers for interacting with Bitte Wallet and other NEAR wallets. |
4 | 4 |
|
5 | 5 | <p align="center">
|
6 | 6 |
|
7 | 7 | <img src='https://img.shields.io/npm/dw/@bitte-ai/react' />
|
8 | 8 |
|
9 | 9 | </p>
|
10 | 10 |
|
11 |
| - |
12 | 11 | ## Summary
|
13 | 12 |
|
14 |
| -- [Installing](#Installing) |
15 |
| - |
16 |
| -- [BitteWalletContextProvider (default)](#bittewalletcontextprovider) : The default Bitte Wallet provider |
17 |
| - |
| 13 | +- [Installing](#installing) |
| 14 | +- [Wallet Selection](#wallet-selection) |
| 15 | +- [BitteWalletContextProvider](#bittewalletcontextprovider) |
| 16 | +- [Available Wallets](#available-wallets) |
| 17 | +- [Usage Examples](#usage-examples) |
| 18 | +- [Legacy API](#legacy-api) |
| 19 | +- [Troubleshooting](#troubleshooting) |
18 | 20 |
|
19 | 21 | # Installing
|
20 | 22 |
|
21 | 23 | ### NPM:
|
22 | 24 |
|
23 |
| -``` |
| 25 | +```bash |
24 | 26 | npm install @bitte-ai/react
|
25 | 27 | npm install @near-wallet-selector/modal-ui
|
26 | 28 | ```
|
27 | 29 |
|
28 | 30 | ### Yarn:
|
29 | 31 |
|
30 |
| -``` |
| 32 | +```bash |
31 | 33 | yarn add @bitte-ai/react
|
32 | 34 | yarn add @near-wallet-selector/modal-ui
|
33 | 35 | ```
|
34 | 36 |
|
35 | 37 | ### PNPM:
|
36 | 38 |
|
37 |
| -``` |
| 39 | +```bash |
38 | 40 | pnpm install @bitte-ai/react
|
39 | 41 | pnpm install @near-wallet-selector/modal-ui
|
40 | 42 | ```
|
41 | 43 |
|
| 44 | +# Wallet Selection |
| 45 | + |
| 46 | +You can now easily choose which wallets to display by using the `enabledWallets` prop. This gives developers full control over the wallet selection experience. |
| 47 | + |
| 48 | +## Available Wallets |
| 49 | + |
| 50 | +The following wallets are supported: |
| 51 | + |
| 52 | +- `"intear"` - Intear Wallet |
| 53 | +- `"hot"` - Here Wallet (formerly HOT Wallet) |
| 54 | +- `"okx"` - OKX Wallet |
| 55 | +- `"bitte"` - Bitte Wallet |
| 56 | +- `"meteor"` - Meteor Wallet |
| 57 | +- `"mynear"` - MyNEAR Wallet |
| 58 | + |
42 | 59 | # BitteWalletContextProvider
|
43 | 60 |
|
44 |
| -the default way of interacting with Bitte Wallet is using the BitteWalletContextProvider |
| 61 | +The default way of interacting with Bitte Wallet is using the BitteWalletContextProvider. |
| 62 | + |
| 63 | +## Properties: |
| 64 | + |
| 65 | +**network**: `"mainnet" | "testnet"` - The NEAR network to connect to |
| 66 | + |
| 67 | +**enabledWallets**: `WalletName[]` - Array of wallet names to display (recommended) |
| 68 | + |
| 69 | +**additionalWallets**: `WalletModuleFactory[]` - Extra wallets setup |
| 70 | + |
| 71 | +**contractAddress**: `string` - Contract address for wallet connection |
45 | 72 |
|
| 73 | +**onlyBitteWallet**: `boolean` - Legacy prop to show only Bitte Wallet |
46 | 74 |
|
47 |
| -## properties: |
| 75 | +**walletUrl**: `string` - Custom Bitte Wallet URL |
48 | 76 |
|
49 |
| -**network** : ` mainnet | testnet` |
| 77 | +# Usage Examples |
50 | 78 |
|
51 |
| -**additionalWallets** : `WalletModuleFactory[] extra wallets setup` |
| 79 | +## Basic Wallet Selection (Recommended) |
52 | 80 |
|
53 | 81 | ```typescript
|
54 | 82 | import "@near-wallet-selector/modal-ui/styles.css";
|
55 |
| -import { BitteWalletContextProvider } from '@bitte-ai/react' |
| 83 | +import { BitteWalletContextProvider, useBitteWallet, WalletName } from '@bitte-ai/react'; |
| 84 | + |
| 85 | +// Select only the wallets you want to show |
| 86 | +const enabledWallets: WalletName[] = ['intear', 'hot', 'okx', 'bitte']; |
| 87 | + |
| 88 | +function MyApp() { |
| 89 | + return ( |
| 90 | + <BitteWalletContextProvider |
| 91 | + network="mainnet" |
| 92 | + enabledWallets={enabledWallets} |
| 93 | + contractAddress="your-contract.near" |
| 94 | + > |
| 95 | + <WalletConnector /> |
| 96 | + </BitteWalletContextProvider> |
| 97 | + ); |
| 98 | +} |
| 99 | + |
| 100 | +function WalletConnector() { |
| 101 | + const { connect, disconnect, isConnected, accounts } = useBitteWallet(); |
| 102 | + |
| 103 | + return ( |
| 104 | + <div> |
| 105 | + {!isConnected ? ( |
| 106 | + <button onClick={connect}>Connect Wallet</button> |
| 107 | + ) : ( |
| 108 | + <div> |
| 109 | + <p>Connected: {accounts[0]?.accountId}</p> |
| 110 | + <button onClick={disconnect}>Disconnect</button> |
| 111 | + </div> |
| 112 | + )} |
| 113 | + </div> |
| 114 | + ); |
| 115 | +} |
| 116 | +``` |
| 117 | + |
| 118 | +## All Available Wallets |
| 119 | + |
| 120 | +```typescript |
| 121 | +const allWallets: WalletName[] = ['intear', 'hot', 'okx', 'bitte', 'meteor', 'mynear']; |
| 122 | + |
| 123 | +<BitteWalletContextProvider |
| 124 | + network="mainnet" |
| 125 | + enabledWallets={allWallets} |
| 126 | + contractAddress="your-contract.near" |
| 127 | +> |
| 128 | + <App /> |
| 129 | +</BitteWalletContextProvider> |
| 130 | +``` |
| 131 | + |
| 132 | +## Only Specific Wallets |
| 133 | + |
| 134 | +```typescript |
| 135 | +// Only show Bitte and Intear wallets |
| 136 | +const selectedWallets: WalletName[] = ['bitte', 'intear']; |
| 137 | + |
| 138 | +<BitteWalletContextProvider |
| 139 | + network="testnet" |
| 140 | + enabledWallets={selectedWallets} |
| 141 | + contractAddress="your-contract.testnet" |
| 142 | +> |
| 143 | + <App /> |
| 144 | +</BitteWalletContextProvider> |
| 145 | +``` |
| 146 | + |
| 147 | +## Combining with Additional Wallets |
| 148 | + |
| 149 | +```typescript |
| 150 | +import { setupCustomWallet } from 'custom-wallet'; |
| 151 | + |
| 152 | +const myWallets: WalletName[] = ['bitte', 'intear', 'meteor']; |
56 | 153 |
|
57 | 154 | <BitteWalletContextProvider
|
58 | 155 | network="mainnet"
|
| 156 | + enabledWallets={myWallets} |
| 157 | + additionalWallets={[setupCustomWallet()]} |
| 158 | + contractAddress="your-contract.near" |
| 159 | +> |
| 160 | + <App /> |
| 161 | +</BitteWalletContextProvider> |
| 162 | +``` |
| 163 | + |
| 164 | +## TypeScript Support |
| 165 | + |
| 166 | +The `WalletName` type ensures you only use supported wallet names: |
| 167 | + |
| 168 | +```typescript |
| 169 | +import { WalletName } from '@bitte-ai/react'; |
| 170 | +
|
| 171 | +// ✅ This works |
| 172 | +const validWallets: WalletName[] = ['intear', 'bitte', 'meteor']; |
| 173 | +
|
| 174 | +// ❌ TypeScript error - 'invalid' is not a valid wallet name |
| 175 | +const invalidWallets: WalletName[] = ['intear', 'invalid']; |
| 176 | +``` |
| 177 | + |
| 178 | +# Legacy API |
| 179 | + |
| 180 | +The previous API is still supported for backwards compatibility: |
| 181 | + |
| 182 | +## Using onlyBitteWallet |
| 183 | + |
| 184 | +```typescript |
| 185 | +<BitteWalletContextProvider |
| 186 | + network="mainnet" |
| 187 | + onlyBitteWallet={true} |
| 188 | + contractAddress="your-contract.near" |
59 | 189 | >
|
60 |
| - <Component {...pageProps} /> |
| 190 | + <App /> |
61 | 191 | </BitteWalletContextProvider>
|
| 192 | +``` |
| 193 | + |
| 194 | +## Using additionalWallets Only |
62 | 195 |
|
| 196 | +```typescript |
| 197 | +import { setupSomeCustomWallet } from 'some-custom-wallet'; |
| 198 | +
|
| 199 | +<BitteWalletContextProvider |
| 200 | + network="mainnet" |
| 201 | + additionalWallets={[setupSomeCustomWallet()]} |
| 202 | + contractAddress="your-contract.near" |
| 203 | +> |
| 204 | + <App /> |
| 205 | +</BitteWalletContextProvider> |
63 | 206 | ```
|
64 | 207 |
|
| 208 | +## Important Notes |
| 209 | + |
| 210 | +- If you don't specify `enabledWallets`, the default wallets (`meteor`, `mynear`, `hot`) plus `bitte` will be used |
| 211 | +- If you specify an empty `enabledWallets` array, no wallets will be shown |
| 212 | +- The `enabledWallets` option takes precedence over `onlyBitteWallet` when both are provided |
| 213 | +- Additional wallets from `additionalWallets` will always be included regardless of the `enabledWallets` setting |
| 214 | + |
65 | 215 | # Troubleshooting
|
66 | 216 | The wallet runs only on client-side.
|
67 | 217 |
|
|
0 commit comments