Skip to content

Commit

Permalink
feat(embed, platforms): wet approach to moving logic over (#3080)
Browse files Browse the repository at this point in the history
* feat(embed, platforms): wet approach to moving logic over

* feat(embed): wip embed/verify

* fix: build error

* feat: fixing build errors, adding metadata API handler

* feat: adding rate limiting to embed API

* fix: adding tests for express app

* fix: build error

* fix: test failures

* feat: reworked autoVerification.ts, added tests

* fix: dependencies for iam

---------

Co-authored-by: Gerald Iakobinyi-Pich1 <[email protected]>
  • Loading branch information
tim-schultz and nutrina authored Jan 9, 2025
1 parent 7780837 commit 6271cb0
Show file tree
Hide file tree
Showing 20 changed files with 1,665 additions and 290 deletions.
65 changes: 1 addition & 64 deletions app/scripts/preBuild.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,70 +4,7 @@ dotenv.config();
import { writeFileSync } from "fs";
import { join } from "path";

import { PlatformGroupSpec, platforms } from "@gitcoin/passport-platforms";

type StampData = {
name: string;
description: string;
hash: string;
};

type GroupData = {
name: string;
stamps: StampData[];
};

type PlatformData = {
name: string;
icon: string;
description: string;
connectMessage: string;
groups: GroupData[];
};

const skipPlatforms = ["ClearText"];

const formatPlatformGroups = (providerConfig: PlatformGroupSpec[]) =>
providerConfig.reduce(
(groups: GroupData[], group: PlatformGroupSpec) => [
...groups,
{
name: group.platformGroup,
stamps: group.providers.map(({ name, title, hash }) => {
if (!hash) {
throw new Error(`No hash defined for ${name}`);
}
return {
name,
hash,
description: title,
};
}),
},
],
[] as GroupData[]
);

const platformsData = Object.entries(platforms).reduce((data, [id, platform]) => {
if (skipPlatforms.includes(id)) return data;

const { name, icon, description, connectMessage } = platform.PlatformDetails;
if (!icon) throw new Error(`No icon defined for ${id}`);

const groups = formatPlatformGroups(platform.ProviderConfig);

return [
...data,
{
id,
name,
icon,
description,
connectMessage,
groups,
},
];
}, [] as PlatformData[]);
import { platformsData } from "@gitcoin/passport-platforms";

const outPath = join(__dirname, "..", "public", "stampMetadata.json");
console.log(`Saving platform info to JSON file at ${outPath}`);
Expand Down
1 change: 1 addition & 0 deletions embed/.env-example.env
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,4 @@ ALCHEMY_API_KEY=...
SCROLL_BADGE_PROVIDER_INFO='{"badge_provider":{"contractAddress":"0x...","level":1}}'
SCROLL_BADGE_ATTESTATION_SCHEMA_UID=0xd57de4f41c3d3cc855eadef68f98c0d4edd22d57161d96b7c06d2f4336cc3b49

REDIS_URL=redis://localhost:6379/0
9 changes: 8 additions & 1 deletion embed/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

The Passport Embed service implements the backend part used by the passport embed UI component.


```
# Ensure you copy and update the required variables for the environment
$ cp ./.env-example.env ./.env
Expand Down Expand Up @@ -40,3 +39,11 @@ There are a few options for adding the variable into the build process:

Passport uses redis to handle caching. For local development you can spin up a redis instance using docker:
`docker run -d -p 6379:6379 redis` or using whatever other method you prefer. The redis instance should be available at `localhost:6379` by default.

## Example requests

```bash
curl -X POST http://localhost:80/embed/verify \
-H "Content-Type: application/json" \
-d '{"address":"0x85fF01cfF157199527528788ec4eA6336615C989", "scorerId":736}'
```
18 changes: 18 additions & 0 deletions embed/__mocks__/ioredis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// __mocks__/ioredis.ts
const RedisMock = jest.fn().mockImplementation(() => {
return {
get: jest.fn((key) => Promise.resolve(null)),
set: jest.fn((key, value) => {
return Promise.resolve("OK");
}),
on: jest.fn((key, func) => {}),
call: jest.fn((type, ...args) => {
if(type === "EVALSHA") {
return Promise.resolve([ 1, 60000 ]);
}
return Promise.resolve("OK");
}),
};
});

module.exports = RedisMock;
Loading

0 comments on commit 6271cb0

Please sign in to comment.