From 5a4336da3ccaeb5a6bbef0f19db150cccd67fd50 Mon Sep 17 00:00:00 2001 From: Rene Vergara A Date: Thu, 21 Jul 2022 23:06:23 -0500 Subject: [PATCH] Viewing key error messages implemented partially --- CHANGELOG.md | 7 +++ src/app/app.component.ts | 1 + src/app/app.module.ts | 6 ++- src/app/settings/settings.component.ts | 36 ++++++-------- src/app/show-error/show-error.component.css | 21 ++++++++ src/app/show-error/show-error.component.html | 8 ++++ .../show-error/show-error.component.spec.ts | 23 +++++++++ src/app/show-error/show-error.component.ts | 21 ++++++++ src/app/user.service.ts | 48 ++++++++++++------- src/styles.css | 1 + 10 files changed, 132 insertions(+), 40 deletions(-) create mode 100644 src/app/show-error/show-error.component.css create mode 100644 src/app/show-error/show-error.component.html create mode 100644 src/app/show-error/show-error.component.spec.ts create mode 100644 src/app/show-error/show-error.component.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 96f7431..e724654 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Changed +- (2022-07-21) user.service.ts + - Function updateOwner() removed - not needed anymore. + - Response Error 500 (Invalid Viewing Key) catched in + function addOwner() + - Beta version of Invalid viewing key message (snackbar) + implemented and working. + ToDo -> CSS definition. - (2022-07-20) Buttons in Main form have been enclosed to display inside a fixed area. On wide screens, new Order will display below main buttons. diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 8dad2f4..4c00724 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -6,6 +6,7 @@ import { Component } from '@angular/core'; templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) + export class AppComponent { //StoredPosts: Post[] = []; title = 'sell4zec'; diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 97b2df0..89c27b0 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -16,6 +16,7 @@ import { MatSelectModule } from '@angular/material/select'; import { MatProgressBarModule } from '@angular/material/progress-bar'; import { MatStepperModule } from '@angular/material/stepper'; import { MatSlideToggleModule } from '@angular/material/slide-toggle'; +import { MatSnackBarModule } from '@angular/material/snack-bar'; import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; @@ -41,6 +42,7 @@ import { ReceiptQRComponent } from './receipt-qr/receipt-qr.component'; import { InvoiceComponent } from './invoice/invoice.component'; import { FontAwesomeModule } from '@fortawesome/angular-fontawesome'; import { PromptInvoiceComponent } from './prompt-invoice/prompt-invoice.component'; +import { ShowErrorComponent } from './show-error/show-error.component'; @NgModule({ declarations: [ @@ -64,7 +66,8 @@ import { PromptInvoiceComponent } from './prompt-invoice/prompt-invoice.componen ReceiptComponent, ReceiptQRComponent, InvoiceComponent, - PromptInvoiceComponent + PromptInvoiceComponent, + ShowErrorComponent ], imports: [ BrowserModule, @@ -86,6 +89,7 @@ import { PromptInvoiceComponent } from './prompt-invoice/prompt-invoice.componen MatStepperModule, MatAutocompleteModule, MatSlideToggleModule, + MatSnackBarModule, BrowserAnimationsModule, FontAwesomeModule ], diff --git a/src/app/settings/settings.component.ts b/src/app/settings/settings.component.ts index 277c0ff..9e68c2f 100644 --- a/src/app/settings/settings.component.ts +++ b/src/app/settings/settings.component.ts @@ -39,23 +39,20 @@ export class SettingsComponent implements OnInit { constructor( private fb: UntypedFormBuilder, private dialogRef: MatDialogRef, - @Inject(MAT_DIALOG_DATA) public data: Owner - ) { - this.useZats = data.zats; - this.useVKey = data.payconf; - this.settingsForm = fb.group({ - name: [data.name, Validators.required], - currency: [data.currency, Validators.required], - useZats: [data.zats, Validators.required], - useVKey: [data.payconf, Validators.required], - vKey: [data.viewkey] - }); - if (data.payconf) { - this.settingsForm.get('vKey')!.enable(); - } - this.owner = data; - - + @Inject(MAT_DIALOG_DATA) public data: Owner) { + this.useZats = data.zats; + this.useVKey = data.payconf; + this.settingsForm = fb.group({ + name: [data.name, Validators.required], + currency: [data.currency, Validators.required], + useZats: [data.zats, Validators.required], + useVKey: [data.payconf, Validators.required], + vKey: [data.viewkey] + }); + if (data.payconf) { + this.settingsForm.get('vKey')!.enable(); + } + this.owner = data; } ngOnInit() { @@ -66,19 +63,14 @@ export class SettingsComponent implements OnInit { } save() { - console.log('===> Saving Settins '); - console.log('viewnkey from Form: ' + this.settingsForm.value.vKey); - console.log('payconf from Form: ' + (this.settingsForm.value.useVKey?"On":"Off")); this.owner.name = this.settingsForm.value.name; this.owner.currency = this.settingsForm.value.currency; this.owner.zats = this.settingsForm.value.useZats; this.owner.payconf = this.settingsForm.value.useVKey; this.owner.viewkey = this.settingsForm.value.vKey; - console.log('Save Settings from Owner.viewkey :' + this.owner.viewkey); this.dialogRef.close(this.owner); - console.log("===> Settings dialog closed") } onChange(ob: MatSlideToggleChange) { diff --git a/src/app/show-error/show-error.component.css b/src/app/show-error/show-error.component.css new file mode 100644 index 0000000..b3b4528 --- /dev/null +++ b/src/app/show-error/show-error.component.css @@ -0,0 +1,21 @@ +.green-snackbar { + background: rgb(65, 252, 134); + color: white; +} + +.green-snackbar button { + background-color: rgb(65, 252, 134); + color: white; + border: none; +} + +.red-snackbar { + background: #F44336; + color: white; +} + +.red-snackbar button { + background-color: #F44336; + color: white !important; + border: none; +} \ No newline at end of file diff --git a/src/app/show-error/show-error.component.html b/src/app/show-error/show-error.component.html new file mode 100644 index 0000000..8ba2676 --- /dev/null +++ b/src/app/show-error/show-error.component.html @@ -0,0 +1,8 @@ +
+
{{ data }}
+
+ +
+
diff --git a/src/app/show-error/show-error.component.spec.ts b/src/app/show-error/show-error.component.spec.ts new file mode 100644 index 0000000..2438453 --- /dev/null +++ b/src/app/show-error/show-error.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ShowErrorComponent } from './show-error.component'; + +describe('ShowErrorComponent', () => { + let component: ShowErrorComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ ShowErrorComponent ] + }) + .compileComponents(); + + fixture = TestBed.createComponent(ShowErrorComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/show-error/show-error.component.ts b/src/app/show-error/show-error.component.ts new file mode 100644 index 0000000..a724d92 --- /dev/null +++ b/src/app/show-error/show-error.component.ts @@ -0,0 +1,21 @@ +import { Component, OnInit, Inject } from '@angular/core'; +import { MatSnackBarRef, MAT_SNACK_BAR_DATA } from "@angular/material/snack-bar"; + +@Component({ + selector: 'app-show-error', + templateUrl: './show-error.component.html', + styleUrls: ['./show-error.component.css'] +}) + + +export class ShowErrorComponent implements OnInit { + + constructor( + public sbRef: MatSnackBarRef, + @Inject(MAT_SNACK_BAR_DATA) public data: any + ) { } + + ngOnInit(): void { + } + +} diff --git a/src/app/user.service.ts b/src/app/user.service.ts index e0eca80..42be39f 100644 --- a/src/app/user.service.ts +++ b/src/app/user.service.ts @@ -1,10 +1,14 @@ -import {Injectable} from '@angular/core'; -import {Subject, BehaviorSubject, Observable} from 'rxjs'; -import {HttpClient, HttpParams, HttpHeaders} from '@angular/common/http'; -import {User} from './user.model'; -import {Owner} from './owner.model'; +import { Injectable } from '@angular/core'; +import { Subject, BehaviorSubject, Observable } from 'rxjs'; + +import { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http'; +import { MatSnackBar } from '@angular/material/snack-bar'; +//import { ShowErrorComponent } from './show-error/show-error.component'; + +import { User } from './user.model'; +import { Owner } from './owner.model'; import { Country } from './country.model'; -import {Tx} from './tx.model'; +import { Tx } from './tx.model'; import { ConfigData } from './configdata'; @@ -69,7 +73,8 @@ export class UserService{ public readonly countriesUpdate: Observable = this._countriesUpdated.asObservable(); private reqHeaders: HttpHeaders; - constructor(private http: HttpClient){ + constructor(private http: HttpClient, + private _snackBar: MatSnackBar){ var auth = 'Basic ' + Buffer.from(ConfigData.UsrPwd).toString('base64'); this.reqHeaders = new HttpHeaders().set('Authorization', auth); //console.log('US:', this.reqHeaders); @@ -142,26 +147,31 @@ export class UserService{ } addOwner(owner: Owner) { + owner.address = this.dataStore.user.address; let obs = this.http.post(this.beUrl+'api/owner', {payload: owner}, {headers: this.reqHeaders}); obs.subscribe((responseData) => { + console.log("Entra a console log"); this.getOwner(this.dataStore.user.address); + }, (error) => { + console.log("Status is : [" + error.status + "]"); + if ( error.status = 500 ) { + let sb = this._snackBar.open("Error: Invalid Viewing Key", + "Close", + { duration: 4000, + panelClass: ["green-snackbar"] + } + ); + sb.onAction().subscribe(() => { + sb.dismiss(); + }); + }; }); return obs; } - updateOwner(owner: Owner) { - this.http.post<{message: string, owner: Owner}>(this.beUrl+'api/updateowner', {owner: owner}, {headers: this.reqHeaders}). - subscribe((responseData) => { - //console.log(responseData.message); - this.dataStore.owner = responseData.owner; - this._ownerUpdated.next(Object.assign({},this.dataStore).owner); - }); - } - - getOwner(address: string) { console.log('getOwner', address); const ownParams = new HttpParams().append('address', address); @@ -194,4 +204,8 @@ export class UserService{ return obs; } + + openSnackBar(message: string, action: string) { + this._snackBar.open(message, action); + } } diff --git a/src/styles.css b/src/styles.css index 8c7b963..75a3d95 100644 --- a/src/styles.css +++ b/src/styles.css @@ -25,3 +25,4 @@ body { margin: 0; font-family: 'Spartan', sans-serif; } +