-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from Dev-Pasaka/dev
Added transactions
- Loading branch information
Showing
21 changed files
with
550 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...oseApp/src/commonMain/kotlin/org/example/data/remote/dto/response/getTransactions/Data.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.example.data.remote.dto.response.getTransactions | ||
|
||
import kotlinx.serialization.Serializable | ||
import org.example.domain.model.Transaction | ||
|
||
@Serializable | ||
data class Data( | ||
val amount: String, | ||
val blockchain: String, | ||
val feeLevel: String, | ||
val id: String, | ||
val receiverAddress: String, | ||
val senderAddress: String, | ||
val status: String, | ||
val timestamp: String | ||
){ | ||
fun toTransaction(): Transaction { | ||
return Transaction( | ||
amount = amount, | ||
blockchain = blockchain, | ||
feeLevel = feeLevel, | ||
id = id, | ||
receiverAddress = receiverAddress, | ||
senderAddress = senderAddress, | ||
status = status, | ||
timestamp = timestamp | ||
|
||
) | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...monMain/kotlin/org/example/data/remote/dto/response/getTransactions/GetTransactionsRes.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.example.data.remote.dto.response.getTransactions | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class GetTransactionsRes( | ||
val `data`: List<Data>, | ||
val httpStatusCode: Int, | ||
val message: String, | ||
val status: Boolean | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
composeApp/src/commonMain/kotlin/org/example/domain/model/Transaction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.example.domain.model | ||
|
||
data class Transaction( | ||
val amount: String, | ||
val blockchain: String, | ||
val feeLevel: String, | ||
val id: String, | ||
val receiverAddress: String, | ||
val senderAddress: String, | ||
val status: String, | ||
val timestamp: String, | ||
val transactionType: String = "" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
composeApp/src/commonMain/kotlin/org/example/domain/usecase/wallet/GetTransactionUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.example.domain.usecase.wallet | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.flow | ||
import org.example.common.Constants | ||
import org.example.common.Resource | ||
import org.example.domain.model.Transaction | ||
import org.example.domain.repository.KeyValueStorage | ||
import org.example.domain.repository.WalletRepository | ||
|
||
class GetTransactionUseCase( | ||
private val repository: WalletRepository, | ||
private val keyValueStorage: KeyValueStorage | ||
) { | ||
suspend operator fun invoke(): Flow<Resource<List<Transaction>>> = flow { | ||
emit(Resource.Loading()) | ||
try { | ||
val walletId = keyValueStorage.getString(Constants.WALLET_ID) ?: "" | ||
val transactions = repository.getTransactions(walletId) | ||
if (transactions.status) { | ||
emit( | ||
Resource.Success( | ||
data = transactions.data.map { it.toTransaction() }, | ||
message = "Transactions retrieved successfully" | ||
) | ||
) | ||
} else { | ||
emit(Resource.Error(transactions.message)) | ||
} | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
emit(Resource.Error(e.message ?: "An error occurred")) | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
composeApp/src/commonMain/kotlin/org/example/domain/usecase/wallet/GetWalletUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.