From 593a4c53075aa48d49ece03606148ea077489d69 Mon Sep 17 00:00:00 2001 From: jawndiego Date: Mon, 24 Jun 2024 12:48:38 -0400 Subject: [PATCH] syn helpers --- apps/site/app/api/post/route.ts | 12 ++++-------- apps/site/app/api/postBatch/route.ts | 11 ++++++----- apps/site/app/api/registerFor/route.ts | 23 +++++++++++++++-------- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/apps/site/app/api/post/route.ts b/apps/site/app/api/post/route.ts index e06d74db..af50bed9 100644 --- a/apps/site/app/api/post/route.ts +++ b/apps/site/app/api/post/route.ts @@ -3,11 +3,8 @@ import { generatePostTxnInput, projectIdPost, } from '@/config/syndicateClient' -import { ethers } from 'ethers' import type { NextRequest } from 'next/server' -import { addresses, postGatewayABI } from 'scrypt' -import type { Hex } from 'viem' -import { waitUntilTx, authToken } from '@/lib' +import { waitForHash } from '@syndicateio/syndicate-node/utils' export const maxDuration = 30 // This function can run for a maximum of 30 seconds @@ -33,10 +30,9 @@ export async function POST(req: NextRequest) { generatePostTxnInput(post), ) - const successfulTxHash = await waitUntilTx({ - projectID: projectIdPost as string, - txID: postTx.transactionId, - authToken: authToken as string, + const successfulTxHash = await waitForHash(syndicateClientPost, { + projectId: projectIdPost, + transactionId: postTx.transactionId, }) return new Response( diff --git a/apps/site/app/api/postBatch/route.ts b/apps/site/app/api/postBatch/route.ts index 040c458c..e606698e 100644 --- a/apps/site/app/api/postBatch/route.ts +++ b/apps/site/app/api/postBatch/route.ts @@ -4,7 +4,7 @@ import { generatePostBatchTxnInput, projectIdPost, } from '@/config/syndicateClient' -import { waitUntilTx, authToken } from '@/lib' +import { waitForHash } from '@syndicateio/syndicate-node/utils' export async function POST(req: NextRequest) { const postsArray = await req.json() @@ -29,12 +29,13 @@ export async function POST(req: NextRequest) { generatePostBatchTxnInput(postsArray), ) - const successfulTxHash = await waitUntilTx({ - projectID: projectIdPost as string, - txID: postTx.transactionId, - authToken: authToken as string, + const successfulTxHash = await waitForHash(syndicateClientPost, { + projectId: projectIdPost, + transactionId: postTx.transactionId, }) + console.log({ successfulTxHash }) + return new Response( JSON.stringify({ success: true, hash: successfulTxHash }), { diff --git a/apps/site/app/api/registerFor/route.ts b/apps/site/app/api/registerFor/route.ts index 1ea00f8f..6c130577 100644 --- a/apps/site/app/api/registerFor/route.ts +++ b/apps/site/app/api/registerFor/route.ts @@ -1,12 +1,13 @@ -import { optimismPubClient } from '@/config/publicClient' import type { NextRequest } from 'next/server' -import { type Hex, decodeAbiParameters } from 'viem' +import { decodeAbiParameters } from 'viem' import { syndicateClientIdRegistry, generateIdRegistryInput, projectIdRegistry, } from '@/config/syndicateClient' -import { waitUntilTx, authToken } from '@/lib' +import { waitForHash } from '@syndicateio/syndicate-node/utils' +import { optimismPubClient } from '@/config/publicClient' +import type { Hex } from 'viem' export const maxDuration = 30 // This function can run for a maximum of 30 seconds @@ -39,10 +40,15 @@ export async function POST(req: NextRequest) { generateIdRegistryInput({ to, recovery, deadline, sig }), ) - const successfulTxHash = await waitUntilTx({ - projectID: projectIdRegistry as string, - txID: registerTx.transactionId, - authToken: authToken as string, + const successfulTxHash = await waitForHash(syndicateClientIdRegistry, { + projectId: projectIdRegistry, + transactionId: registerTx.transactionId, + }) + + console.log({ successfulTxHash }) + + const txnReceipt = await optimismPubClient.waitForTransactionReceipt({ + hash: successfulTxHash as Hex, }) const [rid] = decodeAbiParameters( @@ -50,7 +56,8 @@ export async function POST(req: NextRequest) { { name: 'rid', type: 'uint256' }, { name: 'recoveryAddress', type: 'address' }, ], - successfulTxHash.logs[0].data, + + txnReceipt.logs[0].data, ) console.log('rid: ', rid)