diff --git a/packages/web/components/place-limit-tool/index.tsx b/packages/web/components/place-limit-tool/index.tsx index 202e8ae067..7456fd3c3e 100644 --- a/packages/web/components/place-limit-tool/index.tsx +++ b/packages/web/components/place-limit-tool/index.tsx @@ -143,8 +143,8 @@ export const PlaceLimitTool: FunctionComponent = observer( const { onOpenWalletSelect } = useWalletSelect(); const slippageConfig = useSlippageConfig({ - defaultSlippage: quoteType === "in-given-out" ? "1" : "0.5", - selectedIndex: quoteType === "in-given-out" ? 1 : 0, + defaultSlippage: quoteType === "in-given-out" ? "0.5" : "0.5", + selectedIndex: quoteType === "in-given-out" ? 0 : 0, }); const swapState = usePlaceLimit({ @@ -160,14 +160,14 @@ export const PlaceLimitTool: FunctionComponent = observer( }); const resetSlippage = useCallback(() => { - const defaultSlippage = quoteType === "in-given-out" ? "1" : "0.5"; + const defaultSlippage = quoteType === "in-given-out" ? "0.5" : "0.5"; if ( slippageConfig.slippage.toDec() === new Dec(defaultSlippage).quo(DecUtils.getTenExponentN(2)) ) { return; } - slippageConfig.select(quoteType === "in-given-out" ? 1 : 0); + slippageConfig.select(quoteType === "in-given-out" ? 0 : 0); slippageConfig.setDefaultSlippage(defaultSlippage); }, [quoteType, slippageConfig]); @@ -290,7 +290,7 @@ export const PlaceLimitTool: FunctionComponent = observer( return; } - if (type === "market") { + if (type === "market" || (amountType === "fiat" && tab === "buy")) { setMarketAmount(updatedValue); } const isFocused = focused === amountType; diff --git a/packages/web/components/swap-tool/alt.tsx b/packages/web/components/swap-tool/alt.tsx index 8b55b67592..1688b1dcfb 100644 --- a/packages/web/components/swap-tool/alt.tsx +++ b/packages/web/components/swap-tool/alt.tsx @@ -113,8 +113,8 @@ export const AltSwapTool: FunctionComponent = observer( const account = accountStore.getWallet(chainId); const slippageConfig = useSlippageConfig({ - defaultSlippage: quoteType === "in-given-out" ? "1" : "0.5", - selectedIndex: quoteType === "in-given-out" ? 1 : 0, + defaultSlippage: quoteType === "in-given-out" ? "0.5" : "0.5", + selectedIndex: quoteType === "in-given-out" ? 0 : 0, }); const swapState = useSwap({ @@ -189,14 +189,14 @@ export const AltSwapTool: FunctionComponent = observer( }, [setBuyOpen, setSellOpen]); const resetSlippage = useCallback(() => { - const defaultSlippage = quoteType === "in-given-out" ? "1" : "0.5"; + const defaultSlippage = quoteType === "in-given-out" ? "0.5" : "0.5"; if ( slippageConfig.slippage.toDec() === new Dec(defaultSlippage).quo(DecUtils.getTenExponentN(2)) ) { return; } - slippageConfig.select(quoteType === "in-given-out" ? 1 : 0); + slippageConfig.select(quoteType === "in-given-out" ? 0 : 0); slippageConfig.setDefaultSlippage(defaultSlippage); }, [quoteType, slippageConfig]); @@ -282,8 +282,8 @@ export const AltSwapTool: FunctionComponent = observer( buttonText = t("swap.continueAnyway"); } else if ( !!swapState.networkFeeError && - (swapState.isSlippageOverBalance || - swapState.networkFeeError.message.includes("insufficient funds")) + swapState.isSlippageOverBalance && + swapState.networkFeeError.message.includes("insufficient funds") ) { buttonText = t("swap.slippageOverBalance"); } else { diff --git a/packages/web/hooks/limit-orders/use-place-limit.ts b/packages/web/hooks/limit-orders/use-place-limit.ts index 7157e8f46c..88f5b2b877 100644 --- a/packages/web/hooks/limit-orders/use-place-limit.ts +++ b/packages/web/hooks/limit-orders/use-place-limit.ts @@ -76,6 +76,13 @@ export const usePlaceLimit = ({ baseDenom, }); + const isMarket = useMemo( + () => type === "market", + //|| priceState.isBeyondOppositePrice + // Disabled auto market placing but can be readded with the above conditional + [type] + ); + const swapAssets = useSwapAssets({ initialFromDenom: baseDenom, initialToDenom: quoteDenom, @@ -93,19 +100,12 @@ export const usePlaceLimit = ({ useQueryParams: false, useOtherCurrencies, maxSlippage, - quoteType, + quoteType: type !== "market" ? "out-given-in" : quoteType, }); const quoteAsset = swapAssets.toAsset; const baseAsset = swapAssets.fromAsset; - const isMarket = useMemo( - () => type === "market", - //|| priceState.isBeyondOppositePrice - // Disabled auto market placing but can be readded with the above conditional - [type] - ); - const account = accountStore.getWallet(osmosisChainId); // TODO: Readd this once orderbooks support non-stablecoin pairs @@ -149,7 +149,8 @@ export const usePlaceLimit = ({ } // Determine the outgoing fiat amount the user wants to buy - const outgoingFiatValue = inAmountInput.amount?.toDec() ?? new Dec(0); + const outgoingFiatValue = + marketState.inAmountInput.amount?.toDec() ?? new Dec(0); // Determine the amount of quote asset tokens to send by dividing the outgoing fiat amount by the current quote asset price // Multiply by 10^n where n is the amount of decimals for the quote asset diff --git a/packages/web/hooks/use-estimate-tx-fees.ts b/packages/web/hooks/use-estimate-tx-fees.ts index 28e9920465..b4ab8d7033 100644 --- a/packages/web/hooks/use-estimate-tx-fees.ts +++ b/packages/web/hooks/use-estimate-tx-fees.ts @@ -136,7 +136,6 @@ export function useEstimateTxFees({ return new SwapRequiresError(queryResult.error.message); } - if (queryResult.error) console.log(messages, queryResult.error); return queryResult.error; }, [queryResult.error]); diff --git a/packages/web/hooks/use-swap.tsx b/packages/web/hooks/use-swap.tsx index 202ec802c5..f877049928 100644 --- a/packages/web/hooks/use-swap.tsx +++ b/packages/web/hooks/use-swap.tsx @@ -212,12 +212,6 @@ export function useSwap( ? trimPlaceholderZeros(inGivenOutQuote.amount.toDec().toString()) : "" ); - } else if ( - quoteType === "in-given-out" && - outAmountInput.isEmpty && - !inAmountInput.isEmpty - ) { - inAmountInput.setAmount(""); } if ( @@ -230,12 +224,6 @@ export function useSwap( ? trimPlaceholderZeros(quote.amount.toDec().toString()) : "" ); - } else if ( - quoteType === "out-given-in" && - inAmountInput.isEmpty && - !outAmountInput.isEmpty - ) { - outAmountInput.setAmount(""); } /** @@ -1784,21 +1772,14 @@ export function useDynamicSlippageConfig({ if (!required || !sent) return; - console.log(`Required: ${required}`); - console.log(`Sent: ${sent}`); - console.log("Current slippage", slippage.toString()); const amountPreSlippage = new Dec(sent).quo(slippage); const slippageRequired = new Dec(required).quo(amountPreSlippage); - console.log("Slippage Required", slippageRequired.toString()); - if (slippageRequired.gt(slippage) && slippage.lt(new Dec(1.05))) { const [index, amount] = slippageConfig.getSmallestSlippage( slippageRequired.sub(new Dec(1)) ); - console.log("Setting slippage to", amount.toString()); - slippageConfig.select(index as number); slippageConfig.setDefaultSlippage( trimPlaceholderZeros(