Skip to content

Commit

Permalink
Improve NFT sync
Browse files Browse the repository at this point in the history
  • Loading branch information
serg-plusplus committed Jul 26, 2022
1 parent bc29513 commit f553d0c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
13 changes: 1 addition & 12 deletions src/core/back/sync/chain.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import memoize from "mem";
import retry from "async-retry";
import { props } from "lib/system/promise";
import { slugify } from "lib/system/slugify";
import { NFTMetadataAgent } from "lib/nft-metadata";

import { ERC20__factory, ERC721__factory } from "abi-types";
Expand Down Expand Up @@ -96,18 +97,6 @@ function parseContentType(contentType?: string): NFTContentType | undefined {
return;
}

function slugify(text: string) {
return text
.toString() // Cast to string (optional)
.normalize("NFKD") // The normalize() using NFKD method returns the Unicode Normalization Form of a given string.
.toLowerCase() // Convert the string to lowercase letters
.trim() // Remove whitespace from both sides of a string (optional)
.replace(/\s+/g, "-") // Replace spaces with -
.replace(/[^\w\-]+/g, "") // Remove all non-word chars
.replace(/\-\-+/g, "-") // Replace multiple - with single -
.replace(/\-$/g, ""); // Remove trailing -
}

// async function legacy() {
// switch (standard) {
// case TokenStandard.ERC721: {
Expand Down
8 changes: 5 additions & 3 deletions src/core/back/sync/tokens/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,12 @@ export const syncAccountTokens = memoize(
const metadata = {
contractAddress,
tokenId,
name: existing?.name || token.name,
name: existing?.name || token.name || `#${tokenId}`,
description: existing?.description || token.description,
thumbnailUrl: existing?.thumbnailUrl || token.thumbnail_url,
contentUrl: existing?.contentUrl || token.content,
thumbnailUrl:
existing?.thumbnailUrl || token.thumbnail_url || token.content,
contentUrl:
existing?.contentUrl || token.content || token.thumbnail_url,
contentType: existing?.contentType || token.content_type,
collectionId: existing?.collectionId || token.collection_id,
collectionName: existing?.collectionName || token.contract_name,
Expand Down
11 changes: 11 additions & 0 deletions src/lib/system/slugify.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export function slugify(text: string) {
return text
.toString() // Cast to string (optional)
.normalize("NFKD") // The normalize() using NFKD method returns the Unicode Normalization Form of a given string.
.toLowerCase() // Convert the string to lowercase letters
.trim() // Remove whitespace from both sides of a string (optional)
.replace(/\s+/g, "-") // Replace spaces with -
.replace(/[^\w\-]+/g, "") // Remove all non-word chars
.replace(/\-\-+/g, "-") // Replace multiple - with single -
.replace(/\-$/g, ""); // Remove trailing -
}

0 comments on commit f553d0c

Please sign in to comment.