force_pause on subscribe/redeem

This commit is contained in:
Nicolás Sánchez 2025-04-07 09:08:06 -03:00
parent ddc3e272bc
commit a0b89896dc
2 changed files with 9 additions and 7 deletions

View File

@ -345,7 +345,7 @@ public class EarnerInterface {
final double amountToSubscribe = Double.parseDouble(input.getText().toString()); final double amountToSubscribe = Double.parseDouble(input.getText().toString());
new Thread(() -> { new Thread(() -> {
try { try {
JsonObject response = subscribeFunds(exchange, amountToSubscribe,true); JsonObject response = subscribeFunds(exchange, amountToSubscribe,true,true);
new Handler(Looper.getMainLooper()).post(() -> { new Handler(Looper.getMainLooper()).post(() -> {
showJsonDialog(response, context); showJsonDialog(response, context);
}); });
@ -379,7 +379,7 @@ public class EarnerInterface {
final double amountToRedeem = Double.parseDouble(input.getText().toString()); final double amountToRedeem = Double.parseDouble(input.getText().toString());
new Thread(() -> { new Thread(() -> {
try { try {
JsonObject response = redeemFunds(exchange, amountToRedeem,true); JsonObject response = redeemFunds(exchange, amountToRedeem,true,true);
new Handler(Looper.getMainLooper()).post(() -> { new Handler(Looper.getMainLooper()).post(() -> {
showJsonDialog(response, context); showJsonDialog(response, context);
}); });
@ -868,11 +868,12 @@ public class EarnerInterface {
} }
} }
public static JsonObject subscribeFunds(String exchange, double amount, boolean retry) throws IOException { public static JsonObject subscribeFunds(String exchange, double amount, boolean forcePause, boolean retry) throws IOException {
Gson gson = new Gson(); Gson gson = new Gson();
JsonObject jsonPayload = new JsonObject(); JsonObject jsonPayload = new JsonObject();
jsonPayload.addProperty("broker", exchange); jsonPayload.addProperty("broker", exchange);
jsonPayload.addProperty("amount", amount); jsonPayload.addProperty("amount", amount);
jsonPayload.addProperty("force_pause", forcePause);
String jsonPayloadString = gson.toJson(jsonPayload); String jsonPayloadString = gson.toJson(jsonPayload);
RequestBody requestBody = RequestBody.create(jsonPayloadString, MediaType.get("application/json; charset=utf-8")); RequestBody requestBody = RequestBody.create(jsonPayloadString, MediaType.get("application/json; charset=utf-8"));
@ -885,7 +886,7 @@ public class EarnerInterface {
try (Response subscribeFundsResponse = httpClient.newCall(subscribeFundsRequest).execute()) { try (Response subscribeFundsResponse = httpClient.newCall(subscribeFundsRequest).execute()) {
if (!subscribeFundsResponse.isSuccessful()) { if (!subscribeFundsResponse.isSuccessful()) {
if (subscribeFundsResponse.code() == 503 && retry) { if (subscribeFundsResponse.code() == 503 && retry) {
return subscribeFunds(exchange, amount, false); return subscribeFunds(exchange, amount, forcePause,false);
} }
throw new IOException("Unexpected code " + subscribeFundsResponse); throw new IOException("Unexpected code " + subscribeFundsResponse);
} }
@ -906,11 +907,12 @@ public class EarnerInterface {
} }
} }
public static JsonObject redeemFunds(String exchange, double amount, boolean retry) throws IOException { public static JsonObject redeemFunds(String exchange, double amount, boolean forcePause, boolean retry) throws IOException {
Gson gson = new Gson(); Gson gson = new Gson();
JsonObject jsonPayload = new JsonObject(); JsonObject jsonPayload = new JsonObject();
jsonPayload.addProperty("broker", exchange); jsonPayload.addProperty("broker", exchange);
jsonPayload.addProperty("amount", amount); jsonPayload.addProperty("amount", amount);
jsonPayload.addProperty("force_pause", forcePause);
String jsonPayloadString = gson.toJson(jsonPayload); String jsonPayloadString = gson.toJson(jsonPayload);
RequestBody requestBody = RequestBody.create(jsonPayloadString, MediaType.get("application/json; charset=utf-8")); RequestBody requestBody = RequestBody.create(jsonPayloadString, MediaType.get("application/json; charset=utf-8"));
@ -923,7 +925,7 @@ public class EarnerInterface {
try (Response redeemFundsResponse = httpClient.newCall(redeemFundsRequest).execute()) { try (Response redeemFundsResponse = httpClient.newCall(redeemFundsRequest).execute()) {
if (!redeemFundsResponse.isSuccessful()) { if (!redeemFundsResponse.isSuccessful()) {
if (redeemFundsResponse.code() == 503 && retry) { if (redeemFundsResponse.code() == 503 && retry) {
return redeemFunds(exchange, amount, false); return redeemFunds(exchange, amount, forcePause,false);
} }
throw new IOException("Unexpected code " + redeemFundsResponse); throw new IOException("Unexpected code " + redeemFundsResponse);
} }

View File

@ -1,7 +1,7 @@
<resources> <resources>
<string name="app_name" translatable="false">DCAv2GUI</string> <string name="app_name" translatable="false">DCAv2GUI</string>
<string name="nav_header_title" translatable="false">DCAv2</string> <string name="nav_header_title" translatable="false">DCAv2</string>
<string name="nav_header_subtitle">Version 2025.03.13 </string> <string name="nav_header_subtitle">Version 2025.04.07</string>
<string name="navigation_drawer_open">Open navigation drawer</string> <string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string> <string name="navigation_drawer_close">Close navigation drawer</string>
<string name="nav_header_desc">Navigation header</string> <string name="nav_header_desc">Navigation header</string>