Skip to content

Commit

Permalink
feat(indexer): include deposit tracking for load testing
Browse files Browse the repository at this point in the history
Signed-off-by: james-a-morris <[email protected]>
  • Loading branch information
james-a-morris committed Nov 20, 2024
1 parent dcb3b15 commit c920567
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
75 changes: 75 additions & 0 deletions src/hooks/useIndexerDepositTracking.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { useQueries } from "@tanstack/react-query";
import axios from "axios";
import { BigNumber } from "ethers";
import { indexerApiBaseUrl, isDefined } from "utils";

/**
* A hook used to track the statuses of multiple deposits via the indexer API
* @param deposits Array of deposit objects containing `originChainId` and `depositId`
*/
export function useIndexerDepositsTracking(
deposits: {
originChainId?: number;
depositId?: number;
}[]
) {
const queries = useQueries({
queries: deposits.map((deposit) => ({
queryKey: [
"indexer_deposit_tracking",
deposit.originChainId,
deposit.depositId,
] as [string, number, number],
enabled:
isDefined(deposit.originChainId) &&
isDefined(deposit.depositId) &&
isDefined(indexerApiBaseUrl),
queryFn: async (): Promise<BigNumber | undefined> => {
try {
const response = await axios.get(
`${indexerApiBaseUrl}/deposit/status`,
{
params: {
originChainId: deposit.originChainId,
depositId: deposit.depositId,
},
}
);
return response.data;
} catch (e) {
// FIXME: for now we ignore since this is for load testing purposes
}
},
refetchInterval: 5_000, // 5 seconds
})),
});

return queries.map((query) => ({
depositStatus: query.data ?? undefined,
...query,
}));
}

/**
* A hook used to track a single deposit status via the indexer API
* @param originChainId The chain ID of the deposit's origin
* @param depositId The deposit ID
*/
export function useIndexerDepositTracking(
originChainId?: number,
depositId?: number
) {
const [singleDeposit] = useIndexerDepositsTracking(
isDefined(originChainId) && isDefined(depositId)
? [{ originChainId, depositId }]
: []
);

return (
singleDeposit ?? {
depositStatus: undefined,
isLoading: false,
isError: false,
}
);
}
3 changes: 3 additions & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,3 +536,6 @@ export const vercelApiBaseUrl =
export const defaultSwapSlippage = Number(
process.env.REACT_APP_DEFAULT_SWAP_SLIPPAGE || 0.5
);

export const indexerApiBaseUrl =
process.env.REACT_APP_INDEXER_BASE_URL || undefined;
9 changes: 9 additions & 0 deletions src/views/Transactions/components/PersonalTransactions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { EmptyTable } from "./EmptyTable";
import { usePersonalTransactions } from "../hooks/usePersonalTransactions";
import { DepositStatusFilter } from "../types";
import { SpeedUpModal } from "./SpeedUpModal";
import { useIndexerDepositsTracking } from "hooks/useIndexerDepositTracking";

type Props = {
statusFilter: DepositStatusFilter;
Expand All @@ -32,6 +33,14 @@ export function PersonalTransactions({ statusFilter }: Props) {
const history = useHistory();
const queryClient = useQueryClient();

// FIXME: remove after tracking is complete
void useIndexerDepositsTracking(
deposits.map((d) => ({
depositId: d.depositId,
originChainId: d.sourceChainId,
}))
);

if (!isConnected) {
return (
<EmptyTable>
Expand Down

0 comments on commit c920567

Please sign in to comment.