-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use PolkadotAPI to show live chain data and Bug fixes in stats-dapp (#…
…1566) Co-authored-by: Trung-Tin Pham <[email protected]>
- Loading branch information
1 parent
702fb33
commit a006862
Showing
17 changed files
with
276 additions
and
156 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
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
66 changes: 29 additions & 37 deletions
66
apps/stats-dapp/src/containers/KeyStatusCardContainer/KeyStatusCardContainer.tsx
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 |
---|---|---|
@@ -1,57 +1,49 @@ | ||
import { KeyStatusCard } from '@webb-tools/webb-ui-components/components/KeyStatusCard'; | ||
import { KeyStatusCardProps } from '@webb-tools/webb-ui-components/components/KeyStatusCard/types'; | ||
import { Spinner } from '@webb-tools/icons'; | ||
import React, { FC, forwardRef, useMemo } from 'react'; | ||
import { KeyStatusCardContainerProps } from './types'; | ||
import { useStatsContext } from '../../provider/stats-provider'; | ||
import { PublicKey, useActiveKeys } from '../../provider/hooks'; | ||
import { useBlocks } from '../../provider/hooks'; | ||
import { useMemo } from 'react'; | ||
|
||
/** | ||
* The wrapper of UI component. Handle logic and mapping fields between backend API and component API | ||
*/ | ||
export const KeyStatusCardContainer = () => { | ||
const { dkgDataFromPolkadotAPI, sessionHeight } = useStatsContext(); | ||
|
||
const { error, isFailed, isLoading, val: data } = useActiveKeys(); | ||
|
||
const { currentKey } = useMemo<{ | ||
currentKey: PublicKey | null | undefined; | ||
}>(() => { | ||
return { | ||
currentKey: data ? data[0] : null, | ||
}; | ||
}, [data]); | ||
const { | ||
dkgDataFromPolkadotAPI: { | ||
currentSessionNumber, | ||
currentKey, | ||
currentSessionTimeFrame: { start: sessionStart, end: sessionEnd }, | ||
currentAuthorities, | ||
}, | ||
} = useStatsContext(); | ||
|
||
const { time } = useStatsContext(); | ||
|
||
const authorities = useMemo( | ||
() => | ||
(currentKey?.keyGenAuthorities ?? []).reduce((acc, cur) => { | ||
acc.add(cur); | ||
return acc; | ||
}, new Set() as KeyStatusCardProps['authorities']) ?? new Set<string>(), | ||
[data] | ||
); | ||
const { val: blocksData } = useBlocks(); | ||
|
||
const showDetails = useMemo(() => { | ||
if (blocksData?.finalized && blocksData?.latestIndexedBlock) { | ||
if (blocksData.finalized - blocksData.latestIndexedBlock < 5) { | ||
return true; | ||
} | ||
} | ||
|
||
const activeKeyData = useMemo(() => { | ||
return { | ||
key: currentKey?.compressed, | ||
session: Number(currentKey?.session), | ||
}; | ||
}, [data, currentKey]); | ||
return false; | ||
}, [blocksData]); | ||
|
||
return ( | ||
<KeyStatusCard | ||
title="Active Key" | ||
titleInfo="The public key of the DKG protocol that is currently active." | ||
instance={time} | ||
sessionNumber={activeKeyData.session} | ||
sessionNumber={currentSessionNumber} | ||
keyType="current" | ||
keyVal={activeKeyData.key ?? ''} | ||
startTime={currentKey?.start ?? null} | ||
endTime={currentKey?.end ?? null} | ||
authorities={authorities ?? new Set<string>()} | ||
totalAuthorities={authorities.size ?? 0} | ||
fullDetailUrl={data ? `drawer/${currentKey?.id}` : ''} | ||
keyVal={currentKey ?? ''} | ||
startTime={sessionStart} | ||
endTime={sessionEnd} | ||
authorities={new Set<string>(currentAuthorities) ?? new Set<string>()} | ||
totalAuthorities={0} | ||
fullDetailUrl={currentKey ? `drawer/${currentKey}` : ''} | ||
showDetails={showDetails} | ||
/> | ||
); | ||
}; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,3 +98,9 @@ query LatestThresholds( | |
} | ||
} | ||
} | ||
|
||
query LatestSessionId { | ||
sessions { | ||
totalCount | ||
} | ||
} |
Oops, something went wrong.