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],
imports: [
CommonModule,
NgbPopoverModule,
HttpClientModule,
VisModule,
FormsModule,
SharedModule,
DragulaModule.forRoot(),
CommonModule
],
exports: [
ParticipantRingComponent,

View file

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

View file

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

View file

@ -14,7 +14,7 @@ import { BehaviorSubject, Observable } from 'rxjs';
import { selectNodeOwners } from '../selectors/node-owner.selectors';
@Injectable({
providedIn: 'root'
providedIn: 'root',
})
export class RingDataService {
nodeOwners$!: Observable<NodeOwner[]>;
@ -22,17 +22,18 @@ export class RingDataService {
private actionSource = new BehaviorSubject('default message');
currentAction = this.actionSource.asObservable();
constructor(
private store: Store<fromRoot.State>,
private lnData: LnDataService
) {
) {
this.nodeOwners$ = this.store.select(selectNodeOwners);
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) {
@ -45,7 +46,7 @@ export class RingDataService {
}
setNodeOwners(nodeOwners: any) {
this.store.dispatch(loadNodeOwners({ nodeOwners: nodeOwners }))
this.store.dispatch(loadNodeOwners({ nodeOwners: nodeOwners }));
}
addNodeOwner(pubKey: string, tgUsername: string) {
@ -55,25 +56,33 @@ export class RingDataService {
nodename: nodeInfo.node.alias,
first_name: 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> {
let ring: IRing = [];
for (const [i, node] of this.nodeOwners.entries()) {
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);
ring.push([
Object.assign(new NodeOwner(), this.nodeOwners[i]),
Object.assign(new NodeOwner(), this.nodeOwners[nextIndex]),
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 = {
production: false,
networkClass: null
networkClass: null,
apiEndpoint: 'http://localhost:7464'
};
/*