@injectivelabs/wallet-wallet-connect 1.20.7 → 1.20.9

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.
@@ -1,9 +1,7 @@
1
- let __reown_appkit = require("@reown/appkit");
2
1
  let __injectivelabs_utils = require("@injectivelabs/utils");
3
2
  let __injectivelabs_sdk_ts_utils = require("@injectivelabs/sdk-ts/utils");
4
3
  let __injectivelabs_ts_types = require("@injectivelabs/ts-types");
5
4
  let __injectivelabs_sdk_ts_core_tx = require("@injectivelabs/sdk-ts/core/tx");
6
- let __reown_appkit_adapter_ethers = require("@reown/appkit-adapter-ethers");
7
5
  let __injectivelabs_exceptions = require("@injectivelabs/exceptions");
8
6
  let __injectivelabs_wallet_base = require("@injectivelabs/wallet-base");
9
7
 
@@ -56,7 +54,7 @@ var WalletConnect = class WalletConnect extends __injectivelabs_wallet_base.Base
56
54
  async getWalletDeviceType() {
57
55
  return Promise.resolve(__injectivelabs_wallet_base.WalletDeviceType.Browser);
58
56
  }
59
- createAppKit() {
57
+ async createAppKit() {
60
58
  var _this$metadata;
61
59
  const projectId = (_this$metadata = this.metadata) === null || _this$metadata === void 0 || (_this$metadata = _this$metadata.walletConnect) === null || _this$metadata === void 0 ? void 0 : _this$metadata.projectId;
62
60
  if (!projectId) throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error("Please provide projectId in metadata for WalletConnect"), {
@@ -65,15 +63,24 @@ var WalletConnect = class WalletConnect extends __injectivelabs_wallet_base.Base
65
63
  contextModule: __injectivelabs_wallet_base.WalletAction.GetAccounts
66
64
  });
67
65
  if (WalletConnect.appKit) return WalletConnect.appKit;
66
+ if (WalletConnect.appKitPromise) return WalletConnect.appKitPromise;
67
+ WalletConnect.appKitPromise = this.createAppKitInstance(projectId).catch((e) => {
68
+ WalletConnect.appKitPromise = void 0;
69
+ throw e;
70
+ });
71
+ return WalletConnect.appKitPromise;
72
+ }
73
+ async createAppKitInstance(projectId) {
68
74
  const chainId = this.evmChainId || __injectivelabs_ts_types.EvmChainId.Mainnet;
69
- WalletConnect.appKit = (0, __reown_appkit.createAppKit)({
75
+ const [{ createAppKit }, { EthersAdapter }] = await Promise.all([import("@reown/appkit"), import("@reown/appkit-adapter-ethers")]);
76
+ WalletConnect.appKit = createAppKit({
70
77
  projectId,
71
78
  allWallets: "HIDE",
72
79
  enableEIP6963: false,
73
80
  enableInjected: false,
74
81
  enableCoinbase: false,
75
82
  enableReconnect: true,
76
- adapters: [new __reown_appkit_adapter_ethers.EthersAdapter()],
83
+ adapters: [new EthersAdapter()],
77
84
  networks: [{
78
85
  id: chainId,
79
86
  name: "Injective",
@@ -128,11 +135,11 @@ var WalletConnect = class WalletConnect extends __injectivelabs_wallet_base.Base
128
135
  });
129
136
  }
130
137
  async initStrategy() {
131
- this.createAppKit();
138
+ await this.createAppKit();
132
139
  if (WalletConnect.sessionRestorePromise) await WalletConnect.sessionRestorePromise;
133
140
  }
134
141
  async getProvider() {
135
- return this.createAppKit().getUniversalProvider();
142
+ return (await this.createAppKit()).getUniversalProvider();
136
143
  }
137
144
  async getWalletProvider(contextModule) {
138
145
  const provider = (await this.getAppKit()).getWalletProvider();
@@ -145,7 +152,7 @@ var WalletConnect = class WalletConnect extends __injectivelabs_wallet_base.Base
145
152
  }
146
153
  async getAppKit() {
147
154
  await this.initStrategy();
148
- const modal = this.createAppKit();
155
+ const modal = await this.createAppKit();
149
156
  if (!modal.getIsConnectedState()) throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error("Wallet not connected. Please call enable() first."), {
150
157
  code: __injectivelabs_exceptions.UnspecifiedErrorCode,
151
158
  type: __injectivelabs_exceptions.ErrorType.WalletError,
@@ -155,12 +162,12 @@ var WalletConnect = class WalletConnect extends __injectivelabs_wallet_base.Base
155
162
  }
156
163
  async enable() {
157
164
  await this.initStrategy();
158
- if (this.createAppKit().getIsConnectedState()) return true;
165
+ if ((await this.createAppKit()).getIsConnectedState()) return true;
159
166
  await this.connect();
160
167
  return true;
161
168
  }
162
169
  async connect() {
163
- const modal = this.createAppKit();
170
+ const modal = await this.createAppKit();
164
171
  if (modal.getIsConnectedState()) return;
165
172
  try {
166
173
  var _provider$client;
@@ -189,7 +196,7 @@ var WalletConnect = class WalletConnect extends __injectivelabs_wallet_base.Base
189
196
  }
190
197
  async disconnect() {
191
198
  try {
192
- const modal = this.createAppKit();
199
+ const modal = await this.createAppKit();
193
200
  const provider = modal.getWalletProvider();
194
201
  if (provider === null || provider === void 0 ? void 0 : provider.removeListener) {
195
202
  if (this.listeners[__injectivelabs_wallet_base.WalletEventListener.AccountChange]) provider.removeListener("accountsChanged", this.listeners[__injectivelabs_wallet_base.WalletEventListener.AccountChange]);
@@ -252,9 +259,13 @@ var WalletConnect = class WalletConnect extends __injectivelabs_wallet_base.Base
252
259
  }
253
260
  }
254
261
  async sendTransaction(transaction, options) {
255
- const { endpoints, txTimeout } = options;
262
+ const { endpoints, txTimeout, txInclusion, onBroadcast } = options;
256
263
  if (!endpoints) throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error("You have to pass endpoints within the options"));
257
- const response = await new __injectivelabs_sdk_ts_core_tx.TxGrpcApi(endpoints.grpc).broadcast(transaction, { txTimeout });
264
+ const response = await new __injectivelabs_sdk_ts_core_tx.TxGrpcApi(endpoints.grpc).broadcast(transaction, {
265
+ txTimeout,
266
+ ...txInclusion,
267
+ onBroadcast
268
+ });
258
269
  if (response.code !== 0) throw new __injectivelabs_exceptions.TransactionException(new Error(response.rawLog), {
259
270
  code: __injectivelabs_exceptions.UnspecifiedErrorCode,
260
271
  contextCode: response.code,
@@ -374,6 +385,7 @@ var WalletConnect = class WalletConnect extends __injectivelabs_wallet_base.Base
374
385
  }
375
386
  };
376
387
  _defineProperty(WalletConnect, "appKit", void 0);
388
+ _defineProperty(WalletConnect, "appKitPromise", void 0);
377
389
  _defineProperty(WalletConnect, "sessionRestorePromise", void 0);
378
390
 
379
391
  //#endregion
@@ -6,9 +6,11 @@ import { AminoSignResponse, DirectSignResponse, TxRaw } from "@injectivelabs/sdk
6
6
  //#region src/strategy/strategy.d.ts
7
7
  declare class WalletConnect extends BaseConcreteStrategy implements ConcreteWalletStrategy {
8
8
  private static appKit;
9
+ private static appKitPromise;
9
10
  private static sessionRestorePromise;
10
11
  getWalletDeviceType(): Promise<WalletDeviceType>;
11
12
  private createAppKit;
13
+ private createAppKitInstance;
12
14
  /**
13
15
  * Waits for AppKit to restore session from localStorage on page refresh.
14
16
  * Resolves immediately if already connected, otherwise waits for provider
@@ -6,9 +6,11 @@ import { AminoSignResponse, DirectSignResponse, TxRaw } from "@injectivelabs/sdk
6
6
  //#region src/strategy/strategy.d.ts
7
7
  declare class WalletConnect extends BaseConcreteStrategy implements ConcreteWalletStrategy {
8
8
  private static appKit;
9
+ private static appKitPromise;
9
10
  private static sessionRestorePromise;
10
11
  getWalletDeviceType(): Promise<WalletDeviceType>;
11
12
  private createAppKit;
13
+ private createAppKitInstance;
12
14
  /**
13
15
  * Waits for AppKit to restore session from localStorage on page refresh.
14
16
  * Resolves immediately if already connected, otherwise waits for provider
package/dist/esm/index.js CHANGED
@@ -1,9 +1,7 @@
1
- import { createAppKit } from "@reown/appkit";
2
1
  import { sleep } from "@injectivelabs/utils";
3
2
  import { toUtf8 } from "@injectivelabs/sdk-ts/utils";
4
3
  import { EvmChainId } from "@injectivelabs/ts-types";
5
4
  import { TxGrpcApi } from "@injectivelabs/sdk-ts/core/tx";
6
- import { EthersAdapter } from "@reown/appkit-adapter-ethers";
7
5
  import { ErrorType, TransactionException, UnspecifiedErrorCode, WalletConnectException, WalletException } from "@injectivelabs/exceptions";
8
6
  import { BaseConcreteStrategy, WalletAction, WalletConnectStrategyEventType, WalletDeviceType, WalletEventListener } from "@injectivelabs/wallet-base";
9
7
 
@@ -56,7 +54,7 @@ var WalletConnect = class WalletConnect extends BaseConcreteStrategy {
56
54
  async getWalletDeviceType() {
57
55
  return Promise.resolve(WalletDeviceType.Browser);
58
56
  }
59
- createAppKit() {
57
+ async createAppKit() {
60
58
  var _this$metadata;
61
59
  const projectId = (_this$metadata = this.metadata) === null || _this$metadata === void 0 || (_this$metadata = _this$metadata.walletConnect) === null || _this$metadata === void 0 ? void 0 : _this$metadata.projectId;
62
60
  if (!projectId) throw new WalletException(/* @__PURE__ */ new Error("Please provide projectId in metadata for WalletConnect"), {
@@ -65,7 +63,16 @@ var WalletConnect = class WalletConnect extends BaseConcreteStrategy {
65
63
  contextModule: WalletAction.GetAccounts
66
64
  });
67
65
  if (WalletConnect.appKit) return WalletConnect.appKit;
66
+ if (WalletConnect.appKitPromise) return WalletConnect.appKitPromise;
67
+ WalletConnect.appKitPromise = this.createAppKitInstance(projectId).catch((e) => {
68
+ WalletConnect.appKitPromise = void 0;
69
+ throw e;
70
+ });
71
+ return WalletConnect.appKitPromise;
72
+ }
73
+ async createAppKitInstance(projectId) {
68
74
  const chainId = this.evmChainId || EvmChainId.Mainnet;
75
+ const [{ createAppKit }, { EthersAdapter }] = await Promise.all([import("@reown/appkit"), import("@reown/appkit-adapter-ethers")]);
69
76
  WalletConnect.appKit = createAppKit({
70
77
  projectId,
71
78
  allWallets: "HIDE",
@@ -128,11 +135,11 @@ var WalletConnect = class WalletConnect extends BaseConcreteStrategy {
128
135
  });
129
136
  }
130
137
  async initStrategy() {
131
- this.createAppKit();
138
+ await this.createAppKit();
132
139
  if (WalletConnect.sessionRestorePromise) await WalletConnect.sessionRestorePromise;
133
140
  }
134
141
  async getProvider() {
135
- return this.createAppKit().getUniversalProvider();
142
+ return (await this.createAppKit()).getUniversalProvider();
136
143
  }
137
144
  async getWalletProvider(contextModule) {
138
145
  const provider = (await this.getAppKit()).getWalletProvider();
@@ -145,7 +152,7 @@ var WalletConnect = class WalletConnect extends BaseConcreteStrategy {
145
152
  }
146
153
  async getAppKit() {
147
154
  await this.initStrategy();
148
- const modal = this.createAppKit();
155
+ const modal = await this.createAppKit();
149
156
  if (!modal.getIsConnectedState()) throw new WalletException(/* @__PURE__ */ new Error("Wallet not connected. Please call enable() first."), {
150
157
  code: UnspecifiedErrorCode,
151
158
  type: ErrorType.WalletError,
@@ -155,12 +162,12 @@ var WalletConnect = class WalletConnect extends BaseConcreteStrategy {
155
162
  }
156
163
  async enable() {
157
164
  await this.initStrategy();
158
- if (this.createAppKit().getIsConnectedState()) return true;
165
+ if ((await this.createAppKit()).getIsConnectedState()) return true;
159
166
  await this.connect();
160
167
  return true;
161
168
  }
162
169
  async connect() {
163
- const modal = this.createAppKit();
170
+ const modal = await this.createAppKit();
164
171
  if (modal.getIsConnectedState()) return;
165
172
  try {
166
173
  var _provider$client;
@@ -189,7 +196,7 @@ var WalletConnect = class WalletConnect extends BaseConcreteStrategy {
189
196
  }
190
197
  async disconnect() {
191
198
  try {
192
- const modal = this.createAppKit();
199
+ const modal = await this.createAppKit();
193
200
  const provider = modal.getWalletProvider();
194
201
  if (provider === null || provider === void 0 ? void 0 : provider.removeListener) {
195
202
  if (this.listeners[WalletEventListener.AccountChange]) provider.removeListener("accountsChanged", this.listeners[WalletEventListener.AccountChange]);
@@ -252,9 +259,13 @@ var WalletConnect = class WalletConnect extends BaseConcreteStrategy {
252
259
  }
253
260
  }
254
261
  async sendTransaction(transaction, options) {
255
- const { endpoints, txTimeout } = options;
262
+ const { endpoints, txTimeout, txInclusion, onBroadcast } = options;
256
263
  if (!endpoints) throw new WalletException(/* @__PURE__ */ new Error("You have to pass endpoints within the options"));
257
- const response = await new TxGrpcApi(endpoints.grpc).broadcast(transaction, { txTimeout });
264
+ const response = await new TxGrpcApi(endpoints.grpc).broadcast(transaction, {
265
+ txTimeout,
266
+ ...txInclusion,
267
+ onBroadcast
268
+ });
258
269
  if (response.code !== 0) throw new TransactionException(new Error(response.rawLog), {
259
270
  code: UnspecifiedErrorCode,
260
271
  contextCode: response.code,
@@ -374,6 +385,7 @@ var WalletConnect = class WalletConnect extends BaseConcreteStrategy {
374
385
  }
375
386
  };
376
387
  _defineProperty(WalletConnect, "appKit", void 0);
388
+ _defineProperty(WalletConnect, "appKitPromise", void 0);
377
389
  _defineProperty(WalletConnect, "sessionRestorePromise", void 0);
378
390
 
379
391
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@injectivelabs/wallet-wallet-connect",
3
- "version": "1.20.7",
3
+ "version": "1.20.9",
4
4
  "description": "Wallet connect strategy for use with @injectivelabs/wallet-core.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -44,10 +44,10 @@
44
44
  "dependencies": {
45
45
  "@reown/appkit": "1.8.15",
46
46
  "@reown/appkit-adapter-ethers": "1.8.15",
47
- "@injectivelabs/exceptions": "1.20.7",
48
- "@injectivelabs/sdk-ts": "1.20.7",
49
- "@injectivelabs/ts-types": "1.20.7",
50
- "@injectivelabs/wallet-base": "1.20.7"
47
+ "@injectivelabs/exceptions": "1.20.9",
48
+ "@injectivelabs/ts-types": "1.20.9",
49
+ "@injectivelabs/sdk-ts": "1.20.9",
50
+ "@injectivelabs/wallet-base": "1.20.9"
51
51
  },
52
52
  "publishConfig": {
53
53
  "access": "public"