From f2133307fbdffa66f6bfc8f43335c601a6df6af0 Mon Sep 17 00:00:00 2001 From: reasje Date: Tue, 12 Sep 2023 18:53:29 +0330 Subject: [PATCH 01/10] fix: Switch network bug --- .../subfeatures/open_dapp/open_dapp_presenter.dart | 13 +++++++++++++ .../web3_provider/lib/js_bridge_callback_bean.dart | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart b/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart index 2a170e75..f9c8d341 100644 --- a/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart +++ b/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart @@ -188,6 +188,19 @@ class OpenDAppPresenter extends CompletePresenter { _chainConfigurationUseCase.switchDefaultNetwork(toNetwork); _authUseCase.resetNetwork(toNetwork); notify(() => state.network = toNetwork); + // state.webviewController?.send("eth_chainId"); + var config = """{ + ethereum: { + chainId: ${toNetwork.chainId}, + rpcUrl: "${toNetwork.web3RpcHttpUrl}", + address: "${state.account!.address}", + isDebug: true, + networkVersion: "${toNetwork.chainId}", + isMetaMask: true + } + }"""; + state.webviewController + ?.setConfig(config, "0x${toNetwork.chainId.toRadixString(16)}"); state.webviewController?.sendResult('null', id); } } diff --git a/packages/web3_provider/lib/js_bridge_callback_bean.dart b/packages/web3_provider/lib/js_bridge_callback_bean.dart index c213c364..eeac902f 100644 --- a/packages/web3_provider/lib/js_bridge_callback_bean.dart +++ b/packages/web3_provider/lib/js_bridge_callback_bean.dart @@ -38,4 +38,11 @@ extension Web3Result on InAppWebViewController { await evaluateJavascript(source: script); sendResults([address], id); } + + void setConfig(String config, String chainId) async { + final script = "window.ethereum.setConfig($config);"; + final script2 = "window.ethereum.emitConnect($chainId);"; + await evaluateJavascript(source: script); + await evaluateJavascript(source: script2); + } } From 16c5b67b7a565e14d7773da75b219bb60bbe0fff Mon Sep 17 00:00:00 2001 From: reasje Date: Tue, 12 Sep 2023 19:35:24 +0330 Subject: [PATCH 02/10] fix: Improved switch chain to support more dapps --- .../dapps/subfeatures/open_dapp/open_dapp_page.dart | 2 +- .../subfeatures/open_dapp/open_dapp_presenter.dart | 3 +-- .../web3_provider/lib/js_bridge_callback_bean.dart | 11 +++++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/features/dapps/subfeatures/open_dapp/open_dapp_page.dart b/lib/features/dapps/subfeatures/open_dapp/open_dapp_page.dart index 7eec00b0..0076d217 100644 --- a/lib/features/dapps/subfeatures/open_dapp/open_dapp_page.dart +++ b/lib/features/dapps/subfeatures/open_dapp/open_dapp_page.dart @@ -62,7 +62,7 @@ class OpenAppPage extends HookConsumerWidget { collectLog('onLoadError: $code: $message'), onLoadHttpError: (controller, url, statusCode, description) => collectLog('onLoadHttpError: $description'), - onConsoleMessage: (controller, consoleMessage) => collectLog( + onConsoleMessage: (controller, consoleMessage) => print( 'onConsoleMessage: ${consoleMessage.toString()}'), onWebViewCreated: (controller) => presenter.onWebViewCreated(controller), diff --git a/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart b/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart index f9c8d341..5c52bc23 100644 --- a/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart +++ b/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart @@ -200,7 +200,6 @@ class OpenDAppPresenter extends CompletePresenter { } }"""; state.webviewController - ?.setConfig(config, "0x${toNetwork.chainId.toRadixString(16)}"); - state.webviewController?.sendResult('null', id); + ?.setChain(config, toNetwork.chainId, id); } } diff --git a/packages/web3_provider/lib/js_bridge_callback_bean.dart b/packages/web3_provider/lib/js_bridge_callback_bean.dart index eeac902f..19a249ae 100644 --- a/packages/web3_provider/lib/js_bridge_callback_bean.dart +++ b/packages/web3_provider/lib/js_bridge_callback_bean.dart @@ -38,11 +38,14 @@ extension Web3Result on InAppWebViewController { await evaluateJavascript(source: script); sendResults([address], id); } - - void setConfig(String config, String chainId) async { - final script = "window.ethereum.setConfig($config);"; - final script2 = "window.ethereum.emitConnect($chainId);"; + + void setChain(String config, int chainId, int id) async { + final script = "console.log(window.ethereum.setConfig($config))"; + final script2 = "console.log(window.ethereum.emitConnect($chainId))"; + final script3 = "console.log(window.ethereum.emitChainChanged($chainId))"; await evaluateJavascript(source: script); await evaluateJavascript(source: script2); + await evaluateJavascript(source: script3); + sendResult(chainId.toRadixString(16), id); } } From be28a97b7d7ac54be8d0d2fcd31408645e0d1305 Mon Sep 17 00:00:00 2001 From: reasje Date: Wed, 13 Sep 2023 11:03:42 +0330 Subject: [PATCH 03/10] fix: Added expo number validation --- lib/common/utils/validation.dart | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/common/utils/validation.dart b/lib/common/utils/validation.dart index 085f9895..b6ecc870 100644 --- a/lib/common/utils/validation.dart +++ b/lib/common/utils/validation.dart @@ -83,4 +83,9 @@ class Validation { return null; } } + + static bool isExpoNumber(String input) { + RegExp regex = RegExp(r'^(\d+\.\d+e[-+]\d+)$'); + return regex.hasMatch(input); + } } From b0b7583a43adfc1a15ff8eb5cebcca873767a96d Mon Sep 17 00:00:00 2001 From: reasje Date: Wed, 13 Sep 2023 11:06:13 +0330 Subject: [PATCH 04/10] fix: Added gas amount to estimate gas fee --- .../common/contract/token_contract_use_case.dart | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/features/common/contract/token_contract_use_case.dart b/lib/features/common/contract/token_contract_use_case.dart index a5e3a9ef..8ce13814 100644 --- a/lib/features/common/contract/token_contract_use_case.dart +++ b/lib/features/common/contract/token_contract_use_case.dart @@ -130,13 +130,14 @@ class TokenContractUseCase extends ReactiveUseCase { required String to, EtherAmount? gasPrice, Uint8List? data, + BigInt? amountOfGas, }) async => await _repository.tokenContract.estimateGesFee( - from: from, - to: to, - gasPrice: gasPrice, - data: data, - ); + from: from, + to: to, + gasPrice: gasPrice, + data: data, + amountOfGas: amountOfGas); Future sendTransaction({ required String privateKey, From 8d3d3996147699ede65b72d9a24251ed5259fb19 Mon Sep 17 00:00:00 2001 From: reasje Date: Wed, 13 Sep 2023 11:16:14 +0330 Subject: [PATCH 05/10] fix: expo number control & response for unavailable network --- .../open_dapp/open_dapp_presenter.dart | 39 +++++++++++-------- packages/shared | 2 +- .../lib/js_bridge_callback_bean.dart | 13 +++---- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart b/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart index 5c52bc23..02bfbbeb 100644 --- a/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart +++ b/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart @@ -55,15 +55,16 @@ class OpenDAppPresenter extends CompletePresenter { String to, EtherAmount? gasPrice, Uint8List? data, + BigInt? amountOfGas, ) async { loading = true; try { final gasFee = await _tokenContractUseCase.estimateGesFee( - from: from, - to: to, - gasPrice: gasPrice, - data: data, - ); + from: from, + to: to, + gasPrice: gasPrice, + data: data, + amountOfGas: amountOfGas); loading = false; return gasFee; @@ -106,22 +107,20 @@ class OpenDAppPresenter extends CompletePresenter { EtherAmount? gasPrice; EtherAmount? gasFee; EstimatedGasFee? estimatedGasFee; + BigInt? amountOfGas; if (bridge.gasPrice != null) { gasPrice = EtherAmount.fromBase10String(EtherUnit.wei, bridge.gasPrice!); } if (bridge.gas != null) { + amountOfGas = BigInt.parse(bridge.gas.toString()); gasPrice = gasPrice ?? await _tokenContractUseCase.getGasPrice(); - gasFee = EtherAmount.fromBigInt(EtherUnit.wei, - gasPrice.getInWei * BigInt.parse(bridge.gas.toString())); + gasFee = EtherAmount.fromBigInt( + EtherUnit.wei, gasPrice.getInWei * amountOfGas); } else { estimatedGasFee = await _estimatedFee( - bridge.from!, - bridge.to!, - gasPrice, - bridgeData, - ); + bridge.from!, bridge.to!, gasPrice, bridgeData, amountOfGas); if (estimatedGasFee == null) { cancel.call(); @@ -129,6 +128,14 @@ class OpenDAppPresenter extends CompletePresenter { } } + String finalFee = (gasFee?.getInWei != null + ? gasFee!.getValueInUnit(EtherUnit.ether) + : (estimatedGasFee?.gasFee ?? 0)) + .toString(); + + if (Validation.isExpoNumber(finalFee)) { + finalFee = '0.0'; + } try { final result = await showTransactionDialog( context!, @@ -136,8 +143,7 @@ class OpenDAppPresenter extends CompletePresenter { amount: amount, from: bridge.from!, to: bridge.to!, - estimatedFee: - '${gasFee?.getInWei != null ? gasFee!.getValueInUnit(EtherUnit.ether) : (estimatedGasFee?.gasFee ?? 0)}', + estimatedFee: finalFee, ); if (result != null && result) { @@ -171,6 +177,7 @@ class OpenDAppPresenter extends CompletePresenter { }); } else { addError(translate('network_not_found')); + state.webviewController?.sendError(translate('network_not_found')!, id); } } @@ -188,7 +195,6 @@ class OpenDAppPresenter extends CompletePresenter { _chainConfigurationUseCase.switchDefaultNetwork(toNetwork); _authUseCase.resetNetwork(toNetwork); notify(() => state.network = toNetwork); - // state.webviewController?.send("eth_chainId"); var config = """{ ethereum: { chainId: ${toNetwork.chainId}, @@ -199,7 +205,6 @@ class OpenDAppPresenter extends CompletePresenter { isMetaMask: true } }"""; - state.webviewController - ?.setChain(config, toNetwork.chainId, id); + state.webviewController?.setChain(config, toNetwork.chainId, id); } } diff --git a/packages/shared b/packages/shared index 398b14b9..a26a86d6 160000 --- a/packages/shared +++ b/packages/shared @@ -1 +1 @@ -Subproject commit 398b14b957dc481e2369604b0733da3cd5f24055 +Subproject commit a26a86d6c9d314ad7ad4a85ee7b85b037f7ae669 diff --git a/packages/web3_provider/lib/js_bridge_callback_bean.dart b/packages/web3_provider/lib/js_bridge_callback_bean.dart index 19a249ae..9a5ac3aa 100644 --- a/packages/web3_provider/lib/js_bridge_callback_bean.dart +++ b/packages/web3_provider/lib/js_bridge_callback_bean.dart @@ -40,12 +40,11 @@ extension Web3Result on InAppWebViewController { } void setChain(String config, int chainId, int id) async { - final script = "console.log(window.ethereum.setConfig($config))"; - final script2 = "console.log(window.ethereum.emitConnect($chainId))"; - final script3 = "console.log(window.ethereum.emitChainChanged($chainId))"; - await evaluateJavascript(source: script); - await evaluateJavascript(source: script2); - await evaluateJavascript(source: script3); - sendResult(chainId.toRadixString(16), id); + final setConfigScript = "console.log(window.ethereum.setConfig($config))"; + final emitChainChangeScript = + "console.log(window.ethereum.emitChainChanged($chainId))"; + await evaluateJavascript(source: setConfigScript); + await evaluateJavascript(source: emitChainChangeScript); + sendResult('null', id); } } From a70892df82538b03c72abbe73cf4c22acf60cffe Mon Sep 17 00:00:00 2001 From: reasje Date: Wed, 13 Sep 2023 13:02:23 +0330 Subject: [PATCH 06/10] fix: Updated symbol for dapp tx sheet --- .../subfeatures/open_dapp/open_dapp_page.dart | 2 +- .../open_dapp/open_dapp_presenter.dart | 18 ++++++++------- .../open_dapp/widgets/transaction_dialog.dart | 2 ++ .../open_dapp/widgets/transaction_info.dart | 22 ++++++++++--------- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/lib/features/dapps/subfeatures/open_dapp/open_dapp_page.dart b/lib/features/dapps/subfeatures/open_dapp/open_dapp_page.dart index 0076d217..7eec00b0 100644 --- a/lib/features/dapps/subfeatures/open_dapp/open_dapp_page.dart +++ b/lib/features/dapps/subfeatures/open_dapp/open_dapp_page.dart @@ -62,7 +62,7 @@ class OpenAppPage extends HookConsumerWidget { collectLog('onLoadError: $code: $message'), onLoadHttpError: (controller, url, statusCode, description) => collectLog('onLoadHttpError: $description'), - onConsoleMessage: (controller, consoleMessage) => print( + onConsoleMessage: (controller, consoleMessage) => collectLog( 'onConsoleMessage: ${consoleMessage.toString()}'), onWebViewCreated: (controller) => presenter.onWebViewCreated(controller), diff --git a/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart b/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart index 02bfbbeb..d5861f32 100644 --- a/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart +++ b/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart @@ -136,15 +136,17 @@ class OpenDAppPresenter extends CompletePresenter { if (Validation.isExpoNumber(finalFee)) { finalFee = '0.0'; } + + final symbol = state.network!.symbol; + try { - final result = await showTransactionDialog( - context!, - title: translate('confirm_transaction')!, - amount: amount, - from: bridge.from!, - to: bridge.to!, - estimatedFee: finalFee, - ); + final result = await showTransactionDialog(context!, + title: translate('confirm_transaction')!, + amount: amount, + from: bridge.from!, + to: bridge.to!, + estimatedFee: finalFee, + symbol: symbol); if (result != null && result) { final hash = await _sendTransaction(bridge.to!, amountEther, bridgeData, diff --git a/lib/features/dapps/subfeatures/open_dapp/widgets/transaction_dialog.dart b/lib/features/dapps/subfeatures/open_dapp/widgets/transaction_dialog.dart index 768a1ee8..b6da7c4d 100644 --- a/lib/features/dapps/subfeatures/open_dapp/widgets/transaction_dialog.dart +++ b/lib/features/dapps/subfeatures/open_dapp/widgets/transaction_dialog.dart @@ -11,6 +11,7 @@ Future showTransactionDialog( required String to, String? estimatedFee, VoidCallback? onTap, + required String symbol }) { return showModalBottomSheet( context: context, @@ -46,6 +47,7 @@ Future showTransactionDialog( to: to, estimatedFee: estimatedFee, onTap: onTap, + symbol: symbol, ), const SizedBox(height: 10), ], diff --git a/lib/features/dapps/subfeatures/open_dapp/widgets/transaction_info.dart b/lib/features/dapps/subfeatures/open_dapp/widgets/transaction_info.dart index f6218b87..268b398c 100644 --- a/lib/features/dapps/subfeatures/open_dapp/widgets/transaction_info.dart +++ b/lib/features/dapps/subfeatures/open_dapp/widgets/transaction_info.dart @@ -7,20 +7,22 @@ import 'package:mxc_ui/mxc_ui.dart'; import 'transaction_dialog.dart'; class TransactionInfo extends StatelessWidget { - const TransactionInfo({ - Key? key, - required this.amount, - required this.from, - required this.to, - this.estimatedFee, - this.onTap, - }) : super(key: key); + const TransactionInfo( + {Key? key, + required this.amount, + required this.from, + required this.to, + this.estimatedFee, + this.onTap, + required this.symbol}) + : super(key: key); final String amount; final String from; final String to; final String? estimatedFee; final VoidCallback? onTap; + final String symbol; @override Widget build(BuildContext context) { @@ -80,7 +82,7 @@ class TransactionInfo extends StatelessWidget { ), const SizedBox(width: 4), Text( - 'MXC', + symbol, style: FontTheme.of(context).h5.secondary(), ), const SizedBox(height: 4), @@ -110,7 +112,7 @@ class TransactionInfo extends StatelessWidget { ), const SizedBox(width: 4), Text( - 'MXC', + symbol, style: FontTheme.of(context).body1().copyWith( color: ColorsTheme.of(context).grey2, ), From cf58dc53bf5f577ee643777f188581b67a604b55 Mon Sep 17 00:00:00 2001 From: reasje Date: Wed, 13 Sep 2023 13:03:49 +0330 Subject: [PATCH 07/10] fix: Update dynamic symbol for nft tx sheet --- .../nft/send_nft/send_nft_presenter.dart | 33 ++++++++++++------- .../nft/send_nft/send_nft_state.dart | 1 + .../send_nft/widgets/transaction_dialog.dart | 22 ++++++------- .../send_nft/widgets/transaction_info.dart | 33 ++++++++++--------- packages/shared | 2 +- 5 files changed, 52 insertions(+), 39 deletions(-) diff --git a/lib/features/portfolio/subfeatures/nft/send_nft/send_nft_presenter.dart b/lib/features/portfolio/subfeatures/nft/send_nft/send_nft_presenter.dart index 7a20e35f..232ffa82 100644 --- a/lib/features/portfolio/subfeatures/nft/send_nft/send_nft_presenter.dart +++ b/lib/features/portfolio/subfeatures/nft/send_nft/send_nft_presenter.dart @@ -20,6 +20,8 @@ class SendNftPresenter extends CompletePresenter { late final _tokenContractUseCase = ref.read(tokenContractUseCaseProvider); late final _nftContractUseCase = ref.read(nftContractUseCaseProvider); late final _accountUseCase = ref.read(accountUseCaseProvider); + late final _chainConfigurationUseCase = + ref.read(chainConfigurationUseCaseProvider); late final _nftsUseCase = ref.read(nftsUseCaseProvider); late final TextEditingController recipientController = TextEditingController(); @@ -36,6 +38,14 @@ class SendNftPresenter extends CompletePresenter { }, ); + listen( + _chainConfigurationUseCase.selectedNetwork, + (value) { + notify(() => state.network = value); + loadPage(); + }, + ); + listen( _nftContractUseCase.online, (value) => notify(() => state.online = value), @@ -57,17 +67,18 @@ class SendNftPresenter extends CompletePresenter { } } - final result = await showTransactionDialog( - context!, - title: _getDialogTitle(nft.name), - nft: nft, - newtork: 'MXC zkEVM', - from: state.account!.address, - to: recipient, - processType: state.processType, - estimatedFee: state.estimatedGasFee?.gasFee.toString(), - onTap: _nextTransactionStep, - ); + final symbol = state.network!.symbol; + + final result = await showTransactionDialog(context!, + title: _getDialogTitle(nft.name), + nft: nft, + newtork: 'MXC zkEVM', + from: state.account!.address, + to: recipient, + processType: state.processType, + estimatedFee: state.estimatedGasFee?.gasFee.toString(), + onTap: _nextTransactionStep, + symbol: symbol); if (result != null && !result) { notify(() => state.processType = TransactionProcessType.confirm); diff --git a/lib/features/portfolio/subfeatures/nft/send_nft/send_nft_state.dart b/lib/features/portfolio/subfeatures/nft/send_nft/send_nft_state.dart index 32926bfb..fb71d12c 100644 --- a/lib/features/portfolio/subfeatures/nft/send_nft/send_nft_state.dart +++ b/lib/features/portfolio/subfeatures/nft/send_nft/send_nft_state.dart @@ -11,6 +11,7 @@ class SendNftState with EquatableMixin { TransactionProcessType processType = TransactionProcessType.confirm; Account? account; EstimatedGasFee? estimatedGasFee; + Network? network; @override List get props => [ diff --git a/lib/features/portfolio/subfeatures/nft/send_nft/widgets/transaction_dialog.dart b/lib/features/portfolio/subfeatures/nft/send_nft/widgets/transaction_dialog.dart index cdcd8e12..d97811bc 100644 --- a/lib/features/portfolio/subfeatures/nft/send_nft/widgets/transaction_dialog.dart +++ b/lib/features/portfolio/subfeatures/nft/send_nft/widgets/transaction_dialog.dart @@ -6,17 +6,16 @@ import 'transaction_info.dart'; enum TransactionProcessType { confirm, send, done } -Future showTransactionDialog( - BuildContext context, { - String? title, - required Nft nft, - required String newtork, - required String from, - required String to, - String? estimatedFee, - TransactionProcessType? processType, - VoidCallback? onTap, -}) { +Future showTransactionDialog(BuildContext context, + {String? title, + required Nft nft, + required String newtork, + required String from, + required String to, + String? estimatedFee, + TransactionProcessType? processType, + VoidCallback? onTap, + required String symbol}) { return showModalBottomSheet( context: context, useRootNavigator: true, @@ -52,6 +51,7 @@ Future showTransactionDialog( estimatedFee: estimatedFee, processType: processType, onTap: onTap, + symbol: symbol, ), const SizedBox(height: 10), ], diff --git a/lib/features/portfolio/subfeatures/nft/send_nft/widgets/transaction_info.dart b/lib/features/portfolio/subfeatures/nft/send_nft/widgets/transaction_info.dart index 6f80b5b0..8a03126f 100644 --- a/lib/features/portfolio/subfeatures/nft/send_nft/widgets/transaction_info.dart +++ b/lib/features/portfolio/subfeatures/nft/send_nft/widgets/transaction_info.dart @@ -8,16 +8,17 @@ import 'package:mxc_ui/mxc_ui.dart'; import 'transaction_dialog.dart'; class TransactionInfo extends StatelessWidget { - const TransactionInfo({ - Key? key, - required this.nft, - required this.newtork, - required this.from, - required this.to, - this.estimatedFee, - this.processType = TransactionProcessType.confirm, - this.onTap, - }) : super(key: key); + const TransactionInfo( + {Key? key, + required this.nft, + required this.newtork, + required this.from, + required this.to, + this.estimatedFee, + this.processType = TransactionProcessType.confirm, + this.onTap, + required this.symbol}) + : super(key: key); final Nft nft; final String newtork; @@ -25,6 +26,7 @@ class TransactionInfo extends StatelessWidget { final String to; final String? estimatedFee; final TransactionProcessType? processType; + final String symbol; final VoidCallback? onTap; @override @@ -39,7 +41,7 @@ class TransactionInfo extends StatelessWidget { addressItem(context, 'from', from), addressItem(context, 'to', to), if (TransactionProcessType.confirm != processType) - priceItem(context, 'estimated_fee', estimatedFee), + priceItem(context, 'estimated_fee', estimatedFee, symbol), ], ), ), @@ -92,10 +94,7 @@ class TransactionInfo extends StatelessWidget { } Widget priceItem( - BuildContext context, - String label, - String? price, - ) { + BuildContext context, String label, String? price, String symbol) { return TransactionItem( label: label, content: Row( @@ -103,7 +102,9 @@ class TransactionInfo extends StatelessWidget { children: [ Text( price != null - ? Formatter.formatNumberForUI(price,) + ? Formatter.formatNumberForUI( + price, + ) : '--', style: FontTheme.of(context).body1.primary(), ), diff --git a/packages/shared b/packages/shared index a26a86d6..62a91c6e 160000 --- a/packages/shared +++ b/packages/shared @@ -1 +1 @@ -Subproject commit a26a86d6c9d314ad7ad4a85ee7b85b037f7ae669 +Subproject commit 62a91c6e0e3d1eba325eb7c165622ed1bca16438 From 1b18db62893f232cfd1f752f8c7d19b754a7d4fd Mon Sep 17 00:00:00 2001 From: reasje Date: Wed, 13 Sep 2023 18:38:42 +0330 Subject: [PATCH 08/10] fix: Sending price details to send tx --- .../open_dapp/open_dapp_presenter.dart | 34 ++++++++++--------- packages/shared | 2 +- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart b/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart index d5861f32..b5f3961d 100644 --- a/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart +++ b/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart @@ -75,18 +75,18 @@ class OpenDAppPresenter extends CompletePresenter { } } - Future _sendTransaction( - String to, EtherAmount amount, Uint8List? data, + Future _sendTransaction(String to, EtherAmount amount, + Uint8List? data, EstimatedGasFee? estimatedGasFee, {String? from}) async { loading = true; try { final res = await _tokenContractUseCase.sendTransaction( - privateKey: state.account!.privateKey, - to: to, - from: from, - amount: amount, - data: data, - ); + privateKey: state.account!.privateKey, + to: to, + from: from, + amount: amount, + data: data, + estimatedGasFee: estimatedGasFee); return res; } catch (e, s) { @@ -105,7 +105,7 @@ class OpenDAppPresenter extends CompletePresenter { final amount = amountEther.getValueInUnit(EtherUnit.ether).toString(); final bridgeData = hexToBytes(bridge.data ?? ''); EtherAmount? gasPrice; - EtherAmount? gasFee; + double? gasFee; EstimatedGasFee? estimatedGasFee; BigInt? amountOfGas; @@ -116,8 +116,12 @@ class OpenDAppPresenter extends CompletePresenter { if (bridge.gas != null) { amountOfGas = BigInt.parse(bridge.gas.toString()); gasPrice = gasPrice ?? await _tokenContractUseCase.getGasPrice(); - gasFee = EtherAmount.fromBigInt( - EtherUnit.wei, gasPrice.getInWei * amountOfGas); + final gasPriceDouble = + gasPrice.getValueInUnit(EtherUnit.ether).toDouble(); + gasFee = gasPriceDouble * amountOfGas.toDouble(); + + estimatedGasFee = + EstimatedGasFee(gasPrice: gasPrice, gas: amountOfGas, gasFee: gasFee); } else { estimatedGasFee = await _estimatedFee( bridge.from!, bridge.to!, gasPrice, bridgeData, amountOfGas); @@ -128,10 +132,7 @@ class OpenDAppPresenter extends CompletePresenter { } } - String finalFee = (gasFee?.getInWei != null - ? gasFee!.getValueInUnit(EtherUnit.ether) - : (estimatedGasFee?.gasFee ?? 0)) - .toString(); + String finalFee = estimatedGasFee.gasFee.toString(); if (Validation.isExpoNumber(finalFee)) { finalFee = '0.0'; @@ -149,7 +150,8 @@ class OpenDAppPresenter extends CompletePresenter { symbol: symbol); if (result != null && result) { - final hash = await _sendTransaction(bridge.to!, amountEther, bridgeData, + final hash = await _sendTransaction( + bridge.to!, amountEther, bridgeData, estimatedGasFee, from: bridge.from); if (hash != null) success.call(hash); } else { diff --git a/packages/shared b/packages/shared index 62a91c6e..58fc65f0 160000 --- a/packages/shared +++ b/packages/shared @@ -1 +1 @@ -Subproject commit 62a91c6e0e3d1eba325eb7c165622ed1bca16438 +Subproject commit 58fc65f0bb802af34ac7cc340f934307925811e8 From abbeae29a9149e4948aefcb9f5dd9c707d61fcb1 Mon Sep 17 00:00:00 2001 From: HU Xin Date: Wed, 13 Sep 2023 20:45:48 +0200 Subject: [PATCH 09/10] fix:rpc --- packages/shared | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/shared b/packages/shared index 58fc65f0..95006188 160000 --- a/packages/shared +++ b/packages/shared @@ -1 +1 @@ -Subproject commit 58fc65f0bb802af34ac7cc340f934307925811e8 +Subproject commit 95006188a3c7b06fe575aab2b5d9e252c2a2b1d5 From f916224bc22ef47fa7e4b306a830b6b5057b4007 Mon Sep 17 00:00:00 2001 From: rd101rahul <65663039+rd101rahul@users.noreply.github.com> Date: Wed, 13 Sep 2023 21:07:28 +0200 Subject: [PATCH 10/10] Update pubspec.yaml --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index d0f2852d..606ec8b3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.2.1 +version: 1.2.2 environment: sdk: ">=2.19.0 <3.0.0"