Commit 8c372c61 authored by Jack Short's avatar Jack Short Committed by GitHub

fix: fixing pwat routing edge case (#5987)

* feat: implementing graphql endpoint

* changing from hook to function call

* initial gql routing works

* feat: initial pwatRouting setup

* sending correct amount

* removing console

* it is working

* sufficient balance

* 0 if no inputCurrency

* removing value to send if erc20

* removing console

* permit2 optional flag

* removing not necessary stuff

* mobile fixes

* overlay needs to be here

* changing swap amount to pool reserves

* refactoring routing logic

* no route found button state

* better price loading for insufficient liquidity

* refactoring graphql routing code

* overflow

* initial comments

* resetting bag status on input currency change

* locking

* done

* remove helper text for eth

* fix: pay with any token routing bug

* reordering button

* zindex

* price updated

* keeping debounce
parent 8c0998bd
...@@ -66,7 +66,7 @@ const BagContainer = styled.div<{ raiseZIndex: boolean; isProfilePage: boolean } ...@@ -66,7 +66,7 @@ const BagContainer = styled.div<{ raiseZIndex: boolean; isProfilePage: boolean }
border-radius: 16px; border-radius: 16px;
box-shadow: ${({ theme }) => theme.shallowShadow}; box-shadow: ${({ theme }) => theme.shallowShadow};
z-index: ${({ raiseZIndex, isProfilePage }) => z-index: ${({ raiseZIndex, isProfilePage }) =>
raiseZIndex ? (isProfilePage ? Z_INDEX.modalOverTooltip : Z_INDEX.modalBackdrop) : 3}; raiseZIndex ? (isProfilePage ? Z_INDEX.modalOverTooltip : Z_INDEX.modalBackdrop + 2) : 3};
@media only screen and (max-width: ${({ theme }) => `${theme.breakpoint.sm}px`}) { @media only screen and (max-width: ${({ theme }) => `${theme.breakpoint.sm}px`}) {
right: 0px; right: 0px;
...@@ -232,7 +232,8 @@ const Bag = () => { ...@@ -232,7 +232,8 @@ const Bag = () => {
const { route, routeResponse } = buildRouteResponse(data.nftRoute, !!tokenTradeInput) const { route, routeResponse } = buildRouteResponse(data.nftRoute, !!tokenTradeInput)
const updatedAssets = combineBuyItemsWithTxRoute(itemsToBuy, route) const { hasPriceAdjustment, updatedAssets } = combineBuyItemsWithTxRoute(itemsToBuy, route)
const shouldRefetchCalldata = hasPriceAdjustment && !!tokenTradeInput
const fetchedPriceChangedAssets = updatedAssets const fetchedPriceChangedAssets = updatedAssets
.filter((asset) => asset.updatedPriceInfo) .filter((asset) => asset.updatedPriceInfo)
...@@ -266,9 +267,13 @@ const Bag = () => { ...@@ -266,9 +267,13 @@ const Bag = () => {
if (hasAssets) { if (hasAssets) {
if (!shouldReview) { if (!shouldReview) {
purchaseAssets(routeResponse) if (shouldRefetchCalldata) {
setBagStatus(BagStatus.CONFIRMING_IN_WALLET) setBagStatus(BagStatus.CONFIRM_QUOTE)
shouldLock = true } else {
purchaseAssets(routeResponse)
setBagStatus(BagStatus.CONFIRMING_IN_WALLET)
shouldLock = true
}
} else if (!hasAssetsInReview) setBagStatus(BagStatus.CONFIRM_REVIEW) } else if (!hasAssetsInReview) setBagStatus(BagStatus.CONFIRM_REVIEW)
else { else {
setBagStatus(BagStatus.IN_REVIEW) setBagStatus(BagStatus.IN_REVIEW)
...@@ -289,7 +294,7 @@ const Bag = () => { ...@@ -289,7 +294,7 @@ const Bag = () => {
}) })
) )
const updatedAssets = combineBuyItemsWithTxRoute(itemsToBuy, routeData.route) const { updatedAssets } = combineBuyItemsWithTxRoute(itemsToBuy, routeData.route)
const fetchedPriceChangedAssets = updatedAssets const fetchedPriceChangedAssets = updatedAssets
.filter((asset) => asset.updatedPriceInfo) .filter((asset) => asset.updatedPriceInfo)
...@@ -405,12 +410,7 @@ const Bag = () => { ...@@ -405,12 +410,7 @@ const Bag = () => {
{isProfilePage ? <ProfileBagContent /> : <BagContent />} {isProfilePage ? <ProfileBagContent /> : <BagContent />}
</Column> </Column>
{hasAssetsToShow && !isProfilePage && ( {hasAssetsToShow && !isProfilePage && (
<BagFooter <BagFooter totalEthPrice={totalEthPrice} fetchAssets={fetchAssets} eventProperties={eventProperties} />
totalEthPrice={totalEthPrice}
bagStatus={bagStatus}
fetchAssets={fetchAssets}
eventProperties={eventProperties}
/>
)} )}
{isSellingAssets && isProfilePage && ( {isSellingAssets && isProfilePage && (
<Box <Box
......
This diff is collapsed.
...@@ -16,6 +16,6 @@ export const overlay = style([ ...@@ -16,6 +16,6 @@ export const overlay = style([
{ {
opacity: 0.72, opacity: 0.72,
overflow: 'hidden', overflow: 'hidden',
zIndex: Z_INDEX.modalBackdrop - 1, zIndex: Z_INDEX.modalBackdrop + 1,
}, },
]) ])
...@@ -143,7 +143,7 @@ const findNFTsPurchased = ( ...@@ -143,7 +143,7 @@ const findNFTsPurchased = (
) )
}) })
return combineBuyItemsWithTxRoute(transferredItems, txRoute) return combineBuyItemsWithTxRoute(transferredItems, txRoute).updatedAssets
} }
const findNFTsNotPurchased = (toBuy: GenieAsset[], nftsPurchased: UpdatedGenieAsset[]) => { const findNFTsNotPurchased = (toBuy: GenieAsset[], nftsPurchased: UpdatedGenieAsset[]) => {
......
...@@ -96,4 +96,5 @@ export enum BagStatus { ...@@ -96,4 +96,5 @@ export enum BagStatus {
FETCHING_FINAL_ROUTE = 'Fetching final route', FETCHING_FINAL_ROUTE = 'Fetching final route',
CONFIRMING_IN_WALLET = 'Confirming in wallet', CONFIRMING_IN_WALLET = 'Confirming in wallet',
PROCESSING_TRANSACTION = 'Processing', PROCESSING_TRANSACTION = 'Processing',
CONFIRM_QUOTE = 'Confirm quote',
} }
...@@ -19,8 +19,11 @@ const isTheSame = (item: GenieAsset, routeAsset: BuyItem | PriceInfo) => { ...@@ -19,8 +19,11 @@ const isTheSame = (item: GenieAsset, routeAsset: BuyItem | PriceInfo) => {
} }
} }
const isPriceDiff = (oldPrice: string, newPrice: string) => { const getPriceDiff = (oldPrice: string, newPrice: string): { hasPriceDiff: boolean; hasVisiblePriceDiff: boolean } => {
return formatWeiToDecimal(oldPrice) !== formatWeiToDecimal(newPrice) const hasPriceDiff = oldPrice !== newPrice
const hasVisiblePriceDiff = formatWeiToDecimal(oldPrice) !== formatWeiToDecimal(newPrice)
return { hasPriceDiff, hasVisiblePriceDiff }
} }
const isAveragePriceOfPooledAssets = ( const isAveragePriceOfPooledAssets = (
...@@ -28,7 +31,7 @@ const isAveragePriceOfPooledAssets = ( ...@@ -28,7 +31,7 @@ const isAveragePriceOfPooledAssets = (
numberOfAssetsInPool: number, numberOfAssetsInPool: number,
expectedPrice: string expectedPrice: string
): boolean => { ): boolean => {
return !isPriceDiff(calcAvgGroupPoolPrice(asset, numberOfAssetsInPool), expectedPrice) return !getPriceDiff(calcAvgGroupPoolPrice(asset, numberOfAssetsInPool), expectedPrice).hasVisiblePriceDiff
} }
const isAveragedPrice = ( const isAveragedPrice = (
...@@ -74,11 +77,11 @@ const itemInRouteAndSamePool = ( ...@@ -74,11 +77,11 @@ const itemInRouteAndSamePool = (
export const combineBuyItemsWithTxRoute = ( export const combineBuyItemsWithTxRoute = (
items: UpdatedGenieAsset[], items: UpdatedGenieAsset[],
txRoute?: RoutingItem[] txRoute?: RoutingItem[]
): UpdatedGenieAsset[] => { ): { hasPriceAdjustment: boolean; updatedAssets: UpdatedGenieAsset[] } => {
return items.map((item) => { let hasPriceAdjustment = false
const updatedAssets = items.map((item) => {
const route = getRouteForItem(item, txRoute) const route = getRouteForItem(item, txRoute)
// if the item is not found in txRoute, it means it's no longer for sale
if (txRoute && !route) { if (txRoute && !route) {
return { return {
...item, ...item,
...@@ -86,15 +89,21 @@ export const combineBuyItemsWithTxRoute = ( ...@@ -86,15 +89,21 @@ export const combineBuyItemsWithTxRoute = (
} }
} }
const newPriceInfo = item.updatedPriceInfo ? item.updatedPriceInfo : item.priceInfo let newPriceInfo = item.updatedPriceInfo ? item.updatedPriceInfo : item.priceInfo
// if the price changed
if (route && 'priceInfo' in route.assetOut) { if (route && 'priceInfo' in route.assetOut) {
if (isPriceDiff(newPriceInfo.basePrice, route.assetOut.priceInfo.basePrice)) { const { hasPriceDiff, hasVisiblePriceDiff } = getPriceDiff(
newPriceInfo.basePrice,
route.assetOut.priceInfo.basePrice
)
newPriceInfo = route.assetOut.priceInfo
hasPriceAdjustment = hasPriceDiff
if (hasVisiblePriceDiff) {
if (!isAveragedPrice(item, items, route, txRoute)) { if (!isAveragedPrice(item, items, route, txRoute)) {
return { return {
...item, ...item,
updatedPriceInfo: route.assetOut.priceInfo, updatedPriceInfo: newPriceInfo,
} }
} }
} }
...@@ -107,4 +116,6 @@ export const combineBuyItemsWithTxRoute = ( ...@@ -107,4 +116,6 @@ export const combineBuyItemsWithTxRoute = (
orderSource: route && 'orderSource' in route.assetOut ? route.assetOut.orderSource : undefined, orderSource: route && 'orderSource' in route.assetOut ? route.assetOut.orderSource : undefined,
} }
}) })
return { hasPriceAdjustment, updatedAssets }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment