Don't show link to Bittrex

This commit is contained in:
Javi Rueda 2021-04-08 17:26:20 +02:00
parent 6e32f7724f
commit 8e7b8aba92
2 changed files with 51 additions and 0 deletions

View file

@ -33,6 +33,14 @@ import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.switchmaterial.SwitchMaterial; import com.google.android.material.switchmaterial.SwitchMaterial;
import com.google.android.material.textfield.TextInputEditText; import com.google.android.material.textfield.TextInputEditText;
import org.json.JSONObject;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;
import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.net.URLEncoder; import java.net.URLEncoder;
@ -44,6 +52,10 @@ import java.text.DecimalFormatSymbols;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import javax.crypto.Mac; import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec; import javax.crypto.spec.SecretKeySpec;
@ -291,6 +303,44 @@ public class WalletFragment extends BaseFragment implements SdkStatusListener, W
} }
}); });
ExecutorService executor = Executors.newSingleThreadExecutor();
// This will return /true/ if user IP is **not** on the US or the request fails
Future<Boolean> localeFuture = executor.submit(() -> {
Request request = new Request.Builder().url("https://api.lbry.com/locale/get").build();
OkHttpClient okHttpClient = new OkHttpClient();
try (Response response = okHttpClient.newCall(request).execute()){
ResponseBody responseBody = response.body();
JSONObject responseJson;
if (responseBody != null)
responseJson = new JSONObject(responseBody.string());
else
return false;
if (responseJson.has("data") && responseJson.getBoolean("success")) {
JSONObject dataJson = (JSONObject) responseJson.get("data");
return !dataJson.getString("country").equals("US");
} else {
return false;
}
} catch (IOException e) {
e.printStackTrace();
}
return false;
});
try {
Boolean isNotUS = localeFuture.get();
if (isNotUS)
textConvertCreditsBittrex.setVisibility(View.VISIBLE);
else
textConvertCreditsBittrex.setVisibility(View.GONE);
} catch (ExecutionException | InterruptedException e) {
e.printStackTrace();
}
buttonSignUp.setOnClickListener(new View.OnClickListener() { buttonSignUp.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {

View file

@ -155,6 +155,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:layout_marginStart="16dp" android:layout_marginStart="16dp"
android:visibility="gone"
android:fontFamily="@font/inter" android:fontFamily="@font/inter"
android:text="@string/convert_credits_bittrex" android:text="@string/convert_credits_bittrex"
android:textColorLink="@color/lbryGreen" android:textColorLink="@color/lbryGreen"