generated from t3-oss/create-t3-turbo
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from ArkProjectNFTs/yohan/token-offers
feat: token offers
- Loading branch information
Showing
13 changed files
with
318 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...market/src/app/token/[contractAddress]/[tokenId]/components/token-offers-table-action.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { useAccount } from "@starknet-react/core"; | ||
import { validateAndParseAddress } from "starknet"; | ||
|
||
import { Button } from "@ark-market/ui/button"; | ||
|
||
import AcceptOffer from "~/app/assets/[contract_address]/[token_id]/components/accept-offer"; | ||
import CancelOffer from "~/app/assets/[contract_address]/[token_id]/components/cancel-offer"; | ||
import ConnectWalletModal from "~/components/connect-wallet-modal"; | ||
|
||
interface TokenOffersTableActionProps { | ||
owner: string; | ||
offerSourceAddress: string | null; | ||
offerOrderHash: string; | ||
tokenId: string; | ||
tokenContractAddress: string; | ||
offerAmount: string; | ||
tokenIsListed: boolean; | ||
tokenListingOrderHash: string | null; | ||
} | ||
|
||
export default function TokenOffersTableAction({ | ||
offerAmount, | ||
offerOrderHash, | ||
offerSourceAddress, | ||
owner, | ||
tokenContractAddress, | ||
tokenId, | ||
tokenIsListed, | ||
tokenListingOrderHash, | ||
}: TokenOffersTableActionProps) { | ||
const { address } = useAccount(); | ||
|
||
const isOwner = | ||
address !== undefined && | ||
validateAndParseAddress(address) === validateAndParseAddress(owner); | ||
|
||
if (!address) { | ||
return ( | ||
<ConnectWalletModal> | ||
<Button size="xl">Connect wallet</Button> | ||
</ConnectWalletModal> | ||
); | ||
} | ||
|
||
if (isOwner && tokenListingOrderHash !== null) { | ||
return ( | ||
<AcceptOffer | ||
offerOrderHash={offerOrderHash} | ||
tokenId={tokenId} | ||
tokenContractAddress={tokenContractAddress} | ||
tokenOwner={owner} | ||
offerAmount={offerAmount} | ||
tokenIsListed={tokenIsListed} | ||
tokenListingOrderHash={tokenListingOrderHash} | ||
/> | ||
); | ||
} | ||
|
||
if ( | ||
validateAndParseAddress(address) === | ||
validateAndParseAddress(offerSourceAddress ?? "") | ||
) | ||
return ( | ||
<CancelOffer | ||
offerOrderHash={offerOrderHash} | ||
tokenId={tokenId} | ||
tokenContractAddress={tokenContractAddress} | ||
/> | ||
); | ||
|
||
return null; | ||
} |
86 changes: 86 additions & 0 deletions
86
apps/arkmarket/src/app/token/[contractAddress]/[tokenId]/components/token-offers-table.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { getRoundedRemainingTime, shortAddress } from "@ark-market/ui"; | ||
import { PriceTag } from "@ark-market/ui/price-tag"; | ||
import { | ||
Table, | ||
TableBody, | ||
TableCell, | ||
TableHead, | ||
TableHeader, | ||
TableRow, | ||
} from "@ark-market/ui/table"; | ||
|
||
import type { TokenOffer } from "../queries/getTokenData"; | ||
import type { TokenMarketData } from "~/types"; | ||
import TokenOffersTableAction from "./token-offers-table-action"; | ||
|
||
interface TokenOffersTableProps { | ||
tokenOffers: TokenOffer[]; | ||
tokenContractAdress: string; | ||
tokenId: string; | ||
owner: string; | ||
tokenMarketData: TokenMarketData | null; | ||
} | ||
|
||
export default function TokenOffersTable({ | ||
tokenOffers, | ||
owner, | ||
tokenContractAdress, | ||
tokenId, | ||
tokenMarketData, | ||
}: TokenOffersTableProps) { | ||
return ( | ||
<Table> | ||
<TableHeader className="hover:bg-background"> | ||
<TableRow className="grid w-full grid-cols-5 items-center"> | ||
<TableHead className="sticky top-0 flex items-center"> | ||
Price | ||
</TableHead> | ||
<TableHead className="sticky top-0 flex items-center"> | ||
Floor difference | ||
</TableHead> | ||
<TableHead className="sticky top-0 flex items-center">From</TableHead> | ||
<TableHead className="sticky top-0 flex items-center"> | ||
Expiration | ||
</TableHead> | ||
<TableHead className="sticky top-0 flex items-center"> | ||
Action | ||
</TableHead> | ||
</TableRow> | ||
</TableHeader> | ||
<TableBody className="block max-h-[25.5rem] overflow-auto text-sm font-semibold"> | ||
{tokenOffers.map((offer) => { | ||
return ( | ||
<TableRow | ||
key={offer.offer_id} | ||
className="grid h-[4.625rem] w-full grid-cols-5 items-center" | ||
> | ||
<TableCell> | ||
<PriceTag price={offer.price} /> | ||
</TableCell> | ||
{/* TODO @YohanTz: Check how this one looks */} | ||
<TableCell>{offer.floor_difference ?? "_"}</TableCell> | ||
<TableCell> | ||
{offer.source ? shortAddress(offer.source) : "_"} | ||
</TableCell> | ||
<TableCell> | ||
In {getRoundedRemainingTime(offer.expire_at)} | ||
</TableCell> | ||
<TableCell> | ||
<TokenOffersTableAction | ||
owner={owner} | ||
offerSourceAddress={offer.source} | ||
offerOrderHash={offer.hash} | ||
tokenContractAddress={tokenContractAdress} | ||
tokenId={tokenId} | ||
offerAmount={offer.price} | ||
tokenIsListed={tokenMarketData?.is_listed ?? false} | ||
tokenListingOrderHash={tokenMarketData?.order_hash ?? null} | ||
/> | ||
</TableCell> | ||
</TableRow> | ||
); | ||
})} | ||
</TableBody> | ||
</Table> | ||
); | ||
} |
Oops, something went wrong.