Skip to content

Commit

Permalink
Add customCpu state and functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
vectorisvector committed Nov 28, 2023
1 parent 21f66a8 commit 8d11c8e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 23 deletions.
74 changes: 52 additions & 22 deletions src/app/ierc/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default function Ierc() {
const [logs, setLogs] = useState<string[]>([]);
const [mineRateList, setMineRateList] = useState<number[]>([]);
const [successCount, setSuccessCount] = useState<number>(0);
const [customCpu, setCustomCpu] = useState<number>(0);

const isClient = useIsClient();
const coreCount = useMemo(
Expand All @@ -53,7 +54,8 @@ export default function Ierc() {

const generateWorkers = useCallback(() => {
const newWorkers = [];
for (let i = 0; i < cpu; i++) {
const cpuCount = customCpu > 0 ? customCpu : cpu;
for (let i = 0; i < cpuCount; i++) {
const worker = new Worker(new URL("./mine.js", import.meta.url));
newWorkers.push(worker);

Expand Down Expand Up @@ -91,6 +93,7 @@ export default function Ierc() {
}, [
amount,
cpu,
customCpu,
difficulty,
gasPremium,
privateKey,
Expand Down Expand Up @@ -223,27 +226,54 @@ export default function Ierc() {
</div>

<div className=" flex flex-col gap-2">
<span>cpu 核心数:</span>
<TextField
select
defaultValue={1}
size="small"
disabled={running}
onChange={(e) => {
const text = e.target.value;
setCpu(Number(text));
setMineRateList([]);
}}
>
{new Array(coreCount).fill(null).map((_, index) => (
<MenuItem
key={index}
value={index + 1}
>
{index + 1}
</MenuItem>
))}
</TextField>
<div className=" flex items-center gap-2">
<span>cpu 核心数:</span>
<Button
size="small"
color="secondary"
disabled={running}
onClick={() => {
setCustomCpu((_customCpu) => (_customCpu <= 0 ? 1 : -1));
setMineRateList([]);
}}
>
自定义
</Button>
</div>
{customCpu <= 0 ? (
<TextField
select
defaultValue={1}
size="small"
disabled={running}
onChange={(e) => {
const text = e.target.value;
setCpu(Number(text));
setMineRateList([]);
}}
>
{new Array(coreCount).fill(null).map((_, index) => (
<MenuItem
key={index}
value={index + 1}
>
{index + 1}
</MenuItem>
))}
</TextField>
) : (
<TextField
type="number"
size="small"
placeholder="cpu 核心数,例子:12"
disabled={running}
value={customCpu}
onChange={(e) => {
const num = Number(e.target.value);
!Number.isNaN(num) && setCustomCpu(Math.floor(num));
}}
/>
)}
</div>

<div className=" flex flex-col gap-2">
Expand Down
2 changes: 1 addition & 1 deletion src/components/Log.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface LogProps {
export default function Log({ title, logs, onClear }: LogProps) {
return (
<div className=" mt-5 flex flex-col gap-2">
<div className=" flex items-center gap-5">
<div className=" flex items-center gap-4">
<span>{title}</span>
<Button
variant="contained"
Expand Down

0 comments on commit 8d11c8e

Please sign in to comment.