From 5acfbc5e2466df1b38f87273927d86f67465740e Mon Sep 17 00:00:00 2001 From: cipriandraghici Date: Thu, 21 Dec 2023 10:08:24 +0200 Subject: [PATCH 1/2] remove sdk-network-providers from deps --- package.json | 1 - src/models/TransactionStatus.ts | 83 +++++++++++++++++++ .../transactions/getTransactionsDetails.ts | 2 +- src/utils/operations/calculateFeeLimit.ts | 13 ++- yarn.lock | 47 +++-------- 5 files changed, 100 insertions(+), 46 deletions(-) create mode 100644 src/models/TransactionStatus.ts diff --git a/package.json b/package.json index c6e20010b..1ae950b03 100644 --- a/package.json +++ b/package.json @@ -147,7 +147,6 @@ "@multiversx/sdk-extension-provider": "3.0.0", "@multiversx/sdk-hw-provider": "6.4.0", "@multiversx/sdk-native-auth-client": "1.0.6", - "@multiversx/sdk-network-providers": "2.2.0", "@multiversx/sdk-opera-provider": "1.0.0-alpha.1", "@multiversx/sdk-wallet": "4.2.0", "@multiversx/sdk-wallet-connect-provider": "4.0.4", diff --git a/src/models/TransactionStatus.ts b/src/models/TransactionStatus.ts new file mode 100644 index 000000000..a789e1080 --- /dev/null +++ b/src/models/TransactionStatus.ts @@ -0,0 +1,83 @@ +/** + * An abstraction for handling and interpreting the "status" field of a transaction. + */ +export class TransactionStatus { + /** + * The raw status, as fetched from the Network. + */ + readonly status: string; + + /** + * Creates a new TransactionStatus object. + */ + constructor(status: string) { + this.status = (status || '').toLowerCase(); + } + + /** + * Creates an unknown status. + */ + static createUnknown(): TransactionStatus { + return new TransactionStatus('unknown'); + } + + /** + * Returns whether the transaction is pending (e.g. in mempool). + */ + isPending(): boolean { + return this.status == 'received' || this.status == 'pending'; + } + + /** + * Returns whether the transaction has been executed (not necessarily with success). + */ + isExecuted(): boolean { + return this.isSuccessful() || this.isFailed() || this.isInvalid(); + } + + /** + * Returns whether the transaction has been executed successfully. + */ + isSuccessful(): boolean { + return ( + this.status == 'executed' || + this.status == 'success' || + this.status == 'successful' + ); + } + + /** + * Returns whether the transaction has been executed, but with a failure. + */ + isFailed(): boolean { + return ( + this.status == 'fail' || + this.status == 'failed' || + this.status == 'unsuccessful' || + this.isInvalid() + ); + } + + /** + * Returns whether the transaction has been executed, but marked as invalid (e.g. due to "insufficient funds"). + */ + isInvalid(): boolean { + return this.status == 'invalid'; + } + + toString(): string { + return this.status; + } + + valueOf(): string { + return this.status; + } + + equals(other: TransactionStatus) { + if (!other) { + return false; + } + + return this.status == other.status; + } +} diff --git a/src/services/transactions/getTransactionsDetails.ts b/src/services/transactions/getTransactionsDetails.ts index fe40adcba..f9fd9a590 100644 --- a/src/services/transactions/getTransactionsDetails.ts +++ b/src/services/transactions/getTransactionsDetails.ts @@ -1,5 +1,5 @@ -import { TransactionStatus } from '@multiversx/sdk-network-providers'; import { getTransactionByHashPromise } from 'apiCalls'; +import { TransactionStatus } from 'models/TransactionStatus'; import { ServerTransactionType } from 'types'; import { delayWithPromise } from 'utils/delayWithPromise'; diff --git a/src/utils/operations/calculateFeeLimit.ts b/src/utils/operations/calculateFeeLimit.ts index c24aec6ed..ad1ee86f7 100755 --- a/src/utils/operations/calculateFeeLimit.ts +++ b/src/utils/operations/calculateFeeLimit.ts @@ -5,7 +5,6 @@ import { Address, TokenPayment } from '@multiversx/sdk-core'; -import { NetworkConfig } from '@multiversx/sdk-network-providers'; import BigNumber from 'bignumber.js'; import { EXTRA_GAS_LIMIT_GUARDED_TX, @@ -62,13 +61,13 @@ export function calculateFeeLimit({ version: new TransactionVersion(1) }); - const networkConfig = new NetworkConfig(); - networkConfig.MinGasLimit = parseInt(minGasLimit); - networkConfig.GasPerDataByte = parseInt(gasPerDataByte); - networkConfig.GasPriceModifier = parseFloat(gasPriceModifier); - try { - const bNfee = transaction.computeFee(networkConfig); + const bNfee = transaction.computeFee({ + GasPerDataByte: parseInt(gasPerDataByte), + MinGasLimit: parseInt(minGasLimit), + GasPriceModifier: parseFloat(gasPriceModifier), + ChainID: chainId + }); return bNfee.toString(10); } catch (err) { console.error(err); diff --git a/yarn.lock b/yarn.lock index ca9b2dd75..a763bcc5a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1964,17 +1964,6 @@ dependencies: axios "^1.6.2" -"@multiversx/sdk-network-providers@2.2.0": - version "2.2.0" - resolved "https://registry.yarnpkg.com/@multiversx/sdk-network-providers/-/sdk-network-providers-2.2.0.tgz#2b8d5fbbc848dbeba38950db2f02340908dfcfd3" - integrity sha512-2n/+7Ap6S9rJGTiX38GCZ2TmY9zQ1U7o1DwnWpHNRJRxArSN/xzLrbcSKy8InMyc+4A+VHf5pV0Pk8NdPV6++w== - dependencies: - axios "1.6.1" - bech32 "1.1.4" - bignumber.js "9.0.1" - buffer "6.0.3" - json-bigint "1.0.0" - "@multiversx/sdk-opera-provider@1.0.0-alpha.1": version "1.0.0-alpha.1" resolved "https://registry.yarnpkg.com/@multiversx/sdk-opera-provider/-/sdk-opera-provider-1.0.0-alpha.1.tgz#2beebd5423fdc2e667b33660f17cbff325449097" @@ -3885,9 +3874,9 @@ "@types/estree" "*" "@types/eslint@*": - version "8.44.9" - resolved "https://registry.yarnpkg.com/@types/eslint/-/eslint-8.44.9.tgz#5799663009645637bd1c45b2e1a7c8f4caf89534" - integrity sha512-6yBxcvwnnYoYT1Uk2d+jvIfsuP4mb2EdIxFnrPABj5a/838qe5bGkNLFOiipX4ULQ7XVQvTxOh7jO+BTAiqsEw== + version "8.56.0" + resolved "https://registry.yarnpkg.com/@types/eslint/-/eslint-8.56.0.tgz#e28d045b8e530a33c9cbcfbf02332df0d1380a2c" + integrity sha512-FlsN0p4FhuYRjIxpbdXovvHQhtlG05O1GG/RNWvdAxTboR438IOTwmrY/vLA+Xfgg06BTkP045M3vpFwTMv1dg== dependencies: "@types/estree" "*" "@types/json-schema" "*" @@ -5387,15 +5376,6 @@ axios-mock-adapter@1.21.2: fast-deep-equal "^3.1.3" is-buffer "^2.0.5" -axios@1.6.1: - version "1.6.1" - resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.1.tgz#76550d644bf0a2d469a01f9244db6753208397d7" - integrity sha512-vfBmhDpKafglh0EldBEbVuoe7DyAavGSLWhuSm5ZSEKQnHhBf0xAAwybbNH1IkrJNGnS/VG4I5yxig1pCEXE4g== - dependencies: - follow-redirects "^1.15.0" - form-data "^4.0.0" - proxy-from-env "^1.1.0" - axios@1.6.2, axios@^1.6.2: version "1.6.2" resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.2.tgz#de67d42c755b571d3e698df1b6504cde9b0ee9f2" @@ -5627,7 +5607,7 @@ bignumber.js@9.0.1: resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-9.0.1.tgz#8d7ba124c882bfd8e43260c67475518d0689e4e5" integrity sha512-IdZR9mh6ahOBv/hYGiXyVuyCetmGJhtYkqLBpTStdhEGjegpPlUawydyaF3pbIOFynJTpllEs+NP+CS9jKFLjA== -bignumber.js@9.x, bignumber.js@^9.0.0: +bignumber.js@9.x: version "9.1.2" resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-9.1.2.tgz#b7c4242259c008903b13707983b5f4bbd31eda0c" integrity sha512-2/mKyZH9K85bzOEfhXDBFZTGd1CTs+5IHpeFQo9luiBG7hghdC851Pj2WAhb6E3R6b9tZj/XKhbg4fum+Kepug== @@ -7318,9 +7298,9 @@ ee-first@1.1.1: integrity sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow== electron-to-chromium@^1.4.601: - version "1.4.614" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.614.tgz#2fe789d61fa09cb875569f37c309d0c2701f91c0" - integrity sha512-X4ze/9Sc3QWs6h92yerwqv7aB/uU8vCjZcrMjA8N9R1pjMFRe44dLsck5FzLilOYvcXuDn93B+bpGYyufc70gQ== + version "1.4.615" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.615.tgz#b1c41839962d2e4e63dca05519da9040e34848c2" + integrity sha512-/bKPPcgZVUziECqDc+0HkT87+0zhaWSZHNXqF8FLd2lQcptpmUFwoCSWjCdOng9Gdq+afKArPdEg/0ZW461Eng== element-resize-detector@^1.2.2: version "1.2.4" @@ -8408,9 +8388,9 @@ fast-redact@^3.0.0: integrity sha512-6T5V1QK1u4oF+ATxs1lWUmlEk6P2T9HqJG3e2DnHOdVgZy2rFJBoEnrIedcTXlkAHU/zKC+7KETJ+KGGKwxgMQ== fastq@^1.6.0: - version "1.15.0" - resolved "https://registry.yarnpkg.com/fastq/-/fastq-1.15.0.tgz#d04d07c6a2a68fe4599fea8d2e103a937fae6b3a" - integrity sha512-wBrocU2LCXXa+lWBt8RoIRD89Fi8OdABODa/kEnyeyjS5aZO5/GNvI5sEINADqP/h8M29UHTHUb53sUu5Ihqdw== + version "1.16.0" + resolved "https://registry.yarnpkg.com/fastq/-/fastq-1.16.0.tgz#83b9a9375692db77a822df081edb6a9cf6839320" + integrity sha512-ifCoaXsDrsdkWTtiNJX5uzHDsrck5TzfKKDcuFFTIrrc/BS076qgEIfoIy1VeZqViznfKiysPYTh/QeHtnIsYA== dependencies: reusify "^1.0.4" @@ -10882,13 +10862,6 @@ jsesc@~0.5.0: resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-0.5.0.tgz#e7dee66e35d6fc16f710fe91d5cf69f70f08911d" integrity sha512-uZz5UnB7u4T9LvwmFqXii7pZSouaRPorGs5who1Ip7VO0wxanFvBL7GkM6dTHlgX+jhBApRetaWpnDabOeTcnA== -json-bigint@1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/json-bigint/-/json-bigint-1.0.0.tgz#ae547823ac0cad8398667f8cd9ef4730f5b01ff1" - integrity sha512-SiPv/8VpZuWbvLSMtTDU8hEfrZWg/mH/nV/b4o0CYbSxu1UIQPLdwKOCIyLQX+VIPO5vrLX3i8qtqFyhdPSUSQ== - dependencies: - bignumber.js "^9.0.0" - json-buffer@3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/json-buffer/-/json-buffer-3.0.1.tgz#9338802a30d3b6605fbe0613e094008ca8c05a13" From 7e4326fddf22ee15ce8b0ba621cbad1ab28980b5 Mon Sep 17 00:00:00 2001 From: cipriandraghici Date: Thu, 21 Dec 2023 10:15:45 +0200 Subject: [PATCH 2/2] update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b72924bf6..fa2cd19c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +- [Remove sdk-network-providers from the dependencies](https://github.com/multiversx/mx-sdk-dapp/pull/1000) + ## [[v2.26.0]](https://github.com/multiversx/mx-sdk-dapp/pull/998)] - 2023-12-20 - [Prevent logout action when not logged in or provider not initialized](https://github.com/multiversx/mx-sdk-dapp/pull/997)