Skip to content

Commit

Permalink
feat: Gas Fees Card (#347)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xavier-Charles authored Mar 25, 2024
1 parent c25d287 commit 0ef9781
Show file tree
Hide file tree
Showing 10 changed files with 215 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ export const superfeedApi = alphadayApi.injectEndpoints({
itemType: i.data?.item_type,
projects: i.data?.projects,
projectType: i.data?.project_type,
gasFast: i.data?.GAS_FAST,
gasSlow: i.data?.GAS_SLOW,
gasStandard: i.data?.GAS_STANDARD,
gasPercentChange: i.data?.PERCENT_CHANGE,
gasPrevGasStandard: i.data?.PREV_GAS_STANDARD,
},
})),
}),
Expand Down
5 changes: 5 additions & 0 deletions packages/frontend/src/api/services/superfeed/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ export type TRemoteFeedItemData = Omit<
> & {
item_type?: string | null;
project_type?: "protocol" | "chain";
GAS_FAST?: number;
GAS_SLOW?: number;
GAS_STANDARD?: number;
PERCENT_CHANGE?: number;
PREV_GAS_STANDARD?: number;
};

export type TRemoteSuperfeedItem = {
Expand Down
6 changes: 6 additions & 0 deletions packages/frontend/src/api/types/superfeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export enum EFeedItemType {
DISCORD = "discorditem",
MARKET = "marketitem",
TVL = "tvlitem",
GAS = "gasitem",
}

/**
Expand Down Expand Up @@ -75,6 +76,11 @@ export type TFeedItemData = {
itemType?: string | null;
projects?: TTVLFeedDataItem[];
projectType?: "protocol" | "chain";
gasFast?: number;
gasSlow?: number;
gasStandard?: number;
gasPercentChange?: number;
gasPrevGasStandard?: number;
};

export type TSuperfeedItem = Omit<TBaseItem, "bookmarked"> & {
Expand Down
21 changes: 17 additions & 4 deletions packages/frontend/src/components/gas/GasPriceBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,22 @@ interface IGasPriceBox {
type: "fast" | "standard" | "slow";
gweiPrice: number | undefined;
usdPrice: number | undefined;
isCard?: boolean; // if true, the element will be displayed in a feed card
}

const GasPriceBox: FC<IGasPriceBox> = ({ type, gweiPrice, usdPrice }) => {
const GasPriceBox: FC<IGasPriceBox> = ({
type,
gweiPrice,
usdPrice,
isCard,
}) => {
return (
<div className="flex flex-col justify-center items-center border border-borderLine box-border rounded-lg min-w-[90px] w-full p-0 h-[91px]">
<div
className={twMerge(
"flex flex-col justify-center items-center border border-borderLine box-border rounded-lg min-w-[90px] w-full p-0 h-[91px]",
isCard && "w-[70px]"
)}
>
{type === "fast" && (
<GasPriceTitle className="text-success">{type}</GasPriceTitle>
)}
Expand All @@ -47,13 +58,15 @@ const GasPriceBox: FC<IGasPriceBox> = ({ type, gweiPrice, usdPrice }) => {
</GasPriceTitle>
)}
<div className="whitespace-nowrap text-center">
{gweiPrice && usdPrice ? (
{gweiPrice ? (
<div>
<p className="fontGroup-major text-primary mb-0 text-center">
{gweiPrice}
</p>
<p className="fontGroup-support mb-0 text-center text-primaryVariant100 mt-1">
${usdPrice.toFixed(2)}
{isCard
? "(gwei)"
: usdPrice && `$${usdPrice?.toFixed(2)}`}
</p>
</div>
) : (
Expand Down
10 changes: 10 additions & 0 deletions packages/frontend/src/mobile-components/feed/FeedCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { FC } from "react";
import { EFeedItemType, TSuperfeedItem } from "src/api/types";
import { BlogCard } from "./BlogCard";
import { EventCard } from "./EventCard";
import { GasCard } from "./GasCard";
import { ImageCard } from "./ImageCard";
import { MarketCard } from "./MarketCard";
import { NewsCard } from "./NewsCard";
Expand Down Expand Up @@ -140,6 +141,15 @@ export const FeedCard: FC<IFeedCard> = ({
isAuthenticated={isAuthenticated}
/>
);
case EFeedItemType.GAS:
return (
<GasCard
item={item}
onLike={onLike}
onShare={onShare}
isAuthenticated={isAuthenticated}
/>
);
case EFeedItemType.TVL:
return (
<TVLCard
Expand Down
156 changes: 156 additions & 0 deletions packages/frontend/src/mobile-components/feed/GasCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
import { FC } from "react";
import { Arrow, twMerge } from "@alphaday/ui-kit";
import { TSuperfeedItem } from "src/api/types";
import GasPriceBox from "src/components/gas/GasPriceBox";
import { computeDuration } from "src/utils/dateUtils";
import { imgOnError } from "src/utils/errorHandling";
import {
ActionButtons,
CardTitle,
FeedItemDisclosure,
FeedItemDisclosureButton,
FeedItemDisclosureButtonImage,
FeedItemDisclosurePanel,
TagButtons,
getFeedItemIcon,
} from "./FeedElements";

export const GasCard: FC<{
item: TSuperfeedItem;
isAuthenticated: boolean;
onLike: () => MaybeAsync<void>;
onShare: () => MaybeAsync<void>;
}> = ({ item, onLike, onShare, isAuthenticated }) => {
const {
tags,
likes,
comments,
title,
type,
date,
sourceIcon,
data: gasData,
} = item;

const isDown = gasData?.gasPercentChange && gasData.gasPercentChange < 0;

return (
<FeedItemDisclosure>
{({ open }) => (
<>
<FeedItemDisclosureButton>
<div className="flex flex-col w-full">
<div className="flex justify-between">
<div className="flex flex-col">
<div className="flex items-center">
<FeedItemDisclosureButtonImage
icon={getFeedItemIcon(type)}
/>
<p className="text-primaryVariant100 fontGroup-mini leading-[18px] flex flex-wrap whitespace-nowrap">
{computeDuration(date)}
<span className="mx-1 my-0 self-center">
</span>{" "}
<span>
<img
src={sourceIcon}
alt=""
className="w-3.5 h-3.5 mr-[5px] rounded-full inline-flex ml-1.5"
onError={imgOnError}
/>
</span>
</p>
</div>
<CardTitle title={title || ""} />
<p className="mt-4">
Gas Fees are {isDown ? "down" : "up"}{" "}
{isDown ? (
<Arrow
className="h-2.5"
direction="down"
/>
) : (
<Arrow
className="h-2.5"
direction="up"
/>
)}{" "}
{gasData?.gasPercentChange}%
</p>
</div>
<div className="flex-col min-w-max mr-9">
<div
className={twMerge(
"w-full flex justify-end items-start",
open && "hidden"
)}
/>
</div>
</div>
<div className="flex justify-between">
<div className="flex-col">
{!open && (
<TagButtons
truncated
tags={tags}
onClick={() => {}}
/>
)}
</div>
<div className="flex-col min-w-max ml-2">
{!open && (
<ActionButtons
onLike={onLike}
onCommentClick={onLike}
onShare={onShare}
likes={likes}
comments={comments}
isAuthenticated={isAuthenticated}
isLiked={item.isLiked}
/>
)}
</div>
</div>
</div>
</FeedItemDisclosureButton>
<FeedItemDisclosurePanel>
<div className="my-2 flex justify-between max-w-sm mx-auto">
<GasPriceBox
type="slow"
gweiPrice={gasData?.gasSlow}
usdPrice={undefined}
isCard
/>
<GasPriceBox
type="standard"
gweiPrice={gasData?.gasStandard}
usdPrice={undefined}
isCard
/>
<GasPriceBox
type="fast"
gweiPrice={gasData?.gasFast}
usdPrice={undefined}
isCard
/>
</div>
<div className="my-2 flex justify-between">
<TagButtons tags={tags} onClick={() => {}} />
<div className="min-w-max ml-2 mt-0.5">
<ActionButtons
onLike={onLike}
onCommentClick={onLike}
onShare={onShare}
likes={likes}
comments={comments}
isAuthenticated={isAuthenticated}
isLiked={item.isLiked}
/>
</div>
</div>
</FeedItemDisclosurePanel>
</>
)}
</FeedItemDisclosure>
);
};
2 changes: 2 additions & 0 deletions packages/frontend/src/mobile-components/feed/iconMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { EFeedItemType } from "src/api/types";
import blogIcon from "src/assets/feedIcons/blog.png";
import eventIcon from "src/assets/feedIcons/event.png";
import forumIcon from "src/assets/feedIcons/forum.png";
import gasIcon from "src/assets/feedIcons/gas.png";
import imageIcon from "src/assets/feedIcons/image.png";
import newsIcon from "src/assets/feedIcons/news.png";
import personIcon from "src/assets/feedIcons/person.png";
Expand All @@ -27,4 +28,5 @@ export const feedItemIconMap = {
[EFeedItemType.MARKET]: (down: boolean) =>
down ? trendDownIcon : trendUpIcon,
[EFeedItemType.TVL]: tvlIcon,
[EFeedItemType.GAS]: gasIcon,
};
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ export const STATIC_FILTER_OPTIONS: TLocalFilterOptions = {
color: themeColors.categoryTwelve,
contentType: EFeedItemType.DISCORD,
},
{
id: 14,
slug: EFeedItemType.GAS,
name: "Gas Prices",
selected: false,
color: themeColors.categoryEleven,
contentType: EFeedItemType.GAS,
},
],
},
timeRange: {
Expand Down
Binary file added packages/ui-kit/src/assets/feedIcons/gas.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions packages/ui-kit/src/components/arrow/Arrow.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { FC } from "react";
import ArrowDown from "src/assets/svg/arrow-down.svg";
import ArrowUp from "src/assets/svg/arrow-up.svg";
import { twMerge } from "tailwind-merge";

export const Arrow: FC<{ direction: "up" | "down" }> = ({ direction }) => {
export const Arrow: FC<{ direction: "up" | "down"; className?: string }> = ({
direction,
className,
}) => {
return (
<img
className="ml-[3px] inline-block h-2"
className={twMerge("ml-[3px] inline-block h-2", className)}
src={direction === "up" ? ArrowUp : ArrowDown}
alt="arrow"
/>
Expand Down

0 comments on commit 0ef9781

Please sign in to comment.