Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(wallet): update swap token text #11978

Merged
merged 1 commit into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.hardware.Camera;
Expand All @@ -20,9 +21,12 @@
import android.os.Looper;
import android.text.Editable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextWatcher;
import android.text.method.LinkMovementMethod;
import android.util.DisplayMetrics;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
Expand Down Expand Up @@ -92,6 +96,7 @@
import org.chromium.chrome.browser.util.TabUtils;
import org.chromium.mojo.bindings.ConnectionErrorHandler;
import org.chromium.mojo.system.MojoException;
import org.chromium.ui.text.NoUnderlineClickableSpan;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -118,6 +123,7 @@ public class BuySendSwapActivity extends BraveWalletBaseActivity

private TextView mSlippageToleranceText;
private int radioSlippageToleranceCheckedId;
private TextView mMarketLimitPriceText;

public enum ActivityType {
BUY(0),
Expand Down Expand Up @@ -197,6 +203,7 @@ protected void triggerLayoutInflation() {
TextView toAssetText = findViewById(R.id.to_asset_text);

TextView marketPriceValueText = findViewById(R.id.market_price_value_text);
mMarketLimitPriceText = findViewById(R.id.market_limit_price_text);

mSlippageToleranceText = findViewById(R.id.slippage_tolerance_dropdown);

Expand Down Expand Up @@ -440,12 +447,11 @@ private void updateSwapControls(
} catch (NumberFormatException | NullPointerException ex) {
}
}
TextView marketLimitPriceText = findViewById(R.id.market_limit_price_text);
String symbol = "ETH";
if (mCurrentBlockchainToken != null) {
symbol = mCurrentBlockchainToken.symbol;
}
marketLimitPriceText.setText(String.format(getString(R.string.market_price_in), symbol));
mMarketLimitPriceText.setText(String.format(getString(R.string.market_price_in), symbol));
checkBalanceShowError(response, errorResponse);
}

Expand Down Expand Up @@ -681,6 +687,7 @@ private void setFromSendValueValidationResult(String validationResult) {
}
}

