Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Commit

Permalink
feat: Added contract call support for other chains
Browse files Browse the repository at this point in the history
  • Loading branch information
reasje committed Nov 2, 2023
1 parent e2c1b2d commit 52265a8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
Expand Down
4 changes: 2 additions & 2 deletions lib/features/common/contract/token_contract_use_case.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -240,7 +240,7 @@ class TokenContractUseCase extends ReactiveUseCase {
update(totalBalanceInXsd, totalPrice);
}

StreamSubscription<bool> spyOnTransaction(String hash) {
StreamSubscription<TransactionReceipt?> spyOnTransaction(String hash) {
return _repository.tokenContract.spyTransaction(hash);
}
}
22 changes: 10 additions & 12 deletions lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class OpenDAppPresenter extends CompletePresenter<OpenDAppState> {
amount: amount,
data: data,
estimatedGasFee: estimatedGasFee);
if (!Config.isMxcChains(state.network!.chainId) && Config.isL3Bridge(url)) {
if (!Config.isMxcChains(state.network!.chainId)) {
recordTransaction(res);
}

Expand Down Expand Up @@ -134,23 +134,21 @@ class OpenDAppPresenter extends CompletePresenter<OpenDAppState> {
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,
);

Expand Down
2 changes: 1 addition & 1 deletion packages/shared

0 comments on commit 52265a8

Please sign in to comment.