diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2017-12-13 15:33:20 +0100 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2017-12-19 14:12:42 +0100 |
| commit | b02baf60e26a2e5794dc145e72047b1005f0c2d3 (patch) | |
| tree | af41ec8e77d214f0e832000b6d88c573c3ce1885 /app/components | |
| parent | e35c46c9e0d4fcd8b146be523550e2a88ff1aecf (diff) | |
| download | mullvadvpn-b02baf60e26a2e5794dc145e72047b1005f0c2d3.tar.xz mullvadvpn-b02baf60e26a2e5794dc145e72047b1005f0c2d3.zip | |
Drop hardcoded servers in favor of relay locations
Diffstat (limited to 'app/components')
| -rw-r--r-- | app/components/Connect.js | 56 |
1 files changed, 27 insertions, 29 deletions
diff --git a/app/components/Connect.js b/app/components/Connect.js index 0975e18a1a..5267f3e190 100644 --- a/app/components/Connect.js +++ b/app/components/Connect.js @@ -7,7 +7,6 @@ import { Layout, Container, Header } from './Layout'; import { BackendError } from '../lib/backend'; import ExternalLinkSVG from '../assets/images/icon-extLink.svg'; -import type { ServerInfo } from '../lib/backend'; import type { HeaderBarStyle } from './HeaderBar'; import type { ConnectionReduxState } from '../redux/connection/reducers'; import type { SettingsReduxState } from '../redux/settings/reducers'; @@ -23,7 +22,6 @@ export type ConnectProps = { onCopyIP: () => void, onDisconnect: () => void, onExternalLink: (type: string) => void, - getServerInfo: (relayLocation: RelayLocation) => ?ServerInfo }; @@ -94,45 +92,45 @@ export default class Connect extends Component { ); } - _getServerInfo(): ServerInfo { + _findRelayName(relay: RelayLocation): ?string { + const { countries } = this.props.settings.relayLocations; + const countryPredicate = (countryCode) => (country) => country.code === countryCode; + + if(relay.country) { + const country = countries.find(countryPredicate(relay.country)); + if(country) { + return country.name; + } + } else if(relay.city) { + const [countryCode, cityCode] = relay.city; + const country = countries.find(countryPredicate(countryCode)); + if(country) { + const city = country.cities.find((city) => city.code === cityCode); + if(city) { + return city.name; + } + } + } + return null; + } + + _getLocationName(): string { const { relaySettings } = this.props.settings; if(relaySettings.normal) { const location = relaySettings.normal.location; if(location === 'any') { - return { - address: '', - name: 'Automatic', - country: 'Automatic', - city: 'Automatic', - country_code: 'any', - city_code: 'any', - location: [0, 0], - }; + return 'Automatic'; } else { - const serverInfo = this.props.getServerInfo(location); - if(!serverInfo) { - throw new Error('Server info is not available for: ' + JSON.stringify(location)); - } - return serverInfo; + return this._findRelayName(location) || 'Unknown'; } } else if(relaySettings.custom_tunnel_endpoint) { - return { - address: relaySettings.custom_tunnel_endpoint.host, - name: 'Custom', - country: 'Custom', - city: '', - country_code: 'auto', - city_code: 'auto', - location: [0, 0], - }; + return 'Custom'; } else { throw new Error('Unsupported relay settings.'); } } renderMap(): React.Element<*> { - const serverInfo = this._getServerInfo(); - let [ isConnecting, isConnected, isDisconnected ] = [false, false, false]; switch(this.props.connection.status) { case 'connecting': isConnecting = true; break; @@ -246,7 +244,7 @@ export default class Connect extends Component { <div className="connect__server-label">Connect to</div> <div className="connect__server-value"> - <div className="connect__server-name">{ serverInfo.name }</div> + <div className="connect__server-name">{ this._getLocationName() }</div> </div> </div> |
