1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

I18n add-token.js

This commit is contained in:
Thomas 2018-03-20 02:34:12 -07:00
parent de98cb4039
commit 85a612b34d

View File

@ -26,6 +26,7 @@ const fuse = new Fuse(contractList, {
const actions = require('./actions') const actions = require('./actions')
const ethUtil = require('ethereumjs-util') const ethUtil = require('ethereumjs-util')
const { tokenInfoGetter } = require('./token-util') const { tokenInfoGetter } = require('./token-util')
const t = require('../i18n')
const emptyAddr = '0x0000000000000000000000000000000000000000' const emptyAddr = '0x0000000000000000000000000000000000000000'
@ -139,28 +140,28 @@ AddTokenScreen.prototype.validate = function () {
if (customAddress) { if (customAddress) {
const validAddress = ethUtil.isValidAddress(customAddress) const validAddress = ethUtil.isValidAddress(customAddress)
if (!validAddress) { if (!validAddress) {
errors.customAddress = 'Address is invalid. ' errors.customAddress = t('invalidAddress')
} }
const validDecimals = customDecimals !== null && customDecimals >= 0 && customDecimals < 36 const validDecimals = customDecimals !== null && customDecimals >= 0 && customDecimals < 36
if (!validDecimals) { if (!validDecimals) {
errors.customDecimals = 'Decimals must be at least 0, and not over 36.' errors.customDecimals = t('decimalsMustZerotoTen')
} }
const symbolLen = customSymbol.trim().length const symbolLen = customSymbol.trim().length
const validSymbol = symbolLen > 0 && symbolLen < 10 const validSymbol = symbolLen > 0 && symbolLen < 10
if (!validSymbol) { if (!validSymbol) {
errors.customSymbol = 'Symbol must be between 0 and 10 characters.' errors.customSymbol = t('symbolBetweenZeroTen')
} }
const ownAddress = identitiesList.includes(standardAddress) const ownAddress = identitiesList.includes(standardAddress)
if (ownAddress) { if (ownAddress) {
errors.customAddress = 'Personal address detected. Input the token contract address.' errors.customAddress = t('personalAddressDetected')
} }
const tokenAlreadyAdded = this.checkExistingAddresses(customAddress) const tokenAlreadyAdded = this.checkExistingAddresses(customAddress)
if (tokenAlreadyAdded) { if (tokenAlreadyAdded) {
errors.customAddress = 'Token has already been added.' errors.customAddress = t('tokenAlreadyAdded')
} }
} else if ( } else if (
Object.entries(selectedTokens) Object.entries(selectedTokens)
@ -168,7 +169,7 @@ AddTokenScreen.prototype.validate = function () {
isEmpty && !isSelected isEmpty && !isSelected
), true) ), true)
) { ) {
errors.tokenSelector = 'Must select at least 1 token.' errors.tokenSelector = t('mustSelectOne')
} }
return { return {
@ -198,7 +199,7 @@ AddTokenScreen.prototype.renderCustomForm = function () {
'add-token__add-custom-field--error': errors.customAddress, 'add-token__add-custom-field--error': errors.customAddress,
}), }),
}, [ }, [
h('div.add-token__add-custom-label', 'Token Address'), h('div.add-token__add-custom-label', t('tokenAddress')),
h('input.add-token__add-custom-input', { h('input.add-token__add-custom-input', {
type: 'text', type: 'text',
onChange: this.tokenAddressDidChange, onChange: this.tokenAddressDidChange,
@ -211,7 +212,7 @@ AddTokenScreen.prototype.renderCustomForm = function () {
'add-token__add-custom-field--error': errors.customSymbol, 'add-token__add-custom-field--error': errors.customSymbol,
}), }),
}, [ }, [
h('div.add-token__add-custom-label', 'Token Symbol'), h('div.add-token__add-custom-label', t('tokenSymbol')),
h('input.add-token__add-custom-input', { h('input.add-token__add-custom-input', {
type: 'text', type: 'text',
onChange: this.tokenSymbolDidChange, onChange: this.tokenSymbolDidChange,
@ -225,7 +226,7 @@ AddTokenScreen.prototype.renderCustomForm = function () {
'add-token__add-custom-field--error': errors.customDecimals, 'add-token__add-custom-field--error': errors.customDecimals,
}), }),
}, [ }, [
h('div.add-token__add-custom-label', 'Decimals of Precision'), h('div.add-token__add-custom-label', t('decimal')),
h('input.add-token__add-custom-input', { h('input.add-token__add-custom-input', {
type: 'number', type: 'number',
onChange: this.tokenDecimalsDidChange, onChange: this.tokenDecimalsDidChange,
@ -299,11 +300,11 @@ AddTokenScreen.prototype.renderConfirmation = function () {
h('div.add-token', [ h('div.add-token', [
h('div.add-token__wrapper', [ h('div.add-token__wrapper', [
h('div.add-token__title-container.add-token__confirmation-title', [ h('div.add-token__title-container.add-token__confirmation-title', [
h('div.add-token__title', 'Add Token'), h('div.add-token__title', t('addToken')),
h('div.add-token__description', 'Would you like to add these tokens?'), h('div.add-token__description', t('likeToAddTokens')),
]), ]),
h('div.add-token__content-container.add-token__confirmation-content', [ h('div.add-token__content-container.add-token__confirmation-content', [
h('div.add-token__description.add-token__confirmation-description', 'Your balances'), h('div.add-token__description.add-token__confirmation-description', t('balances')),
h('div.add-token__confirmation-token-list', h('div.add-token__confirmation-token-list',
Object.entries(tokens) Object.entries(tokens)
.map(([ address, token ]) => ( .map(([ address, token ]) => (
@ -322,10 +323,10 @@ AddTokenScreen.prototype.renderConfirmation = function () {
h('div.add-token__buttons', [ h('div.add-token__buttons', [
h('button.btn-cancel.add-token__button', { h('button.btn-cancel.add-token__button', {
onClick: () => this.setState({ isShowingConfirmation: false }), onClick: () => this.setState({ isShowingConfirmation: false }),
}, 'Back'), }, t('back')),
h('button.btn-clear.add-token__button', { h('button.btn-clear.add-token__button', {
onClick: () => addTokens(tokens).then(goHome), onClick: () => addTokens(tokens).then(goHome),
}, 'Add Tokens'), }, t('addTokens')),
]), ]),
]) ])
) )
@ -341,15 +342,15 @@ AddTokenScreen.prototype.render = function () {
h('div.add-token', [ h('div.add-token', [
h('div.add-token__wrapper', [ h('div.add-token__wrapper', [
h('div.add-token__title-container', [ h('div.add-token__title-container', [
h('div.add-token__title', 'Add Token'), h('div.add-token__title', t('addToken')),
h('div.add-token__description', 'Keep track of the tokens youve bought with your MetaMask account. If you bought tokens using a different account, those tokens will not appear here.'), h('div.add-token__description', t('tokenWarning1')),
h('div.add-token__description', 'Search for tokens or select from our list of popular tokens.'), h('div.add-token__description', t('tokenSelection')),
]), ]),
h('div.add-token__content-container', [ h('div.add-token__content-container', [
h('div.add-token__input-container', [ h('div.add-token__input-container', [
h('input.add-token__input', { h('input.add-token__input', {
type: 'text', type: 'text',
placeholder: 'Search', placeholder: t('search'),
onChange: e => this.setState({ searchQuery: e.target.value }), onChange: e => this.setState({ searchQuery: e.target.value }),
}), }),
h('div.add-token__search-input-error-message', errors.tokenSelector), h('div.add-token__search-input-error-message', errors.tokenSelector),
@ -363,7 +364,7 @@ AddTokenScreen.prototype.render = function () {
h('div.add-token__add-custom', { h('div.add-token__add-custom', {
onClick: () => this.setState({ isCollapsed: !isCollapsed }), onClick: () => this.setState({ isCollapsed: !isCollapsed }),
}, [ }, [
'Add custom token', t('addCustomToken'),
h(`i.fa.fa-angle-${isCollapsed ? 'down' : 'up'}`), h(`i.fa.fa-angle-${isCollapsed ? 'down' : 'up'}`),
]), ]),
this.renderCustomForm(), this.renderCustomForm(),
@ -372,10 +373,10 @@ AddTokenScreen.prototype.render = function () {
h('div.add-token__buttons', [ h('div.add-token__buttons', [
h('button.btn-cancel.add-token__button', { h('button.btn-cancel.add-token__button', {
onClick: goHome, onClick: goHome,
}, 'Cancel'), }, t('cancel')),
h('button.btn-clear.add-token__button', { h('button.btn-clear.add-token__button', {
onClick: this.onNext, onClick: this.onNext,
}, 'Next'), }, t('next')),
]), ]),
]) ])
) )