Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add endpoint to return snapit metadata #191

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ SENTRY_TRACE_SAMPLE_RATE=
TUNNEL_SENTRY_DSN=
DIGITAL_OCEAN_TOKEN=
METRICS_AUTHORIZATION=
SNAPIT_URL=
10 changes: 10 additions & 0 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import getModerationList from './lib/moderationList';
import VotesReport from './lib/votesReport';
import mintPayload from './lib/nftClaimer/mint';
import deployPayload from './lib/nftClaimer/deploy';
import metadata from './lib/nftClaimer/metadata';
import { queue, getProgress } from './lib/queue';
import { snapshotFee } from './lib/nftClaimer/utils';

Expand Down Expand Up @@ -87,4 +88,13 @@ router.post('/nft-claimer/mint', async (req, res) => {
}
});

router.get('/nft-claimer/metadata/:proposal_id', async (req, res) => {
try {
return res.json(await metadata(req.params.proposal_id));
} catch (e: any) {
capture(e);
return rpcError(res, e, '');
}
});

export default router;
6 changes: 6 additions & 0 deletions src/helpers/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import { fetchWithKeepAlive } from './utils';

export type Proposal = {
id: string;
title: string;
state: string;
choices: string[];
space: Space;
votes: number;
author: string;
start: number;
end: number;
};

export type Vote = {
Expand Down Expand Up @@ -62,10 +65,13 @@ const PROPOSAL_QUERY = gql`
query Proposal($id: String) {
proposal(id: $id) {
id
title
state
choices
votes
author
start
end
space {
id
network
Expand Down
23 changes: 23 additions & 0 deletions src/lib/nftClaimer/metadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { fetchProposal } from '../../helpers/snapshot';

export default async function metadata(proposal_id: string) {
const proposal = await fetchProposal(proposal_id);

if (!proposal) {
return Promise.reject('RECORD_NOT_FOUND');
}

return {
name: proposal?.title,
image: `${process.env.SNAPIT_URL}/picsnap/snapit/${proposal.id}.png`,
properties: {
space: proposal.space.id,
author: proposal.author,
state: proposal.state,
votes: proposal.votes,
choices: proposal.choices,
start: new Date(proposal.start * 1e3),
end: new Date(proposal.end * 1e3)
}
};
}