Skip to content

Commit

Permalink
update types
Browse files Browse the repository at this point in the history
  • Loading branch information
KidSysco committed Dec 23, 2024
1 parent b317f76 commit b7f5781
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 17 deletions.
54 changes: 42 additions & 12 deletions src/stores/nftStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,53 @@ export const useNftStore = defineStore('nftStore', {
// NFT Meta Data Attributes

/**
* Gets a large version of the image if specified, otherwise the default NFT image.
* This is a safe, and efficient way to call for images.
* @returns An image URL.
* Converts an imgur original image to a smaller image.
* @returns
*/
getImageLarge: () => {
return (metaData) => {
return metaDataAttributeValueOrImage(metaData, 'url-large');
getImageMedium: () => {
return (url) => {
try {
const lastDotIndex = url.lastIndexOf('.');

// If there's no extension, just add "m" to the file name
if (lastDotIndex === -1) {
return url + 'm';
}

// Split the name and extension
const namePart = url.substring(0, lastDotIndex);
const extensionPart = url.substring(lastDotIndex);

// Add "m" to the name part, keep the extension as is
return `${namePart}m${extensionPart}`;
} catch (error) {
return url;
}
};
},
/**
* Gets a medium version of the image if specified, otherwise the default NFT image.
* This is a safe, and efficient way to call for images.
* @returns An image URL.
* Converts an imgur original image to a large image. Still smaller than the original.
* @returns
*/
getImageMedium: () => {
return (metaData) => {
return metaDataAttributeValueOrImage(metaData, 'url-medium');
getImageLarge: () => {
return (url) => {
try {
const lastDotIndex = url.lastIndexOf('.');

// If there's no extension, just add "l" to the file name
if (lastDotIndex === -1) {
return url + 'l';
}

// Split the name and extension
const namePart = url.substring(0, lastDotIndex);
const extensionPart = url.substring(lastDotIndex);

// Add "l" to the name part, keep the extension as is
return `${namePart}l${extensionPart}`;
} catch (error) {
return url;
}
};
},
/**
Expand Down
13 changes: 8 additions & 5 deletions src/types/useNftStore.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,20 @@ export interface NftStoreGetters {
/**
* Gets the URL for an NFT based on its token ID and path.
*/
getNftUrl: (tokenId: string | number, path: string) => string;
getNftUrl: (
tokenId: string | number,
path: string
) => (tokenId: string | number, path: string) => string;

/**
* Gets a large image URL for an NFT if available, otherwise the default NFT image.
* Appends an 'l' to the end of an image to get the large version from imgurl.
*/
getImageLarge: (metaData: NftMetaData) => string;
getImageLarge: (url: string) => (url: string) => string;

/**
* Gets a medium image URL for an NFT if available, otherwise the default NFT image.
* Appends an 'm' to the end of an image to get the large version from imgurl.
*/
getImageMedium: (metaData: NftMetaData) => string;
getImageMedium: (url: string) => (url: string) => string;

/**
* Gets a public attribute value from the NFT metadata.
Expand Down

0 comments on commit b7f5781

Please sign in to comment.