Skip to content

Commit

Permalink
feat(widgets): ensure passed locale is supported (#3245)
Browse files Browse the repository at this point in the history
* ensure passed locale is supported

* warn on locale mismatch

* export SUPPORTED_LOCALES
  • Loading branch information
JFrankfurt authored Feb 8, 2022
1 parent 2efc1fb commit 707abd0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/lib/components/Error/WidgetsPropsValidator.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SUPPORTED_LOCALES } from 'constants/locales'
import { WidgetProps } from 'lib/components/Widget'
import { IntegrationError } from 'lib/errors'
import { PropsWithChildren, useEffect } from 'react'
Expand All @@ -18,5 +19,12 @@ export default function WidgetsPropsValidator(props: PropsWithChildren<WidgetPro
}
}, [width])

const { locale } = props
useEffect(() => {
if (locale && locale !== 'pseudo' && !SUPPORTED_LOCALES.includes(locale)) {
console.warn('Unsupported locale: ', locale)
}
}, [locale])

return <>{props.children}</>
}
1 change: 1 addition & 0 deletions src/lib/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Swap, { SwapProps } from './components/Swap'
import Widget, { WidgetProps } from './components/Widget'
export { SUPPORTED_LOCALES } from 'constants/locales'

type SwapWidgetProps = SwapProps & WidgetProps

Expand Down

0 comments on commit 707abd0

Please sign in to comment.