Skip to content

Added dynamic gas station price based using API#1404

Merged
razvantomegea merged 9 commits intodevelopmentfrom
rt/feature/dynamic-ppu
Apr 24, 2025
Merged

Added dynamic gas station price based using API#1404
razvantomegea merged 9 commits intodevelopmentfrom
rt/feature/dynamic-ppu

Conversation

@razvantomegea
Copy link
Copy Markdown
Contributor

@razvantomegea razvantomegea commented Apr 23, 2025

Issue/Feature

Add dynamic fetching of gas station metadata to provide more accurate gas price estimations based on current network conditions.

Reproduce

Before this change, the dApp did not fetch real-time gas price recommendations (fast/faster) specific to the user's shard from the network's gas station endpoint. Gas price suggestions might not have accurately reflected current network congestion.

Root cause

The ProviderInitializer component and the network configuration state lacked the functionality to dynamically fetch and store gas station metadata (recommended gas prices) based on the logged-in user's shard.

Fix

  • Introduced a new API call getGasStationMetadataFromApi to fetch gas price metadata (fast, faster, lastBlock) for a specific shard from the /transactions/ppu/{shard} endpoint.
  • Modified ProviderInitializer.tsx to:
    • Detect when a logged-in user's account data (including shard) is available and gas station metadata is missing in the network config.
    • Call updateGasStationMetadata function which uses the new API call.
    • Dispatch an updateNetworkConfig action with the fetched gasStationMetadata.
  • Updated the NetworkType and BaseNetworkType in src/types/network.types.ts to accommodate the new structure of gasStationMetadata (keyed by shard number).

Additional changes

  • Updated CHANGELOG.md with the new feature.
  • Added tests and updated existing tests (getGasPriceDetails.test.ts) to reflect the usage of the new gasStationMetadata structure.
  • Added getGasStationMetadata.ts to apiCalls/configuration and updated the corresponding index file.
  • Added getLatestBlock to apiCalls/blocks. Useful to fetch latest block.

Contains breaking changes

  • No
  • Yes

Updated CHANGELOG

  • No
  • Yes

Testing

  • User testing (Verify gas price suggestions in components like ConfirmFee reflect fetched metadata)
  • Unit tests (Added/updated relevant tests)

@MiroMargineanu MiroMargineanu added the enhancement New feature or request label Apr 23, 2025
@razvantomegea razvantomegea merged commit 2a5a7a9 into development Apr 24, 2025
1 check passed
@razvantomegea razvantomegea deleted the rt/feature/dynamic-ppu branch April 24, 2025 12:51
razvantomegea added a commit that referenced this pull request May 7, 2025
* Added dynamic gas station price based using API (#1404)

* Added dynamic gas station metadata fetch

* Log

* Refactor

* revert

* Refactor

* Revert latestblock

* Added chain id check

* Fix

* Fixed sdk-core imports (#1405)

* Added dynamic gas station metadata fetch

* Log

* Refactor

* revert

* Refactor

* Revert latestblock

* Added chain id check

* Fix

* Fixed sdk-core imports

* CHANGELOG

* Added account cleanup on login (#1408)

* Added account cleanup on login

* CHANGELOG

* v4.1.4 (#1409)

* Fixed tests

* Clear address

* Added clear at web wallet login

---------

Co-authored-by: Radu Mojic <radu.mojic@multiversx.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants