-
Notifications
You must be signed in to change notification settings - Fork 902
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
base: master
Are you sure you want to change the base?
Changes from 6 commits
3cdb221
4ea7236
f61090c
5642ba7
c72209f
1651cbd
af496bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line 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) | ||
? SolanaMobileWalletAdapterWalletName | ||
: null | ||
); | ||
const adapter = useMemo( | ||
() => adaptersWithMobileWalletAdapter.find((a) => a.name === walletName) ?? null, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One possibility for this: if the only item in This preserves the existing behavior if the user is on Android mobile (so no other wallets are being injected), the app is passing |
||
|
@@ -106,7 +108,12 @@ export function WalletProvider({ | |
function handleDisconnect() { | ||
if (isUnloadingRef.current) return; | ||
// Leave the adapter selected in the event of a disconnection. | ||
if (walletName === SolanaMobileWalletAdapterWalletName && getIsMobile(adaptersWithStandardAdapters)) return; | ||
if ( | ||
walletName === SolanaMobileWalletAdapterWalletName && | ||
adaptersWithStandardAdapters.length === 0 && | ||
getIsMobile(adaptersWithStandardAdapters) | ||
) | ||
return; | ||
setWalletName(null); | ||
} | ||
adapter.on('disconnect', handleDisconnect); | ||
|
@@ -150,11 +157,14 @@ export function WalletProvider({ | |
}; | ||
}, [adaptersWithStandardAdapters, walletName]); | ||
const handleConnectError = useCallback(() => { | ||
if (adapter && adapter.name !== SolanaMobileWalletAdapterWalletName) { | ||
if ( | ||
adapter && | ||
(adapter.name !== SolanaMobileWalletAdapterWalletName || adaptersWithStandardAdapters.length !== 0) | ||
) { | ||
// If any error happens while connecting, unset the adapter. | ||
changeWallet(null); | ||
} | ||
}, [adapter, changeWallet]); | ||
}, [adapter, changeWallet, adaptersWithStandardAdapters]); | ||
const selectWallet = useCallback( | ||
(walletName: WalletName | null) => { | ||
hasUserSelectedAWallet.current = true; | ||
|
There was a problem hiding this comment.
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 thegetIsMobile
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.