-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PLT-1397 Added Mint POAP on POAP package (#60)
* PLT-1397 Added provider * PLT-1397 Added intreface in POAP Client to claim sync * PLT-1397 Updated yarn * Added different ways to claim poaps * Eslint fix * Changed Camel Case to pascalCase * Changed pascalCase to CamelCase * Rename Status to MintingStatus * Eslint fix * Eslint fix * Eslint fix * Eslint fix * Eslint fix * PLT-1397 changed how to create poapTokenApi * PLT-1397 Some documentation and variable refactor * PLT-1397 Refactor code * Changed camel case * Updated yarn * Updated test * Changed name * Changed name * Changed variable name * Changed variable name * Changed variable name * Changed variable name * Changed variable name * Changed variable name * Changed variable name * Changed variable name * Changed names * Changed version
- Loading branch information
Showing
62 changed files
with
1,239 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CLIENT_ID= | ||
CLIENT_SECRET= | ||
API_KEY= | ||
OAUTH_SERVER_DOMAIN= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const getRequiredEnvVar = (envVarName: string): string => { | ||
const envVar = process.env[envVarName]; | ||
if (envVar === undefined) { | ||
throw new Error(`Environment variable ${envVarName} is required`); | ||
} | ||
return envVar; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
CLIENT_ID= | ||
CLIENT_SECRET= | ||
API_KEY= | ||
OAUTH_SERVER_DOMAIN= | ||
POAP_TOKEN_BASE_URL=https://api.poap.tech |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
examples/poaps/backend/src/methods/email_reservation_poap.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { PoapsClient, POAPReservation } from '@poap-xyz/poaps'; | ||
import { handleError } from '../utils/handleError'; | ||
|
||
export const email_reservation_poap = async ( | ||
client: PoapsClient, | ||
): Promise<void> => { | ||
try { | ||
const data: POAPReservation = await client.emailReservation({ | ||
mintCode: 'your_poap_code', | ||
email: '[email protected]', | ||
sendEmail: true, | ||
}); | ||
console.log(data); | ||
} catch (error) { | ||
handleError(error); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const getRequiredEnvVar = (envVarName: string): string => { | ||
const envVar = process.env[envVarName]; | ||
if (envVar === undefined) { | ||
throw new Error(`Environment variable ${envVarName} is required`); | ||
} | ||
return envVar; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { PoapsClient } from '@poap-xyz/poaps'; | ||
import { handleError } from '../utils/handleError'; | ||
|
||
/** | ||
* 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_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 minted POAP or an error. | ||
*/ | ||
export const mint_async_poap = async (client: PoapsClient): Promise<void> => { | ||
try { | ||
// Initiate the asynchronous mint process | ||
const queueUid: string = 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'); | ||
|
||
// 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 minted POAP | ||
console.log( | ||
( | ||
await client.fetch({ | ||
limit: 1, | ||
offset: 0, | ||
ids: [getMintCodeResponse.poapId], | ||
}) | ||
).items[0], | ||
); | ||
} catch (error) { | ||
// Address any errors using the designated utility function | ||
handleError(error); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { POAP, PoapsClient } from '@poap-xyz/poaps'; | ||
import { handleError } from '../utils/handleError'; | ||
|
||
export const mint_sync_poap = async (client: PoapsClient): Promise<void> => { | ||
try { | ||
const data: POAP = await client.mintSync({ | ||
mintCode: 'your_poap_code', | ||
address: 'your_address', | ||
}); | ||
console.log(data); | ||
} catch (error) { | ||
handleError(error); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { | ||
CodeAlreadyMintedError, | ||
CodeExpiredError, | ||
FinishedWithError, | ||
} from '@poap-xyz/poaps'; | ||
|
||
/** | ||
* Handles specific POAP-related errors by logging them. | ||
* | ||
* Errors handled: | ||
* - 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. | ||
* | ||
* @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 mint a POAP that has already been minted by someone else. | ||
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 || | ||
// Checks if the error is an instance of FinishedWithError. | ||
// This error indicates that the POAP mint process finished but encountered an unexpected error. | ||
error instanceof FinishedWithError | ||
) { | ||
// Logs the specific error message. | ||
console.error(error); | ||
} else { | ||
// Logs the generic error message. | ||
console.error('An unexpected error occurred:', error); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.