@rango-dev/widget-embedded 0.38.1-next.1 → 0.38.1-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rango-dev/widget-embedded",
3
- "version": "0.38.1-next.1",
3
+ "version": "0.38.1-next.2",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "source": "./src/index.ts",
@@ -280,10 +280,10 @@ export function resetConnectedWalletState(
280
280
 
281
281
  export const calculateWalletUsdValue = (balances: BalanceState) => {
282
282
  const total = Object.values(balances).reduce((prev, balance) => {
283
- const formattedBalance = formatBalance(balance);
284
- return formattedBalance?.usdValue
285
- ? prev.plus(formattedBalance.usdValue)
286
- : prev;
283
+ const usdBalance = balance.usdValue
284
+ ? representAmountInNumber(balance.usdValue, balance.decimals)
285
+ : ZERO.toFixed();
286
+ return prev.plus(usdBalance);
287
287
  }, new BigNumber(ZERO));
288
288
 
289
289
  return numberWithThousandSeparator(total.toString());
@@ -324,16 +324,18 @@ export const getKeplrCompatibleConnectedWallets = (
324
324
  );
325
325
  };
326
326
 
327
+ function representAmountInNumber(amount: string, decimals: number): string {
328
+ return new BigNumber(amount).shiftedBy(-decimals).toFixed();
329
+ }
330
+
327
331
  export function formatBalance(balance: Balance | null): Balance | null {
328
332
  if (!balance) {
329
333
  return null;
330
334
  }
331
335
 
332
- const amount = new BigNumber(balance.amount)
333
- .shiftedBy(-balance.decimals)
334
- .toFixed();
336
+ const amount = representAmountInNumber(balance.amount, balance.decimals);
335
337
  const usdValue = balance.usdValue
336
- ? new BigNumber(balance.usdValue).shiftedBy(-balance.decimals).toFixed()
338
+ ? representAmountInNumber(balance.usdValue, balance.decimals)
337
339
  : null;
338
340
  const formattedAmount = numberToString(
339
341
  amount,