Skip to content

Commit 5c3bce2

Browse files
Merge pull request #47 from multiversx/tm/feature/upgrade-sdk-core-v14 (#48)
Upgrade sdk-core v.14
2 parents 6dbffa3 + 9a36951 commit 5c3bce2

File tree

5 files changed

+279
-264
lines changed

5 files changed

+279
-264
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [[3.0.0](https://github.com/multiversx/mx-sdk-dapp-swap/pull/48)] - 2025-03-27
11+
12+
- [Upgrade sdk-core to v.14](https://github.com/multiversx/mx-sdk-dapp-swap/pull/47)
13+
14+
1015
## [[2.1.5](https://github.com/multiversx/mx-sdk-dapp-swap/pull/45)] - 2025-01-17
1116

1217
- [FIX: Swap route is defined when both inputs don't have amounts](https://github.com/multiversx/mx-sdk-dapp-swap/pull/44)

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@multiversx/sdk-dapp-swap",
3-
"version": "2.1.5",
3+
"version": "3.0.0",
44
"description": "A library to hold the main logic for swapping between tokens on the MultiversX blockchain",
55
"author": "MultiversX",
66
"license": "GPL-3.0-or-later",
@@ -27,8 +27,8 @@
2727
"devDependencies": {
2828
"@apollo/client": ">=3.8.6",
2929
"graphql": ">=16.9.0",
30-
"@multiversx/sdk-core": ">=13.12.0",
31-
"@multiversx/sdk-dapp": ">=3.0.0",
30+
"@multiversx/sdk-core": "^14.x",
31+
"@multiversx/sdk-dapp": "^4.x",
3232
"@size-limit/preset-small-lib": "7.0.8",
3333
"@testing-library/jest-dom": "5.16.4",
3434
"@testing-library/react": "13.3.0",
@@ -88,8 +88,8 @@
8888
"transaction"
8989
],
9090
"peerDependencies": {
91-
"@multiversx/sdk-core": ">=13.12.0",
92-
"@multiversx/sdk-dapp": ">=3.0.0",
91+
"@multiversx/sdk-core": "^14.x",
92+
"@multiversx/sdk-dapp": "^4.x",
9393
"@apollo/client": ">=3.8.6",
9494
"react": ">=18",
9595
"react-dom": ">=18",

src/utils/createTransactionFromRaw.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {
22
Address,
33
Transaction,
44
TransactionOptions,
5-
TransactionPayload,
65
TransactionVersion,
76
IPlainTransactionObject
87
} from '@multiversx/sdk-core';
@@ -28,19 +27,26 @@ export const createTransactionFromRaw = (
2827

2928
const { address } = accountSelector(store.getState());
3029

31-
const dataPayload = isStringBase64(data ?? '')
32-
? TransactionPayload.fromEncoded(data)
33-
: new TransactionPayload(data);
30+
const dataPayload = data
31+
? isStringBase64(data)
32+
? Buffer.from(data, 'base64')
33+
: Buffer.from(data.trim())
34+
: undefined;
3435

35-
return new Transaction({
36-
value: value.valueOf(),
36+
const transaction = new Transaction({
37+
value: BigInt(value),
3738
data: dataPayload,
3839
receiver: new Address(receiver),
3940
sender: new Address(sender && sender !== '' ? sender : address),
40-
gasLimit: gasLimit.valueOf() ?? GAS_LIMIT,
41-
gasPrice: gasPrice.valueOf() ?? GAS_PRICE,
41+
gasLimit: BigInt(gasLimit.valueOf() ?? GAS_LIMIT),
42+
gasPrice: BigInt(gasPrice.valueOf() ?? GAS_PRICE),
4243
chainID: chainID.valueOf(),
43-
version: new TransactionVersion(version ?? VERSION),
44-
...(options ? { options: new TransactionOptions(options) } : {})
44+
version: new TransactionVersion(version ?? VERSION).valueOf()
4545
});
46+
47+
if (options) {
48+
transaction.options = new TransactionOptions(options).valueOf();
49+
}
50+
51+
return transaction;
4652
};

src/utils/getTransactionFee.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { IPlainTransactionObject, NetworkConfig } from '@multiversx/sdk-core';
1+
import {
2+
IPlainTransactionObject,
3+
NetworkConfig,
4+
TransactionComputer
5+
} from '@multiversx/sdk-core';
26
import {
37
GAS_LIMIT,
48
GAS_PER_DATA_BYTE,
@@ -10,12 +14,17 @@ export const getTransactionFee = (rawTransaction: IPlainTransactionObject) => {
1014
const transaction = createTransactionFromRaw(rawTransaction);
1115

1216
const networkConfig = new NetworkConfig();
13-
networkConfig.MinGasLimit = GAS_LIMIT;
14-
networkConfig.GasPerDataByte = GAS_PER_DATA_BYTE;
15-
networkConfig.GasPriceModifier = GAS_PRICE_MODIFIER;
17+
networkConfig.minGasLimit = BigInt(GAS_LIMIT);
18+
networkConfig.gasPerDataByte = BigInt(GAS_PER_DATA_BYTE);
19+
networkConfig.gasPriceModifier = GAS_PRICE_MODIFIER;
1620

1721
try {
18-
return transaction.computeFee(networkConfig).toString(10);
22+
const transactionComputer = new TransactionComputer();
23+
const fee = transactionComputer.computeTransactionFee(
24+
transaction,
25+
networkConfig
26+
);
27+
return fee.toString(10);
1928
} catch (err) {
2029
return 0;
2130
}

0 commit comments

Comments
 (0)