diff --git a/packages/demo/src/pages/Kiosk.tsx b/packages/demo/src/pages/Kiosk.tsx index eab1bec..3bd6891 100644 --- a/packages/demo/src/pages/Kiosk.tsx +++ b/packages/demo/src/pages/Kiosk.tsx @@ -1,8 +1,8 @@ import { useState } from 'react'; +import { motion, AnimatePresence } from 'framer-motion'; import { Transaction } from '@mysten/sui/transactions'; import { useWalrusWallet } from '@zktx.io/walrus-wallet'; -import { enqueueSnackbar } from 'notistack'; interface Item { id: number; @@ -20,6 +20,9 @@ const menuItems: Item[] = [ export const Kiosk = () => { const [cart, setCart] = useState([]); + const [orderedItems, setOrderedItems] = useState([]); + const [isModalOpen, setIsModalOpen] = useState(false); + const [txDigest, setTxDigest] = useState(null); const { pay } = useWalrusWallet(); const addToCart = (item: Item) => { @@ -46,34 +49,24 @@ export const Kiosk = () => { ), ], }); + const txResult = await pay('Pay', 'Please scan the QR code to pay.', { transactions: [transaction], isSponsored: true, }); - enqueueSnackbar(txResult[0].digest, { - variant: 'success', - style: { - whiteSpace: 'nowrap', - overflow: 'hidden', - textOverflow: 'ellipsis', - }, - }); + + setTxDigest(txResult[0].digest); + setOrderedItems(cart); // 결제 완료 후 주문 내역 저장 + setIsModalOpen(true); setCart([]); } catch (error) { - enqueueSnackbar(`${error}`, { - variant: 'error', - style: { - whiteSpace: 'nowrap', - overflow: 'hidden', - textOverflow: 'ellipsis', - }, - }); + alert(`Payment failed: ${error}`); } }; return (
-

McDonald's Kiosk

+

McDonald's Kiosk

{menuItems.map((item) => ( ))}
-

Cart

+

Cart

{cart.length === 0 ? ( -

Your cart is empty.

+

Your cart is empty.

) : (
    {cart.map((item, index) => ( -
  • +
  • - {item.name} - {item.price.toLocaleString()} KRW + {item.name} -{' '} + + {item.price.toLocaleString()} KRW +
)} -

- Total: {getTotalPrice().toLocaleString()} KRW +

+ Total:{' '} + + {getTotalPrice().toLocaleString()} KRW +

+ + + {isModalOpen && ( +
+ +

+ Payment Successful! +

+

Transaction ID:

+

{txDigest}

+

+ Your Order +

+
    + {orderedItems.map((item, index) => ( +
  • + {item.name} + + {item.price.toLocaleString()} KRW + +
  • + ))} +
+

+ Total:{' '} + + {orderedItems + .reduce((acc, item) => acc + item.price, 0) + .toLocaleString()}{' '} + KRW + +

+ +
+
+ )} +
); };