Skip to content

Commit 22cae91

Browse files
authored
Frontend - Ledger HID communication #606
Frontend - Ledger HID communication
2 parents f58e293 + 0c91610 commit 22cae91

File tree

16 files changed

+686
-50
lines changed

16 files changed

+686
-50
lines changed

frontend/angular.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
"index": "src/index.html",
3636
"main": "src/main.ts",
3737
"polyfills": [
38-
"zone.js"
38+
"zone.js",
39+
"polyfills.ts"
3940
],
4041
"tsConfig": "tsconfig.app.json",
4142
"inlineStyleLanguage": "scss",

frontend/package-lock.json

Lines changed: 104 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@
2424
"@angular/platform-browser": "^16.2.0",
2525
"@angular/platform-browser-dynamic": "^16.2.0",
2626
"@angular/router": "^16.2.0",
27+
"@ledgerhq/hw-transport-webhid": "^6.29.2",
2728
"@ngneat/until-destroy": "^10.0.0",
2829
"@ngrx/effects": "^16.2.0",
2930
"@ngrx/router-store": "^16.2.0",
3031
"@ngrx/store": "^16.2.0",
3132
"@openmina/shared": "^0.96.0",
33+
"buffer": "^6.0.3",
3234
"d3": "^7.8.4",
3335
"eigen": "^0.2.2",
3436
"mathjs": "^12.3.0",
@@ -48,6 +50,7 @@
4850
"@types/d3": "^7.4.0",
4951
"@types/jasmine": "~4.3.0",
5052
"@types/node": "^20.4.8",
53+
"@types/w3c-web-hid": "^1.0.6",
5154
"cypress": "^13.3.2",
5255
"cypress-real-events": "^1.10.0",
5356
"jasmine-core": "~4.6.0",

frontend/polyfills.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import * as buffer from 'buffer';
2+
3+
(window as any).Buffer = buffer.Buffer;

frontend/src/app/app.effects.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { MinaState, selectMinaState } from '@app/app.setup';
33
import { Actions, createEffect, ofType } from '@ngrx/effects';
44
import { Store } from '@ngrx/store';
55
import { createNonDispatchableEffect, Effect, removeParamsFromURL } from '@openmina/shared';
6-
import { map, switchMap, tap } from 'rxjs';
6+
import { filter, map, switchMap, tap } from 'rxjs';
77
import { AppActions } from '@app/app.actions';
88
import { Router } from '@angular/router';
99
import { FeatureType, MinaNode } from '@shared/types/core/environment/mina-env.type';
@@ -24,6 +24,8 @@ export class AppEffects extends BaseEffect {
2424
readonly onNodeChange$: Effect;
2525
readonly getNodeDetails$: Effect;
2626

27+
private requestInProgress: boolean = false;
28+
2729
constructor(private actions$: Actions,
2830
private appService: AppService,
2931
private rustNode: RustService,
@@ -65,7 +67,10 @@ export class AppEffects extends BaseEffect {
6567

6668
this.getNodeDetails$ = createEffect(() => this.actions$.pipe(
6769
ofType(AppActions.getNodeDetails),
70+
filter(() => !this.requestInProgress),
71+
tap(() => this.requestInProgress = true),
6872
switchMap(() => this.appService.getActiveNodeDetails()),
73+
tap(() => this.requestInProgress = false),
6974
map(details => AppActions.getNodeDetailsSuccess({ details })),
7075
));
7176
}

frontend/src/app/app.service.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,30 +39,30 @@ export class AppService {
3939
snarks: data.snark_pool.snarks,
4040
transactions: data.transaction_pool.transactions,
4141
} as AppNodeDetails)),
42-
catchError(() => of({
43-
status: AppNodeStatus.OFFLINE,
44-
blockHeight: null,
45-
blockTime: null,
46-
peers: 0,
47-
download: 0,
48-
upload: 0,
49-
transactions: 0,
50-
snarks: 0,
51-
} as AppNodeDetails)),
42+
catchError((err) => {
43+
return of({
44+
status: AppNodeStatus.OFFLINE,
45+
blockHeight: null,
46+
blockTime: null,
47+
peers: 0,
48+
download: 0,
49+
upload: 0,
50+
transactions: 0,
51+
snarks: 0,
52+
} as AppNodeDetails);
53+
}),
5254
);
5355
}
5456

