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
- Upgrade to v3.79
  • Loading branch information
JamesSmartCell committed Mar 26, 2024
1 parent d887ad2 commit 2f1161a
Show file tree
Hide file tree
Showing 18 changed files with 290 additions and 224 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ android {
applicationId "io.stormbird.wallet"
minSdk 24
targetSdk 34
versionCode 257
versionName "3.78"
versionCode 261
versionName "3.79"

android.buildFeatures.buildConfig true

Expand Down
11 changes: 2 additions & 9 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +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="android.permission.FOREGROUND_SERVICE_CONNECTED_DEVICE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="com.google.android.gms.permission.AD_ID" tools:node="remove"/>

<uses-feature
android:name="android.hardware.fingerprint"
Expand Down Expand Up @@ -125,8 +124,7 @@
<service
android:name=".service.WalletConnectV2Service"
android:enabled="true"
android:exported="false"
android:foregroundServiceType="connectedDevice">
android:exported="false">
</service>

<service
Expand Down Expand Up @@ -282,11 +280,6 @@
android:name=".ui.TokenScriptManagementActivity"
android:label="@string/tokenscript_management" />

<activity
android:name=".ui.WalletConnectActivity"
android:label="WalletConnect"
android:launchMode="singleTop" />

<activity
android:name=".ui.BackupFlowActivity"
android:label="WalletConnect" />
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 @@ -131,6 +131,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState)
initIntents();

initViewModel();

usingNativeTokenScript = !viewModel.getUseTSViewer();
}

private void initIntents()
Expand Down Expand Up @@ -308,12 +310,6 @@ private void setup()
setTitle(token.tokenInfo.name);
updateDefaultTokenData();

if (!viewModel.getUseTSViewer())
{
TokenDefinition td = viewModel.getAssetDefinitionService().getAssetDefinition(this.token);
this.usingNativeTokenScript = (td != null && td.nameSpace != null);
}

if (asset != null && asset.isAttestation())
{
setupAttestation(viewModel.getAssetDefinitionService().getAssetDefinition(token));
Expand Down Expand Up @@ -356,11 +352,6 @@ private void newScriptFound(TokenDefinition td)

setTitle(token.getTokenName(viewModel.getAssetDefinitionService(), 1));

if (!viewModel.getUseTSViewer())
{
this.usingNativeTokenScript = td.nameSpace != null;
}

//now re-load the verbs if already called. If wallet is null this won't complete
setupFunctionBar(viewModel.getWallet());

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
Loading

0 comments on commit 2f1161a

Please sign in to comment.