Skip to content

Commit

Permalink
sync merkl app
Browse files Browse the repository at this point in the history
  • Loading branch information
hugolxt committed Jan 7, 2025
1 parent 07c3f75 commit 7d2e01f
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/api/services/reward.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ export abstract class RewardService {

// biome-ignore lint/suspicious/noExplicitAny: TODO
const query: Record<string, any> = {
chainId: url.searchParams.get("chainId") ?? undefined,
test: config.alwaysShowTestTokens ? true : (url.searchParams.get("test") ?? false),
};
if (!!url.searchParams.get("chainId")) query.reloadChainId = url.searchParams.get("chainId");
if (chainIds) query.chainIds = chainIds;
return await RewardService.#fetch(async () =>
api.v4.users({ address }).rewards.breakdowns.get({
Expand Down
7 changes: 5 additions & 2 deletions src/components/element/rewards/ClaimRewardsChainTableRow.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Reward } from "@merkl/api";
import { Button, type Component, Icon, Space, Value, mergeClass } from "dappkit";
import config from "merkl.config";
import TransactionButton from "packages/dappkit/src/components/dapp/TransactionButton";
import TransactionButton, { type TransactionButtonProps } from "packages/dappkit/src/components/dapp/TransactionButton";
import Collapsible from "packages/dappkit/src/components/primitives/Collapsible";
import EventBlocker from "packages/dappkit/src/components/primitives/EventBlocker";
import { useWalletContext } from "packages/dappkit/src/context/Wallet.context";
Expand All @@ -16,12 +16,14 @@ import ClaimRewardsTokenTableRow from "./ClaimRewardsTokenTableRow";
export type ClaimRewardsChainTableRowProps = Component<{
from: string;
reward: Reward;
onClaimSuccess: TransactionButtonProps["onSuccess"];
}>;

export default function ClaimRewardsChainTableRow({
from,
reward,
className,
onClaimSuccess,
...props
}: ClaimRewardsChainTableRowProps) {
const [open, setOpen] = useState(false);
Expand Down Expand Up @@ -99,7 +101,8 @@ export default function ClaimRewardsChainTableRow({
disabled={!claimTransaction}
className="ml-xl"
look="hype"
tx={claimTransaction}>
tx={claimTransaction}
onSuccess={onClaimSuccess}>
Claim
</TransactionButton>
) : (
Expand Down
12 changes: 9 additions & 3 deletions src/components/element/rewards/ClaimRewardsLibrary.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Reward } from "@merkl/api";
import { Group, Text } from "dappkit";
import config from "merkl.config";
import type { TransactionButtonProps } from "packages/dappkit/src/components/dapp/TransactionButton";
import { useMemo } from "react";
import { ClaimRewardsChainTable } from "./ClaimRewardsChainTable";
import ClaimRewardsChainTableRow from "./ClaimRewardsChainTableRow";
Expand All @@ -9,9 +10,10 @@ import ClaimRewardsByOpportunity from "./byOpportunity/ClaimRewardsByOpportunity
export type ClaimRewardsLibraryProps = {
rewards: Reward[];
from: string;
onClaimSuccess: TransactionButtonProps["onSuccess"];
};

export default function ClaimRewardsLibrary({ from, rewards }: ClaimRewardsLibraryProps) {
export default function ClaimRewardsLibrary({ from, rewards, onClaimSuccess }: ClaimRewardsLibraryProps) {
const flatenedRewards = useMemo(
() =>
rewards.flatMap(({ chain, rewards, distributor }) =>
Expand All @@ -30,12 +32,16 @@ export default function ClaimRewardsLibrary({ from, rewards }: ClaimRewardsLibra
return (
<ClaimRewardsChainTable dividerClassName={index => (index === 1 ? "bg-accent-10" : "bg-main-7")}>
{rewards?.map((reward, index) => (
<ClaimRewardsChainTableRow {...{ from, reward }} key={reward.chain?.id ?? index} />
<ClaimRewardsChainTableRow
{...{ from, reward }}
key={reward.chain?.id ?? index}
onClaimSuccess={onClaimSuccess}
/>
))}
</ClaimRewardsChainTable>
);
}
}, [rewards, flatenedRewards, from]);
}, [rewards, flatenedRewards, from, onClaimSuccess]);

return (
<Group className="flex-row w-full [&>*]:flex-grow">
Expand Down
4 changes: 2 additions & 2 deletions src/components/layout/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ export default function Header() {
<Group className="hidden lg:flex items-center" size="xl">
{Object.entries(routes)
.filter(([key]) => !["home", "faq", "docs"].includes(key))
.map(([key, { route }]) => {
.map(([key, route]) => {
return (
<Button
className={`${["faq"].includes(key) ? "uppercase" : "capitalize"}`}
look="soft"
size="lg"
key={`${key}-link`}
to={route}>
to={route?.route}>
{key}
</Button>
);
Expand Down
5 changes: 3 additions & 2 deletions src/routes/_merkl.users.$address.(rewards).tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export async function loader({ params: { address } }: LoaderFunctionArgs) {

export default function Index() {
const { address } = useLoaderData<typeof loader>();
const { sortedRewards } = useOutletContext<OutletContextRewards>();
const { rewards: sortedRewards, onClaimSuccess } = useOutletContext<OutletContextRewards>();


return (
<Container>
Expand All @@ -28,7 +29,7 @@ export default function Index() {
</Group>
)}
<Space size="md" />
<ClaimRewardsLibrary from={address} rewards={sortedRewards} />
<ClaimRewardsLibrary from={address} rewards={sortedRewards} onClaimSuccess={onClaimSuccess} />
</Container>
);
}
13 changes: 8 additions & 5 deletions src/routes/_merkl.users.$address.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { LoaderFunctionArgs, MetaFunction } from "@remix-run/node";
import { Outlet, json, useFetcher, useLoaderData } from "@remix-run/react";
import { Button, Divider, Dropdown, Group, Hash, Icon, Text, Value } from "dappkit";
import config from "merkl.config";
import TransactionButton from "packages/dappkit/src/components/dapp/TransactionButton";
import TransactionButton, { type TransactionButtonProps } from "packages/dappkit/src/components/dapp/TransactionButton";
import { useWalletContext } from "packages/dappkit/src/context/Wallet.context";
import { useMemo } from "react";
import { RewardService } from "src/api/services/reward.service";
Expand Down Expand Up @@ -38,13 +38,16 @@ export const meta: MetaFunction<typeof loader> = ({ data, error }) => {
];
};

export type OutletContextRewards = ReturnType<typeof useRewards>;
export type OutletContextRewards = {
rewards: ReturnType<typeof useRewards>["sortedRewards"];
onClaimSuccess: TransactionButtonProps["onSuccess"];
};

export default function Index() {
const { rewards: raw, address, token: rawToken } = useLoaderData<typeof loader>();
const fetcher = useFetcher<typeof loader>();

const handleRefreshData = async () => {
const onClaimSuccess = async (_hash: string) => {
await fetcher.submit(null, { method: "post", action: `/claim/${address}?chainId=${chainId}` });
};

Expand Down Expand Up @@ -151,7 +154,7 @@ export default function Index() {
look="hype"
size="lg"
tx={claimTransaction}
onSuccess={_hash => handleRefreshData()}>
onSuccess={onClaimSuccess}>
{isSingleChain ? "Claim Now" : `Claim on ${chain?.name}`}
<Icon remix="RiHandCoinFill" />
</TransactionButton>
Expand Down Expand Up @@ -193,7 +196,7 @@ export default function Index() {
}
description={""}
tabs={tabs}>
<Outlet context={rewards} />
<Outlet context={{ rewards: rewards.sortedRewards, onClaimSuccess } as OutletContextRewards} />
</Hero>
);
}

0 comments on commit 7d2e01f

Please sign in to comment.