mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Remove tOrKey
and tOrDefault
functions from i18n context (#8211)
These two functions were not especially useful. `tOrDefault` was used only by `tOrKey`, and `tOrKey` was only used in one place. All it did was return the given `key` directly if it was falsey, so it was easily replaced by a condition.
This commit is contained in:
parent
23a4c62bd5
commit
4cc75eb9af
@ -27,14 +27,12 @@ export function mountWithRouter (component, store = {}, pathname = '/') {
|
|||||||
context: {
|
context: {
|
||||||
router,
|
router,
|
||||||
t: (str) => str,
|
t: (str) => str,
|
||||||
tOrKey: (str) => str,
|
|
||||||
metricsEvent: () => {},
|
metricsEvent: () => {},
|
||||||
store,
|
store,
|
||||||
},
|
},
|
||||||
childContextTypes: {
|
childContextTypes: {
|
||||||
router: PropTypes.object,
|
router: PropTypes.object,
|
||||||
t: PropTypes.func,
|
t: PropTypes.func,
|
||||||
tOrKey: PropTypes.func,
|
|
||||||
metricsEvent: PropTypes.func,
|
metricsEvent: PropTypes.func,
|
||||||
store: PropTypes.object,
|
store: PropTypes.object,
|
||||||
},
|
},
|
||||||
|
@ -4,14 +4,6 @@ import PropTypes from 'prop-types'
|
|||||||
import { getMessage } from '../utils/i18n-helper'
|
import { getMessage } from '../utils/i18n-helper'
|
||||||
|
|
||||||
class I18nProvider extends Component {
|
class I18nProvider extends Component {
|
||||||
tOrDefault = (key, defaultValue, ...args) => {
|
|
||||||
if (!key) {
|
|
||||||
return defaultValue
|
|
||||||
}
|
|
||||||
const { localeMessages: { current, en } = {}, currentLocale } = this.props
|
|
||||||
return getMessage(currentLocale, current, key, ...args) || getMessage(currentLocale, en, key, ...args) || defaultValue
|
|
||||||
}
|
|
||||||
|
|
||||||
getChildContext () {
|
getChildContext () {
|
||||||
const { localeMessages, currentLocale } = this.props
|
const { localeMessages, currentLocale } = this.props
|
||||||
const { current, en } = localeMessages
|
const { current, en } = localeMessages
|
||||||
@ -25,10 +17,6 @@ class I18nProvider extends Component {
|
|||||||
t (key, ...args) {
|
t (key, ...args) {
|
||||||
return getMessage(currentLocale, current, key, ...args) || getMessage(currentLocale, en, key, ...args) || `[${key}]`
|
return getMessage(currentLocale, current, key, ...args) || getMessage(currentLocale, en, key, ...args) || `[${key}]`
|
||||||
},
|
},
|
||||||
tOrDefault: this.tOrDefault,
|
|
||||||
tOrKey: (key, ...args) => {
|
|
||||||
return this.tOrDefault(key, key, ...args)
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,8 +33,6 @@ I18nProvider.propTypes = {
|
|||||||
|
|
||||||
I18nProvider.childContextTypes = {
|
I18nProvider.childContextTypes = {
|
||||||
t: PropTypes.func,
|
t: PropTypes.func,
|
||||||
tOrDefault: PropTypes.func,
|
|
||||||
tOrKey: PropTypes.func,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapStateToProps = (state) => {
|
const mapStateToProps = (state) => {
|
||||||
|
@ -21,7 +21,6 @@ import TextField from '../../components/ui/text-field'
|
|||||||
export default class ConfirmTransactionBase extends Component {
|
export default class ConfirmTransactionBase extends Component {
|
||||||
static contextTypes = {
|
static contextTypes = {
|
||||||
t: PropTypes.func,
|
t: PropTypes.func,
|
||||||
tOrKey: PropTypes.func.isRequired,
|
|
||||||
metricsEvent: PropTypes.func,
|
metricsEvent: PropTypes.func,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -311,7 +310,7 @@ export default class ConfirmTransactionBase extends Component {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
renderData () {
|
renderData (functionType) {
|
||||||
const { t } = this.context
|
const { t } = this.context
|
||||||
const {
|
const {
|
||||||
txData: {
|
txData: {
|
||||||
@ -320,12 +319,10 @@ export default class ConfirmTransactionBase extends Component {
|
|||||||
} = {},
|
} = {},
|
||||||
} = {},
|
} = {},
|
||||||
methodData: {
|
methodData: {
|
||||||
name,
|
|
||||||
params,
|
params,
|
||||||
} = {},
|
} = {},
|
||||||
hideData,
|
hideData,
|
||||||
dataComponent,
|
dataComponent,
|
||||||
transactionCategory,
|
|
||||||
} = this.props
|
} = this.props
|
||||||
|
|
||||||
if (hideData) {
|
if (hideData) {
|
||||||
@ -337,7 +334,7 @@ export default class ConfirmTransactionBase extends Component {
|
|||||||
<div className="confirm-page-container-content__data-box-label">
|
<div className="confirm-page-container-content__data-box-label">
|
||||||
{`${t('functionType')}:`}
|
{`${t('functionType')}:`}
|
||||||
<span className="confirm-page-container-content__function-type">
|
<span className="confirm-page-container-content__function-type">
|
||||||
{ getMethodName(name) || this.context.tOrKey(transactionCategory) || this.context.t('contractInteraction') }
|
{ functionType }
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{
|
{
|
||||||
@ -627,6 +624,7 @@ export default class ConfirmTransactionBase extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
|
const { t } = this.context
|
||||||
const {
|
const {
|
||||||
isTxReprice,
|
isTxReprice,
|
||||||
fromName,
|
fromName,
|
||||||
@ -660,6 +658,14 @@ export default class ConfirmTransactionBase extends Component {
|
|||||||
const { name } = methodData
|
const { name } = methodData
|
||||||
const { valid, errorKey } = this.getErrorKey()
|
const { valid, errorKey } = this.getErrorKey()
|
||||||
const { totalTx, positionOfCurrentTx, nextTxId, prevTxId, showNavigation, firstTx, lastTx, ofText, requestsWaitingText } = this.getNavigateTxData()
|
const { totalTx, positionOfCurrentTx, nextTxId, prevTxId, showNavigation, firstTx, lastTx, ofText, requestsWaitingText } = this.getNavigateTxData()
|
||||||
|
|
||||||
|
let functionType = getMethodName(name)
|
||||||
|
if (!functionType) {
|
||||||
|
functionType = transactionCategory
|
||||||
|
? t(transactionCategory)
|
||||||
|
: t('contractInteraction')
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ConfirmPageContainer
|
<ConfirmPageContainer
|
||||||
fromName={fromName}
|
fromName={fromName}
|
||||||
@ -670,8 +676,7 @@ export default class ConfirmTransactionBase extends Component {
|
|||||||
toEns={toEns}
|
toEns={toEns}
|
||||||
toNickname={toNickname}
|
toNickname={toNickname}
|
||||||
showEdit={onEdit && !isTxReprice}
|
showEdit={onEdit && !isTxReprice}
|
||||||
// In the event that the key is falsy (and inherently invalid), use a fallback string
|
action={functionType}
|
||||||
action={getMethodName(name) || this.context.tOrKey(transactionCategory) || this.context.t('contractInteraction')}
|
|
||||||
title={title}
|
title={title}
|
||||||
titleComponent={this.renderTitleComponent()}
|
titleComponent={this.renderTitleComponent()}
|
||||||
subtitle={subtitle}
|
subtitle={subtitle}
|
||||||
@ -679,7 +684,7 @@ export default class ConfirmTransactionBase extends Component {
|
|||||||
hideSubtitle={hideSubtitle}
|
hideSubtitle={hideSubtitle}
|
||||||
summaryComponent={summaryComponent}
|
summaryComponent={summaryComponent}
|
||||||
detailsComponent={this.renderDetails()}
|
detailsComponent={this.renderDetails()}
|
||||||
dataComponent={this.renderData()}
|
dataComponent={this.renderData(functionType)}
|
||||||
contentComponent={contentComponent}
|
contentComponent={contentComponent}
|
||||||
nonce={customNonceValue || nonce}
|
nonce={customNonceValue || nonce}
|
||||||
unapprovedTxCount={unapprovedTxCount}
|
unapprovedTxCount={unapprovedTxCount}
|
||||||
|
Loading…
Reference in New Issue
Block a user