Skip to content

Commit

Permalink
Fix some legacy code issues and tidy up wallet naming (#3371)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesSmartCell committed Mar 26, 2024
1 parent 3d728ed commit 0e760a3
Show file tree
Hide file tree
Showing 17 changed files with 286 additions and 203 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ android {
applicationId "io.stormbird.wallet"
minSdk 24
targetSdk 34
versionCode 259
versionCode 261
versionName "3.79"

android.buildFeatures.buildConfig true
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="com.google.android.gms.permission.AD_ID" tools:node="remove"/>

<uses-feature
android:name="android.hardware.fingerprint"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,13 @@ private void initViews() {
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home)
{
onBackPressed();
backPressed();
return true;
}
return super.onOptionsItemSelected(item);
}

@Override
public void onBackPressed() {
public void backPressed() {
Intent intent = new Intent();
setResult(RESULT_CANCELED, intent);
intent.putExtra("Key", wallet.address);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,15 +391,14 @@ public boolean onOptionsItemSelected(MenuItem item)
{
case android.R.id.home:
{
onBackPressed();
backPressed();
return true;
}
}
return super.onOptionsItemSelected(item);
}

@Override
public void onBackPressed()
private void backPressed()
{
switch (state)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,11 @@ private void setTokenListener()
realmTokenUpdates = realm.where(RealmToken.class).equalTo("address", dbKey)
.greaterThan("addedTime", System.currentTimeMillis() - 5 * DateUtils.MINUTE_IN_MILLIS).findAllAsync();
realmTokenUpdates.addChangeListener(realmTokens -> {
if (realmTokens.size() == 0) return;
if (realmTokens.isEmpty())
{
return;
}

for (RealmToken t : realmTokens)
{
TokenCardMeta meta = new TokenCardMeta(t.getChainId(), t.getTokenAddress(), t.getBalance(),
Expand Down Expand Up @@ -363,7 +367,6 @@ private void playNotification()
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
// getMenuInflater().inflate(R.menu.menu_show_contract, menu);
return super.onCreateOptionsMenu(menu);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,12 @@ public boolean onOptionsItemSelected(MenuItem item)
{
if (item.getItemId() == android.R.id.home)
{
onBackPressed();
backPressed();
}
return super.onOptionsItemSelected(item);
}

@Override
public void onBackPressed()
private void backPressed()
{
Intent result = new Intent();
GasSpeed gs = gasSpread.getSelectedGasFee(currentGasSpeedIndex);
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/alphawallet/app/ui/HomeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ public class HomeActivity extends BaseNavigationActivity implements View.OnClick
{
@Inject
AWWalletConnectClient awWalletConnectClient;

public static final int RC_ASSET_EXTERNAL_WRITE_PERM = 223;
public static final int RC_ASSET_NOTIFICATION_PERM = 224;
public static final int DAPP_BARCODE_READER_REQUEST_CODE = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ else if (item.getItemId() == R.id.action_node_status)
return false;
}

@Override
public void onBackPressed()
{
handleSetNetworks();
}

protected abstract void handleSetNetworks();

protected void initTestNetDialog(TestNetDialog.TestNetDialogCallback callback)
Expand Down
106 changes: 77 additions & 29 deletions app/src/main/java/com/alphawallet/app/ui/WalletActionsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,26 @@
import com.alphawallet.app.R;
import com.alphawallet.app.entity.BackupOperationType;
import com.alphawallet.app.entity.ErrorEnvelope;
import com.alphawallet.app.entity.StandardFunctionInterface;
import com.alphawallet.app.entity.Wallet;
import com.alphawallet.app.entity.WalletType;
import com.alphawallet.app.ui.widget.entity.AddressReadyCallback;
import com.alphawallet.app.util.Utils;
import com.alphawallet.app.viewmodel.WalletActionsViewModel;
import com.alphawallet.app.widget.AWalletAlertDialog;
import com.alphawallet.app.widget.FunctionButtonBar;
import com.alphawallet.app.widget.InputAddress;
import com.alphawallet.app.widget.InputView;
import com.alphawallet.app.widget.SettingsItemView;
import com.alphawallet.app.widget.UserAvatar;

import java.util.ArrayList;
import java.util.Collections;

import dagger.hilt.android.AndroidEntryPoint;

@AndroidEntryPoint
public class WalletActionsActivity extends BaseActivity implements Runnable, View.OnClickListener, AddressReadyCallback
public class WalletActionsActivity extends BaseActivity implements Runnable, View.OnClickListener, AddressReadyCallback, StandardFunctionInterface
{
WalletActionsViewModel viewModel;

Expand All @@ -55,12 +61,12 @@ public class WalletActionsActivity extends BaseActivity implements Runnable, Vie
private SettingsItemView deleteWalletSetting;
private SettingsItemView backUpSetting;
private InputAddress inputAddress;
private InputView inputName;
private LinearLayout successOverlay;
private AWalletAlertDialog aDialog;
private final Handler handler = new Handler();

private Wallet wallet;
private int walletCount;
private boolean isNewWallet;

@Override
Expand All @@ -70,10 +76,12 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
toolbar();
setTitle(getString(R.string.manage_wallet));

FunctionButtonBar functionBar = findViewById(R.id.layoutButtons);
functionBar.setupFunctions(this, new ArrayList<>(Collections.singletonList(R.string.action_save_name)));
functionBar.revealButtons();

if (getIntent() != null) {
wallet = (Wallet) getIntent().getExtras().get("wallet");
walletCount = getIntent().getIntExtra("walletCount", 0);
walletCount++;
isNewWallet = getIntent().getBooleanExtra("isNewWallet", false);
initViews();
} else {
Expand Down Expand Up @@ -106,13 +114,36 @@ private void initViewModel() {
viewModel.exportWalletError().observe(this, this::onExportError);
viewModel.deleted().observe(this, this::onDeleteWallet);
viewModel.isTaskRunning().observe(this, this::onTaskStatusChanged);
viewModel.walletCount().observe(this, this::setWalletName);
viewModel.ensName().observe(this, this::fetchedENSName);

if (isNewWallet) {
wallet.name = getString(R.string.wallet_name_template, walletCount);
viewModel.updateWallet(wallet);
if (isNewWallet)
{
viewModel.fetchWalletCount();
}

if (wallet != null && TextUtils.isEmpty(wallet.ENSname))
{
//scan for ENS name
viewModel.scanForENS(wallet, this);
}
}

private void fetchedENSName(String ensName)
{
if (!TextUtils.isEmpty(ensName))
{
inputAddress.setENSName(ensName);
}
}

private void setWalletName(int walletCount)
{
wallet.name = getString(R.string.wallet_name_template, walletCount + 1);
inputName.setText(wallet.name);
viewModel.updateWallet(wallet);
}

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
Expand All @@ -139,7 +170,11 @@ public boolean onOptionsItemSelected(MenuItem item)
{
if (item.getItemId() == android.R.id.home)
{
onBackPressed();
if (isNewWallet)
{
preFinish(); //drop back to home screen, no need to recreate everything
}
finish();
return true;
}
else if (item.getItemId() == R.id.action_key_status)
Expand All @@ -153,18 +188,10 @@ else if (item.getItemId() == R.id.action_key_status)
return super.onOptionsItemSelected(item);
}

@Override
public void onBackPressed()
private void onDeleteWallet(Boolean isDeleted)
{
super.onBackPressed();
if (isNewWallet)
if (isDeleted)
{
preFinish(); //drop back to home screen, no need to recreate everything
}
}

private void onDeleteWallet(Boolean isDeleted) {
if (isDeleted) {
showWalletsActivity();
}
}
Expand Down Expand Up @@ -193,7 +220,8 @@ private void onDeleteError(ErrorEnvelope errorEnvelope) {
aDialog.show();
}

private void initViews() {
private void initViews()
{
walletIcon = findViewById(R.id.wallet_icon);
walletBalance = findViewById(R.id.wallet_balance);
walletBalanceCurrency = findViewById(R.id.wallet_currency);
Expand All @@ -204,6 +232,7 @@ private void initViews() {
backUpSetting = findViewById(R.id.setting_backup);
walletSelectedIcon = findViewById(R.id.selected_wallet_indicator);
inputAddress = findViewById(R.id.input_ens);
inputName = findViewById(R.id.input_name);
walletSelectedIcon.setOnClickListener(this);

walletIcon.bind(wallet);
Expand All @@ -230,22 +259,43 @@ else if (wallet.type == WalletType.WATCH || wallet.type == WalletType.HARDWARE)
findViewById(R.id.layout_backup_method).setVisibility(View.GONE);
}

inputAddress.setAddress(wallet.ENSname);
inputAddress.setAddressCallback(this);
setupWalletNames();
}

private void setupWalletNames()
{
if (!TextUtils.isEmpty(wallet.ENSname))
{
inputAddress.setAddress(wallet.ENSname);
}

if (!Utils.isDefaultName(wallet.name, this))
{
inputName.setText(wallet.name);
}
}

private void setENSText()
{
if (wallet.ENSname != null && !wallet.ENSname.isEmpty()) {
if (!TextUtils.isEmpty(wallet.ENSname))
{
walletNameText.setText(wallet.ENSname);
walletNameText.setVisibility(View.VISIBLE);
walletAddressSeparator.setVisibility(View.VISIBLE);
} else {
}
else
{
walletNameText.setVisibility(View.GONE);
walletAddressSeparator.setVisibility(View.GONE);
}
}

@Override
public void handleClick(String action, int actionId)
{
saveWalletName();
}

private void onDeleteWalletSettingClicked() {
confirmDelete(wallet);
}
Expand All @@ -254,13 +304,11 @@ private void onBackUpSettingClicked() {
doBackUp();
}

private void saveWalletName() {
// wallet.name = walletNameText.getText().toString();
private void saveWalletName()
{
wallet.name = inputName.getText().toString();
viewModel.updateWallet(wallet);
if (isNewWallet) {
viewModel.showHome(this);
preFinish(); //drop back to home screen, no need to recreate everything
}
finish();
}

private void doBackUp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.os.Handler;
import android.os.Looper;
import android.util.Pair;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;
Expand Down Expand Up @@ -47,6 +48,7 @@
import dagger.hilt.android.AndroidEntryPoint;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import timber.log.Timber;
import wallet.core.jni.CoinType;
import wallet.core.jni.HDWallet;
import wallet.core.jni.PrivateKey;
Expand Down Expand Up @@ -151,13 +153,18 @@ private void startKeyDiagnostic()
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item)
{
if (item.getItemId() == android.R.id.home)
{
onBackPressed();
return true;
finish();
}

return super.onOptionsItemSelected(item);
Expand Down Expand Up @@ -402,7 +409,7 @@ private boolean testKeyType(String keyData)

private int wordCount(String value)
{
if (value == null || value.length() == 0) return 0;
if (value == null || value.isEmpty()) return 0;
String[] split = value.split("\\s+");
return split.length;
}
Expand All @@ -411,7 +418,7 @@ private int wordCount(String value)
// Always use the ActionSheet + implement ActionSheetCallback as per SendActivity, NFTAssetDetailActivity etc
private void doUnlock(UnlockCallback cb)
{
if (BuildConfig.DEBUG /*&& Utils.isRunningTest()*/) //running tests in debug build mode, we don't use key unlock
if (BuildConfig.DEBUG && Utils.isRunningTest()) //running tests in debug build mode, we don't use key unlock
{
cb.carryOn(true);
return;
Expand Down Expand Up @@ -455,7 +462,7 @@ private String dumpKeystoreFromSeedPhrase(String seedPhrase, String keystorePass
}
catch (Exception e)
{
e.printStackTrace();
Timber.e(e);
}

return "";
Expand Down
Loading

0 comments on commit 0e760a3

Please sign in to comment.