diff --git a/src/components/NFTPortfolio/MainView.vue b/src/components/NFTPortfolio/MainView.vue
index 8ab74af2b..b9c0b4b02 100644
--- a/src/components/NFTPortfolio/MainView.vue
+++ b/src/components/NFTPortfolio/MainView.vue
@@ -84,15 +84,19 @@
- -
+
-
-
+ {{ $t('campaign_nft_view_nft_dashboard') }}
{
+ collectedNFTs.forEach(nft => {
const { classId, timestamp } = nft;
if (!timestampMap[classId] || timestampMap[classId] < timestamp) {
timestampMap[classId] = timestamp;
}
});
- const collected = [
- ...new Map(
- [...nfts]
- .filter(({ classId }) => !LIKECOIN_NFT_HIDDEN_ITEMS.has(classId))
- .sort((a, b) => b.timestamp - a.timestamp)
- .map(({ classId, nftId }) => [classId, { classId, id: nftId }])
- ).values(),
- ];
- const created = [
- ...new Map(
- [...createdNFTs]
- .filter(({ classId }) => !LIKECOIN_NFT_HIDDEN_ITEMS.has(classId))
- .map(({ classId }) => [classId, { classId }])
- ).values(),
- ];
-
commit(TYPES.NFT_SET_USER_CLASSID_LIST_MAP, {
address,
nfts: {
- created,
- collected,
+ created: normalizeNFTList(createdNFTClasses),
+ collected: normalizeNFTList(collectedNFTs),
},
});
commit(TYPES.NFT_SET_USER_LAST_COLLECTED_TIMESTAMP_MAP, {
diff --git a/src/util/nft.js b/src/util/nft.js
index c9567e836..47994cd02 100644
--- a/src/util/nft.js
+++ b/src/util/nft.js
@@ -9,6 +9,7 @@ import {
LIKECOIN_CHAIN_NFT_RPC,
LIKECOIN_CHAIN_MIN_DENOM,
LIKECOIN_NFT_API_WALLET,
+ LIKECOIN_NFT_HIDDEN_ITEMS,
} from '../constant';
let queryClient = null;
@@ -175,6 +176,14 @@ export function checkIsWritingNFT(classMetadata) {
);
}
+// NOTE: This is a temporary solution to check Writing NFT by NFT ID,
+// should be removed after created NFT list return proper content metadata
+export function checkIsWritingNFTByNFTId(id) {
+ return /^writing-[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(
+ id
+ );
+}
+
export function formatNFTInfo(nftInfo) {
const {
class_id: classId,
@@ -265,7 +274,10 @@ const fetchAllNFTClassFromChain = async (axios, owner) => {
);
// TODO: getNFTClasses API already contains chain metadata
// should reuse them instead of dropping
- return classes.map(c => ({ classId: c.id }));
+ return classes.map(c => ({
+ classId: c.id,
+ timestamp: new Date(c.created_at).getTime(),
+ }));
};
export const getNFTClassesRespectDualPrefix = async (axios, owner) => {
@@ -298,3 +310,24 @@ export function parseNFTMetadataURL(url) {
if (schema === 'ipfs') return `${IPFS_VIEW_GATEWAY_URL}/${path}`;
return url;
}
+
+export function normalizeNFTList(list) {
+ return [
+ ...new Map(
+ [...list].map(({ classId, nftId, ...data }) => [
+ classId,
+ { ...data, classId, id: nftId },
+ ])
+ ).values(),
+ ]
+ .filter(({ classId }) => !LIKECOIN_NFT_HIDDEN_ITEMS.has(classId))
+ .sort((a, b) => {
+ if (a.id && b.id) {
+ const aIsWritingNFT = checkIsWritingNFTByNFTId(a.id);
+ const bIsWritingNFT = checkIsWritingNFTByNFTId(b.id);
+ if (aIsWritingNFT && !bIsWritingNFT) return -1;
+ if (!aIsWritingNFT && bIsWritingNFT) return 1;
+ }
+ return b.timestamp - a.timestamp;
+ });
+}