Skip to content

Commit

Permalink
[Limit Orders]: Price to Tick Crash Handler (#3838)
Browse files Browse the repository at this point in the history
* fix: price to tick error handling

* feat: added swap source to swap amplitude events

---------

Co-authored-by: Matt Upham <[email protected]>
  • Loading branch information
crnbarr93 and mattupham authored Sep 10, 2024
1 parent 8f3e076 commit cbdebf0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
1 change: 1 addition & 0 deletions packages/web/components/swap-tool/alt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ export const AltSwapTool: FunctionComponent<SwapToolProps> = observer(
feeValueUsd: Number(swapState.totalFee?.toString() ?? "0"),
page,
quoteTimeMilliseconds: swapState.quote?.timeMs,
swapSource: "swap" as "swap" | "market",
};
logEvent([EventName.Swap.swapStarted, baseEvent]);
setIsSendingTx(true);
Expand Down
1 change: 1 addition & 0 deletions packages/web/config/analytics-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export type EventProperties = {
isRecommendedVariant: boolean;
walletName: string;
transferDirection: "deposit" | "withdraw";
swapSource: "market" | "swap";
coinDenom: string;
appName: string;
isFeatured: boolean;
Expand Down
34 changes: 20 additions & 14 deletions packages/web/hooks/limit-orders/use-place-limit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,21 +225,26 @@ export const usePlaceLimit = ({
return;
}

// The requested price must account for the ratio between the quote and base asset as the base asset may not be a stablecoin.
// To account for this we divide by the quote asset price.
const tickId = priceToTick(
priceState.price.quo(quoteAssetPrice.toDec()).mul(normalizationFactor)
);
const msg = {
place_limit: {
tick_id: parseInt(tickId.toString()),
order_direction: orderDirection,
quantity,
claim_bounty: CLAIM_BOUNTY,
},
};
try {
// The requested price must account for the ratio between the quote and base asset as the base asset may not be a stablecoin.
// To account for this we divide by the quote asset price.
const tickId = priceToTick(
priceState.price.quo(quoteAssetPrice.toDec()).mul(normalizationFactor)
);
const msg = {
place_limit: {
tick_id: parseInt(tickId.toString()),
order_direction: orderDirection,
quantity,
claim_bounty: CLAIM_BOUNTY,
},
};

return msg;
return msg;
} catch (error) {
console.error("Error attempting to place limit order", error);
return;
}
}, [
orderDirection,
priceState.price,
Expand Down Expand Up @@ -295,6 +300,7 @@ export const usePlaceLimit = ({
feeValueUsd: Number(marketState.totalFee?.toString() ?? "0"),
page,
quoteTimeMilliseconds: marketState.quote?.timeMs,
swapSource: "market" as "swap" | "market",
};
try {
logEvent([EventName.Swap.swapStarted, baseEvent]);
Expand Down

0 comments on commit cbdebf0

Please sign in to comment.