From 7e0c5fb14bd3df3ba2dadb642d5b57475093a5e0 Mon Sep 17 00:00:00 2001 From: Razvan Tomegea Date: Wed, 6 Aug 2025 18:07:15 +0300 Subject: [PATCH 1/4] Refactor GitHub Actions workflows to streamline dependency installation - Removed caching of node_modules and retry mechanism for pnpm install. - Simplified the installation process by directly running pnpm install in both build and publish workflows. --- .github/workflows/build.yml | 20 +++----------------- .github/workflows/publish.yml | 16 +--------------- 2 files changed, 4 insertions(+), 32 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 44ec0be..5066132 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,23 +24,9 @@ jobs: node-version: 18 - name: Setup pnpm run: npm install -g pnpm - - name: Get node_modules cache - uses: actions/cache@v4 - id: node_modules - with: - path: | - **/node_modules - key: ${{ runner.os }}-node_modules-${{ hashFiles('**/pnpm-lock.yaml') }} - name: Remove node_modules - if: steps.node_modules.outputs.cache-hit != 'true' run: rm -rf node_modules - name: Install Dependencies - uses: nick-fields/retry@v3 - if: steps.node_modules.outputs.cache-hit != 'true' - with: - timeout_minutes: 120 - retry_on: error - max_attempts: 3 - command: pnpm install - - run: npm run compile - - run: npm run test + run: pnpm install + - run: pnpm run compile + - run: pnpm run test diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index dd56c43..3bf3a82 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -30,24 +30,10 @@ jobs: registry-url: https://registry.npmjs.org/ - name: Setup pnpm run: npm install -g pnpm - - name: Get node_modules cache - uses: actions/cache@v4 - id: node_modules - with: - path: | - **/node_modules - key: ${{ runner.os }}-node_modules-${{ hashFiles('**/pnpm-lock.yaml') }} - name: Remove node_modules - if: steps.node_modules.outputs.cache-hit != 'true' run: rm -rf node_modules - name: Install Dependencies - uses: nick-fields/retry@v3 - if: steps.node_modules.outputs.cache-hit != 'true' - with: - timeout_minutes: 120 - retry_on: error - max_attempts: 3 - command: pnpm install + run: pnpm install - name: Create release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From f82d667d0bd11d9bdb5cb6b8e8acc6a2aa3f61ac Mon Sep 17 00:00:00 2001 From: Razvan Tomegea Date: Wed, 6 Aug 2025 18:09:27 +0300 Subject: [PATCH 2/4] Rename job in GitHub Actions workflow from 'publish-npm' to 'build' for clarity and consistency. --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5066132..4c45afd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,7 +6,7 @@ on: workflow_dispatch: jobs: - publish-npm: + build: runs-on: ubuntu-latest steps: - name: Fix permissions From 43ff7fa4fe23aa5e71fc10957e34760d07313b81 Mon Sep 17 00:00:00 2001 From: Razvan Tomegea Date: Wed, 6 Aug 2025 18:21:33 +0300 Subject: [PATCH 3/4] Update GitHub Actions workflow to include 'development' branch for pull requests --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4c45afd..169b36f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,7 +2,7 @@ name: Build and Test on: pull_request: - branches: [main] + branches: [main, development] workflow_dispatch: jobs: From 225ffe8cf4387440d542da2d5820adcd22a0c95a Mon Sep 17 00:00:00 2001 From: Tudor Morar Date: Tue, 16 Sep 2025 12:27:45 +0300 Subject: [PATCH 4/4] Merge pull request #26 from multiversx/tm/fix/refactor-parse-amounrt Refactor `parseAmount` --- CHANGELOG.md | 4 ++++ package.json | 2 +- src/helpers/parseAmount.ts | 11 ++--------- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fa5ee3..4955ee0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/package.json b/package.json index 8eb3dba..861440e 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/helpers/parseAmount.ts b/src/helpers/parseAmount.ts index 41a69e9..d9f86c6 100644 --- a/src/helpers/parseAmount.ts +++ b/src/helpers/parseAmount.ts @@ -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); }