-
Notifications
You must be signed in to change notification settings - Fork 498
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix UI thread exception crash (#1650)
Fix UI thread exception crash
- Loading branch information
Showing
2 changed files
with
40 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,53 @@ | ||
using System.Collections.Generic; | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using WalletWasabi.Helpers; | ||
|
||
namespace System | ||
{ | ||
public static class ExceptionExtensions | ||
{ | ||
public static string ToTypeMessageString(this Exception ex) | ||
{ | ||
return $"{ex.GetType().Name}: {ex.Message}"; | ||
var trimmed = Guard.Correct(ex.Message); | ||
if (trimmed == "") | ||
{ | ||
return ex.GetType().Name; | ||
} | ||
else | ||
{ | ||
return $"{ex.GetType().Name}: {ex.Message}"; | ||
} | ||
} | ||
|
||
public static Dictionary<string, string> BitcoinCoreTransalations { get; } = new Dictionary<string, string> { | ||
["too-long-mempool-chain"] = "At least one coin you are trying to spend is part of long or heavy chain of unconfirmed transactions. You must wait for some previous transactions to confirm.", | ||
["bad-txns-inputs-missingorspent"] = "At least one coin you are trying to spend is already spent.", | ||
["missing-inputs"] = "At least one coin you are trying to spend is already spent.", | ||
["txn-mempool-conflict"] = "At least one coin you are trying to spend is already spent.", | ||
["bad-txns-inputs-duplicate"] = "The transaction contains duplicated inputs.", | ||
["bad-txns-nonfinal"] = "The transaction is not final and cannot be broadcasted.", | ||
["bad-txns-oversize"] = "The transaction is too big." | ||
}; | ||
|
||
public static string ToUserFriendlyString(this HttpRequestException ex) | ||
{ | ||
var transalations = new Dictionary<string, string> | ||
var trimmed = Guard.Correct(ex.Message); | ||
if (trimmed == "") | ||
{ | ||
["too-long-mempool-chain"] = "At least one coin you are trying to spend is part of long chain of unconfirmed transactions. You must wait for some previous transactions to confirm.", | ||
["bad-txns-inputs-missingorspent"] = "At least one coin you are trying to spend is already spent.", | ||
["missing-inputs"] = "At least one coin you are trying to spend is already spent.", | ||
["bad-txns-inputs-duplicate"] = "The transaction contains duplicated inputs.", | ||
["bad-txns-nonfinal"] = "The transaction is not final and cannot be broadcasted.", | ||
["bad-txns-oversize"] = "The transaction is too big." | ||
}; | ||
|
||
var msg = ex.Message.Substring(0, ex.Message.IndexOf(',')); | ||
if(transalations.ContainsKey(msg)) | ||
return ex.ToTypeMessageString(); | ||
} | ||
else | ||
{ | ||
return transalations[msg]; | ||
foreach (KeyValuePair<string, string> pair in BitcoinCoreTransalations) | ||
{ | ||
if (trimmed.Contains(pair.Key, StringComparison.InvariantCultureIgnoreCase)) | ||
{ | ||
return pair.Value; | ||
} | ||
} | ||
|
||
return ex.ToTypeMessageString(); | ||
} | ||
return ex.ToTypeMessageString(); | ||
} | ||
} | ||
} |
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