Commit 742c231f authored by dev0tion's avatar dev0tion

Improve coin notation pipe

parent c793a2da
import { CoinAbbreviationPipe } from './coin-abbreviation.pipe';
describe('CoinAbbreviationPipe', () => {
it('create an instance', () => {
const pipe = new CoinAbbreviationPipe();
expect(pipe).toBeTruthy();
});
});
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'coinAbbreviation'
})
export class CoinAbbreviationPipe implements PipeTransform {
transform(value: any): any {
if (!value) return value;
let abbreviationAdded = value + " TBTC"
return abbreviationAdded;
}
}
......@@ -7,22 +7,28 @@ export class CoinNotationPipe implements PipeTransform {
private coinUnit = "BTC";
private coinNotation: number;
private decimalLimit = 8;
transform(value: any): any {
if (!value) return value;
this.coinNotation = value;
switch (this.coinUnit) {
let temp;
if (typeof value === 'number') {
switch (this.getCoinUnit()) {
case "BTC":
this.coinNotation = Number(value.toFixed(8));
return this.coinNotation = this.coinNotation / 100000000;
temp = value / 100000000;
return temp.toFixed(this.decimalLimit) + " TBTC";
case "mBTC":
this.coinNotation = Number(value.toFixed(8));
return this.coinNotation = this.coinNotation / 100000;
temp = value / 100000;
return temp.toFixed(this.decimalLimit) + " TmBTC";
case "uBTC":
this.coinNotation = Number(value.toFixed(8));
return this.coinNotation = this.coinNotation / 100;
temp = value / 100;
return temp.toFixed(this.decimalLimit) + " TuBTC";
}
}
}
getCoinUnit() {
return this.coinUnit;
}
}
import { NgModule, ModuleWithProviders } from '@angular/core';
import { CommonModule } from '@angular/common';
import { CoinNotationPipe } from './pipes/coin-notation.pipe';
import { CoinAbbreviationPipe } from './pipes/coin-abbreviation.pipe';
@NgModule({
imports: [CommonModule],
declarations: [CoinNotationPipe, CoinAbbreviationPipe],
exports: [CoinNotationPipe, CoinAbbreviationPipe]
declarations: [CoinNotationPipe],
exports: [CoinNotationPipe]
})
export class SharedModule {
......
......@@ -2,8 +2,8 @@
<div class="d-flex flex-row align-items-center nopadding" id="dashboard">
<div class="d-flex flex-column">
<div class="p">Active Balance</div>
<div class="p">Balance: {{confirmedBalance | coinNotation | coinAbbreviation}}</div>
<div class="p">Unconfirmed Balance: {{unconfirmedBalance | coinNotation | coinAbbreviation}}</div>
<div class="p">Balance: {{confirmedBalance | coinNotation }}</div>
<div class="p">Unconfirmed Balance: {{unconfirmedBalance | coinNotation }}</div>
</div>
<div class="d-flex flex-column">
<!--<div>Current Value</div>
......@@ -31,7 +31,7 @@
<!--<td *ngIf="{{ transaction.amount }} < 0">SENT</td>
<td *ngIf="{{ transaction.amount }} > 0">RECEIVED</td>-->
<td *ngIf="i<5">{{ transaction.type }}</td>
<td *ngIf="i<5">{{ transaction.amount | coinNotation | coinAbbreviation }}</td>
<td *ngIf="i<5">{{ transaction.amount | coinNotation }}</td>
<td *ngIf="i<5">{{ transaction.id }}</td>
<td *ngIf="i<5">{{ transaction.confirmedInBlock }}</td>
<td *ngIf="i<5">{{ transaction.timestamp * 1000 | date:'medium' }}</td>
......
......@@ -13,7 +13,7 @@
<!--<td *ngIf="{{ transaction.amount }} < 0; else received">SENT</td>
<td #received>RECEIVED</td>-->
<td>{{ transaction.type }}</td>
<td>{{ transaction.amount | coinNotation | coinAbbreviation }}</td>
<td>{{ transaction.amount | coinNotation }}</td>
<td>{{ transaction.id }}</td>
<td>{{ transaction.confirmedInBlock }}</td>
<td>{{ transaction.timestamp * 1000 | date:'medium' }}</td>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment