Skip to content

Commit

Permalink
Merge pull request #161 from curvefi/fix/mobile-view-supply-button
Browse files Browse the repository at this point in the history
fix: lend mobile view buttons
  • Loading branch information
amytsang committed Apr 25, 2024
2 parents 3d9c2ad + 625f8fe commit b9300ab
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const TableRowMobile = ({
<MobileLabelWrapper flexAlignItems="center" grid gridTemplateColumns={userHaveLoan ? '20px 1fr' : '1fr'}>
{userHaveLoan && <CellInPool {...cellProps} isInMarket />}
<MobileLabelContent>
<Box flex gridGap={3}>
<Box flex gridGap={3} onClick={(evt) => handleCellClick()}>
<Box>
<TextCaption isBold isCaps>
Collateral
Expand All @@ -139,10 +139,10 @@ const TableRowMobile = ({
</MobileLabelWrapper>

<MobileTableContentWrapper className={isHideDetail ? '' : 'show'}>
<MobileTableContent onClick={(evt) => handleCellClick(evt.target)}>
<MobileTableContent>
{!isHideDetail && (
<>
<DetailsContent>
<DetailsContent onClick={(evt) => handleCellClick(evt.target)}>
{content[isBorrow ? 'borrow' : 'supply'].map((details, idx) => {
const detailsKey = `details-${idx}`
const show = details.some(({ show }) => _showContent(show))
Expand Down Expand Up @@ -194,11 +194,11 @@ const TableRowMobile = ({
</DetailsContent>
<MobileTableActions>
{isBorrow ? (
<Button variant="filled" onClick={(evt) => handleCellClick(evt.target)}>
<Button variant="filled" onClick={(evt) => handleCellClick()}>
{loanExists ? t`Manage Loan` : t`Get Loan`}
</Button>
) : (
<Button variant="filled" onClick={(evt) => handleCellClick(evt.target)}>
<Button variant="filled" onClick={(evt) => handleCellClick()}>
{t`Supply ${borrowed_token?.symbol ?? ''}`}
</Button>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,24 @@ const TableRowViewContentTable = ({
const userActiveKey = helpers.getUserActiveKey(api, owmDataCachedOrApi)
const loanExists = loansExistsMapper[userActiveKey]?.loanExists

const handleCellClick = (target: EventTarget) => {
const { nodeName } = target as HTMLElement
if (nodeName !== 'BUTTON') {
// update view
if (filterTypeKey === 'borrow') {
setMarketsStateByKey('marketDetailsView', loanExists ? 'user' : 'market')
} else if (filterTypeKey === 'supply') {
const { gauge = '0', vaultShares = '0' } = marketsBalancesMapper[userActiveKey] ?? {}
const haveSupply = +gauge + +vaultShares > 0
setMarketsStateByKey('marketDetailsView', haveSupply ? 'user' : 'market')
}

if (filterTypeKey === 'supply') {
navigate(getVaultPathname(params, owmId, 'deposit'))
} else if (loanExists) {
navigate(getLoanManagePathname(params, owmId, 'loan'))
} else {
navigate(getLoanCreatePathname(params, owmId, 'create'))
}
const handleCellClick = (target?: EventTarget) => {
if (target && (target as HTMLElement).nodeName === 'BUTTON') return

// update view
if (filterTypeKey === 'borrow') {
setMarketsStateByKey('marketDetailsView', loanExists ? 'user' : 'market')
} else if (filterTypeKey === 'supply') {
const { gauge = '0', vaultShares = '0' } = marketsBalancesMapper[userActiveKey] ?? {}
const haveSupply = +gauge + +vaultShares > 0
setMarketsStateByKey('marketDetailsView', haveSupply ? 'user' : 'market')
}

if (filterTypeKey === 'supply') {
navigate(getVaultPathname(params, owmId, 'deposit'))
} else if (loanExists) {
navigate(getLoanManagePathname(params, owmId, 'loan'))
} else {
navigate(getLoanCreatePathname(params, owmId, 'create'))
}
}

Expand Down
2 changes: 1 addition & 1 deletion apps/lend/src/components/PageMarketList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export type TableRowProps = Pick<PageMarketList, 'rChainId' | 'api' | 'searchPar
showBorrowSignerCell: boolean
showSupplySignerCell: boolean
userActiveKey: string
handleCellClick(evt: EventTarget): void
handleCellClick(target?: EventTarget): void // only pass evt.target if there is a child button node
}

export type TableCellProps = {
Expand Down

0 comments on commit b9300ab

Please sign in to comment.