Skip to content

Commit

Permalink
few fixes and remove mwc-wallet logs
Browse files Browse the repository at this point in the history
  • Loading branch information
vekamo committed Nov 13, 2024
1 parent 2ac9c3e commit 4944750
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 97 deletions.
2 changes: 1 addition & 1 deletion crypto_plugins/flutter_libmwc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:stackwallet/wallets/wallet/impl/mimblewimblecoin_wallet.dart';
import 'package:tuple/tuple.dart';
import 'package:url_launcher/url_launcher.dart';

Expand Down Expand Up @@ -1730,7 +1731,7 @@ class _TransactionDetailsViewState
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
floatingActionButton: (coin is Epiccash &&
floatingActionButton: ((coin is Epiccash || coin is Mimblewimblecoin) &&
_transaction.getConfirmations(currentHeight) < 1 &&
_transaction.isCancelled == false)
? ConditionalParent(
Expand Down Expand Up @@ -1775,6 +1776,59 @@ class _TransactionDetailsViewState
),
);

final result =
await wallet.cancelPendingTransactionAndPost(id);
if (mounted) {
// pop progress dialog
Navigator.of(context).pop();

if (result.isEmpty) {
await showDialog<dynamic>(
context: context,
builder: (_) => StackOkDialog(
title: "Transaction cancelled",
onOkPressed: (_) {
wallet.refresh();
Navigator.of(context).popUntil(
ModalRoute.withName(
WalletView.routeName,
),
);
},
),
);
} else {
await showDialog<dynamic>(
context: context,
builder: (_) => StackOkDialog(
title: "Failed to cancel transaction",
message: result,
),
);
}
}
} else if (wallet is MimblewimblecoinWallet) {
final String? id = _transaction.slateId;
if (id == null) {
unawaited(
showFloatingFlushBar(
type: FlushBarType.warning,
message: "Could not find MWC transaction ID",
context: context,
),
);
return;
}

unawaited(
showDialog<dynamic>(
barrierDismissible: false,
context: context,
builder: (_) =>
const CancellingTransactionProgressDialog(),
),
);

final result =
await wallet.cancelPendingTransactionAndPost(id);
if (mounted) {
Expand Down Expand Up @@ -1810,7 +1864,7 @@ class _TransactionDetailsViewState
unawaited(
showFloatingFlushBar(
type: FlushBarType.warning,
message: "ERROR: Wallet type is not Epic Cash",
message: "ERROR: Wallet type is not Epic Cash or MimbleWimbleCoin",
context: context,
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2112,18 +2112,7 @@ class _TransactionV2DetailsViewState
);
}
}
} else {
unawaited(
showFloatingFlushBar(
type: FlushBarType.warning,
message: "ERROR: Wallet type is not Epic Cash",
context: context,
),
);
return;
}

