Skip to content

Commit 846912f

Browse files
author
romin-halltari
committed
Use createModalNotReadyError() when modal is not ready on react native
1 parent 09ec393 commit 846912f

File tree

4 files changed

+12
-23
lines changed

4 files changed

+12
-23
lines changed

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ import {
44
JsonRpcRequestPayload,
55
MagicMessageEvent,
66
MagicMessageRequest,
7-
RPCErrorCode,
8-
JsonRpcError,
97
} from '@magic-sdk/types';
108
import { JsonRpcResponse } from './json-rpc';
119
import { createPromise } from '../util/promise-tools';
1210
import { getItem, setItem } from '../util/storage';
1311
import { createJwt } from '../util/web-crypto';
1412
import { SDKEnvironment } from './sdk-environment';
13+
import { createModalNotReadyError } from './sdk-exceptions';
1514

1615
interface RemoveEventListenerFunction {
1716
(): void;
@@ -140,10 +139,7 @@ export abstract class ViewController {
140139
// if the app was initially opened without internet connection. That is
141140
// why we reject the promise without waiting and just let them call it
142141
// again when internet connection is re-established.
143-
const error: JsonRpcError = {
144-
code: RPCErrorCode.InternalError,
145-
message: 'Connection to Magic SDK not ready. Please check your internet connection.',
146-
};
142+
const error = createModalNotReadyError();
147143
reject(error);
148144
}
149145

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,13 @@
22
/* eslint-disable prefer-spread */
33

44
import browserEnv from '@ikscodes/browser-env';
5-
import {
6-
MagicIncomingWindowMessage,
7-
MagicOutgoingWindowMessage,
8-
JsonRpcRequestPayload,
9-
RPCErrorCode,
10-
} from '@magic-sdk/types';
11-
import _ from 'lodash';
5+
import { MagicIncomingWindowMessage, MagicOutgoingWindowMessage, JsonRpcRequestPayload } from '@magic-sdk/types';
126
import { createViewController } from '../../../factories';
137
import { JsonRpcResponse } from '../../../../src/core/json-rpc';
148
import * as storage from '../../../../src/util/storage';
159
import * as webCryptoUtils from '../../../../src/util/web-crypto';
1610
import { SDKEnvironment } from '../../../../src/core/sdk-environment';
11+
import { createModalNotReadyError } from '../../../../src/core/sdk-exceptions';
1712

1813
/**
1914
* Create a dummy request payload.
@@ -220,10 +215,7 @@ test('does not wait for ready and throws error when platform is react-native', a
220215
try {
221216
await viewController.post(MagicOutgoingWindowMessage.MAGIC_HANDLE_REQUEST, payload);
222217
} catch (e) {
223-
expect(e).toEqual({
224-
code: RPCErrorCode.InternalError,
225-
message: 'Connection to Magic SDK not ready. Please check your internet connection.',
226-
});
218+
expect(e).toEqual(createModalNotReadyError());
227219
}
228220
expect(createJwtStub).not.toHaveBeenCalledWith();
229221
expect(onSpy.mock.calls[0][0]).toEqual(MagicIncomingWindowMessage.MAGIC_HANDLE_RESPONSE);

packages/@magic-sdk/react-native-bare/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,16 @@ When attempting to import `Magic`, take note that the React Native metro bundler
8686
For this issue consider using Microsoft's [rnx-kit](https://microsoft.github.io/rnx-kit/docs/guides/bundling) suite of tools that include a plugin for metro that fixes this symlink related error.
8787

8888
### Handling internet connection problems
89-
When an app is opened without internet connection, any request to the Magic SDK will result in a rejection with the following error:
89+
When an app is opened without internet connection, any request to the Magic SDK will result in a rejection with a `MagicSDKError`:
9090

9191
```json
9292
{
93-
"code": -32603,
94-
"message": "Connection to Magic SDK not ready. Please check your internet connection."
93+
"code": "MODAL_NOT_READY",
94+
"rawMessage": "Modal is not ready."
9595
}
9696
```
9797

98+
9899
It is good practice to use [@react-native-community/netinfo](https://www.npmjs.com/package/@react-native-community/netinfo) to track the internet connection state of the device. For your convenience, we've also added a hook that uses this library behind the scenes:
99100

100101

packages/@magic-sdk/react-native-expo/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ When attempting to import `Magic`, take note that the React Native metro bundler
7777
For this issue consider using Microsoft's [rnx-kit](https://microsoft.github.io/rnx-kit/docs/guides/bundling) suite of tools that include a plugin for metro that fixes this symlink related error.
7878

7979
### Handling internet connection problems
80-
When an app is opened without internet connection, any request to the Magic SDK will result in a rejection with the following error:
80+
When an app is opened without internet connection, any request to the Magic SDK will result in a rejection with a `MagicSDKError`:
8181

8282
```json
8383
{
84-
"code": -32603,
85-
"message": "Connection to Magic SDK not ready. Please check your internet connection."
84+
"code": "MODAL_NOT_READY",
85+
"rawMessage": "Modal is not ready."
8686
}
8787
```
8888

0 commit comments

Comments
 (0)