1
1
import { useState , useCallback , useEffect } from 'react' ;
2
2
import { DateTime } from 'luxon' ;
3
- import { Address } from 'viem' ;
3
+ import { Address , Hash } from 'viem' ;
4
4
import {
5
- ClientDealsManager ,
6
5
DealRecord ,
7
6
DealStatus ,
8
7
} from '../../../../src/index.js' ; // @windingtree /sdk
8
+ import { ClientDealsManager } from '../../../../src/client/dealsManager.js' ;
9
9
import { RequestQuery , OfferOptions } from '../../../shared/index.js' ;
10
10
import {
11
11
centerEllipsis ,
@@ -223,13 +223,31 @@ export const Cancel = ({ deal, manager, onClose }: CancelProps) => {
223
223
* Created deals table
224
224
*/
225
225
export const Deals = ( { deals, manager } : DealsProps ) => {
226
+ const { walletClient } = useWallet ( ) ;
226
227
const [ dealStates , setDealStates ] = useState < Record < string , DealStatus > > ( { } ) ;
227
228
const [ transferDeal , setTransferDeal ] = useState <
228
229
DealsRegistryRecord | undefined
229
230
> ( ) ;
230
231
const [ cancelDeal , setCancelDeal ] = useState <
231
232
DealsRegistryRecord | undefined
232
233
> ( ) ;
234
+ const [ userSign , setUserSign ] = useState < Hash | undefined > ( ) ;
235
+ const [ error , setError ] = useState < string | undefined > ( ) ;
236
+
237
+ const handleCheckInOut = useCallback ( async ( deal : DealsRegistryRecord ) => {
238
+ try {
239
+ if ( ! manager || ! walletClient ) {
240
+ throw new Error ( 'Wallet not connected yet' ) ;
241
+ }
242
+ setUserSign ( await manager . checkInOutSignature (
243
+ deal . offer . id ,
244
+ walletClient ,
245
+ ) ) ;
246
+ } catch ( error ) {
247
+ console . log ( error ) ;
248
+ setError ( ( error as Error ) . message || 'Unknown check in signature error' ) ;
249
+ }
250
+ } , [ manager , walletClient ] ) ;
233
251
234
252
useEffect ( ( ) => {
235
253
if ( deals && deals . length > 0 ) {
@@ -275,8 +293,8 @@ export const Deals = ({ deals, manager }: DealsProps) => {
275
293
{ DealStatus [ dealStates [ d . offer . id ] ] }
276
294
</ td >
277
295
< td >
278
- < div style = { { display : 'flex' , flexDirection : 'column' } } >
279
- < div style = { { marginBottom : 5 } } >
296
+ < div style = { { display : 'flex' , flexDirection : 'column' , gap : 5 } } >
297
+ < div >
280
298
< button
281
299
onClick = { ( ) => setCancelDeal ( d ) }
282
300
disabled = {
@@ -306,13 +324,22 @@ export const Deals = ({ deals, manager }: DealsProps) => {
306
324
Transfer
307
325
</ button >
308
326
</ div >
327
+ { d . status === DealStatus . Claimed &&
328
+ < div >
329
+ < button
330
+ onClick = { ( ) => handleCheckInOut ( d ) }
331
+ >
332
+ Check In
333
+ </ button >
334
+ </ div >
335
+ }
309
336
</ div >
310
337
</ td >
311
338
</ tr >
312
339
) ) }
313
340
</ tbody >
314
341
</ table >
315
- < div style = { { marginTop : 20 } } >
342
+ < div >
316
343
< TransferForm
317
344
deal = { transferDeal }
318
345
manager = { manager }
@@ -323,7 +350,17 @@ export const Deals = ({ deals, manager }: DealsProps) => {
323
350
manager = { manager }
324
351
onClose = { ( ) => setCancelDeal ( undefined ) }
325
352
/>
353
+ { userSign &&
354
+ < div style = { { marginTop : 20 } } >
355
+ < h2 > Provide this signature to the reception manager:</ h2 >
356
+ < input style = { { width : '100%' } } onFocus = { ( event ) => {
357
+ event . target . select ( ) ;
358
+ } } value = { userSign } onChange = { ( ) => { } } />
359
+ </ div >
360
+ }
326
361
</ div >
362
+
363
+ { error && < div style = { { marginTop : 20 } } > 🚨 { error } </ div > }
327
364
</ div >
328
365
) ;
329
366
} ;
0 commit comments