Skip to content

Commit 7d49d6e

Browse files
committed
feat: 🎸 Added check out action to the client example app
1 parent 46c3492 commit 7d49d6e

File tree

1 file changed

+42
-5
lines changed

1 file changed

+42
-5
lines changed

‎examples/client/src/components/Deals.tsx

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { useState, useCallback, useEffect } from 'react';
22
import { DateTime } from 'luxon';
3-
import { Address } from 'viem';
3+
import { Address, Hash } from 'viem';
44
import {
5-
ClientDealsManager,
65
DealRecord,
76
DealStatus,
87
} from '../../../../src/index.js'; // @windingtree/sdk
8+
import { ClientDealsManager } from '../../../../src/client/dealsManager.js';
99
import { RequestQuery, OfferOptions } from '../../../shared/index.js';
1010
import {
1111
centerEllipsis,
@@ -223,13 +223,31 @@ export const Cancel = ({ deal, manager, onClose }: CancelProps) => {
223223
* Created deals table
224224
*/
225225
export const Deals = ({ deals, manager }: DealsProps) => {
226+
const { walletClient } = useWallet();
226227
const [dealStates, setDealStates] = useState<Record<string, DealStatus>>({});
227228
const [transferDeal, setTransferDeal] = useState<
228229
DealsRegistryRecord | undefined
229230
>();
230231
const [cancelDeal, setCancelDeal] = useState<
231232
DealsRegistryRecord | undefined
232233
>();
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]);
233251

234252
useEffect(() => {
235253
if (deals && deals.length > 0) {
@@ -275,8 +293,8 @@ export const Deals = ({ deals, manager }: DealsProps) => {
275293
{DealStatus[dealStates[d.offer.id]]}
276294
</td>
277295
<td>
278-
<div style={{ display: 'flex', flexDirection: 'column' }}>
279-
<div style={{ marginBottom: 5 }}>
296+
<div style={{ display: 'flex', flexDirection: 'column', gap: 5 }}>
297+
<div>
280298
<button
281299
onClick={() => setCancelDeal(d)}
282300
disabled={
@@ -306,13 +324,22 @@ export const Deals = ({ deals, manager }: DealsProps) => {
306324
Transfer
307325
</button>
308326
</div>
327+
{d.status === DealStatus.Claimed &&
328+
<div>
329+
<button
330+
onClick={() => handleCheckInOut(d)}
331+
>
332+
Check In
333+
</button>
334+
</div>
335+
}
309336
</div>
310337
</td>
311338
</tr>
312339
))}
313340
</tbody>
314341
</table>
315-
<div style={{ marginTop: 20 }}>
342+
<div>
316343
<TransferForm
317344
deal={transferDeal}
318345
manager={manager}
@@ -323,7 +350,17 @@ export const Deals = ({ deals, manager }: DealsProps) => {
323350
manager={manager}
324351
onClose={() => setCancelDeal(undefined)}
325352
/>
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+
}
326361
</div>
362+
363+
{error && <div style={{ marginTop: 20 }}>🚨 {error}</div>}
327364
</div>
328365
);
329366
};

0 commit comments

Comments
 (0)