Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Fix) Unlock back contract account on rejecting/accepting of contract execution transaction #238

Merged
merged 22 commits into from
Dec 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
0a82973
unlock contract acount on rejecting/accepting contract execution tran…
vbaranov Dec 24, 2018
333153e
unit tests fix
vbaranov Dec 24, 2018
0ec0198
ESLint fix
vbaranov Dec 24, 2018
11e2ad4
props.isContractExecutionByUser to buyView
vbaranov Dec 24, 2018
eca9e0e
rememeber, that tx is from imported contract on `Buy ether` click
vbaranov Dec 24, 2018
e09aa87
e2e:merge with execute-button
dennis00010011b Dec 25, 2018
d3aec77
add isContractExecutionByUser to prop types validation
vbaranov Dec 25, 2018
9890bcb
e2e: sync with upstream
dennis00010011b Dec 25, 2018
9def952
e2e: test button reject
dennis00010011b Dec 25, 2018
68f979c
e2e: test button reject all, submit
dennis00010011b Dec 25, 2018
feeaf06
e2e: execute method button submit buy ether
dennis00010011b Dec 26, 2018
617bbaf
e2e: fix name of tests
dennis00010011b Dec 26, 2018
aa4a1fc
e2e:check buttons name
dennis00010011b Dec 26, 2018
a5ad1c6
e2e:improve stability
dennis00010011b Dec 26, 2018
b613c3f
e2e:improve stability
dennis00010011b Dec 26, 2018
386dc14
e2e:improve stability#2
dennis00010011b Dec 26, 2018
7ef163b
Merge remote-tracking branch 'origin/develop' into change-to-contract…
vbaranov Dec 26, 2018
3df1341
Merge branch 'change-to-contract-acc-after-execution' into e2e-contra…
vbaranov Dec 26, 2018
b81fe64
Merge pull request #240 from dennis00010011b/e2e-contract-back
vbaranov Dec 26, 2018
2b1e7fd
Merge remote-tracking branch 'origin/develop' into change-to-contract…
vbaranov Dec 26, 2018
e0f8a26
Merge branch 'change-to-contract-acc-after-execution' of github.com:p…
vbaranov Dec 26, 2018
90bac9e
merge with develop branch
vbaranov Dec 27, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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