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 ## 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 - [#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 - [#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) - [#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 { class DeleteRpc extends ConfirmScreen {
static propTypes = { static propTypes = {
} }
render () { render () {
const props = this.props const props = this.props
return ( return (

View File

@ -184,7 +184,7 @@ class ChooseContractExecutor extends Component {
return new Promise((resolve) => { return new Promise((resolve) => {
try { 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) resolve(output)
}) })
} catch (e) { } catch (e) {

View File

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

View File

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