mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-09 15:11:10 +00:00
Improved code quality (#154)
* Removed package-lock.json form gitignore as it ensures specific package versions * Updated all @angular web dependencies * Resolved tslint errors using autofix option * Resolved some more tslint issues * Added lint scripts to package.json to easy lint the ts files * Updated codelyzer and tslint * Run web on travis using node 10 and run the lint task * Resolved some more tslint issues after upgrading tslint and codelyzer * Resolved golint issues with regards to exchange comments * Resolved spelling errors shown by goreportcard.com * Resolved gofmt warnings using goreportcard.com * Resolved golint issue by removing unrequired else statement * Refactored slack.go to reduce cyclomatic complexity * Fixed govet issue where Slack was passed as value instead of reference
This commit is contained in:
committed by
Adrian Gallagher
parent
a5f51328d4
commit
0f209165d5
@@ -21,7 +21,7 @@ export class SidebarService {
|
||||
*/
|
||||
public open(): Promise<MatDrawerToggleResult> {
|
||||
this.sidenav.open();
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -46,4 +46,4 @@ export class SidebarService {
|
||||
this.sidenav.toggle(isOpen);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {inject, TestBed} from '@angular/core/testing';
|
||||
import {HttpModule} from '@angular/http';
|
||||
import {StyleManagerComponent} from './style-manager.component';
|
||||
|
||||
|
||||
|
||||
describe('StyleManager', () => {
|
||||
let styleManager: StyleManagerComponent;
|
||||
@@ -16,8 +16,8 @@ describe('StyleManager', () => {
|
||||
}));
|
||||
|
||||
afterEach(() => {
|
||||
let links = document.head.querySelectorAll('link');
|
||||
for (let link of Array.prototype.slice.call(links)) {
|
||||
const links = document.head.querySelectorAll('link');
|
||||
for (const link of Array.prototype.slice.call(links)) {
|
||||
if (link.className.includes('style-manager-')) {
|
||||
document.head.removeChild(link);
|
||||
}
|
||||
@@ -26,14 +26,14 @@ describe('StyleManager', () => {
|
||||
|
||||
it('should add stylesheet to head', () => {
|
||||
styleManager.setStyle('test', 'test.css');
|
||||
let styleEl = document.head.querySelector('.style-manager-test') as HTMLLinkElement;
|
||||
const styleEl = document.head.querySelector('.style-manager-test') as HTMLLinkElement;
|
||||
expect(styleEl).not.toBeNull();
|
||||
expect(styleEl.href.endsWith('test.css')).toBe(true);
|
||||
});
|
||||
|
||||
it('should change existing stylesheet', () => {
|
||||
styleManager.setStyle('test', 'test.css');
|
||||
let styleEl = document.head.querySelector('.style-manager-test') as HTMLLinkElement;
|
||||
const styleEl = document.head.querySelector('.style-manager-test') as HTMLLinkElement;
|
||||
expect(styleEl).not.toBeNull();
|
||||
expect(styleEl.href.endsWith('test.css')).toBe(true);
|
||||
|
||||
@@ -51,4 +51,4 @@ describe('StyleManager', () => {
|
||||
styleEl = document.head.querySelector('.style-manager-test') as HTMLLinkElement;
|
||||
expect(styleEl).toBeNull();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,7 +2,7 @@ import {Injectable} from '@angular/core';
|
||||
/**
|
||||
* Class for managing stylesheets. Stylesheets are loaded into named slots so that they can be
|
||||
* removed or changed later.
|
||||
*/
|
||||
*/
|
||||
@Injectable()
|
||||
export class StyleManagerService {
|
||||
/**
|
||||
@@ -41,4 +41,4 @@ function createLinkElementWithKey(key: string) {
|
||||
|
||||
function getClassNameForKey(key: string) {
|
||||
return `style-manager-${key}`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,4 +49,4 @@ describe('ThemeStorage Service', () => {
|
||||
expect(service.onThemeUpdate.emit).toHaveBeenCalled();
|
||||
expect(service.onThemeUpdate.emit).toHaveBeenCalledWith(secondTestTheme);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -36,4 +36,4 @@ export class ThemeStorageService {
|
||||
window.localStorage.removeItem(ThemeStorageService.storageKey);
|
||||
} catch (e) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,35 +10,35 @@ const WEBSOCKET_URL = 'ws://localhost:9050/ws';
|
||||
@NgModule({
|
||||
})
|
||||
export class WebsocketResponseHandlerService {
|
||||
public messages: Subject<any>;
|
||||
public shared: Observable<WebSocketMessage>;
|
||||
public isConnected: boolean = false;
|
||||
private ws: WebsocketService;
|
||||
public messages: Subject<any>;
|
||||
public shared: Observable<WebSocketMessage>;
|
||||
public isConnected = false;
|
||||
private ws: WebsocketService;
|
||||
|
||||
constructor(@Optional() @SkipSelf() parentModule: WebsocketResponseHandlerService, wsService: WebsocketService) {
|
||||
this.ws = wsService;
|
||||
this.messages = <Subject<WebSocketMessage>>this.ws
|
||||
.connect(WEBSOCKET_URL).pipe(
|
||||
constructor(@Optional() @SkipSelf() parentModule: WebsocketResponseHandlerService, wsService: WebsocketService) {
|
||||
this.ws = wsService;
|
||||
this.messages = <Subject<WebSocketMessage>>this.ws
|
||||
.connect(WEBSOCKET_URL).pipe(
|
||||
|
||||
map((response: MessageEvent): WebSocketMessage => {
|
||||
var interval = setInterval(() => {
|
||||
this.isConnected = this.ws.isConnected;
|
||||
}, 2000);
|
||||
let websocketResponseMessage = JSON.parse(response.data);
|
||||
var websocketResponseData = websocketResponseMessage.Data === undefined ? websocketResponseMessage.data : websocketResponseMessage.Data;
|
||||
var websocketResponseEvent = websocketResponseMessage.Event === undefined ? websocketResponseMessage.event : websocketResponseMessage.Event;
|
||||
let responseMessage = new WebSocketMessage();
|
||||
|
||||
responseMessage.event = websocketResponseEvent;
|
||||
responseMessage.data = websocketResponseData;
|
||||
responseMessage.exchange = websocketResponseMessage.exchange;
|
||||
responseMessage.assetType = websocketResponseMessage.assetType;
|
||||
responseMessage.error = websocketResponseMessage.error;
|
||||
map((response: MessageEvent): WebSocketMessage => {
|
||||
const interval = setInterval(() => {
|
||||
this.isConnected = this.ws.isConnected;
|
||||
}, 2000);
|
||||
const websocketResponseMessage = JSON.parse(response.data);
|
||||
const websocketResponseData = websocketResponseMessage.Data === undefined ? websocketResponseMessage.data : websocketResponseMessage.Data;
|
||||
const websocketResponseEvent = websocketResponseMessage.Event === undefined ? websocketResponseMessage.event : websocketResponseMessage.Event;
|
||||
const responseMessage = new WebSocketMessage();
|
||||
|
||||
return responseMessage;
|
||||
}));
|
||||
this.isConnected = this.ws.isConnected;
|
||||
|
||||
this.shared = this.messages.pipe(share()); //multicast
|
||||
}
|
||||
}
|
||||
responseMessage.event = websocketResponseEvent;
|
||||
responseMessage.data = websocketResponseData;
|
||||
responseMessage.exchange = websocketResponseMessage.exchange;
|
||||
responseMessage.assetType = websocketResponseMessage.assetType;
|
||||
responseMessage.error = websocketResponseMessage.error;
|
||||
|
||||
return responseMessage;
|
||||
}));
|
||||
this.isConnected = this.ws.isConnected;
|
||||
|
||||
this.shared = this.messages.pipe(share()); // multicast
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { WebSocketMessage } from './../../shared/classes/websocket';
|
||||
|
||||
@NgModule()
|
||||
export class WebsocketService {
|
||||
public isConnected :boolean = false;
|
||||
public isConnected = false;
|
||||
constructor (@Optional() @SkipSelf() parentModule: WebsocketService) {
|
||||
if (parentModule) {
|
||||
throw new Error(
|
||||
@@ -22,25 +22,25 @@ export class WebsocketService {
|
||||
}
|
||||
|
||||
private create(url): Subject<MessageEvent> {
|
||||
let ws = new WebSocket(url);
|
||||
let observable = Observable.create(
|
||||
const ws = new WebSocket(url);
|
||||
const observable = Observable.create(
|
||||
(obs: Observer<MessageEvent>) => {
|
||||
ws.onmessage = obs.next.bind(obs);
|
||||
ws.onerror = obs.error.bind(obs);
|
||||
ws.onclose = () => {
|
||||
this.isConnected = false;
|
||||
obs.complete.bind(obs) };
|
||||
obs.complete.bind(obs); };
|
||||
ws.onopen = () => {
|
||||
this.isConnected = true;
|
||||
ws.send(JSON.stringify(WebSocketMessage.CreateAuthenticationMessage()));
|
||||
};
|
||||
return ws.close.bind(ws);
|
||||
})
|
||||
let observer = {
|
||||
});
|
||||
const observer = {
|
||||
next: (data: any) => {
|
||||
var counter = 0;
|
||||
var interval = setInterval(() => {
|
||||
if (counter == 10) {
|
||||
let counter = 0;
|
||||
const interval = setInterval(() => {
|
||||
if (counter === 10) {
|
||||
clearInterval(interval);
|
||||
}
|
||||
if (ws.readyState === WebSocket.OPEN) {
|
||||
@@ -50,13 +50,13 @@ export class WebsocketService {
|
||||
}
|
||||
counter++;
|
||||
}, 400);
|
||||
|
||||
|
||||
if (ws.readyState !== WebSocket.OPEN) {
|
||||
new Error("Failed to send message to websocket after 10 attempts");
|
||||
new Error('Failed to send message to websocket after 10 attempts');
|
||||
this.isConnected = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
return Subject.create(observer, observable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user