Skip to content

Commit

Permalink
Merge pull request #81 from Lilypad-Tech/ben/minor-fixes
Browse files Browse the repository at this point in the history
feat: make pow smart contract queries more efficient
  • Loading branch information
NadiemM authored Jul 30, 2024
2 parents 3574157 + e3ee05e commit fd35a42
Show file tree
Hide file tree
Showing 16 changed files with 180 additions and 60 deletions.
4 changes: 3 additions & 1 deletion apps/info-dashboard/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,7 @@
"node_status_node_overview_table_warning_status": "Not-earning",
"coming_soon_metrics_card": "Coming soon",
"leaderboard_node_provider_table_wallet_id_copy_text": "Copy",
"node_status_node_overview_table_wallet_id_copy_text": "Copy"
"node_status_node_overview_table_wallet_id_copy_text": "Copy",
"good_patient_spider_amuse": "WebGL is not supported / enabled",
"tangy_stout_guppy_loop": "Please enable WebGL to view this map. Follow the instructions at "
}
2 changes: 2 additions & 0 deletions apps/info-dashboard/public/_headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/*
Strict-Transport-Security: max-age=63072000; includeSubDomains; preload
23 changes: 17 additions & 6 deletions apps/info-dashboard/src/app/leaderboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,16 @@ export default function Leaderboard() {
</span>
<span className="text-uui-text-primary-900 uui-display-sm font-semibold">
{/* Todo add api cumalative Lilybit_rewards earned */}
{ Math.trunc(leaderboardData ? leaderboardData.reduce((total, node) => +node.Points + total, 0) : 0)}
{Math.trunc(
leaderboardData
? leaderboardData.reduce(
(total, node) =>
+node.Points +
total,
0
)
: 0
)}
</span>
</div>
{/* Todo add api week total Lilybit_rewards earned */}
Expand Down Expand Up @@ -239,7 +248,9 @@ export default function Leaderboard() {
nodesIsError ||
leaderboardData?.filter((d) =>
walletAddress
? d.Wallet.includes(walletAddress)
? d.Wallet.toLowerCase().includes(
walletAddress.toLowerCase()
)
: true
).length === 0 ? (
<EmptyState
Expand Down Expand Up @@ -330,8 +341,8 @@ export default function Leaderboard() {
})
.filter((d) =>
walletAddress
? d.Wallet.includes(
walletAddress
? d.Wallet.toLowerCase().includes(
walletAddress.toLowerCase()
)
: true
)
Expand Down Expand Up @@ -534,7 +545,7 @@ export default function Leaderboard() {
}
/>
</td>
<td>
{/* <td>
<TableLeadText
title={
<Badge
Expand Down Expand Up @@ -567,7 +578,7 @@ export default function Leaderboard() {
]
}
/>
</td>
</td> */}
<td>
<TableLeadText
title={
Expand Down
18 changes: 10 additions & 8 deletions apps/info-dashboard/src/app/node-status/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default function NodeStatus() {
error,
} = useQuery({
queryFn: async () =>
getNodesPowSubmissions(nodesData?.map((n) => n.ID) ?? []),
await getNodesPowSubmissions(nodesData?.map((n) => n.ID) ?? []),
queryKey: ["nodesPowSubmissions", nodesData?.map((n) => n.ID)], //Array according to Documentation
enabled: !!nodesData,
});
Expand Down Expand Up @@ -266,7 +266,9 @@ export default function NodeStatus() {
nodesPowSubmissionsIsError ||
nodeStatusData?.filter((d) =>
walletAddress
? d.Wallet.includes(walletAddress)
? d.Wallet.toLowerCase().includes(
walletAddress.toLowerCase()
)
: true
).length === 0 ? (
<EmptyState
Expand Down Expand Up @@ -384,8 +386,8 @@ export default function NodeStatus() {
})
.filter((d) =>
walletAddress
? d.Wallet.includes(
walletAddress
? d.Wallet.toLowerCase().includes(
walletAddress.toLowerCase()
)
: true
)
Expand Down Expand Up @@ -545,7 +547,7 @@ export default function NodeStatus() {
}
/>
</td>
<td>
{/* <td>
<TableLeadText
title={
<Badge
Expand All @@ -569,7 +571,7 @@ export default function NodeStatus() {
</Badge>
}
/>
</td>
</td> */}

<td>
<TableLeadText
Expand Down Expand Up @@ -599,7 +601,7 @@ export default function NodeStatus() {
}
/>
</td>
<td>
{/* <td>
<TableLeadText
className="whitespace-nowrap"
title={
Expand All @@ -608,7 +610,7 @@ export default function NodeStatus() {
]
}
/>
</td>
</td> */}
<td>
<TableLeadText
className="whitespace-nowrap"
Expand Down
40 changes: 32 additions & 8 deletions apps/info-dashboard/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
import React from "react";
import * as m from "@/paraglide/messages.js";
import Head from "next/head";
import { Badge } from "@lilypad/shared-components";
import {
Badge,
ErrorBoundary,
WebGLFallback,
} from "@lilypad/shared-components";
import MetricsCard from "@/components/MetricsCard/MetricsCard";
import HeadingSection from "@/components/HeadingSection";
import { SectionContainer } from "@lilypad/shared-components";
Expand Down Expand Up @@ -35,7 +39,6 @@ import { DateTime } from "luxon";
import EmptyState from "@/components/EmptyState/EmptyState";
import ActiveNodesWorldMap from "@/components/ActiveNodesWorldMap/ActiveNodesWorldMap";
import { fetchNodes, toGeoJson } from "@/lib/fetchers/nodes";

export default function Home() {
const {
data: metricsData,
Expand Down Expand Up @@ -330,13 +333,34 @@ export default function Home() {
/>
</EmptyState>
) : (
<ActiveNodesWorldMap
geojson={toGeoJson(nodesData ?? [])}
protomapsApiKey={
process.env
.NEXT_PUBLIC_PROTOMAPS_API_KEY as string
<WebGLFallback
fallback={
<EmptyState
header={m.good_patient_spider_amuse()}
description={
<span>
{m.tangy_stout_guppy_loop()}
<a>https://get.webgl.org/</a>
</span>
}
>
<FeaturedIcon
spinIcon={false}
iconUrl={
alertAndFeedbackAlertCircle
}
/>
</EmptyState>
}
/>
>
<ActiveNodesWorldMap
geojson={toGeoJson(nodesData ?? [])}
protomapsApiKey={
process.env
.NEXT_PUBLIC_PROTOMAPS_API_KEY as string
}
/>
</WebGLFallback>
)}
</CardWithBorder>
</SectionContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default function ActiveNodesWorldMap({
return (
<div className="relative h-[60vh] w-full">
<Map
onError={(evt) => console.error(evt.error)}
initialViewState={{
latitude: 20,
longitude: 0,
Expand Down
4 changes: 2 additions & 2 deletions apps/info-dashboard/src/components/EmptyState/EmptyState.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { PropsWithChildren } from "react";
import { PropsWithChildren, type ReactNode } from "react";

export default function EmptyState({
children,
header,
description,
}: PropsWithChildren<{
header: string;
description: string;
description: ReactNode;
}>) {
return (
<div className="w-full h-[70vh] flex items-center flex-col justify-center space-y-uui-lg">
Expand Down
2 changes: 1 addition & 1 deletion apps/info-dashboard/src/lib/chain/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const lilypadNetworkBalanceContractAddress =
"0x0352485f8a3cB6d305875FaC0C40ef01e0C06535";

export const lilypadNetworkPowContractAddress =
"0x8B852BA45293d6dd51B10c57625C6c5f25ADFB40";
"0xacDf1005fAb67C13603C19aC5471F0c7dDBc90b2";

export const balanceContract = getContract({
address: lilypadNetworkBalanceContractAddress,
Expand Down
9 changes: 4 additions & 5 deletions apps/info-dashboard/src/lib/fetchers/leaderboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ export function toTableData({
).map(({ Rank, Wallet, Points }) => {
const nodeData = nodesData.find((nodeData) => nodeData.ID === Wallet);
const connectedSince = nodeData ? nodeData.ConnectedSince : null;

return {
Rank,
Wallet,
Wallet: Wallet.toLowerCase(),
Level: (() => {
const rankNumber = Number(Rank);
const result =
Expand Down Expand Up @@ -117,7 +116,7 @@ export function toTableData({
: " 🤖" + "!") +
"\n";
const normalShareText = encodeURIComponent(linkText);
return `https://twitter.com/intent/tweet?text=${normalShareText}&url=${currentUrl}?wallet_id=${Wallet}`;
return `https://twitter.com/intent/tweet?text=${normalShareText}&url=${currentUrl}?wallet_id=${Wallet.toLowerCase()}`;
},
},
};
Expand Down Expand Up @@ -154,7 +153,7 @@ export function getHeaderData() {
},
},

{
/* {
name: "Status",
translation: m.leaderboard_header_titles_status(),
tooltip: {
Expand All @@ -170,7 +169,7 @@ export function getHeaderData() {
description:
m.node_status_header_tooltip_description_connected_since(),
},
},
}, */
{
name: "Share",
translation: m.leaderboard_header_titles_share(),
Expand Down
48 changes: 24 additions & 24 deletions apps/info-dashboard/src/lib/fetchers/node-chain-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,38 +40,38 @@ export type PowSubmissions = {
}[];

export async function getNodesPowSubmissions(addresses: string[]) {
const nodesSubmissions = (await Promise.all(
addresses.map((address) => {
return powContract.read.getMinerPowSubmissions([address]);
const nodesSubmissionCounts = (await Promise.all(
addresses.map((address) =>
powContract.read.minerSubmissionCount([address])
)
)) as bigint[];
const nodesLastSubmissions = (await Promise.all(
nodesSubmissionCounts.map((count, i) => {
return Number(count) > 0
? powContract.read.powSubmissions([
addresses[i],
Number(count) - 1,
])
: undefined;
})
)) as (
| {
walletAddress: `0x${string}`; // wallet address
nodeId: string; // node Id
nonce: bigint; // nonce
start_timestamp: bigint; // start timestamp (unix epoch)
complete_timestamp: bigint; // complete timestamp (unix epoch)
challenge: string; // challenge
difficulty: bigint; // difficulty
}
| [
`0x${string}`, // wallet address
string, // node id
bigint, // nonce
bigint, // start_timestamp
bigint, // complete_timestamp
string, // challenge
bigint // difficulty
]
| undefined
)[][];

const nodesLastSubmissions = nodesSubmissions.map((submissions) => {
return submissions[submissions.length - 1];
});

/* const nodesSubmissionCounts = await Promise.all(
addresses.map((address) =>
powContract.read.getMinerPowSubmissionCount([address])
)
); */
)[];

return addresses.map((address, index) => ({
address,
lastSubmission: {
complete_timestamp: Number(
nodesLastSubmissions[index]?.complete_timestamp ?? null
nodesLastSubmissions[index]?.[4] ?? null
),
},
})) as PowSubmissions;
Expand Down
10 changes: 5 additions & 5 deletions apps/info-dashboard/src/lib/fetchers/node-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export function toTableData({
: "n.a.";

return {
Wallet,
Wallet: Wallet.toLowerCase(),
Status: (() => {
return {
online,
Expand Down Expand Up @@ -117,14 +117,14 @@ export function getHeaderData() {
translation: m.node_status_header_titles_wallet(),
tooltip: undefined,
},
{
/* {
name: "Status",
translation: m.node_status_header_titles_status(),
tooltip: {
title: m.node_status_header_tooltip_title_status(),
description: m.node_status_header_tooltip_description_status(),
},
},
}, */
{
name: "Available ETH",
translation: m.node_status_header_titles_available_eth(),
Expand Down Expand Up @@ -152,15 +152,15 @@ export function getHeaderData() {
m.node_status_header_tooltip_description_last_pow_submitted(),
},
},
{
/* {
name: "Connected since",
translation: m.node_status_header_titles_connected_since(),
tooltip: {
title: m.node_status_header_tooltip_title_connected_since(),
description:
m.node_status_header_tooltip_description_connected_since(),
},
},
}, */

{
name: "Chain",
Expand Down
2 changes: 2 additions & 0 deletions packages/shared-components/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export * from "./lib/Badge/index";
export * from "./lib/SectionContainer/index";
export * from "./lib/Anchor/index";
export * from "./lib/ErrorBoundary/index";
export * from "./lib/WebGLFallback/index";
export * from "./lib/types";
Loading

0 comments on commit fd35a42

Please sign in to comment.