Skip to content

Commit

Permalink
Tighten type guards for account/timestamp activities
Browse files Browse the repository at this point in the history
These now explicitly check for the decimals fields that we expect exist.
  • Loading branch information
Shadowfiend committed Oct 13, 2021
1 parent fe9ebe9 commit 931c44c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions background/redux-slices/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,12 +403,13 @@ export const selectAccountAndTimestampedActivities = createSelector(
asset.symbol === assetItem.asset.symbol && asset.recentPrices.USD
)

if (rawAsset) {
// Does this break if the token is less than 1 USD? Hah...
const usdIndex = rawAsset.recentPrices.USD.amounts[1] > 1 ? 1 : 0
const usdIndex = rawAsset?.recentPrices?.USD?.amounts?.[1] > 1 ? 1 : 0
const usdAsset = rawAsset?.recentPrices?.USD?.pair[usdIndex]

if (rawAsset && "decimals" in usdAsset && "decimals" in assetItem.asset) {
const usdNonDecimalValue = rawAsset.recentPrices.USD.amounts[usdIndex]

const usdDecimals = rawAsset.recentPrices.USD.pair[usdIndex].decimals
const usdDecimals = usdAsset.decimals
const combinedDecimals = assetItem.asset.decimals + usdDecimals

// Choose the precision we actually want
Expand Down

0 comments on commit 931c44c

Please sign in to comment.