Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App: Successfuly intergrate transactions #16

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ val useCaseModule = module{
single{GetSessionStatusUseCase(get())}
single{ CreateRequestLinkUseCase(get())}
single{ GetRequestLinkDataUseCase(get())}
single{ TransferCryptoUseCase(get(), get())}
single{ TransferCryptoUseCase(get())}
single{ GetTransactionUseCase(get(), get())}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,25 @@ import org.example.domain.repository.WalletRepository

class TransferCryptoUseCase(
private val repository: WalletRepository,
private val keyValueStorage: KeyValueStorage
) {
operator fun invoke(
body: TransferCryptoReq
): Flow<Resource<TransferCryptoRes>> = flow {
emit(Resource.Loading())
try {
val walletId = keyValueStorage.getString(Constants.WALLET_ID) ?: ""

val data = body.copy(
walletId =walletId,
idempotencyKey = generateUUID()
)

val response = repository.transferCrypto(data)
println("Transfer response: $response")
if (response.status){
if (response.status) {
emit(Resource.Success(data = response, message = "Success"))
}else{
} else {
emit(Resource.Error(response.message))
}
}catch (e: Exception){
} catch (e: Exception) {
e.printStackTrace()
emit(Resource.Error(e.message.toString()))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,29 @@ fun NavGraph(
onNavigateToExplorer = { url ->
navController.navigate(Explorer(url))
},
onNavigateToTransfer = { amount, address, blockchain, selectedTokenId ->
onNavigateToTransfer = { amount, address, blockchain, selectedTokenId, individualWalletId ->
navController.navigate(
TransactScreen(
individualWalletId = individualWalletId,
amount = amount.toString(),
address = address,
blockchain = blockchain,
tokenId = selectedTokenId
)
){
popUpTo(Screen.DashBoard){
) {
popUpTo(Screen.DashBoard) {
inclusive = true
}
}
},
onOpenQRCodeScreen = {blockchain, tokenId ->
navController.navigate(QRCodeScanner(blockchain = blockchain, tokenId = tokenId))
onOpenQRCodeScreen = { blockchain, tokenId, individualWalletId ->
navController.navigate(
QRCodeScanner(
individualWalletId = individualWalletId,
blockchain = blockchain,
tokenId = tokenId
)
)
}
)
}
Expand All @@ -77,18 +84,20 @@ fun NavGraph(
}
)
}
composable<QRCodeScanner> {backStackEntry ->
composable<QRCodeScanner> { backStackEntry ->
val data: QRCodeScanner = backStackEntry.toRoute()

QrCodeScannerScreen(
individualWalletId = data.individualWalletId,
tokenId = data.tokenId,
blockchain = data.blockchain,
onNavigateBack = {
navController.navigateUp()
},
onNavigateToTransfer = { address, amount, blockchain, tokenId ->
onNavigateToTransfer = { address, amount, blockchain, tokenId, individualWalletId ->
navController.navigate(
TransactScreen(
individualWalletId = individualWalletId,
address = address,
amount = amount.toString(),
blockchain = blockchain,
Expand All @@ -102,12 +111,13 @@ fun NavGraph(
val data: TransactScreen = backStackEntry.toRoute()
TransferScreen(
tokenId = data.tokenId,
individualWalletId = data.individualWalletId,
blockchain = data.blockchain,
address = data.address,
amount = data.amount,
onCancel = {
navController.navigate(Screen.DashBoard){
popUpTo<Screen.DashBoard>{
navController.navigate(Screen.DashBoard) {
popUpTo<Screen.DashBoard> {
inclusive = true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,37 @@ import kotlinx.serialization.Serializable
sealed class Screen() {
@Serializable
object Splash : Screen()

@Serializable
object DashBoard : Screen()

@Serializable
object AuthScreen: Screen()
object AuthScreen : Screen()

@Serializable
object OnBoarding : Screen()

}



@Serializable
data class QRCodeScanner(val blockchain: String, val tokenId : String) : Screen()
data class QRCodeScanner(
val individualWalletId: String,
val blockchain: String,
val tokenId: String
) : Screen()

@Serializable
data class Explorer(
val url: String
): Screen()
) : Screen()

@Serializable
data class TransactScreen(
val individualWalletId: String,
val address: String,
val blockchain: String,
val tokenId: String,
val amount: String
) :Screen()
) : Screen()

Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ import qrscanner.QrScanner

@Composable
fun QrCodeScannerScreen(
individualWalletId: String,
tokenId: String,
blockchain: String,
onNavigateBack: () -> Unit,
onNavigateToTransfer: (String, Double, String, String) -> Unit
onNavigateToTransfer: (String, Double, String, String,String) -> Unit
) {
var qrCodeData by remember { mutableStateOf("") }
var flashlightOn by remember { mutableStateOf(false) }
Expand All @@ -46,7 +47,7 @@ fun QrCodeScannerScreen(
val address = obj?.get("address")
val amount = obj?.get("amount")?.toDoubleOrNull()
if (address != null && amount != null){
onNavigateToTransfer(address, amount, blockchain, tokenId)
onNavigateToTransfer(address, amount, blockchain, tokenId, individualWalletId)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ import org.koin.compose.viewmodel.koinViewModel
@Composable
fun DashBoardScreen(
onNavigateToExplorer: (String) -> Unit,
onOpenQRCodeScreen: (String, String) -> Unit,
onNavigateToTransfer: (Double, String, String, String) -> Unit
onOpenQRCodeScreen: (String, String, String) -> Unit,
onNavigateToTransfer: (Double, String, String, String, String) -> Unit
) {
val viewModel: DashboardScreenViewModel = koinViewModel()

Expand All @@ -69,6 +69,10 @@ fun DashBoardScreen(
var walletId by remember {
mutableStateOf("")
}
var selectedIndividualWalletId by remember {
mutableStateOf("")
}

val scope = rememberCoroutineScope()
var selectedBottomSheetContent by mutableStateOf("")

Expand Down Expand Up @@ -103,12 +107,14 @@ fun DashBoardScreen(
)

"Send" -> TransferCryptoBottomSheetContent(
selectedIndividualWalletId = selectedIndividualWalletId,
selectedBlockchain = selectedBlockchain,
selectedTokenId = selectedTokenId,
onOpenQrScanner = {
onOpenQRCodeScreen(
selectedBlockchain,
selectedTokenId
selectedTokenId,
selectedIndividualWalletId
)
},
onCancel = {
Expand Down Expand Up @@ -150,6 +156,7 @@ fun DashBoardScreen(
walletContent = content
},
onSelectWalletId = { walletId = it },
onSelectIndividualWalletId = { selectedIndividualWalletId = it },
onSend = { blockchain, tokenId ->
scope.launch {
bottomSheetScaffoldState.bottomSheetState.expand()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ fun DashboardScreenMiddleSection(
onNavigateToExplorer: (String) -> Unit,
onRequest: (Pair<String, String>) -> Unit,
onSelectWalletId: (String) -> Unit,
onSelectIndividualWalletId: (String) -> Unit,
onSend: (String, String) -> Unit,
isWalletLoading: Boolean,
) {
Expand Down Expand Up @@ -82,7 +83,8 @@ fun DashboardScreenMiddleSection(
onNavigateToExplorer = onNavigateToExplorer,
onRequest = onRequest,
onSend = onSend,
onSelectWalletId = onSelectWalletId
onSelectWalletId = onSelectWalletId,
onSelectIndividualWalletId = onSelectIndividualWalletId
)

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ import cryptowallet.composeapp.generated.resources.qr_code

@Composable
fun TransferCryptoBottomSheetContent(
selectedIndividualWalletId: String,
selectedBlockchain: String,
selectedTokenId: String,
onCancel: () -> Unit,
onOpenQrScanner : () -> Unit,
onNavigateToTransfer: (Double,String,String, String) -> Unit
onOpenQrScanner: () -> Unit,
onNavigateToTransfer: (Double, String, String, String, String) -> Unit
) {
val clipboardManager = LocalClipboardManager.current
var address by remember {
Expand Down Expand Up @@ -94,12 +95,13 @@ fun TransferCryptoBottomSheetContent(

),
trailingIcon = {
Row(horizontalArrangement = Arrangement.SpaceBetween,
Row(
horizontalArrangement = Arrangement.SpaceBetween,

verticalAlignment = Alignment.CenterVertically,

){
AnimatedVisibility(address.isEmpty()){
) {
AnimatedVisibility(address.isEmpty()) {
IconButton(
onClick = {
val text = clipboardManager.getText()
Expand All @@ -114,7 +116,7 @@ fun TransferCryptoBottomSheetContent(
)
}
}
AnimatedVisibility(address.isNotEmpty()){
AnimatedVisibility(address.isNotEmpty()) {
IconButton(
onClick = {
address = ""
Expand All @@ -130,14 +132,14 @@ fun TransferCryptoBottomSheetContent(
}
Spacer(modifier = Modifier.width(8.dp))

AnimatedVisibility(address.isEmpty()){
AnimatedVisibility(address.isEmpty()) {
IconButton(
onClick = {
onOpenQrScanner()
}
) {
Icon(
painter = painterResource(Res.drawable.qr_code),
painter = painterResource(Res.drawable.qr_code),
contentDescription = "Clear",
tint = MaterialTheme.colorScheme.onPrimaryContainer,
modifier = Modifier.size(32.dp)
Expand All @@ -153,7 +155,13 @@ fun TransferCryptoBottomSheetContent(
CustomNumberKeyboard(
isDoneEnable = address.isNotEmpty(),
onDone = {
onNavigateToTransfer(it.toDoubleOrNull() ?: 0.0, address, selectedBlockchain, selectedTokenId)
onNavigateToTransfer(
it.toDoubleOrNull() ?: 0.0,
address,
selectedBlockchain,
selectedTokenId,
selectedIndividualWalletId
)
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ fun WalletItem(
onNavigateToExplorer: (String) -> Unit,
onRequest: (Pair<String, String>) -> Unit,
onSelectWalletId: (String) -> Unit,
onSelectIndividualWalletId: (String) -> Unit,
onSend: (String, String) -> Unit
) {
val clipboardManager = LocalClipboardManager.current
Expand Down Expand Up @@ -190,8 +191,9 @@ fun WalletItem(
onSend(
wallet.blockchain,
wallet.walletBalance?.tokenId ?: ""
)
},
)
onSelectIndividualWalletId(wallet.individualWalletId)
},
shape = CircleShape,
color = Color.Transparent
) {
Expand Down
Loading
Loading