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

Commit

Permalink
Merge pull request #111 from MXCzkEVM/contact_call_support
Browse files Browse the repository at this point in the history
Contact call support
  • Loading branch information
reasje authored Nov 2, 2023
2 parents 9e57dde + e2c1b2d commit 667ed61
Show file tree
Hide file tree
Showing 13 changed files with 194 additions and 143 deletions.
2 changes: 2 additions & 0 deletions assets/flutter_i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"send": "Send",
"received": "Received",
"sent": "Sent",
"contractCall": "Contract call",
"email_secured_body": "For the security and privacy of your AXS wallet it's essential that you keep all information contained in this email strictly confidential. \nPlease follow these next steps carefully: \n1. Ensure you're the sole recipient of this email by replacing the recipient's address with your own. \n2. After confirming the correct email address, proceed to click the 'Send' button to forward this vital information to yourself securely. By adhering to these measures, you'll ensure the utmost safety for your AXS wallet. Thank you for your diligence in this matter.",
"email_secured_subject": "Secure Your AXS Wallet Key - Important Instructions",
"face_id": "Face ID",
Expand Down Expand Up @@ -172,6 +173,7 @@
"all_transactions": "All transactions",
"send_transactions": "Send transactions",
"receive_transactions": "Receive transactions",
"contract_call_transactions": "Contract call transactions",
"sort": "Sort",
"new_to_old": "New to Old",
"old_to_new": "Old to New",
Expand Down
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,31 @@ class TransactionsHistoryRepository extends ControlledCacheRepository {

late final Field<List<TransactionModel>> transactionsHistory =
fieldWithDefault<List<TransactionModel>>('items', [],
serializer: (b) => b
.map((e) => e.toMap())
.toList(),
deserializer: (b) => (b as List)
.map((e) => TransactionModel.fromMap(e)
)
.toList());
serializer: (b) => b.map((e) => e.toMap()).toList(),
deserializer: (b) =>
(b as List).map((e) => TransactionModel.fromMap(e)).toList());

List<TransactionModel> get items => transactionsHistory.value;



void addItem(TransactionModel item, int index) {
final newList = transactionsHistory.value;
newList.insert(0, item);
transactionsHistory.value = newList;
}

