get upstream from develop branch

This commit is contained in:
Victor Baranov 2018-10-23 13:51:21 +03:00
commit ecca5ab870
5 changed files with 32842 additions and 34182 deletions

View File

@ -2,6 +2,8 @@
## Current Master
- [#164](https://github.com/poanetwork/metamask-extension/pull/164): (Fix) Confirm token transfer page display fix
## 4.8.6 Thu Oct 18 2018
- [#153](https://github.com/poanetwork/metamask-extension/pull/153), [#154](https://github.com/poanetwork/metamask-extension/pull/154), [#158](https://github.com/poanetwork/metamask-extension/pull/158): (Feature) xDai chain support

View File

@ -244,7 +244,7 @@ SendTransactionScreen.prototype.getTokensMetadata = async function () {
return Promise.resolve()
}
SendTransactionScreen.prototype.componentDidUnmount = function () {
SendTransactionScreen.prototype.componentWillUnmount = function () {
this.props.dispatch(actions.displayWarning(''))
if (!this.tracker) return
this.tracker.stop()

66877
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -257,7 +257,7 @@
"geckodriver": "^1.12.2",
"gh-pages": "^1.2.0",
"gifencoder": "^1.1.0",
"gulp": "github:gulpjs/gulp#6d71a658c61edb3090221579d8f97dbe086ba2ed",
"gulp": "github:gulpjs/gulp#v4.0.0",
"gulp-babel": "^7.0.0",
"gulp-json-editor": "^2.2.1",
"gulp-livereload": "^3.8.1",

View File

@ -1,8 +1,109 @@
const log = require('loglevel')
const util = require('./util')
const BigNumber = require('bignumber.js')
import contractMapETH from 'eth-contract-metadata'
import contractMapPOA from 'poa-contract-metadata'
function tokenInfoGetter () {
const casedContractMapETH = Object.keys(contractMapETH).reduce((acc, base) => {
return {
...acc,
[base.toLowerCase()]: contractMapETH[base],
}
}, {})
const casedContractMapPOA = Object.keys(contractMapPOA).reduce((acc, base) => {
return {
...acc,
[base.toLowerCase()]: contractMapPOA[base],
}
}, {})
const casedContractMap = Object.assign(casedContractMapETH, casedContractMapPOA)
const DEFAULT_SYMBOL = ''
const DEFAULT_DECIMALS = '0'
async function getSymbolFromContract (tokenAddress) {
const token = util.getContractAtAddress(tokenAddress)
try {
const result = await token.symbol()
return result[0]
} catch (error) {
log.warn(`symbol() call for token at address ${tokenAddress} resulted in error:`, error)
}
}
async function getDecimalsFromContract (tokenAddress) {
const token = util.getContractAtAddress(tokenAddress)
try {
const result = await token.decimals()
const decimalsBN = result[0]
return decimalsBN && decimalsBN.toString()
} catch (error) {
log.warn(`decimals() call for token at address ${tokenAddress} resulted in error:`, error)
}
}
function getContractMetadata (tokenAddress) {
return tokenAddress && casedContractMap[tokenAddress.toLowerCase()]
}
async function getSymbol (tokenAddress) {
let symbol = await getSymbolFromContract(tokenAddress)
if (!symbol) {
const contractMetadataInfo = getContractMetadata(tokenAddress)
if (contractMetadataInfo) {
symbol = contractMetadataInfo.symbol
}
}
return symbol
}
async function getDecimals (tokenAddress) {
let decimals = await getDecimalsFromContract(tokenAddress)
if (!decimals || decimals === '0') {
const contractMetadataInfo = getContractMetadata(tokenAddress)
if (contractMetadataInfo) {
decimals = contractMetadataInfo.decimals
}
}
return decimals
}
export async function getSymbolAndDecimals (tokenAddress, existingTokens = []) {
const existingToken = existingTokens.find(({ address }) => tokenAddress === address)
if (existingToken) {
return {
symbol: existingToken.symbol,
decimals: existingToken.decimals,
}
}
let symbol, decimals
try {
symbol = await getSymbol(tokenAddress)
decimals = await getDecimals(tokenAddress)
} catch (error) {
log.warn(`symbol() and decimal() calls for token at address ${tokenAddress} resulted in error:`, error)
}
return {
symbol: symbol || DEFAULT_SYMBOL,
decimals: decimals || DEFAULT_DECIMALS,
}
}
export function tokenInfoGetter () {
const tokens = {}
return async (address) => {
@ -16,46 +117,12 @@ function tokenInfoGetter () {
}
}
async function getSymbolAndDecimals (tokenAddress, existingTokens = []) {
const existingToken = existingTokens.find(({ address }) => tokenAddress === address)
if (existingToken) {
return existingToken
}
let result = []
try {
const token = util.getContractAtAddress(tokenAddress)
result = await Promise.all([
token.symbol(),
token.decimals(),
])
} catch (err) {
log.warn(`symbol() and decimal() calls for token at address ${tokenAddress} resulted in error:`, err)
}
const [ symbol = [], decimals = [] ] = result
return {
symbol: symbol[0] || null,
decimals: decimals[0] && decimals[0].toString() || null,
}
}
function calcTokenAmount (value, decimals) {
export function calcTokenAmount (value, decimals) {
const multiplier = Math.pow(10, Number(decimals || 0))
return new BigNumber(String(value)).div(multiplier).toNumber()
}
function calcTokenAmountWithDec (valueWithoutDec, decimals) {
export function calcTokenAmountWithDec (valueWithoutDec, decimals) {
const multiplier = Math.pow(10, Number(decimals || 0))
return new BigNumber(valueWithoutDec).mul(multiplier).toNumber()
}
module.exports = {
tokenInfoGetter,
calcTokenAmount,
calcTokenAmountWithDec,
getSymbolAndDecimals,
}