Skip to content

Commit

Permalink
cherry-pick fix: simulations unavailable native fiat rate (#24910) in…
Browse files Browse the repository at this point in the history
…to v11.16.2 (#24911)

cherry-pick fix: simulations unavailable native fiat rate
cff11d7 (#24910) into v11.16.2

no merge conflicts
  • Loading branch information
dbrans authored May 30, 2024
1 parent 093fa8b commit e607797
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,19 @@ describe('useBalanceChanges', () => {
expect(result.current.value[0].fiatAmount).toBe(-663.3337769927953);
});

it('handles unavailable native fiat rate', async () => {
mockGetConversionRate.mockReturnValue(null);
const { result, waitForNextUpdate } = setupHook({
...dummyBalanceChange,
difference: DIFFERENCE_ETH_MOCK,
isDecrease: true,
});

await waitForNextUpdate();

expect(result.current.value[0].fiatAmount).toBe(FIAT_UNAVAILABLE);
});

it('handles no native balance change', async () => {
const { result, waitForNextUpdate } = setupHook(undefined);
await waitForNextUpdate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,18 @@ async function fetchTokenFiatRates(
// Compiles the balance change for the native asset
function getNativeBalanceChange(
nativeBalanceChange: SimulationBalanceChange | undefined,
nativeFiatRate: number,
nativeFiatRate: number | undefined,
): BalanceChange | undefined {
if (!nativeBalanceChange) {
return undefined;
}
const asset = NATIVE_ASSET_IDENTIFIER;
const amount = getAssetAmount(nativeBalanceChange, NATIVE_DECIMALS);
const fiatAmount = amount
.times(convertNumberToStringWithPrecisionWarning(nativeFiatRate))
.toNumber();
const fiatAmount = nativeFiatRate
? amount
.times(convertNumberToStringWithPrecisionWarning(nativeFiatRate))
.toNumber()
: FIAT_UNAVAILABLE;
return { asset, amount, fiatAmount };
}

Expand Down

0 comments on commit e607797

Please sign in to comment.