diff --git a/next.config.js b/next.config.js
index 7a68294..d0f2ba4 100644
--- a/next.config.js
+++ b/next.config.js
@@ -39,12 +39,21 @@ module.exports = {
},
],
},
+ {
+ source: '/api/holdings/:kind',
+ headers: [
+ {
+ key: "Cache-Control",
+ value: "public; max-age=30, stale-while-revalidate=360",
+ },
+ ],
+ },
{
source: '/api/:any',
headers: [
{
key: "Cache-Control",
- value: "public; max-age=10, stale-while-revalidate=20",
+ value: "public; max-age=5, stale-while-revalidate=20",
},
],
},
diff --git a/src/components/Amount.tsx b/src/components/Amount.tsx
index 5f6fc42..8b0ccb6 100644
--- a/src/components/Amount.tsx
+++ b/src/components/Amount.tsx
@@ -1,6 +1,7 @@
import { css } from '@emotion/react'
import { BreakPoints } from 'src/components/styles'
import colors from './colors'
+import { loadingStyle } from './loadingKeyframes'
interface AmountProps {
label: string
units: number
@@ -20,7 +21,7 @@ export default function Amount({iconSrc, label, units, gridArea, context, value,
{iconSrc && }
{label}
- {display}
+ {display}
)
@@ -36,7 +37,7 @@ interface DollarDisplayProps {
export function DollarDisplay({value, loading, label, className}: DollarDisplayProps) {
const displayValue = value && Math.round(value).toLocaleString()
- return
+ return
{loading ? " ": !!value && `$${displayValue}`}
}
@@ -46,11 +47,14 @@ const abbrCSS = css({
cursor: "help"
})
-const notShowing = css({
- opacity: 0,
- minHeight: "1.15em"
+const amountLoadingStyle = css(loadingStyle, {
+ backgroundColor: colors.gray,
+ borderTopRightRadius: 6,
+ color: "transparent",
+ minHeight: "1.1em",
})
+
const labelCss = css({
textAlign: "left",
alignItems: "flex-end",
diff --git a/src/components/Holdings.tsx b/src/components/Holdings.tsx
index ca67449..54bd5b6 100644
--- a/src/components/Holdings.tsx
+++ b/src/components/Holdings.tsx
@@ -1,36 +1,16 @@
import { css } from '@emotion/react'
-import useSWR from "swr"
import Amount, { DollarDisplay } from 'src/components/Amount'
import Heading from 'src/components/Heading'
import { BreakPoints } from 'src/components/styles'
import PieChart,{ChartData} from 'src/components/PieChart'
import { HoldingsApi} from "src/service/holdings"
import Head from 'next/head'
-import { Tokens} from "src/service/Data"
-import { fetcher } from 'src/utils/fetcher'
import { skipZeros } from 'src/utils/skipZeros'
import { Updated } from 'src/components/Updated'
import Section from 'src/components/Section'
import { sumTotalHoldings } from './sumTotalHoldings'
-
-const initalToken = {
- value: 0,
- units: 0,
- hasError: false,
- token: "CELO" as Tokens,
- updated: 0
-}
-
-const INITAL_DATA: HoldingsApi = {
- celo: {
- custody: initalToken,
- unfrozen: initalToken,
- frozen: initalToken
- },
- otherAssets: []
-}
-
+import useHoldings from 'src/hooks/useHoldings'
export function sumCeloTotal(holdings: HoldingsApi) {
const { custody, frozen, unfrozen } = holdings.celo
@@ -70,34 +50,36 @@ function findOldestValueUpdatedAt(data?: HoldingsApi): number {
}
export default function Holdings() {
- const {data} = useSWR("/api/holdings", fetcher, {initialData: INITAL_DATA, revalidateOnMount: true})
+ const {data} = useHoldings()
const percentages = getPercents(data)
- const isLoading = data.otherAssets.length === 0
- const celo = data.celo
+ const isLoadingCelo = data.celo.frozen.updated === 0 || data.celo.unfrozen.updated === 0
+ const isLoadingOther = !data.otherAssets.findIndex((coin) => coin.updated === 0)
const oldestUpdate = findOldestValueUpdatedAt(data)
+ const celo = data.celo
return (
-
+
>
}
>
-
+
+
-
-
+
+
{data?.otherAssets?.filter(skipZeros)?.map(asset => (
-
+
))}
-
+
)
}
@@ -106,12 +88,14 @@ const rootStyle = css({
display: 'grid',
gridColumnGap: 20,
gridRowGap: 12,
+ gridAutoColumns: "1fr 1fr 1fr",
gridTemplateAreas: `"celo celo celo"
"frozen unfrozen unfrozen"
"crypto crypto crypto"
"btc eth dai"
`,
[BreakPoints.tablet]: {
+ gridAutoColumns: "1fr",
gridTemplateAreas: `"celo"
"frozen"
"unfrozen"
diff --git a/src/components/PieChart.tsx b/src/components/PieChart.tsx
index 24a2497..82a9a75 100644
--- a/src/components/PieChart.tsx
+++ b/src/components/PieChart.tsx
@@ -1,6 +1,7 @@
import {Fragment} from "react"
import { css } from '@emotion/react'
import colors from 'src/components/colors'
+import { loadingStyle } from './loadingKeyframes'
export const INITAL_TARGET: ChartData[] = [
@@ -51,7 +52,7 @@ export default function PieChart({slices,label,showFinePrint, isLoading}: Props)
*Crypto Assets with low volatility. Candidates are decentralised stablecoins e.g. DAI
}
-
+