@aptos-labs/wallet-adapter-react 4.0.0 → 4.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +117 -94
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- > **_NOTE:_** This documentation is for Wallet Adapter `v2.0.0` and up that is fully compatible with the Aptos TypeScript SDK V2. For Wallet Adapter `v^1.*.*` refer to [this guide](./READMEV1.md)
1
+ > **_NOTE:_** This documentation is for Wallet Adapter React `v4.0.0` and up that is fully compatible with the Aptos TypeScript SDK V2. For Wallet Adapter React `v^3.*.*` refer to [this guide](./READMEV2.md)
2
2
 
3
3
  # Wallet Adapter React Provider
4
4
 
@@ -8,26 +8,26 @@ Dapps that want to use the adapter should install this package and other support
8
8
 
9
9
  ### Support
10
10
 
11
- The react provider supports all [wallet standard](https://aptos.dev/integration/wallet-adapter-for-wallets#aip-62-wallet-standard) functions and feature functions
11
+ The React provider follows the [wallet standard](https://github.com/aptos-labs/wallet-standard/tree/main) and supports the following required functions
12
12
 
13
- ##### Standard functions
13
+ ##### [Standard required functions](https://github.com/aptos-labs/wallet-standard/blob/main/src/detect.ts#L16)
14
14
 
15
15
  ```
16
+ account
16
17
  connect
17
18
  disconnect
18
- connected
19
- account
20
19
  network
21
- signAndSubmitTransaction
20
+ onAccountChange
21
+ onNetworkChange
22
22
  signMessage
23
+ signTransaction
23
24
  ```
24
25
 
25
- ##### Feature functions - functions that may not be supported by all wallets
26
+ ##### Additional functions
26
27
 
27
28
  ```
28
- signTransaction
29
+ signAndSubmitTransaction
29
30
  signMessageAndVerify
30
- signAndSubmitBCSTransaction
31
31
  submitTransaction
32
32
  ```
33
33
 
@@ -40,42 +40,32 @@ To do that, you can look at our [supported wallets list](https://github.com/apto
40
40
 
41
41
  Next, install the `@aptos-labs/wallet-adapter-react`
42
42
 
43
- ```
43
+ ```cli
44
44
  pnpm i @aptos-labs/wallet-adapter-react
45
45
  ```
46
46
 
47
47
  using npm
48
48
 
49
- ```
49
+ ```cli
50
50
  npm i @aptos-labs/wallet-adapter-react
51
51
  ```
52
52
 
53
53
  #### Import dependencies
54
54
 
55
- On the `App.jsx` file,
56
-
57
- Import the installed wallets.
58
-
59
- ```js
60
- import { SomeAptosWallet } from "some-aptos-wallet-package";
61
- ```
62
-
63
55
  Import the `AptosWalletAdapterProvider`.
64
56
 
65
- ```js
57
+ ```tsx
66
58
  import { AptosWalletAdapterProvider } from "@aptos-labs/wallet-adapter-react";
67
59
  ```
68
60
 
69
61
  Wrap your app with the Provider, pass it the relevant props.
70
62
 
71
- ```js
72
- const wallets = [new AptosLegacyStandardWallet()];
63
+ ```tsx
64
+ import { Network } from "@aptos-labs/ts-sdk";
73
65
 
74
66
  <AptosWalletAdapterProvider
75
- plugins={wallets}
76
67
  autoConnect={true}
77
- optInWallets={["Petra"]}
78
- dappConfig={{ network: network.MAINNET, aptosApiKey: "my-generated-api-key" }}
68
+ dappConfig={{ network: Network.MAINNET, aptosApiKey: "my-generated-api-key" }}
79
69
  onError={(error) => {
80
70
  console.log("error", error);
81
71
  }}
@@ -86,66 +76,99 @@ const wallets = [new AptosLegacyStandardWallet()];
86
76
 
87
77
  #### Available Provider Props
88
78
 
79
+ - `autoConnect` - a prop indicates whether the dapp should auto connect with a previous connected wallet.
89
80
  - `dappConfig` - Config used to initialize the dapp with.
90
81
  - `network` - the network the dapp works with
91
82
  - `aptosApiKey` - an api key generated from https://developers.aptoslabs.com/docs/api-access
92
83
  - `onError` - a callback function to fire when the adapter throws an error
93
- - `plugins` - any legacy standard wallet, i.e a wallet that is not AIP-62 standard compatible, should be installed and passed in this array. [Check here](../../README.md#supported-wallet-packages) for a list of AIP-62 and legacy standard wallets.
94
- - `autoConnect` - a prop indicates whether the dapp should auto connect with a previous connected wallet.
95
84
  - `optInWallets` - the adapter detects and adds AIP-62 standard wallets by default, sometimes you might want to opt-in with specific wallets. This props lets you define the AIP-62 standard wallets you want to support in your dapp.
85
+
86
+ ```tsx
87
+ <AptosWalletAdapterProvider
88
+ ...
89
+ optInWallets={["Petra"]}
90
+ ...
91
+ >
92
+ <App />
93
+ </AptosWalletAdapterProvider>
94
+ ```
95
+
96
96
  - `disableTelemetry` - A boolean flag to disable the adapter telemetry tool, false by default
97
97
 
98
+ ```tsx
99
+ <AptosWalletAdapterProvider
100
+ ...
101
+ disableTelemetry={true}
102
+ ...
103
+ >
104
+ <App />
105
+ </AptosWalletAdapterProvider>
106
+ ```
107
+
98
108
  #### Use Wallet
99
109
 
100
110
  On any page you want to use the wallet props, import `useWallet` from `@aptos-labs/wallet-adapter-react`
101
111
 
102
- ```js
112
+ ```tsx
103
113
  import { useWallet } from "@aptos-labs/wallet-adapter-react";
104
114
  ```
105
115
 
106
116
  Then you can use the exported properties
107
117
 
108
- ```js
118
+ ```tsx
109
119
  const {
110
- connect,
111
120
  account,
112
- network,
121
+ changeNetwork,
122
+ connect,
113
123
  connected,
114
124
  disconnect,
115
- wallet,
116
- wallets,
125
+ network,
117
126
  signAndSubmitTransaction,
118
- signAndSubmitBCSTransaction,
119
- signTransaction,
120
127
  signMessage,
121
128
  signMessageAndVerify,
129
+ signTransaction,
130
+ submitTransaction,
131
+ wallet,
132
+ wallets,
122
133
  } = useWallet();
123
134
  ```
124
135
 
125
- ### Use a UI package (recommended)
136
+ #### Examples
126
137
 
127
- As part of the wallet adapter repo we provide a wallet connect UI package that provides a wallet connect button and a wallet select modal.
138
+ ##### Account
128
139
 
129
- The available UI Packages are
140
+ ```tsx
141
+ // The account address as a typed AccountAddress
142
+ <div>{account?.address.toString()}</div>
143
+ // The account public key as a typed PublicKey
144
+ <div>{account?.publicKey.toString()}</div>
145
+ ```
130
146
 
131
- - [shadcn/ui](../../apps/nextjs-example/README.md#use-shadcnui-wallet-selector-for-your-own-app)
132
- - [Ant Design](<(../wallet-adapter-ant-design/)>)
133
- - [MUI](../wallet-adapter-mui-design/)
147
+ ##### Network
134
148
 
135
- If you want to create your own wallet selector UI from existing components and styles in your app, `@aptos-labs/wallet-adapter-react` provides a series of headless components and utilities to simplify this process so that you can focus on writing CSS instead of implementing business logic. For more information, check out the [Building Your Own Wallet Selector](./docs/BYO-wallet-selector.md) document.
149
+ ```tsx
150
+ <div>{network?.name}</div>
151
+ ```
136
152
 
137
- #### Examples
153
+ ##### Wallet
138
154
 
139
- ##### Initialize Aptos
155
+ ```tsx
156
+ <div>{wallet?.name}</div>
157
+ <div>{wallet?.icon}</div>
158
+ <div>{wallet?.url}</div>
159
+ ```
140
160
 
141
- ```js
142
- const aptosConfig = new AptosConfig({ network: Network.MAINNET });
143
- const aptos = new Aptos(aptosConfig);
161
+ ##### Wallets
162
+
163
+ ```tsx
164
+ {
165
+ wallets.map((wallet) => <p>{wallet.name}</p>);
166
+ }
144
167
  ```
145
168
 
146
169
  ##### connect(walletName)
147
170
 
148
- ```js
171
+ ```tsx
149
172
  const onConnect = async (walletName) => {
150
173
  await connect(walletName);
151
174
  };
@@ -155,20 +178,19 @@ const onConnect = async (walletName) => {
155
178
 
156
179
  ##### disconnect()
157
180
 
158
- ```js
181
+ ```tsx
159
182
  <button onClick={disconnect}>Disconnect</button>
160
183
  ```
161
184
 
162
185
  ##### signAndSubmitTransaction(payload)
163
186
 
164
- ```js
187
+ ```tsx
165
188
  const onSignAndSubmitTransaction = async () => {
166
189
  const response = await signAndSubmitTransaction({
167
- sender: account.address,
168
190
  data: {
169
191
  function: "0x1::coin::transfer",
170
- typeArguments: ["0x1::aptos_coin::AptosCoin"],
171
- functionArguments: [account.address, 1],
192
+ typeArguments: [APTOS_COIN],
193
+ functionArguments: [account.address, 1], // 1 is in Octas
172
194
  },
173
195
  });
174
196
  // if you want to wait for transaction
@@ -186,10 +208,9 @@ const onSignAndSubmitTransaction = async () => {
186
208
 
187
209
  ##### signAndSubmitBCSTransaction(payload)
188
210
 
189
- ```js
211
+ ```tsx
190
212
  const onSignAndSubmitBCSTransaction = async () => {
191
213
  const response = await signAndSubmitTransaction({
192
- sender: account.address,
193
214
  data: {
194
215
  function: "0x1::coin::transfer",
195
216
  typeArguments: [parseTypeTag(APTOS_COIN)],
@@ -211,7 +232,7 @@ const onSignAndSubmitBCSTransaction = async () => {
211
232
 
212
233
  ##### signMessage(payload)
213
234
 
214
- ```js
235
+ ```tsx
215
236
  const onSignMessage = async () => {
216
237
  const payload = {
217
238
  message: "Hello from Aptos Wallet Adapter",
@@ -223,54 +244,45 @@ const onSignMessage = async () => {
223
244
  <button onClick={onSignMessage}>Sign message</button>;
224
245
  ```
225
246
 
226
- ##### Account
227
-
228
- ```js
229
- <div>{account?.address}</div>
230
- <div>{account?.publicKey}</div>
231
- ```
232
-
233
- ##### Network
234
-
235
- ```js
236
- <div>{network?.name}</div>
237
- ```
238
-
239
- ##### Wallet
240
-
241
- ```js
242
- <div>{wallet?.name}</div>
243
- <div>{wallet?.icon}</div>
244
- <div>{wallet?.url}</div>
245
- ```
246
-
247
- ##### Wallets
248
-
249
- ```js
250
- {
251
- wallets.map((wallet) => <p>{wallet.name}</p>);
252
- }
253
- ```
254
-
255
- ##### signTransaction(payload)
247
+ ##### signTransaction(payload | transaction)
256
248
 
257
- ```js
249
+ ```tsx
258
250
  const onSignTransaction = async () => {
259
- const payload = {
260
- type: "entry_function_payload",
261
- function: "0x1::coin::transfer",
262
- type_arguments: ["0x1::aptos_coin::AptosCoin"],
263
- arguments: [account?.address, 1], // 1 is in Octas
251
+ const payload: InputTransactionData = {
252
+ data: {
253
+ function: "0x1::coin::transfer",
254
+ typeArguments: [APTOS_COIN],
255
+ functionArguments: [account?.address.toString(), 1],
256
+ },
264
257
  };
265
- const response = await signTransaction(payload);
258
+ const response = await signTransaction({
259
+ transactionOrPayload: payload,
260
+ });
261
+ };
262
+
263
+ const onSignRawTransaction = async () => {
264
+ const aptosConfig = new AptosConfig({ network: Network.MAINNET });
265
+ const aptos = new Aptos(aptosConfig);
266
+ const transactionToSign = await aptos.transaction.build.simple({
267
+ sender: account.address,
268
+ data: {
269
+ function: "0x1::coin::transfer",
270
+ typeArguments: [APTOS_COIN],
271
+ functionArguments: [account.address.toString(), 1],
272
+ },
273
+ });
274
+ const response = await signTransaction({
275
+ transactionOrPayload: transactionToSign,
276
+ });
266
277
  };
267
278
 
268
279
  <button onClick={onSignTransaction}>Sign transaction</button>;
280
+ <button onClick={onSignRawTransaction}>Sign raw transaction</button>;
269
281
  ```
270
282
 
271
283
  ##### signMessageAndVerify(payload)
272
284
 
273
- ```js
285
+ ```tsx
274
286
  const onSignMessageAndVerify = async () => {
275
287
  const payload = {
276
288
  message: "Hello from Aptos Wallet Adapter",
@@ -281,3 +293,14 @@ const onSignMessageAndVerify = async () => {
281
293
 
282
294
  <button onClick={onSignMessageAndVerify}>Sign message and verify</button>;
283
295
  ```
296
+
297
+ ### Use a UI package (recommended)
298
+
299
+ As part of the wallet adapter repo we provide a wallet connect UI package that provides a wallet connect button and a wallet select modal.
300
+
301
+ The available UI Packages are
302
+
303
+ - [shadcn/ui](../../apps/nextjs-example/README.md#use-shadcnui-wallet-selector-for-your-own-app)
304
+ - [MUI](../wallet-adapter-mui-design/)
305
+
306
+ If you want to create your own wallet selector UI from existing components and styles in your app, `@aptos-labs/wallet-adapter-react` provides a series of headless components and utilities to simplify this process so that you can focus on writing CSS instead of implementing business logic. For more information, check out the [Building Your Own Wallet Selector](./docs/BYO-wallet-selector.md) document.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aptos-labs/wallet-adapter-react",
3
- "version": "4.0.0",
3
+ "version": "4.0.2",
4
4
  "description": "Aptos Wallet Adapter React Provider",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -38,7 +38,7 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "@radix-ui/react-slot": "^1.0.2",
41
- "@aptos-labs/wallet-adapter-core": "5.0.0"
41
+ "@aptos-labs/wallet-adapter-core": "5.0.2"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "react": "^18"