mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-06-28 12:29:51 +00:00
Cw 872 nano enhancements (#1909)
* fix headers on all api calls * fix duplicate nano nodes on fresh install, api key fixes * fix liveness indicators + false positive responses to queries
This commit is contained in:
parent
214fc7113c
commit
831a6d9f9a
3 changed files with 62 additions and 28 deletions
|
@ -99,8 +99,8 @@ class Node extends HiveObject with Keyable {
|
|||
case WalletType.polygon:
|
||||
case WalletType.solana:
|
||||
case WalletType.tron:
|
||||
return Uri.parse(
|
||||
"http${isSSL ? "s" : ""}://$uriRaw${path!.startsWith("/") ? path : "/$path"}");
|
||||
return Uri.parse(
|
||||
"http${isSSL ? "s" : ""}://$uriRaw${path!.startsWith("/") ? path : "/$path"}");
|
||||
case WalletType.none:
|
||||
throw Exception('Unexpected type ${type.toString()} for Node uri');
|
||||
}
|
||||
|
@ -152,6 +152,7 @@ class Node extends HiveObject with Keyable {
|
|||
return requestMoneroNode();
|
||||
case WalletType.nano:
|
||||
case WalletType.banano:
|
||||
return requestNanoNode();
|
||||
case WalletType.bitcoin:
|
||||
case WalletType.litecoin:
|
||||
case WalletType.bitcoinCash:
|
||||
|
@ -198,14 +199,16 @@ class Node extends HiveObject with Keyable {
|
|||
);
|
||||
client.close();
|
||||
|
||||
if ((
|
||||
response.body.contains("400 Bad Request") // Some other generic error
|
||||
|| response.body.contains("plain HTTP request was sent to HTTPS port") // Cloudflare
|
||||
|| response.headers["location"] != null // Generic reverse proxy
|
||||
|| response.body.contains("301 Moved Permanently") // Poorly configured generic reverse proxy
|
||||
) && !(useSSL??false)
|
||||
) {
|
||||
|
||||
if ((response.body.contains("400 Bad Request") // Some other generic error
|
||||
||
|
||||
response.body.contains("plain HTTP request was sent to HTTPS port") // Cloudflare
|
||||
||
|
||||
response.headers["location"] != null // Generic reverse proxy
|
||||
||
|
||||
response.body
|
||||
.contains("301 Moved Permanently") // Poorly configured generic reverse proxy
|
||||
) &&
|
||||
!(useSSL ?? false)) {
|
||||
final oldUseSSL = useSSL;
|
||||
useSSL = true;
|
||||
try {
|
||||
|
@ -271,6 +274,35 @@ class Node extends HiveObject with Keyable {
|
|||
}
|
||||
}
|
||||
|
||||
Future<bool> requestNanoNode() async {
|
||||
try {
|
||||
final response = await http.post(
|
||||
uri,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"nano-app": "cake-wallet"
|
||||
},
|
||||
body: jsonEncode(
|
||||
{
|
||||
"action": "account_balance",
|
||||
"account": "nano_38713x95zyjsqzx6nm1dsom1jmm668owkeb9913ax6nfgj15az3nu8xkx579",
|
||||
},
|
||||
),
|
||||
);
|
||||
final data = await jsonDecode(response.body);
|
||||
if (response.statusCode != 200 ||
|
||||
data["error"] != null ||
|
||||
data["balance"] == null ||
|
||||
data["receivable"] == null) {
|
||||
throw Exception(
|
||||
"Error while trying to get balance! ${data["error"] != null ? data["error"] : ""}");
|
||||
}
|
||||
return true;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> requestEthereumServer() async {
|
||||
try {
|
||||
final response = await http.get(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue