diff --git a/src/bitpaywalletclient/bpwalletclient.cpp b/src/bitpaywalletclient/bpwalletclient.cpp index 8981f994..e0118741 100644 --- a/src/bitpaywalletclient/bpwalletclient.cpp +++ b/src/bitpaywalletclient/bpwalletclient.cpp @@ -567,6 +567,16 @@ bool BitPayWalletClient::GetFeeLevels() return false; long httpStatusCode = 0; + if (SendRequest("get", "https://www.digitalbitbox.com/fees/levels.json?r="+std::to_string(CheapRandom()), "{}", response, httpStatusCode, false)) { + // we could read our "internal" fees + feeLevelsObject.read(response); + if (response.size() > 10 && feeLevelsObject.isArray()) { + return true; + } + } + + response.clear(); + httpStatusCode = 0; if (!SendRequest("get", "/v1/feelevels/?network=livenet&r="+std::to_string(CheapRandom()), "{}", response, httpStatusCode)) return false; @@ -605,7 +615,7 @@ int64_t BitPayWalletClient::GetFeeForPriority(int prio) } } - return 2000; //default fallback feerate + return 0; //don't use a fallback fee, abort at this point } bool BitPayWalletClient::GetWallets(std::string& response) @@ -631,7 +641,7 @@ bool BitPayWalletClient::GetTransactionHistory(std::string& response) return false; long httpStatusCode = 0; - if (!SendRequest("get", "/v1/txhistory/?limit=50&r="+std::to_string(CheapRandom()), "{}", response, httpStatusCode)) + if (!SendRequest("get", "/v1/txhistory/?r="+std::to_string(CheapRandom()), "{}", response, httpStatusCode)) return false; if (httpStatusCode != 200) @@ -1102,7 +1112,8 @@ bool BitPayWalletClient::SendRequest(const std::string& method, const std::string& url, const std::string& args, std::string& responseOut, - long& httpcodeOut) + long& httpcodeOut, + bool bws) { CURL* curl; CURLcode res; @@ -1114,18 +1125,20 @@ bool BitPayWalletClient::SendRequest(const std::string& method, if (curl) { struct curl_slist* chunk = NULL; std::string hashOut; - std::string signature = SignRequest(method, url, args, hashOut); - if (signature.empty()) { + std::string signature = bws ? SignRequest(method, url, args, hashOut) : ""; + if (signature.empty() && bws) { BP_LOG_MSG("SignRequest failed."); DBB::LogPrintDebug("SignRequest failed.", ""); success = false; } else { - chunk = curl_slist_append(chunk, ("x-identity: " + GetCopayerId()).c_str()); //requestPubKey).c_str()); - chunk = curl_slist_append(chunk, ("x-signature: " + signature).c_str()); - chunk = curl_slist_append(chunk, ("x-client-version: dbb-1.0.0")); + if (bws) { + chunk = curl_slist_append(chunk, ("x-identity: " + GetCopayerId()).c_str()); //requestPubKey).c_str()); + chunk = curl_slist_append(chunk, ("x-signature: " + signature).c_str()); + chunk = curl_slist_append(chunk, ("x-client-version: dbb-1.0.0")); + } chunk = curl_slist_append(chunk, "Content-Type: application/json"); res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk); - curl_easy_setopt(curl, CURLOPT_URL, (baseURL + url).c_str()); + curl_easy_setopt(curl, CURLOPT_URL, (bws ? (baseURL + url) : url).c_str()); if (method == "post") curl_easy_setopt(curl, CURLOPT_POSTFIELDS, args.c_str()); diff --git a/src/bitpaywalletclient/bpwalletclient.h b/src/bitpaywalletclient/bpwalletclient.h index 6d4287d2..1f2001d4 100644 --- a/src/bitpaywalletclient/bpwalletclient.h +++ b/src/bitpaywalletclient/bpwalletclient.h @@ -147,7 +147,8 @@ class BitPayWalletClient const std::string& url, const std::string& args, std::string& responseOut, - long& httpStatusCodeOut); + long& httpStatusCodeOut, + bool bws = true); //!set the master extended public key void setMasterPubKey(const std::string& xPubKey); diff --git a/src/qt/dbb_gui.cpp b/src/qt/dbb_gui.cpp index 5dc39eaf..eb3eb125 100644 --- a/src/qt/dbb_gui.cpp +++ b/src/qt/dbb_gui.cpp @@ -2159,17 +2159,22 @@ void DBBDaemonGui::createTxProposalPressed() std::string errorOut; int64_t fee = singleWallet->client.GetFeeForPriority(this->ui->feeLevel->currentIndex()); - - if (!singleWallet->client.CreatePaymentProposal(this->ui->sendToAddress->text().toStdString(), amount, fee, proposalOut, errorOut)) { + if (fee == 0) { emit changeNetLoading(false); emit shouldHideModalInfo(); - emit shouldShowAlert("Error", QString::fromStdString(errorOut)); - } - else - { - emit changeNetLoading(false); - emit shouldUpdateModalInfo(tr("Start Signing Process")); - emit createTxProposalDone(singleWallet, "", proposalOut); + emit shouldShowAlert("Error", tr("Could not estimate fees. Make sure you are online.")); + } else { + if (!singleWallet->client.CreatePaymentProposal(this->ui->sendToAddress->text().toStdString(), amount, fee, proposalOut, errorOut)) { + emit changeNetLoading(false); + emit shouldHideModalInfo(); + emit shouldShowAlert("Error", QString::fromStdString(errorOut)); + } + else + { + emit changeNetLoading(false); + emit shouldUpdateModalInfo(tr("Start Signing Process")); + emit createTxProposalDone(singleWallet, "", proposalOut); + } } thread->completed();