Skip to content

Commit 2389f1a

Browse files
committed
refactor(assets): improve type safety in balance calculation
- Enhanced the access to percent change data in the balance calculation logic with proper type checking. - Simplified the retrieval of market data and price percent change, improving code clarity and maintainability. - Continued adherence to functional programming principles for better performance and readability.
1 parent 8a839fd commit 2389f1a

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

packages/assets-controllers/src/balances.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -632,12 +632,11 @@ function sumNonEvmAccountChangeForPeriod(
632632

633633
const assetChanges = assetBalances
634634
.map((asset) => {
635-
const percentObj = (
636-
asset.conversionRate as unknown as {
637-
marketData?: { pricePercentChange?: Record<string, number> };
638-
}
639-
)?.marketData?.pricePercentChange;
640-
const percentRaw = percentObj?.[nonEvmRatePropertiesRecord[period]];
635+
// Safely access the percent change data with proper type checking
636+
const marketData = asset.conversionRate?.marketData;
637+
const pricePercentChange = marketData?.pricePercentChange;
638+
const percentRaw =
639+
pricePercentChange?.[nonEvmRatePropertiesRecord[period]];
641640

642641
if (!isNonNaNNumber(percentRaw)) {
643642
return null;

0 commit comments

Comments
 (0)