-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Connect connected-status-indicator to state so that it correctly disp…
…lays status
- Loading branch information
Showing
3 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
ui/app/components/app/connected-status-indicator/connected-status-indicator.container.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { connect } from 'react-redux' | ||
import ConnectedStatusIndicator from './connected-status-indicator.component' | ||
import { | ||
STATUS_CONNECTED, | ||
STATUS_CONNECTED_TO_ANOTHER_ACCOUNT, | ||
STATUS_NOT_CONNECTED, | ||
} from '../../../helpers/constants/connected-sites' | ||
import { | ||
getAddressConnectedDomainMap, | ||
getOriginOfCurrentTab, | ||
getSelectedAddress, | ||
} from '../../../selectors/selectors' | ||
|
||
|
||
const mapStateToProps = (state) => { | ||
const selectedAddress = getSelectedAddress(state) | ||
const addressConnectedDomainMap = getAddressConnectedDomainMap(state) | ||
const originOfCurrentTab = getOriginOfCurrentTab(state) | ||
|
||
const selectedAddressDomainMap = addressConnectedDomainMap[selectedAddress] | ||
const currentTabIsConnectedToSelectedAddress = selectedAddressDomainMap && selectedAddressDomainMap[originOfCurrentTab] | ||
|
||
const allConnectedDomains = Object.values(addressConnectedDomainMap).reduce((acc, val) => { | ||
return { ...acc, ...val } | ||
}, {}) | ||
const currentTabIsConnectToSomeOtherAddress = !currentTabIsConnectedToSelectedAddress && allConnectedDomains[originOfCurrentTab] | ||
|
||
let status | ||
if (currentTabIsConnectedToSelectedAddress) { | ||
status = STATUS_CONNECTED | ||
} else if (currentTabIsConnectToSomeOtherAddress) { | ||
status = STATUS_CONNECTED_TO_ANOTHER_ACCOUNT | ||
} else { | ||
status = STATUS_NOT_CONNECTED | ||
} | ||
|
||
return { | ||
status, | ||
} | ||
} | ||
|
||
export default connect(mapStateToProps)(ConnectedStatusIndicator) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export { default } from './connected-status-indicator.component' | ||
export { default } from './connected-status-indicator.container' |