From d87f37c5a56d5db5ca79ede9bb463d6ad20a13ab Mon Sep 17 00:00:00 2001 From: Erno Date: Fri, 14 Oct 2022 10:16:58 +0200 Subject: [PATCH] fix: change contractType type to string --- .changeset/two-sloths-remember.md | 6 ++++++ .../resolvers/nft/getNFTContractMetadata.ts | 11 ++-------- .../evmUtils/src/dataTypes/EvmNft/EvmNft.ts | 3 +-- .../evmUtils/src/dataTypes/EvmNft/types.ts | 3 +-- .../EvmNftCollection/EvmNftCollection.ts | 3 +-- .../src/dataTypes/EvmNftCollection/types.ts | 3 +-- .../src/dataTypes/EvmNftContractType.test.ts | 17 ---------------- .../src/dataTypes/EvmNftContractType.ts | 20 ------------------- .../src/dataTypes/EvmNftMetadata/types.ts | 5 ++--- packages/evmUtils/src/dataTypes/index.ts | 1 - 10 files changed, 14 insertions(+), 58 deletions(-) create mode 100644 .changeset/two-sloths-remember.md delete mode 100644 packages/evmUtils/src/dataTypes/EvmNftContractType.test.ts delete mode 100644 packages/evmUtils/src/dataTypes/EvmNftContractType.ts diff --git a/.changeset/two-sloths-remember.md b/.changeset/two-sloths-remember.md new file mode 100644 index 0000000000..51e1b33564 --- /dev/null +++ b/.changeset/two-sloths-remember.md @@ -0,0 +1,6 @@ +--- +'@moralisweb3/evm-api': patch +'@moralisweb3/evm-utils': patch +--- + +Due to inconsistencies in the api regarding `contractType` on NFT datatypes, we have removed the tight validation check. This means that the type is not 'ERC721' | 'ERC1155' anymore, but a string. This allows other contractTypes to be parsed without throwing errors diff --git a/packages/evmApi/src/resolvers/nft/getNFTContractMetadata.ts b/packages/evmApi/src/resolvers/nft/getNFTContractMetadata.ts index 0556605203..46d5a48650 100644 --- a/packages/evmApi/src/resolvers/nft/getNFTContractMetadata.ts +++ b/packages/evmApi/src/resolvers/nft/getNFTContractMetadata.ts @@ -1,13 +1,6 @@ import { createEndpoint, createEndpointFactory } from '@moralisweb3/api-utils'; import { maybe, toCamelCase } from '@moralisweb3/core'; -import { - EvmAddress, - EvmAddressish, - EvmChain, - EvmChainish, - EvmNftMetadata, - normalizeEvmNftContractType, -} from '@moralisweb3/evm-utils'; +import { EvmAddress, EvmAddressish, EvmChain, EvmChainish, EvmNftMetadata } from '@moralisweb3/evm-utils'; import { operations } from '../../generated/types'; import { EvmChainResolver } from '../EvmChainResolver'; @@ -36,7 +29,7 @@ export const getNFTContractMetadata = createEndpointFactory((core) => chain: EvmChainResolver.resolve(params.chain, core), tokenAddress: EvmAddress.create(data.token_address, core), syncedAt: data.synced_at ? new Date(data.synced_at) : null, - contractType: maybe(data.contract_type, normalizeEvmNftContractType), + contractType: maybe(data.contract_type), }), resultToJson: (data) => data.toJSON(), parseParams: (params: Params): ApiParams => ({ diff --git a/packages/evmUtils/src/dataTypes/EvmNft/EvmNft.ts b/packages/evmUtils/src/dataTypes/EvmNft/EvmNft.ts index 4b43fdc7a7..531a2c24ed 100644 --- a/packages/evmUtils/src/dataTypes/EvmNft/EvmNft.ts +++ b/packages/evmUtils/src/dataTypes/EvmNft/EvmNft.ts @@ -10,7 +10,6 @@ import MoralisCore, { } from '@moralisweb3/core'; import { EvmAddress } from '../EvmAddress'; import { EvmChain } from '../EvmChain'; -import { normalizeEvmNftContractType } from '../EvmNftContractType'; import { EvmNftData, EvmNftInput } from './types'; /** @@ -53,7 +52,7 @@ export class EvmNft implements MoralisDataObject { static parse = (data: EvmNftInput, core: MoralisCore): EvmNftData => ({ ...data, chain: EvmChain.create(data.chain, core), - contractType: maybe(data.contractType, normalizeEvmNftContractType), + contractType: maybe(data.contractType), tokenAddress: EvmAddress.create(data.tokenAddress, core), metadata: maybe(data.metadata, this.validateMetadata), tokenUri: maybe(data.tokenUri), diff --git a/packages/evmUtils/src/dataTypes/EvmNft/types.ts b/packages/evmUtils/src/dataTypes/EvmNft/types.ts index 41e68b5d1d..c6ada8b94c 100644 --- a/packages/evmUtils/src/dataTypes/EvmNft/types.ts +++ b/packages/evmUtils/src/dataTypes/EvmNft/types.ts @@ -1,7 +1,6 @@ import { BigNumber, BigNumberish, DateInput, MoralisDataObjectValue } from '@moralisweb3/core'; import { EvmAddressish, EvmAddress } from '../EvmAddress'; import { EvmChain, EvmChainish } from '../EvmChain'; -import { EvmNftContractType } from '../EvmNftContractType'; /** * This can be any object with valid transaction data. @@ -51,7 +50,7 @@ export interface EvmNftInput { */ export interface EvmNftData { tokenId: number | string; - contractType?: EvmNftContractType; + contractType?: string; chain: EvmChain; tokenUri?: string; tokenAddress: EvmAddress; diff --git a/packages/evmUtils/src/dataTypes/EvmNftCollection/EvmNftCollection.ts b/packages/evmUtils/src/dataTypes/EvmNftCollection/EvmNftCollection.ts index bce69192f1..82da5e13bf 100644 --- a/packages/evmUtils/src/dataTypes/EvmNftCollection/EvmNftCollection.ts +++ b/packages/evmUtils/src/dataTypes/EvmNftCollection/EvmNftCollection.ts @@ -1,7 +1,6 @@ import MoralisCore, { MoralisDataObject, MoralisCoreProvider, maybe } from '@moralisweb3/core'; import { EvmAddress } from '../EvmAddress'; import { EvmChain } from '../EvmChain'; -import { normalizeEvmNftContractType } from '../EvmNftContractType'; import { EvmNftCollectionData, EvmNftCollectionInput } from './types'; /** @@ -39,7 +38,7 @@ export class EvmNftCollection implements MoralisDataObject { ...data, tokenAddress: EvmAddress.create(data.tokenAddress, core), chain: EvmChain.create(data.chain, core), - contractType: maybe(data.contractType, normalizeEvmNftContractType), + contractType: maybe(data.contractType), }); /** diff --git a/packages/evmUtils/src/dataTypes/EvmNftCollection/types.ts b/packages/evmUtils/src/dataTypes/EvmNftCollection/types.ts index 077d152d7e..79c7ec8da6 100644 --- a/packages/evmUtils/src/dataTypes/EvmNftCollection/types.ts +++ b/packages/evmUtils/src/dataTypes/EvmNftCollection/types.ts @@ -1,6 +1,5 @@ import { EvmAddressish, EvmAddress } from '../EvmAddress'; import { EvmChain, EvmChainish } from '../EvmChain'; -import { EvmNftContractType } from '../EvmNftContractType'; /** * This can be any object with valid block data. @@ -28,7 +27,7 @@ export interface EvmNftCollectionInput { */ export interface EvmNftCollectionData { chain: EvmChain; - contractType?: EvmNftContractType; + contractType?: string; name: string; symbol: string; tokenAddress: EvmAddress; diff --git a/packages/evmUtils/src/dataTypes/EvmNftContractType.test.ts b/packages/evmUtils/src/dataTypes/EvmNftContractType.test.ts deleted file mode 100644 index 135d34b7ad..0000000000 --- a/packages/evmUtils/src/dataTypes/EvmNftContractType.test.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { normalizeEvmNftContractType, EvmNftContractType } from './EvmNftContractType'; - -describe('normalizeEvmNftContractType()', () => { - it('returns ERC721', () => { - expect(normalizeEvmNftContractType('erc721')).toEqual(EvmNftContractType.ERC721); - expect(normalizeEvmNftContractType('ERC721')).toEqual(EvmNftContractType.ERC721); - }); - - it('returns ERC1155', () => { - expect(normalizeEvmNftContractType('erc1155')).toEqual(EvmNftContractType.ERC1155); - expect(normalizeEvmNftContractType('ERC1155')).toEqual(EvmNftContractType.ERC1155); - }); - - it('throws error if value is undefined', () => { - expect(() => normalizeEvmNftContractType('wrongErc')).toThrowError('Invalid NFT contract type provided'); - }); -}); diff --git a/packages/evmUtils/src/dataTypes/EvmNftContractType.ts b/packages/evmUtils/src/dataTypes/EvmNftContractType.ts deleted file mode 100644 index be8618d93a..0000000000 --- a/packages/evmUtils/src/dataTypes/EvmNftContractType.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { CoreErrorCode, MoralisCoreError } from '@moralisweb3/core'; - -export enum EvmNftContractType { - ERC721 = 'ERC721', - ERC1155 = 'ERC1155', -} - -export function normalizeEvmNftContractType(value: string): EvmNftContractType { - switch (value.toUpperCase()) { - case EvmNftContractType.ERC1155: - return EvmNftContractType.ERC1155; - case EvmNftContractType.ERC721: - return EvmNftContractType.ERC721; - } - - throw new MoralisCoreError({ - code: CoreErrorCode.INVALID_ARGUMENT, - message: `Invalid NFT contract type provided: ${value}`, - }); -} diff --git a/packages/evmUtils/src/dataTypes/EvmNftMetadata/types.ts b/packages/evmUtils/src/dataTypes/EvmNftMetadata/types.ts index c86506b792..d8ff1c9e38 100644 --- a/packages/evmUtils/src/dataTypes/EvmNftMetadata/types.ts +++ b/packages/evmUtils/src/dataTypes/EvmNftMetadata/types.ts @@ -1,7 +1,6 @@ import { DateInput } from '@moralisweb3/core'; import { EvmAddressish, EvmAddress } from '../EvmAddress'; import { EvmChain, EvmChainish } from '../EvmChain'; -import { EvmNftContractType } from '../EvmNftContractType'; /** * Valid ERC20 token input @@ -22,7 +21,7 @@ export interface EvmNftMetadataInput { tokenAddress: EvmAddressish; name: string; symbol: string; - contractType?: EvmNftContractType; + contractType?: string; syncedAt: DateInput | null; } @@ -34,6 +33,6 @@ export interface EvmNftMetadataData { tokenAddress: EvmAddress; name: string; symbol: string; - contractType?: EvmNftContractType; + contractType?: string; syncedAt?: Date; } diff --git a/packages/evmUtils/src/dataTypes/index.ts b/packages/evmUtils/src/dataTypes/index.ts index c37e0226e8..be404e0b73 100644 --- a/packages/evmUtils/src/dataTypes/index.ts +++ b/packages/evmUtils/src/dataTypes/index.ts @@ -8,7 +8,6 @@ export * from './EvmEvent'; export * from './EvmNative'; export * from './EvmNft'; export * from './EvmNftCollection'; -export * from './EvmNftContractType'; export * from './EvmNftMetadata'; export * from './EvmNftTrade'; export * from './EvmNftTransfer';