Skip to content

Commit

Permalink
3029 change the title of the wallet tab to show the truncated wallet …
Browse files Browse the repository at this point in the history
…address if enswallet name is not available (#3031)

* Show formatted address by default
* Show custom name instead of address
* Show ENS name instead of address
* Should show custom name instead of ENS name
  • Loading branch information
seabornlee authored Jan 10, 2023
1 parent 3a84fd0 commit 75a0554
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 5 deletions.
68 changes: 68 additions & 0 deletions app/src/androidTest/java/com/alphawallet/app/WalletNameTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.alphawallet.app;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.replaceText;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withSubstring;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static com.alphawallet.app.assertions.Should.shouldSee;
import static com.alphawallet.app.steps.Steps.createNewWallet;
import static com.alphawallet.app.steps.Steps.getWalletAddress;
import static com.alphawallet.app.steps.Steps.gotoWalletPage;
import static com.alphawallet.app.steps.Steps.input;
import static com.alphawallet.app.steps.Steps.watchWalletWithENS;
import static com.alphawallet.app.util.Helper.click;

import com.alphawallet.app.util.Helper;

import org.junit.Test;

public class WalletNameTest extends BaseE2ETest
{
@Test
public void should_show_custom_name_instead_of_address()
{
createNewWallet();
String address = getWalletAddress();

gotoWalletPage();
shouldSeeFormattedAddress(address);

renameWalletTo("TestWallet");
shouldSee("TestWallet");

renameWalletTo("");
shouldSeeFormattedAddress(address);
}

@Test
public void should_show_custom_name_instead_of_ENS_name()
{
watchWalletWithENS("vitalik.eth");
// Should see ENS name instead of address
shouldSee("vitalik.eth");

renameWalletTo("Vitalik");
gotoWalletPage();
shouldSee("Vitalik");

renameWalletTo("");
gotoWalletPage();
shouldSee("vitalik.eth");
}

private void renameWalletTo(String name)
{
click(withId(R.id.action_my_wallet));
click(withSubstring("Rename this Wallet"));
onView(withId(R.id.edit_text)).perform(replaceText(name));
input(R.id.input_name, name);
click(withText("Save Name"));
Helper.wait(2);
}

private void shouldSeeFormattedAddress(String address)
{
shouldSee(address.substring(0, 6) + "..." + address.substring(address.length() - 4)); // 0xabcd...wxyz
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public static void addNewNetwork(String name, String url)
pressBack();
}

private static void input(int id, String text)
public static void input(int id, String text)
{
onView(allOf(withId(R.id.edit_text), isDescendantOfA(withId(id)))).perform(replaceText(text));
}
Expand Down
14 changes: 10 additions & 4 deletions app/src/main/java/com/alphawallet/app/viewmodel/HomeViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.os.IBinder;
Expand Down Expand Up @@ -274,7 +273,7 @@ public void getWalletName(Context context)
.getWallet(preferenceRepository.getCurrentWalletAddress())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(wallet -> onWallet(context, wallet), this::walletError);
.subscribe(wallet -> updateWalletTitle(context, wallet), this::walletError);
}

private void walletError(Throwable throwable)
Expand All @@ -283,7 +282,7 @@ private void walletError(Throwable throwable)
splashActivity.postValue(true);
}

private void onWallet(Context context, Wallet wallet)
private void updateWalletTitle(Context context, Wallet wallet)
{
transactionsService.changeWallet(wallet);
if (!TextUtils.isEmpty(wallet.name))
Expand All @@ -307,7 +306,14 @@ else if (!TextUtils.isEmpty(wallet.ENSname))
.flatMap(fetchWalletsInteract::updateENS) //store the ENS name
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(updatedWallet -> walletName.postValue(updatedWallet.ENSname), this::onENSError).isDisposed();
.subscribe(updatedWallet -> {
String name = Utils.formatAddress(wallet.address);
if (!TextUtils.isEmpty(updatedWallet.ENSname))
{
name = updatedWallet.ENSname;
}
walletName.postValue(name);
}, this::onENSError).isDisposed();
}
}

Expand Down

0 comments on commit 75a0554

Please sign in to comment.