Skip to content

Commit 1c638b8

Browse files
committed
Squashed commit of the following:
commit d5dda83 Author: wzrdx <128477299+wzrdx@users.noreply.github.com> Date: Fri Aug 29 18:07:50 2025 +0300 hotfix: Fix fetchRunningJobsWithAliases when 2 apps are deployed on 2 nodes commit d591348 Author: wzrdx <128477299+wzrdx@users.noreply.github.com> Date: Fri Aug 29 17:42:01 2025 +0300 hotfix: Use getMultiNodeEpochsRange in fetchOraclesCount commit 7118012 Merge: b0c3b3f 724652c Author: wzrdx <128477299+wzrdx@users.noreply.github.com> Date: Fri Aug 29 17:20:55 2025 +0300 Merge branch 'main' into develop commit b0c3b3f Author: wzrdx <128477299+wzrdx@users.noreply.github.com> Date: Thu Aug 28 17:50:32 2025 +0300 hotfix: Use tunneling secrets from TunnelsContext, fix the UX of deleting a tunnel with hostname commit 619c405 Author: wzrdx <128477299+wzrdx@users.noreply.github.com> Date: Thu Aug 28 15:46:19 2025 +0300 hotfix: Always fetch secrets, modify secrets feature
1 parent 724652c commit 1c638b8

File tree

4 files changed

+74
-25
lines changed

4 files changed

+74
-25
lines changed

src/lib/api/oracles.tsx

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,21 @@ export const getNodeInfo = (
2626
node_is_online: boolean;
2727
}> => getNodeLastEpoch(nodeAddress).then(({ node_alias, node_is_online }) => ({ node_alias, node_is_online }));
2828

29+
export const getMultiNodeEpochsRange = (nodesWithRanges: Record<types.EthAddress, [number, number]>) => {
30+
return _doPost<types.OraclesDefaultResult & Record<types.EthAddress, types.OraclesAvailabilityResult>>(
31+
'/multi_node_epochs_range',
32+
{
33+
dct_eth_nodes_request: nodesWithRanges,
34+
},
35+
);
36+
};
37+
2938
// *****
3039
// INTERNAL HELPERS
3140
// *****
3241

