Display asset circulating amount more nicely fixing overflow
fixes #1264
This commit is contained in:
		
							parent
							
								
									3f5a749352
								
							
						
					
					
						commit
						3e6dba2d58
					
				@ -73,6 +73,7 @@ import { MiningDashboardComponent } from './components/mining-dashboard/mining-d
 | 
				
			|||||||
import { DifficultyChartComponent } from './components/difficulty-chart/difficulty-chart.component';
 | 
					import { DifficultyChartComponent } from './components/difficulty-chart/difficulty-chart.component';
 | 
				
			||||||
import { HashrateChartComponent } from './components/hashrate-chart/hashrate-chart.component';
 | 
					import { HashrateChartComponent } from './components/hashrate-chart/hashrate-chart.component';
 | 
				
			||||||
import { MiningStartComponent } from './components/mining-start/mining-start.component';
 | 
					import { MiningStartComponent } from './components/mining-start/mining-start.component';
 | 
				
			||||||
 | 
					import { AmountShortenerPipe } from './shared/pipes/amount-shortener.pipe';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@NgModule({
 | 
					@NgModule({
 | 
				
			||||||
  declarations: [
 | 
					  declarations: [
 | 
				
			||||||
@ -128,6 +129,7 @@ import { MiningStartComponent } from './components/mining-start/mining-start.com
 | 
				
			|||||||
    DifficultyChartComponent,
 | 
					    DifficultyChartComponent,
 | 
				
			||||||
    HashrateChartComponent,
 | 
					    HashrateChartComponent,
 | 
				
			||||||
    MiningStartComponent,
 | 
					    MiningStartComponent,
 | 
				
			||||||
 | 
					    AmountShortenerPipe,
 | 
				
			||||||
  ],
 | 
					  ],
 | 
				
			||||||
  imports: [
 | 
					  imports: [
 | 
				
			||||||
    BrowserModule.withServerTransition({ appId: 'serverApp' }),
 | 
					    BrowserModule.withServerTransition({ appId: 'serverApp' }),
 | 
				
			||||||
 | 
				
			|||||||
@ -1,3 +1,6 @@
 | 
				
			|||||||
<ng-container *ngIf="(circulatingAmount$ | async) as circulating">
 | 
					<ng-container *ngIf="(circulatingAmount$ | async) as circulating">
 | 
				
			||||||
  {{ circulating.amount }} <span class="ticker">{{ circulating.ticker }}</span>
 | 
					  <ng-template [ngIf]="circulating.amount === -1" [ngIfElse]="default" i18n="shared.confidential">Confidential</ng-template>
 | 
				
			||||||
 | 
					  <ng-template #default>
 | 
				
			||||||
 | 
					    <span class="d-inline-block d-md-none">{{ circulating.amount | amountShortener }}</span>
 | 
				
			||||||
 | 
					    <span class="d-none d-md-inline-block">{{ circulating.amount | number: '1.2-2' }}</span> <span class="ticker">{{ circulating.ticker }}</span></ng-template>
 | 
				
			||||||
</ng-container>
 | 
					</ng-container>
 | 
				
			||||||
@ -16,7 +16,7 @@ import { environment } from 'src/environments/environment';
 | 
				
			|||||||
export class AssetCirculationComponent implements OnInit {
 | 
					export class AssetCirculationComponent implements OnInit {
 | 
				
			||||||
  @Input() assetId: string;
 | 
					  @Input() assetId: string;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  circulatingAmount$: Observable<{ amount: string, ticker: string}>;
 | 
					  circulatingAmount$: Observable<{ amount: number, ticker: string}>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  constructor(
 | 
					  constructor(
 | 
				
			||||||
    private electrsApiService: ElectrsApiService,
 | 
					    private electrsApiService: ElectrsApiService,
 | 
				
			||||||
@ -35,20 +35,18 @@ export class AssetCirculationComponent implements OnInit {
 | 
				
			|||||||
        if (!asset.chain_stats.has_blinded_issuances) {
 | 
					        if (!asset.chain_stats.has_blinded_issuances) {
 | 
				
			||||||
          if (asset.asset_id === environment.nativeAssetId) {
 | 
					          if (asset.asset_id === environment.nativeAssetId) {
 | 
				
			||||||
            return {
 | 
					            return {
 | 
				
			||||||
              amount: formatNumber(this.formatAmount(asset.chain_stats.peg_in_amount - asset.chain_stats.burned_amount
 | 
					              amount: this.formatAmount(asset.chain_stats.peg_in_amount - asset.chain_stats.burned_amount - asset.chain_stats.peg_out_amount, assetData[3]),
 | 
				
			||||||
              - asset.chain_stats.peg_out_amount, assetData[3]), this.locale, '1.2-2'),
 | 
					 | 
				
			||||||
              ticker: assetData[1]
 | 
					              ticker: assetData[1]
 | 
				
			||||||
            };
 | 
					            };
 | 
				
			||||||
          } else {
 | 
					          } else {
 | 
				
			||||||
            return {
 | 
					            return {
 | 
				
			||||||
              amount: formatNumber(this.formatAmount(asset.chain_stats.issued_amount
 | 
					              amount: this.formatAmount(asset.chain_stats.issued_amount - asset.chain_stats.burned_amount, assetData[3]),
 | 
				
			||||||
              - asset.chain_stats.burned_amount, assetData[3]), this.locale, '1.2-2'),
 | 
					 | 
				
			||||||
              ticker: assetData[1]
 | 
					              ticker: assetData[1]
 | 
				
			||||||
            };
 | 
					            };
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
          return {
 | 
					          return {
 | 
				
			||||||
            amount: $localize`:@@shared.confidential:Confidential`,
 | 
					            amount: -1,
 | 
				
			||||||
            ticker: '',
 | 
					            ticker: '',
 | 
				
			||||||
          };
 | 
					          };
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										22
									
								
								frontend/src/app/shared/pipes/amount-shortener.pipe.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								frontend/src/app/shared/pipes/amount-shortener.pipe.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,22 @@
 | 
				
			|||||||
 | 
					import { Pipe, PipeTransform } from '@angular/core';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@Pipe({
 | 
				
			||||||
 | 
					  name: 'amountShortener'
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					export class AmountShortenerPipe implements PipeTransform {
 | 
				
			||||||
 | 
					  transform(num: number, ...args: number[]): unknown {
 | 
				
			||||||
 | 
					    const digits = args[0] || 1;
 | 
				
			||||||
 | 
					    const lookup = [
 | 
				
			||||||
 | 
					      { value: 1, symbol: '' },
 | 
				
			||||||
 | 
					      { value: 1e3, symbol: 'k' },
 | 
				
			||||||
 | 
					      { value: 1e6, symbol: 'M' },
 | 
				
			||||||
 | 
					      { value: 1e9, symbol: 'G' },
 | 
				
			||||||
 | 
					      { value: 1e12, symbol: 'T' },
 | 
				
			||||||
 | 
					      { value: 1e15, symbol: 'P' },
 | 
				
			||||||
 | 
					      { value: 1e18, symbol: 'E' }
 | 
				
			||||||
 | 
					    ];
 | 
				
			||||||
 | 
					    const rx = /\.0+$|(\.[0-9]*[1-9])0+$/;
 | 
				
			||||||
 | 
					    var item = lookup.slice().reverse().find((item) => num >= item.value);
 | 
				
			||||||
 | 
					    return item ? (num / item.value).toFixed(digits).replace(rx, '$1') + item.symbol : '0';
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user