Skip to content

Commit 732692d

Browse files
committed
perf directory
1 parent 42b62d6 commit 732692d

File tree

4 files changed

+48
-41
lines changed

4 files changed

+48
-41
lines changed
Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { lazy, Suspense } from "react"
2-
import type { Environment } from "~/config/data/ccip/types"
2+
import type { Environment } from "~/config/data/ccip/types.ts"
33

4-
const NetworkGrid = lazy(() => import("./NetworkGrid"))
4+
const NetworkGrid = lazy(() => import("./NetworkGrid.tsx"))
55

66
interface LazyNetworkGridProps {
77
networks: Array<{
@@ -16,22 +16,25 @@ interface LazyNetworkGridProps {
1616

1717
export default function LazyNetworkGrid({ networks, environment }: LazyNetworkGridProps) {
1818
return (
19-
<Suspense
19+
<Suspense
2020
fallback={
21-
<div className="grid" style={{
22-
display: 'grid',
23-
gridTemplateColumns: 'repeat(auto-fill, minmax(280px, 1fr))',
24-
gap: '1rem',
25-
padding: '1rem 0'
26-
}}>
21+
<div
22+
className="grid"
23+
style={{
24+
display: "grid",
25+
gridTemplateColumns: "repeat(auto-fill, minmax(280px, 1fr))",
26+
gap: "1rem",
27+
padding: "1rem 0",
28+
}}
29+
>
2730
{Array.from({ length: 8 }, (_, i) => (
28-
<div
31+
<div
2932
key={i}
3033
style={{
31-
height: '120px',
32-
backgroundColor: '#f8f9fa',
33-
borderRadius: '8px',
34-
animation: 'pulse 1.5s ease-in-out infinite alternate'
34+
height: "120px",
35+
backgroundColor: "#f8f9fa",
36+
borderRadius: "8px",
37+
animation: "pulse 1.5s ease-in-out infinite alternate",
3538
}}
3639
/>
3740
))}
@@ -41,4 +44,4 @@ export default function LazyNetworkGrid({ networks, environment }: LazyNetworkGr
4144
<NetworkGrid networks={networks} environment={environment} />
4245
</Suspense>
4346
)
44-
}
47+
}

src/components/CCIP/Search/Search.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { directoryToSupportedChain, getExplorer, fallbackTokenIconUrl } from "~/
77
import { drawerContentStore } from "../Drawer/drawerStore.ts"
88
import LaneDrawer from "../Drawer/LaneDrawer.tsx"
99
import { ChainType, ExplorerInfo } from "~/config/types.ts"
10-
import type { WorkerMessage, WorkerResponse } from "~/workers/data-worker"
10+
import type { WorkerMessage, WorkerResponse } from "~/workers/data-worker.ts"
1111

1212
interface SearchProps {
1313
chains: {
@@ -57,10 +57,7 @@ function Search({ chains, tokens, small, environment, lanes }: SearchProps) {
5757
useEffect(() => {
5858
if (typeof window !== "undefined") {
5959
// Import the worker as a URL that Vite will process
60-
workerRef.current = new Worker(
61-
new URL("~/workers/data-worker.ts", import.meta.url),
62-
{ type: "module" }
63-
)
60+
workerRef.current = new Worker(new URL("~/workers/data-worker.ts", import.meta.url), { type: "module" })
6461

6562
workerRef.current.onmessage = (event: MessageEvent<WorkerResponse>) => {
6663
const { networks, tokens: workerTokens, lanes: workerLanes } = event.data
Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { lazy, Suspense } from "react"
2-
import type { Environment } from "~/config/data/ccip/types"
2+
import type { Environment } from "~/config/data/ccip/types.ts"
33

4-
const TokenGrid = lazy(() => import("./TokenGrid"))
4+
const TokenGrid = lazy(() => import("./TokenGrid.tsx"))
55

66
interface LazyTokenGridProps {
77
tokens: Array<{
@@ -14,22 +14,25 @@ interface LazyTokenGridProps {
1414

1515
export default function LazyTokenGrid({ tokens, environment }: LazyTokenGridProps) {
1616
return (
17-
<Suspense
17+
<Suspense
1818
fallback={
19-
<div className="grid" style={{
20-
display: 'grid',
21-
gridTemplateColumns: 'repeat(auto-fill, minmax(280px, 1fr))',
22-
gap: '1rem',
23-
padding: '1rem 0'
24-
}}>
19+
<div
20+
className="grid"
21+
style={{
22+
display: "grid",
23+
gridTemplateColumns: "repeat(auto-fill, minmax(280px, 1fr))",
24+
gap: "1rem",
25+
padding: "1rem 0",
26+
}}
27+
>
2528
{Array.from({ length: 8 }, (_, i) => (
26-
<div
29+
<div
2730
key={i}
2831
style={{
29-
height: '120px',
30-
backgroundColor: '#f8f9fa',
31-
borderRadius: '8px',
32-
animation: 'pulse 1.5s ease-in-out infinite alternate'
32+
height: "120px",
33+
backgroundColor: "#f8f9fa",
34+
borderRadius: "8px",
35+
animation: "pulse 1.5s ease-in-out infinite alternate",
3336
}}
3437
/>
3538
))}
@@ -39,4 +42,4 @@ export default function LazyTokenGrid({ tokens, environment }: LazyTokenGridProp
3942
<TokenGrid tokens={tokens} environment={environment} />
4043
</Suspense>
4144
)
42-
}
45+
}

src/workers/data-worker.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
// TypeScript Web Worker for CCIP Search filtering
2+
// Security Note: Web Workers run in isolated contexts and don't have access to event.origin
3+
// Instead, we validate message structure and sanitize all inputs to prevent attacks
4+
import type { LaneConfig } from "~/config/data/ccip/types.ts"
5+
import type { ChainType, ExplorerInfo } from "~/config/types.ts"
6+
27
interface SearchData {
38
chains: Array<{
49
name: string
@@ -17,18 +22,16 @@ interface SearchData {
1722
name: string
1823
logo: string
1924
key: string
20-
chainType: any
25+
chainType: ChainType
2126
}
2227
destinationNetwork: {
2328
name: string
2429
logo: string
2530
key: string
26-
explorer: any
27-
chainType: any
28-
}
29-
lane: {
30-
supportedTokens?: Record<string, any>
31+
explorer: ExplorerInfo
32+
chainType: ChainType
3133
}
34+
lane: LaneConfig
3235
}>
3336
}
3437

@@ -44,6 +47,7 @@ interface WorkerResponse {
4447
}
4548

4649
self.onmessage = (event: MessageEvent<WorkerMessage>) => {
50+
// Basic validation - Web Workers run in isolated contexts, lower security risk
4751
const { search, data } = event.data
4852

4953
if (!search || !data) {

0 commit comments

Comments
 (0)