From 1f49772ca316f69f77101c7d42807133fea05b62 Mon Sep 17 00:00:00 2001 From: Erik Marks <25517051+rekmarks@users.noreply.github.com> Date: Thu, 16 Apr 2020 14:34:40 -0700 Subject: [PATCH] Create new tabs instead of windows in most cases (#8347) * openExtensionInBrowser: create tab, not window * open tabs instead of windows in most cases --- app/scripts/metamask-controller.js | 2 +- app/scripts/platforms/extension.js | 14 +++++++++++++- .../account-details-dropdown.container.js | 2 +- .../app/dropdowns/token-menu-dropdown.js | 2 +- .../account-details-modal.component.js | 2 +- .../app/modals/tests/account-details-modal.test.js | 6 +++--- .../permissions-connect-footer.component.js | 2 +- .../shift-list-item/shift-list-item.component.js | 2 +- .../signature-request-original.component.js | 2 +- .../transaction-activity-log.component.js | 2 +- .../transaction-list-item-details.component.js | 2 +- .../connect-hardware/connect-screen.js | 2 +- .../pages/create-account/import-account/index.js | 2 +- ui/app/store/actions.js | 2 +- 14 files changed, 28 insertions(+), 16 deletions(-) diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 5f01893d2..63f9039ed 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -1894,7 +1894,7 @@ export default class MetamaskController extends EventEmitter { const network = this.networkController.getNetworkState() const url = getBuyEthUrl({ network, address, amount }) if (url) { - this.platform.openWindow({ url }) + this.platform.openTab({ url }) } } diff --git a/app/scripts/platforms/extension.js b/app/scripts/platforms/extension.js index 77ed4e451..5f0e308d8 100644 --- a/app/scripts/platforms/extension.js +++ b/app/scripts/platforms/extension.js @@ -12,6 +12,18 @@ class ExtensionPlatform { extension.runtime.reload() } + openTab (options) { + return new Promise((resolve, reject) => { + extension.tabs.create(options, (newTab) => { + const error = checkForError() + if (error) { + return reject(error) + } + return resolve(newTab) + }) + }) + } + openWindow (options) { return new Promise((resolve, reject) => { extension.windows.create(options, (newWindow) => { @@ -68,7 +80,7 @@ class ExtensionPlatform { if (route) { extensionURL += `#${route}` } - this.openWindow({ url: extensionURL }) + this.openTab({ url: extensionURL }) if (getEnvironmentType() !== ENVIRONMENT_TYPE_BACKGROUND) { window.close() } diff --git a/ui/app/components/app/dropdowns/account-details-dropdown/account-details-dropdown.container.js b/ui/app/components/app/dropdowns/account-details-dropdown/account-details-dropdown.container.js index 5bde03da6..6353d1afe 100644 --- a/ui/app/components/app/dropdowns/account-details-dropdown/account-details-dropdown.container.js +++ b/ui/app/components/app/dropdowns/account-details-dropdown/account-details-dropdown.container.js @@ -21,7 +21,7 @@ function mapDispatchToProps (dispatch) { dispatch(actions.showModal({ name: 'ACCOUNT_DETAILS' })) }, viewOnEtherscan: (address, network, rpcPrefs) => { - global.platform.openWindow({ url: genAccountLink(address, network, rpcPrefs) }) + global.platform.openTab({ url: genAccountLink(address, network, rpcPrefs) }) }, showRemoveAccountConfirmationModal: (identity) => { return dispatch(actions.showModal({ name: 'CONFIRM_REMOVE_ACCOUNT', identity })) diff --git a/ui/app/components/app/dropdowns/token-menu-dropdown.js b/ui/app/components/app/dropdowns/token-menu-dropdown.js index f988f8cb9..08da49f82 100644 --- a/ui/app/components/app/dropdowns/token-menu-dropdown.js +++ b/ui/app/components/app/dropdowns/token-menu-dropdown.js @@ -40,7 +40,7 @@ class TokenMenuDropdown extends Component { onClick={(e) => { e.stopPropagation() const url = genAccountLink(this.props.token.address, this.props.network) - global.platform.openWindow({ url }) + global.platform.openTab({ url }) this.props.onClose() }} text={this.context.t('viewOnEtherscan')} diff --git a/ui/app/components/app/modals/account-details-modal/account-details-modal.component.js b/ui/app/components/app/modals/account-details-modal/account-details-modal.component.js index 1c46d792b..fafdd8444 100644 --- a/ui/app/components/app/modals/account-details-modal/account-details-modal.component.js +++ b/ui/app/components/app/modals/account-details-modal/account-details-modal.component.js @@ -62,7 +62,7 @@ export default class AccountDetailsModal extends Component { type="secondary" className="account-modal__button" onClick={() => { - global.platform.openWindow({ url: genAccountLink(address, network, rpcPrefs) }) + global.platform.openTab({ url: genAccountLink(address, network, rpcPrefs) }) }} > {rpcPrefs.blockExplorerUrl diff --git a/ui/app/components/app/modals/tests/account-details-modal.test.js b/ui/app/components/app/modals/tests/account-details-modal.test.js index 2b29102de..f8e76d95c 100644 --- a/ui/app/components/app/modals/tests/account-details-modal.test.js +++ b/ui/app/components/app/modals/tests/account-details-modal.test.js @@ -7,7 +7,7 @@ import AccountDetailsModal from '../account-details-modal' describe('Account Details Modal', function () { let wrapper - global.platform = { openWindow: sinon.spy() } + global.platform = { openTab: sinon.spy() } const props = { hideModal: sinon.spy(), @@ -53,12 +53,12 @@ describe('Account Details Modal', function () { assert.equal(props.setAccountLabel.getCall(0).args[1], 'New Label') }) - it('opens new window when view block explorer is clicked', function () { + it('opens new tab when view block explorer is clicked', function () { const modalButton = wrapper.find('.account-modal__button') const etherscanLink = modalButton.first() etherscanLink.simulate('click') - assert(global.platform.openWindow.calledOnce) + assert(global.platform.openTab.calledOnce) }) it('shows export private key modal when clicked', function () { diff --git a/ui/app/components/app/permissions-connect-footer/permissions-connect-footer.component.js b/ui/app/components/app/permissions-connect-footer/permissions-connect-footer.component.js index 825e77f5d..7bc2a8afd 100644 --- a/ui/app/components/app/permissions-connect-footer/permissions-connect-footer.component.js +++ b/ui/app/components/app/permissions-connect-footer/permissions-connect-footer.component.js @@ -15,7 +15,7 @@ export default class PermissionsConnectFooter extends Component {
{ - global.platform.openWindow({ url: 'https://medium.com/metamask/privacy-mode-is-now-enabled-by-default-1c1c957f4d57' }) + global.platform.openTab({ url: 'https://medium.com/metamask/privacy-mode-is-now-enabled-by-default-1c1c957f4d57' }) }} >{ t('learnMore') }
diff --git a/ui/app/components/app/shift-list-item/shift-list-item.component.js b/ui/app/components/app/shift-list-item/shift-list-item.component.js index 56c9ecd1f..bc360d237 100644 --- a/ui/app/components/app/shift-list-item/shift-list-item.component.js +++ b/ui/app/components/app/shift-list-item/shift-list-item.component.js @@ -146,7 +146,7 @@ export default class ShiftListItem extends Component { width: '200px', overflow: 'hidden', }} - onClick={() => global.platform.openWindow({ url })} + onClick={() => global.platform.openTab({ url })} >
{ - global.platform.openWindow({ + global.platform.openTab({ url: 'https://metamask.zendesk.com/hc/en-us/articles/360015488751', }) }} diff --git a/ui/app/components/app/transaction-activity-log/transaction-activity-log.component.js b/ui/app/components/app/transaction-activity-log/transaction-activity-log.component.js index 24b057b64..d23d0fc71 100644 --- a/ui/app/components/app/transaction-activity-log/transaction-activity-log.component.js +++ b/ui/app/components/app/transaction-activity-log/transaction-activity-log.component.js @@ -33,7 +33,7 @@ export default class TransactionActivityLog extends PureComponent { const prefix = prefixForNetwork(metamaskNetworkId) const etherscanUrl = `https://${prefix}etherscan.io/tx/${hash}` - global.platform.openWindow({ url: etherscanUrl }) + global.platform.openTab({ url: etherscanUrl }) } renderInlineRetry (index, activity) { diff --git a/ui/app/components/app/transaction-list-item-details/transaction-list-item-details.component.js b/ui/app/components/app/transaction-list-item-details/transaction-list-item-details.component.js index 5aeb6e5cc..09c560d1a 100644 --- a/ui/app/components/app/transaction-list-item-details/transaction-list-item-details.component.js +++ b/ui/app/components/app/transaction-list-item-details/transaction-list-item-details.component.js @@ -56,7 +56,7 @@ export default class TransactionListItemDetails extends PureComponent { }, }) - global.platform.openWindow({ url: getBlockExplorerUrlForTx(metamaskNetworkId, hash, rpcPrefs) }) + global.platform.openTab({ url: getBlockExplorerUrlForTx(metamaskNetworkId, hash, rpcPrefs) }) } handleCancel = (event) => { diff --git a/ui/app/pages/create-account/connect-hardware/connect-screen.js b/ui/app/pages/create-account/connect-hardware/connect-screen.js index 3464c43eb..24c6a3e84 100644 --- a/ui/app/pages/create-account/connect-hardware/connect-screen.js +++ b/ui/app/pages/create-account/connect-hardware/connect-screen.js @@ -88,7 +88,7 @@ class ConnectScreen extends Component {