Skip to content

Commit 9c9c460

Browse files
Merge branch 'test' of github.com:CoNET-project/SilentPassUI into test
2 parents 1a44300 + a3e151c commit 9c9c460

File tree

4 files changed

+103
-73
lines changed

4 files changed

+103
-73
lines changed

src/App.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useDaemonContext } from "./providers/DaemonProvider";
66
import { createOrGetWallet, getCurrentPassportInfo, tryToRequireFreePassport } from "./services/wallets";
77
import { getAllNodes } from "./services/mining";
88
import { checkCurrentRate } from "./services/passportPurchase";
9-
import { CoNET_Data, setCoNET_Data } from "./utils/globals";
9+
import { CoNET_Data, setCoNET_Data, setGlobalAllNodes } from "./utils/globals";
1010
import { listenProfileVer } from "./services/listeners";
1111
import Vip from './pages/Vip';
1212
import Wallet from './pages/Wallet';
@@ -98,6 +98,7 @@ function App() {
9898
getAllNodes(allRegions, setClosestRegion, (allNodes: nodes_info[]) => {
9999
setSOlanaRPC(allNodes)
100100
setaAllNodes(allNodes)
101+
setGlobalAllNodes(allNodes)
101102
const randomIndex = Math.floor(Math.random() * (allNodes.length - 1))
102103
setRandomSolanaRPC(allNodes[randomIndex])
103104
if (!CoNET_Data || !CoNET_Data?.profiles) {

src/services/listeners.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
import {
99
CoNET_Data,
1010
currentPageInvitees,
11+
globalAllNodes,
1112
processingBlock,
1213
setCoNET_Data,
1314
setProcessingBlock,
@@ -52,10 +53,11 @@ const listenProfileVer = async (
5253
await getProfileAssets(profiles[0], profiles[1]);
5354
await getVpnTimeUsed();
5455
await getSpClubInfo(profiles[0], currentPageInvitees);
55-
// const receivedTransactions = await getReceivedAmounts(
56-
// profiles[1].keyID
57-
// );
58-
// console.log(receivedTransactions);
56+
const receivedTransactions = await getReceivedAmounts(
57+
profiles[1].keyID,
58+
globalAllNodes
59+
);
60+
console.log(receivedTransactions);
5961
}
6062

6163
if (block % 2 === 0) {

src/services/wallets.ts

Lines changed: 88 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ const refreshSolanaBalances = async (
688688
if (!node) {
689689
return;
690690
}
691-
const solanaRPC_url = `https://${node.domain}/solana-rpc`;
691+
const solanaRPC_url = `https://${node.domain}`;
692692
try {
693693
const [sol, sp] = await Promise.all([
694694
scanSolanaSol(solanaProfile.keyID, solanaRPC_url),
@@ -946,13 +946,16 @@ const getSpClubMemberId = async (profile: profile) => {
946946
return profile.spClub.memberId;
947947
};
948948

949-
async function getReceivedAmounts(walletAddress: string) {
950-
const connection = new Connection(solanaRpc, "confirmed");
951-
949+
async function getReceivedAmounts(
950+
walletAddress: string,
951+
allNodes: nodes_info[]
952+
) {
952953
try {
953954
const walletPubKey = new PublicKey(walletAddress);
954955
const senderPubKey = new PublicKey(rewardWalletAddress);
955956

957+
const connection = new Connection(solanaRpc, "confirmed");
958+
956959
// Step 1: Get transaction signatures
957960
const signatures = await connection.getSignaturesForAddress(walletPubKey, {
958961
limit: 20,
@@ -965,74 +968,91 @@ async function getReceivedAmounts(walletAddress: string) {
965968

966969
// For only one transaction it works. Here's an example.
967970
// For multiple transactions it fails because the server doesn't support it.
968-
// const transaction = await connection.getTransaction(
969-
// signatures[0].signature,
970-
// {
971-
// commitment: "confirmed",
972-
// maxSupportedTransactionVersion: 0, // Ensures we handle versioned transactions
973-
// }
974-
// );
975-
// console.log(transaction);
976-
977-
// Step 2: Fetch all transactions in **one batch request**
978-
const transactions = await connection.getTransactions(
979-
signatures.map((sig) => sig.signature),
980-
{ commitment: "confirmed" }
971+
const _node1 = allNodes[Math.floor(Math.random() * (allNodes.length - 1))];
972+
const _connection1 = new Connection(
973+
`https://${_node1.domain}`,
974+
"confirmed"
981975
);
982-
// Step 3: Filter transactions where sender matches
983-
const receivedTransactions = transactions
984-
.filter((tx: any) => tx && tx.meta)
985-
.map((tx) => {
986-
if (!tx || !tx.meta) return null;
987-
988-
// Get account balances before and after the transaction
989-
const preBalances = tx.meta.preBalances;
990-
const postBalances = tx.meta.postBalances;
991-
992-
// Get account keys (supports both legacy & versioned transactions)
993-
const accountKeys =
994-
tx.transaction.message.getAccountKeys().staticAccountKeys;
995-
996-
// Find the index of the recipient (walletAddress) in the account keys
997-
const recipientIndex = accountKeys.findIndex(
998-
(key: any) => key.toBase58() === walletPubKey.toBase58()
999-
);
1000-
1001-
if (recipientIndex === -1) return null; // Wallet not found in the transaction
1002-
1003-
// Calculate SOL received (in lamports, convert to SOL)
1004-
const solReceived =
1005-
(postBalances[recipientIndex] - preBalances[recipientIndex]) / 1e9;
1006-
1007-
// Extract token transfers (SPL tokens)
1008-
const tokenTransfers = tx.meta.postTokenBalances?.map(
1009-
(tokenBalance: any) => {
1010-
const preToken = tx?.meta?.preTokenBalances?.find(
1011-
(pre) =>
1012-
pre.mint === tokenBalance.mint && pre.owner === walletAddress
1013-
);
1014-
1015-
const receivedAmount =
1016-
(tokenBalance.uiTokenAmount.uiAmount || 0) -
1017-
(preToken?.uiTokenAmount.uiAmount || 0);
1018-
1019-
return {
1020-
mint: tokenBalance.mint,
1021-
receivedAmount,
1022-
};
1023-
}
1024-
);
976+
const transaction = await _connection1.getTransaction(
977+
signatures[0].signature,
978+
{
979+
commitment: "confirmed",
980+
maxSupportedTransactionVersion: 0, // Ensures we handle versioned transactions
981+
}
982+
);
983+
console.log(transaction);
1025984

1026-
return {
1027-
signature: tx.transaction.signatures[0],
1028-
solReceived,
1029-
tokenTransfers,
1030-
};
1031-
});
985+
// Step 2: Fetch transactions with a delay to avoid rate limits
986+
// const transactions = [];
987+
// for (const sig of signatures) {
988+
// const _node = allNodes[Math.floor(Math.random() * (allNodes.length - 1))];
1032989

1033-
console.log(receivedTransactions.filter((tx: any) => tx !== null));
990+
// const _connection = new Connection(
991+
// `https://${_node.domain}/solana-rpc`,
992+
// "confirmed"
993+
// );
1034994

1035-
return receivedTransactions.filter((tx: any) => tx !== null);
995+
// const tx = await _connection.getTransaction(sig.signature, {
996+
// commitment: "confirmed",
997+
// maxSupportedTransactionVersion: 0,
998+
// });
999+
// if (tx) transactions.push(tx);
1000+
// }
1001+
1002+
// Step 3: Filter transactions where sender matches
1003+
// const receivedTransactions = transactions
1004+
// .filter((tx: any) => tx && tx.meta)
1005+
// .map((tx) => {
1006+
// if (!tx || !tx.meta) return null;
1007+
1008+
// // Get account balances before and after the transaction
1009+
// const preBalances = tx.meta.preBalances;
1010+
// const postBalances = tx.meta.postBalances;
1011+
1012+
// // Get account keys (supports both legacy & versioned transactions)
1013+
// const accountKeys =
1014+
// tx.transaction.message.getAccountKeys().staticAccountKeys;
1015+
1016+
// // Find the index of the recipient (walletAddress) in the account keys
1017+
// const recipientIndex = accountKeys.findIndex(
1018+
// (key: any) => key.toBase58() === walletPubKey.toBase58()
1019+
// );
1020+
1021+
// if (recipientIndex === -1) return null; // Wallet not found in the transaction
1022+
1023+
// // Calculate SOL received (in lamports, convert to SOL)
1024+
// const solReceived =
1025+
// (postBalances[recipientIndex] - preBalances[recipientIndex]) / 1e9;
1026+
1027+
// // Extract token transfers (SPL tokens)
1028+
// const tokenTransfers = tx.meta.postTokenBalances?.map(
1029+
// (tokenBalance: any) => {
1030+
// const preToken = tx?.meta?.preTokenBalances?.find(
1031+
// (pre) =>
1032+
// pre.mint === tokenBalance.mint && pre.owner === walletAddress
1033+
// );
1034+
1035+
// const receivedAmount =
1036+
// (tokenBalance.uiTokenAmount.uiAmount || 0) -
1037+
// (preToken?.uiTokenAmount.uiAmount || 0);
1038+
1039+
// return {
1040+
// mint: tokenBalance.mint,
1041+
// receivedAmount,
1042+
// };
1043+
// }
1044+
// );
1045+
1046+
// return {
1047+
// signature: tx.transaction.signatures[0],
1048+
// solReceived,
1049+
// tokenTransfers,
1050+
// };
1051+
// });
1052+
1053+
// console.log(receivedTransactions.filter((tx: any) => tx !== null));
1054+
1055+
// return receivedTransactions.filter((tx: any) => tx !== null);
10361056
} catch (error) {
10371057
console.error("Error fetching transaction history:", error);
10381058
return [];

src/utils/globals.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
let CoNET_Data: encrypt_keys_object | null = null;
22
let processingBlock: boolean = false;
33
let currentPageInvitees: number = 0;
4+
let globalAllNodes: nodes_info[] = [];
45

56
const setCoNET_Data = (data: encrypt_keys_object | null) => {
67
CoNET_Data = data;
@@ -14,11 +15,17 @@ const setCurrentPageInvitees = (value: number) => {
1415
currentPageInvitees = value;
1516
};
1617

18+
const setGlobalAllNodes = (_nodes: nodes_info[]) => {
19+
globalAllNodes = _nodes;
20+
};
21+
1722
export {
1823
CoNET_Data,
1924
setCoNET_Data,
2025
processingBlock,
2126
setProcessingBlock,
2227
currentPageInvitees,
2328
setCurrentPageInvitees,
29+
globalAllNodes,
30+
setGlobalAllNodes,
2431
};

0 commit comments

Comments
 (0)