void updateItem(TransactionModel item, int index,) {
void updateItem(
TransactionModel item,
int index,
) {
final newList = transactionsHistory.value;

newList[index] = item;

transactionsHistory.value = newList;
}

void removeItem(TransactionModel item) =>
transactionsHistory.value = transactionsHistory.value
.where((e) => e.hash != item.hash)
.toList();
void removeItem(TransactionModel item) => transactionsHistory.value =
transactionsHistory.value.where((e) => e.hash != item.hash).toList();

void removeAll() => transactionsHistory.value = [];
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class TransactionsHistoryUseCase extends ReactiveUseCase {
update(transactionsHistory, _repository.items);
}

/// This function will spy on the given transaction
void spyOnTransaction(
TransactionModel item,
) {
Expand All @@ -69,6 +70,8 @@ class TransactionsHistoryUseCase extends ReactiveUseCase {
}
}

/// This function will run through all the transactions and will start spying on
/// pending transactions
void checkForPendingTransactions(int chainId) {
if (!Config.isMxcChains(chainId)) {
final txList = transactionsHistory.value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:mxc_ui/mxc_ui.dart';

export 'domain/transactions_use_case.dart';
export 'domain/transactions_repository.dart';
export 'domain/transactions_history_use_case.dart';
export 'domain/transactions_history_repository.dart';

class RecentTransactions extends HookConsumerWidget {
const RecentTransactions({
Expand Down
12 changes: 10 additions & 2 deletions lib/common/components/recent_transactions/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class RecentTransactionsUtils {
case TransactionType.received:
txColor = ColorsTheme.of(context).greenMain;
break;
case TransactionType.contractCall:
txColor = ColorsTheme.of(context).textGrey1;
break;
default:
txColor = ColorsTheme.of(context).mainRed;
}
Expand All @@ -52,6 +55,9 @@ class RecentTransactionsUtils {
case TransactionType.received:
txIcon = MxcIcons.receive;
break;
case TransactionType.contractCall:
txIcon = Icons.article_rounded;
break;
default:
txIcon = Icons.question_mark;
}
Expand Down Expand Up @@ -85,11 +91,13 @@ class RecentTransactionsUtils {
'assets/svg/networks/unknown.svg';
final decimal =
foundToken.decimals ?? e.token.decimals ?? Config.ethDecimals;
final symbol = foundToken.symbol ?? e.token.symbol ?? 'Unknown';
final symbol = foundToken.symbol ?? e.token.symbol;

return RecentTrxListItem(
logoUrl: logoUrl,
amount: Formatter.convertWeiToEth(e.value, decimal),
amount: e.value == null
? null
: Formatter.convertWeiToEth(e.value!, decimal),
symbol: symbol,
timestamp:
e.timeStamp == null ? "Unknown" : Formatter.localTime(e.timeStamp!),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import '../../../common.dart';
import '../utils.dart';

class RecentTrxListItem extends HookConsumerWidget {
final String amount;
final String symbol;
final String? amount;
final String? symbol;
final String txHash;
final String timestamp;
final TransactionType transactionType;
Expand Down Expand Up @@ -86,40 +86,42 @@ class RecentTrxListItem extends HookConsumerWidget {
),
Row(
children: [
Text(
amount,
style: FontTheme.of(context)
.body1
.primary()
.copyWith(
fontWeight: FontWeight.w500,
foreground: state.hideBalance == true
? (Paint()
..style = PaintingStyle.fill
..color = Colors.white
..maskFilter = const MaskFilter.blur(
BlurStyle.normal, 6))
: null,
),
softWrap: true,
),
if (amount != null)
Text(
amount!,
style: FontTheme.of(context)
.body1
.primary()
.copyWith(
fontWeight: FontWeight.w500,
foreground: state.hideBalance == true
? (Paint()
..style = PaintingStyle.fill
..color = Colors.white
..maskFilter = const MaskFilter.blur(
BlurStyle.normal, 6))
: null,
),
softWrap: true,
),
const SizedBox(
width: 4,
),
Expanded(
child: Text(
symbol,
style: FontTheme.of(context).h7().copyWith(
fontSize: 16,
fontWeight: FontWeight.w400,
color:
ColorsTheme.of(context).textSecondary,
),
textAlign: TextAlign.start,
overflow: TextOverflow.ellipsis,
softWrap: false,
if (symbol != null)
Expanded(
child: Text(
symbol!,
style: FontTheme.of(context).h7().copyWith(
fontSize: 16,
fontWeight: FontWeight.w400,
color:
ColorsTheme.of(context).textSecondary,
),
textAlign: TextAlign.start,
overflow: TextOverflow.ellipsis,
softWrap: false,
),
),
),
],
),
],
Expand Down
3 changes: 3 additions & 0 deletions lib/common/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class Config {
static int decimalShowFixed = 3;
static int decimalWriteFixed = 8;

/// It's in days
static int transactionsHistoryLimit = 7;

static bool isMxcChains(int chainId) {
return chainId == mxcMainnetChainId || chainId == mxcTestnetChainId;
}
Expand Down
8 changes: 8 additions & 0 deletions lib/core/src/providers/providers_use_cases.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:datadashwallet/common/common.dart';
import 'package:datadashwallet/common/components/recent_transactions/domain/mxc_transaction_use_case.dart';
import 'package:datadashwallet/features/common/account/log_out_use_case.dart';
import 'package:datadashwallet/features/common/common.dart';
import 'package:datadashwallet/features/common/contract/chains_use_case.dart';
Expand Down Expand Up @@ -114,6 +115,13 @@ final Provider<ChainConfigurationUseCase> chainConfigurationUseCaseProvider =
),
);

final Provider<MXCTransactionsUseCase> mxcTransactionsUseCaseProvider =
Provider(
(ref) => MXCTransactionsUseCase(
ref.watch(web3RepositoryProvider),
),
);

final Provider<TransactionsHistoryUseCase> transactionHistoryUseCaseProvider =
Provider(
(ref) => TransactionsHistoryUseCase(
Expand Down
Loading

0 comments on commit 667ed61

Please sign in to comment.