Ability to set tx value for payable methods

This commit is contained in:
Victor Baranov 2020-03-24 11:56:11 +03:00
parent 91918a6cdc
commit 576e957fa4
5 changed files with 22 additions and 6 deletions

View File

@ -2,6 +2,7 @@
## Current Master
- [#334](https://github.com/poanetwork/nifty-wallet/pull/334) - (Feature) Ability to set tx value for payable methods
- [#333](https://github.com/poanetwork/nifty-wallet/pull/333) - (Fix) Support RSK testnet explorer links
- [#332](https://github.com/poanetwork/nifty-wallet/pull/332) - (Chore) Return to main screen from removal of imported account
- [#330](https://github.com/poanetwork/nifty-wallet/pull/330) - (Fix) Derive correct addresses for custom networks (RSK/ETC)

View File

@ -6,7 +6,7 @@ import actions from '../../../ui/app/actions'
class DeleteRpc extends ConfirmScreen {
static propTypes = {
}
render () {
const props = this.props
return (

View File

@ -184,7 +184,7 @@ class ChooseContractExecutor extends Component {
return new Promise((resolve) => {
try {
web3.eth.contract(abi).at(txParams.to)[method].call((err, output) => {
web3.eth.contract(abi).at(txParams.to)[method].call((_err, output) => {
resolve(output)
})
} catch (e) {

View File

@ -12,6 +12,7 @@ import abi from 'web3-eth-abi'
import Web3 from 'web3'
import copyToClipboard from 'copy-to-clipboard'
import CopyButton from '../copy/copy-button'
import { normalizeEthStringToWei } from '../../util'
class SendTransactionField extends Component {
constructor (props) {
@ -130,6 +131,7 @@ class SendTransactionScreen extends PersistentForm {
methodOutputsView: [],
isConstantMethod: false,
inputValues: props.inputValues || {},
txValue: props.txValue || '0x',
outputValues: props.outputValues || {},
copyDisabled: true,
}
@ -167,6 +169,7 @@ class SendTransactionScreen extends PersistentForm {
methodABI: opt.metadata,
outputValues: {},
inputValues: {},
txValue: '0x',
}, () => {
this.generateMethodFieldsView(opt.metadata)
})
@ -251,7 +254,7 @@ class SendTransactionScreen extends PersistentForm {
}
const textTypeProps = {
key: Math.random(),
placeholder: params.type,
placeholder: params.placeholder || params.type,
}
if (params.type === 'bool' && isInput) {
field = (
@ -277,17 +280,25 @@ class SendTransactionScreen extends PersistentForm {
handleInputChange (val, type, ind) {
const { inputValues } = this.state
let { txValue } = this.state
if (val) {
if (type === 'bool') {
inputValues[ind] = (val === 'true')
} else if (type === 'value') {
const valWei = normalizeEthStringToWei(val)
txValue = '0x' + parseInt(valWei, 10).toString(16)
} else {
inputValues[ind] = val
}
} else {
delete inputValues[ind]
if (type === 'value') {
txValue = '0x'
}
}
this.setState({
inputValues,
txValue,
})
}
@ -302,9 +313,13 @@ class SendTransactionScreen extends PersistentForm {
const methodInputs = metadata && metadata.inputs
const methodOutputsView = []
const methodOutputs = metadata && metadata.outputs
if (metadata.stateMutability === 'payable') {
methodInputsView.push(this.generateMethodField({'name': 'tx value', 'type': 'value', 'placeholder': 'tx value in Ether' }, methodInputs.length, true))
}
methodInputs.forEach((input, ind) => {
methodInputsView.push(this.generateMethodField(input, ind, true))
})
methodOutputs.forEach((output, ind) => {
methodOutputsView.push(this.generateMethodField(output, ind, false))
})
@ -448,7 +463,7 @@ class SendTransactionScreen extends PersistentForm {
}
onSubmit = () => {
const { inputValues, methodABI, methodSelected } = this.state
const { inputValues, txValue, methodABI, methodSelected } = this.state
const { address } = this.props
const txData = this.encodeFunctionCall()
@ -456,7 +471,7 @@ class SendTransactionScreen extends PersistentForm {
this.props.hideWarning()
const txParams = {
value: '0x',
value: txValue,
data: txData,
to: address,
}

View File

@ -1000,7 +1000,7 @@ function signTypedMsg (msgData) {
function signTx (txData) {
return (dispatch) => {
global.ethQuery.sendTransaction(txData, (err, data) => {
global.ethQuery.sendTransaction(txData, (err, _data) => {
if (err) {
return dispatch(actions.displayWarning(err.message))
}