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

Track amount and asset of successful txs #17

Merged
merged 4 commits into from
Jul 28, 2023
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: 10 additions & 0 deletions src/analytics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import va from "@vercel/analytics";
import { Route } from "./components/TransactionDialog";

export function trackRoute(route: Route) {
va.track("transaction", {
type: route.actionType,
amount: parseFloat(route.amountIn),
asset: route.sourceAsset.symbol,
});
}
13 changes: 12 additions & 1 deletion src/components/TransactionDialog/TransactionDialogContent.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC, Fragment, useState } from "react";
import { FC, Fragment, useEffect, useRef, useState } from "react";
import { useChain, useManager } from "@cosmos-kit/react";
import { ArrowLeftIcon, CheckCircleIcon } from "@heroicons/react/20/solid";
import Toast from "@/elements/Toast";
Expand Down Expand Up @@ -27,6 +27,16 @@ const TransactionDialogContent: FC<Props> = ({

const [warningOpen, setWarningOpen] = useState(false);

const warningEl = useRef<HTMLDivElement>(null);

useEffect(() => {
if (warningOpen) {
warningEl.current?.scrollIntoView({
behavior: "instant",
});
}
}, [warningOpen]);

const chain = useChain(route.sourceChain.record?.name ?? "");

const { chainRecords } = useManager();
Expand Down Expand Up @@ -274,6 +284,7 @@ const TransactionDialogContent: FC<Props> = ({
receive fees or payment of any kind today and subsidize gas
for users cross-chain)
</p>
<div ref={warningEl}></div>
</div>
)}
</div>
Expand Down
3 changes: 3 additions & 0 deletions src/solve/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { MsgTransfer } from "@injectivelabs/sdk-ts";
import { WalletClient } from "@cosmos-kit/core";
import { useSkipClient } from "./hooks";
import { SkipClient, MsgsRequest } from "./client";
import { trackRoute } from "@/analytics";

const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));

Expand Down Expand Up @@ -330,6 +331,8 @@ export async function executeRoute(
onTxSuccess: (tx: any, index: number) => void,
onError: (error: any) => void
) {
trackRoute(route);

await enableChains(walletClient, route.rawRoute.chain_ids);

const userAddresses: Record<string, string> = {};
Expand Down