Adds a buy functionality to Android wallet
This commit is contained in:
+14
-7
@@ -44,6 +44,7 @@ import org.chromium.chrome.browser.crypto_wallet.fragments.ApproveTxBottomSheetD
|
||||
import org.chromium.chrome.browser.crypto_wallet.fragments.EditVisibleAssetsBottomSheetDialogFragment;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.Utils;
|
||||
import org.chromium.chrome.browser.init.AsyncInitializationActivity;
|
||||
import org.chromium.chrome.browser.util.TabUtils;
|
||||
import org.chromium.mojo.bindings.ConnectionErrorHandler;
|
||||
import org.chromium.mojo.system.MojoException;
|
||||
|
||||
@@ -354,19 +355,18 @@ public class BuySendSwapActivity extends AsyncInitializationActivity
|
||||
}
|
||||
|
||||
btnBuySendSwap.setOnClickListener(v -> {
|
||||
Spinner accountSpinner = findViewById(R.id.accounts_spinner);
|
||||
String from = mCustomAccountAdapter.getTitleAtPosition(
|
||||
accountSpinner.getSelectedItemPosition());
|
||||
TextView fromValueText = findViewById(R.id.from_value_text);
|
||||
// TODO(sergz): Some kind of validation that we have enough balance
|
||||
String value = fromValueText.getText().toString();
|
||||
if (mActivityType == ActivityType.SEND) {
|
||||
// TODO(sergz): token transfers via a token contract
|
||||
String to = toValueText.getText().toString();
|
||||
if (to.isEmpty()) {
|
||||
// TODO(sergz): some address validation
|
||||
return;
|
||||
}
|
||||
TextView fromValueText = findViewById(R.id.from_value_text);
|
||||
// TODO(sergz): Some kind of validation that we have enough balance
|
||||
String value = fromValueText.getText().toString();
|
||||
Spinner accountSpinner = findViewById(R.id.accounts_spinner);
|
||||
String from = mCustomAccountAdapter.getTitleAtPosition(
|
||||
accountSpinner.getSelectedItemPosition());
|
||||
if (mCurrentErcToken == null || mCurrentErcToken.contractAddress.isEmpty()) {
|
||||
TxData data =
|
||||
Utils.getTxData("0x1", "", "", to, Utils.toHexWei(value), new byte[0]);
|
||||
@@ -375,6 +375,13 @@ public class BuySendSwapActivity extends AsyncInitializationActivity
|
||||
addUnapprovedTransactionERC20(
|
||||
to, Utils.toHexWei(value), from, mCurrentErcToken.contractAddress);
|
||||
}
|
||||
} else if (mActivityType == ActivityType.BUY) {
|
||||
assert mErcTokenRegistry != null;
|
||||
String asset = assetDropDown.getText().toString();
|
||||
mErcTokenRegistry.getBuyUrl(from, asset, value, url -> {
|
||||
TabUtils.openUrlInNewTab(false, url);
|
||||
TabUtils.bringChromeTabbedActivityToTheTop(this);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ package org.chromium.chrome.browser.util;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
@@ -17,6 +18,7 @@ import android.widget.PopupMenu;
|
||||
|
||||
import org.chromium.base.ApplicationStatus;
|
||||
import org.chromium.chrome.R;
|
||||
import org.chromium.chrome.browser.ChromeTabbedActivity;
|
||||
import org.chromium.chrome.browser.app.BraveActivity;
|
||||
import org.chromium.chrome.browser.app.ChromeActivity;
|
||||
import org.chromium.chrome.browser.night_mode.GlobalNightModeStateProviderHolder;
|
||||
@@ -97,4 +99,10 @@ public class TabUtils {
|
||||
}
|
||||
rewardsLayout.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
public static void bringChromeTabbedActivityToTheTop(Activity activity) {
|
||||
Intent braveActivityIntent = new Intent(activity, ChromeTabbedActivity.class);
|
||||
braveActivityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
activity.startActivity(braveActivityIntent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,10 @@ static base::NoDestructor<std::vector<mojom::ERCToken>> kBuyTokens(
|
||||
|
||||
const char kWalletBaseDirectory[] = "BraveWallet";
|
||||
const char kImageSourceHost[] = "erc-token-images";
|
||||
const char kWyreID[] = "AC_MGNVBGHPA9T";
|
||||
const char kBuyUrl[] =
|
||||
"https://pay.sendwyre.com/?dest=ethereum:%s"
|
||||
"&destCurrency=%s&amount=%s&accountId=%s&paymentMethod=debit-card";
|
||||
|
||||
} // namespace brave_wallet
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "brave/components/brave_wallet/browser/brave_wallet_constants.h"
|
||||
|
||||
namespace brave_wallet {
|
||||
@@ -87,4 +88,14 @@ void ERCTokenRegistry::GetBuyTokens(GetBuyTokensCallback callback) {
|
||||
std::move(callback).Run(std::move(erc_buy_tokens));
|
||||
}
|
||||
|
||||
void ERCTokenRegistry::GetBuyUrl(const std::string& address,
|
||||
const std::string& symbol,
|
||||
const std::string& amount,
|
||||
GetBuyUrlCallback callback) {
|
||||
std::string url = base::StringPrintf(kBuyUrl, address.c_str(), symbol.c_str(),
|
||||
amount.c_str(), kWyreID);
|
||||
|
||||
std::move(callback).Run(url);
|
||||
}
|
||||
|
||||
} // namespace brave_wallet
|
||||
|
||||
@@ -38,6 +38,10 @@ class ERCTokenRegistry : public mojom::ERCTokenRegistry {
|
||||
GetTokenBySymbolCallback callback) override;
|
||||
void GetAllTokens(GetAllTokensCallback callback) override;
|
||||
void GetBuyTokens(GetBuyTokensCallback callback) override;
|
||||
void GetBuyUrl(const std::string& address,
|
||||
const std::string& symbol,
|
||||
const std::string& amount,
|
||||
GetBuyUrlCallback callback) override;
|
||||
|
||||
protected:
|
||||
std::vector<mojom::ERCTokenPtr> erc_tokens_;
|
||||
|
||||
@@ -200,6 +200,7 @@ interface ERCTokenRegistry {
|
||||
GetTokenBySymbol(string symbol) => (ERCToken? token);
|
||||
GetAllTokens() => (array<ERCToken> tokens);
|
||||
GetBuyTokens() => (array<ERCToken> tokens);
|
||||
GetBuyUrl(string address, string symbol, string amount) => (string url);
|
||||
};
|
||||
|
||||
interface KeyringController {
|
||||
|
||||
Reference in New Issue
Block a user