Skip to content

Commit

Permalink
fix: change contractType type to string
Browse files Browse the repository at this point in the history
  • Loading branch information
ErnoW committed Oct 14, 2022
1 parent b0a9a9e commit d87f37c
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 58 deletions.
6 changes: 6 additions & 0 deletions .changeset/two-sloths-remember.md
Original file line number Diff line number Diff line change
@@ -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
11 changes: 2 additions & 9 deletions packages/evmApi/src/resolvers/nft/getNFTContractMetadata.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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 => ({
Expand Down
3 changes: 1 addition & 2 deletions packages/evmUtils/src/dataTypes/EvmNft/EvmNft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down Expand Up @@ -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),
Expand Down
3 changes: 1 addition & 2 deletions packages/evmUtils/src/dataTypes/EvmNft/types.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -51,7 +50,7 @@ export interface EvmNftInput {
*/
export interface EvmNftData {
tokenId: number | string;
contractType?: EvmNftContractType;
contractType?: string;
chain: EvmChain;
tokenUri?: string;
tokenAddress: EvmAddress;
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

/**
Expand Down Expand Up @@ -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),
});

/**
Expand Down
3 changes: 1 addition & 2 deletions packages/evmUtils/src/dataTypes/EvmNftCollection/types.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -28,7 +27,7 @@ export interface EvmNftCollectionInput {
*/
export interface EvmNftCollectionData {
chain: EvmChain;
contractType?: EvmNftContractType;
contractType?: string;
name: string;
symbol: string;
tokenAddress: EvmAddress;
Expand Down
17 changes: 0 additions & 17 deletions packages/evmUtils/src/dataTypes/EvmNftContractType.test.ts

This file was deleted.

20 changes: 0 additions & 20 deletions packages/evmUtils/src/dataTypes/EvmNftContractType.ts

This file was deleted.

5 changes: 2 additions & 3 deletions packages/evmUtils/src/dataTypes/EvmNftMetadata/types.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -22,7 +21,7 @@ export interface EvmNftMetadataInput {
tokenAddress: EvmAddressish;
name: string;
symbol: string;
contractType?: EvmNftContractType;
contractType?: string;
syncedAt: DateInput | null;
}

Expand All @@ -34,6 +33,6 @@ export interface EvmNftMetadataData {
tokenAddress: EvmAddress;
name: string;
symbol: string;
contractType?: EvmNftContractType;
contractType?: string;
syncedAt?: Date;
}
1 change: 0 additions & 1 deletion packages/evmUtils/src/dataTypes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit d87f37c

Please sign in to comment.