forked from wormhole-foundation/wormhole
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bridge_ui: minimal transaction count metrics on stats page
Change-Id: I197284b33514b0eb4ece281d982b541dbc5dc015
- Loading branch information
Showing
4 changed files
with
276 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,156 @@ | ||
import { | ||
CircularProgress, | ||
Link, | ||
makeStyles, | ||
Typography, | ||
} from "@material-ui/core"; | ||
import clsx from "clsx"; | ||
import useTransactionCount from "../../hooks/useTransactionCount"; | ||
import { WORMHOLE_EXPLORER_BASE } from "../../utils/consts"; | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
logoPositioner: { | ||
height: "30px", | ||
width: "30px", | ||
maxWidth: "30px", | ||
marginRight: theme.spacing(1), | ||
display: "flex", | ||
alignItems: "center", | ||
}, | ||
logo: { | ||
maxHeight: "100%", | ||
maxWidth: "100%", | ||
}, | ||
tokenContainer: { | ||
display: "flex", | ||
justifyContent: "flex-start", | ||
alignItems: "center", | ||
}, | ||
flexBox: { | ||
display: "flex", | ||
alignItems: "flex-end", | ||
marginBottom: theme.spacing(1), | ||
textAlign: "left", | ||
[theme.breakpoints.down("sm")]: { | ||
flexDirection: "column", | ||
alignItems: "unset", | ||
}, | ||
}, | ||
grower: { | ||
flexGrow: 1, | ||
}, | ||
alignCenter: { | ||
margin: "0 auto", | ||
display: "block", | ||
textAlign: "center", | ||
}, | ||
totalsBox: { | ||
display: "flex", | ||
width: "100%", | ||
justifyContent: "space-evenly", | ||
alignItems: "center", | ||
}, | ||
totalContainer: { | ||
display: "flex", | ||
alignItems: "flex-end", | ||
paddingBottom: 1, // line up with left text bottom | ||
[theme.breakpoints.down("sm")]: { | ||
marginTop: theme.spacing(1), | ||
}, | ||
}, | ||
totalValue: { | ||
marginLeft: theme.spacing(0.5), | ||
marginBottom: "-.125em", // line up number with label | ||
}, | ||
typog: { | ||
marginTop: theme.spacing(3), | ||
}, | ||
})); | ||
|
||
const TransactionMetrics: React.FC<any> = () => { | ||
const transactionCount = useTransactionCount(); | ||
const classes = useStyles(); | ||
const isFetching = transactionCount.isFetching; | ||
|
||
const header = ( | ||
<div className={classes.flexBox}> | ||
<div> | ||
<Typography variant="h5">Transaction Count</Typography> | ||
<Typography variant="subtitle2" color="textSecondary"> | ||
This is how many transactions the Token Bridge has processed. | ||
</Typography> | ||
</div> | ||
<div className={classes.grower} /> | ||
</div> | ||
); | ||
|
||
const content = ( | ||
<div className={classes.totalsBox}> | ||
<div className={classes.totalContainer}> | ||
<Typography | ||
variant="body2" | ||
color="textSecondary" | ||
component="div" | ||
noWrap | ||
> | ||
{"Last 48 Hours"} | ||
</Typography> | ||
<Typography | ||
variant="h3" | ||
component="div" | ||
noWrap | ||
className={classes.totalValue} | ||
> | ||
{transactionCount.data?.total24h || "0"} | ||
</Typography> | ||
</div> | ||
<div className={classes.totalContainer}> | ||
<Typography | ||
variant="body2" | ||
color="textSecondary" | ||
component="div" | ||
noWrap | ||
> | ||
{"All Time"} | ||
</Typography> | ||
<Typography | ||
variant="h3" | ||
component="div" | ||
noWrap | ||
className={classes.totalValue} | ||
> | ||
{transactionCount.data?.totalAllTime || "0"} | ||
</Typography> | ||
</div> | ||
</div> | ||
); | ||
|
||
const networkExplorer = ( | ||
<Typography | ||
variant="subtitle1" | ||
className={clsx(classes.alignCenter, classes.typog)} | ||
> | ||
To see metrics for the entire Wormhole Network (not just this bridge), | ||
check out the{" "} | ||
<Link href={WORMHOLE_EXPLORER_BASE} target="_blank"> | ||
Wormhole Network Explorer | ||
</Link> | ||
</Typography> | ||
); | ||
|
||
return ( | ||
<> | ||
{header} | ||
{isFetching ? ( | ||
<CircularProgress className={classes.alignCenter} /> | ||
) : ( | ||
<> | ||
{content} | ||
{networkExplorer} | ||
</> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default TransactionMetrics; |
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 |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import axios from "axios"; | ||
import { useEffect, useMemo, useState } from "react"; | ||
import { DataWrapper } from "../store/helpers"; | ||
import { | ||
RECENT_TRANSACTIONS_WORMHOLE, | ||
TOTAL_TRANSACTIONS_WORMHOLE, | ||
VAA_EMITTER_ADDRESSES, | ||
} from "../utils/consts"; | ||
|
||
export type TransactionCount = { | ||
totalAllTime: number; | ||
total24h: number; | ||
mostRecent: any; //This will be a signedVAA | ||
}; | ||
|
||
const mergeResults = (totals: any, recents: any): TransactionCount | null => { | ||
let totalAllTime = 0; | ||
let total24h = 0; | ||
VAA_EMITTER_ADDRESSES.forEach((address: string) => { | ||
let totalAll = (totals?.TotalCount && totals.TotalCount[address]) || 0; | ||
let total24 = (totals?.LastDayCount && totals.LastDayCount[address]) || 0; | ||
|
||
totalAllTime += totalAll; | ||
total24h += total24; | ||
}); | ||
|
||
return { | ||
totalAllTime, | ||
total24h, | ||
mostRecent: null, | ||
}; | ||
}; | ||
|
||
const useTransactionCount = (): DataWrapper<TransactionCount> => { | ||
const [totals, setTotals] = useState(null); | ||
const [recents, setRecents] = useState(null); | ||
|
||
const [loadingTotals, setLoadingTotals] = useState(false); | ||
const [loadingRecents, setLoadingRecents] = useState(false); | ||
|
||
const [totalsError, setTotalsError] = useState(""); | ||
const [recentsError, setRecentsError] = useState(""); | ||
|
||
useEffect(() => { | ||
let cancelled = false; | ||
setLoadingTotals(true); | ||
axios.get(TOTAL_TRANSACTIONS_WORMHOLE).then( | ||
(results) => { | ||
if (!cancelled) { | ||
setTotals(results.data); | ||
setLoadingTotals(false); | ||
} | ||
}, | ||
(error) => { | ||
if (!cancelled) { | ||
setTotalsError("Unable to retrieve transaction totals."); | ||
setLoadingTotals(false); | ||
} | ||
} | ||
); | ||
}, []); | ||
|
||
useEffect(() => { | ||
let cancelled = false; | ||
setLoadingRecents(true); | ||
axios.get(RECENT_TRANSACTIONS_WORMHOLE).then( | ||
(results) => { | ||
if (!cancelled) { | ||
setRecents(results.data); | ||
setLoadingRecents(false); | ||
} | ||
}, | ||
(error) => { | ||
if (!cancelled) { | ||
setRecentsError("Unable to retrieve recent transactions."); | ||
setLoadingRecents(false); | ||
} | ||
} | ||
); | ||
}, []); | ||
|
||
return useMemo(() => { | ||
const data = mergeResults(totals, recents); | ||
return { | ||
isFetching: loadingRecents || loadingTotals, | ||
error: totalsError || recentsError, | ||
receivedAt: null, | ||
data: data, | ||
}; | ||
}, [ | ||
totals, | ||
recents, | ||
loadingRecents, | ||
loadingTotals, | ||
recentsError, | ||
totalsError, | ||
]); | ||
}; | ||
|
||
export default useTransactionCount; |
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