Skip to content

Commit

Permalink
Merge pull request #13692 from brave/pr13687_android_dapps_full_addre…
Browse files Browse the repository at this point in the history
…ss_1.40.x

Shows full addresses on Android wallet, adds an origin on a sign message screen (uplift to 1.40.x)
  • Loading branch information
kjozwiak authored Jun 14, 2022
2 parents 707b9e8 + 32d715f commit 04e65ff
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ private void fillAssetDependentControls(String asset, View view, int decimals) {
}
TextView fromTo = view.findViewById(R.id.from_to);
fromTo.setText(String.format(getResources().getString(R.string.crypto_wallet_from_to),
mAccountName, Utils.stripAccountAddress(to)));
mAccountName, Utils.stripAccountAddress(mTxInfo.fromAddress),
Utils.stripAccountAddress(to)));
TextView amountAsset = view.findViewById(R.id.amount_asset);
amountAsset.setText(
String.format(getResources().getString(R.string.crypto_wallet_amount_asset),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.URLUtil;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
Expand All @@ -27,6 +28,7 @@
import org.chromium.brave_wallet.mojom.AddChainRequest;
import org.chromium.brave_wallet.mojom.CoinType;
import org.chromium.brave_wallet.mojom.NetworkInfo;
import org.chromium.brave_wallet.mojom.OriginInfo;
import org.chromium.brave_wallet.mojom.SwitchChainRequest;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.app.BraveActivity;
Expand Down Expand Up @@ -59,6 +61,7 @@ public class AddSwitchChainNetworkFragment extends BaseDAppsFragment {
private List<TwoLineItemDataSource> networks;
private List<TwoLineItemDataSource> details;
private ImageView mFavicon;
private TextView mSiteTv;
private FaviconHelper mFaviconHelper;
private DefaultFaviconHelper mDefaultFaviconHelper;

Expand Down Expand Up @@ -141,13 +144,8 @@ public void onClick(@NonNull View widget) {
}
});
mFavicon = view.findViewById(R.id.fragment_add_token_iv_domain_icon);
TextView siteTv = view.findViewById(R.id.fragment_add_token_tv_site);
GURL siteUrl = Utils.getCurentTabUrl();
if (siteUrl != null) {
getBraveWalletService().geteTldPlusOneFromOrigin(Utils.getCurrentMojomOrigin(),
origin -> { siteTv.setText(Utils.geteTLD(origin.eTldPlusOne)); });
showFavIcon(siteUrl.getOrigin());
}
mSiteTv = view.findViewById(R.id.fragment_add_token_tv_site);

return view;
}

Expand Down Expand Up @@ -189,6 +187,7 @@ private void fetchNetworkInfo() {
mNetworkInfo = mAddChainRequest.networkInfo;
hasMultipleAddSwitchChainRequest = addChainRequests.length > 1;
updateState();
fillOriginInfo(mAddChainRequest.originInfo);
});
} else if (mPanelType == SWITCH_ETHEREUM_CHAIN) {
mBraveWalletBaseActivity.getJsonRpcService().getPendingSwitchChainRequests(
Expand All @@ -205,10 +204,19 @@ private void fetchNetworkInfo() {
}
}
});
fillOriginInfo(mSwitchChainRequest.originInfo);
});
}
}

private void fillOriginInfo(OriginInfo originInfo) {
if (originInfo != null && URLUtil.isValidUrl(originInfo.originSpec)) {
GURL url = new GURL(originInfo.originSpec);
mSiteTv.setText(Utils.geteTLD(url, originInfo.eTldPlusOne));
showFavIcon(url);
}
}

private void updateState() {
if (getView() != null && mNetworkInfo != null) {
addNetworkTabInfo(mNetworkInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.URLUtil;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
Expand All @@ -25,6 +26,7 @@
import org.chromium.chrome.browser.crypto_wallet.BlockchainRegistryFactory;
import org.chromium.chrome.browser.crypto_wallet.activities.BraveWalletBaseActivity;
import org.chromium.chrome.browser.crypto_wallet.util.Utils;
import org.chromium.url.GURL;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -94,11 +96,18 @@ private void fillAddSuggestTokenRequest(boolean init) {
}
});
}
mWebSite.setText(mCurrentAddSuggestTokenRequest.origin.originSpec);
fillOriginInfo(mCurrentAddSuggestTokenRequest.origin);
initToken();
});
}

private void fillOriginInfo(OriginInfo originInfo) {
if (originInfo != null && URLUtil.isValidUrl(originInfo.originSpec)) {
GURL url = new GURL(originInfo.originSpec);
mWebSite.setText(Utils.geteTLD(url, originInfo.eTldPlusOne));
}
}

