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

Fix: Address issue #891->cleanup of apidelay,and Refactor addr assign… #922

Merged
merged 8 commits into from
Nov 2, 2024
79 changes: 30 additions & 49 deletions app/leaderboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from "@services/apiService";
import { calculatePercentile } from "@utils/numberService";
import styles from "@styles/leaderboard.module.css";
import { useAccount } from "@starknet-react/core";
import { useAccount,type Address } from "@starknet-react/core";
import LeaderboardSkeleton from "@components/skeletons/leaderboardSkeleton";
import FeaturedQuest from "@components/UI/featured_banner/featuredQuest";
import { QuestsContext } from "@context/QuestsProvider";
Expand All @@ -31,7 +31,7 @@ import Divider from "@mui/material/Divider";
import Blur from "@components/shapes/blur";
import RankingsTable from "@components/leaderboard/RankingsTable";
import { TOP_50_TAB_STRING } from "@constants/common";
import { hexToDecimal } from "@utils/feltService";
// import { } from "@utils/feltService";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to have this comment

import Avatar from "@components/UI/avatar";
import RankingSkeleton from "@components/skeletons/rankingSkeleton";
import { Button } from "@mui/material";
Expand All @@ -43,6 +43,8 @@ import {
LeaderboardRankingParams,
LeaderboardTopperParams,
} from "../../types/backTypes";
import { decimalToHex } from "@utils/feltService";


export default function Page() {
const router = useRouter();
Expand Down Expand Up @@ -71,6 +73,12 @@ export default function Page() {
});
const [inititalFetchTop50, setInititalFetchTop50] = useState(false);

const [leaderboardToppers, setLeaderboardToppers] =
useState<LeaderboardToppersData>({
best_users: [],
total_users: 0,
});

const isTop50RankedView = useMemo(
() =>
!currentSearchedAddress &&
Expand All @@ -87,18 +95,21 @@ export default function Page() {

// set user address on wallet connect and disconnect
useEffect(() => {
setTimeout(() => {
setApiCallDelay(true);
}, 1000);
if (address === "") return;
const timeoutId = setTimeout(() => setApiCallDelay(true), 1000);
if (address) setUserAddress(address);
if (status === "disconnected") setUserAddress("");
return () => clearTimeout(timeoutId); // Cleanup
}, [address, status]);

useEffect(() => {
if (!apiCallDelay) return;
fetchPageData();
}, [apiCallDelay]);
const fetchTimeout = setTimeout(() => {
fetchPageData();
}, 500);

return () => clearTimeout(fetchTimeout);
}, [apiCallDelay]);


