Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
indaviande committed Dec 3, 2024
1 parent 7d0222a commit e9a3f1c
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 221 deletions.
7 changes: 5 additions & 2 deletions src/api/services/opportunity.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ export abstract class OpportunityService {
): Promise<{ opportunities: Opportunity[]; count: number }> {
//TODO: updates tags to take an array
const opportunities = await OpportunityService.#fetch(async () =>
api.v4.opportunities.index.get({ query: Object.assign({ ...query }, config.tags?.[0] ? { tags: config.tags?.[0] }: {}) }),
api.v4.opportunities.index.get({
query: Object.assign({ ...query }, config.tags?.[0] ? { tags: config.tags?.[0] } : {}),
}),
);
const count = await OpportunityService.#fetch(async () => api.v4.opportunities.count.get({ query }));

Expand All @@ -83,7 +85,8 @@ export abstract class OpportunityService {
);

//TODO: updates tags to take an array
if (config.tags && !opportunity.tags.includes(config.tags?.[0])) throw new Response("Opportunity inacessible", { status: 403 });
if (config.tags && !opportunity.tags.includes(config.tags?.[0]))
throw new Response("Opportunity inacessible", { status: 403 });

return opportunity;
}
Expand Down
51 changes: 10 additions & 41 deletions src/components/composite/Hero.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
import type { Campaign } from "@angleprotocol/merkl-api";
import { useLocation } from "@remix-run/react";
import {
Container,
Divider,
Group,
Icon,
type IconProps,
Icons,
Text,
Title,
Value,
} from "dappkit";
import { Container, Divider, Group, Icon, type IconProps, Icons, Text, Title, Value } from "dappkit";
import { Button } from "dappkit";
import config from "merkl.config";
import { type PropsWithChildren, type ReactNode, useMemo } from "react";
Expand All @@ -26,30 +16,18 @@ export type HeroProps = PropsWithChildren<{
campaigns?: Campaign[];
}>;

