From bd8e8ad783987c9e9e4b05ddda5b9ccf715d8974 Mon Sep 17 00:00:00 2001 From: Kristof Csillag Date: Fri, 16 Feb 2024 14:15:46 +0100 Subject: [PATCH] Update testnet faucet to support layer/token configuration --- .../ParaTimeSnapshot.tsx | 8 +++++--- .../ParatimeDashboardPage/TestnetFaucet.tsx | 19 +++++++++---------- src/app/utils/__tests__/externalLinks.test.ts | 1 + src/app/utils/externalLinks.ts | 19 ++++++++++++------- 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/app/pages/ParatimeDashboardPage/ParaTimeSnapshot.tsx b/src/app/pages/ParatimeDashboardPage/ParaTimeSnapshot.tsx index 442c9f4299..d71e631d10 100644 --- a/src/app/pages/ParatimeDashboardPage/ParaTimeSnapshot.tsx +++ b/src/app/pages/ParatimeDashboardPage/ParaTimeSnapshot.tsx @@ -9,7 +9,8 @@ import { ActiveAccounts } from './ActiveAccounts' import { ChartDuration } from '../../utils/chart-utils' import { useTranslation } from 'react-i18next' import { useConstant } from '../../hooks/useConstant' -import { Network } from '../../../types/network' +import { Ticker } from '../../../types/ticker' +import { getTickerForScope } from '../../../config' import { getLayerLabels } from '../../utils/content' import { TestnetFaucet } from './TestnetFaucet' import { SearchScope } from '../../../types/searchScope' @@ -24,6 +25,7 @@ export const ParaTimeSnapshot: FC<{ scope: SearchScope }> = ({ scope }) => { const defaultChartDurationValue = useConstant(() => ChartDuration.TODAY) const [chartDuration, setChartDuration] = useState(defaultChartDurationValue) const paratime = getLayerLabels(t)[scope.layer] + const ticker = getTickerForScope(scope) const handleDurationSelectedChange = (duration: ChartDuration | null) => { if (!duration) { return @@ -54,8 +56,8 @@ export const ParaTimeSnapshot: FC<{ scope: SearchScope }> = ({ scope }) => { - {scope.network === Network.mainnet && } - {scope.network === Network.testnet && } + {ticker === Ticker.ROSE && } + diff --git a/src/app/pages/ParatimeDashboardPage/TestnetFaucet.tsx b/src/app/pages/ParatimeDashboardPage/TestnetFaucet.tsx index 473d067463..918d6f55d4 100644 --- a/src/app/pages/ParatimeDashboardPage/TestnetFaucet.tsx +++ b/src/app/pages/ParatimeDashboardPage/TestnetFaucet.tsx @@ -8,6 +8,8 @@ import { SnapshotCard } from '../../components/Snapshots/SnapshotCard' import { COLORS } from '../../../styles/theme/colors' import { faucet } from '../../utils/externalLinks' import { Layer } from '../../../oasis-nexus/api' +import { NativeTicker, Ticker } from '../../../types/ticker' +import { Network } from '../../../types/network' const StyledBox = styled(Box)(({ theme }) => ({ gap: theme.spacing(5), @@ -19,13 +21,16 @@ const StyledBox = styled(Box)(({ theme }) => ({ })) type TestnetFaucetProps = { + network: Network layer: Layer + ticker: NativeTicker } -export const TestnetFaucet: FC = ({ layer }) => { +export const TestnetFaucet: FC = ({ network, layer, ticker }) => { const { t } = useTranslation() + const link = faucet[network]?.[layer]?.[ticker] - return ( + return link ? ( = ({ layer }) => { > {t('testnetFaucet.description')} - - ) + ) : null } diff --git a/src/app/utils/__tests__/externalLinks.test.ts b/src/app/utils/__tests__/externalLinks.test.ts index ad916e25f4..719e58f5df 100644 --- a/src/app/utils/__tests__/externalLinks.test.ts +++ b/src/app/utils/__tests__/externalLinks.test.ts @@ -17,6 +17,7 @@ onlyRunOnCI('externalLinks', () => { expect(Object.entries(linksGroup).length).toBeGreaterThan(0) // eslint-disable-next-line @typescript-eslint/no-unused-vars for (const [_linkName, url] of Object.entries(linksGroup)) { + if (Array.isArray(url)) continue // We don't need to go into faucets if (url === undefined) continue expect(typeof url).toBe('string') expect(url).toMatch(/^(https|mailto):/) diff --git a/src/app/utils/externalLinks.ts b/src/app/utils/externalLinks.ts index 12c21e695b..440623abc7 100644 --- a/src/app/utils/externalLinks.ts +++ b/src/app/utils/externalLinks.ts @@ -1,4 +1,6 @@ import { Layer } from '../../oasis-nexus/api' +import { Network } from '../../types/network' +import { NativeTicker, Ticker } from '../../types/ticker' export const socialMedia = { telegram: process.env.REACT_APP_SOCIAL_TELEGRAM, @@ -50,13 +52,16 @@ export const github = { const faucetUrl = 'https://faucet.testnet.oasis.dev/' const faucetParaTimeBaseUrl = `${faucetUrl}?paratime=` -export const faucet = { - [Layer.consensus]: faucetUrl, - [Layer.emerald]: `${faucetParaTimeBaseUrl}emerald`, - [Layer.sapphire]: `${faucetParaTimeBaseUrl}sapphire`, - [Layer.pontusx]: 'mailto:contact@delta-dao.com?subject=tokens', - [Layer.cipher]: `${faucetParaTimeBaseUrl}cipher`, -} +export const faucet: Partial>>>>> = + { + [Network.testnet]: { + [Layer.consensus]: { [Ticker.TEST]: faucetUrl }, + [Layer.emerald]: { [Ticker.TEST]: `${faucetParaTimeBaseUrl}emerald` }, + [Layer.sapphire]: { [Ticker.TEST]: `${faucetParaTimeBaseUrl}sapphire` }, + [Layer.pontusx]: { [Ticker.TEST]: 'mailto:contact@delta-dao.com?subject=tokens' }, + [Layer.cipher]: { [Ticker.TEST]: `${faucetParaTimeBaseUrl}cipher` }, + }, + } export const api = { spec: `${process.env.REACT_APP_API}spec/v1.html`,