Skip to content

Commit

Permalink
Pairing QR-code validation
Browse files Browse the repository at this point in the history
  • Loading branch information
koloale committed Feb 16, 2018
1 parent f24154c commit 6fcd678
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 11 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ android {
defaultConfig {
applicationId "com.wavesplatform.wallet"
targetSdkVersion 25
versionCode 330
versionName "1.1.4"
versionCode 335
versionName "1.1.5"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
archivesBaseName = "waves-wallet-$versionName"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,14 @@ public void updateAccountList() {
null);
activeAccountAndAddressList.add(all);

List<ItemAccount> assets = assetsHelper.getAccountItems();

for (ItemAccount itemAccount : assets) {
spinnerIndex++;
activeAccountAndAddressList.add(itemAccount);
activeAccountAndAddressBiMap.put((AssetBalance) itemAccount.accountObject, spinnerIndex);
if (assetsHelper != null) {
List<ItemAccount> assets = assetsHelper.getAccountItems();

for (ItemAccount itemAccount : assets) {
spinnerIndex++;
activeAccountAndAddressList.add(itemAccount);
activeAccountAndAddressBiMap.put((AssetBalance) itemAccount.accountObject, spinnerIndex);
}
}

//If we have multiple accounts/addresses we will show dropdown in toolbar, otherwise we will only display a static text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.StringRes;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;

Expand Down Expand Up @@ -70,7 +71,8 @@ public void onBackPressed() {
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK && requestCode == PAIRING_QR) {
if (data != null && data.getStringExtra(CaptureActivity.SCAN_RESULT) != null) {
viewModel.pairWithQR(data.getStringExtra(CaptureActivity.SCAN_RESULT));
String seed = data.getStringExtra(CaptureActivity.SCAN_RESULT);
viewModel.pairWithQR(seed);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import android.support.annotation.StringRes;

import com.wavesplatform.wallet.R;
import com.wavesplatform.wallet.injection.Injector;
import com.wavesplatform.wallet.ui.base.BaseViewModel;
import com.wavesplatform.wallet.ui.customviews.ToastCustom;
import com.wavesplatform.wallet.util.AddressUtil;
import com.wavesplatform.wallet.util.AppUtil;
import com.wavesplatform.wallet.util.PrefsUtil;

Expand Down Expand Up @@ -38,9 +40,18 @@ interface DataListener {
public void onViewReady() {
}

private boolean isLooksLikeAddress(String seed) {
return AddressUtil.isWavesUri(seed) || AddressUtil.isValidAddress(seed);
}

void pairWithQR(String raw) {
if (dataListener != null)
dataListener.startSeedWalletActivity(raw);
if (dataListener != null) {
if (isLooksLikeAddress(raw)) {
dataListener.showToast(R.string.seed_like_address, ToastCustom.TYPE_ERROR);
} else {
dataListener.startSeedWalletActivity(raw);
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public static String addressFromPublicKey(String publicKey) {
}
}

public static boolean isWavesUri(String uri) {
return uri.startsWith("waves://");
}

public static String generateReceiveUri(long amount, AssetBalance ab, String attachment) {
List<String> params = new ArrayList<>();
if (!ab.isWaves()) params.add("asset=" + ab.assetId);
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -645,4 +645,6 @@
<item>4H</item>
<item>1D</item>
</string-array>

<string name="seed_like_address">It looks like you scan address QR-code instead of seed. Please use correct QR-code.</string>
</resources>

0 comments on commit 6fcd678

Please sign in to comment.