File tree Expand file tree Collapse file tree 6 files changed +17
-29
lines changed Expand file tree Collapse file tree 6 files changed +17
-29
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " thirdweb " : patch
3+ ---
4+
5+ Always reconnect any previously connected wallet properly
Original file line number Diff line number Diff line change @@ -14,7 +14,6 @@ export function useAutoConnectCore(
1414 storage : AsyncStorage ,
1515 props : AutoConnectProps & { wallets : Wallet [ ] } ,
1616 createWalletFn : ( id : WalletId ) => Wallet ,
17- getInstalledWallets ?: ( ) => Wallet [ ] ,
1817) {
1918 const manager = useConnectionManagerCtx ( "useAutoConnect" ) ;
2019 const { connect } = useConnect ( {
@@ -28,7 +27,6 @@ export function useAutoConnectCore(
2827 autoConnectCore ( {
2928 connectOverride : connect ,
3029 createWalletFn,
31- getInstalledWallets,
3230 manager,
3331 props,
3432 setLastAuthProvider,
Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ import { webLocalStorage } from "../../../../utils/storage/webStorage.js";
22import type { AutoConnectProps } from "../../../../wallets/connection/types.js" ;
33import { createWallet } from "../../../../wallets/create-wallet.js" ;
44import { getDefaultWallets } from "../../../../wallets/defaultWallets.js" ;
5- import { getInstalledWalletProviders } from "../../../../wallets/injected/mipdStore.js" ;
65import { useAutoConnectCore } from "../../../core/hooks/wallets/useAutoConnect.js" ;
76
87/**
@@ -34,15 +33,5 @@ export function useAutoConnect(props: AutoConnectProps) {
3433 wallets,
3534 } ,
3635 createWallet ,
37- ( ) => {
38- const specifiedWalletIds = new Set ( wallets . map ( ( x ) => x . id ) ) ;
39-
40- // pass the wallets that are not already specified but are installed by the user
41- const installedWallets = getInstalledWalletProviders ( )
42- . filter ( ( x ) => ! specifiedWalletIds . has ( x . info . rdns ) )
43- . map ( ( x ) => createWallet ( x . info . rdns ) ) ;
44-
45- return installedWallets ;
46- } ,
4736 ) ;
4837}
Original file line number Diff line number Diff line change 11import { webLocalStorage } from "../../utils/storage/webStorage.js" ;
22import { createWallet } from "../create-wallet.js" ;
33import { getDefaultWallets } from "../defaultWallets.js" ;
4- import { getInstalledWalletProviders } from "../injected/mipdStore.js" ;
54import type { Wallet } from "../interfaces/wallet.js" ;
65import { createConnectionManager } from "../manager/index.js" ;
76import { autoConnectCore } from "./autoConnectCore.js" ;
@@ -44,16 +43,6 @@ export async function autoConnect(
4443 const manager = createConnectionManager ( webLocalStorage ) ;
4544 const result = await autoConnectCore ( {
4645 createWalletFn : createWallet ,
47- getInstalledWallets : ( ) => {
48- const specifiedWalletIds = new Set ( wallets . map ( ( x ) => x . id ) ) ;
49-
50- // pass the wallets that are not already specified but are installed by the user
51- const installedWallets = getInstalledWalletProviders ( )
52- . filter ( ( x ) => ! specifiedWalletIds . has ( x . info . rdns ) )
53- . map ( ( x ) => createWallet ( x . info . rdns ) ) ;
54-
55- return installedWallets ;
56- } ,
5746 manager,
5847 props : {
5948 ...props ,
Original file line number Diff line number Diff line change @@ -28,7 +28,6 @@ type AutoConnectCoreProps = {
2828 connectOverride ?: (
2929 walletOrFn : Wallet | ( ( ) => Promise < Wallet > ) ,
3030 ) => Promise < Wallet | null > ;
31- getInstalledWallets ?: ( ) => Wallet [ ] ;
3231 setLastAuthProvider ?: (
3332 authProvider : AuthArgsType [ "strategy" ] ,
3433 storage : AsyncStorage ,
@@ -69,7 +68,6 @@ const _autoConnectCore = async ({
6968 createWalletFn,
7069 manager,
7170 connectOverride,
72- getInstalledWallets,
7371 setLastAuthProvider,
7472} : AutoConnectCoreProps ) : Promise < boolean > => {
7573 const { wallets, onConnect } = props ;
@@ -120,7 +118,17 @@ const _autoConnectCore = async ({
120118 // in that case, we default to the passed chain to connect to
121119 const lastConnectedChain =
122120 ( await getLastConnectedChain ( storage ) ) || props . chain ;
123- const availableWallets = [ ...wallets , ...( getInstalledWallets ?.( ) ?? [ ] ) ] ;
121+ const availableWallets = lastConnectedWalletIds . map ( ( id ) => {
122+ const specifiedWallet = wallets . find ( ( w ) => w . id === id ) ;
123+ if ( specifiedWallet ) {
124+ return specifiedWallet ;
125+ }
126+ return createWalletFn ( id as WalletId ) ;
127+ } ) ;
128+ console . log (
129+ "availableWallets" ,
130+ availableWallets . map ( ( w ) => w . id ) ,
131+ ) ;
124132 const activeWallet =
125133 lastActiveWalletId &&
126134 ( availableWallets . find ( ( w ) => w . id === lastActiveWalletId ) ||
Original file line number Diff line number Diff line change @@ -238,13 +238,12 @@ export function createConnectionManager(storage: AsyncStorage) {
238238 // save last connected wallet ids to storage
239239 effect (
240240 async ( ) => {
241- const prevAccounts = ( await getStoredConnectedWalletIds ( storage ) ) || [ ] ;
242241 const accounts = connectedWallets . getValue ( ) ;
243242 const ids = accounts . map ( ( acc ) => acc ?. id ) . filter ( ( c ) => ! ! c ) as string [ ] ;
244243
245244 storage . setItem (
246245 CONNECTED_WALLET_IDS ,
247- stringify ( Array . from ( new Set ( [ ...prevAccounts , ... ids ] ) ) ) ,
246+ stringify ( Array . from ( new Set ( [ ...ids ] ) ) ) ,
248247 ) ;
249248 } ,
250249 [ connectedWallets ] ,
You can’t perform that action at this time.
0 commit comments