Skip to content

Commit

Permalink
Issue 102
Browse files Browse the repository at this point in the history
  • Loading branch information
Nazar Usov authored and Nazar Usov committed Mar 1, 2024
1 parent 57bbc97 commit d3811cb
Show file tree
Hide file tree
Showing 36 changed files with 344 additions and 136 deletions.
19 changes: 14 additions & 5 deletions html_source/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import { paths, pathsChildrenAuth } from './pages/paths';
import { hasOwnProperty } from '@parts/functions/hasOwnProperty';
import { Dialog } from '@angular/cdk/dialog';
import { ParamsCallRpc } from '@api/models/call_rpc.model';
import { ZanoLoadersService } from '@parts/services/zano-loaders.service';

@Component({
selector: 'app-root',
template: `
<router-outlet *ngIf="[0, 1, 2, 6].indexOf(variablesService.daemon_state) !== -1"></router-outlet>
<router-outlet *ngIf="[0, 1, 2, 6].indexOf(variablesService.daemon_state) !== -1 && !(zanoLoadersService.getState('fullScreen') | async)"></router-outlet>
<div *ngIf="[3, 4, 5].indexOf(variablesService.daemon_state) !== -1" class="preloader">
<p *ngIf="variablesService.daemon_state === 3" class="mb-2">
Expand All @@ -33,6 +34,13 @@ import { ParamsCallRpc } from '@api/models/call_rpc.model';
<div class="loading-bar"></div>
</div>
<div class="preloader" *ngIf="zanoLoadersService.getState('fullScreen') | async">
<p class="mb-2">
{{ zanoLoadersService.getMessage('fullScreen') | async | translate }}
</p>
<div class="loading-bar"></div>
</div>
<app-register-context-templates></app-register-context-templates>
<app-open-wallet-modal *ngIf="needOpenWallets.length" [wallets]="needOpenWallets"></app-open-wallet-modal>
Expand Down Expand Up @@ -66,7 +74,8 @@ export class AppComponent implements OnInit, OnDestroy {
private intToMoneyPipe: IntToMoneyPipe,
private modalService: ModalService,
private store: Store,
private dialog: Dialog
private dialog: Dialog,
public zanoLoadersService: ZanoLoadersService
) {
translate.addLangs(['en', 'fr', 'de', 'it', 'pt']);
translate.setDefaultLang('en');
Expand Down Expand Up @@ -117,9 +126,9 @@ export class AppComponent implements OnInit, OnDestroy {
return;
}

await this.ngZone.run(async () => {
await this.router.navigate(['/']);
});
// await this.ngZone.run(async () => {
// await this.router.navigate(['/']);
// });

this.dialog.closeAll();
this.needOpenWallets = [];
Expand Down
22 changes: 15 additions & 7 deletions html_source/src/app/layouts/sidebar/sidebar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ConfirmModalComponent, ConfirmModalData } from '@parts/modals/confirm-m
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { WalletsService } from '@parts/services/wallets.service';
import { ZanoLoadersService } from '@parts/services/zano-loaders.service';

@Component({
selector: 'app-sidebar',
Expand Down Expand Up @@ -101,7 +102,8 @@ export class SidebarComponent implements OnDestroy {
private route: ActivatedRoute,
private router: Router,
private ngZone: NgZone,
private dialog: Dialog
private dialog: Dialog,
public zanoLoadersService: ZanoLoadersService
) {}

ngOnDestroy(): void {
Expand Down Expand Up @@ -153,11 +155,17 @@ export class SidebarComponent implements OnDestroy {
}

logOut(): void {
this.variablesService.stopCountdown();
this.variablesService.appLogin = false;
this.variablesService.appPass = '';
this.ngZone.run(() => {
this.router.navigate(['/login'], { queryParams: { type: 'auth' } });
});
this.zanoLoadersService.open('fullScreen', 'SIDEBAR.SYNCHRONIZATION.LOGGING_OUT');

setTimeout(() => {
this.variablesService.stopCountdown();
this.variablesService.appLogin = false;
this.variablesService.appPass = '';
this.ngZone.run(() => {
this.router.navigate(['/login'], { queryParams: { type: 'auth' } }).then(() => {
this.zanoLoadersService.close('fullScreen');
});
});
}, 500);
}
}
82 changes: 55 additions & 27 deletions html_source/src/app/pages/auth/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { BackendService } from '@api/services/backend.service';
import { VariablesService } from '@parts/services/variables.service';
import { Wallet } from '@api/models/wallet.model';
import { hasOwnProperty } from '@parts/functions/hasOwnProperty';
import { Subject } from 'rxjs';
import { BehaviorSubject, Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { regExpPassword, ZanoValidators } from '@parts/utils/zano-validators';
import { WalletsService } from '@parts/services/wallets.service';
Expand Down Expand Up @@ -112,16 +112,20 @@ import { WalletsService } from '@parts/services/wallets.service';
</div>
<button class="primary big w-100 mb-1" type="submit">
{{ 'LOGIN.BUTTON_NEXT' | translate }}
<span class="ml-1" *ngIf="submitLoading$ | async" [ngTemplateOutlet]="loaderTemp"></span>
</button>
<button (click)="dropSecureAppData()" class="outline big w-100" type="button">
{{ 'LOGIN.BUTTON_RESET' | translate }}
<span class="ml-1" *ngIf="resetLoading$ | async" [ngTemplateOutlet]="loaderTemp"></span>
</button>
</form>
</div>
<app-synchronization-status class="max-w-19-rem"></app-synchronization-status>
</div>
<ng-template #loaderTemp><zano-loader></zano-loader></ng-template>
`,
styles: [
`
Expand All @@ -134,6 +138,10 @@ import { WalletsService } from '@parts/services/wallets.service';
],
})
export class LoginComponent implements OnInit, OnDestroy {
submitLoading$ = new BehaviorSubject(false);

resetLoading$ = new BehaviorSubject(false);

fb = inject(FormBuilder);

regForm = this.fb.group(
Expand Down Expand Up @@ -211,38 +219,53 @@ export class LoginComponent implements OnInit, OnDestroy {
}

dropSecureAppData(): void {
this.backend.dropSecureAppData(() => {
this.onSkipCreatePass();
});
this.closeAllWallets();
this.variablesService.contacts = [];
this.resetLoading$.next(true);

// This delay is necessary for the loader to display, as the application freezes for a few seconds
setTimeout(() => {
this.backend.dropSecureAppData(() => {
this.resetLoading$.next(false);
this.onSkipCreatePass();
});
this.closeAllWallets();
this.variablesService.contacts = [];
}, 500);
}

onSubmitAuthPass(): void {
if (this.authForm.valid) {
this.variablesService.appPass = this.authForm.get('password').value;
if (this.variablesService.dataIsLoaded) {
this.backend.checkMasterPassword({ pass: this.variablesService.appPass }, status => {
if (status) {
this.variablesService.appLogin = true;
if (this.variablesService.settings.appLockTime) {
this.variablesService.startCountdown();
}
this.ngZone.run(() => {
this.router.navigate(['/'], {
queryParams: { prevUrl: 'login' },
this.submitLoading$.next(true);

// This delay is necessary for the loader to display, as the application freezes for a few seconds
setTimeout(() => {
if (this.authForm.valid) {
this.variablesService.appPass = this.authForm.get('password').value;
if (this.variablesService.dataIsLoaded) {
this.backend.checkMasterPassword({ pass: this.variablesService.appPass }, status => {
if (status) {
this.variablesService.appLogin = true;
if (this.variablesService.settings.appLockTime) {
this.variablesService.startCountdown();
}
this.ngZone.run(() => {
this.submitLoading$.next(false);
this.router.navigate(['/'], {
queryParams: { prevUrl: 'login' },
});
});
});
} else {
this.ngZone.run(() => {
this.setAuthPassError({ wrong_password: true });
});
}
});
} else {
this.ngZone.run(() => {
this.submitLoading$.next(false);
this.setAuthPassError({ wrong_password: true });
});
}
});
} else {
this.getData(this.variablesService.appPass);
}
} else {
this.getData(this.variablesService.appPass);
this.submitLoading$.next(false);
}
}
}, 500);
}

getData(appPass): void {
Expand All @@ -259,6 +282,7 @@ export class LoginComponent implements OnInit, OnDestroy {

if (this.variablesService.wallets.length > 0) {
this.ngZone.run(() => {
this.submitLoading$.next(false);
this.router.navigate(['/wallet/']);
});
return;
Expand All @@ -275,6 +299,7 @@ export class LoginComponent implements OnInit, OnDestroy {
this.getWalletData(data['wallets']);
} else {
this.ngZone.run(() => {
this.submitLoading$.next(false);
this.router.navigate(['/']);
});
}
Expand All @@ -284,6 +309,7 @@ export class LoginComponent implements OnInit, OnDestroy {
this.getWalletData(data);
} else {
this.ngZone.run(() => {
this.submitLoading$.next(false);
this.router.navigate(['/']);
});
}
Expand All @@ -292,6 +318,7 @@ export class LoginComponent implements OnInit, OnDestroy {

if (data.error_code === 'WRONG_PASSWORD') {
this.ngZone.run(() => {
this.submitLoading$.next(false);
this.setAuthPassError({ wrong_password: true });
});
}
Expand Down Expand Up @@ -365,6 +392,7 @@ export class LoginComponent implements OnInit, OnDestroy {
}
});
});
this.submitLoading$.next(false);
}

closeAllWallets(): void {
Expand Down
23 changes: 21 additions & 2 deletions html_source/src/app/pages/create-wallet/create-wallet.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { TranslateService } from '@ngx-translate/core';
import { regExpPassword, ZanoValidators } from '@parts/utils/zano-validators';
import { WalletsService } from '@parts/services/wallets.service';
import { BreadcrumbItems } from '@parts/components/breadcrumbs/breadcrumbs.models';
import { BehaviorSubject } from 'rxjs';

@Component({
selector: 'app-create-wallet',
Expand Down Expand Up @@ -118,11 +119,14 @@ import { BreadcrumbItems } from '@parts/components/breadcrumbs/breadcrumbs.model
<button (click)="createWallet()" [disabled]="createForm.invalid" class="primary big w-100" type="button">
{{ 'CREATE_WALLET.BUTTON_CREATE' | translate }}
<span class="ml-1" *ngIf="loading$ | async" [ngTemplateOutlet]="loaderTemp"></span>
</button>
</form>
</div>
</div>
</div>
<ng-template #loaderTemp><zano-loader></zano-loader></ng-template>
`,
styles: [
`
Expand All @@ -137,6 +141,8 @@ import { BreadcrumbItems } from '@parts/components/breadcrumbs/breadcrumbs.model
export class CreateWalletComponent {
variablesService = inject(VariablesService);

loading$ = new BehaviorSubject(false);

breadcrumbItems: BreadcrumbItems = [
{
routerLink: '/add-wallet',
Expand Down Expand Up @@ -179,8 +185,12 @@ export class CreateWalletComponent {
}

createWallet(): void {
const { path: selectedPath, password, name } = this.createForm.getRawValue();
this.backend.generateWallet(selectedPath, password, async (generate_status, generate_data, errorCode) => {
this.loading$.next(true);

// This delay is necessary for the loader to display, as the application freezes for a few seconds
setTimeout(() => {
const { path: selectedPath, password, name } = this.createForm.getRawValue();
this.backend.generateWallet(selectedPath, password, async (generate_status, generate_data, errorCode) => {
if (generate_status) {
const { wallet_id } = generate_data;
const { path, address, balance, unlocked_balance, mined_total, tracking_hey } = generate_data['wi'];
Expand All @@ -198,18 +208,27 @@ export class CreateWalletComponent {
this.backend.storeSecureAppData();
}
this.variablesService.setCurrentWallet(wallet_id);
this.loading$.next(false);
await this.router.navigate(['/seed-phrase'], { queryParams: { wallet_id } });
});
} else {
console.log(run_data['error_code']);
this.ngZone.run(() => {
this.loading$.next(false);
});
}
});
} else {
const errorTranslationKey =
errorCode === 'ALREADY_EXISTS' ? 'CREATE_WALLET.ERROR_CANNOT_SAVE_TOP' : 'CREATE_WALLET.ERROR_CANNOT_SAVE_SYSTEM';
this.modalService.prepareModal('error', errorTranslationKey);

this.ngZone.run(() => {
this.loading$.next(false);
});
}
});
}, 500);
}

selectWalletLocation(): void {
Expand Down
Loading

0 comments on commit d3811cb

Please sign in to comment.