Skip to content

Commit 5456d66

Browse files
committed
refactor: Support for new transaction entity
1 parent d7330a8 commit 5456d66

File tree

4 files changed

+43
-36
lines changed

4 files changed

+43
-36
lines changed

logic/lib/src/domain/const/urls.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class Urls {
5151
testnetFunc: () => testnetApiBaseUrl,
5252
);
5353

54-
static const String mainnetApiBaseUrl = 'https://explorer-v1.mxc.com/api/v2/';
54+
static const String mainnetApiBaseUrl = 'https://explorer-v1.moonchain.com/api/v2/';
5555
static const String testnetApiBaseUrl =
5656
'https://geneva-explorer-v1.moonchain.com/api/v2/';
5757

logic/lib/src/domain/entities/moonchain/moonchain_transactions_model/moonchain_transaction_model.dart

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@ import 'package:equatable/equatable.dart';
44
import 'package:mxc_logic/mxc_logic.dart';
55
import 'package:mxc_logic/src/domain/entities/moonchain/moonchain_transactions_model/decoded_input.dart';
66

7-
87
import 'fee.dart';
98

109
class MoonchainTransactionModel extends Equatable {
11-
1210
/// `dart:convert`
1311
///
1412
/// Parses the string and returns the resulting Json object as [MoonchainTransactionModel].
1513
factory MoonchainTransactionModel.fromJson(String data) {
1614
return MoonchainTransactionModel.fromMap(
17-
json.decode(data) as Map<String, dynamic>,);
15+
json.decode(data) as Map<String, dynamic>,
16+
);
1817
}
1918

