Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions app/src/main/java/com/alphawallet/app/entity/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
import com.alphawallet.app.service.KeyService;
import com.alphawallet.app.util.BalanceUtils;

import org.web3j.utils.Strings;

import java.math.BigDecimal;

public class Wallet implements Parcelable {
public final String address;
public String balance;
public String ENSname;
public String name;
private String ENSname;
private String name;
public WalletType type;
public long lastBackupTime;
public KeyService.AuthenticationLevel authLevel;
Expand Down Expand Up @@ -110,4 +112,33 @@ public void zeroWalletBalance(NetworkInfo networkInfo)
balance = BalanceUtils.getScaledValueFixed(BigDecimal.ZERO, 0, Token.TOKEN_BALANCE_PRECISION);
}
}

public void setName(String name)
{
this.name = name;
}

public void setEnsName(String name)
{
this.ENSname = name;
}

public String getName()
{
return name;
}

public String getENSName()
{
return ENSname;
}

public String getDisplayName()
{
if (!Strings.isEmpty(name))
{
return name;
}
return ENSname;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public Single<Wallet> storeHDWallet(String walletAddress, KeyService.Authenticat
wallet.lastBackupTime = System.currentTimeMillis();
return ensResolver.resolveEnsName(wallet.address)
.subscribeOn(Schedulers.io())
.map(name -> { wallet.ENSname = name; return wallet; })
.map(name -> { wallet.setEnsName(name); return wallet; })
.flatMap(walletRepository::storeWallet);
}

Expand All @@ -49,7 +49,7 @@ public Single<Wallet> storeWatchWallet(String address, AWEnsResolver ensResolver
wallet.lastBackupTime = System.currentTimeMillis();
return ensResolver.resolveEnsName(wallet.address)
.subscribeOn(Schedulers.io())
.map(name -> { wallet.ENSname = name; return wallet; })
.map(name -> { wallet.setEnsName(name); return wallet; })
.flatMap(walletRepository::storeWallet);
}

Expand All @@ -60,7 +60,7 @@ public Single<Wallet> storeKeystoreWallet(Wallet wallet, KeyService.Authenticati
wallet.lastBackupTime = System.currentTimeMillis();
return ensResolver.resolveEnsName(wallet.address)
.subscribeOn(Schedulers.io())
.map(name -> { wallet.ENSname = name; return wallet; })
.map(name -> { wallet.setEnsName(name); return wallet; })
.flatMap(walletRepository::storeWallet);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ private void composeWallet(Wallet wallet, RealmWalletData d)
{
if (d != null)
{
wallet.ENSname = d.getENSName();
wallet.setEnsName(d.getENSName());
wallet.balance = balance(d);
wallet.name = d.getName();
wallet.setName(d.getName());
}
}

Expand Down Expand Up @@ -185,9 +185,9 @@ private String balance(RealmWalletData data)

private Wallet convertWallet(RealmWalletData data) {
Wallet wallet = new Wallet(data.getAddress());
wallet.ENSname = data.getENSName();
wallet.setEnsName(data.getENSName());
wallet.balance = data.getBalance();
wallet.name = data.getName();
wallet.setName(data.getName());
return wallet;
}

Expand All @@ -203,15 +203,15 @@ public Single<Wallet[]> storeWallets(Wallet[] wallets) {

if (realmWallet == null) {
realmWallet = realm.createObject(RealmWalletData.class, wallet.address);
realmWallet.setENSName(wallet.ENSname);
realmWallet.setENSName(wallet.getENSName());
realmWallet.setBalance(wallet.balance);
realmWallet.setName(wallet.name);
realmWallet.setName(wallet.getName());
} else {
if (realmWallet.getBalance() == null || !wallet.balance.equals(realmWallet.getENSName()))
realmWallet.setBalance(wallet.balance);
if (wallet.ENSname != null && (realmWallet.getENSName() == null || !wallet.ENSname.equals(realmWallet.getENSName())))
realmWallet.setENSName(wallet.ENSname);
realmWallet.setName(wallet.name);
if (wallet.getENSName() != null && (realmWallet.getENSName() == null || !wallet.getENSName().equals(realmWallet.getENSName())))
realmWallet.setENSName(wallet.getENSName());
realmWallet.setName(wallet.getName());
}
}
realm.commitTransaction();
Expand Down Expand Up @@ -420,8 +420,8 @@ private void storeWalletData(Wallet wallet)
.equalTo("address", wallet.address)
.findFirst();
if (item == null) item = realm.createObject(RealmWalletData.class, wallet.address);
item.setName(wallet.name);
item.setENSName(wallet.ENSname);
item.setName(wallet.getName());
item.setENSName(wallet.getENSName());
item.setBalance(wallet.balance);
realm.insertOrUpdate(item);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ private void showAddress()
}
copyAddress.setVisibility(View.VISIBLE);
onWindowFocusChanged(true);
updateAddressWithENS(wallet.ENSname); //JB: see if there's any cached value to display while we wait for ENS
updateAddressWithENS(wallet.getDisplayName()); //JB: see if there's any cached value to display while we wait for ENS

//When view changes, this function loads again. It will again try to fetch ENS
if(TextUtils.isEmpty(displayName))
Expand All @@ -303,7 +303,7 @@ private void printTrace(Throwable throwable) {
if (ensFetchProgressBar != null) {
ensFetchProgressBar.setVisibility(View.GONE);
}
updateAddressWithENS(wallet.ENSname); // JB: if there's any issue then fall back to cached name
updateAddressWithENS(wallet.getDisplayName()); // JB: if there's any issue then fall back to cached name
}

private void showContract()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private void initViewModel() {
viewModel.isTaskRunning().observe(this, this::onTaskStatusChanged);

if (isNewWallet) {
wallet.name = getString(R.string.wallet_name_template, walletCount);
wallet.setName(getString(R.string.wallet_name_template, walletCount));
viewModel.storeWallet(wallet);
}
}
Expand Down Expand Up @@ -193,14 +193,14 @@ private void initViews() {

walletSelectedIcon.setImageResource(R.drawable.ic_copy);

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

private void setENSText()
{
if (wallet.ENSname != null && !wallet.ENSname.isEmpty()) {
walletNameText.setText(wallet.ENSname);
if (wallet.getDisplayName() != null && !wallet.getDisplayName().isEmpty()) {
walletNameText.setText(wallet.getDisplayName());
walletNameText.setVisibility(View.VISIBLE);
walletAddressSeparator.setVisibility(View.VISIBLE);
} else {
Expand All @@ -218,12 +218,8 @@ private void onBackUpSettingClicked() {
}

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

private void doBackUp() {
Expand Down Expand Up @@ -349,15 +345,15 @@ public void resolvedAddress(String address, String ensName)
if (!TextUtils.isEmpty(address)
&& wallet.address.equalsIgnoreCase(address)
&& !TextUtils.isEmpty(ensName)
&& (TextUtils.isEmpty(wallet.ENSname) || !ensName.equalsIgnoreCase(wallet.ENSname))) //Wallet ENS currently empty or new ENS name is different
&& (TextUtils.isEmpty(wallet.getDisplayName()) || !ensName.equalsIgnoreCase(wallet.getDisplayName()))) //Wallet ENS currently empty or new ENS name is different
{
wallet.ENSname = ensName;
wallet.setEnsName(ensName);
//update database
viewModel.storeWallet(wallet);
successOverlay.setVisibility(View.VISIBLE);
handler.postDelayed(this, 1000);
}
else if (TextUtils.isEmpty(wallet.ENSname) || !ensName.equalsIgnoreCase(wallet.ENSname))
else if (TextUtils.isEmpty(wallet.getDisplayName()) || !ensName.equalsIgnoreCase(wallet.getDisplayName()))
{
Toast.makeText(this, R.string.ens_not_match_wallet, Toast.LENGTH_SHORT).show();
}
Expand All @@ -368,4 +364,10 @@ public void addressReady(String address, String ensName)
{

}

@Override
public void onBackPressed() {
saveWalletName();
super.onBackPressed();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,14 @@ public void bind(@Nullable Wallet data, @NonNull Bundle addition) {

manageWalletBtn.setVisibility(View.VISIBLE);

if (wallet.name != null && !wallet.name.isEmpty()) {
walletNameText.setText(wallet.name);
if (wallet.getDisplayName() != null && !wallet.getDisplayName().isEmpty())
{
walletNameText.setText(wallet.getDisplayName());
walletAddressSeparator.setVisibility(View.VISIBLE);
walletNameText.setVisibility(View.VISIBLE);
} else {
walletAddressSeparator.setVisibility(View.GONE);
walletNameText.setVisibility(View.GONE);
}

if (wallet.ENSname != null && wallet.ENSname.length() > 0) {
walletNameText.setText(wallet.ENSname);
walletAddressSeparator.setVisibility(View.VISIBLE);
walletNameText.setVisibility(View.VISIBLE);
} else {
else
{
walletAddressSeparator.setVisibility(View.GONE);
walletNameText.setVisibility(View.GONE);
}
Expand Down Expand Up @@ -146,8 +140,8 @@ private Wallet fetchWallet(Wallet w)
if (realmWallet != null)
{
w.balance = realmWallet.getBalance();
w.ENSname = realmWallet.getENSName();
w.name = realmWallet.getName();
w.setEnsName(realmWallet.getENSName());
w.setName(realmWallet.getName());
}

return w;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,9 @@ public void getWalletName() {

private void onWallet(Wallet wallet) {
transactionsService.changeWallet(wallet);
if (!TextUtils.isEmpty(wallet.ENSname))
if (!TextUtils.isEmpty(wallet.getDisplayName()))
{
walletName.postValue(wallet.ENSname);
}
else if (!TextUtils.isEmpty(wallet.name))
{
walletName.postValue(wallet.name);
walletName.postValue(wallet.getDisplayName());
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,12 @@ protected void onError(Throwable throwable) {
public void showHome(Context context) {
homeRouter.open(context, true);
}

public void updateWallet(Wallet wallet) {
isTaskRunning.postValue(true);
disposable = fetchWalletsInteract.updateWalletData(wallet)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::onStored, this::onError);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public void swipeRefreshWallets()
disposable = fetchWalletsInteract.fetch().toObservable()
.flatMap(Observable::fromArray)
.forEach(wallet -> ensResolver.resolveEnsName(wallet.address)
.map(ensName -> { wallet.ENSname = ensName; return wallet;})
.map(ensName -> { wallet.setEnsName(ensName); return wallet;})
.flatMap(fetchWalletsInteract::updateWalletData)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@
import androidx.core.content.ContextCompat;
import android.text.InputType;
import android.text.TextUtils;
import android.text.method.DigitsKeyListener;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.widget.CheckBox;
import android.widget.EditText;
Expand Down Expand Up @@ -47,6 +45,7 @@ public class PasswordInputView extends LinearLayout implements TextView.OnEditor
private int innerPadding;
private String imeOptions;
private String hintTxt;
private String charsAllowed;
private Activity activity;
private LayoutCallbackListener callbackListener;

Expand All @@ -70,6 +69,7 @@ public PasswordInputView(Context context, AttributeSet attrs) {
setInputType();
setMinHeight();
setLines();
setCharsAllowed();
}

public void setLayoutListener(Activity a, LayoutCallbackListener callback)
Expand Down Expand Up @@ -115,6 +115,7 @@ private void getAttrs(Context context, AttributeSet attrs) {
minHeight = a.getInteger(R.styleable.InputView_minHeightValue, 0);
innerPadding = a.getInteger(R.styleable.InputView_innerPadding, 0);
hintTxt = a.getString(R.styleable.InputView_hint);
charsAllowed = a.getString(R.styleable.InputView_charsAllowed);
} finally {
a.recycle();
}
Expand Down Expand Up @@ -191,6 +192,14 @@ private void setLines() {
editText.setMinLines(lines);
}

private void setCharsAllowed()
{
if (!TextUtils.isEmpty(charsAllowed))
{
editText.setKeyListener(DigitsKeyListener.getInstance(charsAllowed));
}
}

public CharSequence getText() {
return this.editText.getText();
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/fragment_import_seed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
custom:inputType="textNoSuggestions"
custom:label="@string/enter_seed_phrase"
custom:lines="6"
custom:minHeightValue="170" />
custom:minHeightValue="170"
custom:charsAllowed="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"/>

</LinearLayout>

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<attr name="show_allFunds" format="boolean" />
<attr name="show_paste" format="boolean" />
<attr name="font_size" format="integer" />
<attr name="charsAllowed" format="string" />
</declare-styleable>
<declare-styleable name="CopyTextView">
<attr name="text" format="string" />
Expand Down