From b73669ba3a25812ee0bc435432fd9dcbf899e5b8 Mon Sep 17 00:00:00 2001 From: arthuravianna Date: Tue, 23 Jan 2024 14:16:25 -0300 Subject: [PATCH 1/2] feat: submitLog feedback, svg folder, and util.ts file --- frontend/app/components/CartridgeInfo.tsx | 91 ++++++++++++++++++- frontend/app/components/ThemeSwitch.tsx | 4 +- frontend/app/components/svg/CheckIcon.tsx | 14 +++ .../app/components/{ => svg}/DarkIcon.tsx | 0 frontend/app/components/svg/ErrorIcon.tsx | 14 +++ .../app/components/{ => svg}/LightIcon.tsx | 0 frontend/app/globals.css | 1 - frontend/app/utils/util.ts | 3 + 8 files changed, 119 insertions(+), 8 deletions(-) create mode 100644 frontend/app/components/svg/CheckIcon.tsx rename frontend/app/components/{ => svg}/DarkIcon.tsx (100%) create mode 100644 frontend/app/components/svg/ErrorIcon.tsx rename frontend/app/components/{ => svg}/LightIcon.tsx (100%) create mode 100644 frontend/app/utils/util.ts diff --git a/frontend/app/components/CartridgeInfo.tsx b/frontend/app/components/CartridgeInfo.tsx index 7ae27bd..21a0c12 100644 --- a/frontend/app/components/CartridgeInfo.tsx +++ b/frontend/app/components/CartridgeInfo.tsx @@ -1,7 +1,7 @@ "use client" import { ethers } from "ethers"; -import React, { Suspense, useContext, useRef } from 'react' +import React, { Suspense, useContext, useRef, useState } from 'react' import { selectedCartridgeContext } from '../cartridges/selectedCartridgeProvider'; import PowerSettingsNewIcon from '@mui/icons-material/PowerSettingsNew'; import PublishIcon from '@mui/icons-material/Publish'; @@ -27,8 +27,58 @@ import Link from 'next/link'; import CartridgeScoreboard from './CartridgeScoreboard'; import { envClient } from "../utils/clientEnv"; import { fontPressStart2P } from '../utils/font'; +import { delay } from "../utils/util"; +import CheckIcon from "./svg/CheckIcon"; +import ErrorIcon from "./svg/ErrorIcon"; +enum STATUS { + READY, + VALIDATING, + VALID, + INVALID, +} + +interface LOG_STATUS { + status:STATUS, + error?:string +} + +function logFeedback(logStatus:LOG_STATUS, setLogStatus:Function) { + if (logStatus.status === STATUS.VALID) { + delay(2500).then(() =>{ + setLogStatus({status: STATUS.READY} as LOG_STATUS); + }) + return ( +
+ +
Log Validated
+
+ ) + } else if (logStatus.status === STATUS.INVALID) { + const click = () => { + setLogStatus({status: STATUS.READY} as LOG_STATUS) + } + return ( +
+
+ +
Invalid Log.
+ +
+
+ {logStatus.error} +
+
+ ) + } +} + function scoreboardFallback() { const arr = Array.from(Array(3).keys()); @@ -84,6 +134,7 @@ function CartridgeInfo() { const fileRef = useRef(null); const [{ wallet }, connect] = useConnectWallet(); const { download } = useDownloader(); + const [submitLogStatus, setSubmitLogStatus] = useState({status: STATUS.READY} as LOG_STATUS); if (!selectedCartridge) return <>; @@ -106,7 +157,15 @@ function CartridgeInfo() { in_card: selectedCartridge.inCard ? ethers.utils.hexlify(selectedCartridge.inCard) : "0x", log: ethers.utils.hexlify(selectedCartridge.gameplayLog) } - const replayRes = await replay(signer, envClient.DAPP_ADDR, inputData, {decode:true, cartesiNodeUrl: envClient.CARTESI_NODE_URL}); + + setSubmitLogStatus({status: STATUS.VALIDATING}); + try { + const replayRes = await replay(signer, envClient.DAPP_ADDR, inputData, {decode:true, cartesiNodeUrl: envClient.CARTESI_NODE_URL}); + console.log(replayRes); + setSubmitLogStatus({status: STATUS.VALID}); + } catch (error) { + setSubmitLogStatus({status: STATUS.INVALID, error: (error as Error).message}); + } } async function uploadLog() { @@ -184,9 +243,26 @@ function CartridgeInfo() { Turn on -
diff --git a/frontend/app/components/svg/CloseIcon.tsx b/frontend/app/components/svg/CloseIcon.tsx new file mode 100644 index 0000000..13fd6ec --- /dev/null +++ b/frontend/app/components/svg/CloseIcon.tsx @@ -0,0 +1,11 @@ +import React from 'react' + +function CloseIcon() { + return ( + + ) +} + +export default CloseIcon \ No newline at end of file