-
Notifications
You must be signed in to change notification settings - Fork 44
refactor: user positions table llamalend #1600
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
b55befd
feat: search bar with full width
0xPearce 2037418
feat: onreload user positions
0xPearce c6415dd
feat: new user positions tabs + llama monitor bot button
0xPearce 050aa9c
feat: user position table with searchbar, collapsible filters, chains…
0xPearce 5e1ac77
feat: removed some filter chips for user positions
0xPearce ef19ddb
fix: key prop to user position table to force re-render
0xPearce 8b52961
fix: mint and lend markets column filter set to null when array empty
0xPearce e6f30f9
fix: tabs underline color
0xPearce 14aedc5
feat: end adornment tab with user's market count
0xPearce a2cc7ca
feat: bell icon to llama monitor bot
0xPearce 6968e8e
Merge branch 'main' into refactor/user-positions-table-llamalend
0xPearce c1d98ba
feat: render 3 rows and show all user positions button
0xPearce f2014d1
fix: bell icon svg dimensions
0xPearce 9caf965
feat: llamabot button link for mobile
0xPearce 233c63e
Merge branch 'main' into refactor/user-positions-table-llamalend
0xPearce e717639
feat: user position empty states
0xPearce 4549076
Initial plan
Copilot 84e9e26
feat: add bell ringing animation on hover
Copilot 86d38bb
refactor: extract BellRingingIcon component with Storybook
Copilot 4160143
Merge pull request #1627 from curvefi/copilot/sub-pr-1600
DanielSchiavini 465fcf2
feat: user position header title
0xPearce 4067dae
fix: bell stories typography and lint
0xPearce 20b12e6
refactor: llamabot link to constants
0xPearce 217d042
fix: use sort from query using field name
0xPearce 4f9161f
refactor: table visible rows native to DataTable
0xPearce 8f89a06
feat: user position connect wallet
0xPearce 02123ad
feat: optional title empty state
0xPearce 29394d9
fix: user position search bar hiding for mobile
0xPearce debd41a
fix: is user position prop to filter drawer
0xPearce 7172dbc
refactor: user positions empty state to constants file
0xPearce 6b1a2f8
feat: code optimizations + lint
0xPearce 36669ba
Merge branch 'main' into refactor/user-positions-table-llamalend
0xPearce ad99fce
feat: user position statistics with dummy data
0xPearce 45fd249
refactor: user positions statistics renamed and displayed if wallet p…
0xPearce 9ce26e7
refactor: user position background color
0xPearce f514df4
fix: llama market chips only for borrow positions
0xPearce 935f27b
feat: removed user positions summary
0xPearce ded43f0
Merge branch 'main' into refactor/user-positions-table-llamalend
0xPearce 03217de
fix: default tab updates after data load
0xPearce 1a46e82
Merge branch 'main' into refactor/user-positions-table-llamalend
0xPearce 2b93447
refactor: is expanded table search bar
0xPearce 66380cd
fix: llama bot and user position copywriting
0xPearce edc1704
refacto: useAccount address to check wallet connection
0xPearce e375f45
refactor: move the view all rows logic to DataTable
0xPearce d6c621a
chore: removed old code
0xPearce be614cd
fix: user has positions prop not optional
0xPearce cba9cb2
Merge branch 'main' into refactor/user-positions-table-llamalend
0xPearce 6cf0b7f
refactor: minor optimizations
0xPearce d6f7f7f
Merge branch 'main' into refactor/user-positions-table-llamalend
0xPearce File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
apps/main/src/llamalend/features/market-list/LlamaMonitorBotButton.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import Button from '@mui/material/Button' | ||
| import Link from '@mui/material/Link' | ||
| import { t } from '@ui-kit/lib/i18n' | ||
| import { ArrowTopRightIcon } from '@ui-kit/shared/icons/ArrowTopRightIcon' | ||
|
|
||
| // TODO: move it to constants / links file | ||
| const LLAMA_MONITOR_BOT_URL = 'https://t.me/LlamalendMonitorBot' | ||
|
|
||
| export const LlamaMonitorBotButton = () => ( | ||
| <Button | ||
| color="ghost" | ||
| size="extraSmall" | ||
| component={Link} | ||
| sx={{ textDecoration: 'underline', textUnderlineOffset: '2px', '&:hover': { textDecoration: 'underline' } }} | ||
| endIcon={<ArrowTopRightIcon />} | ||
| href={LLAMA_MONITOR_BOT_URL} | ||
| target="_blank" | ||
| rel="noreferrer noopener" | ||
| > | ||
| {t`Get notified with llamamonitorbot`} | ||
0xPearce marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </Button> | ||
| ) | ||
68 changes: 54 additions & 14 deletions
68
apps/main/src/llamalend/features/market-list/UserPositionTabs.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,67 @@ | ||
| import { useState } from 'react' | ||
| import type { LlamaMarketsResult } from '@/llamalend/entities/llama-markets' | ||
| import { useMemo, useState } from 'react' | ||
| import Stack from '@mui/material/Stack' | ||
| import { t } from '@ui-kit/lib/i18n' | ||
| import { TabsSwitcher, type TabOption } from '@ui-kit/shared/ui/TabsSwitcher' | ||
| import { MarketRateType } from '@ui-kit/types/market' | ||
| import { LlamaMonitorBotButton } from './LlamaMonitorBotButton' | ||
| import { UserPositionsTable, type UserPositionsTableProps } from './UserPositionsTable' | ||
|
|
||
| const tabs: TabOption<MarketRateType>[] = [ | ||
| { value: MarketRateType.Borrow, label: t`Borrow` }, | ||
| { value: MarketRateType.Supply, label: t`Supply` }, | ||
| ] | ||
| const getMarketCountLabel = (openPositions: number) => (openPositions > 0 ? '◼︎' + openPositions : '') | ||
|
|
||
| /** Show the first tab that has user positions by default, or the first tab if none are found. */ | ||
| const getDefault = (userHasPositions: LlamaMarketsResult['userHasPositions'] | undefined) => | ||
| tabs.find(({ value }) => userHasPositions?.Lend[value] || userHasPositions?.Mint[value]) ?? tabs[0] | ||
| export const UserPositionsTabs = (props: Omit<UserPositionsTableProps, 'tab' | 'openPositionsByMarketType'>) => { | ||
| // Calculate total positions across all markets (independent of filters) | ||
| const openPositionsCount = useMemo((): Record<MarketRateType, number> => { | ||
| const markets = props.result?.markets ?? [] | ||
| return { | ||
| [MarketRateType.Borrow]: markets.filter((market) => market.userHasPositions?.[MarketRateType.Borrow]).length, | ||
| [MarketRateType.Supply]: markets.filter((market) => market.userHasPositions?.[MarketRateType.Supply]).length, | ||
| } | ||
| }, [props.result?.markets]) | ||
|
|
||
| // Define tabs with position counts | ||
| const tabs: TabOption<MarketRateType>[] = useMemo( | ||
| () => [ | ||
| { | ||
| value: MarketRateType.Borrow, | ||
| label: `${t`Borrowing`} ${getMarketCountLabel(openPositionsCount[MarketRateType.Borrow])}`, | ||
| }, | ||
| { | ||
| value: MarketRateType.Supply, | ||
| label: `${t`Lending`} ${getMarketCountLabel(openPositionsCount[MarketRateType.Supply])}`, | ||
| }, | ||
| ], | ||
| [openPositionsCount], | ||
| ) | ||
|
|
||
| // Show the first tab that has user positions by default, or the first tab if none are found | ||
| const defaultTab = useMemo(() => { | ||
| const userHasPositions = props.result?.userHasPositions | ||
| return tabs.find(({ value }) => userHasPositions?.Lend[value] || userHasPositions?.Mint[value]) ?? tabs[0] | ||
| }, [props.result?.userHasPositions, tabs]) | ||
|
|
||
| const [tab, setTab] = useState<MarketRateType>(defaultTab.value) | ||
|
|
||
| export const UserPositionsTabs = (props: Omit<UserPositionsTableProps, 'tab'>) => { | ||
| const defaultTab = getDefault(props.result?.userHasPositions).value | ||
| const [tab, setTab] = useState<MarketRateType>(defaultTab) | ||
| return ( | ||
| <Stack> | ||
| <TabsSwitcher value={tab} onChange={setTab} variant="contained" size="medium" options={tabs} /> | ||
| <UserPositionsTable {...props} tab={tab} /> | ||
| <Stack | ||
| direction="row" | ||
| justifyContent="space-between" | ||
| // needed for the bottom border to be the same height as the tabs | ||
| alignItems="stretch" | ||
| sx={{ backgroundColor: (t) => t.design.Layer[1].Fill }} | ||
| > | ||
| <TabsSwitcher value={tab} onChange={setTab} variant="underlined" size="small" options={tabs} /> | ||
| <Stack | ||
| alignItems="center" | ||
| direction="row" | ||
| justifyContent="end" | ||
| sx={{ flexGrow: 1, borderBottom: (t) => `1px solid ${t.design.Layer[2].Outline}` }} | ||
| > | ||
| <LlamaMonitorBotButton /> | ||
| </Stack> | ||
| </Stack> | ||
| {/* the key is needed to force a re-render when the tab changes, otherwise filters have stale state for few milliseconds */} | ||
| <UserPositionsTable key={tab} {...props} tab={tab} /> | ||
| </Stack> | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.