@hashgraphonline/hashinal-wc 1.0.87 → 1.0.89
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/README.md +2 -0
- package/dist/es/hashinal-wc.es.js +69 -5
- package/dist/es/hashinal-wc.es.js.map +1 -1
- package/dist/es/index.d.ts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/umd/hashinal-wc.umd.js +1 -1
- package/dist/umd/hashinal-wc.umd.js.map +1 -1
- package/dist/umd/index.d.ts +6 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -640,6 +640,8 @@ Version 1.0.58 and onward correlate with the NPM Package version.
|
|
|
640
640
|
| v1.0.79 | 0.0.7473819 | UMD |
|
|
641
641
|
| v1.0.82 | 0.0.7522981 | UMD |
|
|
642
642
|
| v1.0.86 | 0.0.7770334 | UMD |
|
|
643
|
+
| v1.0.88 | 0.0.7797532 | UMD |
|
|
644
|
+
| v1.0.89 | 0.0.7812387 | UMD |
|
|
643
645
|
|
|
644
646
|
## Contributing
|
|
645
647
|
|
|
@@ -1810,13 +1810,15 @@ var Result = /* @__PURE__ */ ((Result2) => {
|
|
|
1810
1810
|
return Result2;
|
|
1811
1811
|
})(Result || {});
|
|
1812
1812
|
class HashinalsWalletConnectSDK {
|
|
1813
|
-
get dAppConnector() {
|
|
1814
|
-
return HashinalsWalletConnectSDK.dAppConnectorInstance;
|
|
1815
|
-
}
|
|
1816
1813
|
constructor(logger, network) {
|
|
1814
|
+
this.extensionCheckInterval = null;
|
|
1815
|
+
this.hasCalledExtensionCallback = false;
|
|
1817
1816
|
this.logger = logger || new DefaultLogger();
|
|
1818
1817
|
this.network = network || LedgerId.MAINNET;
|
|
1819
1818
|
}
|
|
1819
|
+
get dAppConnector() {
|
|
1820
|
+
return HashinalsWalletConnectSDK.dAppConnectorInstance;
|
|
1821
|
+
}
|
|
1820
1822
|
static getInstance(logger, network) {
|
|
1821
1823
|
let instance = HashinalsWalletConnectSDK == null ? void 0 : HashinalsWalletConnectSDK.instance;
|
|
1822
1824
|
if (!instance) {
|
|
@@ -2235,12 +2237,13 @@ class HashinalsWalletConnectSDK {
|
|
|
2235
2237
|
return false;
|
|
2236
2238
|
}
|
|
2237
2239
|
}
|
|
2238
|
-
async initAccount(PROJECT_ID, APP_METADATA) {
|
|
2240
|
+
async initAccount(PROJECT_ID, APP_METADATA, networkOverride, onSessionIframeCreated = () => {
|
|
2241
|
+
}) {
|
|
2239
2242
|
const { accountId: savedAccountId, network: savedNetwork } = this.loadConnectionInfo();
|
|
2240
2243
|
if (savedAccountId && savedNetwork) {
|
|
2241
2244
|
try {
|
|
2242
2245
|
const network = savedNetwork === "mainnet" ? LedgerId.MAINNET : LedgerId.TESTNET;
|
|
2243
|
-
await this.init(PROJECT_ID, APP_METADATA, network);
|
|
2246
|
+
await this.init(PROJECT_ID, APP_METADATA, network, onSessionIframeCreated);
|
|
2244
2247
|
const balance = await this.getAccountBalance();
|
|
2245
2248
|
return {
|
|
2246
2249
|
accountId: savedAccountId,
|
|
@@ -2251,9 +2254,70 @@ class HashinalsWalletConnectSDK {
|
|
|
2251
2254
|
this.saveConnectionInfo(void 0, void 0);
|
|
2252
2255
|
return null;
|
|
2253
2256
|
}
|
|
2257
|
+
} else if (networkOverride) {
|
|
2258
|
+
try {
|
|
2259
|
+
this.logger.info("initializing normally through override.", networkOverride);
|
|
2260
|
+
await this.init(PROJECT_ID, APP_METADATA, networkOverride, onSessionIframeCreated);
|
|
2261
|
+
this.logger.info("initialized", networkOverride);
|
|
2262
|
+
await this.connectViaDappBrowser();
|
|
2263
|
+
this.logger.info("connected via dapp browser");
|
|
2264
|
+
} catch (error) {
|
|
2265
|
+
this.logger.error("Failed to fallback connect:", error);
|
|
2266
|
+
this.saveConnectionInfo(void 0, void 0);
|
|
2267
|
+
return null;
|
|
2268
|
+
}
|
|
2254
2269
|
}
|
|
2255
2270
|
return null;
|
|
2256
2271
|
}
|
|
2272
|
+
subscribeToExtensions(callback) {
|
|
2273
|
+
if (this.extensionCheckInterval) {
|
|
2274
|
+
clearInterval(this.extensionCheckInterval);
|
|
2275
|
+
}
|
|
2276
|
+
this.hasCalledExtensionCallback = false;
|
|
2277
|
+
this.extensionCheckInterval = setInterval(() => {
|
|
2278
|
+
var _a;
|
|
2279
|
+
const extensions = ((_a = this.dAppConnector) == null ? void 0 : _a.extensions) || [];
|
|
2280
|
+
const availableExtension = extensions.find((ext) => ext.availableInIframe);
|
|
2281
|
+
if (availableExtension && !this.hasCalledExtensionCallback) {
|
|
2282
|
+
this.hasCalledExtensionCallback = true;
|
|
2283
|
+
callback(availableExtension);
|
|
2284
|
+
if (this.extensionCheckInterval) {
|
|
2285
|
+
clearInterval(this.extensionCheckInterval);
|
|
2286
|
+
this.extensionCheckInterval = null;
|
|
2287
|
+
}
|
|
2288
|
+
}
|
|
2289
|
+
}, 1e3);
|
|
2290
|
+
return () => {
|
|
2291
|
+
if (this.extensionCheckInterval) {
|
|
2292
|
+
clearInterval(this.extensionCheckInterval);
|
|
2293
|
+
this.extensionCheckInterval = null;
|
|
2294
|
+
}
|
|
2295
|
+
this.hasCalledExtensionCallback = false;
|
|
2296
|
+
};
|
|
2297
|
+
}
|
|
2298
|
+
async connectViaDappBrowser() {
|
|
2299
|
+
const extensions = this.dAppConnector.extensions || [];
|
|
2300
|
+
const extension = extensions.find((ext) => {
|
|
2301
|
+
this.logger.info("Checking extension", ext);
|
|
2302
|
+
return ext.availableInIframe;
|
|
2303
|
+
});
|
|
2304
|
+
this.logger.info("extensions are", extensions, extension);
|
|
2305
|
+
if (extension) {
|
|
2306
|
+
await this.connectToExtension(extension);
|
|
2307
|
+
} else {
|
|
2308
|
+
this.subscribeToExtensions(async (newExtension) => {
|
|
2309
|
+
await this.connectToExtension(newExtension);
|
|
2310
|
+
});
|
|
2311
|
+
}
|
|
2312
|
+
}
|
|
2313
|
+
async connectToExtension(extension) {
|
|
2314
|
+
this.logger.info("found extension, connecting to iframe.", extension);
|
|
2315
|
+
const session = await this.dAppConnector.connectExtension(extension.id);
|
|
2316
|
+
const onSessionIframeCreated = this.dAppConnector.onSessionIframeCreated;
|
|
2317
|
+
if (onSessionIframeCreated) {
|
|
2318
|
+
onSessionIframeCreated(session);
|
|
2319
|
+
}
|
|
2320
|
+
}
|
|
2257
2321
|
ensureInitialized() {
|
|
2258
2322
|
if (!this.dAppConnector) {
|
|
2259
2323
|
throw new Error("SDK not initialized. Call init() first.");
|