Repository navigation
feat: add synchronous vault flows and positions #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,10 +10,12 @@ import type { | |
| } from "@epoch-protocol/epoch-flows-sdk"; | ||
| import type { | ||
| EpochEarnMarket, | ||
| EpochEarnVault, | ||
| OneDeltaConfig, | ||
| OneDeltaMarketRow, | ||
| } from "../types"; | ||
| import { MarketRowCard } from "./earn/MarketRowCard"; | ||
| import { VaultMarketRowCard } from "./earn/VaultMarketRowCard"; | ||
| import { ArrowDownUpIcon } from "./Icons"; | ||
| import { FilterDropdown, type FilterOption } from "./ui/FilterDropdown"; | ||
| import { SearchInput } from "./ui/SearchInput"; | ||
|
|
@@ -29,6 +31,9 @@ interface Props { | |
| * re-sort, re-filter (except the page-local text search), or slice. | ||
| */ | ||
| rows: EarnMarketRow[]; | ||
| vaults?: EpochEarnVault[]; | ||
| vaultsLoading?: boolean; | ||
| vaultsError?: Error | null; | ||
| selectedId?: string; | ||
| isLoading: boolean; | ||
| error: Error | null; | ||
|
|
@@ -37,6 +42,7 @@ interface Props { | |
| row: OneDeltaMarketRow, | ||
| config: OneDeltaConfig, | ||
| ) => void; | ||
| onSelectVault?: (market: EpochEarnMarket) => void; | ||
|
|
||
| /** Chain filter — forwarded to the API as `chainId` (or all). */ | ||
| chainFilter: number | "all"; | ||
|
|
@@ -172,10 +178,14 @@ function rowMatches(item: EarnMarketRow, query: string): boolean { | |
|
|
||
| export function MarketPickerPage({ | ||
| rows, | ||
| vaults = [], | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. React Doctor · This reruns hooks that list it in their dependency array because default prop value [] makes a brand new array every render, so move it to a constant at the top of the file Fix → Move it to the top of the file: |
||
| vaultsLoading = false, | ||
| vaultsError = null, | ||
| selectedId, | ||
| isLoading, | ||
| error, | ||
| onSelect, | ||
| onSelectVault, | ||
| chainFilter, | ||
| onChainChange, | ||
| lenderFilter, | ||
|
|
@@ -241,17 +251,14 @@ export function MarketPickerPage({ | |
| () => rows.filter((item) => rowMatches(item, query)), | ||
| [rows, query], | ||
| ); | ||
|
|
||
| if (error) { | ||
| return ( | ||
| <p className="m-0 text-[13px] text-error"> | ||
| Failed to load markets: {error.message} | ||
| </p> | ||
| ); | ||
| } | ||
| const visibleVaults = useMemo(() => { | ||
| const q = query.trim().toLowerCase(); | ||
| return vaults.filter((v) => !q || `${v.share.symbol} ${v.share.address} ${v.underlying.symbol} ${v.provider} ${v.providerName}`.toLowerCase().includes(q)); | ||
| }, [vaults, query]); | ||
|
|
||
| return ( | ||
| <div className="flex flex-col gap-4"> | ||
| {error && <p className="m-0 text-[13px] text-error">Failed to load lending markets: {error.message}</p>} | ||
| <SearchInput | ||
| value={query} | ||
| onChange={setQuery} | ||
|
|
@@ -294,7 +301,7 @@ export function MarketPickerPage({ | |
| /> | ||
| </div> | ||
|
|
||
| {isLoading ? ( | ||
| {error ? null : isLoading ? ( | ||
| <div className="flex flex-col gap-2"> | ||
| <Skeleton width="100%" height={72} radius="var(--epoch-radius-sm)" /> | ||
| <Skeleton width="100%" height={72} radius="var(--epoch-radius-sm)" /> | ||
|
|
@@ -349,6 +356,29 @@ export function MarketPickerPage({ | |
| </div> | ||
| </div> | ||
| )} | ||
|
|
||
| <div className="flex items-center justify-between gap-2 border-t border-line pt-3"> | ||
| <span className={SECTION_LABEL}>Synchronous vaults</span> | ||
| </div> | ||
| {vaultsError && <p className="m-0 text-[12px] text-fg-muted">Vault listings unavailable: {vaultsError.message}</p>} | ||
| {vaultsLoading ? ( | ||
| <div className="flex flex-col gap-2"><Skeleton width="100%" height={72} radius="var(--epoch-radius-sm)" /><Skeleton width="100%" height={72} radius="var(--epoch-radius-sm)" /></div> | ||
| ) : visibleVaults.length === 0 ? ( | ||
| <p className="my-2 text-[13px] text-fg-muted">No synchronous vaults found on this page.</p> | ||
| ) : ( | ||
| <div className="flex flex-col overflow-x-hidden"> | ||
| {visibleVaults.map((vault) => ( | ||
| <VaultMarketRowCard key={vault.id} vault={vault} selected={selectedId === vault.id} onClick={() => onSelectVault?.({ | ||
| id: vault.id, displayName: vault.share.symbol, chainLabel: getEpochChainById(vault.chainId)?.name ?? `Chain ${vault.chainId}`, | ||
| aprDecimal: vault.apyPercent / 100, vaultAddress: vault.vaultAddress, underlyingAddress: vault.underlying.address, | ||
| productKind: 'vault', providerKey: vault.provider, | ||
| token: { address: vault.underlying.address, symbol: vault.underlying.symbol, decimals: vault.underlying.decimals, logoURI: vault.underlying.logoURI }, | ||
| destinationChainName: getEpochChainById(vault.chainId)?.name ?? `Chain ${vault.chainId}`, chainId: vault.chainId, | ||
| lenderName: vault.providerName, | ||
| })} /> | ||
| ))} | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import type { EpochEarnVault } from '../../types'; | ||
| import { getEpochChainById } from '../../epoch-config'; | ||
| import { cn } from '../../lib/cn'; | ||
| import { TrendingUpIcon } from '../Icons'; | ||
| import { TokenAvatar } from '../ui/TokenAvatar'; | ||
|
|
||
| export function VaultMarketRowCard({ vault, selected, onClick }: { vault: EpochEarnVault; selected?: boolean; onClick: () => void }) { | ||
| const chain = getEpochChainById(vault.chainId); | ||
| const provider = vault.provider === 'euler-earn' ? 'Euler Earn' : vault.provider[0].toUpperCase() + vault.provider.slice(1); | ||
| return <button type="button" onClick={onClick} aria-label={`Select ${vault.share.symbol} vault from ${provider}`} | ||
| className={cn('group relative box-border flex w-full cursor-pointer items-center gap-3.5 rounded-sm border-0 border-b border-line bg-transparent px-2 py-3 pl-3 text-left transition-colors hover:bg-surface-muted', selected && 'bg-accent-soft')}> | ||
| <TokenAvatar src={vault.underlying.logoURI} symbol={vault.underlying.symbol} size={40} chainSrc={chain?.logoURI} chainAlt={chain?.name} /> | ||
| <div className="flex min-w-0 flex-1 flex-col gap-1"> | ||
| <span className="truncate text-[15px] font-semibold text-fg">{vault.share.symbol}</span> | ||
| <span className="truncate text-[12px] text-fg-muted">{chain?.name ?? `Chain ${vault.chainId}`} · {provider} · {vault.underlying.symbol}</span> | ||
| </div> | ||
| <span className="inline-flex shrink-0 items-center gap-1 text-[14px] font-bold tabular-nums text-success"><TrendingUpIcon />{vault.apyPercent.toFixed(vault.apyPercent >= 10 ? 1 : 2)}%</span> | ||
| </button>; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
React Doctor ·
react-doctor/no-high-complexity-react-function(warning)MarketPickerPagehas cyclomatic complexity 18, cognitive complexity 23, and maximum nesting depth 4, so its React logic is hard to understand and change. Extract independent branches into components or hooks.Fix → Extract independent render branches and state logic into focused components or hooks until the control flow is easy to follow.
Docs