@@ -10,6 +10,7 @@ import {
1010 type TransactionReceipt ,
1111} from "viem" ;
1212import { getAddresses , requestAddresses , waitForTransactionReceipt } from "viem/actions" ;
13+
1314import { api , applyChainId , isOk , renderJSON } from "./utils/helpers.ts" ;
1415import type {
1516 ApiErr ,
@@ -91,7 +92,7 @@ export function App() {
9192 try {
9293 const resp = await api < ApiOk < PendingAny > | ApiErr > ( "/api/transaction/request" ) ;
9394
94- if ( ! resp || ( resp as ApiErr ) . status !== "ok" ) {
95+ if ( ! isOk ( resp ) ) {
9596 if ( pending ) {
9697 setPending ( null ) ;
9798 lastPendingIdRef . current = null ;
@@ -101,7 +102,7 @@ export function App() {
101102
102103 if ( ! lastPendingIdRef . current || lastPendingIdRef . current !== tx . id ) {
103104 setPending ( tx ) ;
104- lastPendingIdRef . current = tx . id ?? null ;
105+ lastPendingIdRef . current = tx . id ;
105106 setLastTxHash ( null ) ;
106107 setLastTxReceipt ( null ) ;
107108 } else if ( ! pending ) {
@@ -131,19 +132,17 @@ export function App() {
131132 const signAndSendCurrent = async ( ) => {
132133 if ( ! walletClient || ! selected || ! pending ) return ;
133134
134- const tx = pending ;
135-
136135 try {
137136 const hash = ( await selected . provider . request ( {
138137 method : "eth_sendTransaction" ,
139- params : [ tx . request ] ,
138+ params : [ pending . request ] ,
140139 } ) ) as `0x${string } `;
141140 setLastTxHash ( hash ) ;
142141
143142 const receipt = await waitForTransactionReceipt ( walletClient , { hash } ) ;
144143 setLastTxReceipt ( receipt ) ;
145144
146- await api ( "/api/transaction/response" , "POST" , { id : tx . id , hash, error : null } ) ;
145+ await api ( "/api/transaction/response" , "POST" , { id : pending . id , hash, error : null } ) ;
147146 await pollTick ( ) ;
148147 } catch ( e : unknown ) {
149148 const msg =
@@ -158,7 +157,7 @@ export function App() {
158157
159158 try {
160159 await api ( "/api/transaction/response" , "POST" , {
161- id : ( pending as { id ?: string } ) . id ,
160+ id : pending . id ,
162161 hash : null ,
163162 error : msg ,
164163 } ) ;
0 commit comments