From f6e1c3f033407fb2bf2cabbf34dd587b43c673d0 Mon Sep 17 00:00:00 2001 From: Abeeujah Date: Fri, 29 Nov 2024 12:51:55 +0100 Subject: [PATCH] feat: Check connection network --- .../components/modules/Fund/FundDonate.tsx | 36 ++++++++++++------- .../components/modules/Fund/FundVote.tsx | 31 ++++++++++++---- .../components/ui/ConnectWalletButton.tsx | 7 ++-- .../gostarkme-web/state/connectedWallet.ts | 10 ++++-- 4 files changed, 60 insertions(+), 24 deletions(-) diff --git a/frontend/gostarkme-web/components/modules/Fund/FundDonate.tsx b/frontend/gostarkme-web/components/modules/Fund/FundDonate.tsx index 7cad31a..78c7ebc 100644 --- a/frontend/gostarkme-web/components/modules/Fund/FundDonate.tsx +++ b/frontend/gostarkme-web/components/modules/Fund/FundDonate.tsx @@ -5,7 +5,11 @@ import ProgressBar from "@/components/ui/ProgressBar"; import { provider } from "@/constants"; import { strkAbi } from "@/contracts/abis/strk"; import { addrSTRK } from "@/contracts/addresses"; -import { walletStarknetkitLatestAtom } from "@/state/connectedWallet"; +import { + networkAtom, + networkEnvironmentAtom, + walletStarknetkitLatestAtom, +} from "@/state/connectedWallet"; import { useAtomValue } from "jotai"; import Image, { StaticImageData } from "next/image"; import { useState } from "react"; @@ -24,6 +28,8 @@ const FundDonate = ({ currentBalance, goal, addr, icon }: FundDonateProps) => { const [isLoading, setIsLoading] = useState(false); const [localBalance, setLocalBalance] = useState(currentBalance); const wallet = useAtomValue(walletStarknetkitLatestAtom); + const network = useAtomValue(networkAtom); + const networkEnvironment = useAtomValue(networkEnvironmentAtom); const progress = calculatePorcentage(localBalance, goal); const handleAmountChange = (e: React.ChangeEvent) => { @@ -126,17 +132,23 @@ const FundDonate = ({ currentBalance, goal, addr, icon }: FundDonateProps) => { {error}

)} - +
+ + {wallet && !network && ( +

+ Your wallet is currently connected to the wrong network. Please + switch to {networkEnvironment[1]} to continue. +

+ )} +
); }; diff --git a/frontend/gostarkme-web/components/modules/Fund/FundVote.tsx b/frontend/gostarkme-web/components/modules/Fund/FundVote.tsx index 9cd568d..370165f 100644 --- a/frontend/gostarkme-web/components/modules/Fund/FundVote.tsx +++ b/frontend/gostarkme-web/components/modules/Fund/FundVote.tsx @@ -2,7 +2,11 @@ import { calculatePorcentage } from "@/app/utils"; import { Button } from "@/components/ui/Button"; import ProgressBar from "@/components/ui/ProgressBar"; import { fundAbi } from "@/contracts/abis/fund"; -import { walletStarknetkitLatestAtom } from "@/state/connectedWallet"; +import { + networkAtom, + networkEnvironmentAtom, + walletStarknetkitLatestAtom, +} from "@/state/connectedWallet"; import { latestTxAtom } from "@/state/latestTx"; import { useAtomValue, useSetAtom } from "jotai"; import { Contract, InvokeFunctionResponse } from "starknet"; @@ -20,6 +24,8 @@ interface FundVoteProps { export const FundVote = ({ upVotes, upVotesNeeded, addr, setLoading}: FundVoteProps) => { const wallet = useAtomValue(walletStarknetkitLatestAtom); + const network = useAtomValue(networkAtom); + const networkEnvironment = useAtomValue(networkEnvironmentAtom); const progress = calculatePorcentage(upVotes, upVotesNeeded); @@ -110,12 +116,23 @@ export const FundVote = ({ upVotes, upVotesNeeded, addr, setLoading}: FundVotePr

You have already voted

) : ( -