forked from mito-systems/sol-mem-gen
Add check for fourth recipient
This commit is contained in:
parent
6741d539af
commit
bce1719f7e
@ -25,11 +25,16 @@ export async function POST(req: NextRequest): Promise<NextResponse> {
|
|||||||
const isHandleCorrect = handle === process.env.ACCOUNT_HANDLE;
|
const isHandleCorrect = handle === process.env.ACCOUNT_HANDLE;
|
||||||
|
|
||||||
const isVerified = isSigVerified && isHandleCorrect;
|
const isVerified = isSigVerified && isHandleCorrect;
|
||||||
if (isVerified) {
|
if (!isVerified) {
|
||||||
saveTweet({transactionSignature: txHash})
|
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) {
|
} catch (error) {
|
||||||
console.error('Error while verifying tweet:', error)
|
console.error('Error while verifying tweet:', error)
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
@ -49,8 +54,12 @@ const extractData = (tweet: string | object) => {
|
|||||||
const handleMatch = decodedTweet.match(/@([A-Za-z0-9_]+)/);
|
const handleMatch = decodedTweet.match(/@([A-Za-z0-9_]+)/);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
// memeUrl: urlMatch ? urlMatch[1] : null,
|
memeUrl: urlMatch ? urlMatch[1] : null,
|
||||||
txHash: txHashMatch ? txHashMatch[1].trim() : null,
|
txHash: txHashMatch ? txHashMatch[1].trim() : null,
|
||||||
handle: handleMatch ? handleMatch[1] : null,
|
handle: handleMatch ? handleMatch[1] : null,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const createTokenLockForRecipient = () => {
|
||||||
|
console.log('Lock created');
|
||||||
|
}
|
||||||
|
@ -20,10 +20,14 @@ export async function verifySignatureInTweet(transactionSignature: string): Prom
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function saveTweet(data: Partial<Tweet>): Promise<void> {
|
export async function saveTweet(data: Partial<Tweet>): Promise<{ isFourth: boolean }> {
|
||||||
await AppDataSource.transaction(async (transactionalEntityManager) => {
|
return await AppDataSource.transaction(async (transactionalEntityManager) => {
|
||||||
const tweetRepository = transactionalEntityManager.getRepository(Tweet);
|
const tweetRepository = transactionalEntityManager.getRepository(Tweet);
|
||||||
|
|
||||||
await tweetRepository.save(data);
|
const tweet = await tweetRepository.save(data);
|
||||||
|
|
||||||
|
return {
|
||||||
|
isFourth: tweet.id % 4 === 0
|
||||||
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user