-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
9-nftrarity-summary-section-improvements (#10)
* fix: changed the copy for each file Signed-off-by: michalrozekariane <[email protected]> * feat: processZipFile rebuilded + new media files logic implemented Signed-off-by: michalrozekariane <[email protected]> * feat: rarity inspector set up and adjusted for further calculateRarityFromData Signed-off-by: michalrozekariane <[email protected]> * feat: comments added + array for supported image types Signed-off-by: michalrozekariane <[email protected]> * feat: gallery view implemented + modal children logic added Signed-off-by: michalrozekariane <[email protected]> * feat: add total number of nfts label & loader for dropzone Signed-off-by: michalrozekariane <[email protected]> * fix: cursor pointer added for nft card Signed-off-by: michalrozekariane <[email protected]> * Feat: Add details modal Signed-off-by: Stanislaw Mazowiecki <[email protected]> * Fix: Change copyright title Signed-off-by: Stanislaw Mazowiecki <[email protected]> * fix: NFTDetails children deleted because it was unneeded Signed-off-by: michalrozekariane <[email protected]> * fix: loading state is now properly set to false while we get an error Signed-off-by: michalrozekariane <[email protected]> * feat: add missing copy to loader file Signed-off-by: michalrozekariane <[email protected]> * fix: console log removed Signed-off-by: michalrozekariane <[email protected]> * Fix: Some css fixes Signed-off-by: Stanislaw Mazowiecki <[email protected]> * chore: add rarity field to metadata array Signed-off-by: michalrozekariane <[email protected]> * fix: after review Signed-off-by: michalrozekariane <[email protected]> * Feat: Make itemWrapper only display component Signed-off-by: Stanislaw Mazowiecki <[email protected]> * Fix: Infinite loading fix Signed-off-by: Stanislaw Mazowiecki <[email protected]> * chore: rarity logic for NFTStatsDisplay component Signed-off-by: michalrozekariane <[email protected]> * feat: add NFTStatsDisplay component Signed-off-by: michalrozekariane <[email protected]> * fix: rarityRank fix for nft details modal Signed-off-by: michalrozekariane <[email protected]> * feat: code refactor Signed-off-by: michalrozekariane <[email protected]> * feat: rarity code refactor Signed-off-by: michalrozekariane <[email protected]> * feat: featured attribues cards content redesign Signed-off-by: michalrozekariane <[email protected]> * feat: dictionary changes & small improvements Signed-off-by: michalrozekariane <[email protected]> * feat: charts colors changes Signed-off-by: michalrozekariane <[email protected]> * feat: global scrollbar styles Signed-off-by: michalrozekariane <[email protected]> * fix: dialog scrollbar fixes Signed-off-by: michalrozekariane <[email protected]> * fix: overflow scroll dialog property Signed-off-by: michalrozekariane <[email protected]> --------- Signed-off-by: michalrozekariane <[email protected]> Signed-off-by: Stanislaw Mazowiecki <[email protected]> Co-authored-by: Stanislaw Mazowiecki <[email protected]>
- Loading branch information
1 parent
41ffd53
commit a254339
Showing
15 changed files
with
212 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/components/pages/DropzonePage/findMostAndLeastRareAttribute.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/*- | ||
* | ||
* NFT Rarity Inspector | ||
* | ||
* Copyright (C) 2024 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
import { AttributeOccurrence } from '@/utils/types/attributeOccurrence'; | ||
import { MetadataRow } from '@/utils/types/metadataRow'; | ||
|
||
export const findMostAndLeastRareAttribute = ( | ||
metadata: MetadataRow[], | ||
): { leastRareAttribute: AttributeOccurrence; mostRareAttribute: AttributeOccurrence } => { | ||
const attributeOccurrences: Record<string, number> = {}; | ||
|
||
metadata.forEach((nft) => { | ||
const attributes = nft.metadata['attributes']; | ||
if (Array.isArray(attributes)) { | ||
attributes.forEach((attribute) => { | ||
const key = `${attribute.trait_type}:${attribute.value}`; | ||
attributeOccurrences[key] = (attributeOccurrences[key] || 0) + 1; | ||
}); | ||
} | ||
}); | ||
|
||
let leastRare: AttributeOccurrence | null = null; | ||
let mostRare: AttributeOccurrence | null = null; | ||
|
||
Object.entries(attributeOccurrences).forEach(([key, count]) => { | ||
const [trait, value] = key.split(':'); | ||
if (!leastRare || count > leastRare.occurrence) { | ||
leastRare = { trait, value, occurrence: count }; | ||
} | ||
if (!mostRare || count < mostRare.occurrence) { | ||
mostRare = { trait, value, occurrence: count }; | ||
} | ||
}); | ||
|
||
return { | ||
leastRareAttribute: leastRare || { trait: '', value: '', occurrence: 0 }, | ||
mostRareAttribute: mostRare || { trait: '', value: '', occurrence: 0 }, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/*- | ||
* | ||
* NFT Rarity Inspector | ||
* | ||
* Copyright (C) 2024 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
import { useMemo } from 'react'; | ||
import { MetadataRow } from '@/utils/types/metadataRow'; | ||
import { calculateTraitOccurrenceFromData } from 'hedera-nft-utilities/src/rarity'; | ||
import { findNFTRarity } from '@/components/pages/DropzonePage/findNFTRarity'; | ||
import { findMostAndLeastRareAttribute } from '@/components/pages/DropzonePage/findMostAndLeastRareAttribute'; | ||
import { findNFTsWithAttribute } from '@/components/pages/DropzonePage/findNFTsWithAttribute'; | ||
|
||
export const useNFTRarityData = (metadata: MetadataRow[]) => { | ||
const traitOccurrence = useMemo(() => calculateTraitOccurrenceFromData(metadata.map((m) => m.metadata)), [metadata]); | ||
const mostRareNFT = findNFTRarity(metadata, 'most-rare'); | ||
const leastRareNFT = findNFTRarity(metadata, 'least-rare'); | ||
const { mostRareAttribute, leastRareAttribute } = findMostAndLeastRareAttribute(metadata); | ||
const { nftsWithAttribute: nftsWithLeastRareAttribute, count: countLeastRare } = findNFTsWithAttribute(metadata, leastRareAttribute); | ||
const { nftsWithAttribute: nftsWithMostRareAttribute, count: countMostRare } = findNFTsWithAttribute(metadata, mostRareAttribute); | ||
|
||
return { | ||
traitOccurrence, | ||
mostRareNFT, | ||
leastRareNFT, | ||
mostRareAttribute, | ||
leastRareAttribute, | ||
nftsWithLeastRareAttribute, | ||
nftsWithMostRareAttribute, | ||
countLeastRare, | ||
countMostRare, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.