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

Fix disabled tokens list #1247

Merged
merged 4 commits into from
Jul 21, 2020
Merged
Changes from 3 commits
Commits
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
97 changes: 52 additions & 45 deletions src/components/DepositWidget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { useEthBalances } from 'hooks/useEthBalance'
import useDataFilter from 'hooks/useDataFilter'

// Reducer/Actions
import { LocalTokensState } from 'reducers-actions/localTokens'
import { TokenLocalState } from 'reducers-actions'

interface WithdrawState {
Expand Down Expand Up @@ -183,13 +182,7 @@ interface BalanceDisplayProps extends TokenLocalState {
): Promise<void>
}

const customFilterFnFactory = (localTokens: LocalTokensState) => (searchTxt: string) => ({
symbol,
name,
address,
}: TokenBalanceDetails): boolean => {
if (localTokens.disabled.has(address)) return false

const customFilterFnFactory = (searchTxt: string) => ({ symbol, name, address }: TokenBalanceDetails): boolean => {
if (searchTxt === '') return true

return (
Expand Down Expand Up @@ -229,7 +222,7 @@ const BalancesDisplay: React.FC<BalanceDisplayProps> = ({
const memoizedSearchFilterParams = useMemo(
() => ({
data: balances,
filterFnFactory: customFilterFnFactory(localTokens),
filterFnFactory: customFilterFnFactory,
userConditionalCheck: ({ debouncedSearch }: { debouncedSearch: string }): boolean =>
!debouncedSearch && localTokens.disabled.size === 0,
}),
Expand Down Expand Up @@ -297,41 +290,49 @@ const BalancesDisplay: React.FC<BalanceDisplayProps> = ({
</tr>
</thead>
<tbody>
{displayedBalances && displayedBalances.length > 0
? displayedBalances.map(tokenBalances => (
<Row
key={tokenBalances.address}
ethBalance={ethBalance}
tokenBalances={tokenBalances}
onEnableToken={(): Promise<void> => enableToken(tokenBalances.address)}
onSubmitDeposit={(balance, onTxHash): Promise<void> =>
depositToken(balance, tokenBalances.address, onTxHash)
}
onSubmitWithdraw={(balance, onTxHash): Promise<void> => {
return requestWithdrawConfirmation(
balance,
tokenBalances.address,
tokenBalances.claimable,
onTxHash,
)
}}
onClaim={(): Promise<void> => claimToken(tokenBalances.address)}
claiming={claiming.has(tokenBalances.address)}
withdrawing={withdrawing.has(tokenBalances.address)}
depositing={depositing.has(tokenBalances.address)}
highlighted={highlighted.has(tokenBalances.address)}
enabling={enabling.has(tokenBalances.address)}
enabled={enabled.has(tokenBalances.address)}
{...windowSpecs}
/>
))
: (search || hideZeroBalances) && (
<NoTokensMessage>
<td>
No enabled tokens match provided filters <a onClick={clearFilters}>clear filters</a>
</td>
</NoTokensMessage>
)}
{displayedBalances && displayedBalances.length > 0 ? (
displayedBalances.map(tokenBalances => (
<Row
key={tokenBalances.address}
ethBalance={ethBalance}
tokenBalances={tokenBalances}
onEnableToken={(): Promise<void> => enableToken(tokenBalances.address)}
onSubmitDeposit={(balance, onTxHash): Promise<void> =>
depositToken(balance, tokenBalances.address, onTxHash)
}
onSubmitWithdraw={(balance, onTxHash): Promise<void> => {
return requestWithdrawConfirmation(
balance,
tokenBalances.address,
tokenBalances.claimable,
onTxHash,
)
}}
onClaim={(): Promise<void> => claimToken(tokenBalances.address)}
claiming={claiming.has(tokenBalances.address)}
withdrawing={withdrawing.has(tokenBalances.address)}
depositing={depositing.has(tokenBalances.address)}
highlighted={highlighted.has(tokenBalances.address)}
enabling={enabling.has(tokenBalances.address)}
enabled={enabled.has(tokenBalances.address)}
{...windowSpecs}
/>
))
) : balances.length === 0 ? (
<NoTokensMessage>
<td>
All tokens disabled. Enable some in <a onClick={toggleModal}>Manage Tokens</a>
</td>
</NoTokensMessage>
) : (
(search || hideZeroBalances) && (
<NoTokensMessage>
<td>
No enabled tokens match provided filters <a onClick={clearFilters}>clear filters</a>
</td>
</NoTokensMessage>
)
)}
</tbody>
</CardTable>
)}
Expand All @@ -346,7 +347,13 @@ const BalancesDisplayMemoed = React.memo(BalancesDisplay)
const DepositWidget: React.FC = () => {
const { ethBalance } = useEthBalances()
// get all token balances, including deprecated
const { balances, error } = useTokenBalances()
const { balances: allBalances, error } = useTokenBalances()

const [{ localTokens }] = useGlobalState()

const balances = useMemo(() => {
return allBalances.filter(bal => !localTokens.disabled.has(bal.address))
}, [allBalances, localTokens.disabled])

const { requestWithdrawToken, ...restActions } = useRowActions({ balances })

Expand Down