Skip to content

Commit

Permalink
[Tech Debt] Remove stale api server code and add switch for dev mode -
Browse files Browse the repository at this point in the history
  • Loading branch information
vsima committed Jan 15, 2023
1 parent 451fff8 commit 332315e
Show file tree
Hide file tree
Showing 12 changed files with 206 additions and 90 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ android {
archivesBaseName = "${versionName}(${versionCode})"

buildConfigField "String", "INFURA_KEY", "\"set the infura key here\""
buildConfigField "String", "LITEWALLET_API_URL_PROD", "\"https://api-prod.lite-wallet.org\""
buildConfigField "String", "LITEWALLET_API_URL_DEV", "\"https://api-dev.lite-wallet.org\""


// Similar to other properties in the defaultConfig block,
// you can configure the ndk block for each product flavor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
package com.breadwallet.presenter.activities.settings;

import static com.breadwallet.BuildConfig.LITEWALLET_API_URL_DEV;
import static com.breadwallet.R.layout.settings_list_item;
import static com.breadwallet.R.layout.settings_list_section;
import static com.breadwallet.R.layout.settings_list_switch;
import static com.breadwallet.presenter.entities.BRSettingsItem.SettingItemsType.ADDON;
import static com.breadwallet.presenter.entities.BRSettingsItem.SettingItemsType.SECTION;
import static com.breadwallet.presenter.entities.BRSettingsItem.SettingItemsType.SWITCH;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.SwitchCompat;

import com.breadwallet.R;
import com.breadwallet.presenter.activities.util.BRActivity;
import com.breadwallet.presenter.entities.BRSettingsItem;
import com.breadwallet.tools.manager.BRSharedPrefs;

import java.util.ArrayList;
import java.util.List;

import static com.breadwallet.R.layout.settings_list_item;
import static com.breadwallet.R.layout.settings_list_section;

public class AdvancedActivity extends BRActivity {
private static final String TAG = AdvancedActivity.class.getName();
private ListView listView;
Expand All @@ -41,10 +49,8 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_advanced);

listView = (ListView) findViewById(R.id.settings_list);

}


