1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-23 03:36:18 +02:00

Merge branch 'i1616-AddTokenAdding' into i784-SendTokenButton

This commit is contained in:
Dan Finlay 2017-06-27 15:08:29 -07:00
commit 40223687ae
5 changed files with 45 additions and 22 deletions

View File

@ -645,7 +645,9 @@ function addToken (address, symbol, decimals) {
if (err) {
return dispatch(actions.displayWarning(err.message))
}
dispatch(actions.goHome())
setTimeout(() => {
dispatch(actions.goHome())
}, 250)
})
}
}

View File

@ -31,6 +31,7 @@ function AddTokenScreen () {
AddTokenScreen.prototype.render = function () {
const state = this.state
const props = this.props
const { warning, symbol, decimals } = state
return (
@ -40,7 +41,7 @@ AddTokenScreen.prototype.render = function () {
h('.section-title.flex-row.flex-center', [
h('i.fa.fa-arrow-left.fa-lg.cursor-pointer', {
onClick: (event) => {
state.dispatch(actions.goHome())
props.dispatch(actions.goHome())
},
}),
h('h2.page-subtitle', 'Add Token'),
@ -141,7 +142,13 @@ AddTokenScreen.prototype.render = function () {
if (!valid) return
const { address, symbol, decimals } = this.state
this.props.dispatch(actions.addToken(address.trim(), symbol.trim(), decimals))
this.checkIfToken(address.trim())
.then(() => {
this.props.dispatch(actions.addToken(address.trim(), symbol.trim(), decimals))
})
.catch((reason) => {
this.setState({ warning: 'Not a valid token address.' })
})
},
}, 'Add'),
]),
@ -201,6 +208,12 @@ AddTokenScreen.prototype.validateInputs = function () {
return isValid
}
AddTokenScreen.prototype.checkIfToken = async function (address) {
const contract = this.TokenContract.at(address)
const result = await contract.balance(address)
return result[0].toString()
}
AddTokenScreen.prototype.attemptToAutoFillTokenParams = async function (address) {
const contract = this.TokenContract.at(address)

View File

@ -2,6 +2,7 @@ const Component = require('react').Component
const h = require('react-hyperscript')
const inherits = require('util').inherits
const Identicon = require('./identicon')
const prefixForNetwork = require('../../lib/etherscan-prefix-for-network')
module.exports = TokenCell
@ -59,7 +60,8 @@ function navigateTo (url) {
}
function etherscanLinkFor (tokenAddress, address, network) {
return `https://etherscan.io/token/${tokenAddress}?a=${address}`
const prefix = prefixForNetwork(network)
return `https://${prefix}etherscan.io/token/${tokenAddress}?a=${address}`
}
function tokenFactoryFor (tokenAddress) {

View File

@ -0,0 +1,21 @@
module.exports = function (network) {
const net = parseInt(network)
let prefix
switch (net) {
case 1: // main net
prefix = ''
break
case 3: // ropsten test net
prefix = 'ropsten.'
break
case 4: // rinkeby test net
prefix = 'rinkeby.'
break
case 42: // kovan test net
prefix = 'kovan.'
break
default:
prefix = ''
}
return prefix
}

View File

@ -1,21 +1,6 @@
const prefixForNetwork = require('./etherscan-prefix-for-network')
module.exports = function (hash, network) {
const net = parseInt(network)
let prefix
switch (net) {
case 1: // main net
prefix = ''
break
case 3: // ropsten test net
prefix = 'ropsten.'
break
case 4: // rinkeby test net
prefix = 'rinkeby.'
break
case 42: // kovan test net
prefix = 'kovan.'
break
default:
prefix = ''
}
const prefix = prefixForNetwork(network)
return `http://${prefix}etherscan.io/tx/${hash}`
}