Skip to content

Commit 0e17fa5

Browse files
authored
Merge pull request #404 from valory-xyz/staging
staging to main
2 parents f879340 + 43d1763 commit 0e17fa5

9 files changed

+65
-10
lines changed

frontend/context/RewardProvider.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { AutonolasService } from '@/service/Autonolas';
1818

1919
import { OnlineStatusContext } from './OnlineStatusProvider';
2020
import { ServicesContext } from './ServicesProvider';
21-
import { StakingProgramContext } from './StakingProgramContext';
21+
import { StakingProgramContext } from './StakingProgramProvider';
2222

2323
export const RewardContext = createContext<{
2424
accruedServiceStakingRewards?: number;

frontend/context/StakingContractInfoProvider.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { AutonolasService } from '@/service/Autonolas';
1818
import { StakingContractInfo } from '@/types/Autonolas';
1919

2020
import { ServicesContext } from './ServicesProvider';
21-
import { StakingProgramContext } from './StakingProgramContext';
21+
import { StakingProgramContext } from './StakingProgramProvider';
2222

2323
type StakingContractInfoContextProps = {
2424
activeStakingContractInfo?: Partial<StakingContractInfo>;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { PropsWithChildren, useCallback, useEffect, useRef } from 'react';
2+
3+
import { DeploymentStatus } from '@/client';
4+
import { useElectronApi } from '@/hooks/useElectronApi';
5+
import { useReward } from '@/hooks/useReward';
6+
import { useServices } from '@/hooks/useServices';
7+
8+
const Notifications = {
9+
AgentEarned:
10+
"Your agent earned its rewards! It's now idle and will resume working next epoch.",
11+
};
12+
13+
export const SystemNotificationTriggers = ({ children }: PropsWithChildren) => {
14+
const electronApi = useElectronApi();
15+
const { serviceStatus } = useServices();
16+
const { isEligibleForRewards } = useReward();
17+
18+
const prevIsEligibleForRewards = useRef<boolean>();
19+
20+
// Notify the user when the agent earns rewards
21+
const handleAgentEarned = useCallback(() => {
22+
if (!electronApi.showNotification) return;
23+
24+
// ignore if agent is not running
25+
if (serviceStatus !== DeploymentStatus.DEPLOYED) return;
26+
// ignore if eligibility is not yet defined
27+
if (isEligibleForRewards === undefined) return;
28+
// ignore if agent was previously eligible and is still eligible
29+
if (prevIsEligibleForRewards.current && isEligibleForRewards) return;
30+
// ignore if eligibility has not changed
31+
if (prevIsEligibleForRewards.current === isEligibleForRewards) return;
32+
33+
// show notification when agent becomes eligible for rewards
34+
// (and was not previously eligible)
35+
if (isEligibleForRewards && prevIsEligibleForRewards.current === false) {
36+
electronApi.showNotification(Notifications.AgentEarned);
37+
}
38+
39+
prevIsEligibleForRewards.current = isEligibleForRewards;
40+
}, [electronApi, isEligibleForRewards, serviceStatus]);
41+
42+
useEffect(() => {
43+
if (!electronApi.showNotification) return;
44+
// Show notification when agent earns rewards
45+
handleAgentEarned();
46+
}, [electronApi, handleAgentEarned, isEligibleForRewards, serviceStatus]);
47+
48+
return children;
49+
};

frontend/hooks/useStakingProgram.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useContext, useMemo } from 'react';
33
import { Chain } from '@/client';
44
import { SERVICE_STAKING_TOKEN_MECH_USAGE_CONTRACT_ADDRESSES } from '@/constants/contractAddresses';
55
import { STAKING_PROGRAM_META } from '@/constants/stakingProgramMeta';
6-
import { StakingProgramContext } from '@/context/StakingProgramContext';
6+
import { StakingProgramContext } from '@/context/StakingProgramProvider';
77

88
/**
99
* Hook to get the active staking program and its metadata, and the default staking program.

frontend/pages/_app.tsx

+7-4
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ import { ServicesProvider } from '@/context/ServicesProvider';
1717
import { SettingsProvider } from '@/context/SettingsProvider';
1818
import { SetupProvider } from '@/context/SetupProvider';
1919
import { StakingContractInfoProvider } from '@/context/StakingContractInfoProvider';
20-
import { StakingProgramProvider } from '@/context/StakingProgramContext';
20+
import { StakingProgramProvider } from '@/context/StakingProgramProvider';
2121
import { StoreProvider } from '@/context/StoreProvider';
22+
import { SystemNotificationTriggers } from '@/context/SystemNotificationTriggers';
2223
import { WalletProvider } from '@/context/WalletProvider';
2324
import { mainTheme } from '@/theme';
2425

@@ -48,9 +49,11 @@ export default function App({ Component, pageProps }: AppProps) {
4849
<ModalProvider>
4950
{isMounted ? (
5051
<QueryClientProvider client={queryClient}>
51-
<Layout>
52-
<Component {...pageProps} />
53-
</Layout>
52+
<SystemNotificationTriggers>
53+
<Layout>
54+
<Component {...pageProps} />
55+
</Layout>
56+
</SystemNotificationTriggers>
5457
</QueryClientProvider>
5558
) : null}
5659
</ModalProvider>

operate/services/service.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import typing as t
2929
from copy import copy, deepcopy
3030
from dataclasses import dataclass
31+
from json import JSONDecodeError
3132
from pathlib import Path
3233
from time import sleep
3334
from traceback import print_exc
@@ -758,8 +759,10 @@ def deployment(self) -> Deployment:
758759
"""Load deployment object for the service."""
759760
if not (self.path / DEPLOYMENT_JSON).exists():
760761
self._deployment = Deployment.new(path=self.path)
761-
if self._deployment is None:
762+
try:
762763
self._deployment = Deployment.load(path=self.path)
764+
except JSONDecodeError:
765+
self._deployment = Deployment.new(path=self.path)
763766
return t.cast(Deployment, self._deployment)
764767

765768
@staticmethod

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,5 @@
6363
"download-binaries": "sh download_binaries.sh",
6464
"build:pearl": "sh build_pearl.sh"
6565
},
66-
"version": "0.1.0-rc168"
66+
"version": "0.1.0-rc173"
6767
}

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "olas-operate-middleware"
3-
version = "0.1.0-rc168"
3+
version = "0.1.0-rc173"
44
description = ""
55
authors = ["David Vilela <[email protected]>", "Viraj Patel <[email protected]>"]
66
readme = "README.md"

0 commit comments

Comments
 (0)