-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(indexer): include deposit tracking for load testing
Signed-off-by: james-a-morris <[email protected]>
- Loading branch information
1 parent
dcb3b15
commit c920567
Showing
3 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters