@aptos-labs/wallet-adapter-core 2.3.1 → 2.3.3

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,17 @@
1
1
  # @aptos-labs/wallet-adapter-core
2
2
 
3
+ ## 2.3.3
4
+
5
+ ### Patch Changes
6
+
7
+ - dc98bf4: fix sendAndSubmitTransaction params
8
+
9
+ ## 2.3.2
10
+
11
+ ### Patch Changes
12
+
13
+ - 22ecf6a: Throw `wallet already connected` error when trying to connect to an already connected wallet
14
+
3
15
  ## 2.3.1
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -114,6 +114,10 @@ interface SignMessageResponse {
114
114
  signature: string | string[];
115
115
  bitmap?: Uint8Array;
116
116
  }
117
+ interface TransactionOptions {
118
+ max_gas_amount?: bigint;
119
+ gas_unit_price?: bigint;
120
+ }
117
121
 
118
122
  declare class WalletCore extends EventEmitter<WalletCoreEvents> {
119
123
  private _wallets;
@@ -160,7 +164,7 @@ declare class WalletCore extends EventEmitter<WalletCoreEvents> {
160
164
  @emit emits "connect" event
161
165
  @throws WalletConnectionError
162
166
  */
163
- connect(walletName: WalletName): Promise<void>;
167
+ connect(walletName: WalletName): Promise<void | string>;
164
168
  /**
165
169
  Disconnect the exisitng wallet. On success, we clear the
166
170
  current account, current network and LocalStorage data.
@@ -171,24 +175,27 @@ declare class WalletCore extends EventEmitter<WalletCoreEvents> {
171
175
  /**
172
176
  Sign and submit an entry (not bcs serialized) transaction type to chain.
173
177
  @param transaction a non-bcs serialized transaction
178
+ @param options max_gas_amount and gas_unit_limit
174
179
  @return response from the wallet's signAndSubmitTransaction function
175
180
  @throws WalletSignAndSubmitMessageError
176
181
  */
177
- signAndSubmitTransaction(transaction: Types.TransactionPayload): Promise<any>;
182
+ signAndSubmitTransaction(transaction: Types.TransactionPayload, options?: TransactionOptions): Promise<any>;
178
183
  /**
179
184
  Sign and submit a bsc serialized transaction type to chain.
180
185
  @param transaction a bcs serialized transaction
186
+ @param options max_gas_amount and gas_unit_limit
181
187
  @return response from the wallet's signAndSubmitBCSTransaction function
182
188
  @throws WalletSignAndSubmitMessageError
183
189
  */
184
- signAndSubmitBCSTransaction(transaction: TxnBuilderTypes.TransactionPayload): Promise<any>;
190
+ signAndSubmitBCSTransaction(transaction: TxnBuilderTypes.TransactionPayload, options?: TransactionOptions): Promise<any>;
185
191
  /**
186
192
  Sign transaction (doesnt submit to chain).
187
193
  @param transaction
194
+ @param options max_gas_amount and gas_unit_limit
188
195
  @return response from the wallet's signTransaction function
189
196
  @throws WalletSignTransactionError
190
197
  */
191
- signTransaction(transaction: Types.TransactionPayload): Promise<Uint8Array | null>;
198
+ signTransaction(transaction: Types.TransactionPayload, options?: TransactionOptions): Promise<Uint8Array | null>;
192
199
  /**
193
200
  Sign message (doesnt submit to chain).
194
201
  @param message
@@ -221,4 +228,4 @@ declare function isMobile(): boolean;
221
228
  declare function isInAppBrowser(): boolean;
222
229
  declare function isRedirectable(): boolean;
223
230
 
224
- export { AccountInfo, AdapterPlugin, AdapterPluginEvents, AdapterPluginProps, AptosWalletErrorResult, NetworkInfo, NetworkName, PluginProvider, SignMessagePayload, SignMessageResponse, Wallet, WalletCore, WalletCoreEvents, WalletInfo, WalletName, WalletReadyState, getLocalStorage, isInAppBrowser, isMobile, isRedirectable, removeLocalStorage, scopePollingDetectionStrategy, setLocalStorage };
231
+ export { AccountInfo, AdapterPlugin, AdapterPluginEvents, AdapterPluginProps, AptosWalletErrorResult, NetworkInfo, NetworkName, PluginProvider, SignMessagePayload, SignMessageResponse, TransactionOptions, Wallet, WalletCore, WalletCoreEvents, WalletInfo, WalletName, WalletReadyState, getLocalStorage, isInAppBrowser, isMobile, isRedirectable, removeLocalStorage, scopePollingDetectionStrategy, setLocalStorage };
package/dist/index.js CHANGED
@@ -344,7 +344,9 @@ var WalletCore = class extends import_eventemitter3.default {
344
344
  return;
345
345
  if (this._connected) {
346
346
  if (((_b = this.wallet) == null ? void 0 : _b.name) === walletName)
347
- return;
347
+ throw new WalletConnectionError(
348
+ `${walletName} wallet is already connected`
349
+ ).message;
348
350
  await this.disconnect();
349
351
  }
350
352
  if (isRedirectable()) {
@@ -385,12 +387,13 @@ var WalletCore = class extends import_eventemitter3.default {
385
387
  throw new WalletDisconnectionError(error).message;
386
388
  }
387
389
  }
388
- async signAndSubmitTransaction(transaction) {
390
+ async signAndSubmitTransaction(transaction, options) {
389
391
  var _a;
390
392
  try {
391
393
  this.doesWalletExist();
392
394
  const response = await ((_a = this._wallet) == null ? void 0 : _a.signAndSubmitTransaction(
393
- transaction
395
+ transaction,
396
+ options
394
397
  ));
395
398
  return response;
396
399
  } catch (error) {
@@ -398,7 +401,7 @@ var WalletCore = class extends import_eventemitter3.default {
398
401
  throw new WalletSignAndSubmitMessageError(errMsg).message;
399
402
  }
400
403
  }
401
- async signAndSubmitBCSTransaction(transaction) {
404
+ async signAndSubmitBCSTransaction(transaction, options) {
402
405
  var _a;
403
406
  if (this._wallet && !("signAndSubmitBCSTransaction" in this._wallet)) {
404
407
  throw new WalletNotSupportedMethod(
@@ -408,7 +411,8 @@ var WalletCore = class extends import_eventemitter3.default {
408
411
  try {
409
412
  this.doesWalletExist();
410
413
  const response = await this._wallet.signAndSubmitBCSTransaction(
411
- transaction
414
+ transaction,
415
+ options
412
416
  );
413
417
  return response;
414
418
  } catch (error) {
@@ -416,7 +420,7 @@ var WalletCore = class extends import_eventemitter3.default {
416
420
  throw new WalletSignAndSubmitMessageError(errMsg).message;
417
421
  }
418
422
  }
419
- async signTransaction(transaction) {
423
+ async signTransaction(transaction, options) {
420
424
  var _a;
421
425
  if (this._wallet && !("signTransaction" in this._wallet)) {
422
426
  throw new WalletNotSupportedMethod(
@@ -425,7 +429,7 @@ var WalletCore = class extends import_eventemitter3.default {
425
429
  }
426
430
  try {
427
431
  this.doesWalletExist();
428
- const response = await this._wallet.signTransaction(transaction);
432
+ const response = await this._wallet.signTransaction(transaction, options);
429
433
  return response;
430
434
  } catch (error) {
431
435
  const errMsg = typeof error == "object" && "message" in error ? error.message : error;
package/dist/index.mjs CHANGED
@@ -303,7 +303,9 @@ var WalletCore = class extends EventEmitter {
303
303
  return;
304
304
  if (this._connected) {
305
305
  if (((_b = this.wallet) == null ? void 0 : _b.name) === walletName)
306
- return;
306
+ throw new WalletConnectionError(
307
+ `${walletName} wallet is already connected`
308
+ ).message;
307
309
  await this.disconnect();
308
310
  }
309
311
  if (isRedirectable()) {
@@ -344,12 +346,13 @@ var WalletCore = class extends EventEmitter {
344
346
  throw new WalletDisconnectionError(error).message;
345
347
  }
346
348
  }
347
- async signAndSubmitTransaction(transaction) {
349
+ async signAndSubmitTransaction(transaction, options) {
348
350
  var _a;
349
351
  try {
350
352
  this.doesWalletExist();
351
353
  const response = await ((_a = this._wallet) == null ? void 0 : _a.signAndSubmitTransaction(
352
- transaction
354
+ transaction,
355
+ options
353
356
  ));
354
357
  return response;
355
358
  } catch (error) {
@@ -357,7 +360,7 @@ var WalletCore = class extends EventEmitter {
357
360
  throw new WalletSignAndSubmitMessageError(errMsg).message;
358
361
  }
359
362
  }
360
- async signAndSubmitBCSTransaction(transaction) {
363
+ async signAndSubmitBCSTransaction(transaction, options) {
361
364
  var _a;
362
365
  if (this._wallet && !("signAndSubmitBCSTransaction" in this._wallet)) {
363
366
  throw new WalletNotSupportedMethod(
@@ -367,7 +370,8 @@ var WalletCore = class extends EventEmitter {
367
370
  try {
368
371
  this.doesWalletExist();
369
372
  const response = await this._wallet.signAndSubmitBCSTransaction(
370
- transaction
373
+ transaction,
374
+ options
371
375
  );
372
376
  return response;
373
377
  } catch (error) {
@@ -375,7 +379,7 @@ var WalletCore = class extends EventEmitter {
375
379
  throw new WalletSignAndSubmitMessageError(errMsg).message;
376
380
  }
377
381
  }
378
- async signTransaction(transaction) {
382
+ async signTransaction(transaction, options) {
379
383
  var _a;
380
384
  if (this._wallet && !("signTransaction" in this._wallet)) {
381
385
  throw new WalletNotSupportedMethod(
@@ -384,7 +388,7 @@ var WalletCore = class extends EventEmitter {
384
388
  }
385
389
  try {
386
390
  this.doesWalletExist();
387
- const response = await this._wallet.signTransaction(transaction);
391
+ const response = await this._wallet.signTransaction(transaction, options);
388
392
  return response;
389
393
  } catch (error) {
390
394
  const errMsg = typeof error == "object" && "message" in error ? error.message : error;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aptos-labs/wallet-adapter-core",
3
- "version": "2.3.1",
3
+ "version": "2.3.3",
4
4
  "description": "Aptos Wallet Adapter Core",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
package/src/WalletCore.ts CHANGED
@@ -29,6 +29,7 @@ import {
29
29
  Wallet,
30
30
  WalletInfo,
31
31
  WalletCoreEvents,
32
+ TransactionOptions,
32
33
  } from "./types";
33
34
  import {
34
35
  removeLocalStorage,
@@ -181,7 +182,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
181
182
  @emit emits "connect" event
182
183
  @throws WalletConnectionError
183
184
  */
184
- async connect(walletName: WalletName): Promise<void> {
185
+ async connect(walletName: WalletName): Promise<void | string> {
185
186
  try {
186
187
  const selectedWallet = this._wallets?.find(
187
188
  (wallet: Wallet) => wallet.name === walletName
@@ -191,7 +192,10 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
191
192
 
192
193
  if (this._connected) {
193
194
  // if the selected wallet is already connected, we don't need to connect again
194
- if (this.wallet?.name === walletName) return;
195
+ if (this.wallet?.name === walletName)
196
+ throw new WalletConnectionError(
197
+ `${walletName} wallet is already connected`
198
+ ).message;
195
199
 
196
200
  await this.disconnect();
197
201
  }
@@ -251,16 +255,19 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
251
255
  /**
252
256
  Sign and submit an entry (not bcs serialized) transaction type to chain.
253
257
  @param transaction a non-bcs serialized transaction
258
+ @param options max_gas_amount and gas_unit_limit
254
259
  @return response from the wallet's signAndSubmitTransaction function
255
260
  @throws WalletSignAndSubmitMessageError
256
261
  */
257
262
  async signAndSubmitTransaction(
258
- transaction: Types.TransactionPayload
263
+ transaction: Types.TransactionPayload,
264
+ options?: TransactionOptions
259
265
  ): Promise<any> {
260
266
  try {
261
267
  this.doesWalletExist();
262
268
  const response = await this._wallet?.signAndSubmitTransaction(
263
- transaction
269
+ transaction,
270
+ options
264
271
  );
265
272
  return response;
266
273
  } catch (error: any) {
@@ -273,11 +280,13 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
273
280
  /**
274
281
  Sign and submit a bsc serialized transaction type to chain.
275
282
  @param transaction a bcs serialized transaction
283
+ @param options max_gas_amount and gas_unit_limit
276
284
  @return response from the wallet's signAndSubmitBCSTransaction function
277
285
  @throws WalletSignAndSubmitMessageError
278
286
  */
279
287
  async signAndSubmitBCSTransaction(
280
- transaction: TxnBuilderTypes.TransactionPayload
288
+ transaction: TxnBuilderTypes.TransactionPayload,
289
+ options?: TransactionOptions
281
290
  ): Promise<any> {
282
291
  if (this._wallet && !("signAndSubmitBCSTransaction" in this._wallet)) {
283
292
  throw new WalletNotSupportedMethod(
@@ -288,7 +297,8 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
288
297
  try {
289
298
  this.doesWalletExist();
290
299
  const response = await (this._wallet as any).signAndSubmitBCSTransaction(
291
- transaction
300
+ transaction,
301
+ options
292
302
  );
293
303
  return response;
294
304
  } catch (error: any) {
@@ -301,11 +311,13 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
301
311
  /**
302
312
  Sign transaction (doesnt submit to chain).
303
313
  @param transaction
314
+ @param options max_gas_amount and gas_unit_limit
304
315
  @return response from the wallet's signTransaction function
305
316
  @throws WalletSignTransactionError
306
317
  */
307
318
  async signTransaction(
308
- transaction: Types.TransactionPayload
319
+ transaction: Types.TransactionPayload,
320
+ options?: TransactionOptions
309
321
  ): Promise<Uint8Array | null> {
310
322
  if (this._wallet && !("signTransaction" in this._wallet)) {
311
323
  throw new WalletNotSupportedMethod(
@@ -315,7 +327,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
315
327
 
316
328
  try {
317
329
  this.doesWalletExist();
318
- const response = await (this._wallet as any).signTransaction(transaction);
330
+ const response = await (this._wallet as any).signTransaction(transaction, options);
319
331
  return response;
320
332
  } catch (error: any) {
321
333
  const errMsg =
package/src/types.ts CHANGED
@@ -106,3 +106,8 @@ export interface SignMessageResponse {
106
106
  signature: string | string[]; // The signed full message
107
107
  bitmap?: Uint8Array; // a 4-byte (32 bits) bit-vector of length N
108
108
  }
109
+
110
+ export interface TransactionOptions {
111
+ max_gas_amount?: bigint;
112
+ gas_unit_price?: bigint;
113
+ }