const fetchRankingResults = useCallback(
async (requestBody: LeaderboardRankingParams) => {
Expand All @@ -113,10 +124,9 @@ export default function Page() {
const addRankingResults = useCallback(
async (requestBody: LeaderboardRankingParams) => {
const response = await fetchLeaderboardRankings(requestBody);
if (response)
setRanking((prev) => {
return { ...prev, ranking: [...prev.ranking, ...response.ranking] };
});
if (response) {
setRanking((prev) => ({ ...prev, ranking: [...prev.ranking, ...response.ranking] }));
}
},
[]
);
Expand All @@ -131,10 +141,7 @@ export default function Page() {

const fetchPageData = useCallback(async () => {
const requestBody = {
addr:
status === "connected"
? hexToDecimal(address && address?.length > 0 ? address : userAddress)
: "",
addr: status === "connected" ? (address || userAddress) : "",
page_size: 10,
shift: 0,
duration: timeFrameMap(duration),
Expand All @@ -154,11 +161,7 @@ export default function Page() {
status,
]);

const [leaderboardToppers, setLeaderboardToppers] =
useState<LeaderboardToppersData>({
best_users: [],
total_users: 0,
});


const contract = useMemo(() => {
return new Contract(
Expand Down Expand Up @@ -206,10 +209,7 @@ export default function Page() {
useEffect(() => {
const checkIfValidAddress = async (address: string) => {
try {
let domain = address;
if (isStarkDomain(address)) {
domain = getDomainWithoutStark(address);
}
const domain = isStarkDomain(address) ? getDomainWithoutStark(address) : address;
const res: { message: boolean } = await verifyDomain(domain);
if (res.message) {
setSearchResults([domain.concat(".stark")]);
Expand Down Expand Up @@ -260,12 +260,7 @@ export default function Page() {
}
if (!checkIfLastPage && viewMore) {
const requestBody = {
addr:
currentSearchedAddress.length > 0
? currentSearchedAddress
: userAddress
? hexToDecimal(userAddress)
: "",
addr: currentSearchedAddress || (userAddress ? (userAddress) : ""),
page_size: rowsPerPage,
shift: currentPage,
duration: timeFrameMap(duration),
Expand Down Expand Up @@ -294,14 +289,7 @@ export default function Page() {
*/
useEffect(() => {
const requestBody = {
addr:
currentSearchedAddress.length > 0
? currentSearchedAddress
: userAddress
? hexToDecimal(userAddress)
: address
? address
: "",
addr: currentSearchedAddress || (userAddress ? (userAddress) : address || ""),
page_size: rowsPerPage,
shift: 0,
duration: timeFrameMap(duration),
Expand All @@ -326,14 +314,7 @@ export default function Page() {
useEffect(() => {
if (inititalFetchTop50 && address && duration !== TOP_50_TAB_STRING) {
const requestBody = {
addr:
currentSearchedAddress.length > 0
? currentSearchedAddress
: userAddress
? hexToDecimal(userAddress)
: address
? address
: "",
addr: currentSearchedAddress || (userAddress ? (userAddress) : address || ""),
page_size: rowsPerPage,
shift: 0,
duration: timeFrameMap(duration),
Expand Down Expand Up @@ -453,7 +434,7 @@ export default function Page() {
<Avatar
address={
currentSearchedAddress.length > 0
? currentSearchedAddress
? decimalToHex(currentSearchedAddress)
: userAddress
}
/>
Expand Down Expand Up @@ -544,7 +525,7 @@ export default function Page() {
selectedAddress={
currentSearchedAddress.length > 0
? currentSearchedAddress
: hexToDecimal(userAddress)
: (userAddress)
}
searchedAddress={currentSearchedAddress}
leaderboardToppers={leaderboardToppers}
Expand Down
8 changes: 4 additions & 4 deletions app/not-connected/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { useAccount, useConnect } from "@starknet-react/core";
import { useAccount, useConnect, Connector } from "@starknet-react/core";
import React, { useEffect } from "react";
import { useRouter } from "next/navigation";
import ErrorScreen from "@components/UI/screens/errorScreen";
Expand All @@ -12,7 +12,7 @@ export default function Page() {
const { connectAsync } = useConnect();
const { push } = useRouter();
const { starknetkitConnectModal } = useStarknetkitConnectModal({
connectors: availableConnectors,
connectors: availableConnectors as any,
Marchand-Nicolas marked this conversation as resolved.
Show resolved Hide resolved
modalTheme: "dark",
});

Expand All @@ -25,14 +25,14 @@ export default function Page() {
if (!connector) {
return;
}
await connectAsync({ connector });
await connectAsync({ connector: connector as Connector }); // Type casted
localStorage.setItem("SQ-connectedWallet", connector.id);
};

return (
<>
<ErrorScreen
errorMessage="You're not connected !"
errorMessage="You're not connected!"
buttonText="Connect wallet"
onClick={connectWallet}
/>
Expand Down
6 changes: 3 additions & 3 deletions app/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ export const availableConnectors = [
? "https://web.hydrogen.argent47.net"
: "https://web.argent.xyz/",
}),
new ArgentMobileConnector({
dappName: "Starknet Quest",
ArgentMobileConnector.init({
options: {dappName: "Starknet Quest",
url: process.env.NEXT_PUBLIC_APP_LINK as string,
chainId: constants.NetworkName.SN_MAIN,
icons: ["https://starknet.quest/visuals/starknetquestLogo.svg"],
icons: ["https://starknet.quest/visuals/starknetquestLogo.svg"],}
}),

new InjectedConnector({ options: { id: "keplr", name: "Keplr" } })
Expand Down
24 changes: 18 additions & 6 deletions components/UI/avatar.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
import React, { FunctionComponent } from "react";
import React, {
FunctionComponent,
useContext,
useEffect,
useState,
} from "react";
import ProfilIcon from "@components/UI/iconsComponents/icons/profilIcon";
import theme from "@styles/theme";
import { useStarkProfile } from "@starknet-react/core";
import { StarknetIdJsContext } from "@context/StarknetIdJsProvider";
import { StarkProfile } from "starknetid.js";

type AvatarProps = {
address: string;
width?: string;
};

const Avatar: FunctionComponent<AvatarProps> = ({ address, width = "32" }) => {
const { data: profileData } = useStarkProfile({ address });

const { starknetIdNavigator } = useContext(StarknetIdJsContext);
const [profile, setProfile] = useState<StarkProfile | null>(null);

useEffect(() => {
if (!starknetIdNavigator) return;
starknetIdNavigator.getProfileData(address).then((profile) => {
setProfile(profile);
});
}, [starknetIdNavigator, address]);
Marchand-Nicolas marked this conversation as resolved.
Show resolved Hide resolved
return (
<>
{profileData?.profilePicture ? (
{profile?.profilePicture ? (
<img
src={profileData?.profilePicture}
src={profile?.profilePicture}
width={width}
height={width}
className="rounded-full"
Expand Down
8 changes: 4 additions & 4 deletions components/UI/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Link from "next/link";
import React, { useState, useEffect, FunctionComponent } from "react";
import styles from "@styles/components/navbar.module.css";
import Button from "./button";
import { useConnect, useAccount, useDisconnect } from "@starknet-react/core";
import { useConnect, useAccount, useDisconnect, Connector } from "@starknet-react/core";
import ModalMessage from "./modalMessage";
import { useDisplayName } from "@hooks/displayName.tsx";
import { constants } from "starknet";
Expand Down Expand Up @@ -54,7 +54,7 @@ const Navbar: FunctionComponent = () => {
},
]);
const { starknetkitConnectModal } = useStarknetkitConnectModal({
connectors: availableConnectors,
connectors: availableConnectors as any,
Marchand-Nicolas marked this conversation as resolved.
Show resolved Hide resolved
});

const fetchAndUpdateNotifications = async () => {
Expand Down Expand Up @@ -94,7 +94,7 @@ const Navbar: FunctionComponent = () => {
const connector = availableConnectors.find(
(item) => item.id === connectordId
);
await connectAsync({ connector });
await connectAsync({ connector: connector as Connector });
Marchand-Nicolas marked this conversation as resolved.
Show resolved Hide resolved
}
};
connectToStarknet();
Expand All @@ -121,7 +121,7 @@ const Navbar: FunctionComponent = () => {
if (!connector) {
return;
}
await connectAsync({ connector });
await connectAsync({ connector: connector as Connector });
localStorage.setItem("SQ-connectedWallet", connector.id);
};

Expand Down
4 changes: 2 additions & 2 deletions components/UI/notifications/notificationDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from "@constants/notifications";
import { CircularProgress } from "@mui/material";
import { getCurrentNetwork } from "@utils/network";
import { useWaitForTransaction } from "@starknet-react/core";
import { useTransactionReceipt } from "@starknet-react/core";
import { useNotificationManager } from "@hooks/useNotificationManager";

type NotificationDetailProps = {
Expand All @@ -27,7 +27,7 @@ const NotificationDetail: FunctionComponent<NotificationDetailProps> = ({
}) => {
const currentNetwork = getCurrentNetwork();
const { updateNotificationStatus } = useNotificationManager();
const { data, error, isLoading, isError } = useWaitForTransaction({
const { data, error, isLoading, isError } = useTransactionReceipt({
hash:
notification.type === NotificationType.TRANSACTION
? notification.data.hash
Expand Down
5 changes: 3 additions & 2 deletions components/UI/profileCard/profileCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React, {
import styles from "@styles/dashboard.module.css";
import CopyIcon from "@components/UI/iconsComponents/icons/copyIcon";
import { CDNImage } from "@components/cdn/image";
import { useStarkProfile } from "@starknet-react/core";
import { useStarkProfile,type Address } from "@starknet-react/core";
import { minifyAddress } from "@utils/stringService";
import trophyIcon from "public/icons/trophy.svg";
import xpIcon from "public/icons/xpBadge.svg";
Expand All @@ -35,7 +35,8 @@ const ProfileCard: FunctionComponent<ProfileCard> = ({
}) => {
const [copied, setCopied] = useState(false);
const sinceDate = useCreationDate(identity);
const { data: profileData } = useStarkProfile({ address: identity.owner });
const formattedAddress = (identity.owner.startsWith("0x") ? identity.owner : `0x${identity.owner}`) as Address;
const { data: profileData } = useStarkProfile({ address: formattedAddress });
const [userXp, setUserXp] = useState<number>();


Expand Down
4 changes: 2 additions & 2 deletions components/discover/claimModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import AppIcon from "./appIcon";
import TokenIcon from "./tokenIcon";
import { useNotification } from "@context/NotificationProvider";
import Loading from "@app/loading";
import { useAccount, useContractWrite } from "@starknet-react/core";
import { useAccount, useSendTransaction } from "@starknet-react/core";
import { RewardsPerProtocol } from "../../types/backTypes";
import { getRewards } from "@services/apiService";
import { gweiToEth } from "@utils/feltService";
Expand Down Expand Up @@ -86,7 +86,7 @@ const ClaimModal: FunctionComponent<ClaimModalProps> = ({
const { address } = useAccount();
const [rewards, setRewards] = useState<RewardsPerProtocol | null>(null);
const [calls, setCalls] = useState<Call[]>([]);
const { writeAsync: execute } = useContractWrite({
const { sendAsync: execute } = useSendTransaction({
calls: calls,
});

Expand Down
3 changes: 2 additions & 1 deletion components/leaderboard/RankCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ const RankCard: FunctionComponent<RankCardProps> = ({
</div>

<div className={styles.rank_card_naming}>
<Avatar address={name} width="32" />

<Avatar address={decimalToHex(name)} width="32" />
<div>{displayName}</div>
</div>

Expand Down
3 changes: 2 additions & 1 deletion components/leaderboard/RankingsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ const RankingsTable: FunctionComponent<RankingProps> = ({
</Typography>
</div>
<div className={styles.ranking_profile_layout}>
<Avatar address={item.address} width="32" />

<Avatar address={decimalToHex(item.address)} width="32" />
<Typography type={TEXT_TYPE.BODY_DEFAULT}
style={{
color:
Expand Down
4 changes: 3 additions & 1 deletion components/navbar/walletButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ const WalletButton: FunctionComponent<WalletButtonProps> = ({
const [unfocus, setUnfocus] = useState<boolean>(false);
const network = currentNetwork === "TESTNET" ? "testnet" : "mainnet";
const isWebWallet =
(connector as Connector)?.wallet?.id === "argentWebWallet";
(connector as Connector)?.id === "argentWebWallet";

// console.log(connector?.id,"wallet")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to keep this comment too


const buttonName = useMemo(
() =>
Expand Down
Loading