Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove logs and correct limit input amount #3788

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/web/components/place-limit-tool/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ export const PlaceLimitTool: FunctionComponent<PlaceLimitToolProps> = 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({
Expand All @@ -160,14 +160,14 @@ export const PlaceLimitTool: FunctionComponent<PlaceLimitToolProps> = 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]);

Expand Down Expand Up @@ -290,7 +290,7 @@ export const PlaceLimitTool: FunctionComponent<PlaceLimitToolProps> = observer(
return;
}

if (type === "market") {
if (type === "market" || (amountType === "fiat" && tab === "buy")) {
setMarketAmount(updatedValue);
}
const isFocused = focused === amountType;
Expand Down
12 changes: 6 additions & 6 deletions packages/web/components/swap-tool/alt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ export const AltSwapTool: FunctionComponent<SwapToolProps> = 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({
Expand Down Expand Up @@ -189,14 +189,14 @@ export const AltSwapTool: FunctionComponent<SwapToolProps> = 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]);

Expand Down Expand Up @@ -282,8 +282,8 @@ export const AltSwapTool: FunctionComponent<SwapToolProps> = 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 {
Expand Down
19 changes: 10 additions & 9 deletions packages/web/hooks/limit-orders/use-place-limit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion packages/web/hooks/use-estimate-tx-fees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down
19 changes: 0 additions & 19 deletions packages/web/hooks/use-swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -230,12 +224,6 @@ export function useSwap(
? trimPlaceholderZeros(quote.amount.toDec().toString())
: ""
);
} else if (
quoteType === "out-given-in" &&
inAmountInput.isEmpty &&
!outAmountInput.isEmpty
) {
outAmountInput.setAmount("");
}

/**
Expand Down Expand Up @@ -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(
Expand Down
Loading