From 3aa6dde5767a67239733de833ed41e86239c268f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ignacio=20Nicol=C3=A1s=20Negro=20Caino?= Date: Tue, 19 Mar 2024 11:23:19 -0300 Subject: [PATCH] Remove queue-message, replace it for transactions (#88) * Remove queue-message * Fix tests * Fix multiple errors * Update versions --- .../backend/src/methods/mint_async_poap.ts | 4 +- packages/drops/package.json | 6 +- packages/moments/package.json | 6 +- packages/poaps/package.json | 6 +- packages/poaps/src/PoapsClient.ts | 106 +++++++++--------- packages/poaps/src/utils/MintChecker.ts | 89 ++++++++------- packages/providers/package.json | 4 +- .../src/core/PoapTokenApi/PoapTokenApi.ts | 57 ++++++---- .../TokensApiProvider/TokensApiProvider.ts | 8 +- .../ports/TokensApiProvider/Types/response.ts | 24 ++-- .../src/ports/TokensApiProvider/index.ts | 3 +- packages/providers/src/ports/index.ts | 3 +- packages/providers/test/PoapTokenApi.spec.ts | 73 +++++++++--- packages/utils/package.json | 2 +- packages/utils/src/index.ts | 2 +- ...gStatus.ts => TransactionRequestStatus.ts} | 2 +- yarn.lock | 18 +-- 17 files changed, 238 insertions(+), 175 deletions(-) rename packages/utils/src/types/{mintingStatus.ts => TransactionRequestStatus.ts} (75%) diff --git a/examples/poaps/backend/src/methods/mint_async_poap.ts b/examples/poaps/backend/src/methods/mint_async_poap.ts index d12ee59e..8e9119ed 100644 --- a/examples/poaps/backend/src/methods/mint_async_poap.ts +++ b/examples/poaps/backend/src/methods/mint_async_poap.ts @@ -16,13 +16,13 @@ import { handleError } from '../utils/handleError'; export const mint_async_poap = async (client: PoapsClient): Promise => { try { // Initiate the asynchronous mint process - const queueUid: string = await client.mintAsync({ + await client.mintAsync({ mintCode: 'your_mint_code', address: 'your_address', }); // Wait for the mint's status to transition from 'IN_PROCESS' or 'PENDING' states - await client.waitMintStatus(queueUid, 'your_mint_code'); + await client.waitMintStatus('your_mint_code'); // Wait for the minted POAP to be indexed and fetch the mint code information related to the Mint Code const getMintCodeResponse = await client.waitPoapIndexed('your_mint_code'); diff --git a/packages/drops/package.json b/packages/drops/package.json index bd62bd0e..7a63052e 100644 --- a/packages/drops/package.json +++ b/packages/drops/package.json @@ -1,6 +1,6 @@ { "name": "@poap-xyz/drops", - "version": "0.1.6", + "version": "0.1.7", "description": "Drops module for the poap.js library", "main": "dist/cjs/index.cjs", "module": "dist/esm/index.mjs", @@ -29,7 +29,7 @@ "node": ">=18" }, "dependencies": { - "@poap-xyz/providers": "0.1.6", - "@poap-xyz/utils": "0.1.6" + "@poap-xyz/providers": "0.1.7", + "@poap-xyz/utils": "0.1.7" } } diff --git a/packages/moments/package.json b/packages/moments/package.json index bef27576..0eba6bb6 100644 --- a/packages/moments/package.json +++ b/packages/moments/package.json @@ -1,6 +1,6 @@ { "name": "@poap-xyz/moments", - "version": "0.1.6", + "version": "0.1.7", "description": "Moments module for the poap.js library", "main": "dist/cjs/index.cjs", "module": "dist/esm/index.mjs", @@ -26,8 +26,8 @@ "build": "rollup -c --bundleConfigAsCjs" }, "dependencies": { - "@poap-xyz/providers": "0.1.6", - "@poap-xyz/utils": "0.1.6", + "@poap-xyz/providers": "0.1.7", + "@poap-xyz/utils": "0.1.7", "uuid": "^9.0.0" }, "engines": { diff --git a/packages/poaps/package.json b/packages/poaps/package.json index f11aeba9..a0b91152 100644 --- a/packages/poaps/package.json +++ b/packages/poaps/package.json @@ -1,6 +1,6 @@ { "name": "@poap-xyz/poaps", - "version": "0.1.6", + "version": "0.1.7", "description": "Poaps module for the poap.js library", "main": "dist/cjs/index.cjs", "module": "dist/esm/index.mjs", @@ -26,8 +26,8 @@ "build": "rollup -c --bundleConfigAsCjs" }, "dependencies": { - "@poap-xyz/providers": "0.1.6", - "@poap-xyz/utils": "0.1.6" + "@poap-xyz/providers": "0.1.7", + "@poap-xyz/utils": "0.1.7" }, "engines": { "node": ">=18" diff --git a/packages/poaps/src/PoapsClient.ts b/packages/poaps/src/PoapsClient.ts index 3a633056..df3e40a6 100644 --- a/packages/poaps/src/PoapsClient.ts +++ b/packages/poaps/src/PoapsClient.ts @@ -1,27 +1,30 @@ -import { CompassProvider, TokensApiProvider } from '@poap-xyz/providers'; +import { + CompassProvider, + TokensApiProvider, + Transaction, +} from '@poap-xyz/providers'; import { POAP } from './domain/Poap'; import { POAPReservation } from './domain/POAPReservation'; -import { PaginatedPoapsResponse, PAGINATED_POAPS_QUERY } from './queries'; +import { PAGINATED_POAPS_QUERY, PaginatedPoapsResponse } from './queries'; import { - FetchPoapsInput, EmailReservationInput, + FetchPoapsInput, + PoapMintStatus, WalletMintInput, } from './types'; import { - PaginatedResult, - nextCursor, + creatAddressFilter, createBetweenFilter, - creatEqFilter, createInFilter, + creatEqFilter, createUndefinedOrder, - creatAddressFilter, - MintingStatus, + nextCursor, + PaginatedResult, } from '@poap-xyz/utils'; import { CodeAlreadyMintedError } from './errors/CodeAlreadyMintedError'; import { CodeExpiredError } from './errors/CodeExpiredError'; import { MintChecker } from './utils/MintChecker'; import { PoapIndexed } from './utils/PoapIndexed'; -import { PoapMintStatus } from './types/response'; /** * Represents a client for interacting with POAPs . @@ -106,32 +109,11 @@ export class PoapsClient { ); } - /** - * Retrieves the secret code associated with a POAP code. - * @async - * @param {string} mintCode - The POAP code for which to get the secret. - * @returns {Promise} The associated secret code. - * @throws {CodeAlreadyMintedError} Thrown when the POAP code has already been minted. - * @throws {CodeExpiredError} Thrown when the POAP code is expired. - */ - private async getSecretCode(mintCode: string): Promise { - const getCodeResponse = await this.getMintCode(mintCode); - - if (getCodeResponse.minted == true) { - throw new CodeAlreadyMintedError(mintCode); - } - if (getCodeResponse.isActive == false) { - throw new CodeExpiredError(mintCode); - } - - return getCodeResponse.secretCode; - } - /** * Retrieves mint code details for a specific Mint Code. * @async * @param {string} mintCode - The Mint Code for which to get the mint code. - * @returns {Promise} The mint code details. + * @returns {Promise} The Mint status. */ async getMintCode(mintCode: string): Promise { const getMintCodeRaw = await this.tokensApiProvider.getMintCode(mintCode); @@ -144,25 +126,25 @@ export class PoapsClient { } /** - * Fetches the current status of a mint based on its unique ID. - * @async - * @param {string} queueUid - The unique ID of the mint. - * @returns {Promise} The current status of the mint. + * Gets the Transaction associated with the mint. + * The Transaction could change in case of a bump. + * It returns null if the mint has no transaction associated. + * + * @param {string} qrHash - The qrHash of the mint. + * @returns {Promise | null} The Transaction associated with the mint. Null if no transaction is found. */ - async getMintStatus(queueUid: string): Promise { - const mintStatusResponse = - await this.tokensApiProvider.mintStatus(queueUid); - return mintStatusResponse.status; + public async getMintTransaction(qrHash: string): Promise { + return await this.tokensApiProvider.getMintTransaction(qrHash); } /** - * Awaits until the mint's status changes from 'IN_PROCESS' or 'PENDING'. + * Awaits until we have a final Transaction status for a specific Mint Code. * @async - * @param {string} queueUid - The unique ID of the mint. * @returns {Promise} + * @param mintCode - The Mint Code */ - async waitMintStatus(queueUid: string, mintCode: string): Promise { - const checker = new MintChecker(queueUid, this.tokensApiProvider, mintCode); + public async waitMintStatus(mintCode: string): Promise { + const checker = new MintChecker(this.tokensApiProvider, mintCode); await checker.checkMintStatus(); } @@ -170,9 +152,9 @@ export class PoapsClient { * Awaits until a specific POAP, identified by its Mint Code, is indexed on our database. * @async * @param {string} mintCode - The Mint Code identifying the POAP to be indexed. - * @returns {Promise} Details of the indexed POAP. + * @returns {Promise} - The status of the POAP mint. */ - async waitPoapIndexed(mintCode: string): Promise { + public async waitPoapIndexed(mintCode: string): Promise { const checker = new PoapIndexed(mintCode, this.tokensApiProvider); return await checker.waitPoapIndexed(); } @@ -181,19 +163,16 @@ export class PoapsClient { * Begins an asynchronous mint process and provides a unique queue ID in return. * @async * @param {WalletMintInput} input - Details required for the mint. - * @returns {Promise} A unique queue ID for the initiated mint. */ - async mintAsync(input: WalletMintInput): Promise { + public async mintAsync(input: WalletMintInput): Promise { const secretCode = await this.getSecretCode(input.mintCode); - const response = await this.tokensApiProvider.postMintCode({ + await this.tokensApiProvider.postMintCode({ address: input.address, qr_hash: input.mintCode, secret: secretCode, sendEmail: false, }); - - return response.queue_uid; } /** @@ -206,9 +185,9 @@ export class PoapsClient { * @throws {FinishedWithError} If there's an error concluding the mint process. */ async mintSync(input: WalletMintInput): Promise { - const queueUid = await this.mintAsync(input); + await this.mintAsync(input); - await this.waitMintStatus(queueUid, input.mintCode); + await this.waitMintStatus(input.mintCode); const getCodeResponse = await this.waitPoapIndexed(input.mintCode); @@ -227,7 +206,7 @@ export class PoapsClient { * @param {EmailReservationInput} input - Information for the reservation. * @returns {Promise} The reservation details of the POAP. */ - async emailReservation( + public async emailReservation( input: EmailReservationInput, ): Promise { const secretCode = await this.getSecretCode(input.mintCode); @@ -251,4 +230,25 @@ export class PoapsClient { name: response.event.name, }); } + + /** + * Retrieves the secret code associated with a POAP code. + * @async + * @param {string} mintCode - The POAP code for which to get the secret. + * @returns {Promise} The associated secret code. + * @throws {CodeAlreadyMintedError} Thrown when the POAP code has already been minted. + * @throws {CodeExpiredError} Thrown when the POAP code is expired. + */ + private async getSecretCode(mintCode: string): Promise { + const getCodeResponse = await this.getMintCode(mintCode); + + if (getCodeResponse.minted) { + throw new CodeAlreadyMintedError(mintCode); + } + if (!getCodeResponse.isActive) { + throw new CodeExpiredError(mintCode); + } + + return getCodeResponse.secretCode; + } } diff --git a/packages/poaps/src/utils/MintChecker.ts b/packages/poaps/src/utils/MintChecker.ts index db426e98..075fb093 100644 --- a/packages/poaps/src/utils/MintChecker.ts +++ b/packages/poaps/src/utils/MintChecker.ts @@ -1,5 +1,8 @@ -import { MintingStatus } from '@poap-xyz/utils'; -import { TokensApiProvider, MintStatusResponse } from '@poap-xyz/providers'; +import { + TokensApiProvider, + Transaction, + TransactionStatus, +} from '@poap-xyz/providers'; import { FinishedWithError } from '../errors/FinishedWithError'; import { RetryableTask } from './RetryableTask'; @@ -8,37 +11,56 @@ import { RetryableTask } from './RetryableTask'; * If a mint is still pending or in process, it implements a backoff retry mechanism. */ export class MintChecker extends RetryableTask { - private queueUid: string; private mintCode: string; /** * Constructs a new instance of the MintChecker class. * - * @param {string} queueUid - The unique identifier for the token mint. * @param {string} mintCode - The unique code for the token mint. * @param {TokensApiProvider} tokensApiProvider - The provider to fetch the mint status. */ - constructor( - queueUid: string, - tokensApiProvider: TokensApiProvider, - mintCode: string, - ) { + constructor(tokensApiProvider: TokensApiProvider, mintCode: string) { super(tokensApiProvider); - this.queueUid = queueUid; this.mintCode = mintCode; } + /** + * Checks the current status of a token mint. + * If the mint is still pending or in process, it will retry the check with an increased delay. + * + * @public + * @returns {Promise} A promise that resolves once the status has been checked. + * @throws {FinishedWithError} Throws an error if the minting process finished with an error. + */ + public async checkMintStatus(): Promise { + try { + const transaction = await this.tokensApiProvider.getMintTransaction( + this.mintCode, + ); + + if (this.shouldRetry(transaction)) { + await this.backoffAndRetry(() => this.checkMintStatus()); + } else { + this.handleErrorStatus(transaction, this.mintCode); + } + } catch (e) { + if (e instanceof FinishedWithError) { + throw e; + } + + await this.backoffAndRetry(() => this.checkMintStatus()); + } + } + /** * Determines if a retry should be performed based on the provided minting status. * * @private - * @param {MintingStatus} status - The current minting status. * @returns {boolean} Returns true if a retry should be performed, otherwise false. + * @param transaction - The transaction to check for retry. */ - private shouldRetry(status: MintingStatus): boolean { - return ( - status === MintingStatus.IN_PROCESS || status === MintingStatus.PENDING - ); + private shouldRetry(transaction: Transaction | null): boolean { + return !transaction || transaction.status === TransactionStatus.pending; } /** @@ -46,42 +68,19 @@ export class MintChecker extends RetryableTask { * If the minting process finishes with an error, an exception will be thrown. * * @private - * @param {MintStatusResponse} mintStatusResponse - The response from the mint status check. + * @param {Transaction} transaction - The transaction to check for errors. + * @param mintCode * @throws {FinishedWithError} Throws an error if the minting process finished with an error. */ private handleErrorStatus( - mintStatusResponse: MintStatusResponse, + transaction: Transaction | null, mintCode: string, ): void { - if ( - mintStatusResponse.status === MintingStatus.FINISH_WITH_ERROR && - mintStatusResponse.result?.error - ) { - throw new FinishedWithError(mintStatusResponse.result?.error, mintCode); - } - } - - /** - * Checks the current status of a token mint. - * If the mint is still pending or in process, it will retry the check with an increased delay. - * - * @public - * @returns {Promise} A promise that resolves once the status has been checked. - * @throws {FinishedWithError} Throws an error if the minting process finished with an error. - */ - public async checkMintStatus(): Promise { - try { - const mintStatusResponse = await this.tokensApiProvider.mintStatus( - this.queueUid, + if (transaction?.status === TransactionStatus.failed) { + throw new FinishedWithError( + 'The Transaction associated with this mint failed', + mintCode, ); - - if (this.shouldRetry(mintStatusResponse.status)) { - await this.backoffAndRetry(() => this.checkMintStatus()); - } else { - this.handleErrorStatus(mintStatusResponse, this.mintCode); - } - } catch (e) { - await this.backoffAndRetry(() => this.checkMintStatus()); } } } diff --git a/packages/providers/package.json b/packages/providers/package.json index e198e2c2..a5b1b08b 100644 --- a/packages/providers/package.json +++ b/packages/providers/package.json @@ -1,6 +1,6 @@ { "name": "@poap-xyz/providers", - "version": "0.1.6", + "version": "0.1.7", "description": "Providers module for the poap.js library", "main": "dist/cjs/index.cjs", "module": "dist/esm/index.mjs", @@ -25,7 +25,7 @@ "build": "rollup -c --bundleConfigAsCjs" }, "dependencies": { - "@poap-xyz/utils": "0.1.6", + "@poap-xyz/utils": "0.1.7", "axios": "^1.3.5" }, "devDependencies": { diff --git a/packages/providers/src/core/PoapTokenApi/PoapTokenApi.ts b/packages/providers/src/core/PoapTokenApi/PoapTokenApi.ts index 77dcec01..dec936e4 100644 --- a/packages/providers/src/core/PoapTokenApi/PoapTokenApi.ts +++ b/packages/providers/src/core/PoapTokenApi/PoapTokenApi.ts @@ -1,13 +1,15 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -import { MissingAuthenticationProviderError } from './../../ports/AuthenticationProvider/errors/MissingAuthenticationProviderError'; +import { MissingAuthenticationProviderError } from '../../ports/AuthenticationProvider/errors/MissingAuthenticationProviderError'; import { - PostMintCodeResponse, - MintStatusResponse, + AuthenticationProvider, GetMintCodeResponse, -} from './../../ports/TokensApiProvider/Types/response'; -import { MintCodeInput } from './../../ports/TokensApiProvider/Types/input'; -import { AuthenticationProvider } from './../../ports/AuthenticationProvider/AuthenticationProvider'; -import { TokensApiProvider } from './../../ports/TokensApiProvider/TokensApiProvider'; + MintCodeInput, + PostMintCodeResponse, + TokensApiProvider, +} from '../../ports'; +import { + Transaction, + TransactionStatus, +} from '../../ports/TokensApiProvider/Types'; const DEFAULT_DROP_BASE_URL = 'https://api.poap.tech'; @@ -22,6 +24,7 @@ export class PoapTokenApi implements TokensApiProvider { private apiKey: string; private baseUrl: string; private authenticationProvider?: AuthenticationProvider; + /** * Constructs a new instance of the `PoapTokenApi` class. * @@ -77,19 +80,32 @@ export class PoapTokenApi implements TokensApiProvider { } /** - * Checks the status of a mint by its unique identifier. + * Gets the Transaction associated with the mint. + * The Transaction could change in case of a bump. + * It returns null if the mint has no transaction associated. * - * @param {string} uid - The unique identifier for the mint. - * @returns {Promise} Status details of the mint. + * @param {string} qrHash - The qrHash of the mint. + * @returns {Promise | null} The Transaction associated with the mint. Null if no transaction is found. */ - async mintStatus(uid: string): Promise { - return await this.secureFetch( - `${this.baseUrl}/queue-message/${uid}`, - { - method: 'GET', - headers: {}, - }, - ); + async getMintTransaction(qrHash: string): Promise { + const transactions = await this.secureFetch<{ + total: number; + transactions: Transaction[]; + }>(`${this.baseUrl}/transactions?qr_hash=${qrHash}`, { + method: 'GET', + }); + + if (transactions.total === 0) { + return null; + } + + const status = transactions.transactions[0].status; + + if (status === TransactionStatus.waiting) { + return null; + } + + return transactions.transactions[0]; } /** @@ -101,7 +117,7 @@ export class PoapTokenApi implements TokensApiProvider { * @param {any} options - Configuration options for the HTTP request. * @returns {Promise} A promise that resolves with the parsed API response. */ - private async secureFetch(url: string, options: any): Promise { + private async secureFetch(url: string, options: RequestInit): Promise { const headersWithApiKey = { ...options.headers, 'x-api-key': this.apiKey, @@ -109,6 +125,7 @@ export class PoapTokenApi implements TokensApiProvider { }; const response = await fetch(url, { + ...options, method: options.method, body: options.body, headers: headersWithApiKey, diff --git a/packages/providers/src/ports/TokensApiProvider/TokensApiProvider.ts b/packages/providers/src/ports/TokensApiProvider/TokensApiProvider.ts index 25605fcb..4fe02a99 100644 --- a/packages/providers/src/ports/TokensApiProvider/TokensApiProvider.ts +++ b/packages/providers/src/ports/TokensApiProvider/TokensApiProvider.ts @@ -1,8 +1,8 @@ import { GetMintCodeResponse, - PostMintCodeResponse, MintCodeInput, - MintStatusResponse, + PostMintCodeResponse, + Transaction, } from './Types'; /** @@ -12,6 +12,8 @@ import { */ export interface TokensApiProvider { getMintCode(code: string): Promise; + postMintCode(input: MintCodeInput): Promise; - mintStatus(uid: string): Promise; + + getMintTransaction(qrHash: string): Promise; } diff --git a/packages/providers/src/ports/TokensApiProvider/Types/response.ts b/packages/providers/src/ports/TokensApiProvider/Types/response.ts index f99ce711..2c4137fe 100644 --- a/packages/providers/src/ports/TokensApiProvider/Types/response.ts +++ b/packages/providers/src/ports/TokensApiProvider/Types/response.ts @@ -1,5 +1,3 @@ -import { MintingStatus } from '@poap-xyz/utils'; - export interface GetMintCodeResponse { id: number; qr_hash: string; @@ -35,16 +33,6 @@ export interface PostMintCodeResponse { event: Drop; } -export interface MintStatusResponse { - uid: number; - operation: string; - status: MintingStatus; - result: { - tx_hash: string; - error: string; - } | null; -} - interface Drop { id: number; fancy_id: string; @@ -64,3 +52,15 @@ interface Drop { event_template_id?: number | null; private_event: boolean; } + +export enum TransactionStatus { + pending = 'pending', + passed = 'passed', + failed = 'failed', + waiting = 'waiting_tx', +} + +export interface Transaction { + tx_hash: string; + status: TransactionStatus; +} diff --git a/packages/providers/src/ports/TokensApiProvider/index.ts b/packages/providers/src/ports/TokensApiProvider/index.ts index 350af322..603cab6e 100644 --- a/packages/providers/src/ports/TokensApiProvider/index.ts +++ b/packages/providers/src/ports/TokensApiProvider/index.ts @@ -3,5 +3,6 @@ export { GetMintCodeResponse, PostMintCodeResponse, MintCodeInput, - MintStatusResponse, + Transaction, + TransactionStatus, } from './Types'; diff --git a/packages/providers/src/ports/index.ts b/packages/providers/src/ports/index.ts index 422f5555..dd92612d 100644 --- a/packages/providers/src/ports/index.ts +++ b/packages/providers/src/ports/index.ts @@ -5,7 +5,8 @@ export { GetMintCodeResponse, PostMintCodeResponse, MintCodeInput, - MintStatusResponse, + Transaction, + TransactionStatus, } from './TokensApiProvider'; export { HttpProvider } from './HttpProvider/HttpProvider'; diff --git a/packages/providers/test/PoapTokenApi.spec.ts b/packages/providers/test/PoapTokenApi.spec.ts index 4dc05d42..c98f9664 100644 --- a/packages/providers/test/PoapTokenApi.spec.ts +++ b/packages/providers/test/PoapTokenApi.spec.ts @@ -1,10 +1,10 @@ -import { MintingStatus } from '@poap-xyz/utils'; import { GetMintCodeResponse, MintCodeInput, - MintStatusResponse, PoapTokenApi, PostMintCodeResponse, + Transaction, + TransactionStatus, } from '../src'; import { mock } from 'node:test'; @@ -131,27 +131,70 @@ describe('PoapTokenApi', () => { }); describe('mintStatus', () => { - it('should retrieve the status of a mint by its unique identifier', async () => { - const mockUid = 'mockUid12345'; - const mockResponse: MintStatusResponse = { - uid: 1002, - operation: 'MINT', - status: MintingStatus.FINISH, - result: { - tx_hash: '0xDEF123ABC456', - error: '', - }, + const QR_HASH = 'mockQrHash1'; + + it('should retrieve a Transaction associated with a mint-link when exists', async () => { + //GIVEN + const transaction: Transaction = { + tx_hash: '0xABC123DEF456', + status: TransactionStatus.passed, }; + mock.method(global, 'fetch', () => { + return Promise.resolve({ + ok: true, + json: () => + Promise.resolve({ + total: 1, + transactions: [{ ...transaction }], + }), + }); + }); + + //WHEN + const result = await api.getMintTransaction(QR_HASH); + + //THEN + expect(result).toEqual(transaction); + }); + it('should return null when no Transaction is associated with a mint-link', async () => { + //GIVEN mock.method(global, 'fetch', () => { return Promise.resolve({ ok: true, - json: () => Promise.resolve(mockResponse), + json: () => + Promise.resolve({ + total: 0, + transactions: [], + }), }); }); - const result = await api.mintStatus(mockUid); - expect(result).toEqual(mockResponse); + //WHEN + const result = await api.getMintTransaction(QR_HASH); + + //THEN + expect(result).toBeNull(); + }); + + it('should return null when the Transaction associated with a mint-link is waiting', async () => { + //GIVEN + mock.method(global, 'fetch', () => { + return Promise.resolve({ + ok: true, + json: () => + Promise.resolve({ + total: 1, + transactions: [{ status: TransactionStatus.waiting }], + }), + }); + }); + + //WHEN + const result = await api.getMintTransaction(QR_HASH); + + //THEN + expect(result).toBeNull(); }); }); }); diff --git a/packages/utils/package.json b/packages/utils/package.json index 90d4edfd..61493ab8 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -1,6 +1,6 @@ { "name": "@poap-xyz/utils", - "version": "0.1.6", + "version": "0.1.7", "description": "Utils module for the poap.js library", "type": "module", "main": "dist/cjs/index.cjs", diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index adf3092c..ee3b5313 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -1,4 +1,4 @@ -export { MintingStatus } from './types/mintingStatus'; +export { TransactionRequestStatus } from './types/TransactionRequestStatus'; export { Chain } from './types/chain'; export { Order } from './types/filter'; export { PaginationInput } from './types/input'; diff --git a/packages/utils/src/types/mintingStatus.ts b/packages/utils/src/types/TransactionRequestStatus.ts similarity index 75% rename from packages/utils/src/types/mintingStatus.ts rename to packages/utils/src/types/TransactionRequestStatus.ts index 434ab8d4..2f6f93b9 100644 --- a/packages/utils/src/types/mintingStatus.ts +++ b/packages/utils/src/types/TransactionRequestStatus.ts @@ -1,4 +1,4 @@ -export enum MintingStatus { +export enum TransactionRequestStatus { PENDING = 'PENDING', IN_PROCESS = 'IN_PROCESS', FINISH = 'FINISH', diff --git a/yarn.lock b/yarn.lock index 56fd27f5..0343d02f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -884,8 +884,8 @@ __metadata: version: 0.0.0-use.local resolution: "@poap-xyz/drops@workspace:packages/drops" dependencies: - "@poap-xyz/providers": 0.1.6 - "@poap-xyz/utils": 0.1.6 + "@poap-xyz/providers": 0.1.7 + "@poap-xyz/utils": 0.1.7 languageName: unknown linkType: soft @@ -893,8 +893,8 @@ __metadata: version: 0.0.0-use.local resolution: "@poap-xyz/moments@workspace:packages/moments" dependencies: - "@poap-xyz/providers": 0.1.6 - "@poap-xyz/utils": 0.1.6 + "@poap-xyz/providers": 0.1.7 + "@poap-xyz/utils": 0.1.7 "@types/uuid": ^9.0.2 uuid: ^9.0.0 languageName: unknown @@ -904,22 +904,22 @@ __metadata: version: 0.0.0-use.local resolution: "@poap-xyz/poaps@workspace:packages/poaps" dependencies: - "@poap-xyz/providers": 0.1.6 - "@poap-xyz/utils": 0.1.6 + "@poap-xyz/providers": 0.1.7 + "@poap-xyz/utils": 0.1.7 languageName: unknown linkType: soft -"@poap-xyz/providers@*, @poap-xyz/providers@0.1.6, @poap-xyz/providers@workspace:packages/providers": +"@poap-xyz/providers@*, @poap-xyz/providers@0.1.7, @poap-xyz/providers@workspace:packages/providers": version: 0.0.0-use.local resolution: "@poap-xyz/providers@workspace:packages/providers" dependencies: - "@poap-xyz/utils": 0.1.6 + "@poap-xyz/utils": 0.1.7 axios: ^1.3.5 axios-mock-adapter: ^1.21.4 languageName: unknown linkType: soft -"@poap-xyz/utils@*, @poap-xyz/utils@0.1.6, @poap-xyz/utils@workspace:packages/utils": +"@poap-xyz/utils@*, @poap-xyz/utils@0.1.7, @poap-xyz/utils@workspace:packages/utils": version: 0.0.0-use.local resolution: "@poap-xyz/utils@workspace:packages/utils" languageName: unknown