Various fixes from review

This commit is contained in:
Victor Baranov 2018-12-05 14:22:50 +03:00
parent 6af70ad914
commit 2546ed374b
9 changed files with 29 additions and 15 deletions

View File

@ -824,7 +824,7 @@ module.exports = class MetamaskController extends EventEmitter {
* @param {string[]} address A hex address
*
*/
async removeAccount (address) {
async removeAccount (address, network) {
// Remove account from the preferences controller
this.preferencesController.removeAddress(address)
// Remove account from the account tracker controller
@ -832,7 +832,7 @@ module.exports = class MetamaskController extends EventEmitter {
// Remove account from the keyring
try {
await this.keyringController.removeAccount(address)
await this.keyringController.removeAccount(address, network)
} catch (e) {
log.error(e)
}

View File

@ -225,9 +225,11 @@ class AccountDropdowns extends Component {
}
renderAccountOptions () {
const { actions, selected } = this.props
const { actions, selected, network, keyrings, identities } = this.props
const { optionsMenuActive } = this.state
const keyring = getCurrentKeyring(selected, network, keyrings, identities)
return h(
Dropdown,
{
@ -285,7 +287,7 @@ class AccountDropdowns extends Component {
},
'Copy address to clipboard',
),
!this.ifHardwareAcc(selected) ? h(
(!this.ifHardwareAcc(selected) && !(ifContractAcc(keyring))) ? h(
DropdownMenuItem,
{
closeMenu: () => {},

View File

@ -68,7 +68,7 @@ DeleteImportedAccount.prototype.render = function () {
h('button',
{
onClick: () => {
this.props.dispatch(actions.removeAccount(this.props.identity.address))
this.props.dispatch(actions.removeAccount(this.props.identity.address, this.props.network))
.then(() => {
this.props.dispatch(actions.showConfigPage())
})

View File

@ -45,11 +45,11 @@ class ChooseContractExecutor extends Component {
}}
/>
<div style={{ padding: '0 30px' }}>
<span className="hw-connect__header__msg">contract transaction will be executed from selected account</span>
<span className="hw-connect__header__msg">Contract transaction will be executed from selected account</span>
</div>
<div style={{
padding: '0 30px',
maxHeight: '350px',
maxHeight: '220px',
overflow: 'auto',
}}>
{this.state.accountsCells}
@ -100,6 +100,7 @@ class ChooseContractExecutor extends Component {
key={Math.random()}
address={address}
identity={identity}
isAccountSelected={this.isAccountSelected(address)}
onClick={(e, isSelected) => this.selectExecutor(e, isSelected, address)}
/>
)
@ -112,6 +113,12 @@ class ChooseContractExecutor extends Component {
})
}
componentDidUpdate (prevProps, prevState) {
if (prevState.selectedExecutor !== this.state.selectedExecutor) {
this.generateListOfAccounts()
}
}
onSubmit = () => {
const { txParams } = this.props
const { selectedExecutor } = this.state
@ -134,6 +141,10 @@ class ChooseContractExecutor extends Component {
}
}
isAccountSelected (address) {
return address === this.state.selectedExecutor
}
back () {
const { methodSelected, methodABI, inputValues } = this.props
this.props.showSendContractPage({methodSelected, methodABI, inputValues})

View File

@ -7,11 +7,12 @@ class ExecutorCell extends Component {
constructor (props) {
super(props)
this.state = {
isSelected: false,
isSelected: props.isAccountSelected,
}
}
static propTypes = {
isAccountSelected: PropTypes.bool,
address: PropTypes.string,
identity: PropTypes.object,
onClick: PropTypes.func,

2
package-lock.json generated
View File

@ -10599,7 +10599,7 @@
}
},
"eth-keychain-controller": {
"version": "github:vbaranov/KeyringController#9bce73e9d2b9d23ac6d372d0c39f8d90347ee1ea",
"version": "github:vbaranov/KeyringController#37d3ec688427b16c092e85d3da8809036be5a24a",
"from": "github:vbaranov/KeyringController#simple-address",
"requires": {
"bip39": "^2.4.0",

View File

@ -66,7 +66,7 @@ describe('ChooseContractExecutor component', () => {
})
it('shows correct description', () => {
assert.equal(wrapper.find('.hw-connect__header__msg').text(), 'contract transaction will be executed from selected account')
assert.equal(wrapper.find('.hw-connect__header__msg').text(), 'Contract transaction will be executed from selected account')
})
it('shows Next button', () => {

View File

@ -471,7 +471,7 @@ describe('Actions', () => {
removeAccountSpy = sinon.spy(background, 'removeAccount')
return store.dispatch(actions.removeAccount('0xe18035bf8712672935fdb4e5e431b1a0183d2dfc'))
return store.dispatch(actions.removeAccount('0xe18035bf8712672935fdb4e5e431b1a0183d2dfc', '1'))
.then(() => {
assert(removeAccountSpy.calledOnce)
assert.deepEqual(store.getActions(), expectedActions)
@ -486,11 +486,11 @@ describe('Actions', () => {
{ type: 'DISPLAY_WARNING', value: 'error' },
]
removeAccountSpy = sinon.stub(background, 'removeAccount')
removeAccountSpy.callsFake((address, callback) => {
removeAccountSpy.callsFake((address, network, callback) => {
callback(new Error('error'))
})
return store.dispatch(actions.removeAccount('0xe18035bf8712672935fdb4e5e431b1a0183d2dfc'))
return store.dispatch(actions.removeAccount('0xe18035bf8712672935fdb4e5e431b1a0183d2dfc', '1'))
.catch(() => {
assert.deepEqual(store.getActions(), expectedActions)
})

View File

@ -635,12 +635,12 @@ function getContract (address) {
}
}
function removeAccount (address) {
function removeAccount (address, network) {
return dispatch => {
dispatch(actions.showLoadingIndication())
return new Promise((resolve, reject) => {
background.removeAccount(address, (err, account) => {
background.removeAccount(address, network, (err, account) => {
dispatch(actions.hideLoadingIndication())
if (err) {
dispatch(actions.displayWarning(err.message))