mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
add useI18nContext shortcut hook (#8635)
This commit is contained in:
parent
9e2e353a24
commit
f9ea9b541a
@ -1,4 +1,4 @@
|
|||||||
import React, { useContext, useState } from 'react'
|
import React, { useState } from 'react'
|
||||||
import { useDispatch, useSelector } from 'react-redux'
|
import { useDispatch, useSelector } from 'react-redux'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -9,12 +9,12 @@ import {
|
|||||||
getAlertState,
|
getAlertState,
|
||||||
} from '../../../../ducks/alerts/switch-to-connected'
|
} from '../../../../ducks/alerts/switch-to-connected'
|
||||||
import { getPermittedIdentitiesForCurrentTab } from '../../../../selectors'
|
import { getPermittedIdentitiesForCurrentTab } from '../../../../selectors'
|
||||||
import { I18nContext } from '../../../../contexts/i18n'
|
|
||||||
import Popover from '../../../ui/popover'
|
import Popover from '../../../ui/popover'
|
||||||
import Button from '../../../ui/button'
|
import Button from '../../../ui/button'
|
||||||
import Dropdown from '../../../ui/dropdown'
|
import Dropdown from '../../../ui/dropdown'
|
||||||
import Checkbox from '../../../ui/check-box'
|
import Checkbox from '../../../ui/check-box'
|
||||||
import Tooltip from '../../../ui/tooltip-v2'
|
import Tooltip from '../../../ui/tooltip-v2'
|
||||||
|
import { useI18nContext } from '../../../../hooks/useI18nContext'
|
||||||
|
|
||||||
const {
|
const {
|
||||||
ERROR,
|
ERROR,
|
||||||
@ -22,7 +22,7 @@ const {
|
|||||||
} = ALERT_STATE
|
} = ALERT_STATE
|
||||||
|
|
||||||
const SwitchToUnconnectedAccountAlert = () => {
|
const SwitchToUnconnectedAccountAlert = () => {
|
||||||
const t = useContext(I18nContext)
|
const t = useI18nContext()
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
const alertState = useSelector(getAlertState)
|
const alertState = useSelector(getAlertState)
|
||||||
const connectedAccounts = useSelector(getPermittedIdentitiesForCurrentTab)
|
const connectedAccounts = useSelector(getPermittedIdentitiesForCurrentTab)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, { useContext, useState } from 'react'
|
import React, { useState } from 'react'
|
||||||
import { useDispatch, useSelector } from 'react-redux'
|
import { useDispatch, useSelector } from 'react-redux'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -8,12 +8,12 @@ import {
|
|||||||
dismissAndDisableAlert,
|
dismissAndDisableAlert,
|
||||||
getAlertState,
|
getAlertState,
|
||||||
} from '../../../../ducks/alerts/unconnected-account'
|
} from '../../../../ducks/alerts/unconnected-account'
|
||||||
import { I18nContext } from '../../../../contexts/i18n'
|
|
||||||
import Popover from '../../../ui/popover'
|
import Popover from '../../../ui/popover'
|
||||||
import Button from '../../../ui/button'
|
import Button from '../../../ui/button'
|
||||||
import Checkbox from '../../../ui/check-box'
|
import Checkbox from '../../../ui/check-box'
|
||||||
import Tooltip from '../../../ui/tooltip-v2'
|
import Tooltip from '../../../ui/tooltip-v2'
|
||||||
import { getSelectedIdentity, getOriginOfCurrentTab } from '../../../../selectors'
|
import { getSelectedIdentity, getOriginOfCurrentTab } from '../../../../selectors'
|
||||||
|
import { useI18nContext } from '../../../../hooks/useI18nContext'
|
||||||
|
|
||||||
const {
|
const {
|
||||||
ERROR,
|
ERROR,
|
||||||
@ -21,7 +21,7 @@ const {
|
|||||||
} = ALERT_STATE
|
} = ALERT_STATE
|
||||||
|
|
||||||
const SwitchToUnconnectedAccountAlert = () => {
|
const SwitchToUnconnectedAccountAlert = () => {
|
||||||
const t = useContext(I18nContext)
|
const t = useI18nContext()
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
const alertState = useSelector(getAlertState)
|
const alertState = useSelector(getAlertState)
|
||||||
const origin = useSelector(getOriginOfCurrentTab)
|
const origin = useSelector(getOriginOfCurrentTab)
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import React, { PureComponent, useContext } from 'react'
|
import React, { PureComponent } from 'react'
|
||||||
import ReactDOM from 'react-dom'
|
import ReactDOM from 'react-dom'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import classnames from 'classnames'
|
import classnames from 'classnames'
|
||||||
import { I18nContext } from '../../../contexts/i18n'
|
import { useI18nContext } from '../../../hooks/useI18nContext'
|
||||||
|
|
||||||
const Popover = ({
|
const Popover = ({
|
||||||
title,
|
title,
|
||||||
@ -17,7 +17,7 @@ const Popover = ({
|
|||||||
showArrow,
|
showArrow,
|
||||||
CustomBackground,
|
CustomBackground,
|
||||||
}) => {
|
}) => {
|
||||||
const t = useContext(I18nContext)
|
const t = useI18nContext()
|
||||||
return (
|
return (
|
||||||
<div className="popover-container">
|
<div className="popover-container">
|
||||||
{ CustomBackground
|
{ CustomBackground
|
||||||
|
13
ui/app/hooks/useI18nContext.js
Normal file
13
ui/app/hooks/useI18nContext.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import { useContext } from 'react'
|
||||||
|
import { I18nContext } from '../contexts/i18n'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* useI18ncContext
|
||||||
|
*
|
||||||
|
* A time saving shortcut to using useContext + I18ncontext in many
|
||||||
|
* different places.
|
||||||
|
* @return {Function} I18n function from contexts/I18n.js
|
||||||
|
*/
|
||||||
|
export function useI18nContext () {
|
||||||
|
return useContext(I18nContext)
|
||||||
|
}
|
@ -1,16 +1,16 @@
|
|||||||
import React, { useContext } from 'react'
|
import React from 'react'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import { useDispatch, useSelector } from 'react-redux'
|
import { useDispatch, useSelector } from 'react-redux'
|
||||||
|
|
||||||
import { ALERT_TYPES } from '../../../../../app/scripts/controllers/alert'
|
import { ALERT_TYPES } from '../../../../../app/scripts/controllers/alert'
|
||||||
import { I18nContext } from '../../../contexts/i18n'
|
|
||||||
import Tooltip from '../../../components/ui/tooltip-v2'
|
import Tooltip from '../../../components/ui/tooltip-v2'
|
||||||
import ToggleButton from '../../../components/ui/toggle-button'
|
import ToggleButton from '../../../components/ui/toggle-button'
|
||||||
import { setAlertEnabledness } from '../../../store/actions'
|
import { setAlertEnabledness } from '../../../store/actions'
|
||||||
import { getAlertEnabledness } from '../../../ducks/metamask/metamask'
|
import { getAlertEnabledness } from '../../../ducks/metamask/metamask'
|
||||||
|
import { useI18nContext } from '../../../hooks/useI18nContext'
|
||||||
|
|
||||||
const AlertSettingsEntry = ({ alertId, description, title }) => {
|
const AlertSettingsEntry = ({ alertId, description, title }) => {
|
||||||
const t = useContext(I18nContext)
|
const t = useI18nContext()
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
const isEnabled = useSelector((state) => getAlertEnabledness(state)[alertId])
|
const isEnabled = useSelector((state) => getAlertEnabledness(state)[alertId])
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ AlertSettingsEntry.propTypes = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const AlertsTab = () => {
|
const AlertsTab = () => {
|
||||||
const t = useContext(I18nContext)
|
const t = useI18nContext()
|
||||||
|
|
||||||
const alertConfig = {
|
const alertConfig = {
|
||||||
[ALERT_TYPES.switchToConnected]: {
|
[ALERT_TYPES.switchToConnected]: {
|
||||||
|
Loading…
Reference in New Issue
Block a user