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

remove 15s auto success #861

Merged
merged 3 commits into from
Mar 6, 2025
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
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
Loading