Skip to content

Commit

Permalink
feat: add basepaint nft worker
Browse files Browse the repository at this point in the history
  • Loading branch information
bigint committed Sep 29, 2023
1 parent 6e015d9 commit 30a7fe8
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
64 changes: 64 additions & 0 deletions packages/workers/nft/src/handlers/getBasePaintNft.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import response from '@hey/lib/response';

import type { WorkerRequest } from '../types';

export default async (request: WorkerRequest) => {
const { id } = request.query;

if (!id) {
return response({ success: false, error: 'No id provided' });
}

try {
const basePaintResponse = await fetch('https://basepaint.art/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'User-agent': 'Hey.xyz'
},
body: JSON.stringify({
query: `
query Canvas {
canvass(first: 1, orderDirection: "ASC") {
id
}
canvas(id: ${id}) {
id
palette
theme
totalEarned
totalMints
pixelsCount
contributions(first: 20) {
account {
id
screenName
totalPixels
}
}
}
}
`
})
});
const canvas: {
data: {
canvass: {
id: number;
}[];
canvas: any;
};
} = await basePaintResponse.json();
const numberId = parseInt(id as string);
const currentCanvas = canvas.data.canvass[0].id;

return response({
success: true,
canContribute: currentCanvas === numberId,
canMint: currentCanvas - 1 === numberId,
canvas: canvas.data.canvas || null
});
} catch (error) {
throw error;
}
};
2 changes: 2 additions & 0 deletions packages/workers/nft/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Errors } from '@hey/data/errors';
import response from '@hey/lib/response';
import { createCors, error, Router, status } from 'itty-router';

import getBasePaintNft from './handlers/getBasePaintNft';
import getZoraNft from './handlers/getZoraNft';
import buildRequest from './helper/buildRequest';
import type { Env, WorkerRequest } from './types';
Expand All @@ -23,6 +24,7 @@ router
})
)
.get('/zora', getZoraNft)
.get('/basepaint', getBasePaintNft)
.all('*', () => error(404));

export default {
Expand Down

0 comments on commit 30a7fe8

Please sign in to comment.