@aptos-labs/wallet-adapter-core 2.3.2 → 2.4.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 +16 -0
- package/dist/index.d.ts +25 -13
- package/dist/index.js +40 -31
- package/dist/index.mjs +40 -31
- package/package.json +1 -1
- package/src/WalletCore.ts +71 -48
- package/src/types.ts +5 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @aptos-labs/wallet-adapter-core
|
|
2
2
|
|
|
3
|
+
## 2.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- d2a0bbd: Support error message on connect and disconnect functions
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- b0586e8: Separate connect and connectWallet for SRP
|
|
12
|
+
|
|
13
|
+
## 2.3.3
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- dc98bf4: fix sendAndSubmitTransaction params
|
|
18
|
+
|
|
3
19
|
## 2.3.2
|
|
4
20
|
|
|
5
21
|
### 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;
|
|
@@ -151,16 +155,21 @@ declare class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
151
155
|
*/
|
|
152
156
|
get network(): NetworkInfo | null;
|
|
153
157
|
/**
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
@param walletName. The wallet name we want to connect as a WalletName type.
|
|
160
|
-
@emit emits "connect" event
|
|
161
|
-
@throws WalletConnectionError
|
|
162
|
-
*/
|
|
158
|
+
* We first make sure we can connect a dapp to a wallet.
|
|
159
|
+
* If all good, we connect the wallet by calling `this.connectWallet`
|
|
160
|
+
* @param walletName. The wallet name we want to connect.
|
|
161
|
+
*/
|
|
163
162
|
connect(walletName: WalletName): Promise<void | string>;
|
|
163
|
+
/**
|
|
164
|
+
* Connects a wallet to the dapp.
|
|
165
|
+
* On connect success, we set the current account and the network, and keeping the selected wallet
|
|
166
|
+
* name in LocalStorage to support autoConnect function.
|
|
167
|
+
*
|
|
168
|
+
* @param selectedWallet. The wallet we want to connect.
|
|
169
|
+
* @emit emits "connect" event
|
|
170
|
+
* @throws WalletConnectionError
|
|
171
|
+
*/
|
|
172
|
+
connectWallet(selectedWallet: Wallet): Promise<void>;
|
|
164
173
|
/**
|
|
165
174
|
Disconnect the exisitng wallet. On success, we clear the
|
|
166
175
|
current account, current network and LocalStorage data.
|
|
@@ -171,24 +180,27 @@ declare class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
171
180
|
/**
|
|
172
181
|
Sign and submit an entry (not bcs serialized) transaction type to chain.
|
|
173
182
|
@param transaction a non-bcs serialized transaction
|
|
183
|
+
@param options max_gas_amount and gas_unit_limit
|
|
174
184
|
@return response from the wallet's signAndSubmitTransaction function
|
|
175
185
|
@throws WalletSignAndSubmitMessageError
|
|
176
186
|
*/
|
|
177
|
-
signAndSubmitTransaction(transaction: Types.TransactionPayload): Promise<any>;
|
|
187
|
+
signAndSubmitTransaction(transaction: Types.TransactionPayload, options?: TransactionOptions): Promise<any>;
|
|
178
188
|
/**
|
|
179
189
|
Sign and submit a bsc serialized transaction type to chain.
|
|
180
190
|
@param transaction a bcs serialized transaction
|
|
191
|
+
@param options max_gas_amount and gas_unit_limit
|
|
181
192
|
@return response from the wallet's signAndSubmitBCSTransaction function
|
|
182
193
|
@throws WalletSignAndSubmitMessageError
|
|
183
194
|
*/
|
|
184
|
-
signAndSubmitBCSTransaction(transaction: TxnBuilderTypes.TransactionPayload): Promise<any>;
|
|
195
|
+
signAndSubmitBCSTransaction(transaction: TxnBuilderTypes.TransactionPayload, options?: TransactionOptions): Promise<any>;
|
|
185
196
|
/**
|
|
186
197
|
Sign transaction (doesnt submit to chain).
|
|
187
198
|
@param transaction
|
|
199
|
+
@param options max_gas_amount and gas_unit_limit
|
|
188
200
|
@return response from the wallet's signTransaction function
|
|
189
201
|
@throws WalletSignTransactionError
|
|
190
202
|
*/
|
|
191
|
-
signTransaction(transaction: Types.TransactionPayload): Promise<Uint8Array | null>;
|
|
203
|
+
signTransaction(transaction: Types.TransactionPayload, options?: TransactionOptions): Promise<Uint8Array | null>;
|
|
192
204
|
/**
|
|
193
205
|
Sign message (doesnt submit to chain).
|
|
194
206
|
@param message
|
|
@@ -221,4 +233,4 @@ declare function isMobile(): boolean;
|
|
|
221
233
|
declare function isInAppBrowser(): boolean;
|
|
222
234
|
declare function isRedirectable(): boolean;
|
|
223
235
|
|
|
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 };
|
|
236
|
+
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
|
@@ -335,30 +335,32 @@ var WalletCore = class extends import_eventemitter3.default {
|
|
|
335
335
|
}
|
|
336
336
|
}
|
|
337
337
|
async connect(walletName) {
|
|
338
|
-
var _a
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
if (
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
const location = selectedWallet.deeplinkProvider({ url });
|
|
356
|
-
window.location.href = location;
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
if (selectedWallet.readyState !== "Installed" /* Installed */ && selectedWallet.readyState !== "Loadable" /* Loadable */) {
|
|
360
|
-
return;
|
|
338
|
+
var _a;
|
|
339
|
+
const selectedWallet = (_a = this._wallets) == null ? void 0 : _a.find(
|
|
340
|
+
(wallet) => wallet.name === walletName
|
|
341
|
+
);
|
|
342
|
+
if (!selectedWallet)
|
|
343
|
+
return;
|
|
344
|
+
if (this._connected) {
|
|
345
|
+
if (selectedWallet.name === walletName)
|
|
346
|
+
throw new WalletConnectionError(
|
|
347
|
+
`${walletName} wallet is already connected`
|
|
348
|
+
).message;
|
|
349
|
+
}
|
|
350
|
+
if (isRedirectable()) {
|
|
351
|
+
if (selectedWallet.deeplinkProvider) {
|
|
352
|
+
const url = encodeURIComponent(window.location.href);
|
|
353
|
+
const location = selectedWallet.deeplinkProvider({ url });
|
|
354
|
+
window.location.href = location;
|
|
361
355
|
}
|
|
356
|
+
}
|
|
357
|
+
if (selectedWallet.readyState !== "Installed" /* Installed */ && selectedWallet.readyState !== "Loadable" /* Loadable */) {
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
await this.connectWallet(selectedWallet);
|
|
361
|
+
}
|
|
362
|
+
async connectWallet(selectedWallet) {
|
|
363
|
+
try {
|
|
362
364
|
this._connecting = true;
|
|
363
365
|
this.setWallet(selectedWallet);
|
|
364
366
|
const account = await selectedWallet.connect();
|
|
@@ -371,7 +373,8 @@ var WalletCore = class extends import_eventemitter3.default {
|
|
|
371
373
|
this.emit("connect", account);
|
|
372
374
|
} catch (error) {
|
|
373
375
|
this.clearData();
|
|
374
|
-
|
|
376
|
+
const errMsg = typeof error == "object" && "message" in error ? error.message : error;
|
|
377
|
+
throw new WalletConnectionError(errMsg).message;
|
|
375
378
|
} finally {
|
|
376
379
|
this._connecting = false;
|
|
377
380
|
}
|
|
@@ -384,15 +387,17 @@ var WalletCore = class extends import_eventemitter3.default {
|
|
|
384
387
|
this.clearData();
|
|
385
388
|
this.emit("disconnect");
|
|
386
389
|
} catch (error) {
|
|
387
|
-
|
|
390
|
+
const errMsg = typeof error == "object" && "message" in error ? error.message : error;
|
|
391
|
+
throw new WalletDisconnectionError(errMsg).message;
|
|
388
392
|
}
|
|
389
393
|
}
|
|
390
|
-
async signAndSubmitTransaction(transaction) {
|
|
394
|
+
async signAndSubmitTransaction(transaction, options) {
|
|
391
395
|
var _a;
|
|
392
396
|
try {
|
|
393
397
|
this.doesWalletExist();
|
|
394
398
|
const response = await ((_a = this._wallet) == null ? void 0 : _a.signAndSubmitTransaction(
|
|
395
|
-
transaction
|
|
399
|
+
transaction,
|
|
400
|
+
options
|
|
396
401
|
));
|
|
397
402
|
return response;
|
|
398
403
|
} catch (error) {
|
|
@@ -400,7 +405,7 @@ var WalletCore = class extends import_eventemitter3.default {
|
|
|
400
405
|
throw new WalletSignAndSubmitMessageError(errMsg).message;
|
|
401
406
|
}
|
|
402
407
|
}
|
|
403
|
-
async signAndSubmitBCSTransaction(transaction) {
|
|
408
|
+
async signAndSubmitBCSTransaction(transaction, options) {
|
|
404
409
|
var _a;
|
|
405
410
|
if (this._wallet && !("signAndSubmitBCSTransaction" in this._wallet)) {
|
|
406
411
|
throw new WalletNotSupportedMethod(
|
|
@@ -410,7 +415,8 @@ var WalletCore = class extends import_eventemitter3.default {
|
|
|
410
415
|
try {
|
|
411
416
|
this.doesWalletExist();
|
|
412
417
|
const response = await this._wallet.signAndSubmitBCSTransaction(
|
|
413
|
-
transaction
|
|
418
|
+
transaction,
|
|
419
|
+
options
|
|
414
420
|
);
|
|
415
421
|
return response;
|
|
416
422
|
} catch (error) {
|
|
@@ -418,7 +424,7 @@ var WalletCore = class extends import_eventemitter3.default {
|
|
|
418
424
|
throw new WalletSignAndSubmitMessageError(errMsg).message;
|
|
419
425
|
}
|
|
420
426
|
}
|
|
421
|
-
async signTransaction(transaction) {
|
|
427
|
+
async signTransaction(transaction, options) {
|
|
422
428
|
var _a;
|
|
423
429
|
if (this._wallet && !("signTransaction" in this._wallet)) {
|
|
424
430
|
throw new WalletNotSupportedMethod(
|
|
@@ -427,7 +433,10 @@ var WalletCore = class extends import_eventemitter3.default {
|
|
|
427
433
|
}
|
|
428
434
|
try {
|
|
429
435
|
this.doesWalletExist();
|
|
430
|
-
const response = await this._wallet.signTransaction(
|
|
436
|
+
const response = await this._wallet.signTransaction(
|
|
437
|
+
transaction,
|
|
438
|
+
options
|
|
439
|
+
);
|
|
431
440
|
return response;
|
|
432
441
|
} catch (error) {
|
|
433
442
|
const errMsg = typeof error == "object" && "message" in error ? error.message : error;
|
package/dist/index.mjs
CHANGED
|
@@ -294,30 +294,32 @@ var WalletCore = class extends EventEmitter {
|
|
|
294
294
|
}
|
|
295
295
|
}
|
|
296
296
|
async connect(walletName) {
|
|
297
|
-
var _a
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
if (
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
const location = selectedWallet.deeplinkProvider({ url });
|
|
315
|
-
window.location.href = location;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
if (selectedWallet.readyState !== "Installed" /* Installed */ && selectedWallet.readyState !== "Loadable" /* Loadable */) {
|
|
319
|
-
return;
|
|
297
|
+
var _a;
|
|
298
|
+
const selectedWallet = (_a = this._wallets) == null ? void 0 : _a.find(
|
|
299
|
+
(wallet) => wallet.name === walletName
|
|
300
|
+
);
|
|
301
|
+
if (!selectedWallet)
|
|
302
|
+
return;
|
|
303
|
+
if (this._connected) {
|
|
304
|
+
if (selectedWallet.name === walletName)
|
|
305
|
+
throw new WalletConnectionError(
|
|
306
|
+
`${walletName} wallet is already connected`
|
|
307
|
+
).message;
|
|
308
|
+
}
|
|
309
|
+
if (isRedirectable()) {
|
|
310
|
+
if (selectedWallet.deeplinkProvider) {
|
|
311
|
+
const url = encodeURIComponent(window.location.href);
|
|
312
|
+
const location = selectedWallet.deeplinkProvider({ url });
|
|
313
|
+
window.location.href = location;
|
|
320
314
|
}
|
|
315
|
+
}
|
|
316
|
+
if (selectedWallet.readyState !== "Installed" /* Installed */ && selectedWallet.readyState !== "Loadable" /* Loadable */) {
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
await this.connectWallet(selectedWallet);
|
|
320
|
+
}
|
|
321
|
+
async connectWallet(selectedWallet) {
|
|
322
|
+
try {
|
|
321
323
|
this._connecting = true;
|
|
322
324
|
this.setWallet(selectedWallet);
|
|
323
325
|
const account = await selectedWallet.connect();
|
|
@@ -330,7 +332,8 @@ var WalletCore = class extends EventEmitter {
|
|
|
330
332
|
this.emit("connect", account);
|
|
331
333
|
} catch (error) {
|
|
332
334
|
this.clearData();
|
|
333
|
-
|
|
335
|
+
const errMsg = typeof error == "object" && "message" in error ? error.message : error;
|
|
336
|
+
throw new WalletConnectionError(errMsg).message;
|
|
334
337
|
} finally {
|
|
335
338
|
this._connecting = false;
|
|
336
339
|
}
|
|
@@ -343,15 +346,17 @@ var WalletCore = class extends EventEmitter {
|
|
|
343
346
|
this.clearData();
|
|
344
347
|
this.emit("disconnect");
|
|
345
348
|
} catch (error) {
|
|
346
|
-
|
|
349
|
+
const errMsg = typeof error == "object" && "message" in error ? error.message : error;
|
|
350
|
+
throw new WalletDisconnectionError(errMsg).message;
|
|
347
351
|
}
|
|
348
352
|
}
|
|
349
|
-
async signAndSubmitTransaction(transaction) {
|
|
353
|
+
async signAndSubmitTransaction(transaction, options) {
|
|
350
354
|
var _a;
|
|
351
355
|
try {
|
|
352
356
|
this.doesWalletExist();
|
|
353
357
|
const response = await ((_a = this._wallet) == null ? void 0 : _a.signAndSubmitTransaction(
|
|
354
|
-
transaction
|
|
358
|
+
transaction,
|
|
359
|
+
options
|
|
355
360
|
));
|
|
356
361
|
return response;
|
|
357
362
|
} catch (error) {
|
|
@@ -359,7 +364,7 @@ var WalletCore = class extends EventEmitter {
|
|
|
359
364
|
throw new WalletSignAndSubmitMessageError(errMsg).message;
|
|
360
365
|
}
|
|
361
366
|
}
|
|
362
|
-
async signAndSubmitBCSTransaction(transaction) {
|
|
367
|
+
async signAndSubmitBCSTransaction(transaction, options) {
|
|
363
368
|
var _a;
|
|
364
369
|
if (this._wallet && !("signAndSubmitBCSTransaction" in this._wallet)) {
|
|
365
370
|
throw new WalletNotSupportedMethod(
|
|
@@ -369,7 +374,8 @@ var WalletCore = class extends EventEmitter {
|
|
|
369
374
|
try {
|
|
370
375
|
this.doesWalletExist();
|
|
371
376
|
const response = await this._wallet.signAndSubmitBCSTransaction(
|
|
372
|
-
transaction
|
|
377
|
+
transaction,
|
|
378
|
+
options
|
|
373
379
|
);
|
|
374
380
|
return response;
|
|
375
381
|
} catch (error) {
|
|
@@ -377,7 +383,7 @@ var WalletCore = class extends EventEmitter {
|
|
|
377
383
|
throw new WalletSignAndSubmitMessageError(errMsg).message;
|
|
378
384
|
}
|
|
379
385
|
}
|
|
380
|
-
async signTransaction(transaction) {
|
|
386
|
+
async signTransaction(transaction, options) {
|
|
381
387
|
var _a;
|
|
382
388
|
if (this._wallet && !("signTransaction" in this._wallet)) {
|
|
383
389
|
throw new WalletNotSupportedMethod(
|
|
@@ -386,7 +392,10 @@ var WalletCore = class extends EventEmitter {
|
|
|
386
392
|
}
|
|
387
393
|
try {
|
|
388
394
|
this.doesWalletExist();
|
|
389
|
-
const response = await this._wallet.signTransaction(
|
|
395
|
+
const response = await this._wallet.signTransaction(
|
|
396
|
+
transaction,
|
|
397
|
+
options
|
|
398
|
+
);
|
|
390
399
|
return response;
|
|
391
400
|
} catch (error) {
|
|
392
401
|
const errMsg = typeof error == "object" && "message" in error ? error.message : error;
|
package/package.json
CHANGED
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,
|
|
@@ -171,51 +172,58 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
171
172
|
}
|
|
172
173
|
}
|
|
173
174
|
|
|
174
|
-
/**
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
@param walletName. The wallet name we want to connect as a WalletName type.
|
|
181
|
-
@emit emits "connect" event
|
|
182
|
-
@throws WalletConnectionError
|
|
183
|
-
*/
|
|
175
|
+
/**
|
|
176
|
+
* We first make sure we can connect a dapp to a wallet.
|
|
177
|
+
* If all good, we connect the wallet by calling `this.connectWallet`
|
|
178
|
+
* @param walletName. The wallet name we want to connect.
|
|
179
|
+
*/
|
|
184
180
|
async connect(walletName: WalletName): Promise<void | string> {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
if
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
181
|
+
const selectedWallet = this._wallets?.find(
|
|
182
|
+
(wallet: Wallet) => wallet.name === walletName
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
if (!selectedWallet) return;
|
|
186
|
+
|
|
187
|
+
if (this._connected) {
|
|
188
|
+
// if the selected wallet is already connected, we don't need to connect again
|
|
189
|
+
if (selectedWallet.name === walletName)
|
|
190
|
+
throw new WalletConnectionError(
|
|
191
|
+
`${walletName} wallet is already connected`
|
|
192
|
+
).message;
|
|
193
|
+
}
|
|
198
194
|
|
|
199
|
-
|
|
195
|
+
// check if we are in a redirectable view (i.e on mobile AND not in an in-app browser) and
|
|
196
|
+
// since wallet readyState can be NotDetected, we check it before the next check
|
|
197
|
+
if (isRedirectable()) {
|
|
198
|
+
// use wallet deep link
|
|
199
|
+
if (selectedWallet.deeplinkProvider) {
|
|
200
|
+
const url = encodeURIComponent(window.location.href);
|
|
201
|
+
const location = selectedWallet.deeplinkProvider({ url });
|
|
202
|
+
window.location.href = location;
|
|
200
203
|
}
|
|
204
|
+
}
|
|
205
|
+
if (
|
|
206
|
+
selectedWallet.readyState !== WalletReadyState.Installed &&
|
|
207
|
+
selectedWallet.readyState !== WalletReadyState.Loadable
|
|
208
|
+
) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
201
211
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
// use wallet deep link
|
|
206
|
-
if (selectedWallet.deeplinkProvider) {
|
|
207
|
-
const url = encodeURIComponent(window.location.href);
|
|
208
|
-
const location = selectedWallet.deeplinkProvider({ url });
|
|
209
|
-
window.location.href = location;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
if (
|
|
213
|
-
selectedWallet.readyState !== WalletReadyState.Installed &&
|
|
214
|
-
selectedWallet.readyState !== WalletReadyState.Loadable
|
|
215
|
-
) {
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
212
|
+
// Now we can connect to the wallet
|
|
213
|
+
await this.connectWallet(selectedWallet);
|
|
214
|
+
}
|
|
218
215
|
|
|
216
|
+
/**
|
|
217
|
+
* Connects a wallet to the dapp.
|
|
218
|
+
* On connect success, we set the current account and the network, and keeping the selected wallet
|
|
219
|
+
* name in LocalStorage to support autoConnect function.
|
|
220
|
+
*
|
|
221
|
+
* @param selectedWallet. The wallet we want to connect.
|
|
222
|
+
* @emit emits "connect" event
|
|
223
|
+
* @throws WalletConnectionError
|
|
224
|
+
*/
|
|
225
|
+
async connectWallet(selectedWallet: Wallet) {
|
|
226
|
+
try {
|
|
219
227
|
this._connecting = true;
|
|
220
228
|
this.setWallet(selectedWallet);
|
|
221
229
|
const account = await selectedWallet.connect();
|
|
@@ -228,7 +236,9 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
228
236
|
this.emit("connect", account);
|
|
229
237
|
} catch (error: any) {
|
|
230
238
|
this.clearData();
|
|
231
|
-
|
|
239
|
+
const errMsg =
|
|
240
|
+
typeof error == "object" && "message" in error ? error.message : error;
|
|
241
|
+
throw new WalletConnectionError(errMsg).message;
|
|
232
242
|
} finally {
|
|
233
243
|
this._connecting = false;
|
|
234
244
|
}
|
|
@@ -247,23 +257,28 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
247
257
|
this.clearData();
|
|
248
258
|
this.emit("disconnect");
|
|
249
259
|
} catch (error: any) {
|
|
250
|
-
|
|
260
|
+
const errMsg =
|
|
261
|
+
typeof error == "object" && "message" in error ? error.message : error;
|
|
262
|
+
throw new WalletDisconnectionError(errMsg).message;
|
|
251
263
|
}
|
|
252
264
|
}
|
|
253
265
|
|
|
254
266
|
/**
|
|
255
267
|
Sign and submit an entry (not bcs serialized) transaction type to chain.
|
|
256
268
|
@param transaction a non-bcs serialized transaction
|
|
269
|
+
@param options max_gas_amount and gas_unit_limit
|
|
257
270
|
@return response from the wallet's signAndSubmitTransaction function
|
|
258
271
|
@throws WalletSignAndSubmitMessageError
|
|
259
272
|
*/
|
|
260
273
|
async signAndSubmitTransaction(
|
|
261
|
-
transaction: Types.TransactionPayload
|
|
274
|
+
transaction: Types.TransactionPayload,
|
|
275
|
+
options?: TransactionOptions
|
|
262
276
|
): Promise<any> {
|
|
263
277
|
try {
|
|
264
278
|
this.doesWalletExist();
|
|
265
279
|
const response = await this._wallet?.signAndSubmitTransaction(
|
|
266
|
-
transaction
|
|
280
|
+
transaction,
|
|
281
|
+
options
|
|
267
282
|
);
|
|
268
283
|
return response;
|
|
269
284
|
} catch (error: any) {
|
|
@@ -276,11 +291,13 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
276
291
|
/**
|
|
277
292
|
Sign and submit a bsc serialized transaction type to chain.
|
|
278
293
|
@param transaction a bcs serialized transaction
|
|
294
|
+
@param options max_gas_amount and gas_unit_limit
|
|
279
295
|
@return response from the wallet's signAndSubmitBCSTransaction function
|
|
280
296
|
@throws WalletSignAndSubmitMessageError
|
|
281
297
|
*/
|
|
282
298
|
async signAndSubmitBCSTransaction(
|
|
283
|
-
transaction: TxnBuilderTypes.TransactionPayload
|
|
299
|
+
transaction: TxnBuilderTypes.TransactionPayload,
|
|
300
|
+
options?: TransactionOptions
|
|
284
301
|
): Promise<any> {
|
|
285
302
|
if (this._wallet && !("signAndSubmitBCSTransaction" in this._wallet)) {
|
|
286
303
|
throw new WalletNotSupportedMethod(
|
|
@@ -291,7 +308,8 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
291
308
|
try {
|
|
292
309
|
this.doesWalletExist();
|
|
293
310
|
const response = await (this._wallet as any).signAndSubmitBCSTransaction(
|
|
294
|
-
transaction
|
|
311
|
+
transaction,
|
|
312
|
+
options
|
|
295
313
|
);
|
|
296
314
|
return response;
|
|
297
315
|
} catch (error: any) {
|
|
@@ -304,11 +322,13 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
304
322
|
/**
|
|
305
323
|
Sign transaction (doesnt submit to chain).
|
|
306
324
|
@param transaction
|
|
325
|
+
@param options max_gas_amount and gas_unit_limit
|
|
307
326
|
@return response from the wallet's signTransaction function
|
|
308
327
|
@throws WalletSignTransactionError
|
|
309
328
|
*/
|
|
310
329
|
async signTransaction(
|
|
311
|
-
transaction: Types.TransactionPayload
|
|
330
|
+
transaction: Types.TransactionPayload,
|
|
331
|
+
options?: TransactionOptions
|
|
312
332
|
): Promise<Uint8Array | null> {
|
|
313
333
|
if (this._wallet && !("signTransaction" in this._wallet)) {
|
|
314
334
|
throw new WalletNotSupportedMethod(
|
|
@@ -318,7 +338,10 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
318
338
|
|
|
319
339
|
try {
|
|
320
340
|
this.doesWalletExist();
|
|
321
|
-
const response = await (this._wallet as any).signTransaction(
|
|
341
|
+
const response = await (this._wallet as any).signTransaction(
|
|
342
|
+
transaction,
|
|
343
|
+
options
|
|
344
|
+
);
|
|
322
345
|
return response;
|
|
323
346
|
} catch (error: any) {
|
|
324
347
|
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
|
+
}
|