2019
factory MoonchainTransactionModel.fromMap(Map<String, dynamic> data) {
@@ -48,7 +47,8 @@ class MoonchainTransactionModel extends Equatable {
4847
tokenTransfers: (data['token_transfers'] as List<dynamic>?)
4948
?.map((dynamic e) => TokenTransfer.fromMap(e as Map<String, dynamic>))
5049
.toList(),
51-
txTypes: (data['tx_types'] as List<dynamic>?)?.cast<String>(),
50+
transactionTypes:
51+
(data['transaction_types'] as List<dynamic>?)?.cast<String>(),
5252
gasUsed: data['gas_used'] as String?,
5353
createdContract: data['created_contract'] as dynamic,
5454
position: data['position'] as int?,
@@ -66,7 +66,7 @@ class MoonchainTransactionModel extends Equatable {
6666
confirmationDuration: (data['confirmation_duration'] as List<dynamic>?)
6767
?.map<double>((dynamic item) => double.parse(item.toString()))
6868
.toList(),
69-
txTag: data['tx_tag'] as dynamic,
69+
transactionTag: data['transaction_tag'] as dynamic,
7070
);
7171
}
7272

@@ -90,7 +90,7 @@ class MoonchainTransactionModel extends Equatable {
9090
this.baseFeePerGas,
9191
this.from,
9292
this.tokenTransfers,
93-
this.txTypes,
93+
this.transactionTypes,
9494
this.gasUsed,
9595
this.createdContract,
9696
this.position,
@@ -104,7 +104,7 @@ class MoonchainTransactionModel extends Equatable {
104104
this.maxPriorityFeePerGas,
105105
this.revertReason,
106106
this.confirmationDuration,
107-
this.txTag,
107+
this.transactionTag,
108108
});
109109
final DateTime? timestamp;
110110
final Fee? fee;
@@ -125,7 +125,7 @@ class MoonchainTransactionModel extends Equatable {
125125
final String? baseFeePerGas;
126126
final From? from;
127127
final List<TokenTransfer>? tokenTransfers;
128-
final List<String>? txTypes;
128+
final List<String>? transactionTypes;
129129
final String? gasUsed;
130130
final dynamic createdContract;
131131
final int? position;
@@ -139,7 +139,7 @@ class MoonchainTransactionModel extends Equatable {
139139
final String? maxPriorityFeePerGas;
140140
final dynamic revertReason;
141141
final List<double>? confirmationDuration;
142-
final dynamic txTag;
142+
final dynamic transactionTag;
143143

144144
Map<String, dynamic> toMap() => <String, dynamic>{
145145
'timestamp': timestamp?.toIso8601String(),
@@ -161,7 +161,7 @@ class MoonchainTransactionModel extends Equatable {
161161
'base_fee_per_gas': baseFeePerGas,
162162
'from': from?.toMap(),
163163
'token_transfers': tokenTransfers?.map((e) => e.toMap()).toList(),
164-
'tx_types': txTypes,
164+
'transaction_types': transactionTypes,
165165
'gas_used': gasUsed,
166166
'created_contract': createdContract,
167167
'position': position,
@@ -175,7 +175,7 @@ class MoonchainTransactionModel extends Equatable {
175175
'max_priority_fee_per_gas': maxPriorityFeePerGas,
176176
'revert_reason': revertReason,
177177
'confirmation_duration': confirmationDuration,
178-
'tx_tag': txTag,
178+
'transaction_tag': transactionTag,
179179
};
180180

181181
/// `dart:convert`
@@ -239,7 +239,7 @@ class MoonchainTransactionModel extends Equatable {
239239
baseFeePerGas: baseFeePerGas ?? this.baseFeePerGas,
240240
from: from ?? this.from,
241241
tokenTransfers: tokenTransfers ?? this.tokenTransfers,
242-
txTypes: txTypes ?? this.txTypes,
242+
transactionTypes: txTypes ?? this.transactionTypes,
243243
gasUsed: gasUsed ?? this.gasUsed,
244244
createdContract: createdContract ?? this.createdContract,
245245
position: position ?? this.position,
@@ -255,7 +255,7 @@ class MoonchainTransactionModel extends Equatable {
255255
maxPriorityFeePerGas: maxPriorityFeePerGas ?? this.maxPriorityFeePerGas,
256256
revertReason: revertReason ?? this.revertReason,
257257
confirmationDuration: confirmationDuration ?? this.confirmationDuration,
258-
txTag: txTag ?? this.txTag,
258+
transactionTag: txTag ?? this.transactionTag,
259259
);
260260
}
261261

@@ -293,7 +293,7 @@ class MoonchainTransactionModel extends Equatable {
293293
baseFeePerGas,
294294
from,
295295
tokenTransfers,
296-
txTypes,
296+
transactionTypes,
297297
gasUsed,
298298
createdContract,
299299
position,
@@ -307,7 +307,7 @@ class MoonchainTransactionModel extends Equatable {
307307
maxPriorityFeePerGas,
308308
revertReason,
309309
confirmationDuration,
310-
txTag,
310+
transactionTag,
311311
];
312312
}
313313
}

logic/lib/src/domain/entities/moonchain/shared/token_transfer.dart

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import 'token.dart';
88
import 'total.dart';
99

1010
class TokenTransfer extends Equatable {
11-
1211
TokenTransfer({
1312
this.blockHash,
1413
this.from,
@@ -18,7 +17,7 @@ class TokenTransfer extends Equatable {
1817
this.to,
1918
this.token,
2019
this.total,
21-
this.txHash,
20+
this.transactionHash,
2221
this.type,
2322
});
2423

@@ -41,7 +40,7 @@ class TokenTransfer extends Equatable {
4140
total: data['total'] == null
4241
? null
4342
: Total.fromMap(data['total'] as Map<String, dynamic>),
44-
txHash: data['tx_hash'] as String?,
43+
transactionHash: data['transaction_hash'] as String?,
4544
type: data['type'] as String?,
4645
);
4746

@@ -59,7 +58,7 @@ class TokenTransfer extends Equatable {
5958
To? to;
6059
final Token? token;
6160
final Total? total;
62-
final String? txHash;
61+
final String? transactionHash;
6362
final String? type;
6463

6564
Map<String, dynamic> toMap() => <String, dynamic>{
@@ -71,7 +70,7 @@ class TokenTransfer extends Equatable {
7170
'to': to?.toMap(),
7271
'token': token?.toMap(),
7372
'total': total?.toMap(),
74-
'tx_hash': txHash,
73+
'transaction_hash': transactionHash,
7574
'type': type,
7675
};
7776

@@ -89,7 +88,7 @@ class TokenTransfer extends Equatable {
8988
To? to,
9089
Token? token,
9190
Total? total,
92-
String? txHash,
91+
String? transactionHash,
9392
String? type,
9493
}) {
9594
return TokenTransfer(
@@ -101,7 +100,7 @@ class TokenTransfer extends Equatable {
101100
to: to ?? this.to,
102101
token: token ?? this.token,
103102
total: total ?? this.total,
104-
txHash: txHash ?? this.txHash,
103+
transactionHash: transactionHash ?? this.transactionHash,
105104
type: type ?? this.type,
106105
);
107106
}
@@ -117,7 +116,7 @@ class TokenTransfer extends Equatable {
117116
to,
118117
token,
119118
total,
120-
txHash,
119+
transactionHash,
121120
type,
122121
];
123122
}

logic/lib/src/domain/entities/transaction_model.dart

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class TransactionModel {
4747
final time = DateTime.now();
4848
timeStamp = time;
4949
final isCoinTransfer =
50-
mxcTransaction.txTypes!.contains('coin_transfer');
50+
mxcTransaction.transactionTypes!.contains('coin_transfer');
5151

5252
// Getting tx info to tx model for speed up & cancel operation
5353
from = mxcTransaction.from?.hash;
@@ -87,7 +87,9 @@ class TransactionModel {
8787
);
8888
value = mxcTransaction.value ?? '0';
8989
token = token.copyWith(
90-
logoUri: Config.mxcLogoUri, symbol: Config.mxcName,);
90+
logoUri: Config.mxcLogoUri,
91+
symbol: Config.mxcName,
92+
);
9193

9294
if (mxcTransaction.decodedInput?.methodId ==
9395
ContractAddresses.erc20TransferMethodId) {
@@ -102,8 +104,8 @@ class TransactionModel {
102104
}
103105
}
104106
}
105-
} else if (mxcTransaction.txTypes != null &&
106-
mxcTransaction.txTypes!.contains('coin_transfer')) {
107+
} else if (mxcTransaction.transactionTypes != null &&
108+
mxcTransaction.transactionTypes!.contains('coin_transfer')) {
107109
token =
108110
token.copyWith(logoUri: Config.mxcLogoUri, symbol: Config.mxcName);
109111

@@ -114,29 +116,31 @@ class TransactionModel {
114116
mxcTransaction.from!.hash!,
115117
);
116118
value = mxcTransaction.value ?? '0';
117-
} else if (mxcTransaction.txTypes == null &&
119+
} else if (mxcTransaction.transactionTypes == null &&
118120
mxcTransaction.tokenTransfers != null &&
119121
mxcTransaction.tokenTransfers!
120122
.indexWhere((element) => element.type == 'token_transfer') !=
121123
-1) {
122124
token = token.copyWith(
123-
symbol: mxcTransaction.tokenTransfers![0].token!.name!,);
125+
symbol: mxcTransaction.tokenTransfers![0].token!.name!,
126+
);
124127

125128
if (mxcTransaction.tokenTransfers?[0].token?.name != null) {
126129
token = token.copyWith(
127-
address: mxcTransaction.tokenTransfers?[0].token?.address,);
130+
address: mxcTransaction.tokenTransfers?[0].token?.address,
131+
);
128132
}
129133

130134
timeStamp = mxcTransaction.tokenTransfers?[0].timestamp;
131135

132136
value = mxcTransaction.tokenTransfers![0].total!.value ?? '0';
133-
hash = mxcTransaction.tokenTransfers![0].txHash ?? 'Unknown';
137+
hash = mxcTransaction.tokenTransfers![0].transactionHash ?? 'Unknown';
134138
type = mxcTransaction.checkForTransactionType(
135139
walletAddress,
136140
mxcTransaction.tokenTransfers![0].from!.hash!.toLowerCase(),
137141
);
138-
} else if (mxcTransaction.txTypes != null &&
139-
mxcTransaction.txTypes!.contains('contract_call')) {
142+
} else if (mxcTransaction.transactionTypes != null &&
143+
mxcTransaction.transactionTypes!.contains('contract_call')) {
140144
timeStamp = mxcTransaction.timestamp!;
141145
type = TransactionType.contractCall;
142146
value = mxcTransaction.txBurntFee;
@@ -182,7 +186,10 @@ class TransactionModel {
182186

183187
// In this state the tx
184188
factory TransactionModel.fromTransactionReceipt(
185-
TransactionReceipt receipt, String walletAddress, Token token,) {
189+
TransactionReceipt receipt,
190+
String walletAddress,
191+
Token token,
192+
) {
186193
final txHash = bytesToHex(receipt.transactionHash, include0x: true);
187194
final timeStamp = DateTime.now();
188195
final txStatus = receipt.status == true
@@ -301,7 +308,8 @@ class TransactionModel {
301308
: null,
302309
hash: map['hash'],
303310
status: TransactionStatus.values.firstWhere(
304-
(status) => status.toString().split('.').last == map['status'],),
311+
(status) => status.toString().split('.').last == map['status'],
312+
),
305313
type: TransactionType.values
306314
.firstWhere((type) => type.toString().split('.').last == map['type']),
307315
value: map['value'],

0 commit comments

Comments
 (0)