if (wallet is MimblewimblecoinWallet) {
} else if (wallet is MimblewimblecoinWallet) {
final String? id = _transaction.slateId;
if (id == null) {
unawaited(
Expand Down Expand Up @@ -2181,8 +2170,7 @@ class _TransactionV2DetailsViewState
unawaited(
showFloatingFlushBar(
type: FlushBarType.warning,
message:
"ERROR: Wallet type is not Mimblewimblecoin",
message: "ERROR: Wallet type is not Epic Cash or MimbleWimbleCoin",
context: context,
),
);
Expand Down
16 changes: 13 additions & 3 deletions lib/utilities/test_mwcmqs_connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,21 @@ import 'prefs.dart';

Future<bool> _testMwcMqsNodeConnection(Uri uri) async {
final HTTP client = HTTP();
try {
try {
final headers = {
'Content-Type': 'application/json',
};

if (uri.toString() == 'https://mwc713.mwc.mw/v1/version') {
const username = 'mwcmain';
const password = '11ne3EAUtOXVKwhxm84U';
final credentials = base64Encode(utf8.encode('$username:$password'));
headers['Authorization'] = 'Basic $credentials';
}
final response = await client
.get(
url: uri,
headers: {'Content-Type': 'application/json'},
headers: headers,
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.getProxyInfo()
: null,
Expand Down Expand Up @@ -67,7 +77,7 @@ Future<NodeFormData?> testMwcNodeConnection(NodeFormData data) async {
Uri uri = Uri.parse(data.host! + path_postfix);

uri = uri.replace(port: data.port);

try {
if (await _testMwcMqsNodeConnection(uri)) {
return data;
Expand Down
14 changes: 14 additions & 0 deletions lib/utilities/test_node_connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import '../wallets/wallet/impl/solana_wallet.dart';
import 'connection_check/electrum_connection_check.dart';
import 'logger.dart';
import 'test_epic_box_connection.dart';
import 'test_mwcmqs_connection.dart';
import 'test_eth_node_connection.dart';
import 'test_monero_node_connection.dart';
import 'test_stellar_node_connection.dart';
Expand Down Expand Up @@ -104,6 +105,19 @@ Future<bool> testNodeConnection({
}
break;

case Mimblewimblecoin():
try {
final data = await testMwcNodeConnection(formData);

if (data != null) {
testPassed = true;
onSuccess?.call(data);
}
} catch (e, s) {
Logging.instance.log("$e\n$s", level: LogLevel.Warning);
}
break;

case CryptonoteCurrency():
try {
final proxyInfo = ref.read(prefsChangeNotifierProvider).useTor
Expand Down
41 changes: 19 additions & 22 deletions lib/wallets/crypto_currency/coins/mimblewimblecoin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,36 +50,33 @@ class Mimblewimblecoin extends Bip39Currency {
// change this to change the number of confirms a tx needs in order to show as confirmed
int get minConfirms => 3;

@override
bool validateAddress(String address) {
// Invalid address that contains HTTP and mwcmqs domain
if ((address.startsWith("http://") || address.startsWith("https://")) &&
address.contains("@")) {
return false;
}
if (address.startsWith("http://") || address.startsWith("https://")) {
if (Uri.tryParse(address) != null) {
return true;
}
}

return mimblewimblecoin.Libmwc.validateSendAddress(address: address);
@override
bool validateAddress(String address) {
Uri? uri = Uri.tryParse(address);
if (uri != null &&
(uri.scheme == "http" || uri.scheme == "https" || uri.scheme == "mwcmqs") &&
uri.host.isNotEmpty &&
!uri.host.endsWith(".onion")) {
return true;
}
return mimblewimblecoin.Libmwc.validateSendAddress(address: address);
}


@override
NodeModel get defaultNode {
switch (network) {
case CryptoCurrencyNetwork.main:
return NodeModel(
host: "http://mwc713.mwc.mw",
port: 3413,
host: "https://mwc713.mwc.mw",
port: 443,
name: DefaultNodes.defaultName,
id: DefaultNodes.buildId(this),
useSSL: false,
useSSL: true,
enabled: true,
coinName: identifier,
isFailover: true,
isDown: false,
isDown: false
);

default:
Expand All @@ -88,10 +85,10 @@ class Mimblewimblecoin extends Bip39Currency {
}

@override
int get defaultSeedPhraseLength => 24;
int get defaultSeedPhraseLength => 12;

@override
int get fractionDigits => 8;
int get fractionDigits => 9;

@override
bool get hasBuySupport => false;
Expand All @@ -100,13 +97,13 @@ class Mimblewimblecoin extends Bip39Currency {
bool get hasMnemonicPassphraseSupport => false;

@override
List<int> get possibleMnemonicLengths => [defaultSeedPhraseLength, 12];
List<int> get possibleMnemonicLengths => [defaultSeedPhraseLength, 24];

@override
AddressType get defaultAddressType => AddressType.mimbleWimble;

@override
BigInt get satsPerCoin => BigInt.from(100000000);
BigInt get satsPerCoin => BigInt.from(1000000000);

@override
int get targetBlockTimeSeconds => 60;
Expand Down
Loading

0 comments on commit 4944750

Please sign in to comment.