magiclabs / magic-js

Magic browser/React Native JavaScript SDK is your entry-point to integrating passwordless authentication inside your application.
https://magic.link/docs/api-reference/client-side-sdks/web
Apache License 2.0
457 stars 85 forks source link

Fix multiple network setups for React Native SDKs #687

Closed romin-halltari closed 9 months ago

romin-halltari commented 9 months ago

📦 Pull Request

Previously, we were using await this.checkIsReadyForRequest before sending a request. Problem is, after first render, this promise will return immediately, even when the relayer is re-rendered. That is because we don't re-construct the controller each time a render happens (that's a no-op).

This PR introduces the isReadyForRequest boolean which we can reset to false when the relayer is unmounted. That allows us to wait again until the WebView is ready for requests on re-mount.

We still keep checkIsReadyForRequest because it is used for faster initial requests in browser environments.

Before: https://github.com/magiclabs/magic-js/assets/150072475/7c184022-7938-4a8b-a9ee-c6ac50ee281c

After: https://github.com/magiclabs/magic-js/assets/150072475/003dcb69-9b1c-41c6-a5bd-1052a9204aca

[Provide a general summary of the pull request here.]

✅ Fixed Issues

🚨 Test instructions

[Describe any additional context required to test the PR/feature/bug fix.]

⚠️ Don't forget to add a semver label!

Please only add one label:

📦 Published PR as canary version: Canary Versions
:sparkles: Test out this PR locally via: ```bash npm install @magic-ext/algorand@16.4.1-canary.687.7227861220.0 npm install @magic-ext/aptos@4.4.1-canary.687.7227861220.0 npm install @magic-ext/avalanche@16.4.1-canary.687.7227861220.0 npm install @magic-ext/bitcoin@16.4.1-canary.687.7227861220.0 npm install @magic-ext/conflux@14.4.1-canary.687.7227861220.0 npm install @magic-ext/cosmos@16.4.1-canary.687.7227861220.0 npm install @magic-ext/ed25519@12.4.1-canary.687.7227861220.0 npm install @magic-ext/flow@16.4.1-canary.687.7227861220.0 npm install @magic-ext/gdkms@4.4.1-canary.687.7227861220.0 npm install @magic-ext/harmony@16.4.1-canary.687.7227861220.0 npm install @magic-ext/icon@16.4.1-canary.687.7227861220.0 npm install @magic-ext/near@16.4.1-canary.687.7227861220.0 npm install @magic-ext/oauth@15.4.1-canary.687.7227861220.0 npm install @magic-ext/oidc@4.4.1-canary.687.7227861220.0 npm install @magic-ext/polkadot@16.4.1-canary.687.7227861220.0 npm install @magic-ext/react-native-bare-oauth@18.1.1-canary.687.7227861220.0 npm install @magic-ext/react-native-expo-oauth@18.1.1-canary.687.7227861220.0 npm install @magic-ext/solana@18.2.1-canary.687.7227861220.0 npm install @magic-ext/taquito@13.4.1-canary.687.7227861220.0 npm install @magic-ext/terra@13.4.1-canary.687.7227861220.0 npm install @magic-ext/tezos@16.4.1-canary.687.7227861220.0 npm install @magic-ext/webauthn@15.4.1-canary.687.7227861220.0 npm install @magic-ext/zilliqa@16.4.1-canary.687.7227861220.0 npm install @magic-sdk/commons@17.4.1-canary.687.7227861220.0 npm install @magic-sdk/pnp@15.4.1-canary.687.7227861220.0 npm install @magic-sdk/provider@21.4.1-canary.687.7227861220.0 npm install @magic-sdk/react-native-bare@22.4.1-canary.687.7227861220.0 npm install @magic-sdk/react-native-expo@22.4.1-canary.687.7227861220.0 npm install magic-sdk@21.4.1-canary.687.7227861220.0 # or yarn add @magic-ext/algorand@16.4.1-canary.687.7227861220.0 yarn add @magic-ext/aptos@4.4.1-canary.687.7227861220.0 yarn add @magic-ext/avalanche@16.4.1-canary.687.7227861220.0 yarn add @magic-ext/bitcoin@16.4.1-canary.687.7227861220.0 yarn add @magic-ext/conflux@14.4.1-canary.687.7227861220.0 yarn add @magic-ext/cosmos@16.4.1-canary.687.7227861220.0 yarn add @magic-ext/ed25519@12.4.1-canary.687.7227861220.0 yarn add @magic-ext/flow@16.4.1-canary.687.7227861220.0 yarn add @magic-ext/gdkms@4.4.1-canary.687.7227861220.0 yarn add @magic-ext/harmony@16.4.1-canary.687.7227861220.0 yarn add @magic-ext/icon@16.4.1-canary.687.7227861220.0 yarn add @magic-ext/near@16.4.1-canary.687.7227861220.0 yarn add @magic-ext/oauth@15.4.1-canary.687.7227861220.0 yarn add @magic-ext/oidc@4.4.1-canary.687.7227861220.0 yarn add @magic-ext/polkadot@16.4.1-canary.687.7227861220.0 yarn add @magic-ext/react-native-bare-oauth@18.1.1-canary.687.7227861220.0 yarn add @magic-ext/react-native-expo-oauth@18.1.1-canary.687.7227861220.0 yarn add @magic-ext/solana@18.2.1-canary.687.7227861220.0 yarn add @magic-ext/taquito@13.4.1-canary.687.7227861220.0 yarn add @magic-ext/terra@13.4.1-canary.687.7227861220.0 yarn add @magic-ext/tezos@16.4.1-canary.687.7227861220.0 yarn add @magic-ext/webauthn@15.4.1-canary.687.7227861220.0 yarn add @magic-ext/zilliqa@16.4.1-canary.687.7227861220.0 yarn add @magic-sdk/commons@17.4.1-canary.687.7227861220.0 yarn add @magic-sdk/pnp@15.4.1-canary.687.7227861220.0 yarn add @magic-sdk/provider@21.4.1-canary.687.7227861220.0 yarn add @magic-sdk/react-native-bare@22.4.1-canary.687.7227861220.0 yarn add @magic-sdk/react-native-expo@22.4.1-canary.687.7227861220.0 yarn add magic-sdk@21.4.1-canary.687.7227861220.0 ```
shortcut-integration[bot] commented 9 months ago

