Skip to content

Commit 09ec393

Browse files
author
romin-halltari
committed
Rename: ready -> checkIsReadyForRequest and isReady -> isReadyForRequest
1 parent 170b74b commit 09ec393

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

packages/@magic-sdk/provider/src/core/sdk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,6 @@ export class SDKBase {
196196
* has completed loading and is ready for requests.
197197
*/
198198
public async preload() {
199-
await this.overlay.ready;
199+
await this.overlay.checkIsReadyForRequest;
200200
}
201201
}

packages/@magic-sdk/provider/src/core/view-controller.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ async function persistMagicEventRefreshToken(event: MagicMessageEvent) {
9090
}
9191

9292
export abstract class ViewController {
93-
private isReady = false;
94-
public ready: Promise<void>;
93+
private isReadyForRequest = false;
94+
public checkIsReadyForRequest: Promise<void>;
9595
protected readonly messageHandlers = new Set<(event: MagicMessageEvent) => any>();
9696

9797
/**
@@ -102,7 +102,7 @@ export abstract class ViewController {
102102
* relevant iframe context.
103103
*/
104104
constructor(protected readonly endpoint: string, protected readonly parameters: string) {
105-
this.ready = this.waitForReady();
105+
this.checkIsReadyForRequest = this.waitForReady();
106106
this.listen();
107107
}
108108

@@ -134,12 +134,12 @@ export abstract class ViewController {
134134
): Promise<JsonRpcResponse<ResultType> | JsonRpcResponse<ResultType>[]> {
135135
return createPromise(async (resolve, reject) => {
136136
if (SDKEnvironment.platform !== 'react-native') {
137-
await this.ready;
138-
} else if (!this.isReady) {
139-
// On a mobile environment, `this.ready` never resolves if the app was
140-
// initially opened without internet connection. That is why we reject
141-
// the promise without waiting and just let them call it again when
142-
// internet connection is re-established.
137+
await this.checkIsReadyForRequest;
138+
} else if (!this.isReadyForRequest) {
139+
// On a mobile environment, `this.checkIsReadyForRequest` never resolves
140+
// if the app was initially opened without internet connection. That is
141+
// why we reject the promise without waiting and just let them call it
142+
// again when internet connection is re-established.
143143
const error: JsonRpcError = {
144144
code: RPCErrorCode.InternalError,
145145
message: 'Connection to Magic SDK not ready. Please check your internet connection.',
@@ -211,7 +211,7 @@ export abstract class ViewController {
211211
return new Promise<void>((resolve) => {
212212
this.on(MagicIncomingWindowMessage.MAGIC_OVERLAY_READY, () => {
213213
resolve();
214-
this.isReady = true;
214+
this.isReadyForRequest = true;
215215
});
216216
});
217217
}

packages/@magic-sdk/provider/test/spec/core/view-controller/post.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function stubViewController(viewController: any, events: [MagicIncomingWindowMes
6161
const postSpy = jest.fn();
6262

6363
viewController.on = onSpy;
64-
viewController.ready = Promise.resolve();
64+
viewController.checkIsReadyForRequest = Promise.resolve();
6565
viewController._post = postSpy;
6666

6767
return { handlerSpy, onSpy, postSpy };
@@ -213,7 +213,7 @@ test('does not wait for ready and throws error when platform is react-native', a
213213
const { handlerSpy, onSpy } = stubViewController(viewController, [
214214
[MagicIncomingWindowMessage.MAGIC_HANDLE_RESPONSE, eventWithRt],
215215
]);
216-
viewController.ready = new Promise(() => null);
216+
viewController.checkIsReadyForRequest = new Promise(() => null);
217217

218218
const payload = requestPayload();
219219

@@ -239,8 +239,8 @@ test('does not call web crypto api if platform is not web', async () => {
239239
]);
240240
const payload = requestPayload();
241241

242-
// @ts-ignore isReady is private
243-
viewController.isReady = true;
242+
// @ts-ignore isReadyForRequest is private
243+
viewController.isReadyForRequest = true;
244244

245245
const response = await viewController.post(MagicOutgoingWindowMessage.MAGIC_HANDLE_REQUEST, payload);
246246

0 commit comments

Comments
 (0)