From ee02e3219ca053ad2864f7233d200b7df314aaf1 Mon Sep 17 00:00:00 2001 From: Velenir Date: Wed, 20 May 2020 16:56:55 +0300 Subject: [PATCH] autoadd token --- src/components/OrdersWidget/OrderRow.tsx | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/components/OrdersWidget/OrderRow.tsx b/src/components/OrdersWidget/OrderRow.tsx index d1e4d242b..92d9457da 100644 --- a/src/components/OrdersWidget/OrderRow.tsx +++ b/src/components/OrdersWidget/OrderRow.tsx @@ -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> = props => { const { transactionHash } = props @@ -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 => { const { order, @@ -339,6 +350,17 @@ const OrderRow: React.FC = 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 (