Skip to content

Commit

Permalink
Localizing binance.com buy URL (Android widget)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanml committed Jan 20, 2021
1 parent 3b5fdd7 commit 2c3ba99
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,11 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
public void onClick(View view) {
String buyUrl = "";
if (buyRadioGroup.getCheckedRadioButtonId() == R.id.com_radio) {
buyUrl = String.format(BinanceWidgetManager.BINANCE_COM, selectedFiat,
selectedCrypto, amountEditText.getText());
String localizedUrl = BinanceWidgetManager.BINANCE_COM_ONE
+ mBinanceNativeWorker.getLocaleForURL()
+ BinanceWidgetManager.BINANCE_COM_TWO;
buyUrl = String.format(localizedUrl, selectedFiat, selectedCrypto,
amountEditText.getText());
} else if (buyRadioGroup.getCheckedRadioButtonId() == R.id.us_radio) {
buyUrl = String.format(BinanceWidgetManager.BINANCE_US, selectedCrypto,
amountEditText.getText());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public boolean IsSupportedRegion() {
}
}

public String getLocaleForURL() {
return nativeGetLocaleForURL(mNativeBinanceNativeWorker);
}

@CalledByNative
private void setNativePtr(long nativePtr) {
assert mNativeBinanceNativeWorker == 0;
Expand Down Expand Up @@ -182,6 +186,7 @@ public void revokeToken() {
private native String nativeGetOAuthClientUrl(long nativeBinanceNativeWorker);
private native void nativeGetAccessToken(long nativeBinanceNativeWorker);
private native boolean nativeIsSupportedRegion(long nativeBinanceNativeWorker);
private native String nativeGetLocaleForURL(long nativeBinanceNativeWorker);
private native void nativeSetAuthToken(long nativeBinanceNativeWorker, String authToken);
private native void nativeGetAccountBalances(long nativeBinanceNativeWorker);
private native void nativeGetConvertQuote(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ public class BinanceWidgetManager {

public static final String BINANCE_US =
"https://www.binance.us/en/buy-sell-crypto?crypto=%1$s&amount=%2$s&ref=35089877&utm_source=brave";
public static final String BINANCE_COM =
"https://www.binance.com/en/buy-sell-crypto?fiat=%1$s&crypto=%2$s&amount=%3$s&ref=W4GYNUAJ&utm_source=brave";
public static final String BINANCE_COM_ONE = "https://www.binance.com/";
public static final String BINANCE_COM_TWO =
"/buy-sell-crypto?fiat=%1$s&crypto=%2$s&amount=%3$s&ref=W4GYNUAJ&utm_source=brave";

private static BinanceWidgetManager sInstance;

Expand Down
14 changes: 14 additions & 0 deletions browser/binance/android/binance_native_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@ bool BinanceNativeWorker::IsSupportedRegion(JNIEnv* env,
return binance_service_->IsSupportedRegion();
}

base::android::ScopedJavaLocalRef<jstring> BinanceNativeWorker::GetLocaleForURL(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller) {
base::android::ScopedJavaLocalRef<jstring> locale =
base::android::ConvertUTF8ToJavaString(env, "");

if (binance_service_) {
locale = base::android::ConvertUTF8ToJavaString(
env, binance_service_->GetLocaleForURL());
}

return locale;
}

void BinanceNativeWorker::OnGetAccessToken(bool success) {
JNIEnv* env = base::android::AttachCurrentThread();
Java_BinanceNativeWorker_OnGetAccessToken(
Expand Down
4 changes: 4 additions & 0 deletions browser/binance/android/binance_native_worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class BinanceNativeWorker {
bool IsSupportedRegion(JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller);

base::android::ScopedJavaLocalRef<jstring> GetLocaleForURL(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller);

void OnGetAccessToken(bool success);

void GetAccountBalances(JNIEnv* env,
Expand Down

0 comments on commit 2c3ba99

Please sign in to comment.