lib: change primary address type to PublicAddress

This commit is contained in:
Oscar Mira 2023-10-23 12:09:04 +02:00
parent 894788f3b2
commit f5998ac369
7 changed files with 30 additions and 10 deletions

View File

@ -41,7 +41,9 @@ class WalletRepository(
},
httpClient = httpClient,
)
check(config.publicAddress == wallet.primaryAddress) { "primary address mismatch" }
check(config.publicAddress == wallet.primaryAddress.address) {
"primary address mismatch"
}
wallet
}
}.await()
@ -69,7 +71,7 @@ class WalletRepository(
val uniqueFilename = UUID.randomUUID().toString()
val wallet = moneroSdkClient.createWallet(moneroNetwork, uniqueFilename)
val walletId = walletDataSource.createWalletConfig(
publicAddress = wallet.primaryAddress,
publicAddress = wallet.primaryAddress.address,
filename = uniqueFilename,
name = name,
remoteNodeIds = remoteNodeIds,
@ -92,7 +94,7 @@ class WalletRepository(
restorePoint,
)
val walletId = walletDataSource.createWalletConfig(
publicAddress = wallet.primaryAddress,
publicAddress = wallet.primaryAddress.address,
filename = uniqueFilename,
name = name,
remoteNodeIds = remoteNodeIds,

View File

@ -6,6 +6,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Card
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
@ -56,10 +57,22 @@ fun WalletCardExpanded(
uiState: WalletUiState.Loaded,
) {
Row {
Text(text = "Wallet ID #${uiState.config.id} (${uiState.config.name}) ${uiState.config.publicAddress}")
Text(
text = "Wallet ID #${uiState.config.id} (${uiState.config.name}) ${uiState.network.name}",
style = MaterialTheme.typography.bodyMedium,
)
}
Row {
Text(text = uiState.blockchainTime.toString())
Text(
text = uiState.config.publicAddress,
style = MaterialTheme.typography.bodyMedium,
)
}
Row {
Text(
text = uiState.blockchainTime.toString(),
style = MaterialTheme.typography.bodyMedium,
)
}
}

View File

@ -19,6 +19,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel
import im.molly.monero.Ledger
import im.molly.monero.MoneroCurrency
import im.molly.monero.PublicAddress
import im.molly.monero.demo.data.model.WalletConfig
import im.molly.monero.demo.ui.component.Toolbar
import im.molly.monero.demo.ui.preview.PreviewParameterData
@ -240,11 +241,12 @@ private fun WalletScreenPopulated(
uiState = WalletUiState.Loaded(
config = WalletConfig(
id = 0,
publicAddress = ledger.primaryAddress,
publicAddress = ledger.primaryAddress.address,
filename = "",
name = "Personal",
remoteNodes = emptySet(),
),
network = ledger.primaryAddress.network,
balance = ledger.balance,
blockchainTime = ledger.checkedAt,
transactions = emptyList(),

View File

@ -6,6 +6,7 @@ import androidx.lifecycle.viewmodel.initializer
import androidx.lifecycle.viewmodel.viewModelFactory
import im.molly.monero.Balance
import im.molly.monero.BlockchainTime
import im.molly.monero.MoneroNetwork
import im.molly.monero.demo.AppModule
import im.molly.monero.demo.common.Result
import im.molly.monero.demo.common.asResult
@ -65,7 +66,8 @@ private fun walletUiState(
ledger.transactions
.map { WalletTransaction(config.id, it.value) }
.sortedByDescending { it.transaction.timestamp }
WalletUiState.Loaded(config, blockchainTime, balance, transactions)
val network = ledger.primaryAddress.network
WalletUiState.Loaded(config, network, blockchainTime, balance, transactions)
}
is Result.Loading -> {
@ -82,6 +84,7 @@ private fun walletUiState(
sealed interface WalletUiState {
data class Loaded(
val config: WalletConfig,
val network: MoneroNetwork,
val blockchainTime: BlockchainTime,
val balance: Balance,
val transactions: List<WalletTransaction>,

View File

@ -29,7 +29,7 @@ object PreviewParameterData {
)
val ledger = Ledger(
primaryAddress = "4AYjQM9HoAFNUeC3cvSfgeAN89oMMpMqiByvunzSzhn97cj726rJj3x8hCbH58UnMqQJShczCxbpWRiCJQ3HCUDHLiKuo4T",
primaryAddress = PublicAddress.parse("4AYjQM9HoAFNUeC3cvSfgeAN89oMMpMqiByvunzSzhn97cj726rJj3x8hCbH58UnMqQJShczCxbpWRiCJQ3HCUDHLiKuo4T"),
checkedAt = BlockchainTime.Block(2999840),
enotes = emptySet(),
transactions = transactions.associateBy { it.txId },

View File

@ -3,7 +3,7 @@ package im.molly.monero
//import im.molly.monero.proto.LedgerProto
data class Ledger(
val primaryAddress: String,
val primaryAddress: PublicAddress,
val transactions: Map<String, Transaction>,
val enotes: Set<TimeLocked<Enote>>,
val checkedAt: BlockchainTime,

View File

@ -18,7 +18,7 @@ class MoneroWallet internal constructor(
private val logger = loggerFor<MoneroWallet>()
val primaryAddress: String = wallet.accountPrimaryAddress
val primaryAddress: PublicAddress = PublicAddress.parse(wallet.accountPrimaryAddress)
var dataStore by storageAdapter::dataStore