-
Notifications
You must be signed in to change notification settings - Fork 894
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
Wallet address resolution for Android #16423
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,7 @@ | |
import com.google.android.gms.vision.barcode.BarcodeDetector; | ||
import com.google.android.material.dialog.MaterialAlertDialogBuilder; | ||
|
||
import org.chromium.base.BraveFeatureList; | ||
import org.chromium.base.Log; | ||
import org.chromium.brave_wallet.mojom.AccountInfo; | ||
import org.chromium.brave_wallet.mojom.BlockchainToken; | ||
|
@@ -83,7 +84,9 @@ | |
import org.chromium.chrome.browser.crypto_wallet.util.TokenUtils; | ||
import org.chromium.chrome.browser.crypto_wallet.util.Utils; | ||
import org.chromium.chrome.browser.crypto_wallet.util.Validations; | ||
import org.chromium.chrome.browser.crypto_wallet.util.WalletNativeUtils; | ||
import org.chromium.chrome.browser.crypto_wallet.util.WalletUtils; | ||
import org.chromium.chrome.browser.flags.ChromeFeatureList; | ||
import org.chromium.chrome.browser.qrreader.BarcodeTracker; | ||
import org.chromium.chrome.browser.qrreader.BarcodeTrackerFactory; | ||
import org.chromium.chrome.browser.qrreader.CameraSource; | ||
|
@@ -169,6 +172,7 @@ public int getValue() { | |
private EditText mFromValueText; | ||
private EditText mToValueText; | ||
private EditText mSendToAddrText; | ||
private TextView mResolvedAddrText; | ||
private TextView mMarketPriceValueText; | ||
private TextView mFromBalanceText; | ||
private TextView mToBalanceText; | ||
|
@@ -759,6 +763,8 @@ private void adjustControls() { | |
toleranceSection.setVisibility(View.GONE); | ||
} | ||
|
||
mResolvedAddrText = findViewById(R.id.resolved_addr_text); | ||
|
||
// Individual | ||
if (mActivityType == ActivityType.BUY) { | ||
TextView fromBuyText = findViewById(R.id.from_buy_text); | ||
|
@@ -919,6 +925,10 @@ public void onTextChanged(CharSequence s, int start, int before, int count) { | |
String value = mFromValueText.getText().toString(); | ||
if (mActivityType == ActivityType.SEND) { | ||
String to = mSendToAddrText.getText().toString(); | ||
if (!mResolvedAddrText.getText().toString().isEmpty()) { | ||
to = mResolvedAddrText.getText().toString(); | ||
} | ||
|
||
if (to.isEmpty()) { | ||
return; | ||
} | ||
|
@@ -1176,6 +1186,59 @@ public void onBackPressed() { | |
super.onBackPressed(); | ||
} | ||
|
||
private void onResolveWalletAddressDone(String domain, String result) { | ||
if (!domain.equals(mSendToAddrText.getText().toString())) { | ||
return; | ||
} | ||
|
||
if (result == null || result.isEmpty()) { | ||
mResolvedAddrText.setVisibility(View.GONE); | ||
mResolvedAddrText.setText(""); | ||
String notRegisteredErrorText = String.format( | ||
getString(R.string.wallet_domain_not_registered_error_text), domain); | ||
|
||
setSendToFromValueValidationResult(notRegisteredErrorText, true, true); | ||
} else { | ||
mResolvedAddrText.setVisibility(View.VISIBLE); | ||
mResolvedAddrText.setText(result); | ||
setSendToFromValueValidationResult("", false, true); | ||
} | ||
} | ||
|
||
private boolean maybeResolveWalletAddress() { | ||
String domain = mSendToAddrText.getText().toString(); | ||
|
||
if (WalletNativeUtils.isUnstoppableDomainsTld(domain)) { | ||
mJsonRpcService.unstoppableDomainsGetWalletAddr( | ||
domain, mCurrentBlockchainToken, (response, errorResponse, errorString) -> { | ||
onResolveWalletAddressDone(domain, response); | ||
}); | ||
return true; | ||
} | ||
|
||
if (mCurrentBlockchainToken.coin == CoinType.ETH && WalletNativeUtils.isEnsTld(domain)) { | ||
mJsonRpcService.ensGetEthAddr(domain, null, | ||
(response, requireOffchainConsent, errorResponse, errorString) -> { | ||
onResolveWalletAddressDone(domain, response); | ||
}); | ||
return true; | ||
} | ||
|
||
if (ChromeFeatureList.isEnabled(BraveFeatureList.BRAVE_WALLET_SNS)) { | ||
if (mCurrentBlockchainToken.coin == CoinType.SOL | ||
&& WalletNativeUtils.isSnsTld(domain)) { | ||
mJsonRpcService.snsGetSolAddr(domain, (response, errorResponse, errorString) -> { | ||
onResolveWalletAddressDone(domain, response); | ||
}); | ||
return true; | ||
} | ||
} | ||
|
||
mResolvedAddrText.setVisibility(View.GONE); | ||
mResolvedAddrText.setText(""); | ||
return false; | ||
} | ||
Comment on lines
+1211
to
+1240
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eventually will be refactored to a single mojo call brave/brave-browser#26655 |
||
|
||
private TextWatcher getTextWatcherFromToValueText(boolean from) { | ||
return new FilterTextFromToValueText(from); | ||
} | ||
|
@@ -1210,6 +1273,8 @@ public FilterTextWatcherSendToAddr() { | |
|
||
@Override | ||
public void onTextChanged(CharSequence s, int start, int before, int count) { | ||
if (maybeResolveWalletAddress()) return; | ||
|
||
String fromAccountAddress = mCustomAccountAdapter.getAccountAddressAtPosition( | ||
mAccountSpinner.getSelectedItemPosition()); | ||
|
||
|
@@ -1237,6 +1302,8 @@ public OnFocusChangeListenerToSend() { | |
@Override | ||
public void onFocusChange(View v, boolean hasFocus) { | ||
if (hasFocus) { | ||
if (maybeResolveWalletAddress()) return; | ||
|
||
String fromAccountAddress = mCustomAccountAdapter.getAccountAddressAtPosition( | ||
mAccountSpinner.getSelectedItemPosition()); | ||
String receiverAccountAddress = ((EditText) v).getText().toString(); | ||
|
@@ -1459,6 +1526,10 @@ token.symbol, getResources().getDisplayMetrics().density, assetText, this, true, | |
enableDisableSwapButton(); | ||
getSendSwapQuota(true, false); | ||
} | ||
|
||
if (mActivityType == ActivityType.SEND) { | ||
maybeResolveWalletAddress(); | ||
} | ||
} | ||
|
||
private void enableDisableSwapButton() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could be combined to a single
if
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is supposed to be a temporary feature and to be removed as soon as our backend is ready. While inner if block matches pattern above