Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: start button stuck on loading #550

Merged
merged 3 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions frontend/components/MainPage/header/AgentButton/AgentButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@ import { AgentStartingButton } from './AgentStartingButton';
import { AgentStoppingButton } from './AgentStoppingButton';

export const AgentButton = () => {
const {
selectedService,
isFetched: isServicesLoaded,
selectedServiceStatusOverride,
} = useServices();
const { selectedService, isFetched, selectedServiceStatusOverride } =
useServices();

const {
isEligibleForStaking,
Expand All @@ -30,7 +27,7 @@ export const AgentButton = () => {
} = useActiveStakingContractInfo();

const button = useMemo(() => {
if (!isServicesLoaded || !isSelectedStakingContractDetailsLoaded) {
if (!isFetched || !isSelectedStakingContractDetailsLoaded) {
return (
<Button type="primary" size="large" disabled loading>
Loading...
Expand Down Expand Up @@ -68,7 +65,7 @@ export const AgentButton = () => {

return <CannotStartAgentDueToUnexpectedError />;
}, [
isServicesLoaded,
isFetched,
isSelectedStakingContractDetailsLoaded,
selectedServiceStatusOverride,
selectedService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ export const AgentNotRunningButton = () => {
!isNil(hasEnoughServiceSlots) &&
!hasEnoughServiceSlots &&
!isServiceStaked
)
) {
return false;
}

const masterSafeOlasBalance = masterSafeBalances?.find(
(walletBalanceResult) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,15 @@ export const StakingRewardsThisEpoch = () => {

const popoverContent = useMemo(() => {
if (!isActiveStakingProgramLoaded) return <Skeleton.Input />;
if (!activeStakingProgramMeta)

if (!activeStakingProgramMeta) {
return (
<div style={{ maxWidth: POPOVER_WIDTH_MEDIUM }}>
You&apos;re not yet in a staking program!
</div>
);
}

return (
<div style={{ maxWidth: POPOVER_WIDTH_MEDIUM }}>
The epoch for {stakingProgramMeta?.name} ends each day at ~{' '}
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/SettingsPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const SettingsMain = () => {
}, [masterSafeBackupAddresses]);

const walletBackup = useMemo(() => {
if (!ownersIsFetched) return <Skeleton />;
if (!ownersIsFetched) return <Skeleton.Input />;
if (!masterSafeBackupAddress) return <NoBackupWallet />;
if (!selectedService?.home_chain) return null;

Expand Down
15 changes: 5 additions & 10 deletions frontend/context/StakingContractDetailsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import {
import { FIVE_SECONDS_INTERVAL } from '@/constants/intervals';
import { REACT_QUERY_KEYS } from '@/constants/react-query-keys';
import { StakingProgramId } from '@/enums/StakingProgram';
import { useService } from '@/hooks/useService';
import { useServices } from '@/hooks/useServices';
import { useStakingProgram } from '@/hooks/useStakingProgram';
import {
ServiceStakingDetails,
StakingContractDetails,
} from '@/types/Autonolas';
import { asMiddlewareChain } from '@/utils/middlewareHelpers';

import { StakingProgramContext } from './StakingProgramProvider';

Expand Down Expand Up @@ -171,18 +171,13 @@ export const StakingContractDetailsProvider = ({
children,
}: PropsWithChildren) => {
const [isPaused, setIsPaused] = useState(false);
const { selectedService, selectedAgentConfig } = useServices();
const { selectedService } = useServices();
const { serviceNftTokenId } = useService(selectedService?.service_config_id);
const { selectedStakingProgramId } = useContext(StakingProgramContext);

const serviceNftTokenId = !isNil(selectedService?.service_config_id)
? selectedService?.chain_configs?.[
asMiddlewareChain(selectedAgentConfig.evmHomeChainId)
]?.chain_data?.token
: null;

const {
data: selectedStakingContractDetails,
isFetched,
isLoading,
refetch,
} = useStakingContractDetailsByStakingProgram({
serviceNftTokenId,
Expand All @@ -200,7 +195,7 @@ export const StakingContractDetailsProvider = ({
<StakingContractDetailsContext.Provider
value={{
selectedStakingContractDetails,
isSelectedStakingContractDetailsLoaded: isFetched,
isSelectedStakingContractDetailsLoaded: !isLoading,
isAllStakingContractDetailsRecordLoaded:
isAllStakingContractDetailsLoaded,
allStakingContractDetailsRecord,
Expand Down
Loading