Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: coverage for unknown network prop in marketplaces component #323

Merged
merged 1 commit into from
Oct 31, 2023
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
16 changes: 16 additions & 0 deletions resources/js/Components/Marketplaces.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,20 @@ describe("Marketplaces", () => {

expect(screen.getByTestId(testId)).toHaveAttribute("href", url);
});

it("should render null url for unknown chain", () => {
render(
<Marketplaces
address={polygonCollection.address}
nftId={polygonNft.tokenNumber}
chainId={0 as ExplorerChains}
type="collection"
/>,
);

expect(screen.getByTestId("NftMarketplaces__Opensea")).toHaveAttribute("href", "#");
expect(screen.getByTestId("NftMarketplaces__Rarible")).toHaveAttribute("href", "#");
expect(screen.getByTestId("NftMarketplaces__Blur")).toHaveAttribute("href", "#");
expect(screen.getByTestId("NftMarketplaces__LooksRare")).toHaveAttribute("href", "#");
});
});
20 changes: 14 additions & 6 deletions resources/js/Components/Marketplaces.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react";
import { useTranslation } from "react-i18next";
import { ButtonLink } from "@/Components/Buttons/ButtonLink";
import { ExplorerChains } from "@/Utils/Explorer";
import { isTruthy } from "@/Utils/is-truthy";

interface Properties {
type: "nft" | "collection";
Expand All @@ -24,12 +25,19 @@ const getNetworkName = (chainId: App.Enums.Chains): string | null => {
export const Marketplaces = ({ type, chainId, address, nftId }: Properties): JSX.Element => {
const { t } = useTranslation();

const getMarketplaceUrl = (marketplace: string): string =>
t(`urls.marketplaces.${marketplace}.${type}`, {
nftId,
network: getNetworkName(chainId),
address,
}).toLowerCase();
const getMarketplaceUrl = (marketplace: string): string => {
const networkName = getNetworkName(chainId);

if (isTruthy(networkName)) {
return t(`urls.marketplaces.${marketplace}.${type}`, {
nftId,
network: networkName,
address,
}).toLowerCase();
}

return "#";
};

return (
<div
Expand Down
Loading