@dynamic-labs-wallet/browser-wallet-client 0.0.106 → 0.0.108
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/index.cjs.js +122 -20
- package/index.esm.js +122 -20
- package/package.json +3 -4
- package/src/client/client.d.ts +5 -0
- package/src/client/client.d.ts.map +1 -1
package/index.cjs.js
CHANGED
|
@@ -173,6 +173,18 @@ class DynamicWalletClient {
|
|
|
173
173
|
throw new Error('Failed to establish secure token exchange: ' + error);
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
|
+
/**
|
|
177
|
+
* Reset the shared iframe and iframe load promise, and iframe instance count
|
|
178
|
+
*/ async resetSharedIframe() {
|
|
179
|
+
DynamicWalletClient.sharedIframe = null;
|
|
180
|
+
DynamicWalletClient.iframeInstanceCount = 0;
|
|
181
|
+
DynamicWalletClient.iframeLoadPromise = null;
|
|
182
|
+
this.iframe = null;
|
|
183
|
+
this.iframeMessageHandler = null;
|
|
184
|
+
this.messageTransport = null;
|
|
185
|
+
// Double the timeout and cap at 60 seconds to give more time for slow networks
|
|
186
|
+
this.iframeLoadTimeout = Math.min(this.iframeLoadTimeout * 2, 60000);
|
|
187
|
+
}
|
|
176
188
|
async loadIframe() {
|
|
177
189
|
// If the iframe is already loaded, just assign and resolve
|
|
178
190
|
if (DynamicWalletClient.sharedIframe) {
|
|
@@ -188,10 +200,54 @@ class DynamicWalletClient {
|
|
|
188
200
|
});
|
|
189
201
|
}
|
|
190
202
|
DynamicWalletClient.iframeLoadPromise = new Promise((resolve, reject)=>{
|
|
203
|
+
var _this_sdkVersion;
|
|
204
|
+
this.logger.info(`Loading iframe for waas wallet client...`, {
|
|
205
|
+
iframeDomain: this.iframeDomain,
|
|
206
|
+
environmentId: this.environmentId,
|
|
207
|
+
sdkVersion: (_this_sdkVersion = this.sdkVersion) != null ? _this_sdkVersion : '',
|
|
208
|
+
instanceId: this.instanceId,
|
|
209
|
+
chainName: this.chainName
|
|
210
|
+
});
|
|
191
211
|
const iframe = document.createElement('iframe');
|
|
212
|
+
let messageListener = null;
|
|
192
213
|
const iframeTimeoutId = setTimeout(()=>{
|
|
193
|
-
|
|
194
|
-
|
|
214
|
+
if (messageListener) {
|
|
215
|
+
window.removeEventListener('message', messageListener);
|
|
216
|
+
}
|
|
217
|
+
this.resetSharedIframe();
|
|
218
|
+
var _this_sdkVersion;
|
|
219
|
+
this.logger.error('Iframe load timeout...', {
|
|
220
|
+
iframeDomain: this.iframeDomain,
|
|
221
|
+
environmentId: this.environmentId,
|
|
222
|
+
sdkVersion: (_this_sdkVersion = this.sdkVersion) != null ? _this_sdkVersion : '',
|
|
223
|
+
instanceId: this.instanceId,
|
|
224
|
+
chainName: this.chainName
|
|
225
|
+
});
|
|
226
|
+
reject(new Error('Iframe load timeout...'));
|
|
227
|
+
}, this.iframeLoadTimeout);
|
|
228
|
+
// Set up message listener BEFORE creating iframe
|
|
229
|
+
messageListener = (event)=>{
|
|
230
|
+
if (event.source === iframe.contentWindow && event.data === `iframe-ready-${this.instanceId}`) {
|
|
231
|
+
if (messageListener) {
|
|
232
|
+
window.removeEventListener('message', messageListener);
|
|
233
|
+
}
|
|
234
|
+
clearTimeout(iframeTimeoutId);
|
|
235
|
+
DynamicWalletClient.sharedIframe = iframe;
|
|
236
|
+
this.iframe = iframe;
|
|
237
|
+
DynamicWalletClient.iframeInstanceCount++;
|
|
238
|
+
resolve();
|
|
239
|
+
var _this_sdkVersion;
|
|
240
|
+
this.logger.info('Iframe loaded successfully...', {
|
|
241
|
+
iframeDomain: this.iframeDomain,
|
|
242
|
+
environmentId: this.environmentId,
|
|
243
|
+
sdkVersion: (_this_sdkVersion = this.sdkVersion) != null ? _this_sdkVersion : '',
|
|
244
|
+
instanceId: this.instanceId,
|
|
245
|
+
chainName: this.chainName
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
window.addEventListener('message', messageListener);
|
|
250
|
+
// Configure iframe
|
|
195
251
|
iframe.style.display = 'none';
|
|
196
252
|
iframe.setAttribute('title', 'Dynamic Wallet Iframe');
|
|
197
253
|
iframe.setAttribute('sandbox', 'allow-scripts allow-same-origin allow-downloads');
|
|
@@ -203,29 +259,30 @@ class DynamicWalletClient {
|
|
|
203
259
|
iframe.style.height = '0';
|
|
204
260
|
iframe.style.border = 'none';
|
|
205
261
|
iframe.style.pointerEvents = 'none';
|
|
206
|
-
var _this_instanceId,
|
|
262
|
+
var _this_instanceId, _this_sdkVersion1;
|
|
207
263
|
const params = new URLSearchParams({
|
|
208
264
|
instanceId: (_this_instanceId = this.instanceId) != null ? _this_instanceId : '',
|
|
209
265
|
hostOrigin: window.location.origin,
|
|
210
266
|
environmentId: this.environmentId,
|
|
211
267
|
baseApiUrl: this.baseApiUrl,
|
|
212
268
|
baseMPCRelayApiUrl: this.baseMPCRelayApiUrl,
|
|
213
|
-
sdkVersion: (
|
|
269
|
+
sdkVersion: (_this_sdkVersion1 = this.sdkVersion) != null ? _this_sdkVersion1 : ''
|
|
214
270
|
});
|
|
215
271
|
iframe.src = `${this.iframeDomain}/waas-v1/${this.environmentId}?${params.toString()}`;
|
|
216
272
|
this.logger.debug('Creating iframe with src:', iframe.src);
|
|
217
273
|
document.body.appendChild(iframe);
|
|
218
274
|
iframe.onload = ()=>{
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
this.iframe = iframe;
|
|
222
|
-
DynamicWalletClient.iframeInstanceCount++;
|
|
223
|
-
resolve();
|
|
275
|
+
// The message listener is already set up, so iframe can send ready message
|
|
276
|
+
this.logger.debug('Iframe onload fired, waiting for ready message...');
|
|
224
277
|
};
|
|
225
278
|
iframe.onerror = (error)=>{
|
|
279
|
+
if (messageListener) {
|
|
280
|
+
window.removeEventListener('message', messageListener);
|
|
281
|
+
}
|
|
226
282
|
clearTimeout(iframeTimeoutId);
|
|
227
|
-
this.logger.error('Iframe failed to load:', error);
|
|
228
|
-
|
|
283
|
+
this.logger.error('Iframe failed to load due to errors: ', error);
|
|
284
|
+
this.resetSharedIframe();
|
|
285
|
+
reject(new Error('Failed to load iframe...'));
|
|
229
286
|
};
|
|
230
287
|
});
|
|
231
288
|
return DynamicWalletClient.iframeLoadPromise;
|
|
@@ -236,39 +293,83 @@ class DynamicWalletClient {
|
|
|
236
293
|
* @returns {Promise<HTMLIFrameElement>} that resolves when the iframe is loaded
|
|
237
294
|
*/ loadIframeForContainer(container) {
|
|
238
295
|
return new Promise((resolve, reject)=>{
|
|
296
|
+
var _this_sdkVersion;
|
|
297
|
+
this.logger.info(`Loading iframe for container...`, {
|
|
298
|
+
iframeDomain: this.iframeDomain,
|
|
299
|
+
environmentId: this.environmentId,
|
|
300
|
+
sdkVersion: (_this_sdkVersion = this.sdkVersion) != null ? _this_sdkVersion : '',
|
|
301
|
+
instanceId: this.instanceId,
|
|
302
|
+
chainName: this.chainName
|
|
303
|
+
});
|
|
239
304
|
const iframe = document.createElement('iframe');
|
|
305
|
+
let messageListener = null;
|
|
240
306
|
const iframeTimeoutId = setTimeout(()=>{
|
|
241
|
-
|
|
242
|
-
|
|
307
|
+
if (messageListener) {
|
|
308
|
+
window.removeEventListener('message', messageListener);
|
|
309
|
+
}
|
|
310
|
+
var _this_sdkVersion;
|
|
311
|
+
this.logger.error('Iframe load timeout due to no handshake message from iframe, this could be network issues, incorrect iframe domain, or CORS errors that prevents iframe from being loaded or sending handshake message.', {
|
|
312
|
+
iframeDomain: this.iframeDomain,
|
|
313
|
+
environmentId: this.environmentId,
|
|
314
|
+
sdkVersion: (_this_sdkVersion = this.sdkVersion) != null ? _this_sdkVersion : '',
|
|
315
|
+
instanceId: this.instanceId,
|
|
316
|
+
chainName: this.chainName
|
|
317
|
+
});
|
|
318
|
+
reject(new Error('Iframe load timeout due to no handshake message from iframe, this could be network issues, incorrect iframe domain, or CORS errors that prevents iframe from being loaded or sending handshake message.'));
|
|
319
|
+
}, this.iframeLoadTimeout);
|
|
243
320
|
iframe.style.display = 'block';
|
|
244
321
|
iframe.style.width = '100%';
|
|
245
322
|
iframe.style.height = '100%';
|
|
246
323
|
iframe.setAttribute('title', 'Dynamic Wallet Storage');
|
|
247
324
|
iframe.setAttribute('sandbox', 'allow-scripts allow-same-origin');
|
|
248
325
|
iframe.setAttribute('referrerpolicy', 'origin');
|
|
249
|
-
var _this_instanceId;
|
|
326
|
+
var _this_instanceId, _this_sdkVersion1;
|
|
250
327
|
const params = new URLSearchParams({
|
|
251
328
|
instanceId: (_this_instanceId = this.instanceId) != null ? _this_instanceId : '',
|
|
252
329
|
hostOrigin: window.location.origin,
|
|
253
330
|
environmentId: this.environmentId,
|
|
254
331
|
baseApiUrl: this.baseApiUrl,
|
|
255
332
|
baseMPCRelayApiUrl: this.baseMPCRelayApiUrl,
|
|
256
|
-
|
|
333
|
+
sdkVersion: (_this_sdkVersion1 = this.sdkVersion) != null ? _this_sdkVersion1 : ''
|
|
257
334
|
});
|
|
258
335
|
iframe.src = `${this.iframeDomain}/waas-v1/${this.environmentId}?${params.toString()}`;
|
|
259
336
|
this.logger.debug('Creating iframe with src:', iframe.src);
|
|
260
337
|
// Add iframe to the provided container
|
|
261
338
|
container.appendChild(iframe);
|
|
262
339
|
iframe.onload = ()=>{
|
|
263
|
-
|
|
264
|
-
this.logger.debug('Iframe
|
|
265
|
-
resolve(iframe);
|
|
340
|
+
// The message listener is already set up, so iframe can send ready message
|
|
341
|
+
this.logger.debug('Iframe onload fired, waiting for ready message...');
|
|
266
342
|
};
|
|
267
343
|
iframe.onerror = (error)=>{
|
|
344
|
+
if (messageListener) {
|
|
345
|
+
window.removeEventListener('message', messageListener);
|
|
346
|
+
}
|
|
268
347
|
clearTimeout(iframeTimeoutId);
|
|
269
|
-
this.logger.error('Iframe failed to load:', error);
|
|
270
|
-
reject(new Error('Failed to load iframe'));
|
|
348
|
+
this.logger.error('Iframe failed to load due to errors: ', error);
|
|
349
|
+
reject(new Error('Failed to load iframe due to unknown load errors, this is likely a browser or network issue.'));
|
|
350
|
+
};
|
|
351
|
+
// Set up message listener BEFORE creating iframe
|
|
352
|
+
messageListener = (event)=>{
|
|
353
|
+
if (event.source === iframe.contentWindow && event.data === `iframe-ready-${this.instanceId}`) {
|
|
354
|
+
if (messageListener) {
|
|
355
|
+
window.removeEventListener('message', messageListener);
|
|
356
|
+
}
|
|
357
|
+
clearTimeout(iframeTimeoutId);
|
|
358
|
+
DynamicWalletClient.sharedIframe = iframe;
|
|
359
|
+
this.iframe = iframe;
|
|
360
|
+
DynamicWalletClient.iframeInstanceCount++;
|
|
361
|
+
resolve(iframe);
|
|
362
|
+
var _this_sdkVersion;
|
|
363
|
+
this.logger.info('Iframe loaded successfully...', {
|
|
364
|
+
iframeDomain: this.iframeDomain,
|
|
365
|
+
environmentId: this.environmentId,
|
|
366
|
+
sdkVersion: (_this_sdkVersion = this.sdkVersion) != null ? _this_sdkVersion : '',
|
|
367
|
+
instanceId: this.instanceId,
|
|
368
|
+
chainName: this.chainName
|
|
369
|
+
});
|
|
370
|
+
}
|
|
271
371
|
};
|
|
372
|
+
window.addEventListener('message', messageListener);
|
|
272
373
|
});
|
|
273
374
|
}
|
|
274
375
|
/**
|
|
@@ -593,6 +694,7 @@ class DynamicWalletClient {
|
|
|
593
694
|
this.messageTransport = null;
|
|
594
695
|
this.iframeMessageHandler = null;
|
|
595
696
|
this.iframe = null;
|
|
697
|
+
this.iframeLoadTimeout = 10000;
|
|
596
698
|
this.environmentId = environmentId;
|
|
597
699
|
this.authToken = authToken;
|
|
598
700
|
this.baseApiUrl = baseApiUrl;
|
package/index.esm.js
CHANGED
|
@@ -172,6 +172,18 @@ class DynamicWalletClient {
|
|
|
172
172
|
throw new Error('Failed to establish secure token exchange: ' + error);
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* Reset the shared iframe and iframe load promise, and iframe instance count
|
|
177
|
+
*/ async resetSharedIframe() {
|
|
178
|
+
DynamicWalletClient.sharedIframe = null;
|
|
179
|
+
DynamicWalletClient.iframeInstanceCount = 0;
|
|
180
|
+
DynamicWalletClient.iframeLoadPromise = null;
|
|
181
|
+
this.iframe = null;
|
|
182
|
+
this.iframeMessageHandler = null;
|
|
183
|
+
this.messageTransport = null;
|
|
184
|
+
// Double the timeout and cap at 60 seconds to give more time for slow networks
|
|
185
|
+
this.iframeLoadTimeout = Math.min(this.iframeLoadTimeout * 2, 60000);
|
|
186
|
+
}
|
|
175
187
|
async loadIframe() {
|
|
176
188
|
// If the iframe is already loaded, just assign and resolve
|
|
177
189
|
if (DynamicWalletClient.sharedIframe) {
|
|
@@ -187,10 +199,54 @@ class DynamicWalletClient {
|
|
|
187
199
|
});
|
|
188
200
|
}
|
|
189
201
|
DynamicWalletClient.iframeLoadPromise = new Promise((resolve, reject)=>{
|
|
202
|
+
var _this_sdkVersion;
|
|
203
|
+
this.logger.info(`Loading iframe for waas wallet client...`, {
|
|
204
|
+
iframeDomain: this.iframeDomain,
|
|
205
|
+
environmentId: this.environmentId,
|
|
206
|
+
sdkVersion: (_this_sdkVersion = this.sdkVersion) != null ? _this_sdkVersion : '',
|
|
207
|
+
instanceId: this.instanceId,
|
|
208
|
+
chainName: this.chainName
|
|
209
|
+
});
|
|
190
210
|
const iframe = document.createElement('iframe');
|
|
211
|
+
let messageListener = null;
|
|
191
212
|
const iframeTimeoutId = setTimeout(()=>{
|
|
192
|
-
|
|
193
|
-
|
|
213
|
+
if (messageListener) {
|
|
214
|
+
window.removeEventListener('message', messageListener);
|
|
215
|
+
}
|
|
216
|
+
this.resetSharedIframe();
|
|
217
|
+
var _this_sdkVersion;
|
|
218
|
+
this.logger.error('Iframe load timeout...', {
|
|
219
|
+
iframeDomain: this.iframeDomain,
|
|
220
|
+
environmentId: this.environmentId,
|
|
221
|
+
sdkVersion: (_this_sdkVersion = this.sdkVersion) != null ? _this_sdkVersion : '',
|
|
222
|
+
instanceId: this.instanceId,
|
|
223
|
+
chainName: this.chainName
|
|
224
|
+
});
|
|
225
|
+
reject(new Error('Iframe load timeout...'));
|
|
226
|
+
}, this.iframeLoadTimeout);
|
|
227
|
+
// Set up message listener BEFORE creating iframe
|
|
228
|
+
messageListener = (event)=>{
|
|
229
|
+
if (event.source === iframe.contentWindow && event.data === `iframe-ready-${this.instanceId}`) {
|
|
230
|
+
if (messageListener) {
|
|
231
|
+
window.removeEventListener('message', messageListener);
|
|
232
|
+
}
|
|
233
|
+
clearTimeout(iframeTimeoutId);
|
|
234
|
+
DynamicWalletClient.sharedIframe = iframe;
|
|
235
|
+
this.iframe = iframe;
|
|
236
|
+
DynamicWalletClient.iframeInstanceCount++;
|
|
237
|
+
resolve();
|
|
238
|
+
var _this_sdkVersion;
|
|
239
|
+
this.logger.info('Iframe loaded successfully...', {
|
|
240
|
+
iframeDomain: this.iframeDomain,
|
|
241
|
+
environmentId: this.environmentId,
|
|
242
|
+
sdkVersion: (_this_sdkVersion = this.sdkVersion) != null ? _this_sdkVersion : '',
|
|
243
|
+
instanceId: this.instanceId,
|
|
244
|
+
chainName: this.chainName
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
window.addEventListener('message', messageListener);
|
|
249
|
+
// Configure iframe
|
|
194
250
|
iframe.style.display = 'none';
|
|
195
251
|
iframe.setAttribute('title', 'Dynamic Wallet Iframe');
|
|
196
252
|
iframe.setAttribute('sandbox', 'allow-scripts allow-same-origin allow-downloads');
|
|
@@ -202,29 +258,30 @@ class DynamicWalletClient {
|
|
|
202
258
|
iframe.style.height = '0';
|
|
203
259
|
iframe.style.border = 'none';
|
|
204
260
|
iframe.style.pointerEvents = 'none';
|
|
205
|
-
var _this_instanceId,
|
|
261
|
+
var _this_instanceId, _this_sdkVersion1;
|
|
206
262
|
const params = new URLSearchParams({
|
|
207
263
|
instanceId: (_this_instanceId = this.instanceId) != null ? _this_instanceId : '',
|
|
208
264
|
hostOrigin: window.location.origin,
|
|
209
265
|
environmentId: this.environmentId,
|
|
210
266
|
baseApiUrl: this.baseApiUrl,
|
|
211
267
|
baseMPCRelayApiUrl: this.baseMPCRelayApiUrl,
|
|
212
|
-
sdkVersion: (
|
|
268
|
+
sdkVersion: (_this_sdkVersion1 = this.sdkVersion) != null ? _this_sdkVersion1 : ''
|
|
213
269
|
});
|
|
214
270
|
iframe.src = `${this.iframeDomain}/waas-v1/${this.environmentId}?${params.toString()}`;
|
|
215
271
|
this.logger.debug('Creating iframe with src:', iframe.src);
|
|
216
272
|
document.body.appendChild(iframe);
|
|
217
273
|
iframe.onload = ()=>{
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
this.iframe = iframe;
|
|
221
|
-
DynamicWalletClient.iframeInstanceCount++;
|
|
222
|
-
resolve();
|
|
274
|
+
// The message listener is already set up, so iframe can send ready message
|
|
275
|
+
this.logger.debug('Iframe onload fired, waiting for ready message...');
|
|
223
276
|
};
|
|
224
277
|
iframe.onerror = (error)=>{
|
|
278
|
+
if (messageListener) {
|
|
279
|
+
window.removeEventListener('message', messageListener);
|
|
280
|
+
}
|
|
225
281
|
clearTimeout(iframeTimeoutId);
|
|
226
|
-
this.logger.error('Iframe failed to load:', error);
|
|
227
|
-
|
|
282
|
+
this.logger.error('Iframe failed to load due to errors: ', error);
|
|
283
|
+
this.resetSharedIframe();
|
|
284
|
+
reject(new Error('Failed to load iframe...'));
|
|
228
285
|
};
|
|
229
286
|
});
|
|
230
287
|
return DynamicWalletClient.iframeLoadPromise;
|
|
@@ -235,39 +292,83 @@ class DynamicWalletClient {
|
|
|
235
292
|
* @returns {Promise<HTMLIFrameElement>} that resolves when the iframe is loaded
|
|
236
293
|
*/ loadIframeForContainer(container) {
|
|
237
294
|
return new Promise((resolve, reject)=>{
|
|
295
|
+
var _this_sdkVersion;
|
|
296
|
+
this.logger.info(`Loading iframe for container...`, {
|
|
297
|
+
iframeDomain: this.iframeDomain,
|
|
298
|
+
environmentId: this.environmentId,
|
|
299
|
+
sdkVersion: (_this_sdkVersion = this.sdkVersion) != null ? _this_sdkVersion : '',
|
|
300
|
+
instanceId: this.instanceId,
|
|
301
|
+
chainName: this.chainName
|
|
302
|
+
});
|
|
238
303
|
const iframe = document.createElement('iframe');
|
|
304
|
+
let messageListener = null;
|
|
239
305
|
const iframeTimeoutId = setTimeout(()=>{
|
|
240
|
-
|
|
241
|
-
|
|
306
|
+
if (messageListener) {
|
|
307
|
+
window.removeEventListener('message', messageListener);
|
|
308
|
+
}
|
|
309
|
+
var _this_sdkVersion;
|
|
310
|
+
this.logger.error('Iframe load timeout due to no handshake message from iframe, this could be network issues, incorrect iframe domain, or CORS errors that prevents iframe from being loaded or sending handshake message.', {
|
|
311
|
+
iframeDomain: this.iframeDomain,
|
|
312
|
+
environmentId: this.environmentId,
|
|
313
|
+
sdkVersion: (_this_sdkVersion = this.sdkVersion) != null ? _this_sdkVersion : '',
|
|
314
|
+
instanceId: this.instanceId,
|
|
315
|
+
chainName: this.chainName
|
|
316
|
+
});
|
|
317
|
+
reject(new Error('Iframe load timeout due to no handshake message from iframe, this could be network issues, incorrect iframe domain, or CORS errors that prevents iframe from being loaded or sending handshake message.'));
|
|
318
|
+
}, this.iframeLoadTimeout);
|
|
242
319
|
iframe.style.display = 'block';
|
|
243
320
|
iframe.style.width = '100%';
|
|
244
321
|
iframe.style.height = '100%';
|
|
245
322
|
iframe.setAttribute('title', 'Dynamic Wallet Storage');
|
|
246
323
|
iframe.setAttribute('sandbox', 'allow-scripts allow-same-origin');
|
|
247
324
|
iframe.setAttribute('referrerpolicy', 'origin');
|
|
248
|
-
var _this_instanceId;
|
|
325
|
+
var _this_instanceId, _this_sdkVersion1;
|
|
249
326
|
const params = new URLSearchParams({
|
|
250
327
|
instanceId: (_this_instanceId = this.instanceId) != null ? _this_instanceId : '',
|
|
251
328
|
hostOrigin: window.location.origin,
|
|
252
329
|
environmentId: this.environmentId,
|
|
253
330
|
baseApiUrl: this.baseApiUrl,
|
|
254
331
|
baseMPCRelayApiUrl: this.baseMPCRelayApiUrl,
|
|
255
|
-
|
|
332
|
+
sdkVersion: (_this_sdkVersion1 = this.sdkVersion) != null ? _this_sdkVersion1 : ''
|
|
256
333
|
});
|
|
257
334
|
iframe.src = `${this.iframeDomain}/waas-v1/${this.environmentId}?${params.toString()}`;
|
|
258
335
|
this.logger.debug('Creating iframe with src:', iframe.src);
|
|
259
336
|
// Add iframe to the provided container
|
|
260
337
|
container.appendChild(iframe);
|
|
261
338
|
iframe.onload = ()=>{
|
|
262
|
-
|
|
263
|
-
this.logger.debug('Iframe
|
|
264
|
-
resolve(iframe);
|
|
339
|
+
// The message listener is already set up, so iframe can send ready message
|
|
340
|
+
this.logger.debug('Iframe onload fired, waiting for ready message...');
|
|
265
341
|
};
|
|
266
342
|
iframe.onerror = (error)=>{
|
|
343
|
+
if (messageListener) {
|
|
344
|
+
window.removeEventListener('message', messageListener);
|
|
345
|
+
}
|
|
267
346
|
clearTimeout(iframeTimeoutId);
|
|
268
|
-
this.logger.error('Iframe failed to load:', error);
|
|
269
|
-
reject(new Error('Failed to load iframe'));
|
|
347
|
+
this.logger.error('Iframe failed to load due to errors: ', error);
|
|
348
|
+
reject(new Error('Failed to load iframe due to unknown load errors, this is likely a browser or network issue.'));
|
|
349
|
+
};
|
|
350
|
+
// Set up message listener BEFORE creating iframe
|
|
351
|
+
messageListener = (event)=>{
|
|
352
|
+
if (event.source === iframe.contentWindow && event.data === `iframe-ready-${this.instanceId}`) {
|
|
353
|
+
if (messageListener) {
|
|
354
|
+
window.removeEventListener('message', messageListener);
|
|
355
|
+
}
|
|
356
|
+
clearTimeout(iframeTimeoutId);
|
|
357
|
+
DynamicWalletClient.sharedIframe = iframe;
|
|
358
|
+
this.iframe = iframe;
|
|
359
|
+
DynamicWalletClient.iframeInstanceCount++;
|
|
360
|
+
resolve(iframe);
|
|
361
|
+
var _this_sdkVersion;
|
|
362
|
+
this.logger.info('Iframe loaded successfully...', {
|
|
363
|
+
iframeDomain: this.iframeDomain,
|
|
364
|
+
environmentId: this.environmentId,
|
|
365
|
+
sdkVersion: (_this_sdkVersion = this.sdkVersion) != null ? _this_sdkVersion : '',
|
|
366
|
+
instanceId: this.instanceId,
|
|
367
|
+
chainName: this.chainName
|
|
368
|
+
});
|
|
369
|
+
}
|
|
270
370
|
};
|
|
371
|
+
window.addEventListener('message', messageListener);
|
|
271
372
|
});
|
|
272
373
|
}
|
|
273
374
|
/**
|
|
@@ -592,6 +693,7 @@ class DynamicWalletClient {
|
|
|
592
693
|
this.messageTransport = null;
|
|
593
694
|
this.iframeMessageHandler = null;
|
|
594
695
|
this.iframe = null;
|
|
696
|
+
this.iframeLoadTimeout = 10000;
|
|
595
697
|
this.environmentId = environmentId;
|
|
596
698
|
this.authToken = authToken;
|
|
597
699
|
this.baseApiUrl = baseApiUrl;
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs-wallet/browser-wallet-client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.108",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@dynamic-labs-wallet/core": "0.0.
|
|
6
|
+
"@dynamic-labs-wallet/core": "0.0.108",
|
|
7
7
|
"@dynamic-labs/message-transport": "^4.9.9",
|
|
8
8
|
"@dynamic-labs/logger": "^4.9.9"
|
|
9
9
|
},
|
|
@@ -23,8 +23,7 @@
|
|
|
23
23
|
".": {
|
|
24
24
|
"types": "./index.esm.d.ts",
|
|
25
25
|
"import": "./index.esm.js",
|
|
26
|
-
"require": "./index.cjs.js"
|
|
27
|
-
"default": "./index.cjs.js"
|
|
26
|
+
"require": "./index.cjs.js"
|
|
28
27
|
}
|
|
29
28
|
}
|
|
30
29
|
}
|
package/src/client/client.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export declare class DynamicWalletClient {
|
|
|
16
16
|
private static iframeLoadPromise;
|
|
17
17
|
protected iframe: HTMLIFrameElement | null;
|
|
18
18
|
private debug;
|
|
19
|
+
iframeLoadTimeout: number;
|
|
19
20
|
private static sharedIframe;
|
|
20
21
|
private static iframeInstanceCount;
|
|
21
22
|
sdkVersion: string | undefined;
|
|
@@ -47,6 +48,10 @@ export declare class DynamicWalletClient {
|
|
|
47
48
|
* securely exchange the auth token with iframe securely
|
|
48
49
|
*/
|
|
49
50
|
private initAuthToken;
|
|
51
|
+
/**
|
|
52
|
+
* Reset the shared iframe and iframe load promise, and iframe instance count
|
|
53
|
+
*/
|
|
54
|
+
private resetSharedIframe;
|
|
50
55
|
private loadIframe;
|
|
51
56
|
/**
|
|
52
57
|
* Load an iframe for a specific container
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mCAAmC,EACnC,0BAA0B,EAC1B,2BAA2B,EAC3B,4BAA4B,EAC5B,iBAAiB,EACjB,uBAAuB,EACvB,0BAA0B,EAC1B,+BAA+B,EAC/B,iCAAiC,EACjC,mCAAmC,EACnC,cAAc,EACd,kBAAkB,EAClB,qBAAqB,EACrB,sBAAsB,EACtB,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAGL,eAAe,EAChB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAGL,KAAK,iCAAiC,EACvC,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAIxE,qBAAa,mBAAmB;IAC9B,SAAS,CAAC,SAAS,EAAE,MAAM,CAAC;IAC5B,SAAS,CAAC,MAAM,wCAAU;IACnB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAQ;IACjC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAQ;IACnC,aAAa,EAAE,MAAM,CAAC;IAC7B,OAAO,CAAC,SAAS,CAAS;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,kBAAkB,EAAE,MAAM,CAAC;IAClC,SAAS,CAAC,gBAAgB,EAAE,iCAAiC,GAAG,IAAI,CAAQ;IAC5E,S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