Skip to content
This repository has been archived by the owner on Jan 15, 2021. It is now read-only.

Commit

Permalink
1032/filter tokens orders widget (#1097)
Browse files Browse the repository at this point in the history
* grab token details inside useOrders

1. use service
2. populate here to filter later
3. created DetailedAuctionElement type

* remove async logic of fetching tokens from OrderRow inside fetchTokens

* export BalanceTools

* pass BalanceTools and DetauledAuction/PendingElement into OrdersWidget

* get detailed info from pendingOrders hook

* BalanceTools added with cehckbox and css changed to keep box on top

* added FormMessage to show filter amount

1. added useDataFilter to OrderWidget

* CSS: removed duped code, added styling

* css fix on text color FormMessage

* move BalanceTools into FilterTools component

1. re-add h5 title to TradeWidget (was removed to try adding as prop)

* Add FilterTools to DepositWidget

* add FilterTools to OrdersWidget + misc changes

1. add isWidget prop to flag smaller size

* prop isWidget

* simplify filter fn

* include data-order-id to each tr

* added id filtering

1. made filtering into fn for ease

* fixed dataFiter props after rebase

* DepositWidget: show filter results on search

* Promise.all inside useOrder/PendingOrders

* FilterTools resultName prop

* move inline CSS to OrdersWidget.styled

* fix missing border-radius for trade pg

* use correct TokenDetails from `types`

* no need for cast after fixed TokenDetails

* return null custom filter fn on empty string

thanks @Velenir

* use TokenDetails from types
  • Loading branch information
W3stside authored Jun 15, 2020
1 parent b31c009 commit ae225ad
Show file tree
Hide file tree
Showing 12 changed files with 334 additions and 139 deletions.
9 changes: 7 additions & 2 deletions src/api/exchange/ExchangeApi.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import BN from 'bn.js'
import { PastEventOptions } from 'web3-eth-contract'

import { assert, BatchExchangeEvents, TokenDetails } from '@gnosis.pm/dex-js'
import { assert, BatchExchangeEvents } from '@gnosis.pm/dex-js'

import { DepositApiImpl, DepositApi, DepositApiDependencies } from 'api/deposit/DepositApi'
import { Receipt, WithTxOptionalParams } from 'types'
import { Receipt, TokenDetails, WithTxOptionalParams } from 'types'
import { logDebug } from 'utils'
import { decodeAuctionElements, decodeOrder } from './utils/decodeAuctionElements'
import { DEFAULT_ORDERS_PAGE_SIZE, LIMIT_EXCEEDED_ERROR_CODE } from 'const'
Expand Down Expand Up @@ -104,6 +104,11 @@ export interface ExchangeApi extends DepositApi {
cancelOrders(params: CancelOrdersParams): Promise<Receipt>
}

export interface DetailedAuctionElement extends AuctionElement {
buyToken: TokenDetails | null
sellToken: TokenDetails | null
}

export interface AuctionElement extends Order {
user: string
sellTokenBalance: BN
Expand Down
101 changes: 14 additions & 87 deletions src/components/DepositWidget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@ import Modali from 'modali'
import styled from 'styled-components'
import BN from 'bn.js'

// Assets
import searchIcon from 'assets/img/search.svg'

// Utils, const, types
import { logDebug, getToken } from 'utils'
import { ZERO, MEDIA } from 'const'
import { TokenBalanceDetails } from 'types'
import { TokenLocalState } from 'reducers-actions'
import { LocalTokensState } from 'reducers-actions/localTokens'
import { TokenLocalState } from 'reducers-actions'

// Components
import { CardTable } from 'components/Layout/Card'
import ErrorMsg from 'components/ErrorMsg'
import Widget from 'components/Layout/Widget'
import FilterTools from 'components/FilterTools'

// DepositWidget: subcomponents
import { Row } from 'components/DepositWidget/Row'
Expand Down Expand Up @@ -183,19 +181,8 @@ const BalancesWidget = styled(Widget)`
}
}
}
`

const BalanceTools = styled.div`
display: flex;
width: 100%;
justify-content: space-between;
margin: 0;
padding: 0;
box-sizing: border-box;
align-items: center;
order: 1;
> .balances-manageTokens {
// button
.balances-manageTokens {
font-size: 1.4rem;
color: var(--color-text-active);
letter-spacing: 0;
Expand All @@ -217,7 +204,8 @@ const BalanceTools = styled.div`
}
}
> .balances-hideZero {
// label + radio input
.balances-hideZero {
display: flex;
flex-flow: row nowrap;
font-size: 1.4rem;
Expand All @@ -236,65 +224,6 @@ const BalanceTools = styled.div`
margin: 0 0 0 0.5rem;
}
}
> .balances-searchTokens {
display: flex;
width: auto;
max-width: 100%;
position: relative;
height: 5.6rem;
margin: 1.6rem;
@media ${MEDIA.mobile} {
width: 100%;
height: 4.6rem;
margin: 0 0 2.4rem;
}
> input {
margin: 0;
width: 35rem;
max-width: 100%;
background: var(--color-background-input) url(${searchIcon}) no-repeat left 1.6rem center/1.6rem;
border-radius: 0.6rem 0.6rem 0 0;
border: 0;
font-size: 1.4rem;
line-height: 1;
box-sizing: border-box;
border-bottom: 0.2rem solid transparent;
font-weight: var(--font-weight-normal);
padding: 0 1.6rem 0 4.8rem;
outline: 0;
@media ${MEDIA.mobile} {
font-size: 1.3rem;
width: 100%;
}
&::placeholder {
font-size: inherit;
color: inherit;
}
&:focus {
border-bottom: 0.2rem solid var(--color-text-active);
border-color: var(--color-text-active);
color: var(--color-text-active);
}
&.error {
border-color: var(--color-error);
}
&.warning {
border-color: orange;
}
&:disabled {
box-shadow: none;
}
}
}
`

const NoTokensMessage = styled.tr`
Expand Down Expand Up @@ -414,23 +343,21 @@ const BalancesDisplay: React.FC<BalanceDisplayProps> = ({

return (
<BalancesWidget>
<BalanceTools>
<label className="balances-searchTokens">
<input
placeholder="Search token by Name, Symbol or Address"
type="text"
value={search}
onChange={handleSearch}
/>
</label>
<FilterTools
resultName="tokens"
searchValue={search}
handleSearch={handleSearch}
showFilter={(!!search || hideZeroBalances) && displayedBalances?.length > 0}
dataLength={displayedBalances.length}
>
<label className="balances-hideZero">
<input type="checkbox" checked={hideZeroBalances} onChange={handleHideZeroBalances} />
<b>Hide zero balances</b>
</label>
<button type="button" className="balances-manageTokens" onClick={toggleModal}>
Manage Tokens
</button>
</BalanceTools>
</FilterTools>
{error ? (
<ErrorMsg title="oops..." message="Something happened while loading the balances" />
) : (
Expand Down
142 changes: 142 additions & 0 deletions src/components/FilterTools.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import React from 'react'
import styled from 'styled-components'
// Components
import FormMessage from './TradeWidget/FormMessage'
// Assets
import searchIcon from 'assets/img/search.svg'
// Misc
import { MEDIA } from 'const'

export const BalanceTools = styled.div<{ $css?: string | false }>`
display: flex;
width: 100%;
justify-content: space-between;
margin: 0;
padding: 0;
box-sizing: border-box;
align-items: center;
order: 0;
${FormMessage} {
color: var(--color-text-primary);
background: var(--color-background-validation-warning);
font-size: x-small;
margin: 0;
position: absolute;
bottom: 0;
left: 0;
width: max-content;
padding: 0.1rem 1.6rem 0.1rem 0.5rem;
border-radius: 0 1.6rem 0rem 0rem;
}
// label + search input
> .balances-searchTokens {
display: flex;
width: auto;
max-width: 100%;
position: relative;
height: 5.6rem;
margin: 1.6rem;
> input {
margin: 0;
width: 35rem;
max-width: 100%;
background: var(--color-background-input) url(${searchIcon}) no-repeat left 1.6rem center/1.6rem;
border-radius: 0.6rem 0.6rem 0 0;
border: 0;
font-size: 1.4rem;
line-height: 1;
box-sizing: border-box;
border-bottom: 0.2rem solid transparent;
font-weight: var(--font-weight-normal);
padding: 0 1.6rem 0 4.8rem;
outline: 0;
@media ${MEDIA.mobile} {
font-size: 1.3rem;
width: 100%;
}
&::placeholder {
font-size: inherit;
color: inherit;
}
&:focus {
color: var(--color-text-active);
}
&:focus {
border-bottom: 0.2rem solid var(--color-text-active);
border-color: var(--color-text-active);
transition: all 0.2s ease-in-out;
}
&.error {
border-color: var(--color-error);
}
&.warning {
border-color: orange;
}
&:disabled {
box-shadow: none;
}
}
@media ${MEDIA.mobile} {
width: 100%;
height: 4.6rem;
margin: 0 0 2.4rem;
> ${FormMessage} {
bottom: -1.2rem;
border-radius: 0 0 1.6rem 0rem;
}
}
}
${({ $css = '' }): string | false => $css}
`

interface Props {
customStyles?: string | false
className?: string
dataLength: number
resultName?: string
searchValue: string
showFilter: boolean
handleSearch: (e: React.ChangeEvent<HTMLInputElement>) => void
}

const FilterTools: React.FC<Props> = ({
children,
className,
customStyles,
dataLength,
resultName = 'results',
searchValue,
showFilter,
handleSearch,
}) => (
<BalanceTools className={className} $css={customStyles}>
<label className="balances-searchTokens">
<input
placeholder="Search token by Name, Symbol or Address"
type="text"
value={searchValue}
onChange={handleSearch}
/>
{showFilter && (
<FormMessage id="filterLabel">
Filter: Showing {dataLength} {dataLength === 1 ? 'result' : resultName}
</FormMessage>
)}
</label>
<>{children}</>
</BalanceTools>
)

export default FilterTools
Loading

0 comments on commit ae225ad

Please sign in to comment.