Skip to content

Commit

Permalink
feat: type change
Browse files Browse the repository at this point in the history
  • Loading branch information
fearlessfe committed Aug 29, 2024
1 parent 8800483 commit 370180a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 29 deletions.
10 changes: 5 additions & 5 deletions src/components/Charts/ClaimChart/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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";
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/pages/game/[game].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
42 changes: 21 additions & 21 deletions src/types/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
}
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;
}
5 changes: 3 additions & 2 deletions src/utils/tree.ts
Original file line number Diff line number Diff line change
@@ -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);
};

0 comments on commit 370180a

Please sign in to comment.