Skip to content

Commit

Permalink
Merge pull request #180 from Tribler/fix/wallet-crashes
Browse files Browse the repository at this point in the history
Move wallet in MusicDAO to separate file
  • Loading branch information
InvictusRMC authored Feb 21, 2024
2 parents f16e356 + 37e22ba commit 745c2ab
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,19 @@ class DashboardActivity : AppCompatActivity() {
}

private fun hasBluetoothPermissions(): Boolean {
return checkSelfPermission(Companion.BLUETOOTH_PERMISSIONS_ADVERTISE) == PackageManager.PERMISSION_GRANTED &&
checkSelfPermission(Companion.BLUETOOTH_PERMISSIONS_CONNECT) == PackageManager.PERMISSION_GRANTED &&
checkSelfPermission(Companion.BLUETOOTH_PERMISSIONS_SCAN) == PackageManager.PERMISSION_GRANTED
return checkSelfPermission(BLUETOOTH_PERMISSIONS_ADVERTISE) == PackageManager.PERMISSION_GRANTED &&
checkSelfPermission(BLUETOOTH_PERMISSIONS_CONNECT) == PackageManager.PERMISSION_GRANTED &&
checkSelfPermission(BLUETOOTH_PERMISSIONS_SCAN) == PackageManager.PERMISSION_GRANTED
}

private fun requestBluetoothPermissions() {
requestPermissions(
arrayOf(
Companion.BLUETOOTH_PERMISSIONS_ADVERTISE,
Companion.BLUETOOTH_PERMISSIONS_CONNECT,
Companion.BLUETOOTH_PERMISSIONS_SCAN
BLUETOOTH_PERMISSIONS_ADVERTISE,
BLUETOOTH_PERMISSIONS_CONNECT,
BLUETOOTH_PERMISSIONS_SCAN
),
Companion.BLUETOOTH_PERMISSIONS_REQUEST_CODE
BLUETOOTH_PERMISSIONS_REQUEST_CODE
)
}

Expand All @@ -88,7 +88,7 @@ class DashboardActivity : AppCompatActivity() {
grantResults: IntArray
) {
when (requestCode) {
Companion.BLUETOOTH_PERMISSIONS_REQUEST_CODE -> {
BLUETOOTH_PERMISSIONS_REQUEST_CODE -> {
if (hasBluetoothPermissions()) {
(application as TrustChainApplication).initIPv8()
} else {
Expand All @@ -106,7 +106,7 @@ class DashboardActivity : AppCompatActivity() {
data: Intent?
) {
when (requestCode) {
Companion.SETTINGS_INTENT_CODE -> {
SETTINGS_INTENT_CODE -> {
if (hasBluetoothPermissions()) {
(application as TrustChainApplication).initIPv8()
} else {
Expand All @@ -132,8 +132,7 @@ class DashboardActivity : AppCompatActivity() {
Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
val uri: Uri = Uri.fromParts("package", packageName, null)
intent.data = uri
@Suppress("DEPRECATION") // TODO: Fix deprecation issue.
startActivityForResult(intent, Companion.SETTINGS_INTENT_CODE)
startActivityForResult(intent, SETTINGS_INTENT_CODE)
}
}.create()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ var minBlockchainPeers = MIN_BLOCKCHAIN_PEERS_TEST_NET
* In these location you can find all information to run the regtest and python server.
* Make sure to also change the IP's (and URLs) in the kotlin code when swapping to a different server.
*/
@Suppress("DEPRECATION", "NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
class WalletManager(
walletManagerConfiguration: WalletManagerConfiguration,
walletDir: File,
Expand Down Expand Up @@ -91,6 +90,8 @@ class WalletManager(
BitcoinNetworkOptions.REG_TEST -> RegTestParams.get()
}

val customPrefix = MUSIC_DAO_PREFIX

val filePrefix =
when (walletManagerConfiguration.network) {
BitcoinNetworkOptions.TEST_NET -> TEST_NET_WALLET_NAME
Expand All @@ -99,7 +100,7 @@ class WalletManager(
}

kit =
object : WalletAppKit(params, walletDir, filePrefix) {
object : WalletAppKit(params, walletDir, customPrefix + filePrefix) {
override fun onSetupCompleted() {
// Make a fresh new key if no keys in stored wallet.
if (wallet().keyChainGroupSize < 1) {
Expand Down Expand Up @@ -731,6 +732,8 @@ class WalletManager(
val creationTime = seed.creationTimeSeconds
return SerializedDeterministicKey(words, creationTime)
}

const val MUSIC_DAO_PREFIX = "musicdao-"
}

fun toSeed(): SerializedDeterministicKey {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import android.content.Context
*/
object WalletManagerAndroid { // TODO: Clean up Thread usage.
private var walletManager: WalletManager? = null
private var context: Context? = null
var isRunning: Boolean = false

fun getInstance(): WalletManager {
Expand All @@ -31,8 +30,6 @@ object WalletManagerAndroid { // TODO: Clean up Thread usage.
configuration
?: throw IllegalStateException("Configuration is not set")

WalletManagerAndroid.context = context

val walletManager =
WalletManager(
configuration,
Expand Down

0 comments on commit 745c2ab

Please sign in to comment.