Skip to content

Commit

Permalink
revert: add switch wallet functionality (#1125)
Browse files Browse the repository at this point in the history
revert: add switch wallet funtionality

Co-authored-by: chary <[email protected]>
  • Loading branch information
Hemanthghs and charymalloju authored Jan 23, 2024
1 parent 701ac4b commit b5c0051
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { useAppDispatch, useAppSelector } from '@/custom-hooks/StateHooks';
import Image from 'next/image';
import React, { useState } from 'react';
import React from 'react';
import { Tooltip } from '@mui/material';
import { LOGOUT_ICON, SUPPORTED_WALLETS } from '@/utils/constants';
import {
establishWalletConnection,
resetWallet,
} from '@/store/features/wallet/walletSlice';
import { getLocalNetworks, getWalletName, logout } from '@/utils/localStorage';
import { LOGOUT_ICON } from '@/utils/constants';
import { resetWallet } from '@/store/features/wallet/walletSlice';
import { logout } from '@/utils/localStorage';
import {
resetError,
resetTxAndHash,
Expand All @@ -17,54 +14,22 @@ import { resetState as rewardsReset } from '@/store/features/distribution/distri
import { resetCompleteState as stakingReset } from '@/store/features/staking/stakeSlice';
import { resetState as authzReset } from '@/store/features/authz/authzSlice';
import useAuthzGrants from '@/custom-hooks/useAuthzGrants';
import WalletPopup from '@/components/WalletPopup';
import { networks } from '@/utils/chainsInfo';

const Profile = () => {
const profileName = useAppSelector((state) => state.wallet.name);
const dispatch = useAppDispatch();
const { disableAuthzMode } = useAuthzGrants();

const [connectWalletDialogOpen, setConnectWalletDialogOpen] =
useState<boolean>(false);
const handleClose = () => {
setConnectWalletDialogOpen(
(connectWalletDialogOpen) => !connectWalletDialogOpen
);
};

const selectWallet = (walletName: string) => {
tryConnectWallet(walletName);
handleClose();
};

const tryConnectWallet = (walletName: string) => {
dispatch(
establishWalletConnection({
walletName,
networks: [...networks, ...getLocalNetworks()],
})
);
};

const selectedWallet = getWalletName();
const walletLogo = SUPPORTED_WALLETS.filter((wallet) => {
return wallet.name.toLowerCase() === selectedWallet;
});

return (
<div className="flex items-center gap-1">
<div className="flex items-center space-x-2 cursor-default">
<Tooltip title="Switch Wallet" placement="bottom">
<Image
className="rounded-full cursor-pointer"
src={walletLogo?.length ? walletLogo[0].logo : '/profile.svg'}
width={36}
height={36}
alt="profile"
onClick={() => setConnectWalletDialogOpen(true)}
></Image>
</Tooltip>
<Image
className="rounded-full cursor-default"
src="/profile.svg"
width={36}
height={36}
alt="profile"
></Image>
<Tooltip title={profileName} arrow placement="bottom">
<p className="text-white text-base not-italic font-normal max-w-[112px] leading-[normal truncate">
{profileName}
Expand All @@ -91,12 +56,6 @@ const Profile = () => {
alt="Logout"
/>
</Tooltip>
<WalletPopup
isOpen={connectWalletDialogOpen}
onClose={handleClose}
selectWallet={selectWallet}
isSwitchWallet={true}
/>
</div>
);
};
Expand Down
1 change: 0 additions & 1 deletion frontend/src/components/LandingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ export const Landingpage = ({ children }: { children: React.ReactNode }) => {
isOpen={connectWalletDialogOpen}
onClose={handleClose}
selectWallet={selectWallet}
isSwitchWallet={false}
/>
</div>

Expand Down
15 changes: 4 additions & 11 deletions frontend/src/components/WalletPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,25 @@ import { DialogContent, Dialog } from '@mui/material';
import Image from 'next/image';
import React, { useState } from 'react';
import { dialogBoxPaperPropStyles } from '@/utils/commonStyles';
import { getWalletName, setWalletName } from '@/utils/localStorage';
import { getWalletName } from '@/utils/localStorage';
import { SUPPORTED_WALLETS } from '@/utils/constants';

const WalletPopup = ({
isOpen,
onClose,
selectWallet,
isSwitchWallet,
}: {
isOpen: boolean;
onClose: () => void;
selectWallet: (walletName: string) => void;
isSwitchWallet: boolean;
}) => {
const [selectedWallet, setSelectedWallet] = useState<string | null>(
getWalletName()
);

const handleWalletClick = async (walletName: string) => {
const handleWalletClick = (walletName: string) => {
setSelectedWallet(walletName);
if (isSwitchWallet) {
await Promise.all([setWalletName(walletName)]);
window.location.reload();
} else {
selectWallet(walletName);
}
selectWallet(walletName);
};

return (
Expand All @@ -54,7 +47,7 @@ const WalletPopup = ({
<div className="flex justify-end items-center gap-10 px-10 py-0 w-full">
<div className="connect-wallet-box space-y-6 w-full">
<div className="text-white text-xl font-bold ">
{isSwitchWallet ? 'Switch Wallet' : 'Connect Wallet'}
Connect Wallet
</div>
<div className="flex space-x-6 justify-center">
{SUPPORTED_WALLETS.map((wallet) => (
Expand Down

0 comments on commit b5c0051

Please sign in to comment.