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 19, 2023
1 parent ceae279 commit 8fcb475
Show file tree
Hide file tree
Showing 28 changed files with 267 additions and 265 deletions.
18 changes: 9 additions & 9 deletions examples/drops/backend/src/methods/create_drop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ export const create_drop = async (client: DropsClient): Promise<void> => {
description: 'Description',
city: 'Buenos Aires',
country: 'Argentina',
start_date: toPOAPdate(today),
end_date: toPOAPdate(oneMonthFromToday),
expiry_date: toPOAPdate(twoMonthsFromToday),
event_url: 'https://poap.xyz/',
virtual_event: true,
secret_code: '123456',
startDate: toPOAPdate(today),
endDate: toPOAPdate(oneMonthFromToday),
expiryDate: toPOAPdate(twoMonthsFromToday),
eventUrl: 'https://poap.xyz/',
virtualEvent: true,
secretCode: '123456',
image: await fs.promises.readFile('src/assets/poap.png'),
filename: 'file.png',
contentType: 'image/png',
event_template_id: 1,
eventTemplateId: 1,
email: '[email protected]',
requested_codes: 10,
private_event: true,
requestedCodes: 10,
privateEvent: true,
};

try {
Expand Down
4 changes: 2 additions & 2 deletions examples/drops/backend/src/methods/fetch_multiple_drops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export const fetch_multiple_drops = async (
): Promise<void> => {
try {
const data: PaginatedResult<Drop> = await client.fetch({
sort_field: DropsSortFields.Id,
sort_dir: Order.ASC,
sortField: DropsSortFields.Id,
sortDir: Order.ASC,
limit: 10,
offset: 1,
});
Expand Down
4 changes: 2 additions & 2 deletions examples/drops/backend/src/methods/fetch_single_drop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { Order, PaginatedResult } from '@poap-xyz/utils';
export const fetch_single_drop = async (client: DropsClient): Promise<void> => {
try {
const data: PaginatedResult<Drop> = await client.fetch({
sort_field: DropsSortFields.Id,
sort_dir: Order.ASC,
sortField: DropsSortFields.Id,
sortDir: Order.ASC,
limit: 10,
offset: 0,
ids: [1],
Expand Down
12 changes: 6 additions & 6 deletions examples/poaps/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { fetch_multiple_poaps } from './methods/fetch_multiple_poaps';
import { fetch_single_poap } from './methods/fetch_single_poap';
import { fetch_multiple_poaps_by_collector } from './methods/fetch_multiple_poaps_by_collector';
import { fetch_multiple_poaps_by_drop_id } from './methods/fetch_multiple_poaps_by_drop_id';
import { claim_sync_poap } from './methods/claim_sync_poap';
import { mint_sync_poap } from './methods/mint_sync_poap';
import { getRequiredEnvVar } from './methods/get_required_env_var';
import { claim_async_poap } from './methods/claim_async_poap';
import { mint_async_poap } from './methods/mint_async_poap';
import { email_reservation_poap } from './methods/email_reservation_poap';
import dotenv from 'dotenv';

Expand Down Expand Up @@ -53,10 +53,10 @@ async function main(): Promise<void> {
() => fetch_multiple_poaps_by_drop_id(client),
'fetch_multiple_poaps_by_drop_id',
);
// Claim Sync Poap
await measurePerformance(() => claim_sync_poap(client), 'claim_sync_poap');
// Claim Async Poap
await measurePerformance(() => claim_async_poap(client), 'claim_async_poap');
// mint Sync Poap
await measurePerformance(() => mint_sync_poap(client), 'mint_sync_poap');
// mint Async Poap
await measurePerformance(() => mint_async_poap(client), 'mint_async_poap');
// Email Reservation Poap
await measurePerformance(
() => email_reservation_poap(client),
Expand Down
28 changes: 14 additions & 14 deletions examples/poaps/backend/src/methods/claim_async_poap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,38 @@ import { PoapsClient } from '@poap-xyz/poaps';
import { handleError } from '../utils/handleError';

/**
* Attempts to claim a POAP (Proof of Attendance Protocol) token asynchronously based on a predefined QR hash and address.
* After successfully claiming, the function fetches and logs the details of the claimed POAP.
* Attempts to mint a POAP (Proof of Attendance Protocol) token asynchronously based on a predefined QR hash and address.
* After successfully minting, the function fetches and logs the details of the minted POAP.
* In the event of an error during the process, the error is captured and managed by a separate utility function.
*
* Note: Replace 'your_poap_code' and 'your_address' placeholders with appropriate values.
* Note: Replace 'your_mint_code' and 'your_address' placeholders with appropriate values.
*
* @async
* @function
* @param {PoapsClient} client - An instance of the PoapsClient to interface with the POAP service.
* @returns {Promise<void>} Resolves when the operation completes, either with a claimed POAP or an error.
* @returns {Promise<void>} Resolves when the operation completes, either with a minted POAP or an error.
*/
export const claim_async_poap = async (client: PoapsClient): Promise<void> => {
export const mint_async_poap = async (client: PoapsClient): Promise<void> => {
try {
// Initiate the asynchronous claim process
const queueUid: string = await client.claimAsync({
poapCode: 'your_poap_code',
// Initiate the asynchronous mint process
const queueUid: string = await client.mintAsync({
mintCode: 'your_mint_code',
address: 'your_address',
});

// Wait for the claim's status to transition from 'IN_PROCESS' or 'PENDING' states
await client.waitClaimStatus(queueUid, 'your_poap_code');
// Wait for the mint's status to transition from 'IN_PROCESS' or 'PENDING' states
await client.waitMintStatus(queueUid, 'your_mint_code');

// Wait for the claimed POAP to be indexed and fetch the claim code information related to the QR hash
const getClaimCodeResponse = await client.waitPoapIndexed('your_poap_code');
// Wait for the minted POAP to be indexed and fetch the mint code information related to the QR hash
const getmintCodeResponse = await client.waitPoapIndexed('your_mint_code');

// Retrieve and log the specifics of the claimed POAP
// Retrieve and log the specifics of the minted POAP
console.log(
(
await client.fetch({
limit: 1,
offset: 0,
ids: [getClaimCodeResponse.result.token],
ids: [getmintCodeResponse.result.token],
})
).items[0],
);
Expand Down
6 changes: 3 additions & 3 deletions examples/poaps/backend/src/methods/claim_sync_poap.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { POAP, PoapsClient } from '@poap-xyz/poaps';
import { handleError } from '../utils/handleError';

export const claim_sync_poap = async (client: PoapsClient): Promise<void> => {
export const mint_sync_poap = async (client: PoapsClient): Promise<void> => {
try {
const data: POAP = await client.claimSync({
poapCode: 'your_poap_code',
const data: POAP = await client.mintSync({
mintCode: 'your_poap_code',
address: 'your_address',
});
console.log(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const email_reservation_poap = async (
): Promise<void> => {
try {
const data: POAPReservation = await client.emailReservation({
poapCode: 'your_poap_code',
mintCode: 'your_poap_code',
email: '[email protected]',
sendEmail: true,
});
Expand Down
4 changes: 2 additions & 2 deletions examples/poaps/backend/src/methods/fetch_multiple_poaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export const fetch_multiple_poaps = async (
): Promise<void> => {
try {
const data: PaginatedResult<POAP> = await client.fetch({
sort_field: PoapsSortFields.MintedOn,
sort_dir: Order.ASC,
sortField: PoapsSortFields.MintedOn,
sortDir: Order.ASC,
limit: 10,
offset: 0,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ export const fetch_multiple_poaps_by_collector = async (
): Promise<void> => {
try {
const data: PaginatedResult<POAP> = await client.fetch({
sort_field: PoapsSortFields.MintedOn,
sort_dir: Order.ASC,
sortField: PoapsSortFields.MintedOn,
sortDir: Order.ASC,
limit: 10,
offset: 0,
collector_address: '0xf6B6F07862A02C85628B3A9688beae07fEA9C863',
collectorAddress: '0xf6B6F07862A02C85628B3A9688beae07fEA9C863',
});
console.log(data);
console.log(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ export const fetch_multiple_poaps_by_drop_id = async (
): Promise<void> => {
try {
const data: PaginatedResult<POAP> = await client.fetch({
sort_field: PoapsSortFields.MintedOn,
sort_dir: Order.DESC,
sortField: PoapsSortFields.MintedOn,
sortDir: Order.DESC,
limit: 10,
offset: 0,
drop_id: 3,
filter_by_zero_address: true,
dropId: 3,
filterByZeroAddress: true,
});
console.log(data);
console.log('The first 10 POAP tokens minted for the drop 14.');
Expand Down
4 changes: 2 additions & 2 deletions examples/poaps/backend/src/methods/fetch_single_poap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { PaginatedResult, Order } from '@poap-xyz/utils';
export const fetch_single_poap = async (client: PoapsClient): Promise<void> => {
try {
const data: PaginatedResult<POAP> = await client.fetch({
sort_field: PoapsSortFields.MintedOn,
sort_dir: Order.ASC,
sortField: PoapsSortFields.MintedOn,
sortDir: Order.ASC,
limit: 10,
offset: 0,
ids: [1],
Expand Down
12 changes: 6 additions & 6 deletions examples/poaps/backend/src/utils/handleError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ import {
* Handles specific POAP-related errors by logging them.
*
* Errors handled:
* - CodeAlreadyClaimedError: Thrown when a POAP claim code has already been claimed.
* - CodeExpiredError: Thrown when a POAP claim code has expired and is no longer valid for claiming.
* - FinishedWithError: Thrown when the POAP claim process completes but encounters an error.
* - CodeAlreadyClaimedError: 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.
*
* @param {unknown} error - The error object to be checked and handled.
*/
export const handleError = (error: unknown): void => {
if (
// Checks if the error is an instance of CodeAlreadyClaimedError.
// This error occurs when a user attempts to claim a POAP that has already been claimed by someone else.
// This error occurs when a user attempts to mint a POAP that has already been minted by someone else.
error instanceof CodeAlreadyClaimedError ||
// Checks if the error is an instance of CodeExpiredError.
// This error is thrown when the claim code for a POAP has expired.
// This error is thrown when the mint code for a POAP has expired.
error instanceof CodeExpiredError ||
// Checks if the error is an instance of FinishedWithError.
// This error indicates that the POAP claim process finished but encountered an unexpected error.
// This error indicates that the POAP mint process finished but encountered an unexpected error.
error instanceof FinishedWithError
) {
// Logs the specific error message.
Expand Down
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,
emailClaim: drop.email_claims_stats
emailReservation: 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,
emailClaim: 0,
emailReservation: 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;
emailClaim: number;
emailReservation: 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.emailClaim = properties.emailClaim;
this.emailReservation = properties.emailReservation;
this.expiryDate = properties.expiryDate;
this.endDate = properties.endDate;
}

public getTotalMinted(): number {
return this.poapCount + this.emailClaim;
return this.poapCount + this.emailReservation;
}

public toSerializableObject(): SerializableDrop {
Expand All @@ -73,7 +73,7 @@ export class Drop {
createdDate: this.createdDate.toISOString(),
poapCount: this.poapCount,
transferCount: this.transferCount,
emailClaim: this.emailClaim,
emailReservation: this.emailReservation,
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;
emailClaim: number;
emailReservation: 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;
emailClaim: number;
emailReservation: number;
}
Loading

0 comments on commit 8fcb475

Please sign in to comment.