@aptos-labs/wallet-adapter-react 2.1.8 → 2.2.1

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 CHANGED
@@ -1,5 +1,23 @@
1
1
  # @aptos-labs/wallet-adapter-react
2
2
 
3
+ ## 2.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [4127cfb]
8
+ - @aptos-labs/wallet-adapter-core@3.8.0
9
+
10
+ ## 2.2.0
11
+
12
+ ### Minor Changes
13
+
14
+ - 4d6e2f6: Add AIP-62 wallet standard support
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies [4d6e2f6]
19
+ - @aptos-labs/wallet-adapter-core@3.7.0
20
+
3
21
  ## 2.1.8
4
22
 
5
23
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
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';
2
+ export { AccountInfo, InputTransactionData, NetworkInfo, NetworkName, Wallet, WalletInfo, WalletName, WalletReadyState, isInAppBrowser, isMobile, isRedirectable } from '@aptos-labs/wallet-adapter-core';
3
3
  import { ReactNode, FC } from 'react';
4
4
 
5
5
  interface WalletContextState {
@@ -10,7 +10,7 @@ interface WalletContextState {
10
10
  connect(walletName: WalletName): void;
11
11
  disconnect(): void;
12
12
  wallet: WalletInfo | null;
13
- wallets: ReadonlyArray<Wallet>;
13
+ wallets?: ReadonlyArray<Wallet>;
14
14
  signAndSubmitTransaction(transaction: InputTransactionData): Promise<any>;
15
15
  signTransaction(transactionOrPayload: AnyRawTransaction | Types.TransactionPayload, asFeePayer?: boolean, options?: InputGenerateTransactionOptions): Promise<AccountAuthenticator>;
16
16
  submitTransaction(transaction: InputSubmitTransactionData): Promise<PendingTransactionResponse>;
@@ -21,7 +21,7 @@ declare function useWallet(): WalletContextState;
21
21
 
22
22
  interface AptosWalletProviderProps {
23
23
  children: ReactNode;
24
- plugins: ReadonlyArray<Wallet>;
24
+ plugins?: ReadonlyArray<Wallet>;
25
25
  autoConnect?: boolean;
26
26
  onError?: (error: any) => void;
27
27
  }
package/dist/index.js CHANGED
@@ -64,7 +64,7 @@ var AptosWalletAdapterProvider = ({
64
64
  }) => {
65
65
  const [{ connected, account, network, wallet }, setState] = (0, import_react2.useState)(initialState);
66
66
  const [isLoading, setIsLoading] = (0, import_react2.useState)(true);
67
- const walletCore = (0, import_react2.useMemo)(() => new import_wallet_adapter_core.WalletCore(plugins), []);
67
+ const walletCore = (0, import_react2.useMemo)(() => new import_wallet_adapter_core.WalletCore(plugins != null ? plugins : []), []);
68
68
  const [wallets, setWallets] = (0, import_react2.useState)(
69
69
  walletCore.wallets
70
70
  );
@@ -73,7 +73,6 @@ var AptosWalletAdapterProvider = ({
73
73
  setIsLoading(true);
74
74
  await walletCore.connect(walletName);
75
75
  } catch (error) {
76
- console.log("connect error", error);
77
76
  if (onError)
78
77
  onError(error);
79
78
  return Promise.reject(error);
@@ -137,7 +136,7 @@ var AptosWalletAdapterProvider = ({
137
136
  };
138
137
  (0, import_react2.useEffect)(() => {
139
138
  if (autoConnect) {
140
- if (localStorage.getItem("AptosWalletName")) {
139
+ if (localStorage.getItem("AptosWalletName") && !connected) {
141
140
  connect(localStorage.getItem("AptosWalletName"));
142
141
  } else {
143
142
  setIsLoading(false);
@@ -149,7 +148,7 @@ var AptosWalletAdapterProvider = ({
149
148
  walletCore.onAccountChange();
150
149
  walletCore.onNetworkChange();
151
150
  }
152
- }, [...wallets, connected]);
151
+ }, [connected]);
153
152
  const handleConnect = () => {
154
153
  setState((state) => {
155
154
  return {
@@ -198,8 +197,23 @@ var AptosWalletAdapterProvider = ({
198
197
  };
199
198
  });
200
199
  }, [connected]);
201
- const handleReadyStateChange = (wallet2) => {
202
- setWallets((wallets2) => [...wallets2]);
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);
203
217
  };
204
218
  (0, import_react2.useEffect)(() => {
205
219
  walletCore.on("connect", handleConnect);
@@ -207,14 +221,16 @@ var AptosWalletAdapterProvider = ({
207
221
  walletCore.on("accountChange", handleAccountChange);
208
222
  walletCore.on("networkChange", handleNetworkChange);
209
223
  walletCore.on("readyStateChange", handleReadyStateChange);
224
+ walletCore.on("standardWalletsAdded", handleStandardWalletsAdded);
210
225
  return () => {
211
226
  walletCore.off("connect", handleConnect);
212
227
  walletCore.off("disconnect", handleDisconnect);
213
228
  walletCore.off("accountChange", handleAccountChange);
214
229
  walletCore.off("networkChange", handleNetworkChange);
215
230
  walletCore.off("readyStateChange", handleReadyStateChange);
231
+ walletCore.off("standardWalletsAdded", handleStandardWalletsAdded);
216
232
  };
217
- }, [...wallets, connected]);
233
+ }, [wallets, connected]);
218
234
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(WalletContext.Provider, {
219
235
  value: {
220
236
  connect,
package/dist/index.mjs CHANGED
@@ -37,7 +37,7 @@ var AptosWalletAdapterProvider = ({
37
37
  }) => {
38
38
  const [{ connected, account, network, wallet }, setState] = useState(initialState);
39
39
  const [isLoading, setIsLoading] = useState(true);
40
- const walletCore = useMemo(() => new WalletCore(plugins), []);
40
+ const walletCore = useMemo(() => new WalletCore(plugins != null ? plugins : []), []);
41
41
  const [wallets, setWallets] = useState(
42
42
  walletCore.wallets
43
43
  );
@@ -46,7 +46,6 @@ var AptosWalletAdapterProvider = ({
46
46
  setIsLoading(true);
47
47
  await walletCore.connect(walletName);
48
48
  } catch (error) {
49
- console.log("connect error", error);
50
49
  if (onError)
51
50
  onError(error);
52
51
  return Promise.reject(error);
@@ -110,7 +109,7 @@ var AptosWalletAdapterProvider = ({
110
109
  };
111
110
  useEffect(() => {
112
111
  if (autoConnect) {
113
- if (localStorage.getItem("AptosWalletName")) {
112
+ if (localStorage.getItem("AptosWalletName") && !connected) {
114
113
  connect(localStorage.getItem("AptosWalletName"));
115
114
  } else {
116
115
  setIsLoading(false);
@@ -122,7 +121,7 @@ var AptosWalletAdapterProvider = ({
122
121
  walletCore.onAccountChange();
123
122
  walletCore.onNetworkChange();
124
123
  }
125
- }, [...wallets, connected]);
124
+ }, [connected]);
126
125
  const handleConnect = () => {
127
126
  setState((state) => {
128
127
  return {
@@ -171,8 +170,23 @@ var AptosWalletAdapterProvider = ({
171
170
  };
172
171
  });
173
172
  }, [connected]);
174
- const handleReadyStateChange = (wallet2) => {
175
- setWallets((wallets2) => [...wallets2]);
173
+ const handleReadyStateChange = (updatedWallet) => {
174
+ const updatedWallets = wallets == null ? void 0 : wallets.map((wallet2) => {
175
+ if (wallet2.name === updatedWallet.name) {
176
+ return { ...wallet2, readyState: updatedWallet.readyState };
177
+ }
178
+ return wallet2;
179
+ });
180
+ setWallets(updatedWallets);
181
+ };
182
+ const handleStandardWalletsAdded = (standardWallet) => {
183
+ const updatedWallets = wallets == null ? void 0 : wallets.map((wallet2) => {
184
+ if (wallet2.name === standardWallet.name) {
185
+ return { ...standardWallet };
186
+ }
187
+ return wallet2;
188
+ });
189
+ setWallets(updatedWallets);
176
190
  };
177
191
  useEffect(() => {
178
192
  walletCore.on("connect", handleConnect);
@@ -180,14 +194,16 @@ var AptosWalletAdapterProvider = ({
180
194
  walletCore.on("accountChange", handleAccountChange);
181
195
  walletCore.on("networkChange", handleNetworkChange);
182
196
  walletCore.on("readyStateChange", handleReadyStateChange);
197
+ walletCore.on("standardWalletsAdded", handleStandardWalletsAdded);
183
198
  return () => {
184
199
  walletCore.off("connect", handleConnect);
185
200
  walletCore.off("disconnect", handleDisconnect);
186
201
  walletCore.off("accountChange", handleAccountChange);
187
202
  walletCore.off("networkChange", handleNetworkChange);
188
203
  walletCore.off("readyStateChange", handleReadyStateChange);
204
+ walletCore.off("standardWalletsAdded", handleStandardWalletsAdded);
189
205
  };
190
- }, [...wallets, connected]);
206
+ }, [wallets, connected]);
191
207
  return /* @__PURE__ */ jsx(WalletContext.Provider, {
192
208
  value: {
193
209
  connect,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aptos-labs/wallet-adapter-react",
3
- "version": "2.1.8",
3
+ "version": "2.2.1",
4
4
  "description": "Aptos Wallet Adapter React Provider",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -37,7 +37,7 @@
37
37
  "@aptos-labs/wallet-adapter-tsconfig": "0.0.0"
38
38
  },
39
39
  "dependencies": {
40
- "@aptos-labs/wallet-adapter-core": "3.6.0"
40
+ "@aptos-labs/wallet-adapter-core": "3.8.0"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "react": "^18"
@@ -27,7 +27,7 @@ import { WalletCore } from "@aptos-labs/wallet-adapter-core";
27
27
 
28
28
  export interface AptosWalletProviderProps {
29
29
  children: ReactNode;
30
- plugins: ReadonlyArray<Wallet>;
30
+ plugins?: ReadonlyArray<Wallet>;
31
31
  autoConnect?: boolean;
32
32
  onError?: (error: any) => void;
33
33
  }
@@ -57,7 +57,7 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
57
57
  // https://github.com/aptos-labs/aptos-wallet-adapter/issues/94
58
58
  const [isLoading, setIsLoading] = useState<boolean>(true);
59
59
 
60
- const walletCore = useMemo(() => new WalletCore(plugins), []);
60
+ const walletCore = useMemo(() => new WalletCore(plugins ?? []), []);
61
61
  const [wallets, setWallets] = useState<ReadonlyArray<Wallet>>(
62
62
  walletCore.wallets
63
63
  );
@@ -67,7 +67,6 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
67
67
  setIsLoading(true);
68
68
  await walletCore.connect(walletName);
69
69
  } catch (error: any) {
70
- console.log("connect error", error);
71
70
  if (onError) onError(error);
72
71
  return Promise.reject(error);
73
72
  } finally {
@@ -143,7 +142,7 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
143
142
 
144
143
  useEffect(() => {
145
144
  if (autoConnect) {
146
- if (localStorage.getItem("AptosWalletName")) {
145
+ if (localStorage.getItem("AptosWalletName") && !connected) {
147
146
  connect(localStorage.getItem("AptosWalletName") as WalletName);
148
147
  } else {
149
148
  // if we dont use autoconnect set the connect is loading to false
@@ -157,7 +156,7 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
157
156
  walletCore.onAccountChange();
158
157
  walletCore.onNetworkChange();
159
158
  }
160
- }, [...wallets, connected]);
159
+ }, [connected]);
161
160
 
162
161
  // Handle the adapter's connect event
163
162
  const handleConnect = () => {
@@ -210,11 +209,28 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
210
209
  });
211
210
  }, [connected]);
212
211
 
213
- // Whenever the readyState of any supported wallet changes we produce a new wallets state array
214
- // which in turn causes consumers of the `useWallet` hook to re-render.
215
- // See https://github.com/aptos-labs/aptos-wallet-adapter/pull/129#issuecomment-1519026572 for reasoning.
216
- const handleReadyStateChange = (wallet: Wallet) => {
217
- setWallets((wallets) => [...wallets]);
212
+ const handleReadyStateChange = (updatedWallet: Wallet) => {
213
+ // Create a new array with updated values
214
+ const updatedWallets = wallets?.map((wallet) => {
215
+ if (wallet.name === updatedWallet.name) {
216
+ // Return a new object with updated value
217
+ return { ...wallet, readyState: updatedWallet.readyState };
218
+ }
219
+ return wallet;
220
+ });
221
+ setWallets(updatedWallets);
222
+ };
223
+
224
+ const handleStandardWalletsAdded = (standardWallet: Wallet) => {
225
+ // Manage current wallet state by removing optional duplications
226
+ // as new wallets are coming
227
+ const updatedWallets = wallets?.map((wallet) => {
228
+ if (wallet.name === standardWallet.name) {
229
+ return { ...standardWallet };
230
+ }
231
+ return wallet;
232
+ });
233
+ setWallets(updatedWallets);
218
234
  };
219
235
 
220
236
  useEffect(() => {
@@ -223,14 +239,16 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
223
239
  walletCore.on("accountChange", handleAccountChange);
224
240
  walletCore.on("networkChange", handleNetworkChange);
225
241
  walletCore.on("readyStateChange", handleReadyStateChange);
242
+ walletCore.on("standardWalletsAdded", handleStandardWalletsAdded);
226
243
  return () => {
227
244
  walletCore.off("connect", handleConnect);
228
245
  walletCore.off("disconnect", handleDisconnect);
229
246
  walletCore.off("accountChange", handleAccountChange);
230
247
  walletCore.off("networkChange", handleNetworkChange);
231
248
  walletCore.off("readyStateChange", handleReadyStateChange);
249
+ walletCore.off("standardWalletsAdded", handleStandardWalletsAdded);
232
250
  };
233
- }, [...wallets, connected]);
251
+ }, [wallets, connected]);
234
252
 
235
253
  return (
236
254
  <WalletContext.Provider
package/src/index.tsx CHANGED
@@ -3,6 +3,9 @@ export { useWallet } from "./useWallet";
3
3
  export * from "./WalletProvider";
4
4
  export type {
5
5
  Wallet,
6
+ AccountInfo,
7
+ NetworkInfo,
8
+ WalletInfo,
6
9
  WalletName,
7
10
  InputTransactionData,
8
11
  } from "@aptos-labs/wallet-adapter-core";
package/src/useWallet.tsx CHANGED
@@ -24,7 +24,7 @@ export interface WalletContextState {
24
24
  connect(walletName: WalletName): void;
25
25
  disconnect(): void;
26
26
  wallet: WalletInfo | null;
27
- wallets: ReadonlyArray<Wallet>;
27
+ wallets?: ReadonlyArray<Wallet>;
28
28
  signAndSubmitTransaction(transaction: InputTransactionData): Promise<any>;
29
29
  signTransaction(
30
30
  transactionOrPayload: AnyRawTransaction | Types.TransactionPayload,