Skip to content

Commit

Permalink
Merge pull request #238 from poanetwork/change-to-contract-acc-after-…
Browse files Browse the repository at this point in the history
…execution

(Fix) Unlock back contract account on rejecting/accepting of contract execution transaction
  • Loading branch information
vbaranov committed Dec 28, 2018
2 parents 693024d + 90bac9e commit 798256f
Show file tree
Hide file tree
Showing 9 changed files with 327 additions and 129 deletions.
6 changes: 5 additions & 1 deletion old-ui/app/components/buy-button-subview.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ class BuyButtonSubview extends Component {

backButtonContext () {
if (this.props.context === 'confTx') {
this.props.dispatch(actions.showConfTxPage(false))
this.props.dispatch(actions.showConfTxPage({
isContractExecutionByUser: this.props.isContractExecutionByUser,
}))
} else {
this.props.dispatch(actions.goHome())
}
Expand All @@ -191,6 +193,7 @@ BuyButtonSubview.propTypes = {
buyView: PropTypes.object,
context: PropTypes.string,
provider: PropTypes.object,
isContractExecutionByUser: PropTypes.bool,
}

function mapStateToProps (state) {
Expand All @@ -203,6 +206,7 @@ function mapStateToProps (state) {
provider: state.metamask.provider,
context: state.appState.currentView.context,
isSubLoading: state.appState.isSubLoading,
isContractExecutionByUser: state.appState.buyView.isContractExecutionByUser,
}
}

Expand Down
1 change: 1 addition & 0 deletions old-ui/app/components/send/choose-contract-executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class ChooseContractExecutor extends Component {
const { selectedExecutor } = this.state
this.props.setSelectedAddress(selectedExecutor)
txParams.from = selectedExecutor
txParams.isContractExecutionByUser = true
this.props.signTx(txParams)
}

Expand Down
52 changes: 49 additions & 3 deletions old-ui/app/conf-tx.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const actions = require('../../ui/app/actions')
const LoadingIndicator = require('./components/loading')
const txHelper = require('../lib/tx-helper')
const log = require('loglevel')
const { getCurrentKeyring, ifContractAcc } = require('./util')

const PendingTx = require('./components/pending-tx')
import PendingMsg from './components/pending-msg'
Expand All @@ -20,6 +21,7 @@ function mapStateToProps (state) {
const { screenParams, pendingTxIndex } = appState.currentView
return {
identities: metamask.identities,
keyrings: metamask.keyrings,
accounts: metamask.accounts,
selectedAddress: metamask.selectedAddress,
unapprovedTxs: metamask.unapprovedTxs,
Expand All @@ -38,6 +40,7 @@ function mapStateToProps (state) {
tokenSymbol: (screenParams && screenParams.tokenSymbol),
tokensToSend: (screenParams && screenParams.tokensToSend),
tokensTransferTo: (screenParams && screenParams.tokensTransferTo),
isContractExecutionByUser: (screenParams && screenParams.isContractExecutionByUser),
}
}

Expand Down Expand Up @@ -109,7 +112,7 @@ ConfirmTxScreen.prototype.render = function () {
tokensToSend: props.tokensToSend,
tokensTransferTo: props.tokensTransferTo,
// Actions
buyEth: this.buyEth.bind(this, txParams.from || props.selectedAddress),
buyEth: this.buyEth.bind(this, txParams.from || props.selectedAddress, props.isContractExecutionByUser),
sendTransaction: this.sendTransaction.bind(this),
cancelTransaction: this.cancelTransaction.bind(this, txData),
cancelAllTransactions: this.cancelAllTransactions.bind(this, unconfTxList),
Expand Down Expand Up @@ -148,26 +151,29 @@ function currentTxView (opts) {
}
}

ConfirmTxScreen.prototype.buyEth = function (address, event) {
ConfirmTxScreen.prototype.buyEth = function (address, isContractExecutionByUser, event) {
event.preventDefault()
this.props.dispatch(actions.buyEthView(address))
this.props.dispatch(actions.buyEthView(address, isContractExecutionByUser))
}

ConfirmTxScreen.prototype.sendTransaction = function (txData, event) {
this.stopPropagation(event)
this.props.dispatch(actions.updateAndApproveTx(txData))
this._checkIfContractExecutionAndUnlockContract(txData)
}

ConfirmTxScreen.prototype.cancelTransaction = function (txData, event) {
this.stopPropagation(event)
event.preventDefault()
this.props.dispatch(actions.cancelTx(txData))
this._checkIfContractExecutionAndUnlockContract(txData)
}

ConfirmTxScreen.prototype.cancelAllTransactions = function (unconfTxList, event) {
this.stopPropagation(event)
event.preventDefault()
this.props.dispatch(actions.cancelAllTx(unconfTxList))
this._checkIfMultipleContractExecutionAndUnlockContract(unconfTxList)
}

ConfirmTxScreen.prototype.signMessage = function (msgData, event) {
Expand Down Expand Up @@ -218,6 +224,46 @@ ConfirmTxScreen.prototype.cancelTypedMessage = function (msgData, event) {
this.props.dispatch(actions.cancelTypedMsg(msgData))
}

ConfirmTxScreen.prototype._checkIfMultipleContractExecutionAndUnlockContract = function (unconfTxList) {
const areTxsToOneContractFromTheList = unconfTxList.slice(0).reduce((res, txData, ind, unconfTxList) => {
if (txData.txParams.data && this.props.isContractExecutionByUser) {
const to = txData && txData.txParams && txData.txParams.to
const targetContractIsInTheList = Object.keys(this.props.accounts).some((acc) => acc === to)
if (targetContractIsInTheList && Object.keys(res).length === 0) {
res = { status: true, to }
} else if (res.status && res.to !== to) {
res = { status: false }
unconfTxList.splice(1)
}
} else {
res = { status: false }
unconfTxList.splice(1)
}
return res
}, {})

if (areTxsToOneContractFromTheList.status) {
this._unlockContract(areTxsToOneContractFromTheList.to)
}
}

ConfirmTxScreen.prototype._checkIfContractExecutionAndUnlockContract = function (txData) {
if (txData.txParams.data && this.props.isContractExecutionByUser) {
const to = txData && txData.txParams && txData.txParams.to
const targetContractIsInTheList = Object.keys(this.props.accounts).some((acc) => acc === to)
if (targetContractIsInTheList) {
this._unlockContract(to)
}
}
}

ConfirmTxScreen.prototype._unlockContract = function (to) {
const currentKeyring = getCurrentKeyring(to, this.props.network, this.props.keyrings, this.props.identities)
if (ifContractAcc(currentKeyring)) {
this.props.dispatch(actions.showAccountDetail(to))
}
}

function warningIfExists (warning) {
if (warning &&
// Do not display user rejections on this screen:
Expand Down
2 changes: 0 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 14 additions & 4 deletions test/e2e/elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const webdriver = require('selenium-webdriver')
const { By } = webdriver
module.exports = {
elements: {
buttonArrow: By.className('fa fa-arrow-left fa-lg cursor-pointer'),
errorClose: By.css('.send-screen > div:nth-child(3) > div:nth-child(1)'),
error: By.className('error'),
loader: By.css('#app-content > div > div.full-flex-height > img'),
Expand Down Expand Up @@ -31,12 +32,15 @@ module.exports = {
account: {
account1: By.css('#app-content > div > div.full-width > div.full-width > div > div:nth-child(2) > span > div > div > span > div > li:nth-child(2) > span'),
account2: By.css('#app-content > div > div.full-width > div.full-width > div > div:nth-child(2) > span > div > div > span > div > li:nth-child(3) > span'),
account3: By.css('#app-content > div > div.full-width > div.full-width > div > div:nth-child(2) > span > div > div > span > div > li:nth-child(4) > span'),
account4: By.css('#app-content > div > div.full-width > div.full-width > div > div:nth-child(2) > span > div > div > span > div > li:nth-child(5) > span'),
menu: By.css('#app-content > div > div.full-width > div.full-width > div > div:nth-child(2) > span > div'),
delete: By.css('#app-content > div > div.full-width > div.full-width > div > div:nth-child(2) > span > div > div > span > div > li:nth-child(4) > div.remove'),
delete: By.className('remove'),
createAccount: By.css('#app-content > div > div.full-width > div.full-width > div > div:nth-child(2) > span > div > div > span > div > li:nth-child(3) > span'),
// import: By.css('#app-content > div > div.full-width > div.full-width > div > div:nth-child(2) > span > div > div > span > div > li:nth-child(5) > span'),
import: By.css('li.dropdown-menu-item:nth-child(5) > span:nth-child(1)'),
labelImported: By.css('#app-content > div > div.full-width > div.full-width > div > div:nth-child(2) > span > div > div > span > div > li:nth-child(4) > div.keyring-label'),
import2: By.css('#app-content > div > div.full-width > div.full-width > div > div:nth-child(2) > span > div > div > span > div > li:nth-child(6)'),
label: By.className('keyring-label'),
},
dot: {
menu: By.className('account-dropdown'),
Expand Down Expand Up @@ -73,7 +77,7 @@ module.exports = {
buttonNext: By.css('.section > div:nth-child(1) > button:nth-child(2)'),
buttonArrow: By.className('fa fa-arrow-left fa-lg cursor-pointer'),
buttonCopyABI: By.className('btn-violet'),
buttonExecuteMethod: By.css('#app-content > div > div.app-primary.from-right > div > div > div.flex-row > button'),
buttonExecuteMethod: By.xpath('//*[@id="app-content"]/div/div[2]/div/div/div[2]/button'),
},
eventsEmitter: {
button: By.className('btn btn-default'),
Expand Down Expand Up @@ -195,6 +199,8 @@ module.exports = {
button: {
submit: By.css('#pending-tx-form > div.flex-row.flex-space-around.conf-buttons > input'),
reject: By.css('.cancel'),
rejectAll: By.css('#pending-tx-form > div:nth-child(4) > button'),
buyEther: By.css('#pending-tx-form > div.flex-row.flex-space-around.conf-buttons > button.btn-green'),
},
fields: {
gasLimit: By.css('#pending-tx-form > div:nth-child(1) > div.table-box > div:nth-child(3) > div.cell.value > div > div > input'),
Expand Down Expand Up @@ -233,7 +239,7 @@ module.exports = {
error: By.css('span.error'),
selectArrow: By.className('Select-arrow-zone'),
selectType: By.name('import-type-select'),
itemContract: By.id('react-select-2--option-2'),
itemContract: By.id('react-select-3--option-2'),
contractAddress: By.id('address-box'),
contractABI: By.id('abi-box'),
title: By.css('#app-content > div > div.app-primary.from-right > div > div:nth-child(2) > div.flex-row.flex-center > h2'),
Expand Down Expand Up @@ -265,6 +271,7 @@ module.exports = {
},
},
main: {
accountAddress: By.xpath('//*[@id="app-content"]/div/div[2]/div/div/div[1]/flex-column/div[2]/div/span'),
identicon: By.className('identicon-wrapper select-none'),
fieldAccountName: By.className('sizing-input'),
accountName: By.className('font-medium color-forest'),
Expand Down Expand Up @@ -298,6 +305,9 @@ module.exports = {
counterFF: By.css('div.full-flex-height:nth-child(2) > div:nth-child(1) > span:nth-child(1)'),
},
},
buyEther: {
title: By.className('flex-center buy-title'),
},
info: {
title: By.className('section-title flex-row flex-center'),
titleText: 'Info',
Expand Down
Loading

0 comments on commit 798256f

Please sign in to comment.