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

Commit

Permalink
autoadd token
Browse files Browse the repository at this point in the history
  • Loading branch information
Velenir committed May 20, 2020
1 parent 8d4c2f5 commit ee02e32
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/components/OrdersWidget/OrderRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { AuctionElement } from 'api/exchange/ExchangeApi'

import { OrderRowWrapper } from './OrderRow.styled'
import { useTimeRemainingInBatch } from 'hooks/useTimeRemainingInBatch'
import { tokenListApi } from 'api'

const PendingLink: React.FC<Pick<Props, 'transactionHash'>> = props => {
const { transactionHash } = props
Expand Down Expand Up @@ -316,6 +317,16 @@ interface Props {

const onError = onErrorFactory('Failed to fetch token')

interface AddTokenToList {
token: TokenDetails | null
networkId: number
}
const addTokenToListIfNotAlready = ({ token, networkId }: AddTokenToList): void => {
if (token && !tokenListApi.hasToken({ tokenAddress: token.address, networkId })) {
tokenListApi.addToken({ token, networkId })
}
}

const OrderRow: React.FC<Props> = props => {
const {
order,
Expand All @@ -339,6 +350,17 @@ const OrderRow: React.FC<Props> = props => {
fetchToken(order.sellTokenId, order.id, networkId, setSellToken, isPendingOrder).catch(onError)
}, [isPendingOrder, networkId, order, setBuyToken, setSellToken])

useEffect(() => {
// if token somehow not in list
// as it was traded already we assume it to be a valid token
// and know to user
// and add it to USER_TOKEN_LIST automatically
addTokenToListIfNotAlready({ token: sellToken, networkId })
}, [networkId, sellToken])
useEffect(() => {
addTokenToListIfNotAlready({ token: buyToken, networkId })
}, [networkId, buyToken])

const isUnlimited = isOrderUnlimited(order.priceDenominator, order.priceNumerator)

return (
Expand Down

0 comments on commit ee02e32

Please sign in to comment.