Skip to content

Commit

Permalink
Merge pull request #861 from magiclabs/remove-15s-timeout
Browse files Browse the repository at this point in the history
remove 15s auto success
  • Loading branch information
Ethella authored Mar 6, 2025
2 parents 18b136a + 22183c3 commit 3ad7748
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 72 deletions.
16 changes: 3 additions & 13 deletions packages/@magic-sdk/provider/src/core/view-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function getRequestPayloadFromBatch(
id?: string | number | null,
): JsonRpcRequestPayload | undefined {
return id && Array.isArray(requestPayload)
? requestPayload.find((p) => p.id === id)
? requestPayload.find(p => p.id === id)
: (requestPayload as JsonRpcRequestPayload);
}

Expand Down Expand Up @@ -175,7 +175,7 @@ export abstract class ViewController {
}

const batchData: JsonRpcResponse[] = [];
const batchIds = Array.isArray(payload) ? payload.map((p) => p.id) : [];
const batchIds = Array.isArray(payload) ? payload.map(p => p.id) : [];
const msg = await createMagicRequest(`${msgType}-${this.parameters}`, payload, this.networkHash);

await this._post(msg);
Expand Down Expand Up @@ -240,22 +240,12 @@ export abstract class ViewController {
}

private waitForReady() {
return new Promise<void>((resolve) => {
return new Promise<void>(resolve => {
const unsubscribe = this.on(MagicIncomingWindowMessage.MAGIC_OVERLAY_READY, () => {
this.isReadyForRequest = true;
resolve();
unsubscribe();
});

// We expect the overlay to be ready within 15 seconds.
// Sometimes the message is not properly processed due to
// webview issues. In that case, after 15 seconds we consider
// the overlay ready, to avoid requests hanging forever.
setTimeout(() => {
this.isReadyForRequest = true;
resolve();
unsubscribe();
}, 15000);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ beforeEach(() => {
browserEnv();
});

test('Receive MAGIC_OVERLAY_READY, resolve `waitForReady` promise', (done) => {
test('Receive MAGIC_OVERLAY_READY, resolve `waitForReady` promise', done => {
const overlay = createViewController('');
const waitForReady = (overlay as any).waitForReady();

Expand All @@ -16,17 +16,3 @@ test('Receive MAGIC_OVERLAY_READY, resolve `waitForReady` promise', (done) => {

window.postMessage({ msgType: MSG_TYPES().MAGIC_OVERLAY_READY }, '*');
});

test('Resolve `waitForReady` promise after timeout', (done) => {
jest.useFakeTimers();
const overlay = createViewController('');
const waitForReady = (overlay as any).waitForReady();

waitForReady.then(() => {
done();
});

// Fast forward time to 15 seconds
jest.advanceTimersByTime(15000);
jest.useRealTimers();
});
Loading

0 comments on commit 3ad7748

Please sign in to comment.