@@ -287,10 +276,10 @@ const WalletSidebar = (props: Props) => {
props.onClose,
props.type,
props.showAddressInput,
+ props.onConnectWallet,
renderWalletOptions,
address,
addressError,
- submitAddress,
]);
return (
diff --git a/wormhole-connect/src/views/v2/Bridge/WalletConnector/index.tsx b/wormhole-connect/src/views/v2/Bridge/WalletConnector/index.tsx
index f39ab7e80..f42423e78 100644
--- a/wormhole-connect/src/views/v2/Bridge/WalletConnector/index.tsx
+++ b/wormhole-connect/src/views/v2/Bridge/WalletConnector/index.tsx
@@ -1,4 +1,4 @@
-import React, { useCallback, useMemo, useState } from 'react';
+import React, { useMemo } from 'react';
import { useSelector } from 'react-redux';
import { useTheme } from '@mui/material/styles';
import { makeStyles } from 'tss-react/mui';
@@ -10,9 +10,9 @@ import Button from 'components/v2/Button';
import { RootState } from 'store';
import { displayWalletAddress } from 'utils';
import { TransferWallet } from 'utils/wallet';
+import { useWalletManager } from 'contexts/WalletManager';
import { TransferSide } from 'config/types';
-import WalletSidebar from './Sidebar';
const useStyles = makeStyles()((theme: any) => ({
connectWallet: {
@@ -49,6 +49,7 @@ type Props = {
// and the sidebar for the list of available wallets.
const WalletConnector = (props: Props) => {
const { disabled = false, type } = props;
+ const { connectWallet } = useWalletManager();
const theme = useTheme();
@@ -56,20 +57,6 @@ const WalletConnector = (props: Props) => {
const mobile = useMediaQuery(theme.breakpoints.down('sm'));
const wallet = useSelector((state: RootState) => state.wallet[type]);
- const [isOpen, setIsOpen] = useState(false);
-
- const connectWallet = useCallback(
- async (popupState?: any) => {
- if (disabled) {
- return;
- }
-
- popupState?.close();
- setIsOpen(true);
- },
- [disabled],
- );
-
const connected = useMemo(() => {
if (!wallet?.address) {
return null;
@@ -97,7 +84,7 @@ const WalletConnector = (props: Props) => {
pointerEvents: 'all !important',
},
}}
- onClick={() => connectWallet()}
+ onClick={() => connectWallet(type)}
>
{mobile
@@ -119,23 +106,10 @@ const WalletConnector = (props: Props) => {
);
} else {
- return (
- <>
- {button}
- {
- setIsOpen(false);
- }}
- showAddressInput={props.type === TransferWallet.RECEIVING}
- />
- >
- );
+ return <>{button}>;
}
}, [
disabled,
- isOpen,
mobile,
props.side,
props.type,
diff --git a/wormhole-connect/src/views/v2/Bridge/index.tsx b/wormhole-connect/src/views/v2/Bridge/index.tsx
index ec97da88f..0e8738c4a 100644
--- a/wormhole-connect/src/views/v2/Bridge/index.tsx
+++ b/wormhole-connect/src/views/v2/Bridge/index.tsx
@@ -29,7 +29,7 @@ import {
setDestToken,
} from 'store/transferInput';
import { isTransferValid, useValidate } from 'utils/transferValidation';
-import { TransferWallet, useConnectToLastUsedWallet } from 'utils/wallet';
+import { TransferWallet } from 'utils/wallet';
import WalletConnector from 'views/v2/Bridge/WalletConnector';
import AssetPicker from 'views/v2/Bridge/AssetPicker';
import WalletController from 'views/v2/Bridge/WalletConnector/Controller';
@@ -195,9 +195,6 @@ const Bridge = () => {
// Pre-fetch available routes
useFetchSupportedRoutes();
- // Connect to any previously used wallets for the selected networks
- useConnectToLastUsedWallet();
-
// Call to initiate transfer inputs validations
useValidate();
diff --git a/wormhole-connect/src/views/v2/Redeem/index.tsx b/wormhole-connect/src/views/v2/Redeem/index.tsx
index 548e27ffe..dffbc2c3a 100644
--- a/wormhole-connect/src/views/v2/Redeem/index.tsx
+++ b/wormhole-connect/src/views/v2/Redeem/index.tsx
@@ -37,6 +37,7 @@ import PoweredByIcon from 'icons/PoweredBy';
import { SDKv2Signer } from 'routes/sdkv2/signer';
import { setRoute } from 'store/router';
import { useUSDamountGetter } from 'hooks/useUSDamountGetter';
+import { useWalletManager } from 'contexts/WalletManager';
import { interpretTransferError } from 'utils/errors';
import {
removeTxFromLocalStorage,
@@ -47,14 +48,8 @@ import {
millisToMinutesAndSeconds,
minutesAndSecondsWithPadding,
} from 'utils/transferValidation';
-import {
- TransferWallet,
- registerWalletSigner,
- switchChain,
-} from 'utils/wallet';
+import { TransferWallet } from 'utils/wallet';
import TransactionDetails from 'views/v2/Redeem/TransactionDetails';
-import WalletSidebar from 'views/v2/Bridge/WalletConnector/Sidebar';
-import { useConnectToLastUsedWallet } from 'utils/wallet';
import type { RootState } from 'store';
import TxCompleteIcon from 'icons/TxComplete';
@@ -145,8 +140,12 @@ const Redeem = () => {
const [transferSuccessEventFired, setTransferSuccessEventFired] =
useState(false);
const [etaExpired, setEtaExpired] = useState(false);
-
- const [isWalletSidebarOpen, setIsWalletSidebarOpen] = useState(false);
+ const {
+ connectWallet,
+ getConnectedWallet,
+ switchChain,
+ registerWalletSigner,
+ } = useWalletManager();
const routeContext = React.useContext(RouteContext);
@@ -159,8 +158,6 @@ const Redeem = () => {
// TODO
}
- useConnectToLastUsedWallet();
-
const {
route: routeName,
timestamp: txTimestamp,
@@ -740,11 +737,19 @@ const Redeem = () => {
throw new Error('Route is not manual or finalizable');
}
+ const receivingConnectedWallet = getConnectedWallet(
+ TransferWallet.RECEIVING,
+ );
+
+ if (!receivingConnectedWallet) {
+ throw new Error('Could not get receiving connected wallet');
+ }
+
const signer = await SDKv2Signer.fromChain(
toChain,
receivingWallet.address,
{},
- TransferWallet.RECEIVING,
+ receivingConnectedWallet,
);
const finishPromise = (() => {
@@ -816,7 +821,7 @@ const Redeem = () => {
);
};
diff --git a/wormhole-connect/vite.config.ts b/wormhole-connect/vite.config.ts
index 0ee380ab8..e95656dbf 100644
--- a/wormhole-connect/vite.config.ts
+++ b/wormhole-connect/vite.config.ts
@@ -59,6 +59,7 @@ const resolve = {
views: path.resolve(__dirname, './src/views'),
'process/': 'process',
'buffer/': 'buffer',
+ 'buffer/index.js': 'buffer',
},
};