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 21, 2023
1 parent 1d8a6cc commit 4b2b780
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 60 deletions.
2 changes: 1 addition & 1 deletion examples/poaps/backend/src/methods/mint_async_poap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const mint_async_poap = async (client: PoapsClient): Promise<void> => {
await client.fetch({
limit: 1,
offset: 0,
ids: [getmintCodeResponse.result.token],
ids: [getmintCodeResponse.poapId],
})
).items[0],
);
Expand Down
26 changes: 7 additions & 19 deletions packages/poaps/src/PoapsClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +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';
import { PoapMintStatus } from './types/response';

/**
* Represents a client for interacting with POAPs (Proof of Attendance Protocol tokens).
Expand Down Expand Up @@ -117,7 +117,7 @@ export class PoapsClient {
private async getSecretCode(mintCode: string): Promise<string> {
const getCodeResponse = await this.getMintCode(mintCode);

if (getCodeResponse.claimed == true) {
if (getCodeResponse.minted == true) {
throw new CodeAlreadyMintedError(mintCode);
}
if (getCodeResponse.isActive == false) {
Expand All @@ -133,25 +133,13 @@ export class PoapsClient {
* @param {string} mintCode - The QR hash for which to get the mint code.
* @returns {Promise<GetMintCodeResponse>} The mint code details.
*/
async getMintCode(mintCode: string): Promise<GetMintCodeResponse> {
async getMintCode(mintCode: string): Promise<PoapMintStatus> {
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,
minted: getMintCodeRaw.claimed,
isActive: getMintCodeRaw.is_active,
secret: getMintCodeRaw.secret,
txStatus: getMintCodeRaw.tx_status,
result: {
token: getMintCodeRaw.result?.token,
},
poapId: getMintCodeRaw.result?.token,
};
}

Expand Down Expand Up @@ -185,7 +173,7 @@ export class PoapsClient {
* @param {string} mintCode - The QR hash identifying the POAP to be indexed.
* @returns {Promise<GetMintCodeResponse>} Details of the indexed POAP.
*/
async waitPoapIndexed(mintCode: string): Promise<GetMintCodeResponse> {
async waitPoapIndexed(mintCode: string): Promise<PoapMintStatus> {
const checker = new PoapIndexed(mintCode, this.tokensApiProvider);
return await checker.waitPoapIndexed();
}
Expand Down Expand Up @@ -229,7 +217,7 @@ export class PoapsClient {
await this.fetch({
limit: 1,
offset: 0,
ids: [getCodeResponse.result.token],
ids: [getCodeResponse.poapId],
})
).items[0];
}
Expand Down
18 changes: 3 additions & 15 deletions packages/poaps/src/types/response.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
export interface GetMintCodeResponse {
id: number;
qrHash: string;
txHash: string;
eventId: number;
beneficiary: string;
userInput: string;
signer: string;
claimed: boolean;
claimedDate: string;
createdDate: string;
export interface PoapMintStatus {
minted: boolean;
isActive: boolean;
secret: string;
txStatus: string;
result: {
token: number;
};
poapId: number;
}
20 changes: 4 additions & 16 deletions packages/poaps/src/utils/PoapIndexed.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TokensApiProvider } from '@poap-xyz/providers';
import { RetryableTask } from './RetryableTask';
import { GetMintCodeResponse } from '../types';
import { PoapMintStatus } from '../types';

/**
* @class PoapIndexed
Expand Down Expand Up @@ -29,30 +29,18 @@ export class PoapIndexed extends RetryableTask {
*
* @returns {Promise<GetClaimCodeResponse>} A promise that either resolves with the indexed token's mint code response or rejects due to reaching the max retry limit.
*/
public async waitPoapIndexed(): Promise<GetMintCodeResponse> {
public async waitPoapIndexed(): Promise<PoapMintStatus> {
let response = await this.tokensApiProvider.getMintCode(this.mintCode);
while (response.result == null) {
response = await this.backoffAndRetry(() =>
this.tokensApiProvider.getMintCode(this.mintCode),
);
}
return {
id: response.id,
qrHash: response.qr_hash,
txHash: response.tx_hash,
eventId: response.event_id,
beneficiary: response.beneficiary,
userInput: response.user_input,
signer: response.signer,
claimed: response.claimed,
claimedDate: response.claimed_date,
createdDate: response.created_date,
minted: response.claimed,
isActive: response.is_active,
secret: response.secret,
txStatus: response.tx_status,
result: {
token: response.result?.token,
},
poapId: response.result?.token,
};
}
}
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,
GetMintCodeResponseRaw,
GetMintCodeResponse,
} 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<GetMintCodeResponseRaw>} Details of the mint code.
* @returns {Promise<GetMintCodeResponse>} Details of the mint code.
*/
async getMintCode(code: string): Promise<GetMintCodeResponseRaw> {
return await this.secureFetch<GetMintCodeResponseRaw>(
async getMintCode(code: string): Promise<GetMintCodeResponse> {
return await this.secureFetch<GetMintCodeResponse>(
`${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 {
GetMintCodeResponseRaw,
GetMintCodeResponse,
PostMintCodeResponse,
MintCodeInput,
MintStatusResponse,
Expand All @@ -11,7 +11,7 @@ import {
* @interface TokensApiProvider
*/
export interface TokensApiProvider {
getMintCode(code: string): Promise<GetMintCodeResponseRaw>;
getMintCode(code: string): Promise<GetMintCodeResponse>;
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 GetMintCodeResponseRaw {
export interface GetMintCodeResponse {
id: number;
qr_hash: string;
tx_hash: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/providers/src/ports/TokensApiProvider/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export { TokensApiProvider } from './TokensApiProvider';
export {
GetMintCodeResponseRaw,
GetMintCodeResponse,
PostMintCodeResponse,
MintCodeInput,
MintStatusResponse,
Expand Down
2 changes: 1 addition & 1 deletion packages/providers/src/ports/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export * from './MomentsApiProvider/MomentsApiProvider';
export * from './DropApiProvider/DropApiProvider';
export {
TokensApiProvider,
GetMintCodeResponseRaw,
GetMintCodeResponse,
PostMintCodeResponse,
MintCodeInput,
MintStatusResponse,
Expand Down

0 comments on commit 4b2b780

Please sign in to comment.