Skip to content
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
4 changes: 2 additions & 2 deletions components/SearchInputResultsList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ const SearchInputResultsList = ({
name,
template_id,
collection: { collection_name },
immutable_data: { image, video },
immutable_data: { image, img, video },
},
i
) => {
Expand All @@ -154,7 +154,7 @@ const SearchInputResultsList = ({
key={name}>
<TemplateIcon
name={name}
image={image}
image={image || img}
video={video}
margin="0 12px 0 0"
/>
Expand Down
26 changes: 19 additions & 7 deletions services/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type Schema = {
type ImmutableData = {
name: string;
image?: string;
img?: string;
series: number;
desc: string;
video?: string;
Expand Down Expand Up @@ -83,6 +84,17 @@ type formatTemplatesWithLowPriceAndAssetCountProps = {
* @return {Template[]} Returns array of templates, most likely will only return one item in the array
*/

/**
* Normalize immutable_data: fall back to 'img' if 'image' is missing.
* Some collections use 'img' instead of the standard 'image' attribute.
*/
const normalizeTemplate = (template: Template): Template => {
if (template.immutable_data && !template.immutable_data.image && template.immutable_data.img) {
template.immutable_data.image = template.immutable_data.img;
}
return template;
};

export const getTemplateDetails = async (
collectionName: string,
templateId: string
Expand Down Expand Up @@ -117,10 +129,10 @@ export const getTemplateDetails = async (
)} ${lowestPriceSale.listing_symbol}`
: '';

return {
return normalizeTemplate({
...templatesResponse.data[0],
lowestPrice,
};
});
} catch (e) {
throw new Error(e);
}
Expand Down Expand Up @@ -159,7 +171,7 @@ export const getTemplatesByCollection = async ({
throw new Error(errorMessage as string);
}

return templatesResponse.data;
return templatesResponse.data.map(normalizeTemplate);
} catch (e) {
throw new Error(e);
}
Expand Down Expand Up @@ -206,7 +218,7 @@ export const getAllTemplatesByCollection = async ({
hasResults = false;
}

templates = templates.concat(templatesResponse.data);
templates = templates.concat(templatesResponse.data.map(normalizeTemplate));
page += 1;
}

Expand Down Expand Up @@ -496,7 +508,7 @@ export const getTemplatesFromTemplateIds = async (
}

page += 1;
templates = templates.concat(templatesResponse.data);
templates = templates.concat(templatesResponse.data.map(normalizeTemplate));
} catch (e) {
throw new Error(e);
}
Expand Down Expand Up @@ -534,7 +546,7 @@ export const getPaginatedCreationsByCreator = async ({
throw new Error((templatesResponse.message as unknown) as string);
}

return templatesResponse.data;
return templatesResponse.data.map(normalizeTemplate);
} catch (e) {
throw new Error(e);
}
Expand Down Expand Up @@ -576,7 +588,7 @@ export const getAllCreationsByCreator = async ({
hasResults = false;
}

templates = templates.concat(templatesResponse.data);
templates = templates.concat(templatesResponse.data.map(normalizeTemplate));
page += 1;
}

Expand Down
Loading