public class SettingsListAdapter extends ArrayAdapter<String> {

private List<BRSettingsItem> items;
Expand All @@ -64,19 +70,30 @@ public View getView(int position, @Nullable View convertView, @NonNull ViewGroup
BRSettingsItem item = items.get(position);
LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();

if (item.isSection) {
v = inflater.inflate(settings_list_section, parent, false);
} else {
v = inflater.inflate(settings_list_item, parent, false);
TextView addon = (TextView) v.findViewById(R.id.item_addon);
addon.setText(item.addonText);
v.setOnClickListener(item.listener);
switch (item.type) {
case SECTION:
v = inflater.inflate(settings_list_section, parent, false);
v.setOnClickListener(item.listener);
break;
case SWITCH:
v = inflater.inflate(settings_list_switch, parent, false);
View switchView = v.findViewById(R.id.item_switch);
if (switchView instanceof SwitchCompat) {
((SwitchCompat) switchView).setChecked(item.isChecked);
switchView.setOnClickListener(item.listener);
}
break;
default:
v = inflater.inflate(settings_list_item, parent, false);
TextView addon = (TextView) v.findViewById(R.id.item_addon);
addon.setText(item.addonText);
v.setOnClickListener(item.listener);
break;
}

TextView title = (TextView) v.findViewById(R.id.item_title);
title.setText(item.title);
return v;

}

@Override
Expand Down Expand Up @@ -113,21 +130,24 @@ public void onBackPressed() {

private void populateItems() {

items.add(new BRSettingsItem("", "", null, true));

items.add(new BRSettingsItem(getString(R.string.NodeSelector_title), "", new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(AdvancedActivity.this, NodesActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.enter_from_right, R.anim.empty_300);

}
}, false));
}

@Override
protected void onSaveInstanceState(Bundle outState) {
items.add(new BRSettingsItem(SECTION, null, null, null, null));

items.add(new BRSettingsItem(ADDON, getString(R.string.NodeSelector_title), "", null, v -> {
Intent intent = new Intent(AdvancedActivity.this, NodesActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.enter_from_right, R.anim.empty_300);
}));

items.add(new BRSettingsItem(SWITCH, getString(R.string.DeveloperMode_title), "",
BRSharedPrefs.getApiServerMode(getApplicationContext()) == LITEWALLET_API_URL_DEV, v -> {
if (v instanceof SwitchCompat) {
if (((SwitchCompat) v).isChecked()) {
BRSharedPrefs.setApiServerMode(v.getContext(), BRSharedPrefs.PrefsServerMode.DEV);
} else {
BRSharedPrefs.setApiServerMode(v.getContext(), BRSharedPrefs.PrefsServerMode.PROD);
}
}
}));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package com.breadwallet.presenter.activities.settings;

import static com.breadwallet.R.layout.settings_list_item;
import static com.breadwallet.R.layout.settings_list_section;
import static com.breadwallet.R.layout.settings_list_switch;
import static com.breadwallet.presenter.entities.BRSettingsItem.SettingItemsType.ADDON;
import static com.breadwallet.presenter.entities.BRSettingsItem.SettingItemsType.SECTION;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
Expand All @@ -16,20 +22,16 @@
import androidx.annotation.Nullable;

import com.breadwallet.R;
import com.breadwallet.presenter.language.ChangeLanguageBottomSheet;
import com.breadwallet.presenter.activities.util.BRActivity;
import com.breadwallet.presenter.entities.BRSettingsItem;
import com.breadwallet.presenter.interfaces.BRAuthCompletion;
import com.breadwallet.presenter.language.ChangeLanguageBottomSheet;
import com.breadwallet.tools.manager.BRSharedPrefs;
import com.breadwallet.tools.security.AuthManager;
import com.platform.APIClient;

import java.util.ArrayList;
import java.util.List;

import static com.breadwallet.R.layout.settings_list_item;
import static com.breadwallet.R.layout.settings_list_section;

public class SettingsActivity extends BRActivity {
private ListView listView;
public List<BRSettingsItem> items;
Expand Down Expand Up @@ -67,19 +69,32 @@ public View getView(int position, @Nullable View convertView, @NonNull ViewGroup
BRSettingsItem item = items.get(position);
LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();

if (item.isSection) {
v = inflater.inflate(settings_list_section, parent, false);
} else {
v = inflater.inflate(settings_list_item, parent, false);
TextView addon = (TextView) v.findViewById(R.id.item_addon);
addon.setText(item.addonText);
v.setOnClickListener(item.listener);

switch (item.type) {
case SECTION:
v = inflater.inflate(settings_list_section, parent, false);
v.setOnClickListener(item.listener);
break;
case SWITCH:
v = inflater.inflate(settings_list_switch, parent, false);
if (item.isChecked) {
View switchView = v.findViewById(R.id.button_switch);
if (switchView != null) {
switchView.setOnClickListener(item.listener);
}
}
break;
default:
v = inflater.inflate(settings_list_item, parent, false);
TextView addon = (TextView) v.findViewById(R.id.item_addon);
addon.setText(item.addonText);
v.setOnClickListener(item.listener);
break;
}

TextView title = (TextView) v.findViewById(R.id.item_title);
title.setText(item.title);
return v;

}

@Override
Expand Down Expand Up @@ -116,29 +131,29 @@ public void onBackPressed() {
private void populateItems() {

/*Wallet Title*/
items.add(new BRSettingsItem(getString(R.string.Settings_wallet), "", null, true));
items.add(new BRSettingsItem(SECTION, getString(R.string.Settings_wallet), "", null, null));

/*Import Title*/
items.add(new BRSettingsItem(getString(R.string.Settings_importTitle), "", v -> {
items.add(new BRSettingsItem(ADDON, getString(R.string.Settings_importTitle), "", null, v -> {
Intent intent = new Intent(SettingsActivity.this, ImportActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.enter_from_bottom, R.anim.empty_300);

}, false));
}));

/*Wipe Start_Recover Wallet*/
items.add(new BRSettingsItem(getString(R.string.Settings_wipe), "", v -> {
items.add(new BRSettingsItem(ADDON, getString(R.string.Settings_wipe), "", null, v -> {
Intent intent = new Intent(SettingsActivity.this, WipeActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.enter_from_bottom, R.anim.empty_300);
}, false));
}));

/*Manage Title*/
items.add(new BRSettingsItem(getString(R.string.Settings_manage), "", null, true));
items.add(new BRSettingsItem(SECTION, getString(R.string.Settings_manage), "", null, null));

/*Fingerprint Limits*/
if (AuthManager.isFingerPrintAvailableAndSetup(this)) {
items.add(new BRSettingsItem(getString(R.string.Settings_touchIdLimit_android), "", v -> AuthManager.getInstance().authPrompt(SettingsActivity.this, null, getString(R.string.VerifyPin_continueBody), true, false, new BRAuthCompletion() {
items.add(new BRSettingsItem(ADDON, getString(R.string.Settings_touchIdLimit_android), "", null, v -> AuthManager.getInstance().authPrompt(SettingsActivity.this, null, getString(R.string.VerifyPin_continueBody), true, false, new BRAuthCompletion() {
@Override
public void onComplete() {
Intent intent = new Intent(SettingsActivity.this, SpendLimitActivity.class);
Expand All @@ -150,58 +165,58 @@ public void onComplete() {
public void onCancel() {

}
}), false));
})));
}

/*Languages*/
items.add(new BRSettingsItem(getString(R.string.Settings_languages), null, v -> {
items.add(new BRSettingsItem(ADDON, getString(R.string.Settings_languages), null, null, v -> {
ChangeLanguageBottomSheet fragment = new ChangeLanguageBottomSheet();
fragment.show(getSupportFragmentManager(), fragment.getTag());
}, false));
}));

/*Display Currency*/
items.add(new BRSettingsItem(getString(R.string.Settings_currency), BRSharedPrefs.getIso(this), v -> {
items.add(new BRSettingsItem(ADDON, getString(R.string.Settings_currency), BRSharedPrefs.getIso(this), null, v -> {
Intent intent = new Intent(SettingsActivity.this, DisplayCurrencyActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.enter_from_right, R.anim.exit_to_left);
}, false));
}));

/*Sync Blockchain*/
items.add(new BRSettingsItem(getString(R.string.Settings_sync), "", v -> {
items.add(new BRSettingsItem(ADDON, getString(R.string.Settings_sync), "", null, v -> {
Intent intent = new Intent(SettingsActivity.this, SyncBlockchainActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.enter_from_right, R.anim.exit_to_left);
}, false));
}));

/*SPACER*/
items.add(new BRSettingsItem("", "", null, true));
items.add(new BRSettingsItem(SECTION, "", "", null, null));

/*Share Anonymous Data*/
items.add(new BRSettingsItem(getString(R.string.Settings_shareData), "", v -> {
items.add(new BRSettingsItem(ADDON, getString(R.string.Settings_shareData), "", null, v -> {
Intent intent = new Intent(SettingsActivity.this, ShareDataActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.enter_from_right, R.anim.exit_to_left);
}, false));
}));

/*About*/
items.add(new BRSettingsItem(getString(R.string.Settings_about), "", v -> {
items.add(new BRSettingsItem(ADDON, getString(R.string.Settings_about), "", null, v -> {
Intent intent = new Intent(SettingsActivity.this, AboutActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.enter_from_right, R.anim.exit_to_left);
}, false));
}));

/*SPACER*/
items.add(new BRSettingsItem("", "", null, true));
items.add(new BRSettingsItem(SECTION, "", "", null, null));

/*Advanced Settings*/
items.add(new BRSettingsItem(getString(R.string.Settings_advancedTitle), "", v -> {
items.add(new BRSettingsItem(ADDON, getString(R.string.Settings_advancedTitle), "", null, v -> {
Intent intent = new Intent(SettingsActivity.this, AdvancedActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.enter_from_right, R.anim.exit_to_left);
}, false));
}));

/*SPACER*/
items.add(new BRSettingsItem("", "", null, true));
items.add(new BRSettingsItem(SECTION, "", "", null, null));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@

public class BRSettingsItem {

public boolean isSection;
public enum SettingItemsType {
SECTION, ADDON, SWITCH
}

public SettingItemsType type;
public String title;
public String addonText;
public Boolean isChecked;
public View.OnClickListener listener;

public BRSettingsItem(String title, String addonText, View.OnClickListener listener, boolean isSection) {
public BRSettingsItem(SettingItemsType type, String title, String addonText, Boolean isChecked, View.OnClickListener listener) {
this.type = type;
this.title = title;
this.addonText = addonText;
this.isChecked = isChecked;
this.listener = listener;
this.isSection = isSection;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public class FragmentBuy extends Fragment {
private ProgressBar progress;
private WebView webView;
private String onCloseUrl;
private static final String URL_BUY_LTC = BuildConfig.DEBUG ? "https://api-stage.lite-wallet.org" : "https://api-prod.lite-wallet.org";
private static final String CURRENCY_KEY = "currency_code_key";
private static final String PARTNER_KEY = "partner_key";
private ValueCallback<Uri> uploadMessage;
Expand Down Expand Up @@ -109,12 +108,12 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
}


public static String url(Context context, Partner partner, String currency) {
public static String url(Context context, Partner partner, String currency) {
String walletAddress = BRSharedPrefs.getReceiveAddress(context);
Long timestamp = new Date().getTime();
String uuid = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
String prefix = partner == Partner.MOONPAY ? "/moonpay/buy" : "";
return String.format(URL_BUY_LTC + prefix + "?address=%s&code=%s&idate=%s&uid=%s", walletAddress, currency, timestamp, uuid);
return String.format(BRSharedPrefs.getApiServerMode(context) + prefix + "?address=%s&code=%s&idate=%s&uid=%s", walletAddress, currency, timestamp, uuid);
}

private void closePayment() {
Expand Down
Loading

0 comments on commit 332315e

Please sign in to comment.