Skip to content

Commit

Permalink
feat: prefills hashes if we're already in VerifiedConfigs
Browse files Browse the repository at this point in the history
  • Loading branch information
Kodylow committed Nov 2, 2023
1 parent 58a4970 commit 28c5acd
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion apps/guardian-ui/src/components/VerifyGuardians.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const VerifyGuardians: React.FC<Props> = ({ next }) => {
// Poll for peers and configGenParams while on this page.
useConsensusPolling();

const verifiedConfigs = peers.every(
const verifiedConfigs: boolean = peers.every(
(peer) => peer.status === ServerStatus.VerifiedConfigs
);

Expand Down Expand Up @@ -78,6 +78,16 @@ export const VerifyGuardians: React.FC<Props> = ({ next }) => {
}))
.filter((peer) => peer.id !== our_current_id.toString())
);

// If we're already at the VerifiedConfigs state, prefill all the other hashes with the correct values
if (peers[our_current_id].status === ServerStatus.VerifiedConfigs) {
const otherPeers = Object.entries(peers).filter(
([id]) => id !== our_current_id.toString()
);
setEnteredHashes(
otherPeers.map(([id]) => hashes[id as unknown as number])
);
}
} catch (err) {
setError(formatApiErrorMessage(err));
}
Expand All @@ -96,13 +106,15 @@ export const VerifyGuardians: React.FC<Props> = ({ next }) => {
});
return;
}

const isAllValid =
peersWithHash &&
peersWithHash.every(({ hash }, idx) => hash === enteredHashes[idx]);

if (isAllValid) {
!verifiedConfigs &&
api.verifiedConfigs().catch((err) => {
console.log('Error: ', err);
setError(formatApiErrorMessage(err));
});
}
Expand Down

0 comments on commit 28c5acd

Please sign in to comment.