Skip to content

Commit 02791bd

Browse files
authored
filter and ping only current node stamps (#117)
1 parent 0d74e8c commit 02791bd

3 files changed

Lines changed: 24 additions & 4 deletions

File tree

src/app/components/StampListSection.tsx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ interface StampListSectionProps {
4343
setShowStampList: (show: boolean) => void;
4444
address: string | undefined;
4545
beeApiUrl: string;
46+
nodeAddress: string; // The node address to filter stamps by
4647
setPostageBatchId: (id: string) => void;
4748
setShowOverlay: (show: boolean) => void;
4849
setUploadStep: (step: UploadStep) => void;
@@ -78,6 +79,7 @@ const StampListSection: React.FC<StampListSectionProps> = ({
7879
setShowStampList,
7980
address,
8081
beeApiUrl,
82+
nodeAddress,
8183
setPostageBatchId,
8284
setShowOverlay,
8385
setUploadStep,
@@ -304,8 +306,25 @@ const StampListSection: React.FC<StampListSectionProps> = ({
304306
// Process the batches data with optimized batching
305307
console.log(`📊 Processing ${(batchesData as any[]).length} stamps from contract...`);
306308

309+
// Filter batches to only include those for the current node
310+
const batchesForCurrentNode = (batchesData as any[]).filter(batch => {
311+
const batchNodeAddress = batch.nodeAddress?.toLowerCase();
312+
const currentNodeAddress = nodeAddress?.toLowerCase();
313+
const isForCurrentNode = batchNodeAddress === currentNodeAddress;
314+
if (!isForCurrentNode) {
315+
console.log(
316+
`🔀 Skipping stamp ${batch.batchId.toString().slice(0, 10)}... (node: ${batchNodeAddress?.slice(0, 10)}... != current: ${currentNodeAddress?.slice(0, 10)}...)`
317+
);
318+
}
319+
return isForCurrentNode;
320+
});
321+
322+
console.log(
323+
`🎯 Found ${batchesForCurrentNode.length} stamps for current node (${(batchesData as any[]).length - batchesForCurrentNode.length} for other nodes)`
324+
);
325+
307326
// Filter out known expired stamps before making API calls
308-
const batchesToCheck = (batchesData as any[]).filter(batch => {
327+
const batchesToCheck = batchesForCurrentNode.filter(batch => {
309328
const batchId = batch.batchId.toString();
310329
const isExpired = isStampKnownExpired(batchId);
311330
if (isExpired) {
@@ -315,7 +334,7 @@ const StampListSection: React.FC<StampListSectionProps> = ({
315334
});
316335

317336
console.log(
318-
`🔍 Making API calls for ${batchesToCheck.length} stamps (${(batchesData as any[]).length - batchesToCheck.length} skipped from cache)`
337+
`🔍 Making API calls for ${batchesToCheck.length} stamps (${batchesForCurrentNode.length - batchesToCheck.length} skipped from cache)`
319338
);
320339

321340
// Process stamps in smaller batches to avoid overwhelming the API
@@ -392,7 +411,7 @@ const StampListSection: React.FC<StampListSectionProps> = ({
392411
};
393412

394413
fetchStamps();
395-
}, [address, beeApiUrl]); // Only dependencies that actually need to trigger re-fetching
414+
}, [address, beeApiUrl, nodeAddress]); // Re-fetch when address, API URL, or node changes
396415

397416
// Function to refresh a specific stamp
398417
const refreshSingleStamp = async (stampToRefresh: BatchEvent) => {

src/app/components/SwapComponent.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2602,6 +2602,7 @@ const SwapComponent: React.FC = () => {
26022602
setShowStampList={setShowStampList}
26032603
address={address}
26042604
beeApiUrl={beeApiUrl}
2605+
nodeAddress={nodeAddress}
26052606
setPostageBatchId={setPostageBatchId}
26062607
setShowOverlay={setShowOverlay}
26072608
setUploadStep={setUploadStep}

src/app/components/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const LIFI_API_KEY =
1111
'83f85c7b-97d2-4130-95b0-f72af1f0261e.b11f7330-ebb1-4684-af33-f28759ec6853';
1212

1313
export const DEFAULT_NODE_ADDRESS =
14-
process.env.NEXT_PUBLIC_DEFAULT_NODE_ADDRESS || '0xb81784e65c84ca25b595ff4f0badb502673e343b';
14+
process.env.NEXT_PUBLIC_DEFAULT_NODE_ADDRESS || '0x5cb4839B7d7b0ab6BaAbFEdD6749497ECa65b2Ca';
1515

1616
export const LIFI_CONTRACT_ADDRESS =
1717
process.env.NEXT_PUBLIC_LIFI_CONTRACT_ADDRESS || '0x2dfaDAB8266483beD9Fd9A292Ce56596a2D1378D';

0 commit comments

Comments
 (0)