diff --git a/.changeset/large-seas-play.md b/.changeset/large-seas-play.md new file mode 100644 index 000000000..9b612f07a --- /dev/null +++ b/.changeset/large-seas-play.md @@ -0,0 +1,5 @@ +--- +'@solana/wallet-adapter-react': patch +--- + +Update MWA default selection behavior diff --git a/packages/core/react/src/WalletProvider.tsx b/packages/core/react/src/WalletProvider.tsx index be50c5d7f..83905c1ad 100644 --- a/packages/core/react/src/WalletProvider.tsx +++ b/packages/core/react/src/WalletProvider.tsx @@ -76,13 +76,14 @@ export function WalletProvider({ } return [mobileWalletAdapter, ...adaptersWithStandardAdapters]; }, [adaptersWithStandardAdapters, mobileWalletAdapter]); - const [walletName, setWalletName] = useLocalStorage( - localStorageKey, - getIsMobile(adaptersWithStandardAdapters) ? SolanaMobileWalletAdapterWalletName : null - ); + const [walletName, setWalletName] = useLocalStorage(localStorageKey, null); const adapter = useMemo( - () => adaptersWithMobileWalletAdapter.find((a) => a.name === walletName) ?? null, - [adaptersWithMobileWalletAdapter, walletName] + () => + adaptersWithMobileWalletAdapter.find((a) => a.name === walletName) ?? + (adaptersWithMobileWalletAdapter.length === 1 && adaptersWithMobileWalletAdapter[0] === mobileWalletAdapter + ? mobileWalletAdapter + : null), + [adaptersWithMobileWalletAdapter, walletName, mobileWalletAdapter] ); const changeWallet = useCallback( (nextWalletName: WalletName | null) => { @@ -105,8 +106,6 @@ export function WalletProvider({ if (!adapter) return; function handleDisconnect() { if (isUnloadingRef.current) return; - // Leave the adapter selected in the event of a disconnection. - if (walletName === SolanaMobileWalletAdapterWalletName && getIsMobile(adaptersWithStandardAdapters)) return; setWalletName(null); } adapter.on('disconnect', handleDisconnect); @@ -150,7 +149,7 @@ export function WalletProvider({ }; }, [adaptersWithStandardAdapters, walletName]); const handleConnectError = useCallback(() => { - if (adapter && adapter.name !== SolanaMobileWalletAdapterWalletName) { + if (adapter) { // If any error happens while connecting, unset the adapter. changeWallet(null); }