@SuppressLint("ClickableViewAccessibility")
private void adjustControls() {
EditText toValueText = findViewById(R.id.to_value_text);
TextView marketPriceValueText = findViewById(R.id.market_price_value_text);
Expand Down Expand Up @@ -892,9 +899,36 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
findViewById(R.id.brave_fee).setVisibility(View.VISIBLE);
TextView dexAggregator = findViewById(R.id.dex_aggregator);
dexAggregator.setVisibility(View.VISIBLE);
dexAggregator.setOnClickListener(v -> {
TabUtils.openUrlInNewTab(false, Utils.DEX_AGGREGATOR_URL);
TabUtils.bringChromeTabbedActivityToTheTop(this);
dexAggregator.setMovementMethod(LinkMovementMethod.getInstance());
String dexAggregatorSrc = getString(R.string.swap_dex_aggregator_name);
String degAggregatorText = getString(R.string.wallet_dex_aggregator, dexAggregatorSrc);

NoUnderlineClickableSpan span = new NoUnderlineClickableSpan(
getResources(), R.color.brave_action_color, (textView) -> {
TabUtils.openUrlInNewTab(false, Utils.DEX_AGGREGATOR_URL);
TabUtils.bringChromeTabbedActivityToTheTop(BuySendSwapActivity.this);
});

SpannableString dexAggregatorSpanStr = Utils.createSpannableString(
degAggregatorText, dexAggregatorSrc, span, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
dexAggregator.setText(dexAggregatorSpanStr);
dexAggregator.setOnTouchListener((v, event) -> {
if (event.getAction() == MotionEvent.ACTION_UP) {
// verify if the touch was on textview's drawable
// note: do not add right padding to this textview, or make sure to adjust the
// below condition for extra padding
if (event.getRawX() >= (v.getRight() - dexAggregator.getTotalPaddingRight())) {
Context context = BuySendSwapActivity.this;
Utils.showPopUp(context, context.getString(R.string.swap_text),
context.getString(R.string.brave_wallet_swap_disclaimer_description,
getString(R.string.swap_dex_aggregator_name)),
context.getString(R.string.dialog_positive_button),
R.drawable.ic_info, (dialog, what) -> {});

return true;
}
}
return false;
});
initSwapFromToAssets();
}
Expand Down Expand Up @@ -1488,12 +1522,16 @@ public void finishNativeInitialization() {
for (EthereumChain chain : chains) {
if (chainId.equals(chain.chainId)) {
TextView fromAssetText = findViewById(R.id.from_asset_text);
TextView marketLimitPriceText =
findViewById(R.id.market_limit_price_text);
if (Utils.isCustomNetwork(chainId)) {
Utils.setBlockiesBitmapCustomAsset(mExecutor, mHandler, null, "",
chain.symbol, getResources().getDisplayMetrics().density,
fromAssetText, this, true, (float) 0.5);
}
fromAssetText.setText(chain.symbol);
marketLimitPriceText.setText(String.format(
getString(R.string.market_price_in), chain.symbol));
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
public class SwapBottomSheetDialogFragment
extends BottomSheetDialogFragment implements View.OnClickListener {
public static final String TAG_FRAGMENT = SwapBottomSheetDialogFragment.class.getName();
LinearLayout mBuyLayout;
LinearLayout mSendLayout;
LinearLayout mSwapLayout;
private LinearLayout mBuyLayout;
private LinearLayout mSendLayout;
private LinearLayout mSwapLayout;
private String mChainId;

public static SwapBottomSheetDialogFragment newInstance() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
Expand All @@ -24,16 +25,21 @@
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Handler;
import android.text.SpannableString;
import android.text.style.ClickableSpan;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.VisibleForTesting;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
Expand All @@ -58,19 +64,13 @@
import org.chromium.brave_wallet.mojom.TransactionType;
import org.chromium.brave_wallet.mojom.TxData;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.crypto_wallet.activities.AccountDetailActivity;
import org.chromium.chrome.browser.crypto_wallet.activities.AddAccountActivity;
import org.chromium.chrome.browser.crypto_wallet.activities.AssetDetailActivity;
import org.chromium.chrome.browser.crypto_wallet.activities.BuySendSwapActivity;
import org.chromium.chrome.browser.crypto_wallet.adapters.WalletCoinAdapter;
import org.chromium.chrome.browser.crypto_wallet.fragments.ApproveTxBottomSheetDialogFragment;
import org.chromium.chrome.browser.crypto_wallet.listeners.OnWalletListItemClick;
import org.chromium.chrome.browser.crypto_wallet.model.WalletListItemModel;
import org.chromium.chrome.browser.crypto_wallet.observers.ApprovedTxObserver;
import org.chromium.chrome.browser.crypto_wallet.util.AssetsPricesHelper;
import org.chromium.chrome.browser.crypto_wallet.util.Blockies;
import org.chromium.chrome.browser.crypto_wallet.util.PendingTxHelper;
import org.chromium.chrome.browser.crypto_wallet.util.TokenUtils;
import org.chromium.chrome.browser.util.TabUtils;
import org.chromium.ui.widget.Toast;

Expand All @@ -89,11 +89,9 @@
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Utils {
public static int ONBOARDING_FIRST_PAGE_ACTION = 1;
Expand Down Expand Up @@ -1315,6 +1313,38 @@ private static void updateWalletCoinTransactionStatus(
itemModel.setTxStatusBitmap(txStatusBitmap);
}

public static AlertDialog showPopUp(Context context, String title, String message,
String positiveButtonTitle, int icon, DialogInterface.OnClickListener onClickListener) {
assert null != context;
MaterialAlertDialogBuilder builder =
new MaterialAlertDialogBuilder(context, R.style.BraveWalletAlertDialogTheme)
.setTitle(title)
.setMessage(message)
.setIcon(icon);
// positive button is only shown if the listener is not null
if (null != onClickListener) {
builder.setPositiveButton(positiveButtonTitle, onClickListener);
}
return builder.show();
}

public static SpannableString createSpannableString(
String text, ClickableSpan clickListener, int startIndex, int endIndex, int flags) {
assert null != text;
SpannableString spannableString = new SpannableString(text);
spannableString.setSpan(clickListener, startIndex, endIndex, flags);
return spannableString;
}

public static SpannableString createSpannableString(
String text, String spanText, ClickableSpan clickListener, int flags) {
assert null != spanText;
assert null != text;
int startIndex = text.indexOf(spanText);
int endIndex = startIndex + spanText.length();
return createSpannableString(text, clickListener, startIndex, endIndex, flags);
}

public static void warnWhenError(
String tag, String apiName, Integer error, String errorMessage) {
if (error != ProviderError.SUCCESS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,7 @@ public void onClick(View v) {
popup.getMenuInflater().inflate(
R.menu.monthly_contribution_popup_menu, popup.getMenu());
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
Pavneet-Sing marked this conversation as resolved.
Show resolved Hide resolved
public boolean onMenuItemClick(MenuItem item) {
if (item.getItemId() == R.id.change_amount_menu_id) {
openBannerActivity();
Expand Down
9 changes: 5 additions & 4 deletions android/java/res/layout/activity_buy_send_swap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -664,14 +664,15 @@
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/wallet_dex_aggregator"
android:textColor="@color/brave_action_color"
app:drawableTint="@color/brave_action_color"
android:drawablePadding="8dp"
android:gravity="center"
android:textSize="14sp"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:visibility="gone"/>
android:layout_marginVertical="16dp"
android:visibility="gone"
app:drawableEndCompat="@drawable/ic_info" />

</LinearLayout>

Expand Down
5 changes: 5 additions & 0 deletions android/java/res/values/brave_styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@
<item name="android:backgroundDimEnabled">false</item>
</style>

<style name="BraveWalletAlertDialogTheme" parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<item name="android:background">@color/wallet_bg</item>
<item name="android:colorBackground">@color/wallet_bg</item>
</style>

<style name="BraveWalletTabsTextAppearance" parent="TextAppearance.Design.Tab">
<item name="textAllCaps">false</item>
</style>
Expand Down
13 changes: 11 additions & 2 deletions browser/ui/android/strings/android_brave_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -1879,7 +1879,13 @@ Are you sure you want to do this?
Send crypto or transfer from one account to another.
</message>
<message name="IDS_SWAP_TEXT" desc="Brave Wallet swap bottomsheet text">
Swap crypto assets with Brave DEX aggregator.
Swap tokens and assets
</message>
<message name="IDS_DIALOG_POSITIVE_BUTTON" desc="Brave Wallet swap bottomsheet text">
OK
</message>
<message name="IDS_BRAVE_WALLET_SWAP_DISCLAIMER_DESCRIPTION" desc="Swap 0x Security and Privacy Disclaimer Description">
<ph name="DEX_PROVIDER">%1$s</ph> will process the Ethereum address and IP address to fulfill a transaction (including getting quotes). <ph name="DEX_PROVIDER">%1$s</ph> will ONLY use this data for the purposes of processing transactions.
</message>
<message name="IDS_SECURE_YOUR_CRYPTO" desc="Brave Wallet onboarding text">
Secure your crypto with a password
Expand Down Expand Up @@ -2677,7 +2683,10 @@ If you don't accept this request, VPN will not reconnect and your internet conne
Failed to import account, please try again.
</message>
<message name="IDS_WALLET_DEX_AGGREGATOR" desc="Brave wallet msg about using 0x for swap">
Brave uses 0x as a DEX aggregator.
Brave uses <ph name="DEX_PROVIDER">%1$s<ex>0x</ex></ph> as a DEX aggregator.
</message>
<message name="IDS_SWAP_DEX_AGGREGATOR_NAME" desc="Brave wallet swap dex aggregator source name" translateable="false">
0x
Pavneet-Sing marked this conversation as resolved.
Show resolved Hide resolved
</message>
<message name="IDS_WALLET_POWERED_BY_COIN_GECKO" desc="Disclaimer on assets details page for GoinGecko contract agreement">
Price data powered by CoinGecko
Expand Down