From 294d7915e1d537691885099d68f0ddbff929b0de Mon Sep 17 00:00:00 2001 From: softsimon Date: Sun, 13 Feb 2022 00:46:42 +0400 Subject: [PATCH] Liquid dashboard assets updates --- frontend/src/app/app.module.ts | 2 + frontend/src/app/bitcoin.utils.ts | 2 +- .../asset-circulation.component.html | 3 ++ .../asset-circulation.component.scss | 0 .../asset-circulation.component.ts | 53 +++++++++++++++++++ .../app/dashboard/dashboard.component.html | 13 +++-- .../app/dashboard/dashboard.component.scss | 13 +++-- .../src/app/dashboard/dashboard.component.ts | 4 +- 8 files changed, 80 insertions(+), 10 deletions(-) create mode 100644 frontend/src/app/components/asset-circulation/asset-circulation.component.html create mode 100644 frontend/src/app/components/asset-circulation/asset-circulation.component.scss create mode 100644 frontend/src/app/components/asset-circulation/asset-circulation.component.ts diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.ts index 97fc16204..28a3f60b7 100644 --- a/frontend/src/app/app.module.ts +++ b/frontend/src/app/app.module.ts @@ -67,6 +67,7 @@ import { PushTransactionComponent } from './components/push-transaction/push-tra import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; import { AssetsFeaturedComponent } from './components/assets/assets-featured/assets-featured.component'; import { AssetGroupComponent } from './components/assets/asset-group/asset-group.component'; +import { AssetCirculationComponent } from './components/asset-circulation/asset-circulation.component'; @NgModule({ declarations: [ @@ -116,6 +117,7 @@ import { AssetGroupComponent } from './components/assets/asset-group/asset-group AssetsNavComponent, AssetsFeaturedComponent, AssetGroupComponent, + AssetCirculationComponent, ], imports: [ BrowserModule.withServerTransition({ appId: 'serverApp' }), diff --git a/frontend/src/app/bitcoin.utils.ts b/frontend/src/app/bitcoin.utils.ts index 577249940..ff2d7a885 100644 --- a/frontend/src/app/bitcoin.utils.ts +++ b/frontend/src/app/bitcoin.utils.ts @@ -69,7 +69,7 @@ export function calcSegwitFeeGains(tx: Transaction) { export function moveDec(num: number, n: number) { let frac, int, neg, ref; if (n === 0) { - return num; + return num.toString(); } ref = ('' + num).split('.'), int = ref[0], frac = ref[1]; int || (int = '0'); diff --git a/frontend/src/app/components/asset-circulation/asset-circulation.component.html b/frontend/src/app/components/asset-circulation/asset-circulation.component.html new file mode 100644 index 000000000..2f4dca8eb --- /dev/null +++ b/frontend/src/app/components/asset-circulation/asset-circulation.component.html @@ -0,0 +1,3 @@ + + {{ circulatingAmount }} + \ No newline at end of file diff --git a/frontend/src/app/components/asset-circulation/asset-circulation.component.scss b/frontend/src/app/components/asset-circulation/asset-circulation.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/frontend/src/app/components/asset-circulation/asset-circulation.component.ts b/frontend/src/app/components/asset-circulation/asset-circulation.component.ts new file mode 100644 index 000000000..6d1511c6e --- /dev/null +++ b/frontend/src/app/components/asset-circulation/asset-circulation.component.ts @@ -0,0 +1,53 @@ +import { ChangeDetectionStrategy, Component, Inject, Input, LOCALE_ID, OnInit } from '@angular/core'; +import { combineLatest, Observable } from 'rxjs'; +import { map } from 'rxjs/operators'; +import { moveDec } from 'src/app/bitcoin.utils'; +import { AssetsService } from 'src/app/services/assets.service'; +import { ElectrsApiService } from 'src/app/services/electrs-api.service'; +import { formatNumber } from '@angular/common'; +import { environment } from 'src/environments/environment'; + +@Component({ + selector: 'app-asset-circulation', + templateUrl: './asset-circulation.component.html', + styleUrls: ['./asset-circulation.component.scss'], + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class AssetCirculationComponent implements OnInit { + @Input() assetId: string; + + circulatingAmount$: Observable; + + constructor( + private electrsApiService: ElectrsApiService, + private assetsService: AssetsService, + @Inject(LOCALE_ID) private locale: string, + ) { } + + ngOnInit(): void { + this.circulatingAmount$ = combineLatest([ + this.electrsApiService.getAsset$(this.assetId), + this.assetsService.getAssetsMinimalJson$] + ) + .pipe( + map(([asset, assetsMinimal]) => { + const assetData = assetsMinimal[asset.asset_id]; + if (!asset.chain_stats.has_blinded_issuances) { + if (asset.asset_id === environment.nativeAssetId) { + return formatNumber(this.formatAmount(asset.chain_stats.peg_in_amount - asset.chain_stats.burned_amount + - asset.chain_stats.peg_out_amount, assetData[3]), this.locale, '1.2-2'); + } else { + return formatNumber(this.formatAmount(asset.chain_stats.issued_amount + - asset.chain_stats.burned_amount, assetData[3]), this.locale, '1.2-2'); + } + } else { + return $localize`:@@shared.confidential:Confidential`; + } + }), + ); + } + + formatAmount(value: number, precision = 0): number { + return parseFloat(moveDec(value, -precision)); + } +} diff --git a/frontend/src/app/dashboard/dashboard.component.html b/frontend/src/app/dashboard/dashboard.component.html index 01a32ac7c..06f9cb0eb 100644 --- a/frontend/src/app/dashboard/dashboard.component.html +++ b/frontend/src/app/dashboard/dashboard.component.html @@ -47,7 +47,7 @@
- +
{{ group.name }} - {{ group.ticker }} + {{ group.ticker }} + @@ -180,13 +181,19 @@ - + + +
+
+
+
+
diff --git a/frontend/src/app/dashboard/dashboard.component.scss b/frontend/src/app/dashboard/dashboard.component.scss index 23c9b226e..e518beaa7 100644 --- a/frontend/src/app/dashboard/dashboard.component.scss +++ b/frontend/src/app/dashboard/dashboard.component.scss @@ -285,8 +285,8 @@ } .assetIcon { - width: 28px; - height: 28px; + width: 40px; + height: 40px; } .asset-title { @@ -298,11 +298,16 @@ } .asset-icon { - width: 54px; - height: 52px; + width: 65px; + height: 65px; } .asset-table { width: calc(100% - 20px); margin-left: 1.25rem; } + +.circulating-amount { + text-align: right; + width: 100%; +} diff --git a/frontend/src/app/dashboard/dashboard.component.ts b/frontend/src/app/dashboard/dashboard.component.ts index 36ad73003..b8a32210c 100644 --- a/frontend/src/app/dashboard/dashboard.component.ts +++ b/frontend/src/app/dashboard/dashboard.component.ts @@ -127,15 +127,15 @@ export class DashboardComponent implements OnInit { this.featuredAssets$ = this.apiService.listFeaturedAssets$() .pipe( - take(5), map((featured) => { + featured = featured.slice(0, 4); for (const feature of featured) { if (feature.assets) { feature.asset = feature.assets[0]; } } return featured; - }) + }), ); this.blocks$ = this.stateService.blocks$