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

Add "slippageChange" plausible event #1615

Merged
merged 2 commits into from
Nov 1, 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
8 changes: 8 additions & 0 deletions apps/hyperdrive-trading/src/ui/analytics/Plausible.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ export interface PlausibleEventParamsMap {
chainId: number;
poolAddress: string;
positionType: PositionType;
positionSize: string;
feeAmount: string;
};
};
slippageChange: {
props: {
value: string;
// TODO: Should we add change/delta?
};
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parseFixed } from "@delvtech/fixed-point-wasm";
import { fixed, parseFixed } from "@delvtech/fixed-point-wasm";
import {
HyperdriveConfig,
TokenConfig,
Expand Down Expand Up @@ -52,6 +52,8 @@ export function OpenLongPreview({
chainId: hyperdrive.chainId,
poolAddress: hyperdrive.address,
positionType: "long",
positionSize: fixed(bondAmount, baseToken.decimals).toString(),
feeAmount: fixed(curveFee ?? 0, baseToken.decimals).toString(),
},
});
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parseFixed } from "@delvtech/fixed-point-wasm";
import { fixed, parseFixed } from "@delvtech/fixed-point-wasm";
import {
HyperdriveConfig,
appConfig,
Expand Down Expand Up @@ -71,6 +71,8 @@ export function OpenShortPreview({
chainId: hyperdrive.chainId,
poolAddress: hyperdrive.address,
positionType: "short",
positionSize: fixed(shortSize ?? 0, baseToken.decimals).toString(),
feeAmount: fixed(curveFee ?? 0, baseToken.decimals).toString(),
},
});
return true;
Expand Down
11 changes: 9 additions & 2 deletions apps/hyperdrive-trading/src/ui/token/SlippageSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ export function SlippageSettings({
onActiveOptionChange: (activeTab: "auto" | "custom") => void;
tooltip?: string;
}): JSX.Element {
function handleSlippageChange(value: string) {
window.plausible("slippageChange", {
props: { value },
});
onSlippageChange(value);
}

return (
<>
<div className="flex items-center">
Expand All @@ -34,7 +41,7 @@ export function SlippageSettings({
onClick={(e) => {
e.preventDefault();
onActiveOptionChange("auto");
onSlippageChange(DEFAULT_SLIPPAGE_AMOUNT);
handleSlippageChange(DEFAULT_SLIPPAGE_AMOUNT);
}}
className={classNames("daisy-tab text-sm", {
"font-bold": activeOption === "auto",
Expand All @@ -58,7 +65,7 @@ export function SlippageSettings({
value={slippage}
onChange={(e) => {
onActiveOptionChange("custom");
onSlippageChange(e);
handleSlippageChange(e);
}}
/>
</div>
Expand Down
11 changes: 9 additions & 2 deletions apps/hyperdrive-trading/src/ui/token/SlippageSettingsTwo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ export function SlippageSettingsTwo({
}): ReactElement {
const [isDropdownOpen, setIsDropdownOpen] = useState(false);

function handleSlippageChange(value: string) {
window.plausible("slippageChange", {
props: { value },
});
onSlippageChange(value);
}

return (
<div className="daisy-dropdown daisy-dropdown-bottom flex justify-end">
<button
Expand Down Expand Up @@ -59,7 +66,7 @@ export function SlippageSettingsTwo({
onClick={(e) => {
e.preventDefault();
onActiveOptionChange("auto");
onSlippageChange(DEFAULT_SLIPPAGE_AMOUNT);
handleSlippageChange(DEFAULT_SLIPPAGE_AMOUNT);
}}
className={classNames("daisy-tab text-sm", {
"font-bold": activeOption === "auto",
Expand All @@ -84,7 +91,7 @@ export function SlippageSettingsTwo({
value={slippage}
onChange={(e) => {
onActiveOptionChange("custom");
onSlippageChange(e);
handleSlippageChange(e);
}}
/>
</div>
Expand Down
Loading