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

Add WebView error handling to Example Web App #1083

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Funkatronics
Copy link
Contributor

Adds an error snackbar if a compatible MWA wallet is not found, and the app is running in a webview. See #1082

@@ -54,7 +43,30 @@ function App({ children }: { children: ReactNode }) {
/**
* Note that you don't have to include the SolanaMobileWalletAdapter here;
* It will be added automatically when this app is running in a compatible mobile context.
*
* However, it is recommended to manually include the SolanaSolanaMobileWalletAdapter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: typo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SolanaSolana! nice catch, fixed

uri: getUriForAppIdentity(),
},
authorizationResultCache: createDefaultAuthorizationResultCache(),
chain: 'solana:testnet',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use Devnet, consistent iwith the CLUSTER variable?

onWalletNotFound: async (mobileWalletAdapter: SolanaMobileWalletAdapter) => {
if (typeof window !== 'undefined') {
const userAgent = window.navigator.userAgent.toLowerCase();
if (userAgent.includes('wv')) { // Android WebView
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a more precise way to check for Android Webview? Wondering if there's ever a case where a non-Android Webview also has "wv" in the userAgent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from my research, this is a reliable way to detect Android WebView on Lollipop and higher.

As far as non-android, that should not happen. since MWA is only loaded on Android. If we are on iOS for example. we wont ever get here.

Even so, if we get here its because MWA failed. There is not much we can do apart from either routing the user to the wallets page, or showing some kind of error.

I could change up the logic here to do an android check, and only route to the wallets webpage if we believe we are indeed in a compatible browser and therefore the user likely does not have a wallet installed. Honestly IMO its the assuming the user does not have a wallet part that we should be questioning here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should change up the UX here entirely. We should never auto route to the wallets page, that UX sucks. We should show a dialog with something like:

We did not find a compatible wallet installed on the device

And depending on what browser we think we are in either:

You can see a list of compatible wallets here

or:

This browser does not appear to support MWA

Something like this. Because we don't actually ever know for sure if the user does not have a wallet installed. Its possible they just dismissed the browser exit warning, or dismissed the disambiguation dialog.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default implementation routes to the wallets page because there is not much else we can do. We cannot show UI from the library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants