diff --git a/src/components/Charts/ClaimChart/index.tsx b/src/components/Charts/ClaimChart/index.tsx index 263a464..c8bb095 100644 --- a/src/components/Charts/ClaimChart/index.tsx +++ b/src/components/Charts/ClaimChart/index.tsx @@ -8,8 +8,8 @@ const xGap = 100; const yGap = 100; const yBase = 100; -const isAttack = (cur: number, parent: number): boolean => { - if (parent * 2 === cur) { +const isAttack = (cur: bigint, parent: bigint): boolean => { + if (parent * BigInt(2) === cur) { return true; } return false; @@ -47,7 +47,7 @@ const genNodesAndLinks = (data: ClaimData[]): any => { continue; } queue.push(i); - const deep = depth(current.position); + const deep = depth(BigInt(current.position)); if (deep > maxDepth) { maxDepth = deep; } @@ -74,7 +74,7 @@ const genNodesAndLinks = (data: ClaimData[]): any => { formatter: "attack", }, }; - if (!isAttack(current.position, parent.position)) { + if (!isAttack(BigInt(current.position), BigInt(parent.position))) { node.itemStyle.color = "blue"; link.lineStyle.color = "blue"; link.label.formatter = "defend"; @@ -406,7 +406,7 @@ const genTreeData = (data: ClaimData[]): any => { }, children: [], }; - if (!isAttack(current.position, parent.position)) { + if (!isAttack(BigInt(current.position), BigInt(parent.position))) { node.itemStyle.color = "blue"; node.lineStyle.color = "blue"; node.value = `${current.position}🏁 ${shortenAddress( diff --git a/src/pages/game/[game].tsx b/src/pages/game/[game].tsx index 5e7931d..4fd494f 100644 --- a/src/pages/game/[game].tsx +++ b/src/pages/game/[game].tsx @@ -23,11 +23,11 @@ const GameDetail = () => { const address = (router.query.game as string | undefined) ?? ""; const { data, isLoading } = useClaimData(address); + console.log(data); const { data: game, isLoading: gameLoading } = useLatestGame({ hitsPerPage: 1, q: address, }); - console.log({ game }); const { explorer_l1: EXPLORER_L1, explorer_l2: EXPLORER_L2 } = useNetworkConfig(); return ( diff --git a/src/types/data.ts b/src/types/data.ts index 5e6ab49..15ba8a5 100644 --- a/src/types/data.ts +++ b/src/types/data.ts @@ -23,7 +23,7 @@ export interface ClaimData { claimant: string; bond: number; claim: string; - position: number; + position: string; clock: number; output_block: number; event_id: number; @@ -56,26 +56,26 @@ export interface Amountperday { } export interface BoundProgress { - amount: string, - date: string + amount: string; + date: string; } export interface LatestEvents { - block_hash: string - block_log_indexed: number - block_number: number - block_time: number - blockchain: string - contract_address: string - created_at: number - data: string - event_hash: string - event_name: string - id: number - retry_count: number - status: string - sync_block_id: number - tx_hash: string - tx_index: string - updated_at: number -} \ No newline at end of file + block_hash: string; + block_log_indexed: number; + block_number: number; + block_time: number; + blockchain: string; + contract_address: string; + created_at: number; + data: string; + event_hash: string; + event_name: string; + id: number; + retry_count: number; + status: string; + sync_block_id: number; + tx_hash: string; + tx_index: string; + updated_at: number; +} diff --git a/src/utils/tree.ts b/src/utils/tree.ts index 629d5a7..4ce6b82 100644 --- a/src/utils/tree.ts +++ b/src/utils/tree.ts @@ -1,3 +1,4 @@ -export const depth = (position: number): number => { - return 31 - Math.clz32(position); +export const depth = (position: bigint): number => { + const bitLength = position.toString(2).length; // 将 position 转为二进制字符串并获取其长度 + return 31 - (bitLength - 1); };