Use environment for api endpoint

This commit is contained in:
Djuri Baars 2022-01-17 18:14:48 +01:00
parent c313bd4973
commit de0db38305
5 changed files with 34 additions and 27 deletions

View file

@ -26,13 +26,13 @@ import { NgbPopoverModule } from '@ng-bootstrap/ng-bootstrap';
], ],
providers: [JsonPipe], providers: [JsonPipe],
imports: [ imports: [
CommonModule,
NgbPopoverModule, NgbPopoverModule,
HttpClientModule, HttpClientModule,
VisModule, VisModule,
FormsModule, FormsModule,
SharedModule, SharedModule,
DragulaModule.forRoot(), DragulaModule.forRoot(),
CommonModule
], ],
exports: [ exports: [
ParticipantRingComponent, ParticipantRingComponent,

View file

@ -3,26 +3,26 @@ import { io, Socket } from 'socket.io-client';
import { NodeInfo } from '../models/node-info.model'; import { NodeInfo } from '../models/node-info.model';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { firstValueFrom } from 'rxjs'; import { firstValueFrom } from 'rxjs';
import { environment } from 'src/environments/environment';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root',
}) })
export class LnDataService { export class LnDataService {
socket: Socket<any, any>; socket: Socket<any, any>;
nodeSocket: Socket<any, any>; nodeSocket: Socket<any, any>;
channelSocket: Socket<any, any>; channelSocket: Socket<any, any>;
constructor(private http: HttpClient) { readonly apiEndpoint = environment.apiEndpoint;
const url = 'http://localhost:7464';
this.socket = io(url) constructor(private http: HttpClient) {;
this.nodeSocket = io(`${url}/node`) this.socket = io(this.apiEndpoint);
this.channelSocket = io(`${url}/channel`) this.nodeSocket = io(`${this.apiEndpoint}/node`);
this.channelSocket = io(`${this.apiEndpoint}/channel`);
} }
getNodeInfo(pubKey: string) { getNodeInfo(pubKey: string) {
return this.http.get<NodeInfo>( return this.http.get<NodeInfo>(`${this.apiEndpoint}/node/${pubKey}`);
`http://localhost:7464/node/${pubKey}`
);
} }
getNodeInfoAsync(pubKey: string) { getNodeInfoAsync(pubKey: string) {

View file

@ -2,13 +2,10 @@ import { Injectable } from '@angular/core';
import { ToastService } from '../shared/notification/toast/toast.service'; import { ToastService } from '../shared/notification/toast/toast.service';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root',
}) })
export class NotificationService { export class NotificationService {
constructor(private toast: ToastService) {}
constructor(private toast: ToastService) {
}
showSuccess(message: string) { showSuccess(message: string) {
this.toast.show(`${message}`, { this.toast.show(`${message}`, {

View file

@ -14,7 +14,7 @@ import { BehaviorSubject, Observable } from 'rxjs';
import { selectNodeOwners } from '../selectors/node-owner.selectors'; import { selectNodeOwners } from '../selectors/node-owner.selectors';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root',
}) })
export class RingDataService { export class RingDataService {
nodeOwners$!: Observable<NodeOwner[]>; nodeOwners$!: Observable<NodeOwner[]>;
@ -30,9 +30,10 @@ export class RingDataService {
this.nodeOwners$ = this.store.select(selectNodeOwners); this.nodeOwners$ = this.store.select(selectNodeOwners);
this.nodeOwners$.subscribe((nodeOwners: NodeOwner[]) => { this.nodeOwners$.subscribe((nodeOwners: NodeOwner[]) => {
this.nodeOwners = nodeOwners.map(no => Object.assign(new NodeOwner, no)); this.nodeOwners = nodeOwners.map((no) =>
Object.assign(new NodeOwner(), no)
);
}); });
} }
loadSettings(item: RingSetting) { loadSettings(item: RingSetting) {
@ -45,7 +46,7 @@ export class RingDataService {
} }
setNodeOwners(nodeOwners: any) { setNodeOwners(nodeOwners: any) {
this.store.dispatch(loadNodeOwners({ nodeOwners: nodeOwners })) this.store.dispatch(loadNodeOwners({ nodeOwners: nodeOwners }));
} }
addNodeOwner(pubKey: string, tgUsername: string) { addNodeOwner(pubKey: string, tgUsername: string) {
@ -55,25 +56,33 @@ export class RingDataService {
nodename: nodeInfo.node.alias, nodename: nodeInfo.node.alias,
first_name: tgUsername, first_name: tgUsername,
username: tgUsername, username: tgUsername,
username_or_name: '' username_or_name: '',
}; };
this.store.dispatch(addNodeOwner({nodeOwner: no })); this.store.dispatch(addNodeOwner({ nodeOwner: no }));
}) });
} }
async getRing(): Promise<IRing> { async getRing(): Promise<IRing> {
let ring: IRing = []; let ring: IRing = [];
for (const [i, node] of this.nodeOwners.entries()) { for (const [i, node] of this.nodeOwners.entries()) {
let nextIndex = (i + 1) % this.nodeOwners.length; let nextIndex = (i + 1) % this.nodeOwners.length;
const nodeInfo = Object.assign(new NodeInfo, (await this.lnData.getNodeInfoAsync(this.nodeOwners[i].pub_key))); const nodeInfo = Object.assign(
new NodeInfo(),
await this.lnData.getNodeInfoAsync(this.nodeOwners[i].pub_key)
);
let channel = nodeInfo.hasChannelWith(this.nodeOwners[nextIndex].pub_key); let channel = nodeInfo.hasChannelWith(this.nodeOwners[nextIndex].pub_key);
ring.push([ ring.push([
Object.assign(new NodeOwner(), this.nodeOwners[i]), Object.assign(new NodeOwner(), this.nodeOwners[i]),
Object.assign(new NodeOwner(), this.nodeOwners[nextIndex]), Object.assign(new NodeOwner(), this.nodeOwners[nextIndex]),
channel, channel,
channel ? nodeInfo.getChannelPolicies(this.nodeOwners[nextIndex].pub_key, channel) : undefined channel
? nodeInfo.getChannelPolicies(
this.nodeOwners[nextIndex].pub_key,
channel
)
: undefined,
]); ]);
} }

View file

@ -4,7 +4,8 @@
export const environment = { export const environment = {
production: false, production: false,
networkClass: null networkClass: null,
apiEndpoint: 'http://localhost:7464'
}; };
/* /*