Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Gateway] remove listener for account change #1689

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import {
TwitterLogoIcon,
DiscordLogoIcon,
} from "@radix-ui/react-icons";
import { useWalletConnection } from "../providers/wallet-provider";

export default function Footer() {
const { version } = useWalletConnection();

return (
<div className="border-t px-2">
<div className="flex h-16 items-center px-4">
Expand All @@ -33,6 +36,11 @@ export default function Footer() {
<DiscordLogoIcon />
</a>
</div>
<div className="flex-1 flex items-center justify-center">
<h3 className="text-sm text-muted-foreground">
Version: {version || "Unknown"}
</h3>
</div>
<div className="flex items-center space-x-4">
<Link
href="/docs/privacy"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ import { socialLinks } from "../../../lib/constants";
import { Skeleton } from "../../ui/skeleton";

const Connected = () => {
const { accounts, connectAccount, version, revokeAccounts } =
useWalletConnection();
const { accounts, connectAccount, revokeAccounts } = useWalletConnection();

return (
<>
Expand Down Expand Up @@ -84,12 +83,6 @@ const Connected = () => {
)}
</TableBody>
</Table>

<div className="mt-8">
<h3 className="text-sm text-muted-foreground">
Version: {version || "Unknown"}
</h3>
</div>
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,40 +43,22 @@ export const WalletConnectionProvider = ({
const [accounts, setAccounts] = useState<Account[] | null>(null);
const [provider, setProvider] = useState({} as ethers.providers.Web3Provider);

useEffect(() => {
initialize();
ethereum.on("accountsChanged", handleAccountsChanged);

return () => {
ethereum.removeListener("accountsChanged", handleAccountsChanged);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const handleAccountsChanged = async () => {
if (!ethereum) {
return;
}
const status = await ethService.isUserConnectedToTenChain(token);
await fetchUserAccounts();
setWalletConnected(status);
};

const initialize = async () => {
if (!ethereum) {
showToast(
ToastType.DESTRUCTIVE,
"Please install Metamask to connect your wallet."
);
return;
}
try {
if (!ethereum) {
showToast(
ToastType.DESTRUCTIVE,
"Please install Metamask to connect your wallet."
);
return;
}
const providerInstance = new ethers.providers.Web3Provider(ethereum);
setProvider(providerInstance);
await ethService.checkIfMetamaskIsLoaded(providerInstance);

const fetchedToken = await getToken(providerInstance);
setToken(fetchedToken);

const status = await ethService.isUserConnectedToTenChain(fetchedToken);
setWalletConnected(status);

Expand Down Expand Up @@ -179,6 +161,11 @@ export const WalletConnectionProvider = ({
}
};

useEffect(() => {
initialize();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const walletConnectionContextValue: WalletConnectionContextType = {
walletConnected,
accounts,
Expand Down
8 changes: 4 additions & 4 deletions tools/walletextension/frontend/src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ export const tenGatewayAddress = process.env.NEXT_PUBLIC_API_GATEWAY_URL;
export const tenscanLink = "https://testnet.tenscan.com";

export const socialLinks = {
github: "https://github.com/obscuronet",
discord: "https://discord.gg/2JQ2Z3r",
twitter: "https://twitter.com/obscuronet",
twitterHandle: "@obscuronet",
github: "https://github.com/ten-protocol",
discord: "https://discord.gg/fVXstswaJY",
twitter: "https://twitter.com/tenprotocol",
twitterHandle: "@tenprotocol",
};
Jennievon marked this conversation as resolved.
Show resolved Hide resolved

export const GOOGLE_ANALYTICS_ID = process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS_ID;
Expand Down
Loading