5557
private getStatus(data: NodeDetails): AppNodeStatus {
56-
if (data.transition_frontier.best_tip === null && data.transition_frontier.sync.status !== 'Synced') {
57-
return AppNodeStatus.BOOTSTRAP;
58-
}
59-
if (data.transition_frontier.best_tip !== null && data.transition_frontier.sync.status !== 'Synced') {
60-
return AppNodeStatus.CATCHUP;
61-
}
6258
if (data.transition_frontier.sync.status === 'Synced') {
6359
return AppNodeStatus.SYNCED;
60+
} else {
61+
if (data.transition_frontier.best_tip === null) {
62+
return AppNodeStatus.BOOTSTRAP;
63+
}
64+
return AppNodeStatus.CATCHUP;
6465
}
65-
return data.transition_frontier.sync.status as AppNodeStatus;
6666
}
6767
}
6868

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ export class BenchmarksWalletsComponent extends StoreDispatcher implements OnIni
2222
this.select(AppSelectors.activeNode, () => {
2323
this.dispatch(BenchmarksWalletsGetWallets, { initialRequest: true });
2424
}, filter(Boolean), skip(1));
25-
26-
// this.select(selectAppNodeStatus, (status: NodeStatus) => {
27-
// this.blockLevel = status.blockLevel;
28-
// this.dispatch(BenchmarksWalletsGetWallets);
29-
// }, filter(Boolean), filter(status => status.blockLevel !== this.blockLevel));
3025
}
3126

3227
override ngOnDestroy(): void {

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {
22
BENCHMARKS_WALLETS_CHANGE_FEE,
33
BENCHMARKS_WALLETS_CHANGE_TRANSACTION_BATCH,
4-
BENCHMARKS_WALLETS_CLOSE, BENCHMARKS_WALLETS_GET_ALL_TXS_SUCCESS,
4+
BENCHMARKS_WALLETS_CLOSE,
5+
BENCHMARKS_WALLETS_GET_ALL_TXS_SUCCESS,
56
BENCHMARKS_WALLETS_GET_WALLETS,
67
BENCHMARKS_WALLETS_GET_WALLETS_SUCCESS,
78
BENCHMARKS_WALLETS_SELECT_WALLET,
@@ -16,7 +17,7 @@ import {
1617
BenchmarksWalletTransactionStatus,
1718
} from '@shared/types/benchmarks/wallets/benchmarks-wallet.type';
1819
import { BenchmarksWalletTransaction } from '@shared/types/benchmarks/wallets/benchmarks-wallet-transaction.type';
19-
import { hasValue, lastItem, ONE_BILLION, toReadableDate } from '@openmina/shared';
20+
import { hasValue, lastItem, ONE_BILLION } from '@openmina/shared';
2021
import { BenchmarksWalletsState } from '@benchmarks/wallets/benchmarks-wallets.state';
2122
import { getTimeFromMemo } from '@shared/helpers/transaction.helper';
2223

@@ -98,8 +99,9 @@ export function reducer(state: BenchmarksWalletsState = initialState, action: Be
9899
from: wallet.publicKey,
99100
nonce,
100101
to: getRandomReceiver(wallet, state.wallets),
102+
// to: 'B62qp6QqfMrDGULkuCTMhLYrG4iTxnjnyS3pv8bFppRsz488HCxExEY', // Teo's ledger address
101103
fee: (state.sendingFee * ONE_BILLION).toString(),
102-
amount: '2000000000',
104+
amount: (2 * ONE_BILLION).toString(),
103105
memo,
104106
validUntil: '4294967295',
105107
};
@@ -121,7 +123,7 @@ export function reducer(state: BenchmarksWalletsState = initialState, action: Be
121123
nonce: nonce.toString(),
122124
to: state.wallets[i].publicKey,
123125
fee: (state.sendingFee * ONE_BILLION).toString(),
124-
amount: '2000000000',
126+
amount: (2 * ONE_BILLION).toString(),
125127
memo,
126128
validUntil: '4294967295',
127129
};

0 commit comments

Comments
 (0)