diff --git a/src/app/api/tweet/route.ts b/src/app/api/tweet/route.ts index 30d299d..e22c0bb 100644 --- a/src/app/api/tweet/route.ts +++ b/src/app/api/tweet/route.ts @@ -25,11 +25,16 @@ export async function POST(req: NextRequest): Promise { const isHandleCorrect = handle === process.env.ACCOUNT_HANDLE; const isVerified = isSigVerified && isHandleCorrect; - if (isVerified) { - saveTweet({transactionSignature: txHash}) + if (!isVerified) { + throw new Error('Tweet is not valid'); } - return NextResponse.json({ isVerified }) + const { isFourth } = await saveTweet({ transactionSignature: txHash }); + if (isFourth) { + createTokenLockForRecipient(); + } + + return NextResponse.json({ success: isVerified, message: 'Tweet verified' }) } catch (error) { console.error('Error while verifying tweet:', error) return NextResponse.json( @@ -49,8 +54,12 @@ const extractData = (tweet: string | object) => { const handleMatch = decodedTweet.match(/@([A-Za-z0-9_]+)/); return { - // memeUrl: urlMatch ? urlMatch[1] : null, + memeUrl: urlMatch ? urlMatch[1] : null, txHash: txHashMatch ? txHashMatch[1].trim() : null, handle: handleMatch ? handleMatch[1] : null, }; }; + +const createTokenLockForRecipient = () => { + console.log('Lock created'); +} diff --git a/src/utils/verifyTweet.ts b/src/utils/verifyTweet.ts index 25216ae..b90bb16 100644 --- a/src/utils/verifyTweet.ts +++ b/src/utils/verifyTweet.ts @@ -20,10 +20,14 @@ export async function verifySignatureInTweet(transactionSignature: string): Prom return true; } -export async function saveTweet(data: Partial): Promise { - await AppDataSource.transaction(async (transactionalEntityManager) => { +export async function saveTweet(data: Partial): Promise<{ isFourth: boolean }> { + return await AppDataSource.transaction(async (transactionalEntityManager) => { const tweetRepository = transactionalEntityManager.getRepository(Tweet); - await tweetRepository.save(data); + const tweet = await tweetRepository.save(data); + + return { + isFourth: tweet.id % 4 === 0 + }; }); }