Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7762d86
chain selector basic
dev-dist Oct 2, 2025
ca15d30
cleanup
dev-dist Oct 2, 2025
3ac49e4
mainnet table/testnet table conditional
dev-dist Oct 2, 2025
eed2ce3
various fixes
dev-dist Oct 2, 2025
b6576e5
more cleanup
dev-dist Oct 2, 2025
26adc39
hydration mismatch fix: prevent default feed flashing when arriving v…
dev-dist Oct 2, 2025
84e610b
lint fix
dev-dist Oct 2, 2025
cff5ee9
removed unused imports
dev-dist Oct 2, 2025
5191156
fixed default network checking
dev-dist Oct 2, 2025
033a06f
styling update
dev-dist Oct 2, 2025
03a2aea
feedback & mobile styling fixes
dev-dist Oct 4, 2025
2ec110e
increase size of network switch button
dev-dist Oct 4, 2025
6e6399e
lint fix + chain->selectedChain
dev-dist Oct 4, 2025
b7eccd4
cleanup
dev-dist Oct 6, 2025
8ce0336
keyboard controls and focus state
dev-dist Oct 6, 2025
18a6b21
more fixes
dev-dist Oct 6, 2025
d05c8ac
fixed tab selection for dropdown elements
dev-dist Oct 6, 2025
bac70c0
url params for preserving user election in url params
dev-dist Oct 6, 2025
ca24d91
more switching logic edge cases (mainnet+testnet, mainnet only, testn…
dev-dist Oct 6, 2025
719fec2
added ChainSelector.example.tsx
dev-dist Oct 6, 2025
634d7bd
Merge branch 'main' into chain-selector-shared-component
dev-dist Oct 6, 2025
2fb7475
fix cl-search-frontend in packagelock breaking ci
dev-dist Oct 6, 2025
ab95598
fixed network toggle to be easier to click on mobile
dev-dist Oct 6, 2025
32de3dd
Merge branch 'main' into chain-selector-shared-component
dev-dist Oct 6, 2025
89c43d9
log removal
dev-dist Oct 6, 2025
6512c7b
Merge branch 'chain-selector-shared-component' of github.com:smartcon…
dev-dist Oct 6, 2025
9e4ee08
Merge branch 'main' into chain-selector-shared-component
dev-dist Oct 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 136 additions & 0 deletions src/components/ChainSelector/ChainSelector.example.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/** @jsxImportSource preact */
import { useState } from "preact/hooks"
import { ChainSelector } from "./ChainSelector.tsx"
import type { Chain } from "~/features/data/chains.ts"

/**
* ChainSelectorExample - Minimal usage example for the ChainSelector component
*/
export function ChainSelectorExample() {
// Sample chain data - demonstrates different network availability scenarios
const sampleChains: Chain[] = [
{
page: "ethereum",
title: "Ethereum",
label: "Ethereum",
img: "/assets/chains/ethereum.svg",
networkStatusUrl: "https://status.chain.link/",
supportedFeatures: ["feeds"],
tags: ["default"],
networks: [
{
name: "Ethereum Mainnet",
explorerUrl: "https://etherscan.io/",
networkType: "mainnet",
queryString: "ethereum-mainnet",
},
{
name: "Ethereum Sepolia",
explorerUrl: "https://sepolia.etherscan.io/",
networkType: "testnet",
queryString: "ethereum-testnet-sepolia",
},
],
},
{
page: "polygon",
title: "Polygon (Mainnet Only)",
label: "Polygon",
img: "/assets/chains/polygon.svg",
networkStatusUrl: "https://status.chain.link/",
supportedFeatures: ["feeds"],
tags: ["default"],
networks: [
{
name: "Polygon Mainnet",
explorerUrl: "https://polygonscan.com/",
networkType: "mainnet",
queryString: "polygon-mainnet",
},
],
},
{
page: "base",
title: "Base (Testnet Only)",
label: "Base",
img: "/assets/chains/base.svg",
networkStatusUrl: "https://status.chain.link/",
supportedFeatures: ["feeds"],
tags: ["default"],
networks: [
{
name: "Base Sepolia",
explorerUrl: "https://sepolia.basescan.org/",
networkType: "testnet",
queryString: "base-testnet-sepolia",
},
],
},
]

// Component state
const [selectedChain, setSelectedChain] = useState<Chain>(sampleChains[0])
const [selectedNetworkType, setSelectedNetworkType] = useState<"mainnet" | "testnet">("mainnet")

// Event handlers
const handleChainSelect = (chain: Chain) => {
setSelectedChain(chain)

// Auto-correct network type if not available on new chain
const newAvailableTypes = {
mainnet: chain.networks?.some((network) => network.networkType === "mainnet") ?? false,
testnet: chain.networks?.some((network) => network.networkType === "testnet") ?? false,
}

if (selectedNetworkType === "mainnet" && !newAvailableTypes.mainnet && newAvailableTypes.testnet) {
setSelectedNetworkType("testnet")
} else if (selectedNetworkType === "testnet" && !newAvailableTypes.testnet && newAvailableTypes.mainnet) {
setSelectedNetworkType("mainnet")
}

console.log("Chain selected:", chain.title)
}

const handleNetworkTypeChange = (networkType: "mainnet" | "testnet") => {
setSelectedNetworkType(networkType)
console.log("Network type changed:", networkType)
}

// Calculate available network types based on the selected chain's actual networks
const availableNetworkTypes = {
mainnet: selectedChain.networks?.some((network) => network.networkType === "mainnet") ?? false,
testnet: selectedChain.networks?.some((network) => network.networkType === "testnet") ?? false,
}

return (
<div style={{ padding: "20px", maxWidth: "400px" }}>
<h2>ChainSelector Example</h2>

<ChainSelector
chains={sampleChains}
selectedChain={selectedChain}
onChainSelect={handleChainSelect}
onNetworkTypeChange={handleNetworkTypeChange}
selectedNetworkType={selectedNetworkType}
availableNetworkTypes={availableNetworkTypes}
dataFeedType="default"
/>

<div style={{ marginTop: "20px", fontSize: "14px" }}>
<p>
<strong>Selected:</strong> {selectedChain.title}
</p>
<p>
<strong>Network Type:</strong> {selectedNetworkType}
</p>
<p>
<strong>Available:</strong>
</p>
<ul style={{ margin: "5px 0", paddingLeft: "20px" }}>
<li>Mainnet: {availableNetworkTypes.mainnet ? "✅" : "❌"}</li>
<li>Testnet: {availableNetworkTypes.testnet ? "✅" : "❌"}</li>
</ul>
</div>
</div>
)
}
Loading
Loading