Added signTokenTx; Adding token confirmation screen
This commit is contained in:
parent
836bf2e1a3
commit
7eb6dae418
|
@ -1,6 +1,7 @@
|
||||||
const EventEmitter = require('events').EventEmitter
|
const EventEmitter = require('events').EventEmitter
|
||||||
const async = require('async')
|
const async = require('async')
|
||||||
const Dnode = require('dnode')
|
const Dnode = require('dnode')
|
||||||
|
const Eth = require('ethjs')
|
||||||
const EthQuery = require('eth-query')
|
const EthQuery = require('eth-query')
|
||||||
const launchMetamaskUi = require('../../ui')
|
const launchMetamaskUi = require('../../ui')
|
||||||
const StreamProvider = require('web3-stream-provider')
|
const StreamProvider = require('web3-stream-provider')
|
||||||
|
@ -34,6 +35,7 @@ function setupWeb3Connection (connectionStream) {
|
||||||
providerStream.on('error', console.error.bind(console))
|
providerStream.on('error', console.error.bind(console))
|
||||||
global.ethereumProvider = providerStream
|
global.ethereumProvider = providerStream
|
||||||
global.ethQuery = new EthQuery(providerStream)
|
global.ethQuery = new EthQuery(providerStream)
|
||||||
|
global.eth = new Eth(providerStream)
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupControllerConnection (connectionStream, cb) {
|
function setupControllerConnection (connectionStream, cb) {
|
||||||
|
@ -47,6 +49,7 @@ function setupControllerConnection (connectionStream, cb) {
|
||||||
})
|
})
|
||||||
connectionStream.pipe(accountManagerDnode).pipe(connectionStream)
|
connectionStream.pipe(accountManagerDnode).pipe(connectionStream)
|
||||||
accountManagerDnode.once('remote', function (accountManager) {
|
accountManagerDnode.once('remote', function (accountManager) {
|
||||||
|
console.log({ accountManager })
|
||||||
// setup push events
|
// setup push events
|
||||||
accountManager.on = eventEmitter.on.bind(eventEmitter)
|
accountManager.on = eventEmitter.on.bind(eventEmitter)
|
||||||
cb(null, accountManager)
|
cb(null, accountManager)
|
||||||
|
|
|
@ -80,6 +80,7 @@
|
||||||
"ethereumjs-tx": "^1.3.0",
|
"ethereumjs-tx": "^1.3.0",
|
||||||
"ethereumjs-util": "github:ethereumjs/ethereumjs-util#ac5d0908536b447083ea422b435da27f26615de9",
|
"ethereumjs-util": "github:ethereumjs/ethereumjs-util#ac5d0908536b447083ea422b435da27f26615de9",
|
||||||
"ethereumjs-wallet": "^0.6.0",
|
"ethereumjs-wallet": "^0.6.0",
|
||||||
|
"ethjs": "^0.2.8",
|
||||||
"ethjs-ens": "^2.0.0",
|
"ethjs-ens": "^2.0.0",
|
||||||
"ethjs-query": "^0.2.9",
|
"ethjs-query": "^0.2.9",
|
||||||
"express": "^4.14.0",
|
"express": "^4.14.0",
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
const abi = require('human-standard-token-abi')
|
||||||
const getBuyEthUrl = require('../../app/scripts/lib/buy-eth-url')
|
const getBuyEthUrl = require('../../app/scripts/lib/buy-eth-url')
|
||||||
|
|
||||||
var actions = {
|
var actions = {
|
||||||
|
@ -118,6 +119,7 @@ var actions = {
|
||||||
cancelPersonalMsg,
|
cancelPersonalMsg,
|
||||||
sendTx: sendTx,
|
sendTx: sendTx,
|
||||||
signTx: signTx,
|
signTx: signTx,
|
||||||
|
signTokenTx: signTokenTx,
|
||||||
updateAndApproveTx,
|
updateAndApproveTx,
|
||||||
cancelTx: cancelTx,
|
cancelTx: cancelTx,
|
||||||
completedTx: completedTx,
|
completedTx: completedTx,
|
||||||
|
@ -192,6 +194,7 @@ module.exports = actions
|
||||||
var background = null
|
var background = null
|
||||||
function _setBackgroundConnection (backgroundConnection) {
|
function _setBackgroundConnection (backgroundConnection) {
|
||||||
background = backgroundConnection
|
background = backgroundConnection
|
||||||
|
console.log({ background })
|
||||||
}
|
}
|
||||||
|
|
||||||
function goHome () {
|
function goHome () {
|
||||||
|
@ -439,6 +442,19 @@ function sendTx (txData) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function signTokenTx (tokenAddress, toAddress, amount, txData) {
|
||||||
|
return dispatch => {
|
||||||
|
dispatch(actions.showLoadingIndication())
|
||||||
|
const token = global.eth.contract(abi).at(tokenAddress)
|
||||||
|
token.transfer(toAddress, amount, txData)
|
||||||
|
.catch(err => {
|
||||||
|
dispatch(actions.hideLoadingIndication())
|
||||||
|
dispatch(actions.displayWarning(err.message))
|
||||||
|
})
|
||||||
|
dispatch(actions.showConfTxPage({}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function updateAndApproveTx (txData) {
|
function updateAndApproveTx (txData) {
|
||||||
log.info('actions: updateAndApproveTx: ' + JSON.stringify(txData))
|
log.info('actions: updateAndApproveTx: ' + JSON.stringify(txData))
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
|
|
|
@ -91,9 +91,9 @@ PendingTx.prototype.render = function () {
|
||||||
// const maxCost = txFeeBn.add(amountBn)
|
// const maxCost = txFeeBn.add(amountBn)
|
||||||
// const balanceBn = hexToBn(balance)
|
// const balanceBn = hexToBn(balance)
|
||||||
// const insufficientBalance = balanceBn.lt(maxCost)
|
// const insufficientBalance = balanceBn.lt(maxCost)
|
||||||
|
const fromName = identities[txParams.from].name
|
||||||
const fromName = identities[txParams.from].name;
|
const to = identities[txParams.to]
|
||||||
const toName = identities[txParams.to].name;
|
const toName = to ? to.name : ' '
|
||||||
|
|
||||||
const endOfFromAddress = txParams.from.slice(txParams.from.length - 4)
|
const endOfFromAddress = txParams.from.slice(txParams.from.length - 4)
|
||||||
const endOfToAddress = txParams.to.slice(txParams.to.length - 4)
|
const endOfToAddress = txParams.to.slice(txParams.to.length - 4)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const Component = require('react').Component
|
const Component = require('react').Component
|
||||||
const connect = require('react-redux').connect
|
const connect = require('react-redux').connect
|
||||||
const h = require('react-hyperscript')
|
const h = require('react-hyperscript')
|
||||||
const ethUtil = require('ethereumjs-util')
|
const { addHexPrefix } = require('ethereumjs-util')
|
||||||
const classnames = require('classnames')
|
const classnames = require('classnames')
|
||||||
const inherits = require('util').inherits
|
const inherits = require('util').inherits
|
||||||
const actions = require('../../actions')
|
const actions = require('../../actions')
|
||||||
|
@ -50,6 +50,14 @@ function mapStateToProps (state) {
|
||||||
function mapDispatchToProps (dispatch) {
|
function mapDispatchToProps (dispatch) {
|
||||||
return {
|
return {
|
||||||
backToAccountDetail: address => dispatch(actions.backToAccountDetail(address)),
|
backToAccountDetail: address => dispatch(actions.backToAccountDetail(address)),
|
||||||
|
hideWarning: () => dispatch(actions.hideWarning()),
|
||||||
|
addToAddressBook: (recipient, nickname) => dispatch(
|
||||||
|
actions.addToAddressBook(recipient, nickname)
|
||||||
|
),
|
||||||
|
signTx: txParams => dispatch(actions.signTx(txParams)),
|
||||||
|
signTokenTx: (tokenAddress, toAddress, amount, txData) => (
|
||||||
|
dispatch(actions.signTokenTx(tokenAddress, toAddress, amount, txData))
|
||||||
|
),
|
||||||
// showSidebar: () => { dispatch(actions.showSidebar()) },
|
// showSidebar: () => { dispatch(actions.showSidebar()) },
|
||||||
// hideSidebar: () => { dispatch(actions.hideSidebar()) },
|
// hideSidebar: () => { dispatch(actions.hideSidebar()) },
|
||||||
// showModal: (payload) => { dispatch(actions.showModal(payload)) },
|
// showModal: (payload) => { dispatch(actions.showModal(payload)) },
|
||||||
|
@ -75,13 +83,14 @@ function SendTokenScreen () {
|
||||||
SendTokenScreen.prototype.validate = function () {
|
SendTokenScreen.prototype.validate = function () {
|
||||||
const {
|
const {
|
||||||
to,
|
to,
|
||||||
amount,
|
amount: stringAmount,
|
||||||
gasPrice: hexGasPrice,
|
gasPrice: hexGasPrice,
|
||||||
gasLimit: hexGasLimit,
|
gasLimit: hexGasLimit,
|
||||||
} = this.state
|
} = this.state
|
||||||
|
|
||||||
const gasPrice = parseInt(hexGasPrice, 16)
|
const gasPrice = parseInt(hexGasPrice, 16)
|
||||||
const gasLimit = parseInt(hexGasLimit, 16) / 1000000000
|
const gasLimit = parseInt(hexGasLimit, 16) / 1000000000
|
||||||
|
const amount = Number(stringAmount)
|
||||||
|
|
||||||
if (to && amount && gasPrice && gasLimit) {
|
if (to && amount && gasPrice && gasLimit) {
|
||||||
return {
|
return {
|
||||||
|
@ -92,7 +101,7 @@ SendTokenScreen.prototype.validate = function () {
|
||||||
|
|
||||||
const errors = {
|
const errors = {
|
||||||
to: !to ? 'Required' : null,
|
to: !to ? 'Required' : null,
|
||||||
amount: !Number(amount) ? 'Required' : null,
|
amount: !amount ? 'Required' : null,
|
||||||
gasPrice: !gasPrice ? 'Gas Price Required' : null,
|
gasPrice: !gasPrice ? 'Gas Price Required' : null,
|
||||||
gasLimit: !gasLimit ? 'Gas Limit Required' : null,
|
gasLimit: !gasLimit ? 'Gas Limit Required' : null,
|
||||||
}
|
}
|
||||||
|
@ -104,20 +113,41 @@ SendTokenScreen.prototype.validate = function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
SendTokenScreen.prototype.submit = function () {
|
SendTokenScreen.prototype.submit = function () {
|
||||||
// const {
|
const {
|
||||||
// to,
|
to,
|
||||||
// amount,
|
amount,
|
||||||
// selectedCurrency,
|
gasPrice,
|
||||||
// isGasTooltipOpen,
|
gasLimit,
|
||||||
// gasPrice,
|
} = this.state
|
||||||
// gasLimit,
|
|
||||||
// } = this.state
|
const {
|
||||||
|
identities,
|
||||||
|
selectedAddress,
|
||||||
|
selectedTokenAddress,
|
||||||
|
hideWarning,
|
||||||
|
addToAddressBook,
|
||||||
|
signTokenTx,
|
||||||
|
} = this.props
|
||||||
|
|
||||||
|
const { nickname = ' ' } = identities[to] || {}
|
||||||
|
|
||||||
const { isValid, errors } = this.validate()
|
const { isValid, errors } = this.validate()
|
||||||
|
|
||||||
if (!isValid) {
|
if (!isValid) {
|
||||||
return this.setState({ errors })
|
return this.setState({ errors })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hideWarning()
|
||||||
|
addToAddressBook(to, nickname)
|
||||||
|
|
||||||
|
const txParams = {
|
||||||
|
from: selectedAddress,
|
||||||
|
value: '0',
|
||||||
|
gas: gasLimit,
|
||||||
|
gasPrice: gasPrice,
|
||||||
|
}
|
||||||
|
|
||||||
|
signTokenTx(selectedTokenAddress, to, Number(amount).toString(16), txParams)
|
||||||
}
|
}
|
||||||
|
|
||||||
SendTokenScreen.prototype.renderToAddressInput = function () {
|
SendTokenScreen.prototype.renderToAddressInput = function () {
|
||||||
|
|
|
@ -3382,7 +3382,7 @@ ethjs-util@^0.1.3:
|
||||||
is-hex-prefixed "1.0.0"
|
is-hex-prefixed "1.0.0"
|
||||||
strip-hex-prefix "1.0.0"
|
strip-hex-prefix "1.0.0"
|
||||||
|
|
||||||
ethjs@^0.2.7:
|
ethjs@^0.2.7, ethjs@^0.2.8:
|
||||||
version "0.2.8"
|
version "0.2.8"
|
||||||
resolved "https://registry.yarnpkg.com/ethjs/-/ethjs-0.2.8.tgz#65ed276c5e58e89d51d4573585b7a16142ccf8f0"
|
resolved "https://registry.yarnpkg.com/ethjs/-/ethjs-0.2.8.tgz#65ed276c5e58e89d51d4573585b7a16142ccf8f0"
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|
Loading…
Reference in New Issue