Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Resolve issue where user can't delete their own listing if they are not the cheapest #683

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions apps/next-react/src/components/TokenCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
CHAIN_IDENTIFIERS,
COLLECTION_NAME_TRUNCATE_LENGTH,
} from "../lib/constants";
import { findListingItemByOwner } from "@/lib/utilities";

const TokenCard = ({
originalItem,
Expand Down Expand Up @@ -52,10 +53,10 @@ const TokenCard = ({
const [refreshing, setRefreshing] = useState(false);
const [showModel, setShowModel] = useState(false);

const hasMatchingListing = item?.listing?.all_sellers?.find((seller) => {
return seller.profile_id === pageProfile?.profile_id;
});

const hasMatchingListing = findListingItemByOwner(
item,
pageProfile?.profile_id
);
const freeListedItem = item?.listing?.min_price === 0;
const singleItem = item?.token_count === 1;

Expand Down
13 changes: 8 additions & 5 deletions apps/next-react/src/components/UI/Modals/UnlistModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import useProfile from "@/hooks/useProfile";
import { ExclamationIcon } from "@heroicons/react/outline";
import XIcon from "@/components/Icons/XIcon";
import { DEFAULT_PROFILE_PIC } from "@/lib/constants";
import { formatAddressShort, truncateWithEllipses } from "@/lib/utilities";
import {
formatAddressShort,
truncateWithEllipses,
findListingItemByOwner,
} from "@/lib/utilities";
import BadgeIcon from "@/components/Icons/BadgeIcon";
import useFlags, { FLAGS } from "@/hooks/useFlags";

Expand Down Expand Up @@ -76,6 +80,7 @@ const UnlistModal = ({ open, onClose, onSuccess = () => null, token }) => {

const unlistToken = async () => {
setModalPage(MODAL_PAGES.LOADING);
const ownerItem = findListingItemByOwner(token, myProfile.profile_id);

const web3Modal = getWeb3Modal({
theme: resolvedTheme,
Expand Down Expand Up @@ -110,7 +115,7 @@ const UnlistModal = ({ open, onClose, onSuccess = () => null, token }) => {
const provider = biconomy.getEthersProvider();

const { data } = await contract.populateTransaction.cancelSale(
token.listing.sale_identifier
ownerItem.sale_identifier
);

const transaction = await provider
Expand Down Expand Up @@ -225,9 +230,7 @@ const UnlistModal = ({ open, onClose, onSuccess = () => null, token }) => {
};

const UnlistPage = ({ token, unlistToken, onClose, profile_id }) => {
const currentListing = token?.listing?.all_sellers?.find(
(seller) => seller.profile_id === profile_id
);
const currentListing = findListingItemByOwner(token, profile_id);
const hasMultipleEditions = token?.listing?.total_edition_quantity > 1;

return (
Expand Down
8 changes: 8 additions & 0 deletions apps/next-react/src/lib/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,3 +375,11 @@ export const parseBalance = (balance, currency) => {

return parseUnits(balance, 6);
};

export const findListingItemByOwner = (item, profileID) => {
const listedItem = item?.listing?.all_sellers?.find((seller) => {
return seller.profile_id === profileID;
});

return listedItem;
};