diff --git a/lib/infrastructure/blockchain/blockchain_info_repository.dart b/lib/infrastructure/blockchain/blockchain_info_repository.dart index 29811de..186bb49 100644 --- a/lib/infrastructure/blockchain/blockchain_info_repository.dart +++ b/lib/infrastructure/blockchain/blockchain_info_repository.dart @@ -35,14 +35,13 @@ class BlockchainInfoRepository { } Future> fetchGasPrice() async { - final GasPrices200Response? gasPrice = await queryApi.gasPrices(); - final price = gasPrice?.prices.firstOrNull; - final double? gasPriceValue = double.tryParse(price?.amount ?? "0.01"); - final String denom = price?.denom ?? feeDenom; + final EvmBaseFee200Response? gasPrice = await queryApi.baseFee(); + final price = gasPrice?.baseFee; + final double? gasPriceValue = double.tryParse(price ?? "0.02"); return { - "gasPrice": "$gasPriceValue $denom", + "gasPrice": "$gasPriceValue $feeDenom", "amount": gasPriceValue.toString(), - "denom": denom + "denom": feeDenom }; } } diff --git a/lib/infrastructure/blockchain/wallet_repository.dart b/lib/infrastructure/blockchain/wallet_repository.dart index 14b1f8f..2a57467 100644 --- a/lib/infrastructure/blockchain/wallet_repository.dart +++ b/lib/infrastructure/blockchain/wallet_repository.dart @@ -237,7 +237,7 @@ class WalletRepository { String gasPriceStr, mantra.Simulate200ResponseGasInfo gasInfo, ) { - final gasPrice = double.parse(gasPriceStr); + final gasPrice = double.parse(gasPriceStr) * gasLimitMultiplier; final gasLimit = double.parse( gasInfo.gasUsed ?? defaultGasUsed ) * gasLimitMultiplier; diff --git a/lib/infrastructure/constants.dart b/lib/infrastructure/constants.dart index a5e4675..5566eb2 100644 --- a/lib/infrastructure/constants.dart +++ b/lib/infrastructure/constants.dart @@ -5,5 +5,5 @@ const String feeDenom = "uom"; const int feeExponent = 6; // For building transactions, lib/infrastructure/blockchain/wallet_repository.dart const String defaultGasUsed = "30000"; -const double gasLimitMultiplier = 3; -const String explorerUrl = "https://explorer.mantrachain.io/MANTRA-Dukong"; +const double gasLimitMultiplier = 2; +const String explorerUrl = "https://mantrascan.io/dukong"; diff --git a/lib/presentation/home_page/dapps/tx_status_widget.dart b/lib/presentation/home_page/dapps/tx_status_widget.dart index 8ac61d7..727b242 100644 --- a/lib/presentation/home_page/dapps/tx_status_widget.dart +++ b/lib/presentation/home_page/dapps/tx_status_widget.dart @@ -175,7 +175,7 @@ class _TxStatusWidgetState extends State { context, MaterialPageRoute( builder: (context) => Browser( - title: "MANTRA Explorer", + title: "MANTRA Scan", url: "$explorerUrl/tx/$_txHash", ), ), diff --git a/pubspec.lock b/pubspec.lock index 88cedf7..cf669a6 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -492,8 +492,8 @@ packages: dependency: "direct main" description: path: "." - ref: main - resolved-ref: "63edd4cc2da12b80a002e3111d7f957cc5b5a761" + ref: "v0.2.0" + resolved-ref: "23df8d15c796f7bbf3ad2d5a7bda412437a4a8c2" url: "https://github.com/BigtoC/mantrachain-dart.git" source: git version: "1.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index d3d814d..a20bc82 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 3.0.3 +version: 3.1.0 environment: sdk: "^3.8.0" @@ -41,7 +41,7 @@ dependencies: mantrachain_dart_sdk: git: url: https://github.com/BigtoC/mantrachain-dart.git - ref: main + ref: v0.2.0 cosmos_sdk: ^2.7.0 blockchain_utils: ^5.0.0 flutter_secure_storage: ^9.2.4 diff --git a/test/infrastructure/blockchain/wallet_repository_test.dart b/test/infrastructure/blockchain/wallet_repository_test.dart index e49685f..a95fe77 100644 --- a/test/infrastructure/blockchain/wallet_repository_test.dart +++ b/test/infrastructure/blockchain/wallet_repository_test.dart @@ -15,7 +15,8 @@ void main() { group("_calculateFee", () { // Create a test-only method that exposes the private _calculateFee method Fee calculateFeeForTesting( - String gasPriceStr, mantra.Simulate200ResponseGasInfo gasInfo + String gasPriceStr, + mantra.Simulate200ResponseGasInfo gasInfo, ) { return walletRepository.calculateFee(gasPriceStr, gasInfo); } @@ -25,7 +26,7 @@ void main() { final gasPriceStr = "0.025"; final gasInfo = mantra.Simulate200ResponseGasInfo( gasUsed: "100000", - gasWanted: "150000" + gasWanted: "150000", ); // Act @@ -36,8 +37,7 @@ void main() { expect(fee.amount.length, 1); expect(fee.amount[0].denom, feeDenom); - // Expected amount = gasPrice * gasLimit = 0.025 * (100000 * 3) = 7500 - expect(fee.amount[0].amount, BigInt.from(7500)); + expect(fee.amount[0].amount, BigInt.from(10000)); }); test("should use default gas when gasUsed is null", () { @@ -45,22 +45,24 @@ void main() { final gasPriceStr = "0.025"; final gasInfo = mantra.Simulate200ResponseGasInfo( gasUsed: null, - gasWanted: "150000" + gasWanted: "150000", ); // Act final fee = calculateFeeForTesting(gasPriceStr, gasInfo); // Assert - expect(fee.gasLimit, BigInt.from( - int.parse(defaultGasUsed) * gasLimitMultiplier) + expect( + fee.gasLimit, + BigInt.from(int.parse(defaultGasUsed) * gasLimitMultiplier), ); - // Expected amount = gasPrice * gasLimit = 0.025 * (30000 * 1.5) = 1125 - // (assuming defaultGasUsed is '30000') - final expectedAmount = BigInt.from(double.parse(gasPriceStr) * - double.parse(defaultGasUsed) * - gasLimitMultiplier); + final expectedAmount = BigInt.from( + double.parse(gasPriceStr) * + gasLimitMultiplier * + double.parse(defaultGasUsed) * + gasLimitMultiplier, + ); expect(fee.amount[0].amount, expectedAmount); }); @@ -69,7 +71,7 @@ void main() { final gasPriceStr = "0.01234"; final gasInfo = mantra.Simulate200ResponseGasInfo( gasUsed: "123456", - gasWanted: "200000" + gasWanted: "200000", ); // Act @@ -77,13 +79,14 @@ void main() { // Assert // Check that the result is properly rounded with no decimal places - // Expected calculation: 0.01234 * (123456 * 3) = 4570.0512, truncated to 4570 - final rawAmount = double.parse(gasPriceStr) * - double.parse(gasInfo.gasUsed!) * - gasLimitMultiplier; + final rawAmount = + double.parse(gasPriceStr) * + gasLimitMultiplier * + double.parse(gasInfo.gasUsed!) * + gasLimitMultiplier; final expectedAmount = BigInt.parse(rawAmount.floor().toString()); expect(fee.amount[0].amount, expectedAmount); - expect(fee.amount[0].amount, BigInt.from(4570)); + expect(fee.amount[0].amount, BigInt.from(6093)); }); test("should handle high gas values properly", () { @@ -91,7 +94,7 @@ void main() { final gasPriceStr = "0.0001"; final gasInfo = mantra.Simulate200ResponseGasInfo( gasUsed: "10000000", // 10 million gas - gasWanted: "15000000" + gasWanted: "15000000", ); // Act @@ -100,8 +103,7 @@ void main() { // Assert expect(fee.gasLimit, BigInt.from(10000000 * gasLimitMultiplier)); - // Expected amount = 0.0001 * (10000000 * 3) = 3000 - final expectedAmount = BigInt.from(3000); + final expectedAmount = BigInt.from(4000); expect(fee.amount[0].amount, expectedAmount); }); @@ -110,22 +112,21 @@ void main() { final gasPriceStr = "0.05"; final gasInfo = mantra.Simulate200ResponseGasInfo( gasUsed: "99999", // odd number to test rounding - gasWanted: "100000" + gasWanted: "100000", ); // Act final fee = calculateFeeForTesting(gasPriceStr, gasInfo); - // Assert - // Expected gasLimit = 99999 * 1.5 = 149998.5, rounded to 149999 final expectedGasLimit = BigInt.parse( - (99999 * gasLimitMultiplier).toStringAsFixed(0) + (99999 * gasLimitMultiplier).toStringAsFixed(0), ); expect(fee.gasLimit, expectedGasLimit); - // Expected amount = 0.05 * (99999 * 3) = 14999.85, floored to 14999 final expectedAmount = BigInt.parse( - (0.05 * 99999 * gasLimitMultiplier).floor().toString() + (0.05 * gasLimitMultiplier * 99999 * gasLimitMultiplier) + .floor() + .toString(), ); expect(fee.amount[0].amount, expectedAmount); });