Skip to content

Commit 6cc53ab

Browse files
committed
fix: use enums for tabs
1 parent cfb7a98 commit 6cc53ab

File tree

3 files changed

+29
-23
lines changed

3 files changed

+29
-23
lines changed

src/components/CCIP/Drawer/LaneDrawer.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,7 @@ function LaneDrawer({
202202
const direction = inOutbound === LaneFilter.Outbound ? "out" : "in"
203203

204204
// Get standard and FTF rate limits
205-
const allLimits = tokenRateLimits
206-
? realtimeDataService.getAllRateLimitsForDirection(tokenRateLimits, direction)
207-
: { standard: null, ftf: null }
205+
const allLimits = realtimeDataService.getAllRateLimitsForDirection(tokenRateLimits, direction)
208206

209207
// Token is paused if standard rate limit capacity is 0
210208
const tokenPaused = allLimits.standard?.capacity === "0"

src/components/CCIP/Drawer/TokenDrawer.tsx

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ import { useMultiLaneRateLimits } from "~/hooks/useMultiLaneRateLimits.ts"
2727
import { RateLimitCell } from "~/components/CCIP/RateLimitCell.tsx"
2828
import { realtimeDataService } from "~/lib/ccip/services/realtime-data-instance.ts"
2929

30+
enum TokenTab {
31+
Outbound = "outbound",
32+
Inbound = "inbound",
33+
Verifiers = "verifiers",
34+
}
35+
3036
function TokenDrawer({
3137
token,
3238
network,
@@ -60,7 +66,7 @@ function TokenDrawer({
6066
environment: Environment
6167
}) {
6268
const [search, setSearch] = useState("")
63-
const [activeTab, setActiveTab] = useState<"outbound" | "inbound" | "verifiers">("outbound")
69+
const [activeTab, setActiveTab] = useState<TokenTab>(TokenTab.Outbound)
6470

6571
// Get verifiers for the current network
6672
const verifiers = getVerifiersByNetwork({
@@ -82,8 +88,8 @@ function TokenDrawer({
8288
// Build lane configurations for fetching rate limits
8389
const laneConfigs = useMemo(() => {
8490
return Object.keys(destinationLanes).map((destinationChain) => ({
85-
source: activeTab === "outbound" ? network.key : destinationChain,
86-
destination: activeTab === "outbound" ? destinationChain : network.key,
91+
source: activeTab === TokenTab.Outbound ? network.key : destinationChain,
92+
destination: activeTab === TokenTab.Outbound ? destinationChain : network.key,
8793
}))
8894
}, [destinationLanes, network.key, activeTab])
8995

@@ -163,23 +169,23 @@ function TokenDrawer({
163169
tabs={[
164170
{
165171
name: "Outbound lanes",
166-
key: "outbound",
172+
key: TokenTab.Outbound,
167173
},
168174
{
169175
name: "Inbound lanes",
170-
key: "inbound",
176+
key: TokenTab.Inbound,
171177
},
172178
{
173179
name: "Verifiers",
174-
key: "verifiers",
180+
key: TokenTab.Verifiers,
175181
},
176182
]}
177-
onChange={(key) => setActiveTab(key as "outbound" | "inbound" | "verifiers")}
183+
onChange={(key) => setActiveTab(key as TokenTab)}
178184
/>
179185
</div>
180186
<TableSearchInput search={search} setSearch={setSearch} />
181187
</div>
182-
{activeTab === "verifiers" ? (
188+
{activeTab === TokenTab.Verifiers ? (
183189
<div className="ccip-table__wrapper">
184190
<table className="ccip-table">
185191
<thead>
@@ -242,7 +248,7 @@ function TokenDrawer({
242248
<table className="ccip-table">
243249
<thead>
244250
<tr>
245-
<th>{activeTab === "inbound" ? "Source" : "Destination"} network</th>
251+
<th>{activeTab === TokenTab.Inbound ? "Source" : "Destination"} network</th>
246252
<th>
247253
Rate limit capacity
248254
<Tooltip
@@ -303,18 +309,16 @@ function TokenDrawer({
303309
if (!laneData || !networkDetails) return null
304310

305311
// Get rate limit data for this lane
306-
const source = activeTab === "outbound" ? network.key : destinationChain
307-
const destination = activeTab === "outbound" ? destinationChain : network.key
312+
const source = activeTab === TokenTab.Outbound ? network.key : destinationChain
313+
const destination = activeTab === TokenTab.Outbound ? destinationChain : network.key
308314
const laneKey = `${source}-${destination}`
309315
const laneRateLimits = rateLimitsMap[laneKey]
310316
const tokenRateLimits = laneRateLimits?.[token.id]
311317

312-
const direction = activeTab === "outbound" ? "out" : "in"
318+
const direction = activeTab === TokenTab.Outbound ? "out" : "in"
313319

314320
// Get standard and FTF rate limits
315-
const allLimits = tokenRateLimits
316-
? realtimeDataService.getAllRateLimitsForDirection(tokenRateLimits, direction)
317-
: { standard: null, ftf: null }
321+
const allLimits = realtimeDataService.getAllRateLimitsForDirection(tokenRateLimits, direction)
318322

319323
// Token is paused if standard rate limit capacity is 0
320324
const tokenPaused = allLimits.standard?.capacity === "0"
@@ -337,7 +341,7 @@ function TokenDrawer({
337341
logo: networkDetails?.logo || "",
338342
key: destinationChain,
339343
}}
340-
inOutbound={activeTab === "outbound" ? LaneFilter.Outbound : LaneFilter.Inbound}
344+
inOutbound={activeTab === TokenTab.Outbound ? LaneFilter.Outbound : LaneFilter.Inbound}
341345
explorer={network.explorer}
342346
/>
343347
))
@@ -374,7 +378,7 @@ function TokenDrawer({
374378
<RateLimitCell isLoading={isLoadingRateLimits} rateLimit={allLimits.ftf} type="rate" />
375379
</td>
376380
<td>
377-
{activeTab === "outbound"
381+
{activeTab === TokenTab.Outbound
378382
? determineTokenMechanism(network.tokenPoolType, destinationPoolType)
379383
: determineTokenMechanism(destinationPoolType, network.tokenPoolType)}
380384
</td>
@@ -397,7 +401,7 @@ function TokenDrawer({
397401
</div>
398402
)}
399403

400-
{activeTab !== "verifiers" && (
404+
{activeTab !== TokenTab.Verifiers && (
401405
<div className="ccip-table__notFound">
402406
{laneRows?.filter(
403407
({ networkDetails }) => networkDetails && networkDetails.name.toLowerCase().includes(search.toLowerCase())

src/lib/ccip/services/realtime-data.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,17 +219,21 @@ export class RealtimeDataService {
219219
/**
220220
* Gets both standard and FTF rate limits for a specific token and direction
221221
*
222-
* @param tokenRateLimits - Token rate limits containing standard and custom entries
222+
* @param tokenRateLimits - Token rate limits containing standard and custom entries (can be null/undefined)
223223
* @param direction - Direction ("in" for inbound, "out" for outbound)
224224
* @returns Object containing both standard and FTF rate limits
225225
*/
226226
getAllRateLimitsForDirection(
227-
tokenRateLimits: TokenRateLimits,
227+
tokenRateLimits: TokenRateLimits | null | undefined,
228228
direction: "in" | "out"
229229
): {
230230
standard: RateLimiterConfig | null
231231
ftf: RateLimiterConfig | null
232232
} {
233+
if (!tokenRateLimits) {
234+
return { standard: null, ftf: null }
235+
}
236+
233237
const standardLimit =
234238
tokenRateLimits.standard && !this.isRateLimiterUnavailable(tokenRateLimits.standard)
235239
? tokenRateLimits.standard[direction] || null

0 commit comments

Comments
 (0)