Skip to content

Commit

Permalink
fix: types in nft/types and adjusting tests for currentOwnerAddres re…
Browse files Browse the repository at this point in the history
…turn in packNftContract
  • Loading branch information
AlexandreG-tech committed Dec 19, 2023
1 parent 920ee0f commit 8683e85
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 43 deletions.
3 changes: 2 additions & 1 deletion libs/nft/thirdweb-organizer/src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type {
PackNftContract_Insert_Input,
} from '@gql/shared/types';
import { defaultLocale } from '@next/i18n';
import { ContractType } from '@nft/types';
import { ThirdwebSDK } from '@thirdweb-dev/sdk';

export async function createEventPassNftContract(
Expand Down Expand Up @@ -127,6 +128,6 @@ export async function getUnopenedNftPackAmount(packId: string) {

export async function getPackSupply(contractAddress: string) {
const sdk = new ThirdwebSDK(env.CHAIN);
const pack = await sdk.getContract(contractAddress, 'pack');
const pack = await sdk.getContract(contractAddress, ContractType.PACK);
return pack.erc1155.totalSupply(0);
}
51 changes: 9 additions & 42 deletions libs/nft/thirdweb-organizer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@ import {
EventPass,
EventPassDelayedRevealed,
} from '@features/back-office/events-types';
import { GetEventPassOrganizerFolderPath } from '@features/pass-common';
import { GetEventPassNftContractNftsQuery } from '@gql/admin/types';
import { EventPassNftContractType_Enum } from '@gql/shared/types';
import {
EventPassNftContractType_Enum,
EventPassNftContract_Insert_Input,
} from '@gql/shared/types';
import { EventPassNft } from '@nft/types';
import {
NFTMetadata as ThirdwebNFTMetadata,
ThirdwebSDK,
TransactionResultWithId,
} from '@thirdweb-dev/sdk';
ContractType,
EventPassNftContractObject,
EventSmallData,
NftsMetadata,
RequiredEventPassNft,
} from '@nft/types';
import { ThirdwebSDK, TransactionResultWithId } from '@thirdweb-dev/sdk';
import * as crypto from 'crypto';
import { Signer, ethers } from 'ethers';
import {
Expand All @@ -28,33 +26,13 @@ import {
updateNftsWithPackId,
} from './action';

type NftsMetadata = ThirdwebNFTMetadata & {
name: string;
};

type EventSmallData = Omit<GetEventPassOrganizerFolderPath, 'eventPassId'> & {
eventSlug: string;
};

type EventPassNftContractObject = Required<
Pick<
EventPassNftContract_Insert_Input,
| 'type'
| 'contractAddress'
| 'eventPassId'
| 'chainId'
| 'eventId'
| 'organizerId'
>
> &
EventPassNftContract_Insert_Input;

interface CommonProps extends EventPass, EventSmallData {
address: string;
chainId: string;
}

type Pack = {
//TODO: change to Pack from hygraph
id: string;
name: string;
image: string;
Expand All @@ -75,10 +53,6 @@ type SaveEventPassContractIntoDbProps = {
object: EventPassNftContractObject;
};

type RequiredEventPassNft = Required<
Pick<EventPassNft, 'contractAddress' | 'tokenId'>
>;

type SavePackContractIntoDbProps = {
chainIdNumber: number;
eventData: {
Expand All @@ -100,15 +74,8 @@ type DeployAndCreatePackProps = {
}[];
};

const CONTRACT_TYPE_NFT_DROP = 'nft-drop';
const CONTRACT_TYPE_PACK = 'pack';
const BASE_URL = 'https://www.offline.live/pass/organizer/';

enum ContractType {
NFT_DROP = CONTRACT_TYPE_NFT_DROP,
PACK = CONTRACT_TYPE_PACK,
}

class CollectionDeploymentError extends Error {
constructor(error: Error) {
super(`Error deploying a collection: ${error.message}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,13 @@ describe('NftCollection', () => {
tokenId: 0,
contractAddress: '0xFakeDelayedReveal',
eventPassId: 'fakeEventPassDelayedRevealId',
currentOwnerAddress: '0xB98bD7C7f656290071E52D1aA617D9cB4467Fd6D',
},
{
tokenId: 1,
contractAddress: '0xFakeDelayedReveal',
eventPassId: 'fakeEventPassDelayedRevealId',
currentOwnerAddress: '0xc0ffee254729296a45a3885639AC7E10F9d54979',
},
],
}),
Expand Down Expand Up @@ -513,11 +515,13 @@ describe('NftCollection', () => {
tokenId: 0,
contractAddress: '0xFakePack',
eventPassId: 'FakePackId',
currentOwnerAddress: null,
},
{
tokenId: 1,
contractAddress: '0xFakePack',
eventPassId: 'FakePackId',
currentOwnerAddress: null,
},
],
}),
Expand Down
36 changes: 36 additions & 0 deletions libs/nft/types/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { GetEventPassOrganizerFolderPath } from '@features/pass-common';
import type {
GetEventPassOrderFromIdQuery,
GetEventPassOrdersFromStripeCheckoutSessionQuery,
Expand All @@ -7,6 +8,8 @@ import type {
EventPassNft as ImportedEventPassNft,
NftTransfer as ImportedNftTransfer,
} from '@gql/shared/types';
import { EventPassNftContract_Insert_Input } from '@gql/shared/types';
import { NFTMetadata as ThirdwebNFTMetadata } from '@thirdweb-dev/sdk';

export type NftTransfer = ImportedNftTransfer;

Expand All @@ -31,3 +34,36 @@ export type EventPassNftAfterMutation = NonNullable<
export type EventPassOrderWithContractData =
GetEventPassOrdersFromStripeCheckoutSessionQuery['eventPassOrder'][0] &
GetEventPassOrderFromIdQuery['eventPassOrder_by_pk'];

export enum ContractType {
NFT_DROP = 'nft-drop',
PACK = 'pack',
}

export type EventSmallData = Omit<
GetEventPassOrganizerFolderPath,
'eventPassId'
> & {
eventSlug: string;
};

export type NftsMetadata = ThirdwebNFTMetadata & {
name: string;
};

export type EventPassNftContractObject = Required<
Pick<
EventPassNftContract_Insert_Input,
| 'type'
| 'contractAddress'
| 'eventPassId'
| 'chainId'
| 'eventId'
| 'organizerId'
>
> &
EventPassNftContract_Insert_Input;

export type RequiredEventPassNft = Required<
Pick<EventPassNft, 'contractAddress' | 'tokenId'>
>;

0 comments on commit 8683e85

Please sign in to comment.