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 #111 from MXCzkEVM/contact_call_support
Contact call support
- Loading branch information
Showing
13 changed files
with
194 additions
and
143 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
80 changes: 80 additions & 0 deletions
80
lib/common/components/recent_transactions/domain/mxc_transaction_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,80 @@ | ||
import 'package:datadashwallet/common/common.dart'; | ||
import 'package:datadashwallet/core/core.dart'; | ||
import 'package:mxc_logic/mxc_logic.dart'; | ||
import 'package:web3dart/web3dart.dart'; | ||
|
||
class MXCTransactionsUseCase extends ReactiveUseCase { | ||
MXCTransactionsUseCase(this._web3Repository); | ||
|
||
final Web3Repository _web3Repository; | ||
|
||
/// Will remove token transfer (tx that are in general transaction) from general transaction | ||
List<WannseeTransactionModel> removeTokenTransfersFromTxList( | ||
List<WannseeTransactionModel> txList, | ||
List<TokenTransfer> tokenTransferList) { | ||
return txList.where((element) { | ||
if (element.hash != null) { | ||
// 1. Delete if txHash is null | ||
// 2. Delete if tx is token transfer | ||
return tokenTransferList.indexWhere( | ||
(e) => e.txHash == null ? true : e.txHash == element.hash) == | ||
-1; | ||
} else { | ||
return false; | ||
} | ||
}).toList(); | ||
} | ||
|
||
void addTokenTransfersToTxList(List<WannseeTransactionModel> txList, | ||
List<TokenTransfer> tokenTransferList) { | ||
for (int i = 0; i < tokenTransferList.length; i++) { | ||
final item = tokenTransferList[i]; | ||
txList.add(WannseeTransactionModel(tokenTransfers: [item])); | ||
} | ||
} | ||
|
||
List<WannseeTransactionModel> keepOnlySixTransactions( | ||
List<WannseeTransactionModel> txList, | ||
) { | ||
if (txList.length > 6) { | ||
return txList.sublist(0, 6); | ||
} | ||
return txList; | ||
} | ||
|
||
void sortByDate(List<WannseeTransactionModel> txList) { | ||
if (txList.isNotEmpty) { | ||
txList.sort((a, b) { | ||
final item1 = a.timestamp ?? a.tokenTransfers![0].timestamp; | ||
final item2 = b.timestamp ?? b.tokenTransfers![0].timestamp; | ||
|
||
return item2!.compareTo(item1!); | ||
}); | ||
} | ||
} | ||
|
||
List<TransactionModel> axsTxListFromMxcTxList( | ||
List<WannseeTransactionModel> mxcTxList, String walletAddress) { | ||
return mxcTxList | ||
.map((e) => TransactionModel.fromMXCTransaction(e, walletAddress)) | ||
.toList(); | ||
} | ||
|
||
void removeInvalidTx(List<TransactionModel> txList) { | ||
txList.removeWhere( | ||
(element) => element.hash == "Unknown", | ||
); | ||
} | ||
|
||
List<WannseeTransactionModel> applyTxDateLimit( | ||
List<WannseeTransactionModel> txList) { | ||
final sevenDays = DateTime.now() | ||
.subtract(Duration(days: Config.transactionsHistoryLimit)); | ||
return txList.where((element) { | ||
if (element.timestamp != null) { | ||
return element.timestamp!.isAfter(sevenDays); | ||
} | ||
return element.tokenTransfers![0].timestamp!.isAfter(sevenDays); | ||
}).toList(); | ||
} | ||
} |
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
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
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.