Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [[v3.0.2]](https://github.com/multiversx/mx-sdk-dapp-utils/pull/27) - 2025-09-16

- [Refactored parseAmount to mimic sdk-core v.14 implementation](https://github.com/multiversx/mx-sdk-dapp-utils/pull/26)

## [[v3.0.1]](https://github.com/multiversx/mx-sdk-dapp-utils/pull/25) - 2025-08-05

- [Migrate to sdk-core v15](https://github.com/multiversx/mx-sdk-dapp-utils/pull/22)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@multiversx/sdk-dapp-utils",
"version": "3.0.1",
"version": "3.0.2",
"description": "SDK for DApp utilities",
"main": "out/index.js",
"types": "out/index.d.js",
Expand Down
11 changes: 2 additions & 9 deletions src/helpers/parseAmount.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import BigNumber from 'bignumber.js';
import { DECIMALS } from '../constants';

export function parseAmount(amount: string, numDecimals: number = DECIMALS) {
const amountBN = new BigNumber(amount);
const multiplier = new BigNumber(10).pow(numDecimals);
const result = amountBN.multipliedBy(multiplier);

if (!result.isInteger()) {
throw new Error('Amount has too many decimal places');
}

export function parseAmount(amount: string, numDecimals = DECIMALS): string {
const result = new BigNumber(amount).shiftedBy(numDecimals).decimalPlaces(0);
return result.toFixed(0);
}