Skip to content

Commit af2a3f6

Browse files
authored
Frontend - code refactoring (#823)
1 parent 9f63145 commit af2a3f6

File tree

6 files changed

+48
-38
lines changed

6 files changed

+48
-38
lines changed

frontend/src/app/core/services/web-node.service.ts

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import { Injectable } from '@angular/core';
22
import { BehaviorSubject, filter, from, fromEvent, map, merge, Observable, of, switchMap, tap } from 'rxjs';
33
import base from 'base-x';
4-
import { any, log } from '@openmina/shared';
4+
import { any } from '@openmina/shared';
55
import { HttpClient } from '@angular/common/http';
66

77
@Injectable({
88
providedIn: 'root',
99
})
1010
export class WebNodeService {
1111

12-
private readonly backendSubject$: BehaviorSubject<any> = new BehaviorSubject<any>(null);
13-
private backend: any;
12+
private readonly webnode$: BehaviorSubject<any> = new BehaviorSubject<any>(null);
1413
private webNodeKeyPair: { publicKey: string, privateKey: string };
1514

1615
constructor(private http: HttpClient) {
@@ -42,79 +41,74 @@ export class WebNodeService {
4241
console.log(wasm);
4342
return from(wasm.run(this.webNodeKeyPair.privateKey));
4443
}),
45-
tap((jsHandle: any) => {
46-
this.backend = jsHandle;
44+
tap((webnode: any) => {
4745
console.log('----------------WEBNODE----------------');
48-
console.log(jsHandle);
49-
this.backendSubject$.next(jsHandle);
46+
console.log(webnode);
47+
this.webnode$.next(webnode);
5048
}),
51-
switchMap(() => this.backendSubject$.asObservable()),
49+
switchMap(() => this.webnode$.asObservable()),
5250
filter(Boolean),
5351
);
5452
}
5553

56-
get webNodeKeys(): { publicKey: string, privateKey: string } {
57-
return this.webNodeKeyPair;
58-
}
59-
6054
get status$(): Observable<any> {
61-
return this.backendSubject$.asObservable().pipe(
55+
return this.webnode$.asObservable().pipe(
6256
filter(Boolean),
6357
switchMap(handle => from((handle as any).status())),
6458
);
6559
}
6660

6761
get blockProducerStats$(): Observable<any> {
68-
return this.backendSubject$.asObservable().pipe(
62+
return this.webnode$.asObservable().pipe(
6963
filter(Boolean),
7064
switchMap(handle => from((handle as any).stats().block_producer())),
7165
);
7266
}
7367

7468
get peers$(): Observable<any> {
75-
return this.backendSubject$.asObservable().pipe(
69+
return this.webnode$.asObservable().pipe(
7670
filter(Boolean),
7771
switchMap(handle => from(any(handle).state().peers())),
7872
);
7973
}
8074

8175
get messageProgress$(): Observable<any> {
82-
return this.backendSubject$.asObservable().pipe(
76+
return this.webnode$.asObservable().pipe(
8377
filter(Boolean),
8478
switchMap(handle => from((handle as any).state().message_progress())),
8579
);
8680
}
8781

8882
get sync$(): Observable<any> {
89-
return this.backendSubject$.asObservable().pipe(
83+
return this.webnode$.asObservable().pipe(
9084
filter(Boolean),
9185
switchMap(handle => from((handle as any).stats().sync())),
9286
);
9387
}
9488

9589
get accounts$(): Observable<any> {
96-
return this.backendSubject$.asObservable().pipe(
90+
return this.webnode$.asObservable().pipe(
9791
filter(Boolean),
9892
switchMap(handle => from((handle as any).ledger().latest().accounts().all())),
9993
);
10094
}
10195

10296
get bestChainUserCommands$(): Observable<any> {
103-
return this.backendSubject$.asObservable().pipe(
97+
return this.webnode$.asObservable().pipe(
10498
filter(Boolean),
10599
switchMap(handle => from((handle as any).transition_frontier().best_chain().user_commands())),
106100
);
107101
}
108102

109103
sendPayment$(payment: any): Observable<any> {
110-
return this.backendSubject$.asObservable().pipe(
104+
return this.webnode$.asObservable().pipe(
111105
filter(Boolean),
112106
switchMap(handle => from((handle as any).transaction_pool().inject().payment(payment))),
113107
);
114108
}
115109

116110
get transactionPool$(): Observable<any> {
117-
return this.backendSubject$.asObservable().pipe(
111+
return this.webnode$.asObservable().pipe(
118112
filter(Boolean),
119113
switchMap(handle => from((handle as any).transaction_pool().get())),
120114
);

frontend/src/app/features/benchmarks/wallets/benchmarks-wallets.effects.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ import { Injectable } from '@angular/core';
22
import { MinaState, selectMinaState } from '@app/app.setup';
33
import { Actions, createEffect, ofType } from '@ngrx/effects';
44
import { Effect } from '@openmina/shared';
5-
import { forkJoin, map, switchMap } from 'rxjs';
5+
import { EMPTY, forkJoin, map, switchMap } from 'rxjs';
66
import { Store } from '@ngrx/store';
77
import {
8+
BENCHMARKS_WALLETS_CLOSE,
89
BENCHMARKS_WALLETS_GET_ALL_TXS,
910
BENCHMARKS_WALLETS_GET_ALL_TXS_SUCCESS,
1011
BENCHMARKS_WALLETS_GET_WALLETS,
1112
BENCHMARKS_WALLETS_GET_WALLETS_SUCCESS,
1213
BENCHMARKS_WALLETS_SEND_TX_SUCCESS,
1314
BENCHMARKS_WALLETS_SEND_TXS, BENCHMARKS_WALLETS_SEND_ZKAPPS, BENCHMARKS_WALLETS_SEND_ZKAPPS_SUCCESS,
14-
BenchmarksWalletsActions,
15+
BenchmarksWalletsActions, BenchmarksWalletsClose,
1516
BenchmarksWalletsGetWallets,
1617
BenchmarksWalletsSendTxs,
1718
} from '@benchmarks/wallets/benchmarks-wallets.actions';
@@ -38,22 +39,23 @@ export class BenchmarksWalletsEffects extends MinaRustBaseEffect<BenchmarksWalle
3839
private zkService: BenchmarksWalletsZkService,
3940
private mempoolService: MempoolService,
4041
store: Store<MinaState>) {
41-
4242
super(store, selectMinaState);
4343

4444
this.getWallets$ = createEffect(() => this.actions$.pipe(
45-
ofType(BENCHMARKS_WALLETS_GET_WALLETS),
46-
this.latestActionState<BenchmarksWalletsGetWallets>(),
47-
switchMap(({ action }) => this.benchmarksService.getAccounts().pipe(
48-
switchMap(payload => {
49-
const actions = [];
50-
if (action.payload?.initialRequest) {
51-
actions.push({ type: BENCHMARKS_WALLETS_GET_ALL_TXS });
52-
}
53-
actions.push({ type: BENCHMARKS_WALLETS_GET_WALLETS_SUCCESS, payload });
54-
return actions;
55-
}),
56-
)),
45+
ofType(BENCHMARKS_WALLETS_GET_WALLETS, BENCHMARKS_WALLETS_CLOSE),
46+
this.latestActionState<BenchmarksWalletsGetWallets | BenchmarksWalletsClose>(),
47+
switchMap(({ action }) => action.type === BENCHMARKS_WALLETS_CLOSE
48+
? EMPTY
49+
: this.benchmarksService.getAccounts().pipe(
50+
switchMap(payload => {
51+
const actions = [];
52+
if (action.payload?.initialRequest) {
53+
actions.push({ type: BENCHMARKS_WALLETS_GET_ALL_TXS });
54+
}
55+
actions.push({ type: BENCHMARKS_WALLETS_GET_WALLETS_SUCCESS, payload });
56+
return actions;
57+
}),
58+
)),
5759
catchErrorAndRepeat(MinaErrorType.GENERIC, BENCHMARKS_WALLETS_GET_WALLETS_SUCCESS, []),
5860
));
5961

frontend/src/app/features/benchmarks/wallets/benchmarks-wallets.service.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4035,7 +4035,7 @@ export class BenchmarksWalletsService {
40354035
}
40364036

40374037
getAccounts(): Observable<Pick<BenchmarksWallet, 'publicKey' | 'privateKey' | 'minaTokens' | 'nonce'>[]> {
4038-
return this.rust.get<any[]>('/accounts').pipe(
4038+
return this.rust.get<AccountsResponse[]>('/accounts').pipe(
40394039
map(wallets => wallets.map(wallet => {
40404040
return ({
40414041
privateKey: WALLETS.find(w => w.publicKey === wallet.public_key)?.privateKey,
@@ -4140,3 +4140,9 @@ export class BenchmarksWalletsService {
41404140
});
41414141
}
41424142
}
4143+
4144+
export interface AccountsResponse {
4145+
public_key: string;
4146+
nonce: number;
4147+
balance: number;
4148+
}

frontend/src/app/layout/server-status/server-status.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
</div>
2525
</ng-container>
2626
<div class="node-status fx-row-vert-cent bg-surface h-sm border-rad-6 p-relative z-1 mr-10"
27-
[class.can-add-nodes]="canAddNodes">
27+
[class.can-add-nodes]="switchForbidden">
2828
<ng-container *ngIf="!switchForbidden && !hideNodeStats">
2929
<div class="shine-parent overflow-hidden p-absolute z-0 border-rad-6">
3030
<div *ngIf="details.status === AppNodeStatus.CATCHUP || details.status === AppNodeStatus.BOOTSTRAP"

frontend/src/app/layout/server-status/server-status.component.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@
113113
}
114114
}
115115

116+
.chip::before {
117+
border-top-right-radius: 0 !important;
118+
border-bottom-right-radius: 0 !important;
119+
}
120+
116121
.shine-parent {
117122
height: calc(100% + 3px);
118123
width: calc(100% - 2px);

frontend/src/app/layout/toolbar/loading.reducer.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import {
4545
} from '@network/bootstrap-stats/network-bootstrap-stats.actions';
4646
import { BLOCK_PRODUCTION_PREFIX } from '@block-production/block-production.actions';
4747
import {
48+
BENCHMARKS_WALLETS_CLOSE,
4849
BENCHMARKS_WALLETS_GET_ALL_TXS,
4950
BENCHMARKS_WALLETS_GET_ALL_TXS_SUCCESS,
5051
BENCHMARKS_WALLETS_GET_WALLETS, BENCHMARKS_WALLETS_GET_WALLETS_SUCCESS,
@@ -154,6 +155,8 @@ export function loadingReducer(state: LoadingState = initialState, action: Featu
154155
return remove(state, BENCHMARKS_WALLETS_GET_WALLETS);
155156
case BENCHMARKS_WALLETS_GET_ALL_TXS_SUCCESS:
156157
return remove(state, BENCHMARKS_WALLETS_GET_ALL_TXS);
158+
case BENCHMARKS_WALLETS_CLOSE:
159+
return remove(state, [BENCHMARKS_WALLETS_GET_WALLETS, BENCHMARKS_WALLETS_GET_ALL_TXS]);
157160

158161
default:
159162
return state;

0 commit comments

Comments
 (0)