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 account menu entry for imported accounts #8747

Merged
merged 1 commit into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 10 additions & 4 deletions test/e2e/from-import-ui.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const webdriver = require('selenium-webdriver')

const { By, Key, until } = webdriver
const {
tinyDelayMs,
regularDelayMs,
largeDelayMs,
} = require('./helpers')
Expand Down Expand Up @@ -278,7 +277,7 @@ describe('Using MetaMask with an existing account', function () {
await driver.delay(regularDelayMs)
})

it('should open the remove account modal', async function () {
it('should see new account in account menu', async function () {
const accountName = await driver.findElement(By.css('.selected-account__name'))
assert.equal(await accountName.getText(), 'Account 5')
await driver.delay(regularDelayMs)
Expand All @@ -289,8 +288,13 @@ describe('Using MetaMask with an existing account', function () {
const accountListItems = await driver.findElements(By.css('.account-menu__account'))
assert.equal(accountListItems.length, 5)

await driver.clickElement(By.css('.account-menu__account:last-of-type > .remove-account-icon'))
await driver.delay(tinyDelayMs)
await driver.clickPoint(By.css('.account-menu__icon'), 0, 0)
})

it('should open the remove account modal', async function () {
await driver.clickElement(By.css('[data-testid="account-options-menu-button"]'))

await driver.clickElement(By.css('[data-testid="account-options-menu__remove-account"]'))

await driver.findElement(By.css('.confirm-remove-account__account'))
})
Expand All @@ -304,6 +308,8 @@ describe('Using MetaMask with an existing account', function () {
assert.equal(await accountName.getText(), 'Account 1')
await driver.delay(regularDelayMs)

await driver.clickElement(By.css('.account-menu__icon'))

const accountListItems = await driver.findElements(By.css('.account-menu__account'))
assert.equal(accountListItems.length, 4)
})
Expand Down
37 changes: 1 addition & 36 deletions ui/app/components/app/account-menu/account-menu.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import InputAdornment from '@material-ui/core/InputAdornment'
import { Menu, Item, Divider, CloseArea } from '../dropdowns/components/menu'
import { ENVIRONMENT_TYPE_POPUP } from '../../../../../app/scripts/lib/enums'
import { getEnvironmentType } from '../../../../../app/scripts/lib/util'
import Tooltip from '../../ui/tooltip'
import Identicon from '../../ui/identicon'
import IconWithFallBack from '../../ui/icon-with-fallback'
import UserPreferencedCurrencyDisplay from '../user-preferenced-currency-display'
Expand Down Expand Up @@ -38,7 +37,6 @@ export default class AccountMenu extends Component {
lockMetamask: PropTypes.func,
selectedAddress: PropTypes.string,
showAccountDetail: PropTypes.func,
showRemoveAccountConfirmationModal: PropTypes.func,
toggleAccountMenu: PropTypes.func,
addressConnectedDomainMap: PropTypes.object,
originOfCurrentTab: PropTypes.string,
Expand Down Expand Up @@ -176,6 +174,7 @@ export default class AccountMenu extends Component {
type={PRIMARY}
/>
</div>
{ this.renderKeyringType(keyring) }
{ iconAndNameForOpenDomain
? (
<div className="account-menu__icon-list">
Expand All @@ -184,45 +183,11 @@ export default class AccountMenu extends Component {
)
: null
}
{ this.renderKeyringType(keyring) }
{ this.renderRemoveAccount(keyring, identity) }
</div>
)
})
}

renderRemoveAccount (keyring, identity) {
const { t } = this.context

// Sometimes keyrings aren't loaded yet
if (!keyring) {
return null
}

// Any account that's not from the HD wallet Keyring can be removed
const { type } = keyring
const isRemovable = type !== 'HD Key Tree'

return isRemovable && (
<Tooltip
title={t('removeAccount')}
position="bottom"
>
<a
className="remove-account-icon"
onClick={(e) => this.removeAccount(e, identity)}
/>
</Tooltip>
)
}

removeAccount (e, identity) {
e.preventDefault()
e.stopPropagation()
const { showRemoveAccountConfirmationModal } = this.props
showRemoveAccountConfirmationModal(identity)
}

renderKeyringType (keyring) {
const { t } = this.context

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
hideSidebar,
lockMetamask,
hideWarning,
showModal,
} from '../../../store/actions'
import {
getAddressConnectedDomainMap,
Expand Down Expand Up @@ -54,9 +53,6 @@ function mapDispatchToProps (dispatch) {
dispatch(hideSidebar())
dispatch(toggleAccountMenu())
},
showRemoveAccountConfirmationModal: (identity) => {
return dispatch(showModal({ name: 'CONFIRM_REMOVE_ACCOUNT', identity }))
},
}
}

Expand Down
1 change: 1 addition & 0 deletions ui/app/components/app/account-menu/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@

.keyring-label {
margin-top: 5px;
margin-right: 10px;
background-color: $dusty-gray;
color: $black;
font-weight: normal;
Expand Down
13 changes: 0 additions & 13 deletions ui/app/components/app/account-menu/tests/account-menu.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,6 @@ describe('Account Menu', function () {
const importedAccount = wrapper.find('.keyring-label.allcaps')
assert.equal(importedAccount.text(), 'imported')
})

it('remove account', function () {
const removeAccount = wrapper.find('.remove-account-icon')
removeAccount.simulate('click', {
preventDefault: () => {},
stopPropagation: () => {},
})

assert(props.showRemoveAccountConfirmationModal.calledOnce)
assert.deepEqual(props.showRemoveAccountConfirmationModal.getCall(0).args[0],
{ address: '0xImportedAddress', balance: '0x0', name: 'Imported Account 1' }
)
})
})

describe('Log Out', function () {
Expand Down
1 change: 1 addition & 0 deletions ui/app/components/app/menu-bar/account-options-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export default function AccountOptionsMenu ({ anchorElement, onClose }) {
isRemovable
? (
<MenuItem
data-testid="account-options-menu__remove-account"
onClick={() => {
dispatch(showModal({ name: 'CONFIRM_REMOVE_ACCOUNT', identity: selectedIdentity }))
onClose()
Expand Down