From 5dbc4589b5ab92b68b986a1326e5165d259bcc37 Mon Sep 17 00:00:00 2001 From: David Sato Date: Wed, 11 Nov 2020 15:46:24 +0100 Subject: [PATCH] need to check bigNumber prices against each other and return null 1. stops warnings 2. prevents bad rounding string check --- src/components/trade/PriceImpact/utils.ts | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/components/trade/PriceImpact/utils.ts b/src/components/trade/PriceImpact/utils.ts index 3f78442c3..2d0bf0f38 100644 --- a/src/components/trade/PriceImpact/utils.ts +++ b/src/components/trade/PriceImpact/utils.ts @@ -63,18 +63,13 @@ function determinePriceWarning(params: PriceImpactArgs, impact: BigNumber | null const limitPrice = limitPriceString && parseBigNumber(limitPriceString) - // No comparable prices, or user opting for suggested fill price - // round values before comparing - if ( - // if any of the limit/fill/bestAsk params are - // null or zero, return null - !limitPrice || - limitPrice.isZero() || - !fillPrice || - !bestAskPrice - ) + // No calculatable prices: stop early + if (!limitPrice || limitPrice.isZero() || !fillPrice || !bestAskPrice) { return null + } + // Limit price BigNumber === Fill price BigNumber - order is optimised, no warnings + const fillPriceMatchesLimitPrice = limitPrice.eq(fillPrice) // Is user's limit price less than the suggested fill price? const orderWontBeFullyExecuted = limitPrice.lt(fillPrice) // Is user's limit price less than suggested fill price AND best ask? @@ -93,6 +88,9 @@ function determinePriceWarning(params: PriceImpactArgs, impact: BigNumber | null !isPriceAboveDeepMarketThreshold && limitPrice.gte(fillPrice.times(MID_PLACEHOLDER_SLIPPAGE)) switch (true) { + // CASE 4 & 3: price matches fill price, orders goes ahead + case fillPriceMatchesLimitPrice: + return null // CASE 6: Limit price is GREATER THAN Fill price AND upper threshold 5% case isPriceAboveDeepMarketThreshold: return WARNINGS.DEEP_MARKET @@ -104,7 +102,6 @@ function determinePriceWarning(params: PriceImpactArgs, impact: BigNumber | null // CASE 2 case isPriceMidImpactAndExecutable: return WARNINGS.MAYBE_FULLY_EXECUTED - // CASE 4 & 3 default: return null }