Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to cs_monero from flutter_libmonero #1012

Closed
wants to merge 12 commits into from
Prev Previous commit
Next Next commit
hack in xmr and wow support to txV2
  • Loading branch information
julian-CStack committed Oct 29, 2024
commit ab8dc58f0e40e5f93fb1599862039dcfc00585af
34 changes: 34 additions & 0 deletions lib/models/isar/models/blockchain_data/v2/transaction_v2.dart
Original file line number Diff line number Diff line change
@@ -134,6 +134,14 @@ class TransactionV2 {
}

Amount getAmountReceivedInThisWallet({required int fractionDigits}) {
if (_isMonero()) {
if (type == TransactionType.incoming) {
return _getMoneroAmount()!;
} else {
return Amount.zeroWith(fractionDigits: fractionDigits);
}
}

final outSum = outputs
.where((e) => e.walletOwns)
.fold(BigInt.zero, (p, e) => p + e.value);
@@ -151,6 +159,14 @@ class TransactionV2 {
}

Amount getAmountSentFromThisWallet({required int fractionDigits}) {
if (_isMonero()) {
if (type == TransactionType.outgoing) {
return _getMoneroAmount()!;
} else {
return Amount.zeroWith(fractionDigits: fractionDigits);
}
}

final inSum = inputs
.where((e) => e.walletOwns)
.fold(BigInt.zero, (p, e) => p + e.value);
@@ -191,6 +207,21 @@ class TransactionV2 {
}
}

Amount? _getMoneroAmount() {
try {
return Amount.fromSerializedJsonString(
_getFromOtherData(key: TxV2OdKeys.moneroAmount) as String,
);
} catch (_) {
return null;
}
}

bool _isMonero() {
final value = _getFromOtherData(key: TxV2OdKeys.isMoneroTransaction);
return value is bool ? value : false;
}

String statusLabel({
required int currentChainHeight,
required int minConfirms,
@@ -307,4 +338,7 @@ abstract final class TxV2OdKeys {
static const contractAddress = "contractAddress";
static const nonce = "nonce";
static const overrideFee = "overrideFee";
static const moneroAmount = "moneroAmount";
static const moneroAccountIndex = "moneroAccountIndex";
static const isMoneroTransaction = "isMoneroTransaction";
}