Skip to content

Commit

Permalink
Extract getParaTimeName (some tests mock useParaTimes.ts file)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaw3d committed Nov 4, 2024
1 parent 199247c commit 4ff3783
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
3 changes: 2 additions & 1 deletion src/app/pages/ParaTimesPage/ParaTimeSelection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { Select } from 'grommet/es6/components/Select'
import { useTranslation } from 'react-i18next'
import { ParaTimeContent } from '../ParaTimeContent'
import { ParaTimeFormFooter } from '../ParaTimeFormFooter'
import { getParaTimeName, useParaTimes } from '../useParaTimes'
import { useParaTimes } from '../useParaTimes'
import { getParaTimeName } from '../getParaTimeName'
import { useParaTimesNavigation } from '../useParaTimesNavigation'
import { ThemeContext } from 'styled-components'
import { ThemeType } from 'grommet/es6/themes'
Expand Down
24 changes: 24 additions & 0 deletions src/app/pages/ParaTimesPage/getParaTimeName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { TFunction } from 'i18next'
import { ExhaustedTypeError } from 'types/errors'
import { ParaTime } from '../../../config'

export const getParaTimeName = (t: TFunction, paraTime: ParaTime) => {
switch (paraTime) {
case ParaTime.Cipher:
return `${t('paraTimes.common.cipher', 'Cipher')} ${t(
'paraTimes.common.discouragedType',
// Discourage mistaken ParaTime deposits into Cipher accounts controlled
// by Binance. That requires contacting support to recover it.
'(experimental)',
)}`
case ParaTime.Emerald:
return t('paraTimes.common.emerald', 'Emerald')
case ParaTime.Sapphire:
return t('paraTimes.common.sapphire', 'Sapphire')
default:
throw new ExhaustedTypeError(
t('paraTimes.validation.unsupportedParaTime', 'Unsupported ParaTime'),
paraTime,
)
}
}
25 changes: 2 additions & 23 deletions src/app/pages/ParaTimesPage/useParaTimes.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { useCallback } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { useTranslation } from 'react-i18next'
import { TFunction } from 'i18next'
import { paraTimesActions } from 'app/state/paratimes'
import { TransactionForm, TransactionTypes } from 'app/state/paratimes/types'
import { selectSelectedNetwork, selectTicker } from 'app/state/network/selectors'
import { selectAccountAvailableBalance, selectAccountIsLoading } from 'app/state/account/selectors'
import { selectAddress } from 'app/state/wallet/selectors'
import { selectParaTimes } from 'app/state/paratimes/selectors'
import { StringifiedBigInt } from 'types/StringifiedBigInt'
import { ErrorPayload, ExhaustedTypeError } from 'types/errors'
import { ErrorPayload } from 'types/errors'
import { paraTimesConfig, RuntimeTypes, ParaTime, type ParaTimeConfig } from '../../../config'
import { selectEvmAccounts } from 'app/state/evmAccounts/selectors'
import { EvmAccount } from 'app/state/evmAccounts/types'
import { getParaTimeName } from './getParaTimeName'

type AvailableParaTimesForNetwork = {
isEvm: boolean
Expand Down Expand Up @@ -45,27 +45,6 @@ export type ParaTimesHook = {
usesOasisAddress: boolean
}

export const getParaTimeName = (t: TFunction, paraTime: ParaTime) => {
switch (paraTime) {
case ParaTime.Cipher:
return `${t('paraTimes.common.cipher', 'Cipher')} ${t(
'paraTimes.common.discouragedType',
// Discourage mistaken ParaTime deposits into Cipher accounts controlled
// by Binance. That requires contacting support to recover it.
'(experimental)',
)}`
case ParaTime.Emerald:
return t('paraTimes.common.emerald', 'Emerald')
case ParaTime.Sapphire:
return t('paraTimes.common.sapphire', 'Sapphire')
default:
throw new ExhaustedTypeError(
t('paraTimes.validation.unsupportedParaTime', 'Unsupported ParaTime'),
paraTime,
)
}
}

export const useParaTimes = (): ParaTimesHook => {
const { t } = useTranslation()
const dispatch = useDispatch()
Expand Down

0 comments on commit 4ff3783

Please sign in to comment.