private void updateNetwork() {
getJsonRpcService().getChainId(CoinType.ETH, chainId -> {
getJsonRpcService().getAllNetworks(CoinType.ETH, chains -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.URLUtil;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
Expand All @@ -33,6 +34,7 @@
import org.chromium.chrome.R;
import org.chromium.chrome.browser.crypto_wallet.adapters.SignMessagePagerAdapter;
import org.chromium.chrome.browser.crypto_wallet.util.Utils;
import org.chromium.url.GURL;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -50,6 +52,7 @@ public class SignMessageFragment extends BaseDAppsBottomSheetDialogFragment {
private TextView mNetworkName;
private Button mBtCancel;
private Button mBtSign;
private TextView mWebSite;
private ExecutorService mExecutor;
private Handler mHandler;

Expand All @@ -75,6 +78,7 @@ public View onCreateView(

mBtCancel = view.findViewById(R.id.fragment_sign_msg_btn_cancel);
mBtSign = view.findViewById(R.id.fragment_sign_msg_btn_sign);
mWebSite = view.findViewById(R.id.domain);
initComponents();

return view;
Expand Down Expand Up @@ -113,6 +117,12 @@ private void fillSignMessageInfo(boolean init) {
mBtCancel.setOnClickListener(v -> { notifySignMessageRequestProcessed(false); });
mBtSign.setOnClickListener(v -> { notifySignMessageRequestProcessed(true); });
}
if (mCurrentSignMessageRequest.originInfo != null
&& URLUtil.isValidUrl(mCurrentSignMessageRequest.originInfo.originSpec)) {
mWebSite.setText(
Utils.geteTLD(new GURL(mCurrentSignMessageRequest.originInfo.originSpec),
mCurrentSignMessageRequest.originInfo.eTldPlusOne));
}
});
}

Expand All @@ -127,7 +137,8 @@ private void updateAccount() {
if (address.equals(accountInfo.address)) {
Utils.setBlockiesBitmapResource(
mExecutor, mHandler, mAccountImage, address, true);
mAccountName.setText(accountInfo.name);
String accountText = accountInfo.name + "\n" + address;
mAccountName.setText(accountText);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.chromium.brave_wallet.mojom.AccountInfo;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.crypto_wallet.util.Blockies;
import org.chromium.chrome.browser.crypto_wallet.util.Utils;

import java.util.ArrayList;
import java.util.HashSet;
Expand Down Expand Up @@ -95,7 +96,7 @@ public void setSelectedAccount(String selectedAccount) {
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
final int arrayPosition = position;
holder.titleText.setText(mAccountInfo[arrayPosition].name);
holder.subTitleText.setText(stripAccountAddress(mAccountInfo[arrayPosition].address));
holder.subTitleText.setText(Utils.stripAccountAddress(mAccountInfo[arrayPosition].address));
setBlockiesBitmapResource(holder.iconImg, mAccountInfo[arrayPosition].address);
if (mCheckBoxStyle) {
holder.accountCheck.setVisibility(View.VISIBLE);
Expand Down Expand Up @@ -206,14 +207,4 @@ private void setBlockiesBitmapResource(ImageView iconImg, String source) {
});
});
}

private String stripAccountAddress(String address) {
String newAddress = "";

if (address.length() > 6) {
newAddress = address.substring(0, 6) + "***" + address.substring(address.length() - 5);
}

return newAddress;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -767,13 +767,17 @@ public static TxData getTxData(
}

public static String stripAccountAddress(String address) {
String newAddress = "";
return address;
// TODO(serg): Let's leave it for now as it could be we still
// want to show a short address
// String newAddress = "";

if (address.length() > 6) {
newAddress = address.substring(0, 6) + "***" + address.substring(address.length() - 5);
}
// if (address.length() > 6) {
// newAddress = address.substring(0, 6) + "***" + address.substring(address.length() -
// 5);
// }

return newAddress;
// return newAddress;
}

public static boolean isJSONValid(String text) {
Expand Down
15 changes: 14 additions & 1 deletion android/java/res/layout/fragment_sign_message.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@
tools:srcCompat="@drawable/ic_brave_logo" />
</com.google.android.material.card.MaterialCardView>

<TextView
android:id="@+id/domain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginBottom="16dp"
android:gravity="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/fragment_sign_msg_cv_account_image_container"
android:textColor="@color/wallet_text_color"
android:textSize="15sp" />

<TextView
android:id="@+id/fragment_sign_msg_tv_account_name"
android:layout_width="match_parent"
Expand All @@ -63,7 +76,7 @@
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/fragment_sign_msg_cv_account_image_container"
app:layout_constraintTop_toBottomOf="@id/domain"
tools:text="Ledger Nano" />

<TextView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public void numberArrayToHexStrTest() {
@SmallTest
public void stripAccountAddressTest() {
assertEquals(Utils.stripAccountAddress("0xdef1c0ded9bec7f1a1670819833240f027b25eff"),
"0xdef1***25eff");
"0xdef1c0ded9bec7f1a1670819833240f027b25eff");
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion browser/ui/android/strings/android_brave_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -2501,7 +2501,7 @@ If you don't accept this request, VPN will not reconnect and your internet conne
Apps
</message> -->
<message name="IDS_CRYPTO_WALLET_FROM_TO" desc="From address -> to address" translateable="false">
<ph name="FROM">%1$s<ex>0xabcd...</ex></ph> -> <ph name="TO">%2$s<ex>0xabcd...</ex></ph>
<ph name="FROM_NAME">%1$s<ex>Account1</ex></ph>\n <ph name="FROM_ADDRESS">%2$s<ex>0xabcd...</ex></ph> ->\n<ph name="TO">%3$s<ex>0xabcd...</ex></ph>
</message>
<message name="IDS_CRYPTO_WALLET_AMOUNT_ASSET" desc="Amount Asset" translateable="false">
<ph name="AMOUNT">%1$s<ex>0.0001</ex></ph> <ph name="ASSET">%2$s<ex>ETH</ex></ph>
Expand Down

0 comments on commit 04e65ff

Please sign in to comment.