Swap slippage tolerance desktop parity
This commit is contained in:
+90
-16
@@ -17,6 +17,7 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.text.Editable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.MenuItem;
|
||||
@@ -112,6 +113,9 @@ public class BuySendSwapActivity extends AsyncInitializationActivity
|
||||
private CameraSourcePreview mCameraSourcePreview;
|
||||
private boolean mInitialLayoutInflationComplete;
|
||||
|
||||
private TextView mSlippageToleranceText;
|
||||
private int radioSlippageToleranceCheckedId = 0;
|
||||
|
||||
public enum ActivityType {
|
||||
BUY(0),
|
||||
SEND(1),
|
||||
@@ -240,6 +244,8 @@ public class BuySendSwapActivity extends AsyncInitializationActivity
|
||||
|
||||
TextView marketPriceValueText = findViewById(R.id.market_price_value_text);
|
||||
|
||||
mSlippageToleranceText = findViewById(R.id.slippage_tolerance_dropdown);
|
||||
|
||||
onInitialLayoutInflationComplete();
|
||||
|
||||
adjustControls();
|
||||
@@ -327,9 +333,6 @@ public class BuySendSwapActivity extends AsyncInitializationActivity
|
||||
if (mActivityType == ActivityType.SWAP) {
|
||||
updateBalance(mCustomAccountAdapter.getTitleAtPosition(position), false);
|
||||
}
|
||||
} else if (parent.getId() == R.id.slippage_tolerance_spinner
|
||||
&& mActivityType == ActivityType.SWAP) {
|
||||
getSendSwapQuota(true, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -361,12 +364,7 @@ public class BuySendSwapActivity extends AsyncInitializationActivity
|
||||
sellAddress = ETHEREUM_CONTRACT_FOR_SWAP;
|
||||
}
|
||||
}
|
||||
Spinner slippageToleranceSpinner = findViewById(R.id.slippage_tolerance_spinner);
|
||||
String percent =
|
||||
slippageToleranceSpinner
|
||||
.getItemAtPosition(slippageToleranceSpinner.getSelectedItemPosition())
|
||||
.toString();
|
||||
percent = percent.replace("%", "");
|
||||
String percent = mSlippageToleranceText.getText().toString().replace("%", "");
|
||||
|
||||
SwapParams swapParams = new SwapParams();
|
||||
swapParams.takerAddress = from;
|
||||
@@ -701,6 +699,8 @@ public class BuySendSwapActivity extends AsyncInitializationActivity
|
||||
TextView toEstimateText = findViewById(R.id.to_estimate_text);
|
||||
TextView assetFromDropDown = findViewById(R.id.from_asset_text);
|
||||
RadioGroup radioPerPercent = findViewById(R.id.per_percent_radiogroup);
|
||||
RadioGroup radioSlippageTolerance = findViewById(R.id.slippage_tolerance_radiogroup);
|
||||
EditText slippageValueText = findViewById(R.id.slippage_value_text);
|
||||
ImageView arrowDown = findViewById(R.id.arrow_down);
|
||||
radioPerPercent.clearCheck();
|
||||
if (mActivityType == ActivityType.BUY) {
|
||||
@@ -820,13 +820,77 @@ public class BuySendSwapActivity extends AsyncInitializationActivity
|
||||
EditVisibleAssetsBottomSheetDialogFragment.TAG_FRAGMENT);
|
||||
});
|
||||
enableDisableSwapButton();
|
||||
Spinner spinner = findViewById(R.id.slippage_tolerance_spinner);
|
||||
spinner.setOnItemSelectedListener(this);
|
||||
// Creating adapter for a slippage tolerance spinner
|
||||
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
|
||||
android.R.layout.simple_spinner_item, Utils.getSlippageToleranceList(this));
|
||||
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
spinner.setAdapter(dataAdapter);
|
||||
mSlippageToleranceText.setOnClickListener(v -> {
|
||||
LinearLayout toleranceSubSection = findViewById(R.id.tolerance_subsection);
|
||||
int visibility = toleranceSubSection.getVisibility();
|
||||
if (visibility == View.VISIBLE) {
|
||||
toleranceSubSection.setVisibility(View.GONE);
|
||||
// Disable all buttons and fields
|
||||
findViewById(R.id.slippage_per_05_radiobutton).setEnabled(false);
|
||||
findViewById(R.id.slippage_per_1_radiobutton).setEnabled(false);
|
||||
findViewById(R.id.slippage_per_2_radiobutton).setEnabled(false);
|
||||
findViewById(R.id.slippage_value_text).setEnabled(false);
|
||||
} else {
|
||||
toleranceSubSection.setVisibility(View.VISIBLE);
|
||||
// Enable all buttons and fields
|
||||
findViewById(R.id.slippage_per_05_radiobutton).setEnabled(true);
|
||||
findViewById(R.id.slippage_per_1_radiobutton).setEnabled(true);
|
||||
findViewById(R.id.slippage_per_2_radiobutton).setEnabled(true);
|
||||
findViewById(R.id.slippage_value_text).setEnabled(true);
|
||||
}
|
||||
});
|
||||
radioSlippageTolerance.setOnCheckedChangeListener(
|
||||
new RadioGroup.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(RadioGroup group, int checkedId) {
|
||||
if (checkedId == -1) {
|
||||
radioSlippageToleranceCheckedId = checkedId;
|
||||
return;
|
||||
}
|
||||
double percent = 0d;
|
||||
if (checkedId == R.id.slippage_per_05_radiobutton) {
|
||||
percent = 0.5d;
|
||||
} else if (checkedId == R.id.slippage_per_1_radiobutton) {
|
||||
percent = 1d;
|
||||
} else if (checkedId == R.id.slippage_per_2_radiobutton) {
|
||||
percent = 2d;
|
||||
}
|
||||
|
||||
if (!(radioSlippageToleranceCheckedId == 0
|
||||
|| radioSlippageToleranceCheckedId == checkedId)) {
|
||||
updateSlippagePercentage(percent);
|
||||
}
|
||||
if (radioSlippageToleranceCheckedId == -1) {
|
||||
slippageValueText.setText("");
|
||||
}
|
||||
radioSlippageToleranceCheckedId = checkedId;
|
||||
}
|
||||
});
|
||||
slippageValueText.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {}
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
String inputPercent = s.toString().trim();
|
||||
Double percent = 0d;
|
||||
boolean hasError = false;
|
||||
try {
|
||||
percent = Double.parseDouble(inputPercent);
|
||||
if (percent >= 100) hasError = true;
|
||||
} catch (NumberFormatException ex) {
|
||||
hasError = true;
|
||||
}
|
||||
|
||||
if (!hasError && inputPercent.length() > 0) {
|
||||
updateSlippagePercentage(percent);
|
||||
radioSlippageTolerance.clearCheck();
|
||||
}
|
||||
}
|
||||
});
|
||||
ImageView refreshPrice = findViewById(R.id.refresh_price);
|
||||
refreshPrice.setOnClickListener(v -> { getSendSwapQuota(true, false); });
|
||||
EditText fromValueText = findViewById(R.id.from_value_text);
|
||||
@@ -946,6 +1010,16 @@ public class BuySendSwapActivity extends AsyncInitializationActivity
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSlippagePercentage(double percent) {
|
||||
SpannableString slippageToleranceSpannableText = new SpannableString(
|
||||
getString(R.string.crypto_wallet_tolerance_percentage, String.valueOf(percent)));
|
||||
mSlippageToleranceText.setText(slippageToleranceSpannableText);
|
||||
|
||||
if (mActivityType == ActivityType.SWAP) {
|
||||
getSendSwapQuota(true, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void qrCodeFunctionality() {
|
||||
RelativeLayout relativeLayout = findViewById(R.id.camera_layout);
|
||||
if (relativeLayout.getVisibility() == View.VISIBLE) {
|
||||
|
||||
@@ -242,17 +242,6 @@ public class Utils {
|
||||
return categories.toArray(new String[0]);
|
||||
}
|
||||
|
||||
public static List<String> getSlippageToleranceList(Activity activity) {
|
||||
List<String> categories = new ArrayList<String>();
|
||||
categories.add(activity.getText(R.string.crypto_wallet_tolerance_05).toString());
|
||||
categories.add(activity.getText(R.string.crypto_wallet_tolerance_1).toString());
|
||||
categories.add(activity.getText(R.string.crypto_wallet_tolerance_15).toString());
|
||||
categories.add(activity.getText(R.string.crypto_wallet_tolerance_3).toString());
|
||||
categories.add(activity.getText(R.string.crypto_wallet_tolerance_6).toString());
|
||||
|
||||
return categories;
|
||||
}
|
||||
|
||||
public static CharSequence getNetworkText(Activity activity, String chain_id) {
|
||||
CharSequence strNetwork = activity.getText(R.string.mainnet);
|
||||
switch (chain_id) {
|
||||
|
||||
@@ -506,35 +506,125 @@
|
||||
android:paddingEnd="14dp"
|
||||
android:layout_marginStart="14dp"
|
||||
android:layout_marginEnd="14dp"
|
||||
android:layout_marginBottom="24dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:background="@drawable/rounded_filled_bg_radius_12"
|
||||
android:orientation="horizontal">
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/slipping_expires_value_text"
|
||||
android:layout_width="0dp"
|
||||
<LinearLayout
|
||||
android:id="@+id/tolerance_textsection"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="3"
|
||||
android:text="@string/slipping_tolerance"
|
||||
android:textColor="@color/wallet_secondary_text_color"
|
||||
android:textSize="14sp"/>
|
||||
android:layout_marginStart="14dp"
|
||||
android:layout_marginEnd="14dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/slippage_tolerance_spinner"
|
||||
android:layout_width="0dp"
|
||||
<TextView
|
||||
android:id="@+id/slipping_expires_value_text"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="3"
|
||||
android:text="@string/slipping_tolerance"
|
||||
android:textColor="@color/wallet_secondary_text_color"
|
||||
android:textSize="14sp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/slippage_tolerance_dropdown"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/crypto_wallet_tolerance_05"
|
||||
android:textSize="14sp"
|
||||
android:textColor="@color/wallet_text_color"
|
||||
android:maxLines="1"
|
||||
android:gravity="center_vertical"
|
||||
app:drawableRightCompat="@drawable/ic_arrow_drop_down_white"
|
||||
android:drawablePadding="8dp"
|
||||
app:drawableTint="@color/wallet_text_color" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/tolerance_subsection"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:textSize="10sp"
|
||||
android:textColor="@color/wallet_text_color"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:prompt="@string/crypto_wallet_tolerance_05"
|
||||
android:paddingStart="8dp"
|
||||
android:paddingEnd="8dp"
|
||||
android:paddingTop="2dp"
|
||||
android:paddingBottom="2dp"
|
||||
tools:ignore="SmallSp" />
|
||||
android:layout_marginStart="14dp"
|
||||
android:layout_marginEnd="14dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:orientation="horizontal"
|
||||
android:visibility="gone" >
|
||||
|
||||
<RadioGroup
|
||||
android:id="@+id/slippage_tolerance_radiogroup"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="3"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/slippage_per_05_radiobutton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_margin="4dp"
|
||||
android:padding="2dp"
|
||||
android:background="@drawable/wallet_radio_button_selector"
|
||||
android:gravity="center"
|
||||
android:textColor="@color/crypto_wallet_radiobutton_color_selector"
|
||||
android:checked="true"
|
||||
android:button="@null"
|
||||
android:textSize="14sp"
|
||||
android:textStyle="bold"
|
||||
android:text="@string/crypto_wallet_tolerance_05" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/slippage_per_1_radiobutton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:button="@null"
|
||||
android:layout_margin="4dp"
|
||||
android:padding="2dp"
|
||||
android:background="@drawable/wallet_radio_button_selector"
|
||||
android:gravity="center"
|
||||
android:textColor="@color/crypto_wallet_radiobutton_color_selector"
|
||||
android:textSize="14sp"
|
||||
android:textStyle="bold"
|
||||
android:text="@string/crypto_wallet_tolerance_1" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/slippage_per_2_radiobutton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:button="@null"
|
||||
android:layout_margin="4dp"
|
||||
android:padding="2dp"
|
||||
android:background="@drawable/wallet_radio_button_selector"
|
||||
android:gravity="center"
|
||||
android:textSize="14sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/crypto_wallet_radiobutton_color_selector"
|
||||
android:text="@string/crypto_wallet_tolerance_2" />
|
||||
|
||||
</RadioGroup>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/slippage_value_text"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:inputType="numberDecimal"
|
||||
android:maxLines="1"
|
||||
android:textColor="@color/wallet_text_color"
|
||||
android:hint="@string/crypto_wallet_tolerance_percentage_hint"
|
||||
android:textSize="14sp"/>
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
|
||||
Reference in New Issue
Block a user