-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(pol): removes loading from vaults homepage
- Loading branch information
Showing
14 changed files
with
193 additions
and
121 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,52 @@ | ||
"use client"; | ||
|
||
import React from "react"; | ||
import { usePollGlobalData, usePollGlobalDataQueryKey } from "@bera/berajs"; | ||
|
||
import GlobalGaugeWeightChart from "~/components/global-gauge-weight-chart"; | ||
import GaugeTables from "./gauge-tables"; | ||
import GaugeInfoCard from "./gauge-info-card"; | ||
import { GaugeCreation } from "./gauge-creation"; | ||
import { SWRFallback } from "@bera/berajs"; | ||
import { unstable_serialize } from "swr"; | ||
import { useRewardVaultsQueryKey } from "@bera/berajs"; | ||
import { getRewardVaultsFilter } from "~/components/getRewardVaultsFilter"; | ||
import { GetGaugeData, GlobalData } from "@bera/berajs/actions"; | ||
|
||
export default function RewardVaults({ | ||
vaults, | ||
globalInfo, | ||
}: { | ||
vaults: GetGaugeData | undefined; | ||
globalInfo: GlobalData | undefined; | ||
}) { | ||
return ( | ||
<SWRFallback | ||
fallback={{ | ||
[unstable_serialize(useRewardVaultsQueryKey(getRewardVaultsFilter()))]: | ||
vaults, | ||
[unstable_serialize(usePollGlobalDataQueryKey())]: globalInfo, | ||
}} | ||
> | ||
<Gauge /> | ||
</SWRFallback> | ||
); | ||
} | ||
|
||
export function Gauge() { | ||
const { data, isLoading: isGlobalDataLoading } = usePollGlobalData(); | ||
return ( | ||
<div className="grid grid-cols-1 gap-6"> | ||
<div className="grid grid-cols-1 lg:grid-cols-[3fr_1fr] gap-6"> | ||
<GaugeInfoCard /> | ||
<GlobalGaugeWeightChart | ||
gaugeWeights={data?.globalCuttingBoard ?? []} | ||
isLoading={isGlobalDataLoading} | ||
totalBgtDistributed={data?.totalDistributedBGTAmount ?? "0"} | ||
/> | ||
</div> | ||
<GaugeTables /> | ||
<GaugeCreation /> | ||
</div> | ||
); | ||
} |
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 was deleted.
Oops, something went wrong.
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,7 +1,29 @@ | ||
import React from "react"; | ||
|
||
import Gauge from "./components/gauge"; | ||
import RewardVaultsPage from "./components/RewardVaults"; | ||
import { getGlobalData, getRewardVaults } from "@bera/berajs/actions"; | ||
import { getRewardVaultsFilter } from "~/components/getRewardVaultsFilter"; | ||
import { getServerSidePublicClient } from "~/utils/serverSidePublicClient"; | ||
import { defaultBeraConfig } from "@bera/berajs/config"; | ||
|
||
export default function Page() { | ||
return <Gauge />; | ||
export default async function Page() { | ||
const publicClient = await getServerSidePublicClient(); | ||
|
||
const [vaults, globalData] = await Promise.allSettled([ | ||
getRewardVaults({ filter: getRewardVaultsFilter() }), | ||
getGlobalData( | ||
// @ts-ignore viem types | ||
publicClient, | ||
defaultBeraConfig, | ||
), | ||
]); | ||
|
||
return ( | ||
<RewardVaultsPage | ||
vaults={vaults.status === "fulfilled" ? vaults.value : undefined} | ||
globalInfo={ | ||
globalData.status === "fulfilled" ? globalData.value : undefined | ||
} | ||
/> | ||
); | ||
} |
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,32 @@ | ||
import { | ||
GqlRewardVaultOrderBy, | ||
GqlRewardVaultOrderDirection, | ||
} from "@bera/graphql/dex/api"; | ||
import type { SortingState } from "@tanstack/react-table"; | ||
|
||
const map: Record<string, GqlRewardVaultOrderBy> = { | ||
allTimeReceivedBGTAmount: GqlRewardVaultOrderBy.AllTimeBgtReceived, | ||
dynamicData_bgtCapturePercentage: GqlRewardVaultOrderBy.BgtCapturePercentage, | ||
}; | ||
export const REWARD_VAULTS_PAGE_SIZE = 10; | ||
|
||
export const getRewardVaultsFilter = ( | ||
sorting: SortingState = [], | ||
page = 0, | ||
pageSize = REWARD_VAULTS_PAGE_SIZE, | ||
keywords = "", | ||
) => { | ||
return { | ||
orderBy: map[sorting[0]?.id], | ||
orderDirection: | ||
sorting[0] !== undefined | ||
? sorting[0]?.desc | ||
? GqlRewardVaultOrderDirection.Desc | ||
: GqlRewardVaultOrderDirection.Asc | ||
: undefined, | ||
skip: pageSize * page, | ||
// filterByProduct: markets, | ||
pageSize: pageSize, | ||
search: keywords === "" || !keywords ? undefined : keywords, | ||
}; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { defaultBeraNetworkConfig } from "@bera/wagmi/config"; | ||
import "server-only"; | ||
import { createPublicClient, http } from "viem"; | ||
|
||
export const getServerSidePublicClient = async () => { | ||
return createPublicClient({ | ||
// @ts-ignore viem types | ||
chain: defaultBeraNetworkConfig.chain, | ||
transport: http(), | ||
}); | ||
}; |
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
Oops, something went wrong.