-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8788684
commit 2e6f15a
Showing
5 changed files
with
62 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import Tooltip from "../../../ui/tooltip"; | ||
import { toShortAdrress } from "../../../utils"; | ||
|
||
interface Props { | ||
signers: string | null; | ||
heartbeatTimestamp: number | null; | ||
} | ||
|
||
export default function Status({ signers, heartbeatTimestamp }: Props) { | ||
const signersStatus = parseSigners(signers); | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const onlineSigners = signersStatus.filter(([_, isOnline]) => isOnline); | ||
const online = isOnline(heartbeatTimestamp); | ||
|
||
return signersStatus.length > 0 ? ( | ||
<Tooltip | ||
content={ | ||
<div className="flex flex-col items-start gap-2"> | ||
<span className="text-xs font-semibold">{`Total: ${onlineSigners.length} / ${signersStatus.length}`}</span> | ||
{signersStatus.map(([address, isOnline]) => ( | ||
<div key={address} className="flex items-center gap-2"> | ||
<div className={`h-[8px] w-[8px] rounded-full ${isOnline ? "bg-app-green" : "bg-white/50"}`} /> | ||
<span className="text-xs font-semibold">{toShortAdrress(address, 10, 8)}</span> | ||
</div> | ||
))} | ||
</div> | ||
} | ||
className="mx-auto w-fit" | ||
> | ||
<div | ||
className={`h-[8px] w-[8px] rounded-full ${onlineSigners.length === signersStatus.length ? "bg-app-green" : onlineSigners.length > 0 ? "bg-app-orange" : "bg-white/50"}`} | ||
/> | ||
</Tooltip> | ||
) : ( | ||
<Tooltip content={online ? "Online" : "Offline"} className="mx-auto w-fit"> | ||
<div className={`h-[8px] w-[8px] rounded-full ${online ? "bg-app-green" : "bg-white/50"}`} /> | ||
</Tooltip> | ||
); | ||
} | ||
|
||
function isOnline(heartbeat: number | null) { | ||
return Date.now() - (heartbeat ?? 0) * 1000 < 5 * 60 * 1000; // 5 Minutes | ||
} | ||
|
||
function parseSigners(signers: string | null) { | ||
return ( | ||
signers?.split(",").reduce( | ||
(acc, cur) => { | ||
const [address, heartbeat] = cur.split("-"); | ||
acc.push([address, isOnline(Number(heartbeat))]); | ||
return acc; | ||
}, | ||
[] as [string, boolean][], | ||
) || [] | ||
); | ||
} |
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 |
---|---|---|
|
@@ -255,6 +255,7 @@ export const GQL_GET_RELAYERS = gql` | |
lastTransferId | ||
withdrawNonce | ||
transferLimit | ||
signers | ||
} | ||
} | ||
} | ||
|
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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import { Address } from "viem"; | ||
|
||
export function toShortAdrress(address: Address, prefixLength = 5, suffixLength = 4) { | ||
export function toShortAdrress(address: string, prefixLength = 5, suffixLength = 4) { | ||
return address.length > 16 ? `${address.slice(0, prefixLength)}...${address.slice(-1 * suffixLength)}` : address; | ||
} |