Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Picodes committed Dec 19, 2024
1 parent 7c274a8 commit a3f3a46
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 62 deletions.
9 changes: 3 additions & 6 deletions src/components/element/leaderboard/LeaderboardLibrary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import { LeaderboardTable } from "./LeaderboardTable";
import LeaderboardTableRow from "./LeaderboardTableRow";

export type IProps = {
leaderboard: Awaited<
ReturnType<(typeof RewardService)["getManyFromRequest"]>
>["rewards"];
leaderboard: Awaited<ReturnType<(typeof RewardService)["getManyFromRequest"]>>["rewards"];
count?: number;
total?: number;
campaign: Campaign;
Expand All @@ -38,14 +36,13 @@ export default function LeaderboardLibrary(props: IProps) {

return (
<LeaderboardTable
dividerClassName={(index) => (index < 2 ? "bg-accent-8" : "bg-main-8")}
dividerClassName={index => (index < 2 ? "bg-accent-8" : "bg-main-8")}
header={
<Title h={5} className="!text-main-11 w-full">
Leaderboard
</Title>
}
footer={count !== undefined && <OpportunityPagination count={count} />}
>
footer={count !== undefined && <OpportunityPagination count={count} />}>
{!!rows.length ? rows : <Text>No rewarded users</Text>}
</LeaderboardTable>
);
Expand Down
36 changes: 6 additions & 30 deletions src/components/element/leaderboard/LeaderboardTableRow.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import type { Campaign } from "@merkl/api";
import {
type Component,
Group,
PrimitiveTag,
Text,
Value,
mergeClass,
} from "dappkit";
import { type Component, Group, PrimitiveTag, Text, Value, mergeClass } from "dappkit";
import { useWalletContext } from "packages/dappkit/src/context/Wallet.context";
import { useMemo } from "react";
import type { RewardService } from "src/api/services/reward.service";
Expand All @@ -16,36 +9,25 @@ import User from "../user/User";
import { LeaderboardRow } from "./LeaderboardTable";

export type CampaignTableRowProps = Component<{
row: Awaited<
ReturnType<typeof RewardService.getManyFromRequest>
>["rewards"][0];
row: Awaited<ReturnType<typeof RewardService.getManyFromRequest>>["rewards"][0];
total: bigint;
rank: number;
campaign: Campaign;
}>;

export default function LeaderboardTableRow({
row,
rank,
total,
className,
...props
}: CampaignTableRowProps) {
export default function LeaderboardTableRow({ row, rank, total, className, ...props }: CampaignTableRowProps) {
const { campaign } = props;
const { chains } = useWalletContext();

const share = useMemo(() => {
const amount = formatUnits(
BigInt(row?.amount),
campaign.rewardToken.decimals
);
const amount = formatUnits(BigInt(row?.amount), campaign.rewardToken.decimals);
const all = formatUnits(total, campaign.rewardToken.decimals);

return Number.parseFloat(amount) / Number.parseFloat(all);
}, [row, total, campaign]);

const chain = useMemo(() => {
return chains?.find((c) => c.id === campaign.computeChainId);
return chains?.find(c => c.id === campaign.computeChainId);
}, [chains, campaign]);

return (
Expand All @@ -63,13 +45,7 @@ export default function LeaderboardTableRow({
</Group>
}
addressColumn={<User chain={chain} address={row.recipient} />}
rewardsColumn={
<Token
token={campaign.rewardToken}
format="amount_price"
amount={parseUnits(row?.amount, 0)}
/>
}
rewardsColumn={<Token token={campaign.rewardToken} format="amount_price" amount={parseUnits(row?.amount, 0)} />}
protocolColumn={<Text>{row?.reason?.split("_")[0]}</Text>}
/>
);
Expand Down
31 changes: 7 additions & 24 deletions src/routes/_merkl.users.$address.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ export const meta: MetaFunction<typeof loader> = ({ data, error }) => {
if (error) return [{ title: error }];
return [
{
title: `${data?.address?.substring(0, 6)}${data?.address.substring(
data?.address.length - 4
)} on Merkl`,
title: `${data?.address?.substring(0, 6)}${data?.address.substring(data?.address.length - 4)} on Merkl`,
},
];
};
Expand All @@ -38,23 +36,14 @@ export default function Index() {
const rewards = useRewards(raw);

const { chainId, chains, address: user } = useWalletContext();
const chain = useMemo(
() => chains?.find((c) => c.id === chainId),
[chainId, chains]
);
const reward = useMemo(
() => raw.find(({ chain: { id } }) => id === chainId),
[chainId, raw]
);
const chain = useMemo(() => chains?.find(c => c.id === chainId), [chainId, chains]);
const reward = useMemo(() => raw.find(({ chain: { id } }) => id === chainId), [chainId, raw]);
const { claimTransaction } = useReward(reward, user);

const isUserRewards = useMemo(() => user === address, [user, address]);
const isAbleToClaim = useMemo(
() =>
isUserRewards &&
reward &&
!reward.rewards.every(({ amount, claimed }) => amount === claimed),
[isUserRewards, reward]
() => isUserRewards && reward && !reward.rewards.every(({ amount, claimed }) => amount === claimed),
[isUserRewards, reward],
);

return (
Expand Down Expand Up @@ -96,12 +85,7 @@ export default function Index() {
</Group>
<Group className="flex-col">
{isAbleToClaim && (
<TransactionButton
disabled={!claimTransaction}
look="hype"
size="lg"
tx={claimTransaction}
>
<TransactionButton disabled={!claimTransaction} look="hype" size="lg" tx={claimTransaction}>
Claim on {chain?.name}
</TransactionButton>
)}
Expand Down Expand Up @@ -140,8 +124,7 @@ export default function Index() {
link: `/users/${address}/claims`,
key: crypto.randomUUID(),
},
]}
>
]}>
<Outlet context={rewards} />
</Hero>
);
Expand Down
3 changes: 1 addition & 2 deletions src/routes/_merkl.users.(none).tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ export default function Index() {
key: uuidv4(),
},
]
}
>
}>
<Outlet />
</Hero>
);
Expand Down

0 comments on commit a3f3a46

Please sign in to comment.