-
Notifications
You must be signed in to change notification settings - Fork 49
Refactor/mvpn 267 enable tslint #8
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
Merged
Merged
Changes from 11 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
b290c45
Enable TsLint and refactor code
mipo47 fd4206f
Enable Prettier and reformat code
mipo47 93b9430
Don't forget about eslint rules
mipo47 f420d40
Throw away eslint and prettier, restyle code
mipo47 23f77e0
PR fixes
mipo47 6728bfc
PR fixes 2
mipo47 099fd25
fix file names
mipo47 78ce61b
change interfaces to types for component input definition
mipo47 987af30
Add return types and TODOs
mipo47 099ddea
final PR fixes
mipo47 efd8d34
.jest is not used in this PR
mipo47 896ff98
refactor after Donatas PR review
mipo47 58f2e91
change null to undefined
mipo47 4d9d37d
throw away fetcher cache
mipo47 0709f5a
do not export fetcher props
mipo47 6535ba9
Add tslint-eslint-rules
donce db6d492
Add object-curly-spaces rule, unify spacing in code
donce a2e5f38
Merge pull request #14 from mysteriumnetwork/refactor/MVPN-267-tslint…
donce 7f2f52f
Remove empty return jsdocs
donce bb21597
show error for unused import
mipo47 797b722
refactor favorite updating
mipo47 d7ef949
PR fixes after Ignas review
mipo47 affc3fc
simplify tslint config
mipo47 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
This file contains hidden or 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 |
---|---|---|
|
@@ -17,36 +17,81 @@ | |
|
||
import React from 'react' | ||
|
||
import TequilapiClientFactory, { | ||
IdentityDTO, | ||
} from 'mysterium-tequilapi' | ||
import {ConnectionStatusEnum} from "../libraries/tequilapi/enums"; | ||
import TequilapiClientFactory, { IdentityDTO } from 'mysterium-tequilapi' | ||
import { ConnectionStatusEnum } from '../libraries/tequilapi/enums' | ||
|
||
import {CONFIG} from '../config' | ||
import {store} from "../store/tequilapi-store"; | ||
import {ProposalsFetcher} from "../fetchers/proposals-fetcher"; | ||
import {StatusFetcher} from "../fetchers/status-fetcher"; | ||
import {IPFetcher} from "../fetchers/ip-fetcher"; | ||
import {StatsFetcher} from "../fetchers/stats-fetcher"; | ||
import { CONFIG } from '../config' | ||
import { IPFetcher } from '../fetchers/ip-fetcher' | ||
import { ProposalsFetcher } from '../fetchers/proposals-fetcher' | ||
import { StatsFetcher } from '../fetchers/stats-fetcher' | ||
import { StatusFetcher } from '../fetchers/status-fetcher' | ||
import { store } from '../store/app-store' | ||
|
||
const IP_UPDATING = CONFIG.TEXTS.IP_UPDATING | ||
const api = new TequilapiClientFactory(CONFIG.TEQUILAPI_ADDRESS, CONFIG.TEQUILAPI_TIMEOUT).build() | ||
const api = new TequilapiClientFactory( | ||
CONFIG.TEQUILAPI_ADDRESS, | ||
CONFIG.TEQUILAPI_TIMEOUT, | ||
).build() | ||
|
||
/*** | ||
* API operations level | ||
*/ | ||
export default class AppTequilapi extends React.Component { | ||
proposalFetcher = new ProposalsFetcher(api) | ||
statusFetcher = new StatusFetcher(api) | ||
ipFetcher = new IPFetcher(api) | ||
statsFetcher = new StatsFetcher(api) | ||
protected proposalFetcher = new ProposalsFetcher(api) | ||
protected statusFetcher = new StatusFetcher(api) | ||
protected ipFetcher = new IPFetcher(api) | ||
protected statsFetcher = new StatsFetcher(api) | ||
|
||
/*** | ||
* Tries to connect to selected VPN server | ||
* @returns {Promise<void>} | ||
*/ | ||
public async connect(): Promise<void> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be protected. |
||
if (!store.IdentityId || !store.SelectedProviderId) { | ||
console.error('Not enough data to connect', store) | ||
return | ||
} | ||
store.IP = IP_UPDATING | ||
store.ConnectionStatus = { | ||
sessionId: '', | ||
status: ConnectionStatusEnum.CONNECTING, | ||
} | ||
try { | ||
const connection = await api.connectionCreate({ | ||
consumerId: store.IdentityId, | ||
providerCountry: '', | ||
providerId: store.SelectedProviderId, | ||
}) | ||
console.log('connected', connection) | ||
} catch (e) { | ||
console.warn('api.connectionCreate failed', e) | ||
} | ||
} | ||
|
||
/*** | ||
* Tries to disconnect from VPN server | ||
* @returns {Promise<void>} | ||
mipo47 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
public async disconnect(): Promise<void> { | ||
store.IP = IP_UPDATING | ||
store.ConnectionStatus = { | ||
sessionId: '', | ||
status: ConnectionStatusEnum.DISCONNECTING, | ||
} | ||
try { | ||
await api.connectionCancel() | ||
console.log('disconnected') | ||
} catch (e) { | ||
console.warn('api.connectionCancel failed', e) | ||
} | ||
} | ||
|
||
/*** | ||
* Tries to login to API, must be completed once before connect | ||
* @returns {Promise<void>} | ||
mipo47 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
async unlock (): Promise<void> { | ||
let identities: Array<IdentityDTO> | ||
protected async unlock(): Promise<void> { | ||
let identities: IdentityDTO[] | ||
try { | ||
identities = await api.identitiesList() | ||
} catch (e) { | ||
|
@@ -59,7 +104,9 @@ export default class AppTequilapi extends React.Component { | |
if (identities.length) { | ||
identityId = identities[0].id | ||
} else { | ||
const newIdentity: IdentityDTO = await api.identityCreate(CONFIG.PASSPHRASE) | ||
const newIdentity: IdentityDTO = await api.identityCreate( | ||
CONFIG.PASSPHRASE, | ||
) | ||
identityId = newIdentity.id | ||
} | ||
} catch (e) { | ||
|
@@ -74,41 +121,4 @@ export default class AppTequilapi extends React.Component { | |
console.warn('api.identityUnlock failed', e) | ||
} | ||
} | ||
|
||
/*** | ||
* Tries to connect to selected VPN server | ||
* @returns {Promise<void>} | ||
*/ | ||
async connect (): Promise<void> { | ||
if (!store.IdentityId || !store.SelectedProviderId) { | ||
console.error('Not enough data to connect', store) | ||
return | ||
} | ||
store.IP = IP_UPDATING | ||
store.ConnectionStatus = { sessionId: '', status: ConnectionStatusEnum.CONNECTING } | ||
try { | ||
const connection = await api.connectionCreate({ | ||
consumerId: store.IdentityId, | ||
providerId: store.SelectedProviderId | ||
}) | ||
console.log('connect', connection) | ||
} catch (e) { | ||
console.warn('api.connectionCreate failed', e) | ||
} | ||
} | ||
|
||
/*** | ||
* Tries to disconnect from VPN server | ||
* @returns {Promise<void>} | ||
*/ | ||
async disconnect (): Promise<void> { | ||
store.IP = IP_UPDATING | ||
store.ConnectionStatus = { sessionId: '', status: ConnectionStatusEnum.DISCONNECTING } | ||
try { | ||
await api.connectionCancel() | ||
console.log('disconnect') | ||
} catch (e) { | ||
console.warn('api.connectionCancel failed', e) | ||
} | ||
} | ||
} |
This file contains hidden or 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 |
---|---|---|
|
@@ -15,32 +15,52 @@ | |
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import React from 'react' | ||
import { Text, View, Button } from 'react-native' | ||
import { observer } from 'mobx-react/native' | ||
import React, {ReactNode} from 'react' | ||
import { Button, Text, View } from 'react-native' | ||
import { CONFIG } from '../config' | ||
import { logger } from '../libraries/logger' | ||
import MysteriumClient from '../libraries/mysterium-client' | ||
import { store } from '../store/app-store' | ||
import styles from './app-styles' | ||
import {CONFIG} from '../config' | ||
import Stats from './stats' | ||
import AppTequilapi from './app-tequilapi' | ||
import Proposals from './proposals' | ||
import MysteriumClient from '../libraries/mysterium-client' | ||
import {store} from "../store/tequilapi-store"; | ||
import {observer} from "mobx-react/native"; | ||
import Stats from './stats' | ||
|
||
logger.showDebugMessages() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this side-effect is a surprise |
||
|
||
@observer | ||
export default class App extends AppTequilapi { | ||
constructor (props: any) { | ||
super(props) | ||
|
||
// Bind local functions | ||
this.connectDisconnect = this.connectDisconnect.bind(this) | ||
public render(): ReactNode { | ||
return ( | ||
// @ts-ignore TODO remove ignore or transform | ||
<View style={styles.container} transform={[{ scaleX: 2 }, { scaleY: 2 }]}> | ||
<Text> | ||
{store.ConnectionStatus | ||
? store.ConnectionStatus.status | ||
: CONFIG.TEXTS.UNKNOWN_STATUS} | ||
</Text> | ||
<Text>IP: {store.IP}</Text> | ||
<Proposals | ||
proposalsFetcher={this.proposalFetcher} | ||
proposalsStore={store} | ||
/> | ||
<Button | ||
title={this.buttonText} | ||
disabled={!this.buttonEnabled} | ||
onPress={() => this.connectDisconnect()} | ||
/> | ||
{store.Statistics ? <Stats {...store.Statistics} /> : null} | ||
</View> | ||
) | ||
} | ||
|
||
/*** | ||
* Refreshes connection state, ip and unlocks identity. | ||
* Starts periodic state refreshing | ||
* Called once after first rendering. | ||
*/ | ||
async componentDidMount () { | ||
public async componentDidMount() { | ||
await this.unlock() | ||
|
||
// TODO: remove it later, serviceStatus is used only for native call test | ||
|
@@ -49,12 +69,26 @@ export default class App extends AppTequilapi { | |
console.log('serviceStatus', serviceStatus) | ||
} | ||
|
||
private get buttonEnabled(): boolean { | ||
return store.isReady | ||
} | ||
|
||
private get buttonText(): string { | ||
const isReady = store.isReady | ||
const isConnected = store.isConnected | ||
return isReady | ||
? isConnected | ||
? 'disconnect' | ||
: 'connect' | ||
: CONFIG.TEXTS.UNKNOWN_STATUS | ||
} | ||
|
||
/*** | ||
* Connects or disconnects to VPN server, depends on current connection state. | ||
* Is connection state is unknown - does nothing | ||
mipo47 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @returns {Promise<void>} | ||
*/ | ||
async connectDisconnect () { | ||
private async connectDisconnect() { | ||
mipo47 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (!store.isReady) { | ||
return | ||
} | ||
|
@@ -65,21 +99,4 @@ export default class App extends AppTequilapi { | |
await this.connect() | ||
} | ||
} | ||
|
||
render () { | ||
const isReady = store.isReady | ||
const isConnected = store.isConnected | ||
const connectText = isReady | ||
? (isConnected ? 'disconnect' : 'connect') | ||
: CONFIG.TEXTS.UNKNOWN_STATUS | ||
return ( | ||
<View style={styles.container} transform={[{ scaleX: 2 }, { scaleY: 2 }]}> | ||
<Text>{store.ConnectionStatus ? store.ConnectionStatus.status : CONFIG.TEXTS.UNKNOWN}</Text> | ||
<Text>IP: {store.IP}</Text> | ||
<Proposals proposalsFetcher={this.proposalFetcher} proposalsStore={store} /> | ||
<Button title={connectText} onPress={this.connectDisconnect} disabled={!isReady}/> | ||
{ store.Statistics ? <Stats {...store.Statistics} /> : null } | ||
</View> | ||
) | ||
} | ||
} |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private