Browse Source

Merge 1f4a67d3da into 2917ad8586

pull/7557/merge
Sebastian Legarraga 1 day ago
committed by GitHub
parent
commit
4102bc8063
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 4
      CHANGELOG.md
  2. 2
      libs/ui/src/lib/holdings-table/holdings-table.component.html
  3. 5
      libs/ui/src/lib/holdings-table/holdings-table.component.ts
  4. 51
      libs/ui/src/lib/holdings-table/quantity-precision.spec.ts
  5. 18
      libs/ui/src/lib/holdings-table/quantity-precision.ts

4
CHANGELOG.md

@ -18,6 +18,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Improved the style of the close button in the dialog header component
- Upgraded `prettier` from version `3.9.9` to `3.9.10`
### Fixed
- Fixed the precision of cryptocurrency quantities in the holdings table
## 3.90.0 - 2026-10-21
### Changed

2
libs/ui/src/lib/holdings-table/holdings-table.component.html

@ -101,9 +101,9 @@
>
<div class="d-flex justify-content-end">
<gf-value
[isCurrency]="true"
[isLoading]="isLoading()"
[locale]="locale()"
[precision]="getQuantityPrecision(element)"
[value]="element.quantity"
/>
</div>

5
libs/ui/src/lib/holdings-table/holdings-table.component.ts

@ -29,6 +29,7 @@ import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader';
import { GfEntityLogoComponent } from '../entity-logo/entity-logo.component';
import { GfValueComponent } from '../value/value.component';
import { HoldingsTableItem } from './interfaces/interfaces';
import { getHoldingQuantityPrecision } from './quantity-precision';
@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
@ -144,6 +145,10 @@ export class GfHoldingsTableComponent {
: '';
}
protected getQuantityPrecision(holding: HoldingsTableItem): number {
return getHoldingQuantityPrecision(holding);
}
protected onOpenHoldingDialog({
dataSource,
symbol

51
libs/ui/src/lib/holdings-table/quantity-precision.spec.ts

@ -0,0 +1,51 @@
import { AssetSubClass } from '@ghostfolio/prisma/enums';
import { HoldingsTableItem } from './interfaces/interfaces';
import { getHoldingQuantityPrecision } from './quantity-precision';
function createHolding(
quantity: number | undefined,
assetSubClass: AssetSubClass
): Pick<HoldingsTableItem, 'assetProfile' | 'quantity'> {
return {
assetProfile: { assetSubClass } as HoldingsTableItem['assetProfile'],
quantity
};
}
describe('getHoldingQuantityPrecision', () => {
it('preserves satoshi precision for fractional cryptocurrency quantities', () => {
expect(
getHoldingQuantityPrecision(
createHolding(0.01525217, AssetSubClass.CRYPTOCURRENCY)
)
).toBe(8);
expect(
getHoldingQuantityPrecision(
createHolding(10.12345678, AssetSubClass.CRYPTOCURRENCY)
)
).toBe(8);
});
it('does not add decimal places to integer cryptocurrency quantities', () => {
expect(
getHoldingQuantityPrecision(
createHolding(12, AssetSubClass.CRYPTOCURRENCY)
)
).toBe(0);
});
it('keeps the existing precision for non-cryptocurrency quantities', () => {
expect(
getHoldingQuantityPrecision(createHolding(12.3456, AssetSubClass.STOCK))
).toBe(2);
});
it('does not add decimal places when the quantity is not available', () => {
expect(
getHoldingQuantityPrecision(
createHolding(undefined, AssetSubClass.CRYPTOCURRENCY)
)
).toBe(0);
});
});

18
libs/ui/src/lib/holdings-table/quantity-precision.ts

@ -0,0 +1,18 @@
import { AssetSubClass } from '@ghostfolio/prisma/enums';
import { HoldingsTableItem } from './interfaces/interfaces';
export function getHoldingQuantityPrecision({
assetProfile,
quantity
}: Pick<HoldingsTableItem, 'assetProfile' | 'quantity'>): number {
if (quantity === undefined || Number.isInteger(quantity)) {
return 0;
}
if (assetProfile.assetSubClass === AssetSubClass.CRYPTOCURRENCY) {
return 8;
}
return 2;
}
Loading…
Cancel
Save