Skip to content
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

Developer node operations #373

Merged
merged 4 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ const configs = [
enabled: true,
nftClasses: ['ununifi-1AFC3C85B52311F13161F724B284EF900458E3B3'],
},
developer: {
enabled: true,
developerURL: `http://${domainCauchyEA}:3030`,
},
navigations: [],
messageModules,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ const configs = [
enabled: true,
nftClasses: ['ununifi-1AFC3C85B52311F13161F724B284EF900458E3B3'],
},
developer: {
enabled: false,
developerURL: `http://${domainCauchyEA}:3030`,
},
navigations: [],
messageModules,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ const configs = [
enabled: true,
nftClasses: ['ununifi-1AFC3C85B52311F13161F724B284EF900458E3B3'],
},
developer: {
enabled: true,
developerURL: `http://${domainCauchyEA}:3030`,
},
navigations: [],
messageModules,
},
Expand Down
6 changes: 5 additions & 1 deletion projects/explorer/src/app/models/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ export type Config = {
monitor?: {
monitorURL: string;
};
nftMint: {
nftMint?: {
enabled: boolean;
nftClasses: string[];
};
developer?: {
enabled: boolean;
developerURL: string;
};
navigations: {
name: string;
link: string;
Expand Down
4 changes: 4 additions & 0 deletions projects/explorer/src/assets/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ const configs = [
enabled: true,
nftClasses: ['ununifi-1AFC3C85B52311F13161F724B284EF900458E3B3'],
},
developer: {
enabled: true,
developerURL: `http://${domainCauchyEA}:3030`,
},
navigations: [],
messageModules,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ const configs = [
enabled: true,
nftClasses: ['ununifi-1AFC3C85B52311F13161F724B284EF900458E3B3'],
},
developer: {
enabled: true,
developerURL: `http://${domainCauchyEA}:3030`,
},
navigations: [],
messageModules,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ const configs = [
enabled: true,
nftClasses: ['ununifi-1AFC3C85B52311F13161F724B284EF900458E3B3'],
},
developer: {
enabled: false,
developerURL: `http://${domainCauchyEA}:3030`,
},
navigations: [],
messageModules,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ const configs = [
enabled: true,
nftClasses: ['ununifi-1AFC3C85B52311F13161F724B284EF900458E3B3'],
},
developer: {
enabled: true,
developerURL: `http://${domainCauchyEA}:3030`,
},
navigations: [],
messageModules,
},
Expand Down
5 changes: 5 additions & 0 deletions projects/portal/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ const routes: Routes = [
loadChildren: () =>
import('./pages/derivatives/derivatives.module').then((m) => m.AppDerivativesModule),
},
{
path: 'developers',
loadChildren: () =>
import('./pages/developers/developers.module').then((m) => m.AppDevelopersModule),
},
];

@NgModule({
Expand Down
21 changes: 14 additions & 7 deletions projects/portal/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ export class AppComponent implements OnInit {
this.currentStoredWallet$ = this.walletService.currentStoredWallet$;
this.navigations$ = this.config$.pipe(
map((config) => {
if (config?.extension?.developer?.enabled) {
config?.extension?.navigations.unshift({
name: 'Developers',
link: '/portal/developers',
icon: 'build',
});
}
if (config?.extension?.nftMint?.enabled) {
config.extension.navigations.unshift({
name: 'NFT Mint',
link: '/portal/nfts/mint',
icon: 'add_photo_alternate',
});
}
if (config?.extension?.faucet?.filter((faucet) => faucet.hasFaucet == true).length) {
config.extension.navigations.unshift({
name: 'Faucet',
Expand All @@ -63,13 +77,6 @@ export class AppComponent implements OnInit {
icon: 'monitor',
});
}
if (config?.extension?.nftMint.enabled) {
config.extension.navigations.unshift({
name: 'NFT Mint',
link: '/portal/nfts/mint',
icon: 'add_photo_alternate',
});
}
return config?.extension?.navigations;
}),
);
Expand Down
6 changes: 5 additions & 1 deletion projects/portal/src/app/models/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ export type Config = {
monitor?: {
monitorURL: string;
};
nftMint: {
nftMint?: {
enabled: boolean;
nftClasses: string[];
};
developer?: {
enabled: boolean;
developerURL: string;
};
navigations: {
name: string;
link: string;
Expand Down
44 changes: 44 additions & 0 deletions projects/portal/src/app/models/wallets/wallet-developer.guard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { WalletApplicationService } from './wallet.application.service';
import { StoredWallet } from './wallet.model';
import { WalletService } from './wallet.service';
import { Injectable } from '@angular/core';
import {
CanActivate,
ActivatedRouteSnapshot,
RouterStateSnapshot,
UrlTree,
Router,
} from '@angular/router';

@Injectable({
providedIn: 'root',
})
export class WalletDeveloperGuard implements CanActivate {
constructor(
private readonly router: Router,
private readonly walletService: WalletService,
private readonly walletApplicationService: WalletApplicationService,
) {}

async canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean> {
const devAddress = [
'ununifi155u042u8wk3al32h3vzxu989jj76k4zcu44v6w',
'ununifi1v0h8j7x7kfys29kj4uwdudcc9y0nx6twwxahla',
'ununifi1y3t7sp0nfe2nfda7r9gf628g6ym6e7d44evfv6',
'ununifi1pp2ruuhs0k7ayaxjupwj4k5qmgh0d72wrdyjyu',
'ununifi1gnfsfp340h33glkccjet38faxwkspwpz3r4raj',
];
const currentStoredWallet: StoredWallet | undefined =
await this.walletService.getCurrentStoredWallet();
if (
currentStoredWallet &&
devAddress.find((address) => address == currentStoredWallet.address)
) {
return true;
} else {
alert('Please login with developer account.');
this.router.navigate(['']);
return true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { WalletDeveloperGuard } from '../../models/wallets/wallet-developer.guard';
import { DevelopersComponent } from './developers.component';
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';

const routes: Routes = [
{
path: '',
component: DevelopersComponent,
canActivate: [WalletDeveloperGuard],
},
];

@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class DevelopersRoutingModule {}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<view-developers
[config]="config$ | async"
[version]="version$ | async"
(rebuild)="onRebuild($event)"
(restart)="onRestart($event)"
></view-developers>
49 changes: 49 additions & 0 deletions projects/portal/src/app/pages/developers/developers.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Config, ConfigService } from '../../models/config.service';
import { HttpClient } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
import { Observable, of } from 'rxjs';
import { mergeMap } from 'rxjs/operators';

@Component({
selector: 'app-developers',
templateUrl: './developers.component.html',
styleUrls: ['./developers.component.css'],
})
export class DevelopersComponent implements OnInit {
config$: Observable<Config | undefined>;
version$: Observable<string | undefined>;

constructor(private configService: ConfigService, private http: HttpClient) {
this.config$ = this.configService.config$;
this.version$ = this.config$.pipe(
mergeMap((conf) => {
if (conf && conf.extension && conf.extension.developer) {
return this.http.get(conf.extension.developer.developerURL + '/version', {
responseType: 'text',
});
} else {
return of(undefined);
}
}),
);
}

ngOnInit(): void {}

async onRebuild($event: Config) {
await this.http
.get($event?.extension?.developer?.developerURL + '/execute', {
responseType: 'text',
})
.toPromise();
alert('Successfully Sent Rebuild Request');
}
async onRestart($event: Config) {
await this.http
.get($event?.extension?.developer?.developerURL + '/reset', {
responseType: 'text',
})
.toPromise();
alert('Successfully Sent Rebuild Request');
}
}
11 changes: 11 additions & 0 deletions projects/portal/src/app/pages/developers/developers.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { DevelopersModule } from '../../views/developers/developers.module';
import { DevelopersRoutingModule } from './developers-routing.module';
import { DevelopersComponent } from './developers.component';
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';

@NgModule({
declarations: [DevelopersComponent],
imports: [CommonModule, DevelopersRoutingModule, DevelopersModule],
})
export class AppDevelopersModule {}
2 changes: 1 addition & 1 deletion projects/portal/src/app/pages/nfts/mint/mint.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class MintComponent implements OnInit {
map((wallet) => wallet.address),
);
const config$ = this.configService.config$;
this.classes$ = config$.pipe(map((config) => config?.extension?.nftMint.nftClasses));
this.classes$ = config$.pipe(map((config) => config?.extension?.nftMint?.nftClasses));
this.selectedClass$ = this.classes$.pipe(map((classes) => (classes ? classes[0] : '')));
}

Expand Down
Empty file.
41 changes: 41 additions & 0 deletions projects/portal/src/app/views/developers/developers.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<div class="mx-auto max-w-screen-xl">
<div class="flex flex-row flex-wrap mb-8">
<h2>Developers (Only Stable & Alpha)</h2>
</div>

<div class="w-full md:w-auto mb-8">
<div class="card bg-base-100 shadow-xl w-full">
<div class="card-body">
<h2 class="card-title">Node Operations</h2>
<ul class="menu bg-base-100 w-full p-4 rounded-box">
<li (click)="onRebuild()">
<a class="flex gap-4">
<span class="flex-none">
<mat-icon color="primary">build</mat-icon>
</span>
<span class="flex-1 text-lg">Rebuild</span>
</a>
</li>
<li (click)="onRestart()">
<a>
<span class="flex-none">
<mat-icon color="primary">replay</mat-icon>
</span>
<span class="flex-1 text-lg">Restart</span>
</a>
</li>
</ul>
<div class="overflow-x-auto">
<table class="table w-full">
<tbody>
<tr>
<th>Version</th>
<td>{{ version }}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
39 changes: 39 additions & 0 deletions projects/portal/src/app/views/developers/developers.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Config } from '../../models/config.service';
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';

@Component({
selector: 'view-developers',
templateUrl: './developers.component.html',
styleUrls: ['./developers.component.css'],
})
export class DevelopersComponent implements OnInit {
@Input()
config?: Config | null;
@Input()
version?: string | null;

@Output()
rebuild = new EventEmitter<Config>();
@Output()
restart = new EventEmitter<Config>();

constructor() {}

ngOnInit(): void {}

onRebuild() {
if (!this.config) {
alert('Invalid Config');
return;
}
this.rebuild.emit(this.config);
}

onRestart() {
if (!this.config) {
alert('Invalid Config');
return;
}
this.restart.emit(this.config);
}
}
11 changes: 11 additions & 0 deletions projects/portal/src/app/views/developers/developers.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { DevelopersComponent } from './developers.component';
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { MaterialModule } from '../material.module';

@NgModule({
declarations: [DevelopersComponent],
imports: [CommonModule,MaterialModule],
exports: [DevelopersComponent],
})
export class DevelopersModule {}
Loading