Skip to content

Commit d23a64b

Browse files
committed
Merge branch 'development'
2 parents be402ac + a4733f3 commit d23a64b

File tree

17 files changed

+3378
-31
lines changed

17 files changed

+3378
-31
lines changed

src/App.tsx

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
import Layout from '@components/layout/Layout';
2+
import { Spinner } from '@heroui/spinner';
3+
import { getNodeLastEpoch } from '@lib/api/oracles';
24
import { AuthenticationContextType, useAuthenticationContext } from '@lib/contexts/authentication';
35
import { BlockchainContextType, useBlockchainContext } from '@lib/contexts/blockchain';
46
import { routePath } from '@lib/routes/route-paths';
57
import { isParentRoute, isSimpleRoute, routes } from '@lib/routes/routes';
6-
import { useEffect } from 'react';
7-
import { Navigate, Route, Routes } from 'react-router-dom';
8-
import { useAccount } from 'wagmi';
8+
import { useEffect, useState } from 'react';
9+
import toast from 'react-hot-toast';
10+
import { Navigate, Route, Routes, useNavigate } from 'react-router-dom';
11+
import { useAccount, usePublicClient } from 'wagmi';
912

1013
function App() {
1114
const { authenticated } = useAuthenticationContext() as AuthenticationContextType;
12-
const { setR1Balance } = useBlockchainContext() as BlockchainContextType;
15+
const { setR1Balance, fetchLicenses } = useBlockchainContext() as BlockchainContextType;
16+
17+
const [isLoading, setLoading] = useState(false);
1318

1419
const { address } = useAccount();
20+
const navigate = useNavigate();
21+
const publicClient = usePublicClient();
1522

1623
useEffect(() => {
1724
if (!address && !authenticated) {
@@ -20,6 +27,41 @@ function App() {
2027
}
2128
}, [address, authenticated]);
2229

30+
useEffect(() => {
31+
if (!publicClient) {
32+
return;
33+
} else {
34+
if (authenticated && !!address && publicClient) {
35+
if (process.env.NODE_ENV !== 'development') {
36+
checkOracleOwnership();
37+
}
38+
}
39+
}
40+
}, [authenticated, address, publicClient]);
41+
42+
const checkOracleOwnership = async () => {
43+
setLoading(true);
44+
45+
try {
46+
console.log('[checkOracleOwnership] Checking oracle ownership');
47+
48+
const licenses = await fetchLicenses();
49+
const nodeResponses = await Promise.all(licenses.map((license) => getNodeLastEpoch(license.nodeAddress)));
50+
51+
const hasOracle = nodeResponses.some((nodeResponse) => nodeResponse.node_is_oracle);
52+
console.log('[checkOracleOwnership] has oracle', hasOracle);
53+
54+
if (!hasOracle) {
55+
navigate(routePath.notAllowed);
56+
}
57+
} catch (error) {
58+
console.error('Error checking oracle ownership', error);
59+
toast.error('Error checking oracle ownership.');
60+
} finally {
61+
setLoading(false);
62+
}
63+
};
64+
2365
return (
2466
<>
2567
<Routes>
@@ -54,6 +96,11 @@ function App() {
5496
</Routes>
5597

5698
{/* Global overlays */}
99+
{isLoading && (
100+
<div className="center-all col backdrop-blur-xs fixed bottom-0 left-0 right-0 top-0 gap-6 bg-white/50 p-8">
101+
<Spinner />
102+
</div>
103+
)}
57104
</>
58105
);
59106
}

0 commit comments

Comments
 (0)