From 0c62a75ee697f62a41acdc4055dac31ed2014af9 Mon Sep 17 00:00:00 2001 From: rlajous Date: Wed, 20 Sep 2023 12:29:30 +0200 Subject: [PATCH] Changed variable name --- ...claim_async_poap.ts => mint_async_poap.ts} | 0 .../{claim_sync_poap.ts => mint_sync_poap.ts} | 1 + .../poaps/backend/src/utils/handleError.ts | 9 ++++-- packages/drops/src/DropsClient.ts | 4 +-- packages/drops/src/domain/Drop.ts | 12 ++++---- packages/poaps/src/PoapsClient.ts | 29 ++++++++++++++----- packages/poaps/src/index.ts | 1 + packages/poaps/src/types/index.ts | 1 + packages/poaps/src/types/response.ts | 18 ++++++++++++ .../src/core/PoapCompass/PoapCompass.ts | 2 +- .../src/core/PoapTokenApi/PoapTokenApi.ts | 8 ++--- .../TokensApiProvider/TokensApiProvider.ts | 4 +-- .../ports/TokensApiProvider/Types/response.ts | 2 +- 13 files changed, 65 insertions(+), 26 deletions(-) rename examples/poaps/backend/src/methods/{claim_async_poap.ts => mint_async_poap.ts} (100%) rename examples/poaps/backend/src/methods/{claim_sync_poap.ts => mint_sync_poap.ts} (93%) create mode 100644 packages/poaps/src/types/response.ts diff --git a/examples/poaps/backend/src/methods/claim_async_poap.ts b/examples/poaps/backend/src/methods/mint_async_poap.ts similarity index 100% rename from examples/poaps/backend/src/methods/claim_async_poap.ts rename to examples/poaps/backend/src/methods/mint_async_poap.ts diff --git a/examples/poaps/backend/src/methods/claim_sync_poap.ts b/examples/poaps/backend/src/methods/mint_sync_poap.ts similarity index 93% rename from examples/poaps/backend/src/methods/claim_sync_poap.ts rename to examples/poaps/backend/src/methods/mint_sync_poap.ts index 8decac76..4a5dbf1d 100644 --- a/examples/poaps/backend/src/methods/claim_sync_poap.ts +++ b/examples/poaps/backend/src/methods/mint_sync_poap.ts @@ -10,5 +10,6 @@ export const mint_sync_poap = async (client: PoapsClient): Promise => { console.log(data); } catch (error) { handleError(error); + console.error(error); } }; diff --git a/examples/poaps/backend/src/utils/handleError.ts b/examples/poaps/backend/src/utils/handleError.ts index 48534161..3222c06c 100644 --- a/examples/poaps/backend/src/utils/handleError.ts +++ b/examples/poaps/backend/src/utils/handleError.ts @@ -1,5 +1,5 @@ import { - CodeAlreadyClaimedError, + CodeAlreadyMintedError, CodeExpiredError, FinishedWithError, } from '@poap-xyz/poaps'; @@ -8,7 +8,7 @@ import { * Handles specific POAP-related errors by logging them. * * Errors handled: - * - CodeAlreadyClaimedError: Thrown when a POAP mint code has already been minted. + * - CodeAlreadyMintedError: Thrown when a POAP mint code has already been minted. * - CodeExpiredError: Thrown when a POAP mint code has expired and is no longer valid for minting. * - FinishedWithError: Thrown when the POAP mint process completes but encounters an error. * @@ -18,7 +18,7 @@ export const handleError = (error: unknown): void => { if ( // Checks if the error is an instance of CodeAlreadyClaimedError. // This error occurs when a user attempts to mint a POAP that has already been minted by someone else. - error instanceof CodeAlreadyClaimedError || + error instanceof CodeAlreadyMintedError || // Checks if the error is an instance of CodeExpiredError. // This error is thrown when the mint code for a POAP has expired. error instanceof CodeExpiredError || @@ -28,5 +28,8 @@ export const handleError = (error: unknown): void => { ) { // Logs the specific error message. console.error(error); + } else { + // Logs the generic error message. + console.error('An unexpected error occurred:', error); } }; diff --git a/packages/drops/src/DropsClient.ts b/packages/drops/src/DropsClient.ts index d49be8d5..b2ea3844 100644 --- a/packages/drops/src/DropsClient.ts +++ b/packages/drops/src/DropsClient.ts @@ -98,7 +98,7 @@ export class DropsClient { transferCount: drop.stats_by_chain_aggregate.aggregate.sum ? Number(drop.stats_by_chain_aggregate.aggregate.sum.transfer_count) : 0, - emailReservation: drop.email_claims_stats + emailReservationCount: drop.email_claims_stats ? Number(drop.email_claims_stats.total) : 0, expiryDate: new Date(drop.expiry_date), @@ -192,7 +192,7 @@ export class DropsClient { endDate: new Date(drop.end_date), transferCount: 0, poapCount: 0, - emailReservation: 0, + emailReservationCount: 0, }); } } diff --git a/packages/drops/src/domain/Drop.ts b/packages/drops/src/domain/Drop.ts index d325922e..0129130b 100644 --- a/packages/drops/src/domain/Drop.ts +++ b/packages/drops/src/domain/Drop.ts @@ -21,7 +21,7 @@ export class Drop { endDate: Date; poapCount: number; transferCount: number; - emailReservation: number; + emailReservationCount: number; constructor(properties: DropProperties) { this.id = properties.id; @@ -43,13 +43,13 @@ export class Drop { this.createdDate = properties.createdDate; this.poapCount = properties.poapCount; this.transferCount = properties.transferCount; - this.emailReservation = properties.emailReservation; + this.emailReservationCount = properties.emailReservationCount; this.expiryDate = properties.expiryDate; this.endDate = properties.endDate; } public getTotalMinted(): number { - return this.poapCount + this.emailReservation; + return this.poapCount + this.emailReservationCount; } public toSerializableObject(): SerializableDrop { @@ -73,7 +73,7 @@ export class Drop { createdDate: this.createdDate.toISOString(), poapCount: this.poapCount, transferCount: this.transferCount, - emailReservation: this.emailReservation, + emailReservationCount: this.emailReservationCount, expiryDate: this.expiryDate.toISOString(), endDate: this.endDate.toISOString(), }; @@ -100,7 +100,7 @@ export interface SerializableDrop { createdDate: string; // ISO String representation of Date poapCount: number; transferCount: number; - emailReservation: number; + emailReservationCount: number; expiryDate: string; // ISO String representation of Date endDate: string; // ISO String representation of Date } @@ -127,5 +127,5 @@ export interface DropProperties { endDate: Date; poapCount: number; transferCount: number; - emailReservation: number; + emailReservationCount: number; } diff --git a/packages/poaps/src/PoapsClient.ts b/packages/poaps/src/PoapsClient.ts index 523a3207..c924d53a 100644 --- a/packages/poaps/src/PoapsClient.ts +++ b/packages/poaps/src/PoapsClient.ts @@ -1,8 +1,4 @@ -import { - CompassProvider, - TokensApiProvider, - GetMintCodeResponse, -} from '@poap-xyz/providers'; +import { CompassProvider, TokensApiProvider } from '@poap-xyz/providers'; import { POAP } from './domain/Poap'; import { POAPReservation } from './domain/POAPReservation'; import { PaginatedPoapsResponse, PAGINATED_POAPS_QUERY } from './queries'; @@ -25,6 +21,7 @@ import { CodeAlreadyMintedError } from './errors/CodeAlreadyMintedError'; import { CodeExpiredError } from './errors/CodeExpiredError'; import { MintChecker } from './utils/MintChecker'; import { PoapIndexed } from './utils/PoapIndexed'; +import { GetMintCodeResponse } from './types/response'; /** * Represents a client for interacting with POAPs (Proof of Attendance Protocol tokens). @@ -123,7 +120,7 @@ export class PoapsClient { if (getCodeResponse.claimed == true) { throw new CodeAlreadyMintedError(mintCode); } - if (getCodeResponse.is_active == false) { + if (getCodeResponse.isActive == false) { throw new CodeExpiredError(mintCode); } @@ -137,7 +134,25 @@ export class PoapsClient { * @returns {Promise} The mint code details. */ async getMintCode(mintCode: string): Promise { - return await this.tokensApiProvider.getMintCode(mintCode); + const getMintCodeRaw = await this.tokensApiProvider.getMintCode(mintCode); + return { + id: getMintCodeRaw.id, + qrHash: getMintCodeRaw.qr_hash, + txHash: getMintCodeRaw.tx_hash, + eventId: getMintCodeRaw.event_id, + beneficiary: getMintCodeRaw.beneficiary, + userInput: getMintCodeRaw.user_input, + signer: getMintCodeRaw.signer, + claimed: getMintCodeRaw.claimed, + claimedDate: getMintCodeRaw.claimed_date, + createdDate: getMintCodeRaw.created_date, + isActive: getMintCodeRaw.is_active, + secret: getMintCodeRaw.secret, + txStatus: getMintCodeRaw.tx_status, + result: { + token: getMintCodeRaw.result.token, + }, + }; } /** diff --git a/packages/poaps/src/index.ts b/packages/poaps/src/index.ts index 89ecf962..56dd7938 100644 --- a/packages/poaps/src/index.ts +++ b/packages/poaps/src/index.ts @@ -1,4 +1,5 @@ export { PoapsSortFields, FetchPoapsInput } from './types/input'; +export { GetMintCodeResponse } from './types/response'; export { PoapsClient } from './PoapsClient'; export { POAP } from './domain/Poap'; export { POAPReservation } from './domain/POAPReservation'; diff --git a/packages/poaps/src/types/index.ts b/packages/poaps/src/types/index.ts index e3365cb9..eccece42 100644 --- a/packages/poaps/src/types/index.ts +++ b/packages/poaps/src/types/index.ts @@ -1 +1,2 @@ export * from './input'; +export * from './response'; diff --git a/packages/poaps/src/types/response.ts b/packages/poaps/src/types/response.ts new file mode 100644 index 00000000..0ecb6a22 --- /dev/null +++ b/packages/poaps/src/types/response.ts @@ -0,0 +1,18 @@ +export interface GetMintCodeResponse { + id: number; + qrHash: string; + txHash: string; + eventId: number; + beneficiary: string; + userInput: string; + signer: string; + claimed: boolean; + claimedDate: string; + createdDate: string; + isActive: boolean; + secret: string; + txStatus: string; + result: { + token: number; + }; +} diff --git a/packages/providers/src/core/PoapCompass/PoapCompass.ts b/packages/providers/src/core/PoapCompass/PoapCompass.ts index 0743ab20..6a2305d4 100644 --- a/packages/providers/src/core/PoapCompass/PoapCompass.ts +++ b/packages/providers/src/core/PoapCompass/PoapCompass.ts @@ -4,7 +4,7 @@ import { CompassProvider } from '../../ports/CompassProvider/CompassProvider'; import axios from 'axios'; // TODO: Change variable type any to a more specific type -const DEFAULT_COMPASS_BASE_URL = 'https://compass.poap.tech/v1/graphql'; +const DEFAULT_COMPASS_BASE_URL = 'https://public.compass.poap.tech/v1/graphql'; /** * A class that implements the `CompassProvider` interface for fetching data from the Poap API. diff --git a/packages/providers/src/core/PoapTokenApi/PoapTokenApi.ts b/packages/providers/src/core/PoapTokenApi/PoapTokenApi.ts index fe4c8439..81629f1f 100644 --- a/packages/providers/src/core/PoapTokenApi/PoapTokenApi.ts +++ b/packages/providers/src/core/PoapTokenApi/PoapTokenApi.ts @@ -3,7 +3,7 @@ import { MissingAuthenticationProviderError } from './../../ports/Authentication import { PostMintCodeResponse, MintStatusResponse, - GetMintCodeResponse, + GetMintCodeResponseRaw, } from './../../ports/TokensApiProvider/Types/response'; import { MintCodeInput } from './../../ports/TokensApiProvider/Types/input'; import { AuthenticationProvider } from './../../ports/AuthenticationProvider/AuthenticationProvider'; @@ -50,10 +50,10 @@ export class PoapTokenApi implements TokensApiProvider { * Retrieves the mint code details. * * @param {string} code - The unique QR hash for the mint. - * @returns {Promise} Details of the mint code. + * @returns {Promise} Details of the mint code. */ - async getMintCode(code: string): Promise { - return await this.secureFetch( + async getMintCode(code: string): Promise { + return await this.secureFetch( `${this.baseUrl}/actions/claim-qr?qr_hash=${code}`, { method: 'GET', diff --git a/packages/providers/src/ports/TokensApiProvider/TokensApiProvider.ts b/packages/providers/src/ports/TokensApiProvider/TokensApiProvider.ts index 25605fcb..0f44e727 100644 --- a/packages/providers/src/ports/TokensApiProvider/TokensApiProvider.ts +++ b/packages/providers/src/ports/TokensApiProvider/TokensApiProvider.ts @@ -1,5 +1,5 @@ import { - GetMintCodeResponse, + GetMintCodeResponseRaw, PostMintCodeResponse, MintCodeInput, MintStatusResponse, @@ -11,7 +11,7 @@ import { * @interface TokensApiProvider */ export interface TokensApiProvider { - getMintCode(code: string): Promise; + getMintCode(code: string): Promise; postMintCode(input: MintCodeInput): Promise; mintStatus(uid: string): Promise; } diff --git a/packages/providers/src/ports/TokensApiProvider/Types/response.ts b/packages/providers/src/ports/TokensApiProvider/Types/response.ts index 5e3ddbb8..0255e3d7 100644 --- a/packages/providers/src/ports/TokensApiProvider/Types/response.ts +++ b/packages/providers/src/ports/TokensApiProvider/Types/response.ts @@ -1,6 +1,6 @@ import { MintingStatus } from '@poap-xyz/utils'; -export interface GetMintCodeResponse { +export interface GetMintCodeResponseRaw { id: number; qr_hash: string; tx_hash: string;