Skip to content

Commit

Permalink
fix: start button stuck on loading (#550)
Browse files Browse the repository at this point in the history
* feat: update Skeleton component in SettingsPage for improved loading state

* refactor: simplify service loading state management in AgentButton and StakingContractDetailsProvider

* fix: add missing braces for conditional checks in AgentNotRunningButton and StakingRewardsThisEpoch components
  • Loading branch information
mohandast52 authored Dec 9, 2024
1 parent e608a85 commit c0a8bc6
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 20 deletions.
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

0 comments on commit c0a8bc6

Please sign in to comment.