From f78221b268b8b163d687076d2840428764e452fb Mon Sep 17 00:00:00 2001 From: Zehui Zheng Date: Tue, 12 Mar 2024 23:42:40 +0800 Subject: [PATCH] fix frontend for the migration --- frontend/src/model/reader.ts | 28 +++++++++++++++++----------- frontend/src/model/state.ts | 13 +++++++++---- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/frontend/src/model/reader.ts b/frontend/src/model/reader.ts index cbce1e7..8f29cfd 100644 --- a/frontend/src/model/reader.ts +++ b/frontend/src/model/reader.ts @@ -1,7 +1,7 @@ import { useQuery } from "@apollo/client"; import { gql } from "./__generated__/gql"; import { CompletionStatus } from "./__generated__/graphql"; -import { BugLessState, AppBounty, SendExploit, Voucher } from "./state"; +import { BugLessState, AppBounty, SendExploitInput, Voucher } from "./state"; type ReaderLoadingResult = { kind: "loading"; @@ -88,10 +88,11 @@ function GetLatestState(): ReaderResult { if (loading) return { kind: "loading" }; if (error) return { kind: "error", message: error.message }; let reportEdge = data?.reports.edges.findLast((edge) => - edge.node.payload.startsWith("0x0157896b8c"), + // starts with {"Bounties": + edge.node.payload.startsWith("0x7b22426f756e74696573223a"), ); let payload = reportEdge?.node.payload; - let stateBytes = fromHexString(payload?.substring(12)); + let stateBytes = fromHexString(payload?.substring(2)); // remove '0x' let stateJson = null; if (stateBytes !== undefined) { let stateText = new TextDecoder().decode(stateBytes); @@ -108,10 +109,11 @@ function GetBounty(bountyIndex: number): ReaderResult { pollInterval: 500, // ms }); let reportEdge = reportsQuery.data?.reports.edges.findLast((edge) => - edge.node.payload.startsWith("0x0157896b8c"), + // starts with {"Bounties": + edge.node.payload.startsWith("0x7b22426f756e74696573223a"), ); let payload = reportEdge?.node.payload; - let stateBytes = fromHexString(payload?.substring(12)); + let stateBytes = fromHexString(payload?.substring(2)); // remove '0x' let stateJson = null; if (stateBytes !== undefined) { let stateText = new TextDecoder().decode(stateBytes); @@ -125,13 +127,17 @@ function GetBounty(bountyIndex: number): ReaderResult { inputIndex: exploit?.InputIndex as number, // this is fine because of skip }, }); - let sendExploitBytes = fromHexString( - exploitQuery.data?.input.payload?.substring(10), + let SendExploitInputBytes = fromHexString( + exploitQuery.data?.input.payload?.substring(2), // remove '0x' ); - if (exploit && sendExploitBytes) { - let sendExploitText = new TextDecoder().decode(sendExploitBytes); - let sendExploit = JSON.parse(sendExploitText) as SendExploit; - exploit.Code = atob(sendExploit.Exploit); + if (exploit && SendExploitInputBytes) { + let SendExploitInputText = new TextDecoder().decode( + SendExploitInputBytes, + ); + let SendExploitInput = JSON.parse( + SendExploitInputText, + ) as SendExploitInput; + exploit.Code = atob(SendExploitInput.payload.exploit); } if (reportsQuery.loading) return { kind: "loading" }; diff --git a/frontend/src/model/state.ts b/frontend/src/model/state.ts index 730bd8d..67eeca4 100644 --- a/frontend/src/model/state.ts +++ b/frontend/src/model/state.ts @@ -42,10 +42,15 @@ export interface Sponsorship { } export interface SendExploit { - BountyIndex: number; - Name: string; - ImgLink: string; - Exploit: string; + bountyIndex: number; + name: string; + imgLink: string; + exploit: string; +} + +export interface SendExploitInput { + kind: string; + payload: SendExploit; } export interface Voucher {