@aptos-labs/wallet-adapter-react 0.0.0-aip-62-20240325204648
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.
- package/CHANGELOG.md +250 -0
- package/README.md +263 -0
- package/READMEV1.md +267 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +265 -0
- package/dist/index.mjs +243 -0
- package/package.json +51 -0
- package/src/WalletProvider.tsx +274 -0
- package/src/index.tsx +16 -0
- package/src/useWallet.tsx +55 -0
package/READMEV1.md
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
> **_NOTE:_** This documentation is for Wallet Adapter `v^1.*.*`
|
|
2
|
+
|
|
3
|
+
# Wallet Adapter React Provider
|
|
4
|
+
|
|
5
|
+
A react provider wrapper for the Aptos Wallet Adapter
|
|
6
|
+
|
|
7
|
+
Dapps that want to use the adapter should install this package and other supported wallet packages.
|
|
8
|
+
|
|
9
|
+
### Support
|
|
10
|
+
|
|
11
|
+
The react provider supports all [wallet standard](https://aptos.dev/guides/wallet-standard) functions and feature functions
|
|
12
|
+
|
|
13
|
+
##### Standard functions
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
connect
|
|
17
|
+
disconnect
|
|
18
|
+
connected
|
|
19
|
+
account
|
|
20
|
+
network
|
|
21
|
+
signAndSubmitTransaction
|
|
22
|
+
signMessage
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
##### Feature functions - functions that may not be supported by all wallets
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
signTransaction
|
|
29
|
+
signMessageAndVerify
|
|
30
|
+
signAndSubmitBCSTransaction
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Usage
|
|
34
|
+
|
|
35
|
+
#### Install Dependencies
|
|
36
|
+
|
|
37
|
+
Install wallet dependencies you want to include in your app.
|
|
38
|
+
To do that, you can look at our [supported wallets list](https://github.com/aptos-labs/aptos-wallet-adapter#supported-wallet-packages). Each wallet is a link to npm package where you can install it from.
|
|
39
|
+
|
|
40
|
+
Next, install the `@aptos-labs/wallet-adapter-react`
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
pnpm i @aptos-labs/wallet-adapter-react
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
using npm
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
npm i @aptos-labs/wallet-adapter-react
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
#### Import dependencies
|
|
53
|
+
|
|
54
|
+
On the `App.jsx` file,
|
|
55
|
+
|
|
56
|
+
Import the installed wallets.
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
import { SomeAptosWallet } from "some-aptos-wallet-package";
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Import the `AptosWalletAdapterProvider`.
|
|
63
|
+
|
|
64
|
+
```js
|
|
65
|
+
import { AptosWalletAdapterProvider } from "@aptos-labs/wallet-adapter-react";
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Wrap your app with the Provider, pass it the `plugins (wallets)` you want to have on your app as an array and a `autoConnect` option (set to false by default)
|
|
69
|
+
|
|
70
|
+
```js
|
|
71
|
+
const wallets = [new AptosWallet()];
|
|
72
|
+
|
|
73
|
+
<AptosWalletAdapterProvider
|
|
74
|
+
plugins={wallets}
|
|
75
|
+
autoConnect={true}
|
|
76
|
+
onError={(error) => {
|
|
77
|
+
console.log("error", error);
|
|
78
|
+
}}
|
|
79
|
+
>
|
|
80
|
+
<App />
|
|
81
|
+
</AptosWalletAdapterProvider>;
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
#### Use Wallet
|
|
85
|
+
|
|
86
|
+
On any page you want to use the wallet props, import `useWallet` from `@aptos-labs/wallet-adapter-react`
|
|
87
|
+
|
|
88
|
+
```js
|
|
89
|
+
import { useWallet } from "@aptos-labs/wallet-adapter-react";
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Then you can use the exported properties
|
|
93
|
+
|
|
94
|
+
```js
|
|
95
|
+
const {
|
|
96
|
+
connect,
|
|
97
|
+
account,
|
|
98
|
+
network,
|
|
99
|
+
connected,
|
|
100
|
+
disconnect,
|
|
101
|
+
wallet,
|
|
102
|
+
wallets,
|
|
103
|
+
signAndSubmitTransaction,
|
|
104
|
+
signAndSubmitBCSTransaction,
|
|
105
|
+
signTransaction,
|
|
106
|
+
signMessage,
|
|
107
|
+
signMessageAndVerify,
|
|
108
|
+
} = useWallet();
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Use a UI package (recommended)
|
|
112
|
+
|
|
113
|
+
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.
|
|
114
|
+
You can find it [here](../wallet-adapter-ant-design/) with instructions on how to use it.
|
|
115
|
+
|
|
116
|
+
#### Examples
|
|
117
|
+
|
|
118
|
+
##### connect(walletName)
|
|
119
|
+
|
|
120
|
+
```js
|
|
121
|
+
const onConnect = async (walletName) => {
|
|
122
|
+
await connect(walletName);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
<button onClick={() => onConnect(wallet.name)}>{wallet.name}</button>;
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
##### disconnect()
|
|
129
|
+
|
|
130
|
+
```js
|
|
131
|
+
<button onClick={disconnect}>Disconnect</button>
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
##### signAndSubmitTransaction(payload)
|
|
135
|
+
|
|
136
|
+
```js
|
|
137
|
+
const onSignAndSubmitTransaction = async () => {
|
|
138
|
+
const payload: Types.TransactionPayload = {
|
|
139
|
+
type: "entry_function_payload",
|
|
140
|
+
function: "0x1::coin::transfer",
|
|
141
|
+
type_arguments: ["0x1::aptos_coin::AptosCoin"],
|
|
142
|
+
arguments: [account?.address, 1], // 1 is in Octas
|
|
143
|
+
};
|
|
144
|
+
const response = await signAndSubmitTransaction(payload);
|
|
145
|
+
// if you want to wait for transaction
|
|
146
|
+
try {
|
|
147
|
+
await aptosClient.waitForTransaction(response?.hash || "");
|
|
148
|
+
} catch (error) {
|
|
149
|
+
console.error(error);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
<button onClick={onSignAndSubmitTransaction}>
|
|
154
|
+
Sign and submit transaction
|
|
155
|
+
</button>
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
##### signAndSubmitBCSTransaction(payload)
|
|
159
|
+
|
|
160
|
+
```js
|
|
161
|
+
const onSignAndSubmitBCSTransaction = async () => {
|
|
162
|
+
const token = new TxnBuilderTypes.TypeTagStruct(
|
|
163
|
+
TxnBuilderTypes.StructTag.fromString("0x1::aptos_coin::AptosCoin")
|
|
164
|
+
);
|
|
165
|
+
const entryFunctionBCSPayload =
|
|
166
|
+
new TxnBuilderTypes.TransactionPayloadEntryFunction(
|
|
167
|
+
TxnBuilderTypes.EntryFunction.natural(
|
|
168
|
+
"0x1::coin",
|
|
169
|
+
"transfer",
|
|
170
|
+
[token],
|
|
171
|
+
[
|
|
172
|
+
BCS.bcsToBytes(
|
|
173
|
+
TxnBuilderTypes.AccountAddress.fromHex(account!.address)
|
|
174
|
+
),
|
|
175
|
+
BCS.bcsSerializeUint64(2),
|
|
176
|
+
]
|
|
177
|
+
)
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
const response = await signAndSubmitBCSTransaction(entryFunctionBCSPayload);
|
|
181
|
+
// if you want to wait for transaction
|
|
182
|
+
try {
|
|
183
|
+
await aptosClient.waitForTransaction(response?.hash || "");
|
|
184
|
+
} catch (error) {
|
|
185
|
+
console.error(error);
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
<button onClick={onSignAndSubmitTransaction}>
|
|
190
|
+
Sign and submit BCS transaction
|
|
191
|
+
</button>
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
##### signMessage(payload)
|
|
195
|
+
|
|
196
|
+
```js
|
|
197
|
+
const onSignMessage = async () => {
|
|
198
|
+
const payload = {
|
|
199
|
+
message: "Hello from Aptos Wallet Adapter",
|
|
200
|
+
nonce: "random_string",
|
|
201
|
+
};
|
|
202
|
+
const response = await signMessage(payload);
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
<button onClick={onSignMessage}>Sign message</button>;
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
##### Account
|
|
209
|
+
|
|
210
|
+
```js
|
|
211
|
+
<div>{account?.address}</div>
|
|
212
|
+
<div>{account?.publicKey}</div>
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
##### Network
|
|
216
|
+
|
|
217
|
+
```js
|
|
218
|
+
<div>{network?.name}</div>
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
##### Wallet
|
|
222
|
+
|
|
223
|
+
```js
|
|
224
|
+
<div>{wallet?.name}</div>
|
|
225
|
+
<div>{wallet?.icon}</div>
|
|
226
|
+
<div>{wallet?.url}</div>
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
##### Wallets
|
|
230
|
+
|
|
231
|
+
```js
|
|
232
|
+
{
|
|
233
|
+
wallets.map((wallet) => <p>{wallet.name}</p>);
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
##### signTransaction(payload)
|
|
238
|
+
|
|
239
|
+
```js
|
|
240
|
+
const onSignTransaction = async () => {
|
|
241
|
+
const payload: Types.TransactionPayload = {
|
|
242
|
+
type: "entry_function_payload",
|
|
243
|
+
function: "0x1::coin::transfer",
|
|
244
|
+
type_arguments: ["0x1::aptos_coin::AptosCoin"],
|
|
245
|
+
arguments: [account?.address, 1], // 1 is in Octas
|
|
246
|
+
};
|
|
247
|
+
const response = await signTransaction(payload);
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
<button onClick={onSignTransaction}>
|
|
251
|
+
Sign transaction
|
|
252
|
+
</button>
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
##### signMessageAndVerify(payload)
|
|
256
|
+
|
|
257
|
+
```js
|
|
258
|
+
const onSignMessageAndVerify = async () => {
|
|
259
|
+
const payload = {
|
|
260
|
+
message: "Hello from Aptos Wallet Adapter",
|
|
261
|
+
nonce: "random_string",
|
|
262
|
+
};
|
|
263
|
+
const response = await signMessageAndVerify(payload);
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
<button onClick={onSignMessageAndVerify}>Sign message and verify</button>;
|
|
267
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { AccountInfo, NetworkInfo, WalletName, WalletInfo, Wallet, InputTransactionData, AnyRawTransaction, Types, InputGenerateTransactionOptions, AccountAuthenticator, InputSubmitTransactionData, PendingTransactionResponse, SignMessagePayload, SignMessageResponse } from '@aptos-labs/wallet-adapter-core';
|
|
2
|
+
export { InputTransactionData, NetworkName, Wallet, WalletName, WalletReadyState, isInAppBrowser, isMobile, isRedirectable } from '@aptos-labs/wallet-adapter-core';
|
|
3
|
+
import { ReactNode, FC } from 'react';
|
|
4
|
+
|
|
5
|
+
interface WalletContextState {
|
|
6
|
+
connected: boolean;
|
|
7
|
+
isLoading: boolean;
|
|
8
|
+
account: AccountInfo | null;
|
|
9
|
+
network: NetworkInfo | null;
|
|
10
|
+
connect(walletName: WalletName): void;
|
|
11
|
+
disconnect(): void;
|
|
12
|
+
wallet: WalletInfo | null;
|
|
13
|
+
wallets?: ReadonlyArray<Wallet>;
|
|
14
|
+
signAndSubmitTransaction(transaction: InputTransactionData): Promise<any>;
|
|
15
|
+
signTransaction(transactionOrPayload: AnyRawTransaction | Types.TransactionPayload, asFeePayer?: boolean, options?: InputGenerateTransactionOptions): Promise<AccountAuthenticator>;
|
|
16
|
+
submitTransaction(transaction: InputSubmitTransactionData): Promise<PendingTransactionResponse>;
|
|
17
|
+
signMessage(message: SignMessagePayload): Promise<SignMessageResponse>;
|
|
18
|
+
signMessageAndVerify(message: SignMessagePayload): Promise<boolean>;
|
|
19
|
+
}
|
|
20
|
+
declare function useWallet(): WalletContextState;
|
|
21
|
+
|
|
22
|
+
interface AptosWalletProviderProps {
|
|
23
|
+
children: ReactNode;
|
|
24
|
+
plugins?: ReadonlyArray<Wallet>;
|
|
25
|
+
autoConnect?: boolean;
|
|
26
|
+
onError?: (error: any) => void;
|
|
27
|
+
}
|
|
28
|
+
declare const AptosWalletAdapterProvider: FC<AptosWalletProviderProps>;
|
|
29
|
+
|
|
30
|
+
export { AptosWalletAdapterProvider, AptosWalletProviderProps, useWallet };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.tsx
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
AptosWalletAdapterProvider: () => AptosWalletAdapterProvider,
|
|
24
|
+
NetworkName: () => import_wallet_adapter_core2.NetworkName,
|
|
25
|
+
WalletReadyState: () => import_wallet_adapter_core2.WalletReadyState,
|
|
26
|
+
isInAppBrowser: () => import_wallet_adapter_core2.isInAppBrowser,
|
|
27
|
+
isMobile: () => import_wallet_adapter_core2.isMobile,
|
|
28
|
+
isRedirectable: () => import_wallet_adapter_core2.isRedirectable,
|
|
29
|
+
useWallet: () => useWallet
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(src_exports);
|
|
32
|
+
|
|
33
|
+
// src/useWallet.tsx
|
|
34
|
+
var import_react = require("react");
|
|
35
|
+
var DEFAULT_CONTEXT = {
|
|
36
|
+
connected: false
|
|
37
|
+
};
|
|
38
|
+
var WalletContext = (0, import_react.createContext)(
|
|
39
|
+
DEFAULT_CONTEXT
|
|
40
|
+
);
|
|
41
|
+
function useWallet() {
|
|
42
|
+
const context = (0, import_react.useContext)(WalletContext);
|
|
43
|
+
if (!context) {
|
|
44
|
+
throw new Error("useWallet must be used within a WalletContextState");
|
|
45
|
+
}
|
|
46
|
+
return context;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// src/WalletProvider.tsx
|
|
50
|
+
var import_react2 = require("react");
|
|
51
|
+
var import_wallet_adapter_core = require("@aptos-labs/wallet-adapter-core");
|
|
52
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
53
|
+
var initialState = {
|
|
54
|
+
connected: false,
|
|
55
|
+
account: null,
|
|
56
|
+
network: null,
|
|
57
|
+
wallet: null
|
|
58
|
+
};
|
|
59
|
+
var AptosWalletAdapterProvider = ({
|
|
60
|
+
children,
|
|
61
|
+
plugins,
|
|
62
|
+
autoConnect = false,
|
|
63
|
+
onError
|
|
64
|
+
}) => {
|
|
65
|
+
const [{ connected, account, network, wallet }, setState] = (0, import_react2.useState)(initialState);
|
|
66
|
+
const [isLoading, setIsLoading] = (0, import_react2.useState)(true);
|
|
67
|
+
const walletCore = (0, import_react2.useMemo)(() => new import_wallet_adapter_core.WalletCore(plugins != null ? plugins : []), []);
|
|
68
|
+
const [wallets, setWallets] = (0, import_react2.useState)(
|
|
69
|
+
walletCore.wallets
|
|
70
|
+
);
|
|
71
|
+
const connect = async (walletName) => {
|
|
72
|
+
try {
|
|
73
|
+
setIsLoading(true);
|
|
74
|
+
await walletCore.connect(walletName);
|
|
75
|
+
} catch (error) {
|
|
76
|
+
if (onError)
|
|
77
|
+
onError(error);
|
|
78
|
+
return Promise.reject(error);
|
|
79
|
+
} finally {
|
|
80
|
+
setIsLoading(false);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const disconnect = async () => {
|
|
84
|
+
try {
|
|
85
|
+
await walletCore.disconnect();
|
|
86
|
+
} catch (error) {
|
|
87
|
+
if (onError)
|
|
88
|
+
onError(error);
|
|
89
|
+
return Promise.reject(error);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
const signTransaction = async (transaction, asFeePayer, options) => {
|
|
93
|
+
try {
|
|
94
|
+
return await walletCore.signTransaction(transaction, asFeePayer, options);
|
|
95
|
+
} catch (error) {
|
|
96
|
+
if (onError)
|
|
97
|
+
onError(error);
|
|
98
|
+
return Promise.reject(error);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const signMessage = async (message) => {
|
|
102
|
+
try {
|
|
103
|
+
return await walletCore.signMessage(message);
|
|
104
|
+
} catch (error) {
|
|
105
|
+
if (onError)
|
|
106
|
+
onError(error);
|
|
107
|
+
return Promise.reject(error);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
const signMessageAndVerify = async (message) => {
|
|
111
|
+
try {
|
|
112
|
+
return await walletCore.signMessageAndVerify(message);
|
|
113
|
+
} catch (error) {
|
|
114
|
+
if (onError)
|
|
115
|
+
onError(error);
|
|
116
|
+
return Promise.reject(error);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
const submitTransaction = async (transaction) => {
|
|
120
|
+
try {
|
|
121
|
+
return await walletCore.submitTransaction(transaction);
|
|
122
|
+
} catch (error) {
|
|
123
|
+
if (onError)
|
|
124
|
+
onError(error);
|
|
125
|
+
return Promise.reject(error);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
const signAndSubmitTransaction = async (transaction) => {
|
|
129
|
+
try {
|
|
130
|
+
return await walletCore.signAndSubmitTransaction(transaction);
|
|
131
|
+
} catch (error) {
|
|
132
|
+
if (onError)
|
|
133
|
+
onError(error);
|
|
134
|
+
return Promise.reject(error);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
(0, import_react2.useEffect)(() => {
|
|
138
|
+
if (autoConnect) {
|
|
139
|
+
if (localStorage.getItem("AptosWalletName") && !connected) {
|
|
140
|
+
connect(localStorage.getItem("AptosWalletName"));
|
|
141
|
+
} else {
|
|
142
|
+
setIsLoading(false);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}, wallets);
|
|
146
|
+
(0, import_react2.useEffect)(() => {
|
|
147
|
+
if (connected) {
|
|
148
|
+
walletCore.onAccountChange();
|
|
149
|
+
walletCore.onNetworkChange();
|
|
150
|
+
}
|
|
151
|
+
}, [connected]);
|
|
152
|
+
const handleConnect = () => {
|
|
153
|
+
setState((state) => {
|
|
154
|
+
return {
|
|
155
|
+
...state,
|
|
156
|
+
connected: true,
|
|
157
|
+
account: walletCore.account,
|
|
158
|
+
network: walletCore.network,
|
|
159
|
+
wallet: walletCore.wallet
|
|
160
|
+
};
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
const handleDisconnect = () => {
|
|
164
|
+
if (!connected)
|
|
165
|
+
return;
|
|
166
|
+
setState((state) => {
|
|
167
|
+
return {
|
|
168
|
+
...state,
|
|
169
|
+
connected: false,
|
|
170
|
+
account: walletCore.account,
|
|
171
|
+
network: walletCore.network,
|
|
172
|
+
wallet: null
|
|
173
|
+
};
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
const handleAccountChange = (0, import_react2.useCallback)(() => {
|
|
177
|
+
if (!connected)
|
|
178
|
+
return;
|
|
179
|
+
if (!walletCore.wallet)
|
|
180
|
+
return;
|
|
181
|
+
setState((state) => {
|
|
182
|
+
return {
|
|
183
|
+
...state,
|
|
184
|
+
account: walletCore.account
|
|
185
|
+
};
|
|
186
|
+
});
|
|
187
|
+
}, [connected]);
|
|
188
|
+
const handleNetworkChange = (0, import_react2.useCallback)(() => {
|
|
189
|
+
if (!connected)
|
|
190
|
+
return;
|
|
191
|
+
if (!walletCore.wallet)
|
|
192
|
+
return;
|
|
193
|
+
setState((state) => {
|
|
194
|
+
return {
|
|
195
|
+
...state,
|
|
196
|
+
network: walletCore.network
|
|
197
|
+
};
|
|
198
|
+
});
|
|
199
|
+
}, [connected]);
|
|
200
|
+
const handleReadyStateChange = (updatedWallet) => {
|
|
201
|
+
const updatedWallets = wallets == null ? void 0 : wallets.map((wallet2) => {
|
|
202
|
+
if (wallet2.name === updatedWallet.name) {
|
|
203
|
+
return { ...wallet2, readyState: updatedWallet.readyState };
|
|
204
|
+
}
|
|
205
|
+
return wallet2;
|
|
206
|
+
});
|
|
207
|
+
setWallets(updatedWallets);
|
|
208
|
+
};
|
|
209
|
+
const handleStandardWalletsAdded = (standardWallet) => {
|
|
210
|
+
const updatedWallets = wallets == null ? void 0 : wallets.map((wallet2) => {
|
|
211
|
+
if (wallet2.name === standardWallet.name) {
|
|
212
|
+
return { ...standardWallet };
|
|
213
|
+
}
|
|
214
|
+
return wallet2;
|
|
215
|
+
});
|
|
216
|
+
setWallets(updatedWallets);
|
|
217
|
+
};
|
|
218
|
+
(0, import_react2.useEffect)(() => {
|
|
219
|
+
walletCore.on("connect", handleConnect);
|
|
220
|
+
walletCore.on("disconnect", handleDisconnect);
|
|
221
|
+
walletCore.on("accountChange", handleAccountChange);
|
|
222
|
+
walletCore.on("networkChange", handleNetworkChange);
|
|
223
|
+
walletCore.on("readyStateChange", handleReadyStateChange);
|
|
224
|
+
walletCore.on("standardWalletsAdded", handleStandardWalletsAdded);
|
|
225
|
+
return () => {
|
|
226
|
+
walletCore.off("connect", handleConnect);
|
|
227
|
+
walletCore.off("disconnect", handleDisconnect);
|
|
228
|
+
walletCore.off("accountChange", handleAccountChange);
|
|
229
|
+
walletCore.off("networkChange", handleNetworkChange);
|
|
230
|
+
walletCore.off("readyStateChange", handleReadyStateChange);
|
|
231
|
+
walletCore.off("standardWalletsAdded", handleStandardWalletsAdded);
|
|
232
|
+
};
|
|
233
|
+
}, [wallets, connected]);
|
|
234
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(WalletContext.Provider, {
|
|
235
|
+
value: {
|
|
236
|
+
connect,
|
|
237
|
+
account,
|
|
238
|
+
network,
|
|
239
|
+
connected,
|
|
240
|
+
disconnect,
|
|
241
|
+
wallet,
|
|
242
|
+
wallets,
|
|
243
|
+
signAndSubmitTransaction,
|
|
244
|
+
signTransaction,
|
|
245
|
+
signMessage,
|
|
246
|
+
signMessageAndVerify,
|
|
247
|
+
isLoading,
|
|
248
|
+
submitTransaction
|
|
249
|
+
},
|
|
250
|
+
children
|
|
251
|
+
});
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
// src/index.tsx
|
|
255
|
+
var import_wallet_adapter_core2 = require("@aptos-labs/wallet-adapter-core");
|
|
256
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
257
|
+
0 && (module.exports = {
|
|
258
|
+
AptosWalletAdapterProvider,
|
|
259
|
+
NetworkName,
|
|
260
|
+
WalletReadyState,
|
|
261
|
+
isInAppBrowser,
|
|
262
|
+
isMobile,
|
|
263
|
+
isRedirectable,
|
|
264
|
+
useWallet
|
|
265
|
+
});
|