Increase fiat precision

This commit is contained in:
Felipe Knorr Kuhn 2026-02-14 15:31:32 -08:00
parent be08b954ec
commit ad08c931fc
No known key found for this signature in database
GPG key ID: 79619B52BB097C1A
3 changed files with 7 additions and 4 deletions

View file

@ -94,12 +94,11 @@ describe('Calculator', () => {
});
it('updates fiat and sats when entering 1 sat (0.00000001 BTC)', () => {
const expectedFiat = Math.round((MOCK_BTC_PRICE_USD / 100_000_000) * 100) / 100;
const expectedFiat = (MOCK_BTC_PRICE_USD / 100_000_000 * 100 / 100).toFixed(8);
cy.get('input[formControlName="bitcoin"]').clear().type('0.00000001');
cy.get('input[formControlName="satoshis"]').invoke('val').should('equal', '1');
cy.get('input[formControlName="fiat"]').invoke('val').then((fiatVal) => {
const fiat = parseFloat(String(fiatVal).replace(/,/g, '')) || 0;
expect(fiat).to.equal(expectedFiat);
expect(String(fiatVal)).to.equal(expectedFiat);
});
});
});

View file

@ -53,7 +53,7 @@
<div class="row justify-content-center">
<div class="fiat-text">
<app-fiat [value]="form.get('satoshis').value" digitsInfo="1.0-0"></app-fiat>
<app-fiat [value]="form.get('satoshis').value" digitsInfo="1.2-2"></app-fiat>
</div>
</div>

View file

@ -186,6 +186,10 @@ export class CalculatorComponent implements OnInit {
if (num % 1 === 0) {
return Math.round(num);
}
// For small values (< 1), show more precision
if (Math.abs(num) < 1 && num !== 0) {
return num.toFixed(8);
}
return (Math.round(num * 100) / 100).toFixed(2);
}
}