@@ -20,6 +20,7 @@ import LearnTGVaultsAbi from '@/abis/LearnTGVaults.json'
2020import { newKyselyPostgresql } from '@/.config/kysely.config.ts'
2121import type { CourseUsuario , DB , GuideUsuario , Usuario } from '@/db/db.d.ts'
2222import { updateUserAndCoursePoints } from '@/lib/scores'
23+ import { callWriteFun } from '@/lib/crypto'
2324
2425interface WordPlacement {
2526 word : string
@@ -303,43 +304,19 @@ export async function POST(req: NextRequest) {
303304 retMessage += msg [ locale ] . atLeast50
304305 } else if ( canSubmit ) {
305306 try {
306- const encodedData = encodeFunctionData ( {
307- abi : LearnTGVaultsAbi ,
308- functionName : 'submitGuideResult' ,
309- args : [
307+ let tx : Address = await callWriteFun (
308+ publicClient ,
309+ account ,
310+ contract . write . submitGuideResult ,
311+ [
310312 courseIdArg ,
311313 guideIdArg ,
312314 walletAddress as Address ,
313315 mistakesInCW . length == 0 ,
314316 usuario . profilescore || 0 ,
315317 ] ,
316- } )
317- console . log ( 'encodedData=' , encodedData )
318- let txData = encodedData
319- console . log ( 'txData=' , txData )
320- const tx = await walletClient . sendTransaction ( {
321- account,
322- to : contract . address ,
323- data : txData as Hex ,
324- } )
325- console . log ( 'tx=' , tx )
326- try {
327- const receipt = await publicClient . waitForTransactionReceipt ( {
328- hash : tx ,
329- confirmations : 2 ,
330- timeout : 2_000 ,
331- } )
332- // waitForTransactionReceipt has not worked anytime
333- // Control has not reach this point, but we leave it
334- // to give some time for the transaction to settel before
335- // querying the contract
336- console . log ( `Receipt: ${ receipt } ` )
337-
338- } catch ( e ) {
339- console . error (
340- `*waitForTransactionReceipt(${ tx } ) didnt work, continuing` ,
341- )
342- }
318+ 0
319+ )
343320 // VERIFICAR Y GUARDAR MONTO
344321 const statusArray : any = await contract . read . getStudentGuideStatus ( [
345322 courseIdArg ,
0 commit comments