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

Consolidate connected account alerts #8802

Merged
merged 15 commits into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from 9 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
50 changes: 11 additions & 39 deletions app/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@
"connectedAccountsEmptyDescription": {
"message": "MetaMask is not connected this site. To connect to a Web3 site, find the connect button on their site."
},
"primary": {
"message": "Primary"
},
"lastActive": {
"message": "Last active"
"currentAccountNotConnected": {
"message": "Your current account is not connected"
},
"switchToThisAccount": {
"message": "Switch to this account"
Expand Down Expand Up @@ -139,6 +136,9 @@
"accountSelectionRequired": {
"message": "You need to select an account!"
},
"active": {
"message": "Active"
},
"activity": {
"message": "Activity"
},
Expand Down Expand Up @@ -187,17 +187,11 @@
"alertsSettingsDescription": {
"message": "Enable or disable each alert"
},
"alertSettingsSwitchToConnected": {
"message": "Opening popup with an unconnected account selected"
},
"alertSettingsSwitchToConnectedDescription": {
"message": "This alert is shown when you open the popup with an unconnected account selected."
},
"alertSettingsUnconnectedAccount": {
"message": "Switching to an unconnected account"
},
"alertSettingsUnconnectedAccountDescription": {
"message": "This alert is shown in the popup when you switch from a connected account to an unconnected account."
"alertSettingsUnconnectedAccount": {
"message": "Browsing a website with an unconnected account selected"
},
"alertSettingsUnconnectedAccountDescription": {
"message": "This alert is shown in the popup when you are browsing a connected Web3 site, but the currently selected account is not connected."
},
"allowOriginSpendToken": {
"message": "Allow $1 to spend your $2?",
Expand Down Expand Up @@ -991,9 +985,6 @@
"noAlreadyHaveSeed": {
"message": "No, I already have a seed phrase"
},
"notConnected": {
"message": "Not connected"
},
"protectYourKeys": {
"message": "Protect Your Keys!"
},
Expand Down Expand Up @@ -1475,16 +1466,6 @@
"supportCenter": {
"message": "Visit our Support Center"
},
"switchAccounts": {
"message": "Switch accounts"
},
"switchToConnectedAlertMultipleAccountsDescription": {
"message": "This account is not connected. Switch to a connected account?"
},
"switchToConnectedAlertSingleAccountDescription": {
"message": "This account is not connected. Switch to a connected account ($1)?",
"description": "$1 will be replaced by the name of the connected account"
},
"symbol": {
"message": "Symbol"
},
Expand Down Expand Up @@ -1632,10 +1613,7 @@
"unapproved": {
"message": "Unapproved"
},
"unconnectedAccountAlertDescription": {
"message": "$1 is not connected to $2."
},
"unconnectedAccountAlertDisableTooltip": {
"alertDisableTooltip": {
"message": "This can be changed in \"Settings > Alerts\""
},
"units": {
Expand Down Expand Up @@ -1773,11 +1751,5 @@
"encryptionPublicKeyNotice": {
"message": "$1 would like your public encryption key. By consenting, this site will be able to compose encrypted messages to you.",
"description": "$1 is website or dapp name"
},
"thisSite": {
"message": "this site"
},
"thisAccount": {
"message": "This account"
}
}
19 changes: 9 additions & 10 deletions app/scripts/controllers/alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import ObservableStore from 'obs-store'
*/

export const ALERT_TYPES = {
switchToConnected: 'switchToConnected',
unconnectedAccount: 'unconnectedAccount',
}

Expand All @@ -25,7 +24,7 @@ const defaultState = {
},
{}
),
switchToConnectedAlertShown: {},
unconnectedAccountAlertShownOrigins: {},
}

/**
Expand All @@ -44,7 +43,7 @@ export default class AlertController {
defaultState,
initState,
{
switchToConnectedAlertShown: {},
unconnectedAccountAlertShownOrigins: {},
}
)
this.store = new ObservableStore(state)
Expand All @@ -54,9 +53,9 @@ export default class AlertController {

preferencesStore.subscribe(({ selectedAddress }) => {
const currentState = this.store.getState()
if (currentState.switchToConnectedAlertShown && this.selectedAddress !== selectedAddress) {
if (currentState.unconnectedAccountAlertShownOrigins && this.selectedAddress !== selectedAddress) {
this.selectedAddress = selectedAddress
this.store.updateState({ switchToConnectedAlertShown: {} })
this.store.updateState({ unconnectedAccountAlertShownOrigins: {} })
}
})
}
Expand All @@ -72,10 +71,10 @@ export default class AlertController {
* Sets the "switch to connected" alert as shown for the given origin
* @param {string} origin - The origin the alert has been shown for
*/
setSwitchToConnectedAlertShown (origin) {
let { switchToConnectedAlertShown } = this.store.getState()
switchToConnectedAlertShown = { ...switchToConnectedAlertShown }
switchToConnectedAlertShown[origin] = true
this.store.updateState({ switchToConnectedAlertShown })
setUnconnectedAccountAlertShown (origin) {
let { unconnectedAccountAlertShownOrigins } = this.store.getState()
unconnectedAccountAlertShownOrigins = { ...unconnectedAccountAlertShownOrigins }
unconnectedAccountAlertShownOrigins[origin] = true
this.store.updateState({ unconnectedAccountAlertShownOrigins })
}
}
2 changes: 1 addition & 1 deletion app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ export default class MetamaskController extends EventEmitter {

// alert controller
setAlertEnabledness: nodeify(alertController.setAlertEnabledness, alertController),
setSwitchToConnectedAlertShown: nodeify(this.alertController.setSwitchToConnectedAlertShown, this.alertController),
setUnconnectedAccountAlertShown: nodeify(this.alertController.setUnconnectedAccountAlertShown, this.alertController),

// 3Box
setThreeBoxSyncingPermission: nodeify(threeBoxController.setThreeBoxSyncingPermission, threeBoxController),
Expand Down
3 changes: 0 additions & 3 deletions development/states/confirm-sig-requests.json
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,6 @@
"priceAndTimeEstimatesLastRetrieved": 1541527901281,
"errors": {}
},
"switchToConnected": {
"state": "CLOSED"
},
"unconnectedAccount": {
"state": "CLOSED"
},
Expand Down
3 changes: 0 additions & 3 deletions development/states/currency-localization.json
Original file line number Diff line number Diff line change
Expand Up @@ -473,9 +473,6 @@
"priceAndTimeEstimatesLastRetrieved": 1541527901281,
"errors": {}
},
"switchToConnected": {
"state": "CLOSED"
},
"unconnectedAccount": {
"state": "CLOSED"
},
Expand Down
3 changes: 0 additions & 3 deletions development/states/tx-list-items.json
Original file line number Diff line number Diff line change
Expand Up @@ -1295,9 +1295,6 @@
"errors": {}
},
"confirmTransaction": {},
"switchToConnected": {
"state": "CLOSED"
},
"unconnectedAccount": {
"state": "CLOSED"
}
Expand Down
7 changes: 0 additions & 7 deletions ui/app/components/app/alerts/alerts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,15 @@ import React from 'react'
import { useSelector } from 'react-redux'

import UnconnectedAccountAlert from './unconnected-account-alert'
import SwitchToConnectedAlert from './switch-to-connected-alert'
import { alertIsOpen as unconnectedAccountAlertIsOpen } from '../../../ducks/alerts/unconnected-account'
import { alertIsOpen as switchToConnectedAlertIsOpen } from '../../../ducks/alerts/switch-to-connected'

const Alerts = () => {
const _unconnectedAccountAlertIsOpen = useSelector(unconnectedAccountAlertIsOpen)
const _switchToConnectedAlertIsOpen = useSelector(switchToConnectedAlertIsOpen)

if (_unconnectedAccountAlertIsOpen) {
return (
<UnconnectedAccountAlert />
)
} else if (_switchToConnectedAlertIsOpen) {
return (
<SwitchToConnectedAlert />
)
}

return null
Expand Down
2 changes: 0 additions & 2 deletions ui/app/components/app/alerts/alerts.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
@import './unconnected-account-alert/unconnected-account-alert';

@import './switch-to-connected-alert/switch-to-connected-alert';

This file was deleted.

This file was deleted.

Loading