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

MEP 26/01/2023 #483

Merged
merged 13 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 16 additions & 2 deletions app/quest-boost/[boostId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import BackButton from "@components/UI/backButton";
import useBoost from "@hooks/useBoost";
import { getTokenName } from "@utils/tokenService";
import BoostSkeleton from "@components/skeletons/boostSkeleton";
import { TOKEN_DECIMAL_MAP } from "@utils/constants";

type BoostQuestPageProps = {
params: {
Expand Down Expand Up @@ -95,7 +96,7 @@ export default function Page({ params }: BoostQuestPageProps) {
updateBoostClaimStatus(address, boost?.id, true);

router.push(`/quest-boost/claim/${boost?.id}`);
}, [boost, address]);
}, [boost, address, winnerList]);

useEffect(() => {
fetchPageData();
Expand Down Expand Up @@ -142,7 +143,20 @@ export default function Page({ params }: BoostQuestPageProps) {
<p>Reward:</p>
<div className="flex flex-row gap-2">
<p className={styles.claim_button_text_highlight}>
{boost?.amount} {getTokenName(boost?.token ?? "")}
{boost
? parseInt(
String(
boost?.amount /
Math.pow(
10,
TOKEN_DECIMAL_MAP[
getTokenName(boost?.token ?? "")
]
)
)
)
: 0}{" "}
{getTokenName(boost?.token ?? "")}
</p>
<TokenSymbol tokenAddress={boost?.token ?? ""} />
</div>
Expand Down
18 changes: 16 additions & 2 deletions app/quest-boost/claim/[boostId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { hexToDecimal } from "@utils/feltService";
import { boostClaimCall } from "@utils/callData";
import { getTokenName } from "@utils/tokenService";
import useBoost from "@hooks/useBoost";
import { TOKEN_DECIMAL_MAP } from "@utils/constants";

type BoostQuestPageProps = {
params: {
Expand Down Expand Up @@ -75,7 +76,10 @@ export default function Page({ params }: BoostQuestPageProps) {
// convert values in winner array from hex to decimal
if (!boost.winner) return false;

setDisplayAmount(parseInt(String(boost?.amount / boost?.num_of_winners)));
setDisplayAmount(
parseInt(String(boost?.amount / boost?.num_of_winners)) /
Math.pow(10, TOKEN_DECIMAL_MAP[getTokenName(boost?.token ?? "")])
);
return winnerList.includes(hexToDecimal(address));
}, [boost, address, winnerList]);

Expand Down Expand Up @@ -104,7 +108,9 @@ export default function Page({ params }: BoostQuestPageProps) {
const { transaction_hash } = await account.execute(
boostClaimCall(boost, sign)
);
updateBoostClaimStatus(address, boost?.id, true);
if (transaction_hash) {
updateBoostClaimStatus(address, boost?.id, true);
}
setTransactionHash(transaction_hash);
};

Expand Down Expand Up @@ -144,6 +150,14 @@ export default function Page({ params }: BoostQuestPageProps) {
height={97}
alt="usdc icon"
/>
) : boost && getTokenName(boost?.token) === "LORDS" ? (
<CDNImage
src={"/icons/lord.webp"}
priority
width={97}
height={97}
alt="lords icon"
/>
) : (
<CDNImage
src={"/icons/eth.svg"}
Expand Down
7 changes: 6 additions & 1 deletion components/UI/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import { getPendingBoostClaims } from "@services/apiService";
import { hexToDecimal } from "@utils/feltService";
import CloseFilledIcon from "./iconsComponents/icons/closeFilledIcon";
import { getCurrentNetwork } from "@utils/network";
import { TOKEN_DECIMAL_MAP } from "@utils/constants";
import { getTokenName } from "@utils/tokenService";

const Navbar: FunctionComponent = () => {
const currentNetwork = getCurrentNetwork();
Expand Down Expand Up @@ -73,7 +75,10 @@ const Navbar: FunctionComponent = () => {
res.forEach((boost: Boost) => {
const data = {
title: "Congratulations! 🎉",
subtext: `You have just won ${boost.amount} USDC thanks to the "${boost.name}” boost`,
subtext: `You have just won ${
parseInt(String(boost?.amount / boost?.num_of_winners)) /
Math.pow(10, TOKEN_DECIMAL_MAP[getTokenName(boost?.token ?? "")])
} USDC thanks to the "${boost.name}” boost`,
link: "/quest-boost/" + boost.id,
linkText: "Claim your reward",
};
Expand Down
6 changes: 6 additions & 0 deletions components/achievements/level.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import styles from "@styles/achievements.module.css";
import { AchievementDocument } from "../../types/backTypes";
import { CustomTooltip } from "@components/UI/tooltip";
import { CDNImg } from "@components/cdn/image";
import CheckIcon from "@components/UI/iconsComponents/icons/checkIcon";

type AchievementLevelProps = {
achievement: AchievementDocument;
Expand Down Expand Up @@ -39,6 +40,11 @@ const AchievementLevel: FunctionComponent<AchievementLevelProps> = ({
>
<CDNImg src={achievement.img_url} alt="achievement level image" />
</div>
{achievement.completed && (
<div className={styles.checkIcon}>
<CheckIcon width="24" color="#6AFFAF" />
</div>
)}
</div>
</CustomTooltip>
);
Expand Down
4 changes: 4 additions & 0 deletions components/quest-boost/TokenSymbol.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ const TokenSymbol: FunctionComponent<TokenSymbolProps> = ({
setTokenImageLink("/icons/eth.svg");
imageDimensions = { width: 15, height: 20 };
break;
case TOKEN_ADDRESS_MAP[network].LORDS:
setTokenImageLink("/icons/lord.webp");
imageDimensions = { width: 20, height: 20 };
break;
default:
setTokenImageLink("/icons/usdc.svg");
break;
Expand Down
14 changes: 13 additions & 1 deletion components/quest-boost/boostCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import TokenSymbol from "./TokenSymbol";
import useBoost from "@hooks/useBoost";
import theme from "@styles/theme";
import { useAccount } from "@starknet-react/core";
import { TOKEN_DECIMAL_MAP } from "@utils/constants";
import { getTokenName } from "@utils/tokenService";

type BoostCardProps = {
boost: Boost;
Expand Down Expand Up @@ -86,7 +88,17 @@ const BoostCard: FunctionComponent<BoostCardProps> = ({
</p>
{!hasUserCompletedBoost && boost.expiry > Date.now() ? (
<div className="flex flex-row gap-2 items-center p-1.5">
<p>{boost?.amount}</p>
<p>
{parseInt(
String(
boost?.amount /
Math.pow(
10,
TOKEN_DECIMAL_MAP[getTokenName(boost?.token ?? "")]
)
)
)}
</p>
<TokenSymbol tokenAddress={boost.token} />
</div>
) : (
Expand Down
14 changes: 13 additions & 1 deletion components/quests/quest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { CDNImg } from "@components/cdn/image";
import QuestCard from "./questCard";
import { getBoosts } from "@services/apiService";
import TokenSymbol from "@components/quest-boost/TokenSymbol";
import { TOKEN_DECIMAL_MAP } from "@utils/constants";
import { getTokenName } from "@utils/tokenService";

type QuestProps = {
onClick: () => void;
Expand Down Expand Up @@ -110,7 +112,17 @@ const Quest: FunctionComponent<QuestProps> = ({
style={{ gap: 0, padding: "8px 16px" }}
>
<TokenSymbol tokenAddress={boost?.token} />
<p className="text-white ml-2">{boost?.amount}</p>
<p className="text-white ml-2">
{parseInt(
String(
boost?.amount /
Math.pow(
10,
TOKEN_DECIMAL_MAP[getTokenName(boost?.token ?? "")]
)
)
)}
</p>
</div>
) : null}
</div>
Expand Down
2 changes: 1 addition & 1 deletion components/quests/questDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ const QuestDetails: FunctionComponent<QuestDetailsProps> = ({
verifyRedirect={task.verify_redirect}
verifyEndpoint={
task.verify_endpoint_type &&
task.verify_endpoint_type === "default"
task.verify_endpoint_type.startsWith("default")
? `${task.verify_endpoint}?addr=${hexToDecimal(address)}`
: task.verify_endpoint_type === "quiz"
? task.verify_endpoint
Expand Down
8 changes: 7 additions & 1 deletion components/quests/task.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,20 @@ const Task: FunctionComponent<Task> = ({
}

if (verifyRedirect) {
// if the verify_endpoint_type contains a timeout indication we use it,
// otherwise we use the default timeout of 15 seconds
const timeout =
verifyEndpointType.split("_").length === 2
? parseInt(verifyEndpointType.split("_")[1]) ?? 15000
: 15000;
await new Promise((resolve) =>
setTimeout(() => {
setIsVerified(true);
checkUserRewards();
refreshRewards();
setIsLoading(false);
resolve(null);
}, 15000)
}, timeout)
);
} else {
setIsVerified(true);
Expand Down
24 changes: 14 additions & 10 deletions context/QuestsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,24 @@ export const QuestsContextProvider = ({

setCategories(categoriesWithImages);
setQuests(q);

const notExpired = q.filter((quest) => !quest.expired);
setFeaturedQuest(
notExpired.length >= 1 ? notExpired[notExpired.length - 1] : undefined
);
})();
}, []);

useMemo(() => {
getTrendingQuests().then((data: QuestDocument[] | QueryError) => {
if ((data as QueryError).error) return;
setTrendingQuests(data as QuestDocument[]);
});
}, []);
getTrendingQuests(hexToDecimal(address)).then(
(data: QuestDocument[] | QueryError) => {
if ((data as QueryError).error) return;
const quests = data as QuestDocument[];
setTrendingQuests(quests);
const notExpired = quests.filter((quest) => !quest.expired);
setFeaturedQuest(
notExpired.length >= 1
? notExpired[Math.floor(Math.random() * notExpired.length)]
: undefined
);
}
);
}, [address]);

useMemo(() => {
if (!address) return;
Expand Down
Binary file added public/braavos/realms.webp
Binary file not shown.
Binary file added public/brine/brine.webp
Binary file not shown.
Binary file added public/icons/lord.webp
Binary file not shown.
Binary file added public/nimbora/favicon.ico
Binary file not shown.
Binary file added public/nimbora/pool.webp
Binary file not shown.
6 changes: 4 additions & 2 deletions services/apiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,11 @@ export const getQuests = async () => {
}
};

export const getTrendingQuests = async () => {
export const getTrendingQuests = async (addr = "") => {
try {
const response = await fetch(`${baseurl}/get_trending_quests`);
const response = await fetch(
`${baseurl}/get_trending_quests${addr ? `?addr=${addr}` : ""}`
);
return await response.json();
} catch (err) {
console.log("Error while fetching trending quests", err);
Expand Down
44 changes: 27 additions & 17 deletions styles/achievements.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@
position: absolute;
border-radius: 30px;
background: linear-gradient(
90deg,
rgba(17, 16, 24, 0),
rgba(17, 16, 24, 0.51)
90deg,
rgba(17, 16, 24, 0),
rgba(17, 16, 24, 0.51)
);
width: 100%;
height: 100%;
Expand All @@ -109,12 +109,14 @@
right: -1px;
left: 1px;
bottom: 1px;
background: linear-gradient(90deg,
#437aba 0%,
#59c2e8 45%,
#00ff77 60%,
#59c2e8 70%,
#437aba50 100%);
background: linear-gradient(
90deg,
#437aba 0%,
#59c2e8 45%,
#00ff77 60%,
#59c2e8 70%,
#437aba50 100%
);
border-radius: 30px;
z-index: -1;
}
Expand All @@ -125,12 +127,14 @@
}

.cardContainer:nth-child(even) .card::before {
background: linear-gradient(90deg,
#437aba 0%,
#1e74d6 45%,
#00fbff 60%,
#1e74d6 70%,
#437aba50 100%);
background: linear-gradient(
90deg,
#437aba 0%,
#1e74d6 45%,
#00fbff 60%,
#1e74d6 70%,
#437aba50 100%
);
}

.cardTitle {
Expand Down Expand Up @@ -178,6 +182,7 @@
flex-grow: 1;
min-width: 0;
justify-content: space-between;
position: relative;
}

.levelContainer.completed {
Expand Down Expand Up @@ -286,6 +291,12 @@
line-height: 24px;
}

.checkIcon {
position: absolute;
right: 16px;
top: 8px;
}

@media (max-width: 928px) {
.container {
padding: 0;
Expand Down Expand Up @@ -318,7 +329,6 @@
}
}


.container:has(.skeleton) {
padding: 0 30px;
}
}
6 changes: 6 additions & 0 deletions tests/utils/tokenService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ describe("getTokenName function", () => {
expect(tokenName).toBe("ETH");
});

it("should return 'LORDS' for LORDS token address on the current network", () => {
// Assuming TOKEN_ADDRESS_MAP is defined and has the necessary structure
const tokenName = getTokenName(TOKEN_ADDRESS_MAP["MAINNET"].LORDS);
expect(tokenName).toBe("LORDS");
});

it("should return 'USDC' for unknown token addresses on the current network", () => {
// Assuming TOKEN_ADDRESS_MAP is defined and has the necessary structure
const tokenName = getTokenName("unknownTokenAddress");
Expand Down
8 changes: 8 additions & 0 deletions utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,17 @@ export const TOKEN_ADDRESS_MAP = {
MAINNET: {
USDC: "0x053c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8",
ETH: "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
LORDS: "0x0124aeb495b947201f5fac96fd1138e326ad86195b98df6dec9009158a533b49",
},
TESTNET: {
USDC: "0x005a643907b9a4bc6a55e9069c4fd5fd1f5c79a22470690f75556c4736e34426",
ETH: "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
LORDS: "0x05e367ac160e5f90c5775089b582dfc987dd148a5a2f977c49def2a6644f724b",
},
};

export const TOKEN_DECIMAL_MAP = {
USDC: 6,
ETH: 18,
LORDS:18,
};
2 changes: 2 additions & 0 deletions utils/tokenService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export const getTokenName = (token: string) => {
return "USDC";
case TOKEN_ADDRESS_MAP[network].ETH:
return "ETH";
case TOKEN_ADDRESS_MAP[network].LORDS:
return "LORDS";
default:
return "USDC";
}
Expand Down