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

Allow Disconnect of MWA #960

Merged
merged 8 commits into from
Aug 23, 2024

Conversation

alex-fung
Copy link
Contributor

@alex-fung alex-fung commented May 9, 2024

Currently, if other wallets are available on a dApp on Android, the only one that can be used is the MWA. This PR updates the WalletProvider so that it won't be auto-selected and can be disconnected if other wallets are available.

Comments posted at alex-fung#1 are already addressed (opened against wrong branch)

Before:
https://github.com/anza-xyz/wallet-adapter/assets/2409008/19a522f9-d8f1-4ad9-8374-03ac8ca35de8

After:
With MWA and another wallet:
https://github.com/anza-xyz/wallet-adapter/assets/2409008/36dca9c4-b585-4017-a84a-0fadeb8c10eb
With just MWA:
https://github.com/anza-xyz/wallet-adapter/assets/2409008/da684467-2791-428d-8783-3a9c5485542c

Copy link
Contributor

@Funkatronics Funkatronics left a comment

Choose a reason for hiding this comment

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

Reviewed and approved by me, but I am not a maintainer here unfortunately. Will need input from @jordaaash or @steveluscher

@alirezaayande92

This comment was marked as spam.

Copy link
Collaborator

@steveluscher steveluscher left a comment

Choose a reason for hiding this comment

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

Understood; thanks for this!

I think the original presumption was that there are no wallets that work (or yield a good experience) on mobile web, but I presume TipLink is out there to prove that wrong.

Can you add, to this PR, a quick screencast of how your loadable wallet works so that folks can understand the motivation for this change?

@@ -78,7 +78,9 @@ export function WalletProvider({
}, [adaptersWithStandardAdapters, mobileWalletAdapter]);
const [walletName, setWalletName] = useLocalStorage<WalletName | null>(
localStorageKey,
getIsMobile(adaptersWithStandardAdapters) ? SolanaMobileWalletAdapterWalletName : null
adaptersWithStandardAdapters.length === 0 && getIsMobile(adaptersWithStandardAdapters)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm. This has the effect of, if any adapter is included, to not select MWA. The problem with this in practice is that almost all dapps will include adapters, even ones they don't need because they've been deprecated by Standard Wallets, or ones that simply don't work at all on the platform. This is especially true because most dapps I've seen don't use separate mobile builds with conditional compilation of included adapters.

This basically means that it's always going to be false, and we're never even going to do the getIsMobile check. Now, I'm probably fine with eliminating all preference for MWA, but I want to be clear that's what we're doing here, and if so, we might as well just do it outright and remove these checks.

Copy link
Collaborator

@jordaaash jordaaash left a comment

Choose a reason for hiding this comment

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

Thank you for the new video, this looks good. I left a comment in the code, but if MWA is the only adapter (or maybe if there's only one adapter in general) we could select it by default. We would have to consider if this has any other unintended effects on the state. If it does we can scrap the idea and a wallet will always need to be selected by name.

localStorageKey,
getIsMobile(adaptersWithStandardAdapters) ? SolanaMobileWalletAdapterWalletName : null
);
const [walletName, setWalletName] = useLocalStorage<WalletName | null>(localStorageKey, null);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure there's anything good to be done about this, but if the user has opened the app before, I think it'll probably still have MWA in local storage and selected by default.

Copy link
Contributor Author

@alex-fung alex-fung Jul 23, 2024

Choose a reason for hiding this comment

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

yea fair enough – though that behavior exists for any adapter so at least it's fair?

localStorageKey,
getIsMobile(adaptersWithStandardAdapters) ? SolanaMobileWalletAdapterWalletName : null
);
const [walletName, setWalletName] = useLocalStorage<WalletName | null>(localStorageKey, null);
const adapter = useMemo(
() => adaptersWithMobileWalletAdapter.find((a) => a.name === walletName) ?? null,
Copy link
Collaborator

Choose a reason for hiding this comment

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

One possibility for this: if the only item in adaptersWithMobileWalletAdapter is MWA, could we select it by default?

This preserves the existing behavior if the user is on Android mobile (so no other wallets are being injected), the app is passing wallets={[]}, and no other Standard Wallets are registered. I don't know how common this is, but it might not hurt?

@alex-fung
Copy link
Contributor Author

Updated so that if only MWA is available, it basically locks it as the adapter

MWA only:
https://github.com/user-attachments/assets/3bd0afab-9e46-4397-9a44-97cea086b47c

Other adapters as well:
https://github.com/user-attachments/assets/7d8df7ea-fedb-4043-98e9-9118fde6c625

@jordaaash jordaaash changed the base branch from master to no-mwa-default August 23, 2024 21:08
@jordaaash jordaaash merged commit d8632b4 into anza-xyz:no-mwa-default Aug 23, 2024
@jordaaash
Copy link
Collaborator

I've merged this into a feature branch since it needs a changeset before it can be merged to master. I'll handle that.

@jordaaash
Copy link
Collaborator

jordaaash added a commit that referenced this pull request Aug 24, 2024
@jordaaash jordaaash mentioned this pull request Aug 24, 2024
jordaaash added a commit that referenced this pull request Aug 24, 2024
* Revert "add changeset"

This reverts commit aea46eb.

* Revert "Allow Disconnect of MWA  (#960)"

This reverts commit d8632b4.
jordaaash added a commit that referenced this pull request Aug 24, 2024
This reverts commit 3761cd8.
@jordaaash jordaaash mentioned this pull request Aug 24, 2024
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.

5 participants