@aptos-labs/wallet-adapter-react 1.2.2 → 1.3.0

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,25 @@
1
1
  # @aptos-labs/wallet-adapter-react
2
2
 
3
+ ## 1.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 3834890: Add an optional `onError` prop to error handle wallet callbacks
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [d2a0bbd]
12
+ - Updated dependencies [b0586e8]
13
+ - @aptos-labs/wallet-adapter-core@2.4.0
14
+
15
+ ## 1.2.3
16
+
17
+ ### Patch Changes
18
+
19
+ - dc98bf4: fix sendAndSubmitTransaction params
20
+ - Updated dependencies [dc98bf4]
21
+ - @aptos-labs/wallet-adapter-core@2.3.3
22
+
3
23
  ## 1.2.2
4
24
 
5
25
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AccountInfo, NetworkInfo, WalletName, WalletInfo, Wallet, SignMessagePayload, SignMessageResponse } from '@aptos-labs/wallet-adapter-core';
1
+ import { AccountInfo, NetworkInfo, WalletName, WalletInfo, Wallet, TransactionOptions, SignMessagePayload, SignMessageResponse } from '@aptos-labs/wallet-adapter-core';
2
2
  export { NetworkName, Wallet, WalletName, WalletReadyState, isInAppBrowser, isMobile, isRedirectable } from '@aptos-labs/wallet-adapter-core';
3
3
  import { Types, TxnBuilderTypes } from 'aptos';
4
4
  import { ReactNode, FC } from 'react';
@@ -12,9 +12,9 @@ interface WalletContextState {
12
12
  disconnect(): void;
13
13
  wallet: WalletInfo | null;
14
14
  wallets: ReadonlyArray<Wallet>;
15
- signAndSubmitTransaction<T extends Types.TransactionPayload, V>(transaction: T, options?: V): Promise<any>;
16
- signAndSubmitBCSTransaction<T extends TxnBuilderTypes.TransactionPayload, V>(transaction: T, options?: V): Promise<any>;
17
- signTransaction<T extends Types.TransactionPayload, V>(transaction: T, options?: V): Promise<any>;
15
+ signAndSubmitTransaction<T extends Types.TransactionPayload>(transaction: T, options?: TransactionOptions): Promise<any>;
16
+ signAndSubmitBCSTransaction<T extends TxnBuilderTypes.TransactionPayload>(transaction: T, options?: TransactionOptions): Promise<any>;
17
+ signTransaction<T extends Types.TransactionPayload>(transaction: T, options?: TransactionOptions): Promise<any>;
18
18
  signMessage(message: SignMessagePayload): Promise<SignMessageResponse | null>;
19
19
  signMessageAndVerify(message: SignMessagePayload): Promise<boolean>;
20
20
  }
@@ -24,6 +24,7 @@ interface AptosWalletProviderProps {
24
24
  children: ReactNode;
25
25
  plugins: ReadonlyArray<Wallet>;
26
26
  autoConnect?: boolean;
27
+ onError?: (error: any) => void;
27
28
  }
28
29
  declare const AptosWalletAdapterProvider: FC<AptosWalletProviderProps>;
29
30
 
