Skip to content

Commit

Permalink
fix frontend for the migration
Browse files Browse the repository at this point in the history
  • Loading branch information
ZzzzHui committed Mar 12, 2024
1 parent 8e78399 commit f78221b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
28 changes: 17 additions & 11 deletions frontend/src/model/reader.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -88,10 +88,11 @@ function GetLatestState(): ReaderResult<BugLessState> {
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);
Expand All @@ -108,10 +109,11 @@ function GetBounty(bountyIndex: number): ReaderResult<AppBounty> {
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);
Expand All @@ -125,13 +127,17 @@ function GetBounty(bountyIndex: number): ReaderResult<AppBounty> {
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" };
Expand Down
13 changes: 9 additions & 4 deletions frontend/src/model/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f78221b

Please sign in to comment.