Skip to content

Commit

Permalink
Changed variable name
Browse files Browse the repository at this point in the history
  • Loading branch information
rlajous committed Sep 20, 2023
1 parent 8fcb475 commit 0c62a75
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ export const mint_sync_poap = async (client: PoapsClient): Promise<void> => {
console.log(data);
} catch (error) {
handleError(error);
console.error(error);
}
};
9 changes: 6 additions & 3 deletions examples/poaps/backend/src/utils/handleError.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
CodeAlreadyClaimedError,
CodeAlreadyMintedError,
CodeExpiredError,
FinishedWithError,
} from '@poap-xyz/poaps';
Expand All @@ -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.
*
Expand All @@ -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 ||
Expand All @@ -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);
}
};
4 changes: 2 additions & 2 deletions packages/drops/src/DropsClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -192,7 +192,7 @@ export class DropsClient {
endDate: new Date(drop.end_date),
transferCount: 0,
poapCount: 0,
emailReservation: 0,
emailReservationCount: 0,
});
}
}
12 changes: 6 additions & 6 deletions packages/drops/src/domain/Drop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class Drop {
endDate: Date;
poapCount: number;
transferCount: number;
emailReservation: number;
emailReservationCount: number;

constructor(properties: DropProperties) {
this.id = properties.id;
Expand All @@ -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 {
Expand All @@ -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(),
};
Expand All @@ -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
}
Expand All @@ -127,5 +127,5 @@ export interface DropProperties {
endDate: Date;
poapCount: number;
transferCount: number;
emailReservation: number;
emailReservationCount: number;
}
29 changes: 22 additions & 7 deletions packages/poaps/src/PoapsClient.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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).
Expand Down Expand Up @@ -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);
}

Expand All @@ -137,7 +134,25 @@ export class PoapsClient {
* @returns {Promise<GetMintCodeResponse>} The mint code details.
*/
async getMintCode(mintCode: string): Promise<GetMintCodeResponse> {
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,
},
};
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/poaps/src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
1 change: 1 addition & 0 deletions packages/poaps/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './input';
export * from './response';
18 changes: 18 additions & 0 deletions packages/poaps/src/types/response.ts
Original file line number Diff line number Diff line change
@@ -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;
};
}
2 changes: 1 addition & 1 deletion packages/providers/src/core/PoapCompass/PoapCompass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions packages/providers/src/core/PoapTokenApi/PoapTokenApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<GetMintCodeResponse>} Details of the mint code.
* @returns {Promise<GetMintCodeResponseRaw>} Details of the mint code.
*/
async getMintCode(code: string): Promise<GetMintCodeResponse> {
return await this.secureFetch<GetMintCodeResponse>(
async getMintCode(code: string): Promise<GetMintCodeResponseRaw> {
return await this.secureFetch<GetMintCodeResponseRaw>(
`${this.baseUrl}/actions/claim-qr?qr_hash=${code}`,
{
method: 'GET',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
GetMintCodeResponse,
GetMintCodeResponseRaw,
PostMintCodeResponse,
MintCodeInput,
MintStatusResponse,
Expand All @@ -11,7 +11,7 @@ import {
* @interface TokensApiProvider
*/
export interface TokensApiProvider {
getMintCode(code: string): Promise<GetMintCodeResponse>;
getMintCode(code: string): Promise<GetMintCodeResponseRaw>;
postMintCode(input: MintCodeInput): Promise<PostMintCodeResponse>;
mintStatus(uid: string): Promise<MintStatusResponse>;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MintingStatus } from '@poap-xyz/utils';

export interface GetMintCodeResponse {
export interface GetMintCodeResponseRaw {
id: number;
qr_hash: string;
tx_hash: string;
Expand Down

0 comments on commit 0c62a75

Please sign in to comment.