3342
async function _doGet<T>(endpoint: string) {
34-
const { data } = await axiosOracles.get<{
43+
const { data } = await axiosInstance.get<{
3544
result: (
3645
| {
3746
error: string;
@@ -51,15 +60,32 @@ async function _doGet<T>(endpoint: string) {
5160
return data.result;
5261
}
5362

54-
const axiosOracles = axios.create({
63+
async function _doPost<T>(endpoint: string, body: any) {
64+
const { data } = await axiosInstance.post<{
65+
result: types.OraclesDefaultResult &
66+
(
67+
| {
68+
error: string;
69+
}
70+
| T
71+
);
72+
node_addr: `0xai${string}`;
73+
}>(endpoint, body);
74+
if ('error' in data.result) {
75+
throw new Error(data.result.error);
76+
}
77+
return data.result;
78+
}
79+
80+
const axiosInstance = axios.create({
5581
baseURL: oraclesUrl,
5682
headers: {
5783
Accept: 'application/json',
5884
'Content-Type': 'application/json',
5985
},
6086
});
6187

62-
axiosOracles.interceptors.response.use(
88+
axiosInstance.interceptors.response.use(
6389
(response) => {
6490
return response;
6591
},

src/lib/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,4 @@ export const getDevAddress = (): {
8989
address: import.meta.env.VITE_DEV_ADDRESS,
9090
});
9191

92-
export const isUsingDevAddress = process.env.NODE_ENV === 'development' && false; // TODO: false
92+
export const isUsingDevAddress = process.env.NODE_ENV === 'development' && true; // TODO: false

src/lib/contexts/deployment/deployment-provider.tsx

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -107,25 +107,34 @@ export const DeploymentProvider = ({ children }) => {
107107
functionName: 'getAllJobs',
108108
});
109109

110-
console.log('[DeploymentProvider] SC jobs', runningJobs);
110+
console.log('[DeploymentProvider] Smart contract jobs', runningJobs);
111+
112+
const uniqueAppsWithAliases = _(Object.values(apps))
113+
.map((nodeApps) => {
114+
return Object.entries(nodeApps).map(([alias, app]) => {
115+
return {
116+
alias,
117+
...app,
118+
};
119+
});
120+
})
121+
.flatten()
122+
.filter((app) => app.is_deeployed)
123+
.uniqBy((app) => app.alias)
124+
.value();
111125

112-
let jobsWithAliases: RunningJobWithAlias[] = _(Object.values(apps))
113-
.map((app) => {
114-
const alias: string = Object.keys(app)[0];
115-
const isDeployed = app[alias].is_deeployed;
126+
console.log('[DeploymentProvider] Unique deployed apps with aliases', uniqueAppsWithAliases);
116127

117-
if (!isDeployed) {
118-
console.log('[DeploymentProvider] Job not deployed yet, filtering out', app);
119-
return null;
120-
}
121-
122-
const specs = app[alias].deeploy_specs;
128+
const jobsWithAliases: RunningJobWithAlias[] = _(uniqueAppsWithAliases)
129+
.map((appWithAlias) => {
130+
const alias: string = appWithAlias.alias;
131+
const specs = appWithAlias.deeploy_specs;
123132
const jobId = specs.job_id;
124133

125134
const job = runningJobs.find((job) => Number(job.id) === jobId && job.projectHash === specs.project_id);
126135

127136
if (!job) {
128-
console.log('[DeploymentProvider] Job not found in SC, filtering out', alias, app);
137+
console.log(`[DeploymentProvider] App ${alias} has no matching job in the smart contract`, appWithAlias);
129138
return null;
130139
}
131140

@@ -138,11 +147,7 @@ export const DeploymentProvider = ({ children }) => {
138147
.filter((job) => job !== null)
139148
.value();
140149

141-
console.log('[DeploymentProvider] Jobs before filtering for uniqueness', jobsWithAliases);
142-
143-
jobsWithAliases = _.uniqBy(jobsWithAliases, (job) => job.alias);
144-
145-
console.log('[DeploymentProvider] Unique jobs with running apps data', jobsWithAliases);
150+
console.log('[DeploymentProvider] Running jobs with aliases', jobsWithAliases);
146151

147152
return jobsWithAliases;
148153
};

src/pages/Login.tsx

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ import { PoAIManagerAbi } from '@blockchain/PoAIManager';
33
import LoginCard from '@components/auth/LoginCard';
44
import RestrictedAccess from '@components/auth/RestrictedAccess';
55
import { Spinner } from '@heroui/spinner';
6-
import { getNodeLastEpoch } from '@lib/api/oracles';
7-
import { config, environment, getDevAddress, isUsingDevAddress } from '@lib/config';
6+
import { getMultiNodeEpochsRange } from '@lib/api/oracles';
7+
import { config, environment, getCurrentEpoch, getDevAddress, isUsingDevAddress } from '@lib/config';
88
import { AuthenticationContextType, useAuthenticationContext } from '@lib/contexts/authentication';
99
import { BlockchainContextType, useBlockchainContext } from '@lib/contexts/blockchain';
1010
import { DeploymentContextType, useDeploymentContext } from '@lib/contexts/deployment';
11+
import { isZeroAddress } from '@lib/utils';
1112
import { EthAddress } from '@typedefs/blockchain';
1213
import { ConnectKitButton, useModal } from 'connectkit';
1314
import { useEffect, useState } from 'react';
@@ -78,9 +79,26 @@ function Login() {
7879
}
7980

8081
console.log('Checking oracle ownership...');
81-
const licenses = await fetchLicenses();
82-
const availabilities = await Promise.all(licenses.map((license) => getNodeLastEpoch(license.nodeAddress)));
82+
83+
const linkedLicenses = (await fetchLicenses()).filter((license) => !isZeroAddress(license.nodeAddress));
84+
const currentEpoch = getCurrentEpoch();
85+
86+
const nodesWithRanges = linkedLicenses.reduce(
87+
(acc, license) => {
88+
acc[license.nodeAddress] = [currentEpoch - 1, currentEpoch - 1];
89+
return acc;
90+
},
91+
{} as Record<EthAddress, [number, number]>,
92+
);
93+
94+
if (Object.keys(nodesWithRanges).length === 0) {
95+
return 0;
96+
}
97+
98+
const response = await getMultiNodeEpochsRange(nodesWithRanges);
99+
const availabilities = linkedLicenses.map((license) => response[license.nodeAddress]);
83100
const oracles = availabilities.filter((nodeResponse) => nodeResponse.node_is_oracle);
101+
84102
console.log(`User owns ${oracles.length} oracle${oracles.length === 1 ? '' : 's'}`);
85103

86104
return oracles.length;

0 commit comments

Comments
 (0)