-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(explorer): server-side currency data
- Loading branch information
1 parent
70e57bf
commit 14f0796
Showing
2 changed files
with
45 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { explored } from '../config/explored' | ||
import { unstable_serialize } from 'swr' | ||
import { CurrencyID, exchangeRateRoute } from '@siafoundation/explored-types' | ||
import { exploredApi } from '../config' | ||
|
||
// Builds fallback data for the exchange rate. Passing this to the SWR | ||
// config's fallback prop allows the exchange rate hooks with a matching | ||
// key to server-render with an initial exchange rate value. | ||
export async function buildFallbackDataExchangeRate(currency: CurrencyID) { | ||
const rate = await explored.exchangeRate({ | ||
params: { | ||
currency, | ||
}, | ||
}) | ||
return { | ||
// Hooks build with react-core have keys of the form: | ||
// ['method', `${api}${route}${params}${JSON.stringify(args.payload)}`] | ||
[unstable_serialize([ | ||
'get', | ||
`${exploredApi}${exchangeRateRoute.replace(':currency', currency)}`, | ||
])]: rate.data, | ||
} | ||
} |
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