From 52265a8d8cfa8b7996408c5c7d2f63b373229511 Mon Sep 17 00:00:00 2001 From: reasje Date: Thu, 2 Nov 2023 18:13:26 +0330 Subject: [PATCH] feat: Added contract call support for other chains --- .../domain/transactions_history_use_case.dart | 13 ++++++++--- .../contract/token_contract_use_case.dart | 4 ++-- .../open_dapp/open_dapp_presenter.dart | 22 +++++++++---------- packages/shared | 2 +- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/lib/common/components/recent_transactions/domain/transactions_history_use_case.dart b/lib/common/components/recent_transactions/domain/transactions_history_use_case.dart index 88cb6a1e..0ab28540 100644 --- a/lib/common/components/recent_transactions/domain/transactions_history_use_case.dart +++ b/lib/common/components/recent_transactions/domain/transactions_history_use_case.dart @@ -56,14 +56,21 @@ class TransactionsHistoryUseCase extends ReactiveUseCase { updatingTxList.add(item.hash); final stream = _web3Repository.tokenContract.spyTransaction(item.hash); - stream.onData((succeeded) { - if (succeeded) { - final updatedItem = item.copyWith(status: TransactionStatus.done); + stream.onData((receipt) { + if (receipt?.status ?? false) { + // success + final itemValue = item.value ?? + (receipt!.gasUsed! * receipt.effectiveGasPrice!.getInWei) + .toString(); + + final updatedItem = + item.copyWith(status: TransactionStatus.done, value: itemValue); updateItem( updatedItem, ); updatingTxList.remove(item.hash); update(shouldUpdateBalances, true); + stream.cancel(); } }); diff --git a/lib/features/common/contract/token_contract_use_case.dart b/lib/features/common/contract/token_contract_use_case.dart index 6983cc35..942c0283 100644 --- a/lib/features/common/contract/token_contract_use_case.dart +++ b/lib/features/common/contract/token_contract_use_case.dart @@ -71,7 +71,7 @@ class TokenContractUseCase extends ReactiveUseCase { final cNetwork = _repository.tokenContract.getCurrentNetwork(); final chainNativeToken = Token( - logoUri: result?.logoUri ?? 'assets/svg/networks/unknown.svg', + logoUri: result?.logoUri ?? cNetwork.logo, symbol: cNetwork.symbol, name: '${cNetwork.symbol} Token', decimals: Config.ethDecimals); @@ -240,7 +240,7 @@ class TokenContractUseCase extends ReactiveUseCase { update(totalBalanceInXsd, totalPrice); } - StreamSubscription spyOnTransaction(String hash) { + StreamSubscription spyOnTransaction(String hash) { return _repository.tokenContract.spyTransaction(hash); } } 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 3f8990a4..925c2983 100644 --- a/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart +++ b/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart @@ -96,7 +96,7 @@ class OpenDAppPresenter extends CompletePresenter { amount: amount, data: data, estimatedGasFee: estimatedGasFee); - if (!Config.isMxcChains(state.network!.chainId) && Config.isL3Bridge(url)) { + if (!Config.isMxcChains(state.network!.chainId)) { recordTransaction(res); } @@ -134,23 +134,21 @@ class OpenDAppPresenter extends CompletePresenter { void recordTransaction(String hash) { final timeStamp = DateTime.now(); const txStatus = TransactionStatus.pending; - const txType = TransactionType.sent; - final chainId = state.network!.chainId; + const txType = TransactionType.contractCall; + final currentNetwork = state.network!; + final chainId = currentNetwork.chainId; final token = Token( - chainId: state.network!.chainId, - logoUri: Assets.mxcLogoUri, - name: Config.mxcName, - symbol: Config.mxcSymbol, - // can separate Sepolia & Ethereum - address: Config.isEthereumMainnet(chainId) - ? Config.mxcAddressEthereum - : Config.mxcAddressSepolia); + chainId: currentNetwork.chainId, + logoUri: currentNetwork.logo, + name: currentNetwork.label ?? currentNetwork.web3RpcHttpUrl, + symbol: currentNetwork.symbol, + address: null); final tx = TransactionModel( hash: hash, timeStamp: timeStamp, status: txStatus, type: txType, - value: '0', + value: null, token: token, ); diff --git a/packages/shared b/packages/shared index 378f9c44..aa777733 160000 --- a/packages/shared +++ b/packages/shared @@ -1 +1 @@ -Subproject commit 378f9c4407e9f6494fa34d528c457076adee0a2c +Subproject commit aa77773379d04b87f4e46d5777e5517bddd79622