Skip to content

Commit ce615ef

Browse files
committed
fixed solana
1 parent 93f9cd8 commit ce615ef

File tree

10 files changed

+250
-237
lines changed

10 files changed

+250
-237
lines changed

src/App.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import { HashRouter as Router, Route, Routes } from "react-router-dom";
44
import { Home, Region } from "./pages";
55
import { useDaemonContext } from "./providers/DaemonProvider";
66
import { createOrGetWallet, getCurrentPassportInfo, tryToRequireFreePassport } from "./services/wallets";
7-
import { getAllNodes, startMiningV2 } from "./services/mining";
7+
import { getAllNodes } from "./services/mining";
8+
import {checkCurrentRate} from "./services/passportPurchase";
89
import { CoNET_Data, setCoNET_Data } from "./utils/globals";
910
import { listenProfileVer } from "./services/listeners";
1011
import Vip from './pages/Vip';
@@ -25,8 +26,11 @@ import Transfer from './pages/Transfer';
2526
global.Buffer = require('buffer').Buffer;
2627

2728
function App() {
28-
const { setProfiles, setMiningData, allRegions, setClosestRegion, setaAllNodes, setServerIpAddress, setServerPort, _vpnTimeUsedInMin, setActivePassportUpdated, setActivePassport } = useDaemonContext();
29-
29+
const { setProfiles, setMiningData, allRegions, setClosestRegion, setaAllNodes, setServerIpAddress, setServerPort, _vpnTimeUsedInMin, setActivePassportUpdated, setActivePassport, setRandomSolanaRPC, randomSolanaRPC } = useDaemonContext();
30+
const setSOlanaRPC = (allNodes: nodes_info[]) => {
31+
const randomIndex = Math.floor(Math.random() * (allNodes.length - 1))
32+
setRandomSolanaRPC(allNodes[randomIndex])
33+
}
3034
useEffect(() => {
3135
const handlePassport = async () => {
3236
await tryToRequireFreePassport();
@@ -75,16 +79,16 @@ function App() {
7579

7680
const profiles = await createOrGetWallet(secretPhrase);
7781
setProfiles(profiles);
78-
listenProfileVer(setProfiles, setActivePassport, handlePassport);
79-
82+
listenProfileVer(setProfiles, setActivePassport, handlePassport, setMiningData);
83+
checkCurrentRate(setMiningData);
8084
getAllNodes(allRegions, setClosestRegion, (allNodes: nodes_info[]) => {
81-
setaAllNodes(allNodes)
82-
85+
setSOlanaRPC(allNodes)
86+
const randomIndex = Math.floor(Math.random() * (allNodes.length - 1))
87+
setRandomSolanaRPC(allNodes[randomIndex])
8388
if (!CoNET_Data || !CoNET_Data?.profiles) {
8489
return
8590
}
86-
87-
startMiningV2(CoNET_Data?.profiles?.[0], allRegions, setMiningData);
91+
8892
});
8993

9094
handlePassport();

src/components/AccountList/index.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ interface AccountListProps {
2323

2424
export default function AccountList({ showMainWallet = true, simplifiedView = false, spInUsd = 0, solInUsd = 0 }: AccountListProps) {
2525
const [openAccountList, setOpenAccountList] = useState<string[]>([]);
26-
const { profiles, activePassport, setProfiles } = useDaemonContext();
26+
const { profiles, activePassport, setProfiles, randomSolanaRPC, getAllNodes } = useDaemonContext();
2727

2828
const [mainAccountAddressCopied, setMainAccountAddressCopied] = useState(false);
2929
const [solanaAccountAddressCopied, setSolanaAccountAddressCopied] = useState(false);
@@ -61,7 +61,19 @@ export default function AccountList({ showMainWallet = true, simplifiedView = fa
6161
setIsRefreshingSolanaBalances(true);
6262

6363
try {
64-
await refreshSolanaBalances(profiles?.[1]);
64+
let _randomSolanaRPC = randomSolanaRPC
65+
if (!_randomSolanaRPC) {
66+
const nodes = getAllNodes
67+
const index = Math.floor(Math.random() * (nodes.length - 1))
68+
await refreshSolanaBalances(profiles?.[1], nodes[index]);
69+
70+
} else {
71+
await refreshSolanaBalances(profiles?.[1], _randomSolanaRPC);
72+
}
73+
74+
75+
76+
6577

6678
storeSystemData();
6779

src/pages/Home/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const RenderButton = ({ errorMessage, handleTogglePower, isConnectionLoading, po
9090

9191

9292
const Home = () => {
93-
const { power, setPower, profiles, sRegion, setSRegion, setAllRegions, allRegions, setIsRandom, getAllNodes, closestRegion, _vpnTimeUsedInMin } = useDaemonContext();
93+
const { power, setPower, profiles, sRegion, setSRegion, setAllRegions, allRegions, setIsRandom, getAllNodes, closestRegion, _vpnTimeUsedInMin, randomSolanaRPC, setRandomSolanaRPC } = useDaemonContext();
9494
const [isInitialLoading, setIsInitialLoading] = useState<boolean>(true);
9595
const [isConnectionLoading, setIsConnectionLoading] = useState<boolean>(false)
9696
const [initPercentage, setInitPercentage] = useState<number>(0);

src/providers/DaemonProvider.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ type DaemonContext = {
3838
setPurchasingPlan: (val: string) => void
3939
purchasingPlanPaymentTime: string
4040
setPurchasingPlanPaymentTime: (val: string) => void
41+
randomSolanaRPC: nodes_info|null
42+
setRandomSolanaRPC: (val: nodes_info) => void;
4143
};
4244

4345
type DaemonProps = {
@@ -82,6 +84,8 @@ const defaultContextValue: DaemonContext = {
8284
setPurchasingPlan: () => { },
8385
purchasingPlanPaymentTime: "monthly",
8486
setPurchasingPlanPaymentTime: () => { },
87+
setRandomSolanaRPC: () => { },
88+
randomSolanaRPC: null
8589
};
8690

8791
const Daemon = createContext<DaemonContext>(defaultContextValue);
@@ -111,6 +115,7 @@ export function DaemonProvider({ children }: DaemonProps) {
111115
const [activePassport, setActivePassport] = useState<any>(null);
112116
const [purchasingPlan, setPurchasingPlan] = useState<string>("premium");
113117
const [purchasingPlanPaymentTime, setPurchasingPlanPaymentTime] = useState<string>("monthly");
118+
const [randomSolanaRPC, setRandomSolanaRPC] = useState<nodes_info|null>(null);
114119

115120
useEffect(() => {
116121
{
@@ -121,7 +126,7 @@ export function DaemonProvider({ children }: DaemonProps) {
121126

122127

123128
return (
124-
<Daemon.Provider value={{ power, setPower, sRegion, setSRegion, allRegions, setAllRegions, closestRegion, setClosestRegion, isRandom, setIsRandom, miningData, setMiningData, profiles, setProfiles, isMiningUp, setIsMiningUp, getAllNodes, setaAllNodes, serverIpAddress, setServerIpAddress, serverPort, setServerPort, serverPac, setServerPac, _vpnTimeUsedInMin, isPassportInfoPopupOpen, setIsPassportInfoPopupOpen, activePassportUpdated, setActivePassportUpdated, activePassport, setActivePassport, isSelectPassportPopupOpen, setIsSelectPassportPopupOpen, purchasingPlan, setPurchasingPlan, purchasingPlanPaymentTime, setPurchasingPlanPaymentTime }}>
129+
<Daemon.Provider value={{ power, setPower, sRegion, setSRegion, allRegions, setAllRegions, closestRegion, setClosestRegion, isRandom, setIsRandom, miningData, setMiningData, profiles, setProfiles, isMiningUp, setIsMiningUp, getAllNodes, setaAllNodes, serverIpAddress, setServerIpAddress, serverPort, setServerPort, serverPac, setServerPac, _vpnTimeUsedInMin, isPassportInfoPopupOpen, setIsPassportInfoPopupOpen, activePassportUpdated, setActivePassportUpdated, activePassport, setActivePassport, isSelectPassportPopupOpen, setIsSelectPassportPopupOpen, purchasingPlan, setPurchasingPlan, purchasingPlanPaymentTime, setPurchasingPlanPaymentTime, setRandomSolanaRPC, randomSolanaRPC}}>
125130
{children}
126131
</Daemon.Provider>
127132
);

src/services/listeners.ts

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
} from "../utils/globals";
1515
import contracts from "../utils/contracts";
1616
import { initProfileTokens } from "../utils/utils";
17+
import {checkCurrentRate} from '../services/passportPurchase'
1718
import {
1819
getPassportsInfoForProfile,
1920
getVpnTimeUsed,
@@ -28,6 +29,7 @@ const listenProfileVer = async (
2829
_setProfiles: (profiles: profile[]) => void,
2930
_setActivePassport: (profiles: freePassport) => void,
3031
_updateCurrentPassport: () => Promise<void>,
32+
setMiningData: (response: nodeResponse) => void
3133
) => {
3234
epoch = await conetProvider.getBlockNumber();
3335

@@ -49,7 +51,8 @@ const listenProfileVer = async (
4951
runningList.push(getProfileAssets(profiles[0], profiles[1]));
5052

5153
await Promise.all(runningList);
52-
54+
// get rate update
55+
checkCurrentRate (setMiningData);
5356
await getVpnTimeUsed();
5457

5558
await getPassportsInfoForProfile(profiles[0]);
@@ -84,15 +87,13 @@ const getProfileAssets = async (profile: profile, solanaProfile: profile) => {
8487
profile.tokens = initProfileTokens();
8588
}
8689

87-
const [cCNTP, conet, conetDepin, conet_eth, eth, sol, sp] =
90+
const [cCNTP, conet, conetDepin, conet_eth, eth] =
8891
await Promise.all([
8992
scanCCNTP(key),
9093
scanCONETHolesky(key),
9194
scanCONETDepin(key),
9295
scanConetETH(key),
93-
scanETH(key),
94-
scanSolanaSol(solanaKey),
95-
scanSolanaSp(solanaKey),
96+
scanETH(key)
9697
]);
9798

9899
if (profile.tokens?.cCNTP) {
@@ -177,34 +178,6 @@ const getProfileAssets = async (profile: profile, solanaProfile: profile) => {
177178
};
178179
}
179180

180-
if (solanaProfile.tokens?.sol) {
181-
solanaProfile.tokens.sol.balance =
182-
sol === false ? solanaProfile.tokens.sol.balance : sol?.toFixed(6);
183-
} else {
184-
solanaProfile.tokens.sol = {
185-
balance: sol === false ? "" : sol?.toFixed(6),
186-
network: "Solana Mainnet",
187-
decimal: 18,
188-
contract: "",
189-
name: "sol",
190-
};
191-
}
192-
193-
if (solanaProfile.tokens?.sp) {
194-
solanaProfile.tokens.sp.balance =
195-
sp === false
196-
? solanaProfile.tokens.sp.balance
197-
: parseFloat(sp).toFixed(6);
198-
} else {
199-
solanaProfile.tokens.sp = {
200-
balance: sp === false ? "" : parseFloat(sp).toFixed(6),
201-
network: "Solana Mainnet",
202-
decimal: 18,
203-
contract: "",
204-
name: "sp",
205-
};
206-
}
207-
208181
const temp = CoNET_Data;
209182

210183
if (!temp) {
@@ -250,7 +223,7 @@ const scanETH = async (walletAddr: string) => {
250223
return await scan_natural_balance(walletAddr, ethProvider);
251224
};
252225

253-
const scanSolanaSol = async (walletAddr: string) => {
226+
const scanSolanaSol = async (walletAddr: string, randomSolanaRPC: string) => {
254227
try {
255228
// Validate wallet address format
256229
if (!PublicKey.isOnCurve(walletAddr)) {
@@ -264,7 +237,7 @@ const scanSolanaSol = async (walletAddr: string) => {
264237
params: [walletAddr],
265238
};
266239

267-
const response = await fetch(solanaRpc, {
240+
const response = await fetch(randomSolanaRPC, {
268241
method: "POST",
269242
headers: {
270243
"Content-Type": "application/json",
@@ -288,8 +261,8 @@ const scanSolanaSol = async (walletAddr: string) => {
288261
}
289262
};
290263

291-
const scanSolanaSp = async (walletAddr: string) => {
292-
return await scan_spl_balance(walletAddr, contracts.PassportSolana.address);
264+
const scanSolanaSp = async (walletAddr: string, solanaRPC_url: string) => {
265+
return await scan_spl_balance(walletAddr, contracts.PassportSolana.address, solanaRPC_url);
293266
};
294267

295268
const scan_erc20_balance: (
@@ -324,7 +297,7 @@ const scan_natural_balance = async (walletAddr: string, provider: any) => {
324297
}
325298
};
326299

327-
const scan_spl_balance = async (walletAddr: string, tokenAddress: string) => {
300+
const scan_spl_balance = async (walletAddr: string, tokenAddress: string, solanaRPC_url: string ) => {
328301
try {
329302
const TOKEN_PROGRAM_ID = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"; // Solana SPL Token Program ID
330303

@@ -339,7 +312,7 @@ const scan_spl_balance = async (walletAddr: string, tokenAddress: string) => {
339312
],
340313
};
341314

342-
const response = await fetch(solanaRpc, {
315+
const response = await fetch(solanaRPC_url, {
343316
method: "POST",
344317
headers: {
345318
"Content-Type": "application/json",

0 commit comments

Comments
 (0)