package/dist/index.js CHANGED
@@ -60,7 +60,8 @@ var initialState = {
60
60
  var AptosWalletAdapterProvider = ({
61
61
  children,
62
62
  plugins,
63
- autoConnect = false
63
+ autoConnect = false,
64
+ onError
64
65
  }) => {
65
66
  const [{ connected, account, network, wallet }, setState] = (0, import_react2.useState)(initialState);
66
67
  const [isLoading, setIsLoading] = (0, import_react2.useState)(true);
@@ -74,7 +75,10 @@ var AptosWalletAdapterProvider = ({
74
75
  await walletCore.connect(walletName);
75
76
  } catch (error) {
76
77
  console.log("connect error", error);
77
- throw error;
78
+ if (onError)
79
+ onError(error);
80
+ else
81
+ throw error;
78
82
  } finally {
79
83
  setIsLoading(false);
80
84
  }
@@ -84,41 +88,57 @@ var AptosWalletAdapterProvider = ({
84
88
  await walletCore.disconnect();
85
89
  } catch (e) {
86
90
  console.log("disconnect error", e);
91
+ if (onError)
92
+ onError(e);
87
93
  }
88
94
  };
89
- const signAndSubmitTransaction = async (transaction) => {
95
+ const signAndSubmitTransaction = async (transaction, options) => {
90
96
  try {
91
- return await walletCore.signAndSubmitTransaction(transaction);
97
+ return await walletCore.signAndSubmitTransaction(transaction, options);
92
98
  } catch (error) {
93
- throw error;
99
+ if (onError)
100
+ onError(error);
101
+ else
102
+ throw error;
94
103
  }
95
104
  };
96
- const signAndSubmitBCSTransaction = async (transaction) => {
105
+ const signAndSubmitBCSTransaction = async (transaction, options) => {
97
106
  try {
98
- return await walletCore.signAndSubmitBCSTransaction(transaction);
107
+ return await walletCore.signAndSubmitBCSTransaction(transaction, options);
99
108
  } catch (error) {
100
109
  throw error;
101
110
  }
102
111
  };
103
- const signTransaction = async (transaction) => {
112
+ const signTransaction = async (transaction, options) => {
104
113
  try {
105
- return await walletCore.signTransaction(transaction);
114
+ return await walletCore.signTransaction(transaction, options);
106
115
  } catch (error) {
107
- throw error;
116
+ if (onError)
117
+ onError(error);
118
+ else
119
+ throw error;
108
120
  }
109
121
  };
110
122
  const signMessage = async (message) => {
111
123
  try {
112
124
  return await walletCore.signMessage(message);
113
125
  } catch (error) {
114
- throw error;
126
+ if (onError)
127
+ onError(error);
128
+ else
129
+ throw error;
130
+ return null;
115
131
  }
116
132
  };
117
133
  const signMessageAndVerify = async (message) => {
118
134
  try {
119
135
  return await walletCore.signMessageAndVerify(message);
120
136
  } catch (error) {
121
- throw error;
137
+ if (onError)
138
+ onError(error);
139
+ else
140
+ throw error;
141
+ return false;
122
142
  }
123
143
  };
124
144
  (0, import_react2.useEffect)(() => {
package/dist/index.mjs CHANGED
@@ -39,7 +39,8 @@ var initialState = {
39
39
  var AptosWalletAdapterProvider = ({
40
40
  children,
41
41
  plugins,
42
- autoConnect = false
42
+ autoConnect = false,
43
+ onError
43
44
  }) => {
44
45
  const [{ connected, account, network, wallet }, setState] = useState(initialState);
45
46
  const [isLoading, setIsLoading] = useState(true);
@@ -53,7 +54,10 @@ var AptosWalletAdapterProvider = ({
53
54
  await walletCore.connect(walletName);
54
55
  } catch (error) {
55
56
  console.log("connect error", error);
56
- throw error;
57
+ if (onError)
58
+ onError(error);
59
+ else
60
+ throw error;
57
61
  } finally {
58
62
  setIsLoading(false);
59
63
  }
@@ -63,41 +67,57 @@ var AptosWalletAdapterProvider = ({
63
67
  await walletCore.disconnect();
64
68
  } catch (e) {
65
69
  console.log("disconnect error", e);
70
+ if (onError)
71
+ onError(e);
66
72
  }
67
73
  };
68
- const signAndSubmitTransaction = async (transaction) => {
74
+ const signAndSubmitTransaction = async (transaction, options) => {
69
75
  try {
70
- return await walletCore.signAndSubmitTransaction(transaction);
76
+ return await walletCore.signAndSubmitTransaction(transaction, options);
71
77
  } catch (error) {
72
- throw error;
78
+ if (onError)
79
+ onError(error);
80
+ else
81
+ throw error;
73
82
  }
74
83
  };
75
- const signAndSubmitBCSTransaction = async (transaction) => {
84
+ const signAndSubmitBCSTransaction = async (transaction, options) => {
76
85
  try {
77
- return await walletCore.signAndSubmitBCSTransaction(transaction);
86
+ return await walletCore.signAndSubmitBCSTransaction(transaction, options);
78
87
  } catch (error) {
79
88
  throw error;
80
89
  }
81
90
  };
82
- const signTransaction = async (transaction) => {
91
+ const signTransaction = async (transaction, options) => {
83
92
  try {
84
- return await walletCore.signTransaction(transaction);
93
+ return await walletCore.signTransaction(transaction, options);
85
94
  } catch (error) {
86
- throw error;
95
+ if (onError)
96
+ onError(error);
97
+ else
98
+ throw error;
87
99
  }
88
100
  };
89
101
  const signMessage = async (message) => {
90
102
  try {
91
103
  return await walletCore.signMessage(message);
92
104
  } catch (error) {
93
- throw error;
105
+ if (onError)
106
+ onError(error);
107
+ else
108
+ throw error;
109
+ return null;
94
110
  }
95
111
  };
96
112
  const signMessageAndVerify = async (message) => {
97
113
  try {
98
114
  return await walletCore.signMessageAndVerify(message);
99
115
  } catch (error) {
100
- throw error;
116
+ if (onError)
117
+ onError(error);
118
+ else
119
+ throw error;
120
+ return false;
101
121
  }
102
122
  };
103
123
  useEffect(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aptos-labs/wallet-adapter-react",
3
- "version": "1.2.2",
3
+ "version": "1.3.0",
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": "2.3.2",
40
+ "@aptos-labs/wallet-adapter-core": "2.4.0",
41
41
  "aptos": "^1.3.17",
42
42
  "react": "^18"
43
43
  },
@@ -14,6 +14,7 @@ import type {
14
14
  Wallet,
15
15
  WalletInfo,
16
16
  WalletName,
17
+ TransactionOptions,
17
18
  } from "@aptos-labs/wallet-adapter-core";
18
19
  import { WalletCore } from "@aptos-labs/wallet-adapter-core";
19
20
 
@@ -23,6 +24,7 @@ export interface AptosWalletProviderProps {
23
24
  children: ReactNode;
24
25
  plugins: ReadonlyArray<Wallet>;
25
26
  autoConnect?: boolean;
27
+ onError?: (error: any) => void;
26
28
  }
27
29
 
28
30
  const initialState: {
@@ -41,6 +43,7 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
41
43
  children,
42
44
  plugins,
43
45
  autoConnect = false,
46
+ onError,
44
47
  }: AptosWalletProviderProps) => {
45
48
  const [{ connected, account, network, wallet }, setState] =
46
49
  useState(initialState);
@@ -60,7 +63,8 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
60
63
  await walletCore.connect(walletName);
61
64
  } catch (error: any) {
62
65
  console.log("connect error", error);
63
- throw error;
66
+ if (onError) onError(error);
67
+ else throw error;
64
68
  } finally {
65
69
  setIsLoading(false);
66
70
  }
@@ -71,34 +75,42 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
71
75
  await walletCore.disconnect();
72
76
  } catch (e) {
73
77
  console.log("disconnect error", e);
78
+ if (onError) onError(e);
74
79
  }
75
80
  };
76
81
 
77
82
  const signAndSubmitTransaction = async (
78
- transaction: Types.TransactionPayload
83
+ transaction: Types.TransactionPayload,
84
+ options?: TransactionOptions
79
85
  ) => {
80
86
  try {
81
- return await walletCore.signAndSubmitTransaction(transaction);
87
+ return await walletCore.signAndSubmitTransaction(transaction, options);
82
88
  } catch (error: any) {
83
- throw error;
89
+ if (onError) onError(error);
90
+ else throw error;
84
91
  }
85
92
  };
86
93
 
87
94
  const signAndSubmitBCSTransaction = async (
88
- transaction: TxnBuilderTypes.TransactionPayload
95
+ transaction: TxnBuilderTypes.TransactionPayload,
96
+ options?: TransactionOptions
89
97
  ) => {
90
98
  try {
91
- return await walletCore.signAndSubmitBCSTransaction(transaction);
99
+ return await walletCore.signAndSubmitBCSTransaction(transaction, options);
92
100
  } catch (error: any) {
93
101
  throw error;
94
102
  }
95
103
  };
96
104
 
97
- const signTransaction = async (transaction: Types.TransactionPayload) => {
105
+ const signTransaction = async (
106
+ transaction: Types.TransactionPayload,
107
+ options?: TransactionOptions
108
+ ) => {
98
109
  try {
99
- return await walletCore.signTransaction(transaction);
110
+ return await walletCore.signTransaction(transaction, options);
100
111
  } catch (error: any) {
101
- throw error;
112
+ if (onError) onError(error);
113
+ else throw error;
102
114
  }
103
115
  };
104
116
 
@@ -106,7 +118,9 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
106
118
  try {
107
119
  return await walletCore.signMessage(message);
108
120
  } catch (error: any) {
109
- throw error;
121
+ if (onError) onError(error);
122
+ else throw error;
123
+ return null;
110
124
  }
111
125
  };
112
126
 
@@ -114,7 +128,9 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
114
128
  try {
115
129
  return await walletCore.signMessageAndVerify(message);
116
130
  } catch (error: any) {
117
- throw error;
131
+ if (onError) onError(error);
132
+ else throw error;
133
+ return false;
118
134
  }
119
135
  };
120
136
 
package/src/useWallet.tsx CHANGED
@@ -11,6 +11,7 @@ import {
11
11
  isInAppBrowser,
12
12
  isRedirectable,
13
13
  isMobile,
14
+ TransactionOptions,
14
15
  } from "@aptos-labs/wallet-adapter-core";
15
16
  import { createContext, useContext } from "react";
16
17
  import { TxnBuilderTypes, Types } from "aptos";
@@ -33,17 +34,17 @@ export interface WalletContextState {
33
34
  disconnect(): void;
34
35
  wallet: WalletInfo | null;
35
36
  wallets: ReadonlyArray<Wallet>;
36
- signAndSubmitTransaction<T extends Types.TransactionPayload, V>(
37
+ signAndSubmitTransaction<T extends Types.TransactionPayload>(
37
38
  transaction: T,
38
- options?: V
39
+ options?: TransactionOptions
39
40
  ): Promise<any>;
40
- signAndSubmitBCSTransaction<T extends TxnBuilderTypes.TransactionPayload, V>(
41
+ signAndSubmitBCSTransaction<T extends TxnBuilderTypes.TransactionPayload>(
41
42
  transaction: T,
42
- options?: V
43
+ options?: TransactionOptions
43
44
  ): Promise<any>;
44
- signTransaction<T extends Types.TransactionPayload, V>(
45
+ signTransaction<T extends Types.TransactionPayload>(
45
46
  transaction: T,
46
- options?: V
47
+ options?: TransactionOptions
47
48
  ): Promise<any>;
48
49
  signMessage(message: SignMessagePayload): Promise<SignMessageResponse | null>;
49
50
  signMessageAndVerify(message: SignMessagePayload): Promise<boolean>;