diff --git a/packages/core/package.json b/packages/core/package.json index 7aa604a77..c2a23599f 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@web3-onboard/core", - "version": "2.22.2-alpha.1", + "version": "2.22.2-alpha.2", "description": "Web3-Onboard makes it simple to connect Ethereum hardware and software wallets to your dapp. Features standardized spec compliant web3 providers for all supported wallets, framework agnostic modern javascript UI with code splitting, CSS customization, multi-chain and multi-account support, reactive wallet state subscriptions and real-time transaction state change notifications.", "keywords": [ "Ethereum", diff --git a/packages/core/src/connect.ts b/packages/core/src/connect.ts index f7d08f9de..e0d8b363f 100644 --- a/packages/core/src/connect.ts +++ b/packages/core/src/connect.ts @@ -31,8 +31,9 @@ async function connect( 'At least one chain must be set before attempting to connect a wallet' ) - const { autoSelect } = options || { - autoSelect: { label: '', disableModals: false } + let { autoSelect } = options || {} + if (!autoSelect) { + autoSelect = { label: '', disableModals: false } } // if auto selecting, wait until next event loop @@ -44,7 +45,6 @@ async function connect( if (!state.get().walletModules.length) { setWalletModules(configuration.initialWalletInit) } - connectWallet$.next({ autoSelect: typeof autoSelect === 'string' diff --git a/packages/core/src/disconnect.ts b/packages/core/src/disconnect.ts index 1321ad34a..9c29f8b4e 100644 --- a/packages/core/src/disconnect.ts +++ b/packages/core/src/disconnect.ts @@ -44,18 +44,25 @@ async function disconnect(options: DisconnectOptions): Promise { disconnectWallet$.next(label) removeWallet(label) - const labels = JSON.parse( - getLocalStore(STORAGE_KEYS.LAST_CONNECTED_WALLET) || '' - ) + const lastConnectedWallets = getLocalStore(STORAGE_KEYS.LAST_CONNECTED_WALLET) + if (lastConnectedWallets) { + try { + const labels = JSON.parse(lastConnectedWallets) - if (Array.isArray(labels) && labels.indexOf(label) >= 0) { - setLocalStore( - STORAGE_KEYS.LAST_CONNECTED_WALLET, - JSON.stringify(labels.filter(walletLabel => walletLabel !== label)) - ) - } - if (typeof labels === 'string' && labels === label) { - delLocalStore(STORAGE_KEYS.LAST_CONNECTED_WALLET) + if (Array.isArray(labels) && labels.indexOf(label) >= 0) { + setLocalStore( + STORAGE_KEYS.LAST_CONNECTED_WALLET, + JSON.stringify(labels.filter(walletLabel => walletLabel !== label)) + ) + } + if (typeof labels === 'string' && labels === label) { + delLocalStore(STORAGE_KEYS.LAST_CONNECTED_WALLET) + } + } catch (e) { + console.error( + `There was an error disconnecting the last connected wallet from localStorage - Error: ${e}` + ) + } } return state.get().wallets diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 81d5e07d0..3d785ffb6 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -290,6 +290,12 @@ function init(options: InitOptions): OnboardAPI { ) { connectAllPreviousWallets(lastConnectedWalletsParsed, connect) } + if ( + lastConnectedWalletsParsed && + typeof lastConnectedWalletsParsed === 'string' + ) { + connectAllPreviousWallets([lastConnectedWalletsParsed], connect) + } } catch (err) { // Handle for legacy single wallet approach // Above try will throw syntax error is local storage is not json @@ -361,6 +367,7 @@ const connectAllPreviousWallets = async ( } } } + setLocalStore( STORAGE_KEYS.LAST_CONNECTED_WALLET, JSON.stringify(activeWalletsList) diff --git a/packages/demo/package.json b/packages/demo/package.json index a5c75393a..1d293d270 100644 --- a/packages/demo/package.json +++ b/packages/demo/package.json @@ -33,7 +33,7 @@ "@web3-onboard/blocto": "^2.1.1", "@web3-onboard/capsule": "2.2.0-alpha.1", "@web3-onboard/cede-store": "^2.3.1", - "@web3-onboard/core": "2.22.2-alpha.1", + "@web3-onboard/core": "2.22.2-alpha.2", "@web3-onboard/coinbase": "^2.4.1", "@web3-onboard/dcent": "^2.2.7", "@web3-onboard/enkrypt": "^2.1.1", diff --git a/packages/demo/src/App.svelte b/packages/demo/src/App.svelte index e44c67040..f1bcefbb2 100644 --- a/packages/demo/src/App.svelte +++ b/packages/demo/src/App.svelte @@ -282,8 +282,8 @@ const onboard = Onboard({ wallets: [ metamaskSDKWallet, - injected, coinbaseWallet, + injected, ledger, trezor, walletConnect, @@ -415,7 +415,8 @@ connect: { // disableClose: true, // removeWhereIsMyWalletWarning: true, - autoConnectAllPreviousWallet: true + // autoConnectLastWallet: false, + autoConnectAllPreviousWallet: true, }, appMetadata: { name: 'Blocknative', diff --git a/packages/react/package.json b/packages/react/package.json index 924d5a74b..ff382478e 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -1,6 +1,6 @@ { "name": "@web3-onboard/react", - "version": "2.9.2-alpha.1", + "version": "2.9.2-alpha.2", "description": "A collection of React hooks for integrating Web3-Onboard in to React and Next.js projects. Web3-Onboard makes it simple to connect Ethereum hardware and software wallets to your dapp. Features standardised spec compliant web3 providers for all supported wallets, modern javascript UI with code splitting, CSS customization, multi-chain and multi-account support, reactive wallet state subscriptions and real-time transaction state change notifications.", "keywords": [ "Ethereum", @@ -61,7 +61,7 @@ "typescript": "^5.4.5" }, "dependencies": { - "@web3-onboard/core": "2.22.2-alpha.1", + "@web3-onboard/core": "2.22.2-alpha.2", "@web3-onboard/common": "^2.4.1", "use-sync-external-store": "1.0.0" }, diff --git a/packages/solid/package.json b/packages/solid/package.json index 1b873567c..2883bd50e 100644 --- a/packages/solid/package.json +++ b/packages/solid/package.json @@ -1,6 +1,6 @@ { "name": "@web3-onboard/solid", - "version": "2.1.2-alpha.1", + "version": "2.1.2-alpha.2", "description": "A collection of solid Composables for integrating Web3-Onboard in to a Solid project. Web3-Onboard makes it simple to connect Ethereum hardware and software wallets to your dapp. Features standardized spec compliant web3 providers for all supported wallets, modern javascript UI with code splitting, CSS customization, multi-chain and multi-account support, reactive wallet state subscriptions and real-time transaction state change notifications.", "keywords": [ "Ethereum", @@ -63,7 +63,7 @@ }, "dependencies": { "@web3-onboard/common": "^2.4.1", - "@web3-onboard/core": "2.22.2-alpha.1", + "@web3-onboard/core": "2.22.2-alpha.2", "solid-js": "^1.8.1" } } diff --git a/packages/vue/package.json b/packages/vue/package.json index c3c6516d3..026cc121a 100644 --- a/packages/vue/package.json +++ b/packages/vue/package.json @@ -1,6 +1,6 @@ { "name": "@web3-onboard/vue", - "version": "2.8.2-alpha.1", + "version": "2.8.2-alpha.2", "description": "A collection of Vue Composables for integrating Web3-Onboard in to a Vue or Nuxt project. Web3-Onboard makes it simple to connect Ethereum hardware and software wallets to your dapp. Features standardized spec compliant web3 providers for all supported wallets, modern javascript UI with code splitting, CSS customization, multi-chain and multi-account support, reactive wallet state subscriptions and real-time transaction state change notifications.", "keywords": [ "Ethereum", @@ -62,7 +62,7 @@ "@vueuse/core": "^8.4.2", "@vueuse/rxjs": "^8.2.0", "@web3-onboard/common": "^2.4.1", - "@web3-onboard/core": "2.22.2-alpha.1", + "@web3-onboard/core": "2.22.2-alpha.2", "vue-demi": "^0.12.4" }, "peerDependencies": {