bridge_ui: use solana slot sub for loader

Change-Id: I8c765dbe3d788797452630d06476089c1081a480
This commit is contained in:
Evan Gray 2021-09-13 12:45:15 -04:00
parent 924da96555
commit 45f81981b5
1 changed files with 14 additions and 17 deletions

View File

@ -39,8 +39,8 @@ export default function TransferProgress({ nft }: { nft?: boolean }) {
const [currentBlock, setCurrentBlock] = useState(0); const [currentBlock, setCurrentBlock] = useState(0);
useEffect(() => { useEffect(() => {
if (isSendComplete || !transferTx) return; if (isSendComplete || !transferTx) return;
let cancelled = false;
if (sourceChain === CHAIN_ID_ETH && provider) { if (sourceChain === CHAIN_ID_ETH && provider) {
let cancelled = false;
(async () => { (async () => {
while (!cancelled) { while (!cancelled) {
await new Promise((resolve) => setTimeout(resolve, 500)); await new Promise((resolve) => setTimeout(resolve, 500));
@ -54,26 +54,23 @@ export default function TransferProgress({ nft }: { nft?: boolean }) {
} }
} }
})(); })();
return () => {
cancelled = true;
};
} }
if (sourceChain === CHAIN_ID_SOLANA) { if (sourceChain === CHAIN_ID_SOLANA) {
(async () => { let cancelled = false;
const connection = new Connection(SOLANA_HOST, "confirmed"); const connection = new Connection(SOLANA_HOST, "confirmed");
while (!cancelled) { const sub = connection.onSlotChange((slotInfo) => {
await new Promise((resolve) => setTimeout(resolve, 200)); if (!cancelled) {
try { setCurrentBlock(slotInfo.slot);
const newBlock = await connection.getSlot();
if (!cancelled) {
setCurrentBlock(newBlock);
}
} catch (e) {
console.error(e);
}
} }
})(); });
return () => {
cancelled = true;
connection.removeSlotChangeListener(sub);
};
} }
return () => {
cancelled = true;
};
}, [isSendComplete, sourceChain, provider, transferTx]); }, [isSendComplete, sourceChain, provider, transferTx]);
const blockDiff = const blockDiff =
transferTx && transferTx.block && currentBlock transferTx && transferTx.block && currentBlock