This repository has been archived by the owner on Jun 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from celo-org/aaronmgdr/loading
better data loading
- Loading branch information
Showing
12 changed files
with
177 additions
and
59 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
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
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,19 @@ | ||
import { css, keyframes } from '@emotion/react' | ||
|
||
const loadingKeyframes = keyframes` | ||
from { | ||
opacity: 0.15 | ||
} | ||
to {opacity: 0.40} | ||
` | ||
export const loadingStyle = css({ | ||
opacity: 0, | ||
animationDirection: "alternate-reverse", | ||
animationDuration: '1.4s', | ||
animationDelay: "20ms", | ||
animationFillMode: "none", | ||
animationIterationCount: 'infinite', | ||
animationTimingFunction: "ease-in-out", | ||
animationName: loadingKeyframes | ||
}) |
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,42 @@ | ||
import useSWR from "swr" | ||
import { Tokens} from "src/service/Data" | ||
import { fetcher } from 'src/utils/fetcher' | ||
import { HoldingsApi} from "src/service/holdings" | ||
|
||
const initalToken = { | ||
value: NaN, | ||
units: NaN, | ||
hasError: false, | ||
token: "CELO" as Tokens, | ||
updated: 0 | ||
} | ||
|
||
const initalOtherToken = { | ||
value: NaN, | ||
units: NaN, | ||
hasError: false, | ||
token: "BTC", | ||
updated: 0 | ||
} as const | ||
|
||
const INITAL_DATA: HoldingsApi = { | ||
celo: { | ||
custody: initalToken, | ||
unfrozen: initalToken, | ||
frozen: initalToken | ||
}, | ||
otherAssets: [ | ||
initalOtherToken, | ||
{...initalOtherToken, token: "ETH" }, | ||
{...initalOtherToken, token: "DAI"} | ||
] | ||
} | ||
|
||
|
||
export default function useHoldings(): {data: HoldingsApi, error: any} { | ||
const celoHoldings = useSWR<Pick<HoldingsApi, 'celo'>>("/api/holdings/celo", fetcher, {initialData: {celo: INITAL_DATA.celo}, revalidateOnMount: true}) | ||
const otherHoldings = useSWR<Pick<HoldingsApi,'otherAssets'>>("/api/holdings/other", fetcher, {initialData: {otherAssets: INITAL_DATA.otherAssets}, revalidateOnMount: true}) | ||
const error = celoHoldings.error || otherHoldings.error | ||
const data: HoldingsApi = {...celoHoldings.data, ...otherHoldings.data} | ||
return {data, error} | ||
} |
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,26 @@ | ||
import { NextApiRequest, NextApiResponse } from 'next' | ||
import getHoldings, {getHoldingsCelo, getHoldingsOther} from "src/service/holdings" | ||
|
||
export default async function(req: NextApiRequest, res: NextApiResponse) { | ||
try { | ||
if (req.method === 'GET') { | ||
const start = Date.now() | ||
if (req.query.kind === 'celo') { | ||
const holdings = await getHoldingsCelo() | ||
res.setHeader("Server-Timing", `ms;dur=${Date.now() - start}`) | ||
res.json(holdings) | ||
} else if (req.query.kind === 'other') { | ||
const holdings = await getHoldingsOther() | ||
res.setHeader("Server-Timing", `ms;dur=${Date.now() - start}`) | ||
res.json(holdings) | ||
} else { | ||
res.status(404) | ||
} | ||
|
||
} else { | ||
res.status(405) | ||
} | ||
} catch (error) { | ||
res.status(error.statusCode || 500).json({ message: error.message || 'unknownError' }) | ||
} | ||
} |
File renamed without changes.
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.