Commit 27e0bbc1 authored by pokkst's avatar pokkst

Sweep functionality from home screen.

parent d765786b
No preview for this file type
......@@ -7,6 +7,7 @@ import android.content.IntentFilter
import android.net.Uri
import android.os.Bundle
import android.os.CountDownTimer
import android.text.TextUtils
import android.view.View
import android.widget.*
import androidx.annotation.UiThread
......@@ -20,6 +21,7 @@ import app.crescentcash.src.utils.Constants
import app.crescentcash.src.utils.PermissionHelper
import app.crescentcash.src.utils.PrefsUtil
import com.google.android.material.floatingactionbutton.FloatingActionButton
import org.bitcoinj.crypto.BIP38PrivateKey
import org.bitcoinj.utils.MonetaryFormat
import java.io.File
import java.text.DecimalFormat
......@@ -43,14 +45,14 @@ class MainActivity : AppCompatActivity() {
private lateinit var btnViewHistory: Button
private lateinit var syncPct: TextView
private lateinit var btnViewTokens: Button
private lateinit var tipBCHBtn: Button
private lateinit var coinspiceBtn: Button
private lateinit var sideshiftAIBtn: Button
private lateinit var acceptbchBtn: Button
private lateinit var receiveFabHome: FloatingActionButton
private lateinit var sendFabHome: FloatingActionButton
private lateinit var fiatBalTxt: TextView
lateinit var btnSweepPrivateKey: Button
lateinit var btnScanPrivateKey: ImageView
private lateinit var privKeyText: EditText
private lateinit var bip38Layout: LinearLayout
private lateinit var bip38PrivateKeyPassword: EditText
private var receiver: BroadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (Constants.ACTION_UPDATE_HOME_SCREEN_BALANCE == intent.action) {
......@@ -68,6 +70,11 @@ class MainActivity : AppCompatActivity() {
this@MainActivity.syncPct.text = ""
}
}
if (Constants.ACTION_CLEAR_SWEEP_TEXT == intent.action) {
this@MainActivity.privKeyText.text = null
this@MainActivity.bip38PrivateKeyPassword.text = null
this@MainActivity.bip38Layout.visibility = View.GONE
}
}
}
......@@ -138,14 +145,15 @@ class MainActivity : AppCompatActivity() {
fiatBalTxt = this.findViewById(R.id.fiatBalTxt)
syncPct = this.findViewById(R.id.syncPct)
btnViewTokens = this.findViewById(R.id.viewSLPBtn)
tipBCHBtn = this.findViewById(R.id.tipBCHBtn)
coinspiceBtn = this.findViewById(R.id.coinspiceBtn)
sideshiftAIBtn = this.findViewById(R.id.sideshiftAIBtn)
acceptbchBtn = this.findViewById(R.id.acceptbchBtn)
receiveFabHome = this.findViewById(R.id.receiveFabHome)
sendFabHome = this.findViewById(R.id.sendFabHome)
openKeys = this.findViewById(R.id.openKeys)
btnViewHistory = this.findViewById(R.id.viewBCHBtn)
privKeyText = this.findViewById(R.id.privKeyMainText)
bip38Layout = this.findViewById(R.id.bip38MainLayout)
bip38PrivateKeyPassword = this.findViewById(R.id.bip38MainPrivKeyPass)
btnSweepPrivateKey = this.findViewById(R.id.btnMainSweepPrivKey)
btnScanPrivateKey = this.findViewById(R.id.btnMainScanPrivKey)
}
private fun prepareViews() {
......@@ -166,26 +174,44 @@ class MainActivity : AppCompatActivity() {
this.startActivity(tokensListActivity)
}
this.openKeys.setOnClickListener { UIManager.startActivity(this, SettingsActivity::class.java) }
this.tipBCHBtn.setOnClickListener { openUrl("https://tipbitcoin.cash") }
this.coinspiceBtn.setOnClickListener { openUrl("https://coinspice.io") }
this.sideshiftAIBtn.setOnClickListener { openUrl("https://sideshift.ai/a/mmG1iwJRO") }
this.acceptbchBtn.setOnClickListener { openUrl("https://acceptbitcoin.cash") }
val permissionHelper = PermissionHelper()
permissionHelper.askForPermissions(this, this)
this.btnScanPrivateKey.setOnClickListener { UIManager.clickScanQR(this, Constants.REQUEST_CODE_SWEEP_SCAN) }
this.btnSweepPrivateKey.setOnClickListener {
val privKey = privKeyText.text.toString()
if (!TextUtils.isEmpty(privKey) && WalletManager.walletKit != null) {
if (!WalletManager.isEncryptedBIP38Key(privKey)) {
WalletManager.sweepWallet(this, privKey)
UIManager.showToastMessage(this, "Swept wallet!")
} else {
if(bip38Layout.visibility == View.GONE) {
bip38Layout.visibility = View.VISIBLE
} else {
val bip38Password = bip38PrivateKeyPassword.text.toString()
if(!TextUtils.isEmpty(bip38Password)) {
val encryptedKey = BIP38PrivateKey.fromBase58(WalletManager.parameters, privKey)
try {
val ecKey = encryptedKey.decrypt(bip38Password)
WalletManager.sweepWallet(this, ecKey.getPrivateKeyAsWiF(WalletManager.parameters))
UIManager.showToastMessage(this, "Swept wallet!")
} catch (e: BIP38PrivateKey.BadPassphraseException) {
UIManager.showToastMessage(this, "Incorrect password!")
}
} else {
UIManager.showToastMessage(this, "Please enter a password!")
}
}
}
}
}
val filter = IntentFilter()
filter.addAction(Constants.ACTION_UPDATE_HOME_SCREEN_BALANCE)
filter.addAction(Constants.ACTION_UPDATE_HOME_SCREEN_THEME)
filter.addAction(Constants.ACTION_CLEAR_SWEEP_TEXT)
LocalBroadcastManager.getInstance(this).registerReceiver(receiver, filter)
}
private fun openUrl(url: String) {
val uri = Uri.parse(url)
val intent = Intent(Intent.ACTION_VIEW, uri)
this.startActivity(intent)
}
private fun startSendActivity() {
UIManager.startActivity(this, SendActivity::class.java)
}
......@@ -323,6 +349,23 @@ class MainActivity : AppCompatActivity() {
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == Constants.REQUEST_CODE_SWEEP_SCAN) {
if (data != null) {
val scanData = data.getStringExtra(Constants.QR_SCAN_RESULT)
if (scanData != null) {
if(!WalletManager.isEncryptedBIP38Key(scanData)) {
this.privKeyText.setText(scanData)
this.bip38Layout.visibility = View.GONE
} else {
this.bip38Layout.visibility = View.VISIBLE
this.privKeyText.setText(scanData)
}
}
}
}
}
companion object {
var isNewUser = true
......
......@@ -229,126 +229,115 @@
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="145dp" />
android:minHeight="100dp" />
<TextView
android:id="@+id/labelServices"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="bottom"
android:minHeight="10dp"
android:padding="10dp"
android:paddingStart="20dp"
android:text="Check out our other services"
android:paddingStart="15dp"
android:text="Paperwallet"
android:textColor="?attr/textColor"
android:textSize="13sp" />
android:textSize="34sp"
android:textStyle="bold"
app:autoSizeMaxTextSize="34sp"
app:autoSizeTextType="uniform" />
<Button
android:id="@+id/tipBCHBtn"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_weight="1"
android:background="@drawable/tipbch_button"
android:elevation="8dp"
android:padding="15dp"
android:paddingStart="25dp"
android:singleLine="true"
android:text="tipbitcoin.cash"
android:textAlignment="textStart"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="18sp" />
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingStart="10dp"
android:paddingEnd="30dp">
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="25dp" />
<EditText
android:id="@+id/privKeyMainText"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="0.5"
android:background="@drawable/circle_button"
android:backgroundTint="?attr/textboxOnWhite"
android:hint="Private Key"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:singleLine="true"
android:textColor="?attr/textColor"
android:textColorHint="?attr/textHintOnWhite"
android:textCursorDrawable="@null"
android:textSize="14sp" />
<TextView
android:id="@+id/labelServices2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="bottom"
android:minHeight="10dp"
android:padding="10dp"
android:paddingStart="20dp"
android:text="Other services"
android:textColor="?attr/textColor"
android:textSize="13sp" />
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3.25" />
<Button
android:id="@+id/coinspiceBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_weight="1"
android:background="@drawable/tipbch_button"
android:elevation="8dp"
android:padding="15dp"
android:paddingStart="25dp"
android:singleLine="true"
android:text="🌶️ CoinSpice"
android:textAlignment="textStart"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="18sp" />
<ImageView
android:id="@+id/btnMainScanPrivKey"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="3.125"
android:padding="5dp"
android:tint="?attr/textColor"
app:srcCompat="@drawable/qrcodeicon" />
</LinearLayout>
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="10dp" />
<Button
android:id="@+id/sideshiftAIBtn"
<LinearLayout
android:id="@+id/bip38MainLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_weight="1"
android:background="@drawable/tipbch_button"
android:elevation="8dp"
android:padding="15dp"
android:paddingStart="25dp"
android:singleLine="true"
android:text="SideShift AI"
android:textAlignment="textStart"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="18sp" />
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:visibility="gone">
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="10dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<EditText
android:id="@+id/bip38MainPrivKeyPass"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/circle_button"
android:backgroundTint="?attr/textboxOnWhite"
android:hint="Password"
android:inputType="textPassword"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:singleLine="true"
android:textColor="?attr/textColor"
android:textColorHint="?attr/textHintOnWhite"
android:textCursorDrawable="@null"
android:textSize="14sp" />
</LinearLayout>
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="10dp" />
</LinearLayout>
<Button
android:id="@+id/acceptbchBtn"
android:id="@+id/btnMainSweepPrivKey"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_weight="1"
android:background="@drawable/acceptbch_button"
android:elevation="8dp"
android:padding="15dp"
android:paddingStart="25dp"
android:singleLine="true"
android:text="acceptbitcoin.cash"
android:textAlignment="textStart"
android:background="@drawable/bch_wallet_button"
android:text="Sweep"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="18sp" />
android:textColor="?attr/buttonTextOnWhite" />
<Space
android:layout_width="match_parent"
......
......@@ -217,126 +217,115 @@
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="145dp" />
android:minHeight="100dp" />
<TextView
android:id="@+id/labelServices"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="bottom"
android:minHeight="10dp"
android:padding="10dp"
android:paddingStart="20dp"
android:text="Check out our other services"
android:paddingStart="15dp"
android:text="Paperwallet"
android:textColor="?attr/textColor"
android:textSize="13sp" />
android:textSize="34sp"
android:textStyle="bold"
app:autoSizeMaxTextSize="34sp"
app:autoSizeTextType="uniform" />
<Button
android:id="@+id/tipBCHBtn"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_weight="1"
android:background="@drawable/tipbch_button"
android:elevation="8dp"
android:padding="15dp"
android:paddingStart="25dp"
android:singleLine="true"
android:text="tipbitcoin.cash"
android:textAlignment="textStart"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="18sp" />
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingStart="10dp"
android:paddingEnd="30dp">
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="25dp" />
<EditText
android:id="@+id/privKeyMainText"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="0.5"
android:background="@drawable/circle_button"
android:backgroundTint="?attr/textboxOnWhite"
android:hint="Private Key"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:singleLine="true"
android:textColor="?attr/textColor"
android:textColorHint="?attr/textHintOnWhite"
android:textCursorDrawable="@null"
android:textSize="14sp" />
<TextView
android:id="@+id/labelServices2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="bottom"
android:minHeight="10dp"
android:padding="10dp"
android:paddingStart="20dp"
android:text="Other services"
android:textColor="?attr/textColor"
android:textSize="13sp" />
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3.25" />
<Button
android:id="@+id/coinspiceBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_weight="1"
android:background="@drawable/tipbch_button"
android:elevation="8dp"
android:padding="15dp"
android:paddingStart="25dp"
android:singleLine="true"
android:text="🌶️ CoinSpice"
android:textAlignment="textStart"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="18sp" />
<ImageView
android:id="@+id/btnMainScanPrivKey"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="3.125"
android:padding="5dp"
android:tint="?attr/textColor"
app:srcCompat="@drawable/qrcodeicon" />
</LinearLayout>
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="10dp" />
<Button
android:id="@+id/sideshiftAIBtn"
<LinearLayout
android:id="@+id/bip38MainLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_weight="1"
android:background="@drawable/tipbch_button"
android:elevation="8dp"
android:padding="15dp"
android:paddingStart="25dp"
android:singleLine="true"
android:text="SideShift AI"
android:textAlignment="textStart"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="18sp" />
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:visibility="gone">
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="10dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<EditText
android:id="@+id/bip38MainPrivKeyPass"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/circle_button"
android:backgroundTint="?attr/textboxOnWhite"
android:hint="Password"
android:inputType="textPassword"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:singleLine="true"
android:textColor="?attr/textColor"
android:textColorHint="?attr/textHintOnWhite"
android:textCursorDrawable="@null"
android:textSize="14sp" />
</LinearLayout>
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="10dp" />
</LinearLayout>
<Button
android:id="@+id/acceptbchBtn"
android:id="@+id/btnMainSweepPrivKey"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_weight="1"
android:background="@drawable/acceptbch_button"
android:elevation="8dp"
android:padding="15dp"
android:paddingStart="25dp"
android:singleLine="true"
android:text="acceptbitcoin.cash"
android:textAlignment="textStart"
android:background="@drawable/bch_wallet_button"
android:text="Sweep"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="18sp" />
android:textColor="?attr/buttonTextOnWhite" />
<Space
android:layout_width="match_parent"
......
......@@ -228,126 +228,115 @@
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="145dp" />
android:minHeight="100dp" />
<TextView
android:id="@+id/labelServices"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="bottom"
android:minHeight="10dp"
android:padding="10dp"
android:paddingStart="20dp"
android:text="Check out our other services"
android:paddingStart="15dp"
android:text="Paperwallet"
android:textColor="?attr/textColor"
android:textSize="13sp" />
android:textSize="34sp"
android:textStyle="bold"
app:autoSizeMaxTextSize="34sp"
app:autoSizeTextType="uniform" />
<Button
android:id="@+id/tipBCHBtn"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_weight="1"
android:background="@drawable/tipbch_button"
android:elevation="8dp"
android:padding="15dp"
android:paddingStart="25dp"
android:singleLine="true"
android:text="tipbitcoin.cash"
android:textAlignment="textStart"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="18sp" />
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingStart="10dp"
android:paddingEnd="30dp">
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="25dp" />
<EditText
android:id="@+id/privKeyMainText"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="0.5"
android:background="@drawable/circle_button"
android:backgroundTint="?attr/textboxOnWhite"
android:hint="Private Key"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:singleLine="true"
android:textColor="?attr/textColor"
android:textColorHint="?attr/textHintOnWhite"
android:textCursorDrawable="@null"
android:textSize="14sp" />
<TextView
android:id="@+id/labelServices2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="bottom"
android:minHeight="10dp"
android:padding="10dp"
android:paddingStart="20dp"
android:text="Other services"
android:textColor="?attr/textColor"
android:textSize="13sp" />
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3.25" />
<Button
android:id="@+id/coinspiceBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_weight="1"
android:background="@drawable/tipbch_button"
android:elevation="8dp"
android:padding="15dp"
android:paddingStart="25dp"
android:singleLine="true"
android:text="🌶️ CoinSpice"
android:textAlignment="textStart"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="18sp" />
<ImageView
android:id="@+id/btnMainScanPrivKey"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="3.125"
android:padding="5dp"
android:tint="?attr/textColor"
app:srcCompat="@drawable/qrcodeicon" />
</LinearLayout>
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="10dp" />
<Button
android:id="@+id/sideshiftAIBtn"
<LinearLayout
android:id="@+id/bip38MainLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_weight="1"
android:background="@drawable/tipbch_button"
android:elevation="8dp"
android:padding="15dp"
android:paddingStart="25dp"
android:singleLine="true"
android:text="SideShift AI"
android:textAlignment="textStart"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="18sp" />
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:visibility="gone">
<Space
android:layout_width="match_parent"
android:layout_height=