Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: consider the provider ready after 15s even if the message hasn't arrived #760

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/@magic-sdk/provider/src/core/view-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,16 @@ export abstract class ViewController {
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(() => {
Ethella marked this conversation as resolved.
Show resolved Hide resolved
this.isReadyForRequest = true;
resolve();
unsubscribe();
}, 15000);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,17 @@ 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