Skip to content

Commit

Permalink
Merge pull request #32 from pierobassa/improve-profile-buy-ux
Browse files Browse the repository at this point in the history
  • Loading branch information
akanoce authored Jan 5, 2024
2 parents af52d93 + adf44a8 commit d5c704a
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 179 deletions.
83 changes: 83 additions & 0 deletions src/components/Gems/GemsPriceInfo/GemsPriceInfo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { ethers } from "ethers";
import { useMemo } from "react";
import { FaEthereum, FaGem } from "react-icons/fa";

type Props = {
buyPrice: ethers.BigNumber;
sellPrice: ethers.BigNumber;
onBuyClick?: () => void;
onSellClick?: () => void;
};

export const GemsPriceInfo: React.FC<Props> = ({
buyPrice,
sellPrice,
onBuyClick,
onSellClick
}) => {
const buyPriceEther = useMemo(() => {
return ethers.utils.formatEther(buyPrice);
}, [buyPrice]);

const sellPriceEther = useMemo(() => {
return ethers.utils.formatEther(sellPrice);
}, [sellPrice]);

return (
<div className="bg-[#FF89A9] flex flex-col items-center rounded-md text-[#2b2b2b] py-1 px-2">
<div className="flex flex-row items-center gap-1 ">
<div>
<FaGem />
</div>
<p className="font-medium text-lg">Buy/Sell gems</p>
</div>
<div className="flex flex-row items-center gap-0.5 ">
{onBuyClick ? (
<button
className="py-1 px-2 flex flex-row items-center bg-[#006400] hover:brightness-90 rounded-md "
onClick={onBuyClick}
>
<div className="text-white">
<FaEthereum />
</div>
<div className="pl-1 text-white font-medium">
{buyPriceEther} ETH
</div>
</button>
) : (
<div className="py-1 px-2 flex flex-row items-center bg-[#006400] rounded-md ">
<div className="text-white">
<FaEthereum />
</div>
<div className="pl-1 text-white font-medium">
{buyPriceEther} ETH
</div>
</div>
)}

{onSellClick ? (
<button
className="py-1 px-2 flex flex-row items-center bg-[#99324e] hover:brightness-90 rounded-md "
onClick={onSellClick}
>
<div className="text-white">
<FaEthereum />
</div>
<div className="pl-1 text-white font-medium">
{sellPriceEther} ETH
</div>
</button>
) : (
<div className="py-1 px-2 flex flex-row items-center bg-[#99324e] rounded-md ">
<div className="text-white">
<FaEthereum />
</div>
<div className="pl-1 text-white font-medium">
{sellPriceEther} ETH
</div>
</div>
)}
</div>
</div>
);
};
1 change: 1 addition & 0 deletions src/components/Gems/GemsPriceInfo/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./GemsPriceInfo";
1 change: 1 addition & 0 deletions src/components/Gems/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./GemsPriceInfo";
75 changes: 13 additions & 62 deletions src/components/Pages/Profile/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import {
import { useRouter } from "next/router";
import { FaGem } from "react-icons/fa";
import { useCallback, useMemo, useState } from "react";
import { ethers } from "ethers";
import dynamic from "next/dynamic";
import { BaseSpacer } from "@/components";
import { BaseSpacer, GemsPriceInfo } from "@/components";
import {
profileId,
useProfile,
Expand All @@ -20,14 +19,6 @@ import { LensUtils } from "@/utils";
import { BeatLoader } from "react-spinners";
import { WithLensContext } from "@/providers";

const TradeDialog = dynamic(
() =>
import("@/components/TradeDialog/TradeDialog").then((res) => res.default),
{
ssr: false
}
);

const TransactionDialog = dynamic(
() =>
import("@/components/TransactionDialog/TransactionDialog").then(
Expand Down Expand Up @@ -109,20 +100,6 @@ function ProfileContent() {
return gemBalance.toNumber();
}, [gemBalance]);

const buyPriceEther = useMemo(() => {
return ethers.utils.formatEther(buyPrice);
}, [buyPrice]);

const sellPriceEther = useMemo(() => {
return ethers.utils.formatEther(sellPrice);
}, [sellPrice]);

const {
isOpen: isTradeDialogOpen,
onOpen: openTradeDialog,
onClose: closeTradeDialog
} = useDisclosure();

const {
isOpen: isTransactionDialogOpen,
onOpen: openTransactionDialog,
Expand All @@ -131,36 +108,25 @@ function ProfileContent() {

const [isBuy, setIsBuy] = useState(true);

const onBuyPress = useCallback(() => {
const onBuyClick = useCallback(() => {
setIsBuy(true);

closeTradeDialog();

openTransactionDialog();
}, [closeTradeDialog, openTransactionDialog]);
}, [openTransactionDialog]);

const onSellPress = useCallback(() => {
const onSellClick = useCallback(() => {
setIsBuy(false);

closeTradeDialog();

openTransactionDialog();
}, [closeTradeDialog, openTransactionDialog]);
}, [openTransactionDialog]);

const onTxFinish = useCallback(() => {
closeTransactionDialog();
openTradeDialog();

fetchBuyPrice();
fetchSellPrice();
fetchGemBalance();
}, [
closeTransactionDialog,
fetchBuyPrice,
fetchGemBalance,
fetchSellPrice,
openTradeDialog
]);
}, [closeTransactionDialog, fetchBuyPrice, fetchGemBalance, fetchSellPrice]);

const profilePicture = useMemo(
() => LensUtils.getProfilePicture(profile),
Expand All @@ -186,15 +152,14 @@ function ProfileContent() {
</div>
</div>
<div className="flex flex-col gap-2 items-center">
<button
className="py-2 px-3 bg-[#FF89A9] rounded-md text-[#2b2b2b] text-xs md:text-sm flex items-center justify-between"
onClick={openTradeDialog}
>
<FaGem />
<div className="pl-2 font-medium text-base">BUY GEMS</div>
</button>
<GemsPriceInfo
buyPrice={buyPrice}
sellPrice={sellPrice}
onBuyClick={onBuyClick}
onSellClick={onSellClick}
/>
<div className="flex items-center">
<p className="font-light ">You own {userGemBalance}</p>
<p className="font-medium ">You own {userGemBalance}</p>
{/* TODO: Replace with balance of gems owned */}
<div className="pl-1">
<FaGem />
Expand Down Expand Up @@ -229,20 +194,6 @@ function ProfileContent() {
)}
</div>
</div>
<TradeDialog
userName={userInfo?.name ?? ""}
userImg={profilePicture}
userAddress={smartAccountAddress ?? ""}
gemSubjectAddress={profileSmartAccountAddress ?? ""}
isOpen={isTradeDialogOpen}
buyPriceEther={buyPriceEther}
sellPriceEther={sellPriceEther}
gemBalanceEther={userGemBalance}
onBuyPress={onBuyPress}
onSellPress={onSellPress}
openModal={openTradeDialog}
closeModal={closeTradeDialog}
/>

<TransactionDialog
isOpen={isTransactionDialogOpen}
Expand Down
115 changes: 0 additions & 115 deletions src/components/TradeDialog/TradeDialog.tsx

This file was deleted.

1 change: 0 additions & 1 deletion src/components/TradeDialog/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from "./AccountBox";
export * from "./AccountCard";
export * from "./Base";
export * from "./Breadcrumbs";
export * from "./Gems";
export * from "./ImageDropzone";
export * from "./InputField";
export * from "./Lens";
Expand All @@ -10,5 +11,4 @@ export * from "./Navbar";
export * from "./SearchBar";
export * from "./SocialLoginWrapper";
export * from "./SuccessAnimation";
export * from "./TradeDialog";
export * from "./TransactionDialog";

0 comments on commit d5c704a

Please sign in to comment.