Skip to content

Commit

Permalink
Update version to 5.3.12: Remove Bitcoin.com socket, and fix the Bloc…
Browse files Browse the repository at this point in the history
…kchain.info socket.
  • Loading branch information
pokkst committed Mar 31, 2022
1 parent b9b1a9d commit 669bbe9
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 72 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Other features include:
Why accept Bitcoin Cash?
- Say goodbye to credit card fees! Bitcoin Cash costs absolutely nothing to receive
- Customers pay less than a penny in transaction fees to send
- No registration is required to accept BCH. Just download a free, open-source wallet, like the official Bitcoin.com Bitcoin Wallet
- No registration is required to accept BCH. Just download a free wallet like the official Bitcoin.com Bitcoin Wallet
- No one can freeze your wallet
- No one can seize your funds
- No one can block your payments
Expand Down
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 {
applicationId "com.bitcoin.merchant.app"
minSdkVersion 21
targetSdkVersion 30
versionCode 50311
versionName "5.3.11"
versionCode 50312
versionName "5.3.12"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
10 changes: 0 additions & 10 deletions app/src/main/java/com/bitcoin/merchant/app/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import com.bitcoin.merchant.app.model.Analytics
import com.bitcoin.merchant.app.network.PaymentReceived
import com.bitcoin.merchant.app.network.websocket.TxWebSocketHandler
import com.bitcoin.merchant.app.network.websocket.WebSocketListener
import com.bitcoin.merchant.app.network.websocket.impl.bitcoincom.BitcoinComSocketHandler
import com.bitcoin.merchant.app.network.websocket.impl.blockchaininfo.BlockchainInfoSocketSocketHandler
import com.bitcoin.merchant.app.screens.dialogs.DialogHelper
import com.bitcoin.merchant.app.screens.features.ToolbarAwareFragment
Expand All @@ -51,14 +50,12 @@ open class MainActivity : AppCompatActivity(), WebSocketListener {
val app: CashRegisterApplication
get() = application as CashRegisterApplication

lateinit var bitcoinDotComSocket: TxWebSocketHandler
lateinit var blockchainDotInfoSocket: TxWebSocketHandler

private val receiver: BroadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (Action.SUBSCRIBE_TO_ADDRESS == intent.action) {
println("Subscribed to address!")
bitcoinDotComSocket.subscribeToAddress(intent.getStringExtra("address"))
blockchainDotInfoSocket.subscribeToAddress(intent.getStringExtra("address"))
}
}
Expand All @@ -81,13 +78,6 @@ open class MainActivity : AppCompatActivity(), WebSocketListener {
}

fun restartSocketsWhenNeeded() {
if (!this::bitcoinDotComSocket.isInitialized || !bitcoinDotComSocket.isConnected) {
if (this::bitcoinDotComSocket.isInitialized)
bitcoinDotComSocket.stop()
bitcoinDotComSocket = BitcoinComSocketHandler()
bitcoinDotComSocket.setListener(this)
bitcoinDotComSocket.start()
}
if (!this::blockchainDotInfoSocket.isInitialized || !blockchainDotInfoSocket.isConnected) {
if (this::blockchainDotInfoSocket.isInitialized)
blockchainDotInfoSocket.stop()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ data class PaymentTarget(val type: Type, val target: String) {
if (Xpub.isValid(value))
return PaymentTarget(Type.XPUB, value)
if (AddressUtil.isValidLegacy(value))
return PaymentTarget(Type.ADDRESS, value)
return PaymentTarget(Type.ADDRESS, AddressUtil.toCashAddress(value))
if (AddressUtil.isValidCashAddr(value))
return PaymentTarget(Type.ADDRESS, AddressUtil.toLegacyAddress(value))
return PaymentTarget(Type.ADDRESS, value)
if (isApiKey(value))
return PaymentTarget(Type.API_KEY, value)
return PaymentTarget(Type.INVALID, "")
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ class PaymentRequestFragment : ToolbarAwareFragment() {
object : CountDownTimer(1000, 1000) {
override fun onTick(millisUntilFinished: Long) {
if (isAdded) {
updateConnectionStatus(activity.bitcoinDotComSocket.isConnected)
updateConnectionStatus(activity.blockchainDotInfoSocket.isConnected)
}
}

Expand Down
14 changes: 11 additions & 3 deletions app/src/main/java/com/bitcoin/merchant/app/util/AddressUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,20 @@ object AddressUtil {
}
}

fun toCashAddress(legacy: String): String {
return CashAddressFactory.create().getFromBase58(MainNetParams.get(), legacy).toString()
fun toCashAddress(address: String): String {
return if(isValidLegacy(address)) {
CashAddressFactory.create().getFromBase58(MainNetParams.get(), address).toString()
} else {
CashAddressFactory.create().getFromFormattedAddress(MainNetParams.get(), address).toString()
}
}

fun toLegacyAddress(address: String): String {
return CashAddressFactory.create().getFromFormattedAddress(MainNetParams.get(), address).toBase58()
return if(isValidCashAddr(address)) {
CashAddressFactory.create().getFromFormattedAddress(MainNetParams.get(), address).toBase58()
} else {
CashAddressFactory.create().getFromBase58(MainNetParams.get(), address).toBase58()
}
}

fun toSimpleLedgerAddress(address: String): String {
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/com/bitcoin/merchant/app/util/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ object Settings {
}

fun getPaymentTarget(context: Context): PaymentTarget {
val value = PrefsUtil.getInstance(context).getValue(PrefsUtil.MERCHANT_KEY_MERCHANT_RECEIVER, "")
var value = PrefsUtil.getInstance(context).getValue(PrefsUtil.MERCHANT_KEY_MERCHANT_RECEIVER, "")
if(AddressUtil.isValidLegacy(value)) {
value = AddressUtil.toCashAddress(value)
}
return PaymentTarget.parse(value)
}

Expand Down

0 comments on commit 669bbe9

Please sign in to comment.