Skip to content

Commit 41038ae

Browse files
authored
add env var for polling ops (#83)
1 parent 20a64bd commit 41038ae

File tree

6 files changed

+20
-7
lines changed

6 files changed

+20
-7
lines changed

.env.sample

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ BANNER_CONTENT=
1010
RECLAIM_LOCK_TIME=
1111
NEXT_TELEMETRY_DISABLED=1
1212
LIVECHAT_ID=
13+
POLLING_INTERVAL=5000

src/actions/get-sbtc-bridge-config.ts

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default cache(async function getSbtcBridgeConfig() {
1414
const RECLAIM_LOCK_TIME = env.RECLAIM_LOCK_TIME;
1515
const PUBLIC_MEMPOOL_URL = env.PUBLIC_MEMPOOL_URL;
1616
const LIVECHAT_ID = env.LIVECHAT_ID;
17+
const POLLING_INTERVAL = env.POLLING_INTERVAL;
1718

1819
return {
1920
EMILY_URL,
@@ -23,5 +24,6 @@ export default cache(async function getSbtcBridgeConfig() {
2324
RECLAIM_LOCK_TIME,
2425
PUBLIC_MEMPOOL_URL,
2526
LIVECHAT_ID,
27+
POLLING_INTERVAL,
2628
};
2729
});

src/env.ts

+1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ export const env = {
2020
BANNER_CONTENT: process.env.BANNER_CONTENT,
2121
RECLAIM_LOCK_TIME: process.env.RECLAIM_LOCK_TIME,
2222
LIVECHAT_ID: process.env.LIVECHAT_ID,
23+
POLLING_INTERVAL: Number(process.env.POLLING_INTERVAL) || 5000,
2324
};

src/hooks/use-deposit-status.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@ export function useDepositStatus(txId: string) {
3636
const confirmedBlockHeight = useMemo(() => {
3737
return statusResponse?.status.block_height || 0;
3838
}, [statusResponse]);
39-
const { EMILY_URL: emilyUrl, RECLAIM_LOCK_TIME } =
40-
useAtomValue(bridgeConfigAtom);
39+
const {
40+
EMILY_URL: emilyUrl,
41+
RECLAIM_LOCK_TIME,
42+
POLLING_INTERVAL,
43+
} = useAtomValue(bridgeConfigAtom);
4144

4245
const recipient = useMemo(() => {
4346
return emilyResponse?.recipient || "";
@@ -105,10 +108,11 @@ export function useDepositStatus(txId: string) {
105108
}
106109
};
107110
check();
108-
const interval = setInterval(check, 5000);
111+
const interval = setInterval(check, POLLING_INTERVAL);
109112
return () => clearInterval(interval);
110113
}
111114
}, [
115+
POLLING_INTERVAL,
112116
RECLAIM_LOCK_TIME,
113117
emilyUrl,
114118
notifyEmily,

src/hooks/use-reclaim-status.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { getRawTransaction } from "@/actions/bitcoinClient";
2+
import { bridgeConfigAtom } from "@/util/atoms";
3+
import { useAtomValue } from "jotai";
24
import { useEffect, useState } from "react";
35

46
export enum ReclaimStatus {
@@ -8,6 +10,7 @@ export enum ReclaimStatus {
810
}
911

1012
export const useReclaimStatus = (txId: string) => {
13+
const { POLLING_INTERVAL } = useAtomValue(bridgeConfigAtom);
1114
// we'll need to fetch this from the bitcoin rpc to get the current status of the tx
1215
const [reclaimStatus, setReclaimStatus] = useState<ReclaimStatus>(
1316
ReclaimStatus.Pending,
@@ -17,8 +20,7 @@ export const useReclaimStatus = (txId: string) => {
1720
if (txId && reclaimStatus !== ReclaimStatus.Completed) {
1821
// fetch the status of the reclaim tx from the bitcoin rpc
1922
// and update the reclaimStatus
20-
21-
const interval = setInterval(async () => {
23+
const check = async () => {
2224
const reclaimTx = (await getRawTransaction(txId))!;
2325
let status = ReclaimStatus.Pending;
2426

@@ -28,10 +30,12 @@ export const useReclaimStatus = (txId: string) => {
2830
}
2931

3032
setReclaimStatus(status);
31-
}, 1000);
33+
};
34+
check();
35+
const interval = setInterval(check, POLLING_INTERVAL);
3236
return () => clearInterval(interval);
3337
}
34-
}, [reclaimStatus, txId]);
38+
}, [POLLING_INTERVAL, reclaimStatus, txId]);
3539

3640
return reclaimStatus;
3741
};

src/util/atoms.ts

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const bridgeConfigAtom = atom<BridgeConfig>({
1717
RECLAIM_LOCK_TIME: undefined,
1818
PUBLIC_MEMPOOL_URL: "",
1919
LIVECHAT_ID: undefined,
20+
POLLING_INTERVAL: 5000,
2021
});
2122
export const depositMaxFeeAtom = atom(80000);
2223

0 commit comments

Comments
 (0)