Skip to content

Commit d8632b4

Browse files
authored
Allow Disconnect of MWA (#960)
* can disconnect * add back setting unloading to flase * default to mwa if no other adapters around * always disconect * preserve old logic, but only if adapters with standard wallet adapters is empty * need to flip the boolean * remove MWA checks outright * auto select mobile wallet adapter if no other
1 parent f326fb9 commit d8632b4

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

packages/core/react/src/WalletProvider.tsx

+8-9
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,14 @@ export function WalletProvider({
7676
}
7777
return [mobileWalletAdapter, ...adaptersWithStandardAdapters];
7878
}, [adaptersWithStandardAdapters, mobileWalletAdapter]);
79-
const [walletName, setWalletName] = useLocalStorage<WalletName | null>(
80-
localStorageKey,
81-
getIsMobile(adaptersWithStandardAdapters) ? SolanaMobileWalletAdapterWalletName : null
82-
);
79+
const [walletName, setWalletName] = useLocalStorage<WalletName | null>(localStorageKey, null);
8380
const adapter = useMemo(
84-
() => adaptersWithMobileWalletAdapter.find((a) => a.name === walletName) ?? null,
85-
[adaptersWithMobileWalletAdapter, walletName]
81+
() =>
82+
adaptersWithMobileWalletAdapter.find((a) => a.name === walletName) ??
83+
(adaptersWithMobileWalletAdapter.length === 1 && adaptersWithMobileWalletAdapter[0] === mobileWalletAdapter
84+
? mobileWalletAdapter
85+
: null),
86+
[adaptersWithMobileWalletAdapter, walletName, mobileWalletAdapter]
8687
);
8788
const changeWallet = useCallback(
8889
(nextWalletName: WalletName<string> | null) => {
@@ -105,8 +106,6 @@ export function WalletProvider({
105106
if (!adapter) return;
106107
function handleDisconnect() {
107108
if (isUnloadingRef.current) return;
108-
// Leave the adapter selected in the event of a disconnection.
109-
if (walletName === SolanaMobileWalletAdapterWalletName && getIsMobile(adaptersWithStandardAdapters)) return;
110109
setWalletName(null);
111110
}
112111
adapter.on('disconnect', handleDisconnect);
@@ -150,7 +149,7 @@ export function WalletProvider({
150149
};
151150
}, [adaptersWithStandardAdapters, walletName]);
152151
const handleConnectError = useCallback(() => {
153-
if (adapter && adapter.name !== SolanaMobileWalletAdapterWalletName) {
152+
if (adapter) {
154153
// If any error happens while connecting, unset the adapter.
155154
changeWallet(null);
156155
}

0 commit comments

Comments
 (0)