export default function Hero({
navigation,
icons,
title,
description,
tags,
tabs,
children,
campaigns,
}: HeroProps) {
export default function Hero({ navigation, icons, title, description, tags, tabs, children, campaigns }: HeroProps) {
const location = useLocation();

const totalRewards = useMemo(() => {
const amounts = campaigns?.map((campaign) => {
const amounts = campaigns?.map(campaign => {
const duration = campaign.endTimestamp - campaign.startTimestamp;
const dayspan = BigInt(duration) / BigInt(3600 * 24);

return parseUnits(campaign.amount, 0) / BigInt(dayspan);
});

const sum = amounts?.reduce(
(accumulator, currentValue) => accumulator + currentValue,
0n
);
const sum = amounts?.reduce((accumulator, currentValue) => accumulator + currentValue, 0n);
if (!sum) return "0.0";
return formatUnits(sum, 18);
}, [campaigns]);
Expand All @@ -58,8 +36,7 @@ export default function Hero({
<>
<Group
className="flex-row justify-between aspect-[1440/400] bg-cover bg-no-repeat xl:aspect-auto xl:min-h-[400px]"
style={{ backgroundImage: `url('${config.images.hero}')` }}
>
style={{ backgroundImage: `url('${config.images.hero}')` }}>
<Container>
<Group className="flex-col h-full py-xl gap-xl lg:gap-xs">
<Group className="items-center">
Expand All @@ -70,8 +47,7 @@ export default function Hero({
disabled={!navigation?.link}
to={navigation?.link}
look="soft"
size="xs"
>
size="xs">
Home
</Button>

Expand Down Expand Up @@ -102,14 +78,14 @@ export default function Hero({
{!!icons && (
<Icons size="lg">
{icons?.length > 1
? icons?.map((icon) => (
? icons?.map(icon => (
<Icon
className="hidden md:block text-main-12 !w-lg*4 !h-lg*4"
key={`${Object.values(icon)}`}
{...icon}
/>
))
: icons?.map((icon) => (
: icons?.map(icon => (
<Icon
className="hidden md:block text-main-12 !w-xl*4 !h-xl*4"
key={`${Object.values(icon)}`}
Expand Down Expand Up @@ -138,16 +114,9 @@ export default function Hero({
</Group>
{/* TODO: Show "Opportunities" or "Campaigns" according to the page */}
{!location?.pathname.includes("user") && (
<Group
className="w-full lg:w-auto lg:flex-col mr-xl*2"
size="xl"
>
<Group className="w-full lg:w-auto lg:flex-col mr-xl*2" size="xl">
<Group className="flex-col">
<Value
look={totalRewards === "0" ? "soft" : "base"}
format="$0,0"
size={3}
>
<Value look={totalRewards === "0" ? "soft" : "base"} format="$0,0" size={3}>
{totalRewards}
</Value>

Expand Down
7 changes: 2 additions & 5 deletions src/components/element/SwitchMode.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import config from "merkl.config";
import { Button, Icon, useTheme } from "packages/dappkit/src";
import { useMemo } from "react";
import config from "merkl.config";

export default function SwitchMode() {
const { mode, toggleMode } = useTheme();
const canSwitchModes = useMemo(
() => !(!config.modes || config.modes?.length === 1),
[]
);
const canSwitchModes = useMemo(() => !(!config.modes || config.modes?.length === 1), []);
return (
canSwitchModes && (
<Button look="base" onClick={toggleMode}>
Expand Down
47 changes: 10 additions & 37 deletions src/components/element/Tag.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
import type { Opportunity, Token } from "@angleprotocol/merkl-api";
import {
Button,
Divider,
Dropdown,
Group,
Hash,
Icon,
Text,
PrimitiveTag,
} from "dappkit";
import { Button, Divider, Dropdown, Group, Hash, Icon, PrimitiveTag, Text } from "dappkit";
import type { ButtonProps } from "dappkit";
import { type Action, actions } from "src/config/actions";
import type { Protocol } from "src/config/protocols";
Expand All @@ -32,11 +23,7 @@ export type TagProps<T extends keyof TagTypes> = ButtonProps & {
value: TagTypes[T];
};

export default function Tag<T extends keyof TagTypes>({
type,
value,
...props
}: TagProps<T>) {
export default function Tag<T extends keyof TagTypes>({ type, value, ...props }: TagProps<T>) {
switch (type) {
case "status": {
const status = statuses[value as TagTypes["status"]] ?? statuses.LIVE;
Expand Down Expand Up @@ -64,8 +51,7 @@ export default function Tag<T extends keyof TagTypes>({
</Button>
</Group>
</Group>
}
>
}>
<PrimitiveTag look="soft" key={value} {...props}>
<Icon size={props?.size} {...status.icon} />
{status?.label}
Expand Down Expand Up @@ -99,8 +85,7 @@ export default function Tag<T extends keyof TagTypes>({
</Button>
</Group>
</Group>
}
>
}>
<PrimitiveTag look="base" key={value} {...props}>
<Icon size={props?.size} src={chain?.icon} />
{chain?.name}
Expand Down Expand Up @@ -134,8 +119,7 @@ export default function Tag<T extends keyof TagTypes>({
Open
</Button>
</Group>
}
>
}>
<PrimitiveTag look="bold" key={value} {...props}>
<Icon size={props?.size} {...action.icon} />
{action?.label}
Expand Down Expand Up @@ -181,8 +165,7 @@ export default function Tag<T extends keyof TagTypes>({
</Button>
</Group>
</Group>
}
>
}>
<PrimitiveTag look="base" key={value} {...props}>
<Icon size={props?.size} src={token.icon} />
{token?.symbol}
Expand Down Expand Up @@ -219,11 +202,7 @@ export default function Tag<T extends keyof TagTypes>({
<Divider look="soft" horizontal />
<Group className="flex-col" size="md">
{/* <Text size="xs">{token?.description}</Text> */}
<Button
to={`/chain/${token.chain?.name}`}
size="sm"
look="bold"
>
<Button to={`/chain/${token.chain?.name}`} size="sm" look="bold">
<Icon size="sm" src={token.chain?.icon} />
{token.chain?.name}
</Button>
Expand All @@ -237,8 +216,7 @@ export default function Tag<T extends keyof TagTypes>({
</Button>
</Group>
</Group>
}
>
}>
<PrimitiveTag look="base" key={value} {...props}>
<Icon size={props?.size} src={token.chain.icon} />
{token.chain.name}
Expand Down Expand Up @@ -267,11 +245,7 @@ export default function Tag<T extends keyof TagTypes>({
<Divider look="soft" horizontal />
<Group className="flex-col" size="md">
{/* <Text size="xs">{token?.description}</Text> */}
<Button
to={`/protocol/${protocol?.name}`}
size="xs"
look="soft"
>
<Button to={`/protocol/${protocol?.name}`} size="xs" look="soft">
<Icon remix="RiArrowRightLine" />
{protocol?.name} on Merkl
</Button>
Expand All @@ -281,8 +255,7 @@ export default function Tag<T extends keyof TagTypes>({
</Button>
</Group>
</Group>
}
>
}>
<PrimitiveTag look="tint" key={value} {...props}>
<Icon src={protocol?.icon} />
{value?.name}
Expand Down
34 changes: 6 additions & 28 deletions src/components/element/functions/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import { Button } from "dappkit";
import Scroll from "packages/dappkit/src/components/primitives/Scroll";
import { type ReactNode, useEffect, useMemo, useState } from "react";
import useOpportunity from "src/hooks/resources/useOpportunity";
import {
type Results,
type Searchable,
useMerklSearch,
} from "src/hooks/useMerklSearch";
import { type Results, type Searchable, useMerklSearch } from "src/hooks/useMerklSearch";

const titles: { [S in Searchable]: ReactNode } = {
chain: "Chains",
Expand Down Expand Up @@ -65,33 +61,21 @@ export default function SearchBar({ icon = false }: SearchBarProps) {
switch (category) {
case "chain":
return (
<Button
to={`/chain/${results[i].name}`}
size="lg"
look="bold"
>
<Button to={`/chain/${results[i].name}`} size="lg" look="bold">
<Icon src={results[i].icon} /> {results[i].name}
</Button>
);
case "opportunity":
return <OpportunityResult opportunity={results[i]} />;
case "token":
return (
<Button
to={`/token/${results[i].symbol}`}
size="lg"
look="bold"
>
<Button to={`/token/${results[i].symbol}`} size="lg" look="bold">
<Icon src={results[i].icon} /> {results[i].symbol}
</Button>
);
case "protocol":
return (
<Button
to={`/protocol/${results[i].name}`}
size="lg"
look="bold"
>
<Button to={`/protocol/${results[i].name}`} size="lg" look="bold">
<Icon src={results[i].icon} /> {results[i].name}
</Button>
);
Expand All @@ -113,16 +97,10 @@ export default function SearchBar({ icon = false }: SearchBarProps) {
state={[opened, setOpened]}
modal={
<>
<Input
look="bold"
size="md"
state={[searchInput, setSearchInput]}
placeholder="Search Merkl..."
/>
<Input look="bold" size="md" state={[searchInput, setSearchInput]} placeholder="Search Merkl..." />
{Results}
</>
}
>
}>
<Form>
{icon ? (
<Button look="base">
Expand Down
Loading

0 comments on commit e9a3f1c

Please sign in to comment.