Skip to content

Commit

Permalink
fix: increase timout and remove unused code (#20)
Browse files Browse the repository at this point in the history
* fix: increase timout and remove unused code

* fix: remove debug code

* fix: remove unused funciton

* fix: getEnsAddress query if it fails
  • Loading branch information
irisdv authored Aug 8, 2024
1 parent 29b5d63 commit 3c12dc7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 34 deletions.
12 changes: 8 additions & 4 deletions app/components/eligibility/eligibilitySteps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,14 @@ const EligibilitySteps: FunctionComponent<EligibilityStepsProps> = ({
process.env.NEXT_PUBLIC_IS_TESTNET === "true" ? EthSepolia : EthMainnet,
],
});
getEnsAddress(config, { name: ensDomain }).then((ensAddress) => {
setLoadingEthAddress(false);
if (ensAddress) setEthAddress(ensAddress);
});
getEnsAddress(config, { name: ensDomain })
.then((ensAddress) => {
setLoadingEthAddress(false);
if (ensAddress) setEthAddress(ensAddress);
})
.catch(() => {
setLoadingEthAddress(false);
});
}, [address, network, starkProfile]);

useEffect(() => {
Expand Down
30 changes: 2 additions & 28 deletions app/eligibility/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ import ConnectModal from "../components/connection/connectModal";
import { minifyAddress } from "@/utils/stringService";
import WalletIcon from "../components/iconComponents/walletIcon";
import { useEnsName, useAccount as useWagmiAccount } from "wagmi";
import getRemainingClicks from "@/hooks/getRemainingClicks";
import { Provider, constants } from "starknet";
import canPlayOnStarknet from "@/hooks/canPlayOnStarknet";
import TryAgainModal from "../components/tryAgainModal";
import RecoverTokenModal from "../components/recoverTokenModal";
import WrongNetworkModal from "../components/wrongNetwork";
import { StarknetIdNavigator } from "starknetid.js";
import VideoBackground from "../components/videoBackground";
Expand Down Expand Up @@ -45,9 +41,7 @@ export default function Eligibility() {
// state variables
const [openConnectModal, setOpenConnectModal] = useState(false);
const [openStarknetModal, setOpenStarknetModal] = useState(false);
const [tryAgainModal, setTryAgainModal] = useState(false);
const [wrongNetworkModal, setWrongNetworkModal] = useState(false);
const [recoverTokenModal, setRecoverTokenModal] = useState(false);
const [isConnected, setIsConnected] = useState(false);
const [network, setNetwork] = useState<NetworkType>();
const [progress, setProgress] = useState("verification");
Expand All @@ -57,9 +51,6 @@ export default function Eligibility() {
process.env.NEXT_PUBLIC_IS_TESTNET === "true" ? "testnet" : "mainnet";
const [isWrongStarknetNetwork, setIsWrongStarknetNetwork] = useState(false);

const { isFirstLoad } = getRemainingClicks(network, address);
const { hasEthTokens } = canPlayOnStarknet(network);

const starknetIdNavigator = useMemo(() => {
return new StarknetIdNavigator(
new Provider({
Expand Down Expand Up @@ -95,11 +86,11 @@ export default function Eligibility() {
}, [evmConnected]);

useEffect(() => {
if (network && isConnected && !isFirstLoad) {
if (network && isConnected) {
if (network === NetworkType.STARKNET && isWrongStarknetNetwork)
setWrongNetworkModal(true);
}
}, [isFirstLoad, network, isConnected, isWrongStarknetNetwork]);
}, [network, isConnected, isWrongStarknetNetwork]);

useEffect(() => {
if (network === NetworkType.EVM || !isConnected || !starknetAccount) return;
Expand All @@ -120,11 +111,6 @@ export default function Eligibility() {
setIsConnected(true);
};

const openWalletModal = () => {
disconnectUser();
setOpenConnectModal(true);
};

const getConnectionBtnText = () => {
if (!isConnected || !network) return "Connect wallet";
return getUserNameOrAddress() ?? "Connect wallet";
Expand Down Expand Up @@ -275,18 +261,6 @@ export default function Eligibility() {
open={openConnectModal}
onWalletConnected={onWalletConnected}
/>
<TryAgainModal
closeModal={() => setTryAgainModal(false)}
open={tryAgainModal}
network={network}
hasEthTokens={hasEthTokens}
openWalletModal={openWalletModal}
/>
<RecoverTokenModal
closeModal={() => setRecoverTokenModal(false)}
open={recoverTokenModal}
addr={evmAddress}
/>
<WrongNetworkModal
closeModal={() => setWrongNetworkModal(false)}
open={wrongNetworkModal}
Expand Down
4 changes: 2 additions & 2 deletions hooks/getRemainingClicks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ export default function getRemainingClicks(

if (network === NetworkType.STARKNET) {
fetchStarknetData();
intervalId = setInterval(fetchStarknetData, 5000); // Set interval for fetching Starknet data
intervalId = setInterval(fetchStarknetData, 120000); // Set interval for fetching Starknet data
} else if (network === NetworkType.EVM) {
fetchEvmData();
intervalId = setInterval(fetchEvmData, 5000); // Set interval for fetching EVM data
intervalId = setInterval(fetchEvmData, 120000); // Set interval for fetching EVM data
}

// Clean up interval on component unmount or when network/address changes
Expand Down

0 comments on commit 3c12dc7

Please sign in to comment.