This repository has been archived by the owner on Sep 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from MXCzkEVM/main
1.4.0
- Loading branch information
Showing
58 changed files
with
979 additions
and
294 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export 'presentation/balance_panel.dart'; | ||
export 'presentation/balance_panel.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
lib/common/components/recent_transactions/domain/transactions_repository.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import 'package:datadashwallet/common/components/recent_transactions/entity/transaction_history_model.dart'; | ||
import 'package:mxc_logic/mxc_logic.dart'; | ||
import 'package:datadashwallet/core/core.dart'; | ||
|
||
class TransactionsHistoryRepository extends ControlledCacheRepository { | ||
@override | ||
final String zone = 'transaction-history'; | ||
|
||
late final Field<List<TransactionHistoryModel>> transactionsHistory = | ||
fieldWithDefault<List<TransactionHistoryModel>>('items', [], | ||
serializer: (b) => b | ||
.map((e) => { | ||
'chainId': e.chainId, | ||
'txList': e.txList.map((e) => e.toMap()).toList() | ||
}) | ||
.toList(), | ||
deserializer: (b) => (b as List) | ||
.map((e) => TransactionHistoryModel( | ||
chainId: e['chainId'], | ||
txList: (e['txList'] as List) | ||
.map((e) => TransactionModel.fromMap(e)) | ||
.toList(), | ||
)) | ||
.toList()); | ||
|
||
List<TransactionHistoryModel> get items => transactionsHistory.value; | ||
|
||
void addItem(TransactionHistoryModel item) => | ||
transactionsHistory.value = [...transactionsHistory.value, item]; | ||
|
||
void addItemTx(TransactionModel item, int index) { | ||
final newList = transactionsHistory.value; | ||
newList[index].txList.insert(0, item); | ||
transactionsHistory.value = newList; | ||
} | ||
|
||
void updateItem(TransactionHistoryModel item, int index) { | ||
final newList = transactionsHistory.value; | ||
newList.removeAt(index); | ||
newList.insert(index, item); | ||
transactionsHistory.value = newList; | ||
} | ||
|
||
void updateItemTx(TransactionModel item, int index, int txIndex) { | ||
final newList = transactionsHistory.value; | ||
|
||
newList[index].txList[txIndex] = item; | ||
|
||
transactionsHistory.value = newList; | ||
} | ||
|
||
void removeItem(TransactionHistoryModel item) => | ||
transactionsHistory.value = transactionsHistory.value | ||
.where((e) => e.chainId != item.chainId) | ||
.toList(); | ||
|
||
void removeAll() => transactionsHistory.value = []; | ||
} |
115 changes: 115 additions & 0 deletions
115
lib/common/components/recent_transactions/domain/transactions_use_case.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import 'package:datadashwallet/common/common.dart'; | ||
import 'package:datadashwallet/core/core.dart'; | ||
import 'package:mxc_logic/mxc_logic.dart'; | ||
import '../entity/transaction_history_model.dart'; | ||
import 'transactions_repository.dart'; | ||
import 'package:web3dart/web3dart.dart'; | ||
|
||
class TransactionsHistoryUseCase extends ReactiveUseCase { | ||
TransactionsHistoryUseCase(this._repository, this._web3Repository); | ||
|
||
final Web3Repository _web3Repository; | ||
|
||
final TransactionsHistoryRepository _repository; | ||
|
||
late final ValueStream<List<TransactionHistoryModel>> transactionsHistory = | ||
reactiveField(_repository.transactionsHistory); | ||
|
||
List<TransactionHistoryModel> getTransactionsHistory() => _repository.items; | ||
|
||
List<String> updatingTxList = []; | ||
|
||
void addItem(TransactionHistoryModel item) { | ||
_repository.addItem(item); | ||
update(transactionsHistory, _repository.items); | ||
} | ||
|
||
void updateItem(TransactionHistoryModel item, int index) { | ||
_repository.updateItem(item, index); | ||
update(transactionsHistory, _repository.items); | ||
} | ||
|
||
void updateItemTx(TransactionModel item, int selectedNetworkChainId) { | ||
final txHistory = transactionsHistory.value | ||
.firstWhere((element) => element.chainId == selectedNetworkChainId); | ||
|
||
final index = transactionsHistory.value.indexOf(txHistory); | ||
final txIndex = txHistory.txList.indexWhere( | ||
(element) => element.hash == item.hash, | ||
); | ||
|
||
if (txIndex == -1) { | ||
_repository.addItemTx(item, index); | ||
} else { | ||
_repository.updateItemTx(item, index, txIndex); | ||
} | ||
|
||
update(transactionsHistory, _repository.items); | ||
} | ||
|
||
void removeAll() { | ||
_repository.removeAll(); | ||
update(transactionsHistory, _repository.items); | ||
} | ||
|
||
void removeItem(TransactionHistoryModel item) { | ||
_repository.removeItem(item); | ||
update(transactionsHistory, _repository.items); | ||
} | ||
|
||
void spyOnTransaction(TransactionModel item, int chainId) { | ||
if (!updatingTxList.contains(item.hash)) { | ||
updatingTxList.add(item.hash); | ||
final stream = _web3Repository.tokenContract.spyTransaction(item.hash); | ||
stream.onData((succeeded) { | ||
if (succeeded) { | ||
final updatedItem = item.copyWith(status: TransactionStatus.done); | ||
updateItemTx(updatedItem, chainId); | ||
updatingTxList.remove(item.hash); | ||
stream.cancel(); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
void checkForPendingTransactions(int chainId) { | ||
if (!Config.isMxcChains(chainId)) { | ||
final index = transactionsHistory.value | ||
.indexWhere((element) => element.chainId == chainId); | ||
|
||
if (index != -1) { | ||
final chainTx = transactionsHistory.value[index]; | ||
final pendingTxList = chainTx.txList | ||
.where((element) => element.status == TransactionStatus.pending); | ||
for (TransactionModel pendingTx in pendingTxList) { | ||
spyOnTransaction(pendingTx, chainId); | ||
} | ||
} | ||
} | ||
} | ||
|
||
void spyOnUnknownTransaction( | ||
String hash, String address, Token token, int chainId) async { | ||
TransactionInformation? receipt; | ||
|
||
receipt = await _web3Repository.tokenContract | ||
.getTransactionByHashCustomChain(hash); | ||
|
||
if (receipt != null) { | ||
final tx = TransactionModel.fromTransaction(receipt, address, token); | ||
spyOnTransaction(tx, chainId); | ||
updateItemTx(tx, chainId); | ||
} | ||
} | ||
|
||
void checkChainAvailability(int chainId) { | ||
final index = transactionsHistory.value | ||
.indexWhere((element) => element.chainId == chainId); | ||
|
||
if (index == -1) { | ||
addItem(TransactionHistoryModel(chainId: chainId, txList: [])); | ||
return; | ||
} | ||
update(transactionsHistory, _repository.items); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
lib/common/components/recent_transactions/entity/transaction_history_model.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import 'package:mxc_logic/mxc_logic.dart'; | ||
|
||
class TransactionHistoryModel { | ||
TransactionHistoryModel({ | ||
required this.chainId, | ||
required this.txList, | ||
}); | ||
|
||
int chainId; | ||
List<TransactionModel> txList; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.