Skip to content

Commit 87f971f

Browse files
committed
fixed all isssues
1 parent 5d55c77 commit 87f971f

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

‎src/components/GasOptimizer.tsx‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { HugeiconsIcon } from "@hugeicons/react";
1313
import { useCallback, useEffect, useRef, useState } from "react";
1414

1515
import { useSorokit } from "@/context/useSorokit";
16+
import { useFeeData } from "@/hooks/useFeeData";
1617
import type { SorobanResourceUsage } from "@/lib/client";
1718
import { parseContractPanic } from "@/lib/diagnostics";
1819
import { cn, toXLM } from "@/lib/utils";
@@ -249,6 +250,10 @@ export function GasOptimizer({
249250
}: GasOptimizerProps) {
250251
const { client, network, registerWatcher } = useSorokit();
251252
const [containerRef, isVisible] = useIsVisible<HTMLDivElement>();
253+
// Shares FeeEstimator's polling interval and cache instead of fetching the
254+
// base fee a second time: the hook dedupes concurrent callers down to one
255+
// `estimateFee()` request per tick regardless of how many components use it.
256+
const { fee: sharedFee } = useFeeData(refreshInterval, isVisible);
252257
const [gasPriceData, setGasPriceData] = useState<GasPriceData | null>(null);
253258
const [estimate, setEstimate] = useState<GasEstimate | null>(null);
254259
const [loading, setLoading] = useState(true);
@@ -438,7 +443,7 @@ export function GasOptimizer({
438443
gasMultiplier: customMultiplier,
439444
multiplier: customMultiplier,
440445
gasPrice: gasPriceData?.gasPrice ?? "100",
441-
baseFee: gasPriceData?.baseFee ?? "100",
446+
baseFee: sharedFee?.baseFee ?? gasPriceData?.baseFee ?? "100",
442447
baseReserve: gasPriceData?.baseReserve ?? "0.5",
443448
operations,
444449
resources: {
@@ -459,6 +464,7 @@ export function GasOptimizer({
459464
memoryBytes,
460465
customMultiplier,
461466
gasPriceData,
467+
sharedFee,
462468
operations,
463469
]);
464470

‎src/screens/TransactionsScreen.tsx‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import { TransactionHistory } from "@/components/TransactionHistory";
77
import { TransactionPanel } from "@/components/TransactionPanel";
88
import { SCREEN_LABELS } from "@/lib/nav-labels";
99

10+
// Shared by GasOptimizer and FeeEstimator so both tick in lockstep;
11+
// FeeEstimator's useFeeData() hook dedupes their estimateFee() calls to one
12+
// request per tick regardless of how many components are polling.
13+
const FEE_REFRESH_INTERVAL_MS = 15_000;
14+
1015
export function TransactionsScreen() {
1116
const { title, sub } = SCREEN_LABELS.transactions;
1217

@@ -18,8 +23,8 @@ export function TransactionsScreen() {
1823
</h2>
1924
<p className="text-[11px] text-ink-3 mt-0.5">{sub}</p>
2025
</div>
21-
<GasOptimizer />
22-
<FeeEstimator />
26+
<GasOptimizer refreshInterval={FEE_REFRESH_INTERVAL_MS} />
27+
<FeeEstimator refreshInterval={FEE_REFRESH_INTERVAL_MS} />
2328
<MultiSigTransactionBuilder />
2429
<ErrorBoundary isolate>
2530
<TransactionPanel />

0 commit comments

Comments
 (0)