Skip to content

Commit

Permalink
feat: civic stamp (#1476)
Browse files Browse the repository at this point in the history
* feat: civic stamp

optimise the API calls to the pass lookup service
by specifying the pass type in the call

* feat: civic stamp

updates to match upstream
  • Loading branch information
dankelleher authored Jul 13, 2023
1 parent 81dba00 commit d64189e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
8 changes: 3 additions & 5 deletions platforms/src/Civic/Providers/civic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ export class CivicPassProvider implements Provider {
// if a signer is provider we will use that address to verify against
const address = payload.address.toString().toLowerCase();
try {
const allPasses = await findAllPasses(address, this.includeTestnets);
const filteredPasses = allPasses.filter((pass) => pass.type === this.passType);

const valid = filteredPasses.length > 0;
const expiry = valid ? secondsFromNow(latestExpiry(filteredPasses)) : undefined;
const allPasses = await findAllPasses(address, this.includeTestnets, [this.passType]);
const valid = allPasses.length > 0;
const expiry = valid ? secondsFromNow(latestExpiry(allPasses)) : undefined;

return {
valid,
Expand Down
12 changes: 10 additions & 2 deletions platforms/src/Civic/Providers/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const passLookupResponseToPass =
identifier: pass.identifier,
});

const passTypesToNames = (passTypes: CivicPassType[]): string[] => passTypes.map((id) => CivicPassType[id]);

/**
* Look up all passes for a user's address.
* The endpoint supports DID-lookup as well as looking up passes by an individual wallet.
Expand Down Expand Up @@ -84,9 +86,15 @@ const passLookupResponseToPass =
* }
* @param userAddress
* @param includeTestnets
* @param passTypes
*/
export const findAllPasses = async (userAddress: string, includeTestnets = false): Promise<Pass[]> => {
const queryString = `${CIVIC_URL}/${userAddress}?includeTestnets=${includeTestnets.toString()}`;
export const findAllPasses = async (
userAddress: string,
includeTestnets = false,
passTypes?: CivicPassType[]
): Promise<Pass[]> => {
const passTypesString = passTypes ? `&passTypes=${passTypesToNames(passTypes).join(",")}` : "";
const queryString = `${CIVIC_URL}/${userAddress}?includeTestnets=${includeTestnets.toString()}${passTypesString}`;
const response = await axios.get<CivicPassLookupResponse>(queryString).then((response) => response.data);
return Object.entries(response).flatMap(([, passesForAddress]) =>
Object.entries(passesForAddress.passes).flatMap(([passType, passes]) =>
Expand Down

6 comments on commit d64189e

@Jevenxje
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great

@Sobanrehan
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go

@Everton-Lagoa2303
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great project

@deep22454
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great

@Jack024813
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good

@ArtN7
Copy link

@ArtN7 ArtN7 commented on d64189e Jul 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool

Please sign in to comment.