From 61506cf1ae93d93e50f6f0a765cf105e34078d84 Mon Sep 17 00:00:00 2001 From: Eugene Chybisov Date: Thu, 21 Jul 2022 15:03:46 +0100 Subject: [PATCH] fix: remove attemptEagerConnect --- packages/widget/src/App.tsx | 7 ----- .../WalletProvider/WalletProvider.tsx | 30 +++---------------- .../src/providers/WalletProvider/types.ts | 1 - packages/widget/src/types/widget.ts | 7 ++--- 4 files changed, 7 insertions(+), 38 deletions(-) diff --git a/packages/widget/src/App.tsx b/packages/widget/src/App.tsx index b4259ff64..261a7883e 100644 --- a/packages/widget/src/App.tsx +++ b/packages/widget/src/App.tsx @@ -1,4 +1,3 @@ -import { useEffect } from 'react'; import { Route, Routes } from 'react-router-dom'; import { AppProps, AppProvider } from './AppProvider'; import { AppContainer } from './components/AppContainer'; @@ -11,7 +10,6 @@ import { SelectWalletPage } from './pages/SelectWalletPage'; import { SettingsPage } from './pages/SettingsPage'; import { SwapPage } from './pages/SwapPage'; import { SwapRoutesPage } from './pages/SwapRoutesPage'; -import { useWallet } from './providers/WalletProvider'; import { navigationRoutes } from './utils'; export const App: React.FC = ({ config }) => { @@ -23,11 +21,6 @@ export const App: React.FC = ({ config }) => { }; export const AppDefault = () => { - const { attemptEagerConnect } = useWallet(); - useEffect(() => { - attemptEagerConnect(); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); return (
diff --git a/packages/widget/src/providers/WalletProvider/WalletProvider.tsx b/packages/widget/src/providers/WalletProvider/WalletProvider.tsx index 5f5629b87..00f11651b 100644 --- a/packages/widget/src/providers/WalletProvider/WalletProvider.tsx +++ b/packages/widget/src/providers/WalletProvider/WalletProvider.tsx @@ -30,7 +30,6 @@ const initialContext: WalletContextProps = { switchChain: stub, addChain: stub, addToken: stub, - attemptEagerConnect: stub, account: {}, }; @@ -72,7 +71,7 @@ export const WalletProvider: FC> = ({ children }) => { // only for injected wallets const switchChain = useCallback( async (chainId: number) => { - if (config.walletManagement) { + if (config.walletManagement?.switchChain) { const signer = await config.walletManagement.switchChain(chainId); const account = await extractAccountFromSigner(signer); setAccount(account); @@ -84,7 +83,7 @@ export const WalletProvider: FC> = ({ children }) => { const addChain = useCallback( async (chainId: number) => { - if (config.walletManagement) { + if (config.walletManagement?.addChain) { return config.walletManagement.addChain(chainId); } return walletAddChain(chainId); @@ -94,7 +93,7 @@ export const WalletProvider: FC> = ({ children }) => { const addToken = useCallback( async (chainId: number, token: Token) => { - if (config.walletManagement) { + if (config.walletManagement?.addToken) { return config.walletManagement.addToken(token, chainId); } return switchChainAndAddToken(chainId, token); @@ -102,18 +101,6 @@ export const WalletProvider: FC> = ({ children }) => { [config.walletManagement], ); - const attemptEagerConnect = useCallback(async () => { - if (config.walletManagement) { - try { - const signer = await config.walletManagement.getSigner(); - const account = await extractAccountFromSigner(signer); - setAccount(() => ({ ...account })); - } catch (e) { - console.warn('WalletProvider: attempted eager connect.', e); - } - } - }, [config.walletManagement]); - // keep account information up to date useEffect(() => { const updateAccount = async () => { @@ -137,18 +124,9 @@ export const WalletProvider: FC> = ({ children }) => { switchChain, addChain, addToken, - attemptEagerConnect, account, }), - [ - account, - addChain, - addToken, - connect, - disconnect, - switchChain, - attemptEagerConnect, - ], + [account, addChain, addToken, connect, disconnect, switchChain], ); return ( diff --git a/packages/widget/src/providers/WalletProvider/types.ts b/packages/widget/src/providers/WalletProvider/types.ts index f7bab5118..cdff368ce 100644 --- a/packages/widget/src/providers/WalletProvider/types.ts +++ b/packages/widget/src/providers/WalletProvider/types.ts @@ -9,7 +9,6 @@ export interface WalletContextProps { disconnect(): void; switchChain(chainId: number): Promise; connect(wallet?: Wallet | undefined): Promise; - attemptEagerConnect(): Promise; } export interface WalletAccount { diff --git a/packages/widget/src/types/widget.ts b/packages/widget/src/types/widget.ts index 5f8c06642..38d12de71 100644 --- a/packages/widget/src/types/widget.ts +++ b/packages/widget/src/types/widget.ts @@ -14,10 +14,9 @@ export type ThemeConfig = { export interface WidgetWalletManagement { connect(): Promise; disconnect(): Promise; - getSigner(): Promise; - switchChain(reqChainId: number): Promise; - addToken(token: Token, chainId: number): Promise; - addChain(chainId: number): Promise; + switchChain?(chainId: number): Promise; + addToken?(token: Token, chainId: number): Promise; + addChain?(chainId: number): Promise; signer?: Signer; }