Skip to content

Commit

Permalink
Allow to attach BIP39 wallets
Browse files Browse the repository at this point in the history
  • Loading branch information
akumaigorodski committed Sep 17, 2023
1 parent 7c004a3 commit 20aacc8
Show file tree
Hide file tree
Showing 16 changed files with 236 additions and 156 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ android {
targetSdkVersion 30
minSdkVersion 21

versionName '2.5.1'
versionCode 98
versionName '2.5.2'
versionCode 99
}

buildTypes {
Expand Down
13 changes: 6 additions & 7 deletions app/src/main/java/com/btcontract/wallet/BaseActivity.scala
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,14 @@ trait BaseActivity extends AppCompatActivity { me =>
}

def chainWalletBackground(wallet: ElectrumEclairWallet): Int = if (wallet.isSigning) R.color.cardBitcoinModern else R.color.cardBitcoinLegacy
def chainWalletNotice(wallet: ElectrumEclairWallet): Option[Int] = if (wallet.hasFingerprint) Some(hardware_wallet) else if (!wallet.isSigning) Some(watching_wallet) else None
def browse(maybeUri: String): Unit = try me startActivity new Intent(Intent.ACTION_VIEW, Uri parse maybeUri) catch { case exception: Throwable => me onFail exception }

def chainWalletNotice(wallet: ElectrumEclairWallet): Option[Int] =
if (wallet.info.core.attachedMaster.isDefined) Some(attached_wallet)
else if (wallet.info.core.masterFingerprint.nonEmpty) Some(hardware_wallet)
else if (!wallet.isSigning) Some(watching_wallet)
else None

def share(text: CharSequence): Unit = startActivity {
val shareAction = (new Intent).setAction(Intent.ACTION_SEND)
shareAction.setType("text/plain").putExtra(Intent.EXTRA_TEXT, text)
Expand Down Expand Up @@ -236,12 +241,6 @@ trait BaseActivity extends AppCompatActivity { me =>
new java.util.TimerTask { def run: Unit = me runOnUiThread runnableExec }
}

def selectorList(listAdapter: ListAdapter): ListView = {
val list = getLayoutInflater.inflate(R.layout.frag_selector_list, null).asInstanceOf[ListView]
list.setAdapter(listAdapter)
list
}

// Builders

def clickableTextField(view: View): TextView = {
Expand Down
33 changes: 18 additions & 15 deletions app/src/main/java/com/btcontract/wallet/HubActivity.scala
Original file line number Diff line number Diff line change
Expand Up @@ -409,18 +409,19 @@ class HubActivity extends BaseActivity with ExternalDataChecker { me =>
item match {
case info: TxInfo =>
val amount = if (info.isIncoming) info.receivedSat.toMilliSatoshi else info.sentSat.toMilliSatoshi
val wallet = WalletParams.chainWallets.findByPubKey(info.pubKey).find(wallet => wallet.isSigning || wallet.info.core.masterFingerprint.nonEmpty)
val canRBF = !info.isIncoming && !info.isDoubleSpent && info.depth < 1 && info.description.rbf.isEmpty && info.description.cpfpOf.isEmpty
val canCPFP = info.isIncoming && !info.isDoubleSpent && info.depth < 1 && info.description.rbf.isEmpty && info.description.canBeCPFPd
val walletCanSpend = WalletParams.chainWallets.findByPubKey(info.pubKey).exists(wallet => wallet.isSigning || wallet.hasFingerprint)
val isRbfCancel = info.description.rbf.exists(_.mode == TxDescription.RBF_CANCEL)

val fee = WalletApp.denom.directedWithSign(0L.msat, info.feeSat.toMilliSatoshi, cardOut, cardIn, cardZero, isIncoming = false)
val fiatNow = WalletApp.msatInFiatHuman(WalletParams.fiatRates.info.rates, WalletApp.fiatCode, amount, Denomination.formatFiat)
val fiatThen = WalletApp.msatInFiatHuman(info.fiatRateSnapshot, WalletApp.fiatCode, amount, Denomination.formatFiat)

WalletParams.chainWallets.findByPubKey(info.pubKey) match {
case Some(wallet) if wallet.hasFingerprint => addFlowChip(extraInfo, getString(hardware_wallet), R.drawable.border_gray)
case Some(wallet) if !wallet.isSigning => addFlowChip(extraInfo, getString(watching_wallet), R.drawable.border_gray)
wallet match {
case Some(w) if w.info.core.attachedMaster.isDefined => addFlowChip(extraInfo, getString(attached_wallet), R.drawable.border_gray)
case Some(w) if w.info.core.masterFingerprint.nonEmpty => addFlowChip(extraInfo, getString(hardware_wallet), R.drawable.border_gray)
case Some(w) if !w.isSigning => addFlowChip(extraInfo, getString(watching_wallet), R.drawable.border_gray)
case _ =>
}

Expand All @@ -430,9 +431,11 @@ class HubActivity extends BaseActivity with ExternalDataChecker { me =>
addFlowChip(extraInfo, getString(popup_fiat).format(s"<font color=$cardIn>$fiatNow</font>", fiatThen), R.drawable.border_gray)
if (!info.isIncoming || isRbfCancel || info.description.cpfpOf.isDefined) addFlowChip(extraInfo, getString(popup_chain_fee) format fee, R.drawable.border_gray)

if (walletCanSpend && canCPFP) addFlowChip(extraInfo, getString(dialog_boost), R.drawable.border_yellow, _ => self boostCPFP info)
if (walletCanSpend && canRBF) addFlowChip(extraInfo, getString(dialog_cancel), R.drawable.border_yellow, _ => self cancelRBF info)
if (walletCanSpend && canRBF) addFlowChip(extraInfo, getString(dialog_boost), R.drawable.border_yellow, _ => self boostRBF info)
if (wallet.isDefined) {
if (canCPFP) addFlowChip(extraInfo, getString(dialog_boost), R.drawable.border_yellow, _ => self boostCPFP info)
if (canRBF) addFlowChip(extraInfo, getString(dialog_cancel), R.drawable.border_yellow, _ => self cancelRBF info)
if (canRBF) addFlowChip(extraInfo, getString(dialog_boost), R.drawable.border_yellow, _ => self boostRBF info)
}
}
}

Expand Down Expand Up @@ -879,40 +882,40 @@ class HubActivity extends BaseActivity with ExternalDataChecker { me =>
paymentsAdapter.notifyDataSetChanged
}

def proceedConfirm(fromWallet: ElectrumEclairWallet, sendView: ChainSendView, alert: AlertDialog, response: GenerateTxResponse)(process: Transaction => Unit): Unit = {
def proceedConfirm(wallet: ElectrumEclairWallet, sendView: ChainSendView, alert: AlertDialog, response: GenerateTxResponse)(process: Transaction => Unit): Unit = {
// This is used after user decided to send a transaction, if the wallet happens to be a hardware one then generated response is fake and we got stuff to do
val finalSendButton = sendView.chainConfirmView.chainButtonsView.chainNextButton

if (fromWallet.isSigning) {
if (wallet.isSigning) {
// This is a signing wallet so signed response tx is a final one, we use it
finalSendButton setOnClickListener onButtonTap(process apply response.tx)
sendView.switchToConfirm(alert, response)
} else if (fromWallet.hasFingerprint) {
} else if (wallet.info.core.masterFingerprint.nonEmpty) {
sendView.chainReaderView.onSignedTx = signedTx => UITask {
if (signedTx.txOut.toSet != response.tx.txOut.toSet) alert.dismiss
finalSendButton setOnClickListener onButtonTap(process apply signedTx)
sendView.switchToConfirm(alert, response)
}.run

val masterFingerprint = fromWallet.info.core.masterFingerprint.get
val masterFingerprint = wallet.info.core.masterFingerprint.get
val psbt = prepareBip84Psbt(response, masterFingerprint)
sendView.switchToHardwareOutgoing(alert, psbt)
} else alert.dismiss
}

def proceedWithoutConfirm(fromWallet: ElectrumEclairWallet, sendView: ChainSendView, alert: AlertDialog, response: GenerateTxResponse)(process: Transaction => Unit): Unit = {
def proceedWithoutConfirm(wallet: ElectrumEclairWallet, sendView: ChainSendView, alert: AlertDialog, response: GenerateTxResponse)(process: Transaction => Unit): Unit = {
// This is used after user decided to send CPFP/RBF a transaction, if the wallet happens to be a hardware one then generated response is fake and we got stuff to do

if (fromWallet.isSigning) {
if (wallet.isSigning) {
process(response.tx)
alert.dismiss
} else if (fromWallet.hasFingerprint) {
} else if (wallet.info.core.masterFingerprint.nonEmpty) {
sendView.chainReaderView.onSignedTx = signedTx => UITask {
if (signedTx.txOut.toSet == response.tx.txOut.toSet) process(signedTx)
alert.dismiss
}.run

val masterFingerprint = fromWallet.info.core.masterFingerprint.get
val masterFingerprint = wallet.info.core.masterFingerprint.get
val psbt = prepareBip84Psbt(response, masterFingerprint)
sendView.switchToHardwareOutgoing(alert, psbt)
} else alert.dismiss
Expand Down
Loading

0 comments on commit 20aacc8

Please sign in to comment.