This pull request has been linked to Shortcut Story #91530: Investigate and provide solution for issue with switching networks on react native (Snowball.money).

Ariflo commented 9 months ago

:rocket: PR was released in @magic-ext/algorand@16.4.1, @magic-ext/aptos@4.4.1, @magic-ext/avalanche@16.4.1, @magic-ext/bitcoin@16.4.1, @magic-ext/conflux@14.4.1, @magic-ext/cosmos@16.4.1, @magic-ext/ed25519@12.4.1, @magic-ext/flow@16.4.1, @magic-ext/gdkms@4.4.1, @magic-ext/harmony@16.4.1, @magic-ext/icon@16.4.1, @magic-ext/near@16.4.1, @magic-ext/oauth@15.4.1, @magic-ext/oidc@4.4.1, @magic-ext/polkadot@16.4.1, @magic-ext/react-native-bare-oauth@18.1.1, @magic-ext/react-native-expo-oauth@18.1.1, @magic-ext/solana@18.2.1, @magic-ext/taquito@13.4.1, @magic-ext/terra@13.4.1, @magic-ext/tezos@16.4.1, @magic-ext/webauthn@15.4.1, @magic-ext/zilliqa@16.4.1, @magic-sdk/commons@17.4.1, @magic-sdk/pnp@15.4.1, @magic-sdk/provider@21.4.1, @magic-sdk/react-native-bare@22.4.1, @magic-sdk/react-native-expo@22.4.1, magic-sdk@21.4.1 :rocket: