-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into chore/remove-evm-gas-price-poll
- Loading branch information
Showing
16 changed files
with
171 additions
and
34 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
42 changes: 21 additions & 21 deletions
42
packages/desktop/views/dashboard/collectibles/views/CollectionsGalleryView.svelte
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
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
10 changes: 10 additions & 0 deletions
10
packages/shared/src/lib/core/nfts/interfaces/collection.interface.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,10 @@ | ||
import { NftStandard } from '../enums' | ||
import { Nft } from './nft.interface' | ||
|
||
export interface Collection { | ||
standard: NftStandard | ||
name: string | ||
type: string | ||
uri: string | ||
nfts: Nft[] | ||
} |
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
58 changes: 58 additions & 0 deletions
58
packages/shared/src/lib/core/nfts/stores/selected-account-collections.store.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,58 @@ | ||
import { derived, get, Readable, Writable, writable } from 'svelte/store' | ||
import { selectedAccountNfts } from './selected-account-nfts.store' | ||
import { NftStandard } from '../enums' | ||
import { Nft } from '../interfaces' | ||
import { getCollectionFromNft } from '../utils' | ||
import { Collections } from '../types' | ||
|
||
export const collectionsStore: Writable<Collections> = writable({}) | ||
|
||
async function updateCollections(nfts: Nft[]): Promise<void> { | ||
const existingCollections = get(collectionsStore) | ||
|
||
if (nfts.length === 0) { | ||
if (Object.keys(existingCollections).length > 0) { | ||
collectionsStore.set({}) | ||
} | ||
return | ||
} | ||
|
||
const collectionsUpdate = { ...existingCollections } | ||
|
||
await Promise.all( | ||
nfts.map(async (nft) => { | ||
if (nft.standard !== NftStandard.Irc27 || !nft.issuer) { | ||
return | ||
} | ||
|
||
const issuerId = nft.issuer.aliasId ?? nft.issuer.nftId | ||
if (!issuerId) { | ||
return | ||
} | ||
|
||
if (!collectionsUpdate[issuerId]) { | ||
const collection = await getCollectionFromNft(nft) | ||
if (collection) { | ||
collectionsUpdate[issuerId] = { ...collection, nfts: [nft] } | ||
} | ||
} else { | ||
const existingNfts = collectionsUpdate[issuerId].nfts | ||
if (!existingNfts.find((existingNft) => existingNft.id === nft.id)) { | ||
collectionsUpdate[issuerId].nfts.push(nft) | ||
} | ||
} | ||
}) | ||
) | ||
collectionsStore.set(collectionsUpdate) | ||
} | ||
|
||
selectedAccountNfts.subscribe((nfts) => { | ||
void updateCollections(nfts) | ||
}) | ||
|
||
export const selectedAccountCollections: Readable<Collections> = derived( | ||
collectionsStore, | ||
($collectionsStore) => $collectionsStore | ||
) | ||
|
||
export const collectionsSearchTerm: Writable<string> = writable('') |
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,3 @@ | ||
import { Collection } from '../interfaces' | ||
|
||
export type Collections = { [key: string]: Collection } |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './collections.type' | ||
export * from './nft-download-options.type' | ||
export * from './persisted-nft.type' |
42 changes: 42 additions & 0 deletions
42
packages/shared/src/lib/core/nfts/utils/getCollectionFromNft.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,42 @@ | ||
import { NftStandard } from '../enums' | ||
import { Collection, Nft } from '../interfaces' | ||
import { Converter } from '@core/utils' | ||
import { getClient } from '@core/profile-manager' | ||
import type { AliasOutput, MetadataFeature, NftOutput } from '@iota/sdk' | ||
import { FeatureType } from '@iota/sdk/out/types' | ||
|
||
export async function getCollectionFromNft(nft: Nft): Promise<Collection | undefined> { | ||
if (nft.standard !== NftStandard.Irc27) { | ||
return | ||
} | ||
|
||
const { aliasId = '', nftId = '' } = nft.issuer ?? {} | ||
if (!aliasId && !nftId) { | ||
return | ||
} | ||
|
||
try { | ||
const client = await getClient() | ||
const outputId = aliasId ? await client.aliasOutputId(aliasId) : await client.nftOutputId(nftId) | ||
if (!outputId) { | ||
return | ||
} | ||
|
||
const outputResponse = await client.getOutput(outputId) | ||
const output = outputResponse.output as AliasOutput | NftOutput | ||
|
||
const metadataFeature = output.immutableFeatures?.find( | ||
(feature) => feature.type === FeatureType.Metadata | ||
) as MetadataFeature | ||
|
||
if (!metadataFeature?.data) { | ||
return | ||
} | ||
|
||
const { standard, name, type, uri } = JSON.parse(Converter.hexToUtf8(metadataFeature.data)) | ||
|
||
return { standard, name, type, uri, nfts: [] } | ||
} catch (error) { | ||
console.error('Error retrieving collection from NFT:', error) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,17 +1,19 @@ | ||
export * from './buildNftFromPersistedErc721Nft' | ||
export * from './buildPersistedErc721Nft' | ||
export * from './checkIfNftShouldBeDownloaded' | ||
export * from './fetchWithTimeout' | ||
export * from './getCollectionFromNft' | ||
export * from './getFetchableNftUrls' | ||
export * from './getFilePathForNft' | ||
export * from './getNftsFromNftIds' | ||
export * from './getOwnerOfErc721Nft' | ||
export * from './buildPersistedErc721Nft' | ||
export * from './getFetchableNftUrls' | ||
export * from './getPrimaryNftUrl' | ||
export * from './getSpendableStatusFromUnspentNftOutput' | ||
export * from './fetchWithTimeout' | ||
export * from './isIrc27Nft' | ||
export * from './isNftOwnedByAnyAccount' | ||
export * from './isNftLocked' | ||
export * from './isNftOwnedByAnyAccount' | ||
export * from './isScamIrc27Nft' | ||
export * from './isValidNftUri' | ||
export * from './isVisibleCollection' | ||
export * from './isVisibleNft' | ||
export * from './parseNftMetadata' |
20 changes: 20 additions & 0 deletions
20
packages/shared/src/lib/core/nfts/utils/isVisibleCollection.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,20 @@ | ||
import { get } from 'svelte/store' | ||
import { collectionsSearchTerm } from '../stores' | ||
import { Collection } from '../interfaces' | ||
|
||
export function isVisibleCollection(collection: Collection): boolean { | ||
const searchTerm = get(collectionsSearchTerm) | ||
|
||
if (!isVisibleWithSearchTerm(collection, searchTerm)) { | ||
return false | ||
} | ||
|
||
return true | ||
} | ||
|
||
function isVisibleWithSearchTerm(collection: Collection, searchTerm: string): boolean { | ||
if (searchTerm) { | ||
return collection.name.toLowerCase().includes(searchTerm.toLowerCase()) | ||
} | ||
return true | ||
} |