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

Server:Modified transactions type and origin #14

Merged
merged 1 commit into from
Jan 6, 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 @@ -9,21 +9,27 @@ data class Data(
val blockchain: String,
val feeLevel: String,
val id: String,
val receiverAddress: String,
val senderAddress: String,
val destinationAddress: String,
val sourceAddress: String,
val status: String,
val timestamp: String
val timestamp: String,
val transactionType: String
){
fun toTransaction(): Transaction {
return Transaction(
amount = amount,
blockchain = blockchain,
feeLevel = feeLevel,
id = id,
receiverAddress = receiverAddress,
senderAddress = senderAddress,
receiverAddress = destinationAddress,
senderAddress = sourceAddress,
status = status,
timestamp = timestamp
timestamp = timestamp,
transactionType = when(transactionType){
"INBOUND" -> "IN"
"OUTBOUND" -> "OUT"
else -> ""
}

)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
package example.com.data.datasource.remote.response.getTransactions

import kotlinx.serialization.Serializable
import org.example.presentation.dto.response.TransactionRes

@Serializable
data class GetAllTransactionsRes(
val data: Data
)
){
fun toTransactionRes() = TransactionRes(
httpStatusCode = 200,
status = true,
message = "Transactions retrieved successfully",
data = data.transactions.map { it.toTransaction() }
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package example.com.data.datasource.remote.response.getTransactions

import kotlinx.serialization.Serializable
import org.example.presentation.dto.response.TransactionData

@Serializable
data class Transaction(
Expand All @@ -18,7 +19,7 @@ data class Transaction(
val errorDetails: String? = null,
val errorReason: String? = null,
val estimatedFee: EstimatedFee? = null,
val feeLevel: FeeLevel? = null,
val feeLevel: String? = null,
val firstConfirmDate: String,
val id: String,
val networkFee: String,
Expand All @@ -35,4 +36,17 @@ data class Transaction(
val updateDate: String,
val userId: String? = null,
val walletId: String
)
){
fun toTransaction() = TransactionData(
id = id,
sourceAddress = sourceAddress,
destinationAddress = destinationAddress,
amount = amounts?.get(0) ?: "",
feeLevel = feeLevel ?: "0.0",
blockchain = blockchain,
status = state,
timestamp = createDate,
networkFee = networkFee,
transactionType = transactionType
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import io.ktor.client.statement.*
import io.ktor.http.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import kotlinx.serialization.builtins.ListSerializer
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.json.Json
import org.example.data.datasource.remote.requests.CancelTransactionReq
import org.example.data.datasource.remote.response.createWalletSets.CreateWalletSetsRes
import org.example.data.datasource.remote.response.getWalletSet.GetWalletSetRes
Expand Down Expand Up @@ -175,6 +178,15 @@ class CircleRepositoryImpl(
}.body<GetAllTransactionsRes>()
}

override suspend fun getAllTransactionsInWallet(walletIds: List<String>):GetAllTransactionsRes = withContext(Dispatchers.IO) {
val formattedStr = walletIds.joinToString(",") { "[$it]" }
println(formattedStr)
api.client.get(urlString = "${circle.baseUrl}transactions") {
header(HttpHeaders.Authorization, "Bearer ${circle.apiKey}")
parameter("walletIds", formattedStr)
}.body<GetAllTransactionsRes>()
}

override suspend fun getTransaction(id: String): GetTransactionRes = withContext(Dispatchers.IO) {
api.client.get(urlString = "${circle.baseUrl}transactions/$id") {
header(HttpHeaders.Authorization, "Bearer ${circle.apiKey}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,20 +175,17 @@ class TransactionRepositoryImpl(
Dispatchers.IO
) {

val wallet = walletCollection.find(Filters.eq(Wallet::id.name, walletId)).firstOrNull()
?: return@withContext TransactionRes(
httpStatusCode = 400,
status = false,
message = "Wallet not found",
)
val wallet = walletCollection.find(Filters.eq(Wallet::id.name, walletId)).toList()
if (wallet.isEmpty()) return@withContext TransactionRes(
httpStatusCode = 400,
status = false,
message = "Wallet not found",
)

val transactions = transactionCollection.find(Filters.eq(Wallet::walletId.name, wallet.walletId)).toList()
return@withContext TransactionRes(
httpStatusCode = 200,
status = true,
message = "Transactions retrieved successfully",
data = transactions.map { it.toTransaction() }
val transactions = circleRepository.getAllTransactionsInWallet(
walletIds = wallet.map { it.walletId }
)
return@withContext transactions.toTransactionRes()
}


Expand Down
13 changes: 1 addition & 12 deletions server/src/main/kotlin/org/example/domain/entries/Transaction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,7 @@ data class Transaction(
val blockchain: String,
val status: TransactionStatus = TransactionStatus.PENDING,
val timestamp: String = TimeUtils.getCurrentUtcTimestamp().toString()
){
fun toTransaction() = TransactionData(
id = id,
amount = amounts.first(),
senderAddress = senderAddress,
receiverAddress = destinationAddress,
feeLevel = feeLevel,
blockchain = blockchain,
status = status.name,
timestamp = timestamp
)
}
)

enum class TransactionStatus{
PENDING,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface CircleRepository {
suspend fun getWalletBalance(walletId:String): GetWalletBalanceRes
suspend fun transferCrypto(body: TransferCryptoReq): TransferCryptoRes
suspend fun getAllTransactions():GetAllTransactionsRes
suspend fun getAllTransactionsInWallet(walletIds: List<String>):GetAllTransactionsRes
suspend fun getTransaction(id:String): GetTransactionRes
suspend fun validateAddress(walletAddress:String, blockchain: String):ValidateAddressRes
suspend fun estimateGasFee(amount:String, destinationAddress:String, sourceAddress:String, blockchain: String):EstimateGasFeeRes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ data class TransactionRes(
@Serializable
data class TransactionData(
val id: String,
val senderAddress: String,
val receiverAddress: String,
val sourceAddress: String,
val destinationAddress: String,
val amount: String,
val feeLevel: String,
val blockchain: String,
val status: String,
val timestamp: String,
val networkFee: String,
val transactionType: String = ""
)

Loading