From 2f610c8f7f339656d7eac1f53579b732f88219f7 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Thu, 18 Nov 2021 16:38:25 -0600 Subject: [PATCH 1/5] Implement stepper for login --- backend/app.js | 13 ++-- backend/models/tx.js | 2 +- backend/models/zectxs.js | 12 ++++ src/app/app.module.ts | 4 ++ src/app/login/login.component.html | 103 +++++++++++++---------------- src/app/login/login.component.ts | 40 ++++++++--- 6 files changed, 97 insertions(+), 77 deletions(-) create mode 100644 backend/models/zectxs.js diff --git a/backend/app.js b/backend/app.js index 47356c6..b5cc3d3 100644 --- a/backend/app.js +++ b/backend/app.js @@ -10,6 +10,7 @@ const itemmodel = require('./models/item'); const ordermodel = require('./models/order'); const pricemodel = require('./models/price'); const txmodel = require('./models/tx'); +const zecTxModel = require('./models/zectxs.js'); const mongoose = require('mongoose'); const stdrpc = require('stdrpc'); const CoinGecko = require('coingecko-api'); @@ -99,7 +100,7 @@ var blockInterval = setInterval( function() { var re = /.*ZGO::(.*)\sReply-To:\s(z\w+)/; async.each (txs, function(txData, callback) { var memo = hexToString(txData.memo).replace(/\0/g, ''); - txmodel.updateOne({txid: txData.txid}, { confirmations: txData.confirmations, amount:txData.amount, memo: memo}, {new:true, upsert:true}, function(err,docs) { + zecTxModel.updateOne({txid: txData.txid}, { txid: txData.txid, confirmations: txData.confirmations, amount:txData.amount, memo: memo}, {new:true, upsert:true}, function(err,docs) { if (err) { console.log(err); } @@ -114,16 +115,14 @@ var blockInterval = setInterval( function() { var amount = txData.amount; var expiration = blocktime; //console.log(' ', session, blocktime); - txmodel.updateOne({txid: txData.txid}, { address: address, session: session, confirmations: txData.confirmations, amount:txData.amount, memo: memo}, {new:true, upsert:true}, function(err,docs) { + txmodel.updateOne({txid: txData.txid}, { txid: txData.txid, address: address, session: session, confirmations: txData.confirmations, amount:txData.amount, memo: memo}, {new:true, upsert:true}, function(err,docs) { if (err) { console.log(err); } }); if (txData.confirmations >= 6 ) { usermodel.findOne({address: address, session: session, blocktime: blocktime}).then(function(doc){ - if (doc != null) { - console.log('Found user'); - } else { + if (doc == null){ console.log('User not found', session, blocktime, amount); if (amount >= 0.001 && amount < 0.005){ expiration = blocktime + 3600; @@ -152,9 +151,7 @@ var blockInterval = setInterval( function() { } }); ownermodel.findOne({address: address}).then(function (oDoc) { - if (oDoc != null) { - console.log('Found owner'); - } else { + if (oDoc == null) { console.log('Owner not found', session); var owner = new ownermodel({ address: address, diff --git a/backend/models/tx.js b/backend/models/tx.js index 570b325..0140616 100644 --- a/backend/models/tx.js +++ b/backend/models/tx.js @@ -5,7 +5,7 @@ const txSchema = mongoose.Schema({ session: {type: String, required:true}, confirmations: {type: Number, required:true}, amount: {type: Number, required:true}, - txid: {type:String, required:true}, + txid: {type:String, required:true, unique: true}, memo: {type:String} }); diff --git a/backend/models/zectxs.js b/backend/models/zectxs.js new file mode 100644 index 0000000..8ad2553 --- /dev/null +++ b/backend/models/zectxs.js @@ -0,0 +1,12 @@ +const mongoose = require('mongoose'); + +const ZecTxSchema = mongoose.Schema({ + address: {type: String}, + session: {type: String, required:true}, + confirmations: {type: Number, required:true}, + amount: {type: Number, required:true}, + txid: {type:String, required:true, unique: true}, + memo: {type:String} +}); + +module.exports = mongoose.model('ZecTx', ZecTxSchema); diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 8772c3c..2cb527c 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -12,6 +12,8 @@ import { MatIconModule } from '@angular/material/icon'; import { MatDividerModule } from '@angular/material/divider'; import { MatListModule } from '@angular/material/list'; import { MatSelectModule } from '@angular/material/select'; +import { MatProgressBarModule } from '@angular/material/progress-bar'; +import { MatStepperModule } from '@angular/material/stepper'; import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; @@ -63,6 +65,8 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; MatDividerModule, MatListModule, MatSelectModule, + MatProgressBarModule, + MatStepperModule, BrowserAnimationsModule ], exports: [ diff --git a/src/app/login/login.component.html b/src/app/login/login.component.html index 032e8c5..f6e1cb0 100644 --- a/src/app/login/login.component.html +++ b/src/app/login/login.component.html @@ -19,62 +19,51 @@

The Zcash Register

-
-
    -
  1. - Select your session length. -
  2. -
  3. - Confirm you've sent your shielded memo. -
  4. -
  5. - Wait for confirmation of your transaction on the Zcash blockchain (~10 minutes). -
  6. -
  7. - Enter the PIN provided by ZGo to your wallet to confirm ownership. -
  8. -
-
-
-

Expecting confirmation around block {{targetBlock}}.

-
-
- -

- Check your wallet -

- - PIN - - - - - -
- -

Login received!

- - It needs {{6 - tx.confirmations}} more confirmations. - -
- -
- - Session length - - - {{ticket.viewValue}} - - - -

Wrong pin!

- - - -
+ + + +
+

Select your session length and confirm once you've sent your memo:

+ + Session length + + + {{ticket.viewValue}} + + + + + + +
+
+
+ +

{{barMessage}}

+ + +
+ + +

+ Check your wallet +

+ + PIN + + +

Wrong pin!

+ + + +
+
+
diff --git a/src/app/login/login.component.ts b/src/app/login/login.component.ts index 9ec2ca3..131515d 100644 --- a/src/app/login/login.component.ts +++ b/src/app/login/login.component.ts @@ -1,7 +1,9 @@ -import { Component, OnInit, OnDestroy, Injectable, ChangeDetectorRef } from '@angular/core'; +import { Component, OnInit, OnDestroy, Injectable, ChangeDetectorRef, ViewChild, AfterViewInit } from '@angular/core'; import { CanActivate, Router, RouterStateSnapshot, ActivatedRouteSnapshot, ActivatedRoute } from '@angular/router'; import { MatDialog, MatDialogConfig} from '@angular/material/dialog'; import { FormBuilder, Validators, FormGroup, FormControl } from '@angular/forms'; +import { ProgressBarMode } from '@angular/material/progress-bar'; +import { MatStepper } from '@angular/material/stepper'; import { UserService } from '../user.service'; import { FullnodeService } from '../fullnode.service'; import { ScanComponent} from '../scan/scan.component'; @@ -21,7 +23,7 @@ var Buffer = require('buffer/').Buffer; styleUrls: ['./login.component.css'] }) -export class LoginComponent implements OnInit { +export class LoginComponent implements OnInit, AfterViewInit { txs: Tx[] = []; intervalHolder: any; nodeAddress: string = ''; @@ -57,10 +59,15 @@ export class LoginComponent implements OnInit { prompt: boolean = false; confirmedMemo: boolean = false; targetBlock: number = 0; + barMode: ProgressBarMode = 'indeterminate'; + barValue = 0; + barMessage = 'Scanning blockchain for login memo, please wait.'; + @ViewChild('stepper') private myStepper?: MatStepper; entryForm: FormGroup; pinForm: FormGroup; + constructor( private fb: FormBuilder, private activatedRoute: ActivatedRoute, @@ -89,7 +96,8 @@ export class LoginComponent implements OnInit { }); } - ngOnInit(){ + ngAfterViewInit(){ + //console.log('Step', this.myStepper); this.pinError = false; //console.log('Activated route data in Component:::', this.activatedRoute.data); this.activatedRoute.data.subscribe((addrData) => { @@ -105,12 +113,15 @@ export class LoginComponent implements OnInit { } this.loginCheck(); }); + } + + ngOnInit(){ this.intervalHolder = setInterval(() => { this.fullnodeService.getHeight(); //this.userService.findUser(); this.loginCheck(); this._changeDetectorRef.markForCheck(); - }, 1000 * 75); + }, 1000 * 60); } loginCheck(){ @@ -122,16 +133,24 @@ export class LoginComponent implements OnInit { }); this.userUpdate.subscribe((user) => { if (user.expiration > today) { - this.prompt = true; - console.log('Log in found in blockchain!'); + if(this.myStepper!.selectedIndex === 1){ + this.myStepper!.next(); + } + //console.log('Log in found in blockchain!'); if (user.validated) { this.router.navigate(['/shop']); } } }); + if (this.txs.length > 0) { + this.barMode = 'determinate'; + this.barValue = (this.txs[0].confirmations / 6) * 100; + this.confirmedMemo = true; + this.barMessage = 'Login memo found, awaiting confirmations'; + } } - login() { + login(stepper: MatStepper) { //console.log('Dropdown:', this.entryForm.value.selectedSession); const dialogConfig = new MatDialogConfig(); @@ -146,10 +165,9 @@ export class LoginComponent implements OnInit { const dialogRef = this.dialog.open(ScanComponent, dialogConfig); dialogRef.afterClosed().subscribe((val) => { console.log('Awaiting confirmation'); - this.confirmedMemo = val; - this.heightUpdate.pipe(take(1)).subscribe(block => { - this.targetBlock = block + 10; - }); + if(val){ + stepper.next(); + } }); } From c1c60a4e2084eba7e0fea992f43cc3a3d7fb32e0 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Thu, 18 Nov 2021 16:40:19 -0600 Subject: [PATCH 2/5] Improved wording for login --- src/app/login/login.component.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/login/login.component.html b/src/app/login/login.component.html index f6e1cb0..188fb77 100644 --- a/src/app/login/login.component.html +++ b/src/app/login/login.component.html @@ -40,14 +40,14 @@ - +

{{barMessage}}

- +

Check your wallet From 078916f92de3c863efb21ca3657806f408df4105 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Thu, 18 Nov 2021 16:49:34 -0600 Subject: [PATCH 3/5] Change stepper to not editable --- src/app/login/login.component.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/login/login.component.html b/src/app/login/login.component.html index 188fb77..5c7c190 100644 --- a/src/app/login/login.component.html +++ b/src/app/login/login.component.html @@ -20,7 +20,7 @@

The Zcash Register

- +

Select your session length and confirm once you've sent your memo:

@@ -40,7 +40,7 @@
- +

{{barMessage}}

Date: Mon, 22 Nov 2021 14:37:45 -0600 Subject: [PATCH 4/5] Implement flexible currency --- backend/app.js | 20 +++++++----- backend/models/order.js | 1 + backend/models/owner.js | 7 +++- src/app/fullnode.service.ts | 32 +++++++++++-------- src/app/header/header.component.html | 1 + src/app/header/header.component.ts | 16 ++++++++-- .../items/item-list/item-list.component.html | 2 +- .../items/item-list/item-list.component.ts | 17 ++++++++-- src/app/listorders/listorders.component.html | 2 +- src/app/order/order.component.html | 2 +- src/app/order/order.component.ts | 22 ++++++++++++- src/app/order/order.model.ts | 1 + src/app/order/order.service.ts | 22 ++++++++++++- src/app/owner.model.ts | 5 +++ src/app/settings/settings.component.html | 11 ++++++- src/app/settings/settings.component.ts | 22 ++++++++++++- src/app/user.service.ts | 18 +++++++++-- src/app/viewer/viewer.component.ts | 14 ++++++-- 18 files changed, 177 insertions(+), 38 deletions(-) diff --git a/backend/app.js b/backend/app.js index b5cc3d3..7944318 100644 --- a/backend/app.js +++ b/backend/app.js @@ -100,12 +100,14 @@ var blockInterval = setInterval( function() { var re = /.*ZGO::(.*)\sReply-To:\s(z\w+)/; async.each (txs, function(txData, callback) { var memo = hexToString(txData.memo).replace(/\0/g, ''); - zecTxModel.updateOne({txid: txData.txid}, { txid: txData.txid, confirmations: txData.confirmations, amount:txData.amount, memo: memo}, {new:true, upsert:true}, function(err,docs) { - if (err) { - console.log(err); - } - }); - if (re.test(memo)) { + if (!txData.change) { + zecTxModel.updateOne({txid: txData.txid}, { txid: txData.txid, confirmations: txData.confirmations, amount:txData.amount, memo: memo}, {new:true, upsert:true}, function(err,docs) { + if (err) { + console.log(err); + } + }); + } + if (re.test(memo) && txData.confirmations < 100) { //console.log('Processing tx:', memo); var match = re.exec(memo); if (match != null) { @@ -180,7 +182,7 @@ var blockInterval = setInterval( function() { }); }); -}, 90000); +}, 75000); app.use(cors()); app.options('*', cors()); @@ -346,6 +348,7 @@ app.post('/api/updateowner', (req, res, next) => { if (err) { console.log(err); } else { + console.log(docs); res.status(201).json({ message: 'Owner updated', owner: docs @@ -418,7 +421,7 @@ app.delete('/api/item/:id', (req, res, next) => { app.get('/api/price', (req, res, next) => { console.log('Get /api/price'); - const price = pricemodel.findOne({currency: 'usd'}).then((document) => { + const price = pricemodel.findOne({currency: req.query.currency}).then((document) => { if (document != null) { res.status(200).json({ message: 'price found!', @@ -492,6 +495,7 @@ app.post('/api/order', (req, res, next) => { session: req.body.order.session, price: req.body.order.price, total: req.body.order.total, + currency: req.body.order.currency, totalZec: req.body.order.totalZec, closed: req.body.order.closed }, function(err, docs) { diff --git a/backend/models/order.js b/backend/models/order.js index 64110f9..70044da 100644 --- a/backend/models/order.js +++ b/backend/models/order.js @@ -6,6 +6,7 @@ const orderSchema = mongoose.Schema({ timestamp: {type: Date, required: true, default: Date.now}, closed: { type: Boolean, required: true, default:false }, price: { type: Number, required: true}, + currency: {type: String, required: true}, total: { type: Number}, totalZec: {type: Number}, lines: [{ diff --git a/backend/models/owner.js b/backend/models/owner.js index 195f809..040d7f5 100644 --- a/backend/models/owner.js +++ b/backend/models/owner.js @@ -2,7 +2,12 @@ const mongoose = require('mongoose'); const ownerSchema = mongoose.Schema({ address: {type: String, required:true, unique:true}, - name: {type: String, required:true} + name: {type: String, required:true}, + currency: {type: String, required:true, default: 'usd'}, + tax: {type: Boolean, required: true, default: false}, + taxValue: {type: Number }, + vat: {type: Boolean, required:true, default: false}, + vatValue: {type: Number } }); module.exports = mongoose.model('Owner', ownerSchema); diff --git a/src/app/fullnode.service.ts b/src/app/fullnode.service.ts index 950a0d9..602068a 100644 --- a/src/app/fullnode.service.ts +++ b/src/app/fullnode.service.ts @@ -2,6 +2,7 @@ import {Injectable} from '@angular/core'; import {Subject, Subscription, BehaviorSubject, Observable} from 'rxjs'; import {HttpClient, HttpParams, HttpHeaders} from '@angular/common/http'; import {UserService} from './user.service'; +import { Owner } from './owner.model'; //import {User} from './user.model'; @@ -17,15 +18,30 @@ export class FullnodeService{ public readonly heightUpdate: Observable = this._heightUpdated.asObservable(); public readonly memoUpdate: Observable = this._memoUpdated.asObservable(); public readonly priceUpdate: Observable = this._priceUpdated.asObservable(); + public readonly ownerUpdate: Observable; private UserSub: Subscription = new Subscription(); private apiKey = 'Le2adeic8Thah4Aeng4daem6i'; private reqHeaders: HttpHeaders; + private owner: Owner = { + _id: '', + name: '', + address: '', + currency: 'usd', + tax: false, + taxValue: 0, + vat: false, + vatValue: 0 + }; constructor(private http: HttpClient, public userService: UserService){ this.reqHeaders = new HttpHeaders().set('Authorization', this.apiKey); + this.ownerUpdate = userService.ownerUpdate; this.getAddr(); this.getHeight(); - this.getPrice(); + this.ownerUpdate.subscribe((owner) => { + this.owner = owner; + this.getPrice(this.owner.currency); + }); } getHeight(){ @@ -38,8 +54,8 @@ export class FullnodeService{ return obs; } - getPrice(){ - var currency = 'usd'; + getPrice(currency: string){ + //var currency = 'usd'; const params = new HttpParams().append('currency', currency); let obs = this.http.get<{message: string, price: any}>(this.beUrl+'api/price', { headers:this.reqHeaders, params: params, observe: 'response'}); obs.subscribe((PriceData) => { @@ -55,16 +71,6 @@ export class FullnodeService{ return obs; } - hexToString(hexString: string) { - var str = ''; - for (var n=0; n < hexString.length; n +=2) { - str += String.fromCharCode(parseInt(hexString.substr(n, 2), 16)); - } - return str; - } - - - getAddr() { let obs = this.http.get<{message: string, addr: string}>(this.beUrl+'api/getaddr', { headers: this.reqHeaders }); diff --git a/src/app/header/header.component.html b/src/app/header/header.component.html index dae1b4f..9be405b 100644 --- a/src/app/header/header.component.html +++ b/src/app/header/header.component.html @@ -4,6 +4,7 @@ +

Currency: {{ getCurrency() }}

Last block:

{{heightUpdate | async}}

diff --git a/src/app/header/header.component.ts b/src/app/header/header.component.ts index 4e88167..925fec6 100644 --- a/src/app/header/header.component.ts +++ b/src/app/header/header.component.ts @@ -15,7 +15,16 @@ import {Owner} from '../owner.model'; export class HeaderComponent implements OnInit, OnDestroy { public height = 0; - private owner: Owner= {_id:'', address: 'none', name:''}; + private owner: Owner= { + _id:'', + address: 'none', + name:'', + currency: 'usd', + tax: false, + taxValue: 0, + vat: false, + vatValue: 0 + }; private session: string | null = ''; public heightUpdate: Observable; public ownerUpdate: Observable; @@ -41,6 +50,7 @@ export class HeaderComponent implements OnInit, OnDestroy { ngOnDestroy(){ } - - + getCurrency(){ + return this.owner.currency.toUpperCase(); + } } diff --git a/src/app/items/item-list/item-list.component.html b/src/app/items/item-list/item-list.component.html index dc1518c..cf4d537 100644 --- a/src/app/items/item-list/item-list.component.html +++ b/src/app/items/item-list/item-list.component.html @@ -5,7 +5,7 @@ {{item.name}} -

{{item.cost | currency: 'USD'}}

+

{{item.cost | currency: getCurrency() }}

{{(item.cost/price) | number: '1.0-6'}}

diff --git a/src/app/items/item-list/item-list.component.ts b/src/app/items/item-list/item-list.component.ts index 4bfab70..a7f93ea 100644 --- a/src/app/items/item-list/item-list.component.ts +++ b/src/app/items/item-list/item-list.component.ts @@ -20,7 +20,16 @@ import { ItemAddComponent } from '../item-add/item-add.component'; export class ItemListComponent implements OnInit{ public items: Item[] = []; - private owner: Owner = {_id: '', name: '', address: ''}; + private owner: Owner = { + _id: '', + name: '', + address: '', + currency: 'usd', + tax: false, + taxValue: 0, + vat: false, + vatValue: 0 + }; public price: number = 1; public ownerUpdate: Observable; public itemsUpdate: Observable; @@ -38,7 +47,7 @@ export class ItemListComponent implements OnInit{ this.priceUpdate = fullnodeService.priceUpdate; this.ownerUpdate.subscribe((owner) => { this.owner = owner; - console.log('owner address', this.owner.address); + fullnodeService.getPrice(this.owner.currency); itemService.getItems(this.owner.address); this.itemsUpdate.subscribe((items) => { this.items = items; @@ -151,5 +160,9 @@ export class ItemListComponent implements OnInit{ this.itemService.getItems(this.owner.address); }); } + + getCurrency(){ + return this.owner.currency.toUpperCase(); + } } diff --git a/src/app/listorders/listorders.component.html b/src/app/listorders/listorders.component.html index fbb9e91..552c160 100644 --- a/src/app/listorders/listorders.component.html +++ b/src/app/listorders/listorders.component.html @@ -32,7 +32,7 @@

Order: {{order._id}}

-

Zcash price: {{order.price | currency: 'USD'}}

+

Zcash price: {{order.price | currency: order.currency.toUpperCase()}}

{{item.qty}} x {{item.name}} diff --git a/src/app/order/order.component.html b/src/app/order/order.component.html index cd07ec9..d8bada4 100644 --- a/src/app/order/order.component.html +++ b/src/app/order/order.component.html @@ -8,7 +8,7 @@ Order Total: -

{{total | currency: 'USD'}}

+

{{total | currency: getCurrency()}}

{{(total/price) | number: '1.0-6'}}

diff --git a/src/app/order/order.component.ts b/src/app/order/order.component.ts index 2f9987e..74e92e4 100644 --- a/src/app/order/order.component.ts +++ b/src/app/order/order.component.ts @@ -15,7 +15,23 @@ import { CheckoutComponent} from '../checkout/checkout.component'; }) export class OrderComponent implements OnInit{ - public order: Order = {address: '', session: '', timestamp: '', closed: false, price:0, total:0, totalZec: 0, lines: [{qty: 1, name: '', cost: 0}]}; + public order: Order = { + address: '', + session: '', + timestamp: '', + closed: false, + currency: '', + price:0, + total:0, + totalZec: 0, + lines: [ + { + qty: 1, + name: '', + cost: 0 + } + ] + }; public price: number = 1; public total: number = 0; public orderUpdate: Observable; @@ -87,4 +103,8 @@ export class OrderComponent implements OnInit{ } }); } + + getCurrency(){ + return this.order.currency.toUpperCase(); + } } diff --git a/src/app/order/order.model.ts b/src/app/order/order.model.ts index 5c5a1f2..435f480 100644 --- a/src/app/order/order.model.ts +++ b/src/app/order/order.model.ts @@ -6,6 +6,7 @@ export interface Order { session: string, timestamp?: string, closed: boolean, + currency: string, price?: number, total: number, totalZec: number, diff --git a/src/app/order/order.service.ts b/src/app/order/order.service.ts index 8d69190..18072cd 100644 --- a/src/app/order/order.service.ts +++ b/src/app/order/order.service.ts @@ -5,13 +5,14 @@ import { Order } from './order.model'; import { UserService } from '../user.service'; import { FullnodeService } from '../fullnode.service'; import { User } from '../user.model'; +import { Owner } from '../owner.model'; import { LineItem} from '../items/lineitem.model'; @Injectable({providedIn: 'root'}) export class OrderService { beUrl = 'http://localhost:3000/'; - private dataStore: {allOrders: Order[], user: User, order: Order } = { + private dataStore: {allOrders: Order[], user: User, order: Order, owner: Owner } = { allOrders: [], user:{ address: '', @@ -21,11 +22,22 @@ export class OrderService { pin: '', validated: false }, + owner: { + _id: '', + name: '', + address: '', + currency: 'usd', + tax: false, + taxValue: 0, + vat: false, + vatValue: 0 + }, order: { address: '', session: '', timestamp: '', closed: false, + currency: '', price: 0, total: 0, totalZec: 0, @@ -45,6 +57,7 @@ export class OrderService { private _allOrdersUpdated: BehaviorSubject = new BehaviorSubject(this.dataStore.allOrders); public readonly allOrdersUpdate: Observable = this._allOrdersUpdated.asObservable(); public userUpdate: Observable; + public ownerUpdate: Observable; private apiKey = 'Le2adeic8Thah4Aeng4daem6i'; private reqHeaders: HttpHeaders; @@ -55,11 +68,15 @@ export class OrderService { ) { this.reqHeaders = new HttpHeaders().set('Authorization', this.apiKey); this.userUpdate = userService.userUpdate; + this.ownerUpdate = userService.ownerUpdate; this.userUpdate.subscribe((user) => { this.dataStore.user = user; //console.log('OS: const', user); this.getOrder(); }); + this.ownerUpdate.subscribe((owner) => { + this.dataStore.owner = owner; + }); } getOrder() { @@ -116,6 +133,7 @@ export class OrderService { var order:Order = { address: this.dataStore.user.address, session: this.dataStore.user.session, + currency: this.dataStore.owner.currency, closed: false, totalZec: 0, price: 0, @@ -144,6 +162,7 @@ export class OrderService { session: '', timestamp: '', closed: false, + currency: '', total: 0, totalZec: 0, price: 0, @@ -174,6 +193,7 @@ export class OrderService { session: '', timestamp: '', closed: false, + currency: '', price: 0, total: 0, totalZec: 0, diff --git a/src/app/owner.model.ts b/src/app/owner.model.ts index 432d8c6..0db35f4 100644 --- a/src/app/owner.model.ts +++ b/src/app/owner.model.ts @@ -2,4 +2,9 @@ export interface Owner { _id?: string; address: string; name: string; + currency: string; + tax: boolean; + taxValue: number; + vat: boolean; + vatValue: number; } diff --git a/src/app/settings/settings.component.html b/src/app/settings/settings.component.html index 4235f47..ae2360a 100644 --- a/src/app/settings/settings.component.html +++ b/src/app/settings/settings.component.html @@ -1,9 +1,18 @@

Settings

- + + Name + + Currency + + + {{coin.label}} + + + diff --git a/src/app/settings/settings.component.ts b/src/app/settings/settings.component.ts index b6512fa..19293fa 100644 --- a/src/app/settings/settings.component.ts +++ b/src/app/settings/settings.component.ts @@ -14,6 +14,24 @@ export class SettingsComponent implements OnInit { settingsForm: FormGroup; owner: Owner; + coins = [ + { + label: 'US Dollar', + symbol: 'usd' + },{ + label: 'Euro', + symbol: 'eur' + },{ + label: 'British Pound', + symbol: 'gbp' + },{ + label: 'Canadian Dollar', + symbol: 'cad' + },{ + label: 'Australian Dollar', + symbol: 'aud' + } + ]; constructor( private fb: FormBuilder, @@ -21,7 +39,8 @@ export class SettingsComponent implements OnInit { @Inject(MAT_DIALOG_DATA) public data: Owner ) { this.settingsForm = fb.group({ - name: [data.name, Validators.required] + name: [data.name, Validators.required], + currency: [data.currency, Validators.required] }); this.owner = data; } @@ -35,6 +54,7 @@ export class SettingsComponent implements OnInit { save() { this.owner.name = this.settingsForm.value.name; + this.owner.currency = this.settingsForm.value.currency; this.dialogRef.close(this.owner); } } diff --git a/src/app/user.service.ts b/src/app/user.service.ts index 524b5bb..55c0cd4 100644 --- a/src/app/user.service.ts +++ b/src/app/user.service.ts @@ -20,7 +20,12 @@ export class UserService{ }, owner: { address: '', - name: '' + name: '', + currency: 'usd', + tax: false, + taxValue: 0, + vat: false, + vatValue: 0 }, txs : [] }; @@ -112,7 +117,16 @@ export class UserService{ } addOwner(address: string) { - const owner: Owner={_id: '', address: address, name: 'Zgo-'.concat(address.substring(0,5))}; + const owner: Owner={ + _id: '', + address: address, + name: 'Zgo-'.concat(address.substring(0,5)), + currency: 'usd', + tax: false, + taxValue: 0, + vat: false, + vatValue: 0 + }; let obs = this.http.post<{message: string}>(this.beUrl+'api/addowner', {address: owner.address, name: owner.name}, {headers: this.reqHeaders}); obs.subscribe((responseData) => { diff --git a/src/app/viewer/viewer.component.ts b/src/app/viewer/viewer.component.ts index 4497eb3..00694d1 100644 --- a/src/app/viewer/viewer.component.ts +++ b/src/app/viewer/viewer.component.ts @@ -28,7 +28,16 @@ export class ViewerComponent implements OnInit { pin: '', validated: false }; - private owner: Owner= {_id:'', address: 'none', name:''}; + private owner: Owner= { + _id:'', + address: 'none', + name:'', + currency: 'usd', + tax: false, + taxValue: 0, + vat: false, + vatValue: 0 + }; public addrUpdate: Observable; public ownerUpdate: Observable; public userUpdate: Observable; @@ -87,8 +96,9 @@ export class ViewerComponent implements OnInit { const dialogRef = this.dialog.open(SettingsComponent, dialogConfig); dialogRef.afterClosed().subscribe((val) => { if (val != null) { - console.log('Saving settings'); + //console.log('Saving settings', val); this.userService.updateOwner(val); + this.fullnodeService.getPrice(val.currency); } }); } From 55dc475a6a53b8afa59df09ad01eb8372a8a8850 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Tue, 23 Nov 2021 14:44:46 -0600 Subject: [PATCH 5/5] Correct item create form --- src/app/items/item-create/item-create.component.html | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/app/items/item-create/item-create.component.html b/src/app/items/item-create/item-create.component.html index 8f8c4cc..d6dc06a 100644 --- a/src/app/items/item-create/item-create.component.html +++ b/src/app/items/item-create/item-create.component.html @@ -1,15 +1,18 @@

Add item

- + + Item - + + Description - - + + Price +
Use only numbers