Skip to content

Commit

Permalink
fix: update deps and init start logic (#474)
Browse files Browse the repository at this point in the history
- use a ref to check the initial `handleStart` since auto-mining and
cpu/gpu mining flags may not be ready yet when that initially runs (so
we need the dependencies there)
- also moved `window?.glApp?.stateManager.statusIndex` into an external
var so the value would make a difference to the dep array
- tiny tweak to the orbit animation initial delay


---




https://github.com/user-attachments/assets/4cf9a309-1ccc-4337-b376-39a8375893e5
  • Loading branch information
shanimal08 authored Sep 13, 2024
1 parent 1ebaea9 commit 11f670a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function ButtonOrbitAnimation() {
y: 150 - size / 2,
x: 150 - size / 2,
}}
transition={{ ...orbitTransition, delay: (index + 1) * 1.5 }}
transition={{ ...orbitTransition, delay: index * 1.5 }}
animate={{ rotate: index % 2 === 0 ? 360 : -360, opacity: [0.7, 0.5, 0.8, 1] }}
>
{index % 2 === 0 ? (
Expand Down
16 changes: 9 additions & 7 deletions src/hooks/mining/useMiningUiStateMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useCPUStatusStore } from '@app/store/useCPUStatusStore';
import { useGPUStatusStore } from '@app/store/useGPUStatusStore';
import { useMiningStore } from '@app/store/useMiningStore';
import { setAnimationState } from '@app/visuals';
import { useEffect } from 'react';
import { useEffect, useRef } from 'react';
import { useMiningControls } from './useMiningControls';
import { useShallow } from 'zustand/react/shallow';

Expand All @@ -24,17 +24,19 @@ export const useUiMiningStateMachine = () => {
const gpuIsMining = useGPUStatusStore(useShallow((s) => s.is_mining));
const cpuIsMining = useCPUStatusStore(useShallow((s) => s.is_mining));
const isMining = cpuIsMining || gpuIsMining;

const isSetupFinished = !useAppStateStore(useShallow((s) => s.isSettingUp));

const hasStartedInit = useRef(false);

useEffect(() => {
if (isSetupFinished && isAutoMiningEnabled && isMiningEnabled) {
if (isSetupFinished && !!isAutoMiningEnabled && !!isMiningEnabled && !hasStartedInit.current) {
handleStart();
hasStartedInit.current = true;
}
// Dependencies are intentionally omitted to prevent this effect from running again
}, [isSetupFinished]);
}, [handleStart, isAutoMiningEnabled, isMiningEnabled, isSetupFinished]);

const statusIndex = window?.glApp?.stateManager?.statusIndex;

console.log('window?.glApp?.stateManager', window?.glApp?.stateManager);
useEffect(() => {
if (isSetupFinished && isMiningEnabled && isMining) {
setAnimationState('start');
Expand All @@ -52,13 +54,13 @@ export const useUiMiningStateMachine = () => {
return;
}
}, [
statusIndex,
isSetupFinished,
isMiningEnabled,
isChangingMode,
isMining,
isAutoMiningEnabled,
isMiningInitiated,
setIsChangingMode,
window?.glApp?.stateManager.statusIndex,
]);
};

0 comments on commit 11f670a

Please sign in to comment.