-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* build: add dependency for hooks, lint * style: prettier *.ts * style: eslint *.ts * style: forge fmt sol * style: lint tsx * refactor: rm forge eslint
- Loading branch information
Showing
60 changed files
with
3,044 additions
and
2,838 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
lib | ||
types |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1 @@ | ||
node_modules | ||
packages/contracts/node_modules | ||
|
||
# vscode | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
lib | ||
types |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
{ | ||
"solidity.monoRepoSupport": true | ||
"solidity.monoRepoSupport": true, | ||
"editor.formatOnSave": true, | ||
"solidity.formatter": "forge" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,77 @@ | ||
import { useState, useEffect, useRef } from 'react'; | ||
import useChessboard from './useChessboard' | ||
|
||
|
||
import { useState, useEffect, useRef } from "react"; | ||
import useChessboard from "./useChessboard"; | ||
|
||
const useBlockNumber = () => { | ||
|
||
const { getCurrentBlockNumber, roundInterval, startFrom, autoBattleFn, BoardList } = useChessboard() | ||
const { | ||
getCurrentBlockNumber, | ||
roundInterval, | ||
startFrom, | ||
autoBattleFn, | ||
BoardList, | ||
} = useChessboard(); | ||
|
||
const [blockNumber, setBlockNumber] = useState<number>(); | ||
const [startBlockNumber, setStartBlockNumber] = useState<number>(); | ||
|
||
const [isCalculating, setIsCalculating] = useState(false) | ||
|
||
const [isCalculating, setIsCalculating] = useState(false); | ||
|
||
useEffect(() => { | ||
|
||
const initStart = async () => { | ||
const number = await getCurrentBlockNumber(); | ||
const startTime = Number(startFrom) + Number(roundInterval) | ||
const Timeleft = startTime - number | ||
console.log('init battle', Timeleft) | ||
const startTime = Number(startFrom) + Number(roundInterval); | ||
const Timeleft = startTime - number; | ||
console.log("init battle", Timeleft); | ||
|
||
if (Timeleft <= 0) { | ||
await autoBattleFn(); | ||
setIsCalculating(true) | ||
setIsCalculating(true); | ||
} | ||
} | ||
initStart() | ||
|
||
}, []) | ||
}; | ||
initStart(); | ||
}, []); | ||
|
||
useEffect(() => { | ||
|
||
const interval = setInterval(async () => { | ||
const number = await getCurrentBlockNumber(); | ||
const startTime = Number(startFrom) + Number(roundInterval) | ||
const Timeleft = startTime - number | ||
setStartBlockNumber(Timeleft) | ||
const startTime = Number(startFrom) + Number(roundInterval); | ||
const Timeleft = startTime - number; | ||
setStartBlockNumber(Timeleft); | ||
setBlockNumber(number); | ||
if (Timeleft == 0) { | ||
await autoBattleFn(); | ||
setIsCalculating(true) | ||
setIsCalculating(true); | ||
} | ||
|
||
if (Timeleft < 0 && !isCalculating) { | ||
await autoBattleFn(); | ||
setIsCalculating(true) | ||
setIsCalculating(true); | ||
} | ||
|
||
|
||
}, 1000); | ||
|
||
return () => clearInterval(interval); | ||
}, [startFrom, roundInterval, getCurrentBlockNumber,isCalculating]) | ||
}, [startFrom, roundInterval, getCurrentBlockNumber, isCalculating]); | ||
|
||
useEffect(() => { | ||
let calculateInterval: any; | ||
|
||
if ((BoardList?.status == 1) && isCalculating) { | ||
if (BoardList?.status == 1 && isCalculating) { | ||
calculateInterval = setInterval(async () => { | ||
await autoBattleFn(); | ||
}, 1500); | ||
} | ||
|
||
|
||
return () => { | ||
if (calculateInterval) { | ||
clearInterval(calculateInterval); | ||
} | ||
}; | ||
}, [isCalculating, BoardList?.status]); | ||
|
||
|
||
|
||
return { | ||
blockNumber, | ||
roundInterval, | ||
startBlockNumber | ||
} | ||
|
||
} | ||
|
||
startBlockNumber, | ||
}; | ||
}; | ||
|
||
export default useBlockNumber; |
Oops, something went wrong.