diff --git a/app/src/main/java/org/p2p/wallet/striga/di/StrigaWalletModule.kt b/app/src/main/java/org/p2p/wallet/striga/di/StrigaWalletModule.kt index 874ad36d9d..aecc946bb0 100644 --- a/app/src/main/java/org/p2p/wallet/striga/di/StrigaWalletModule.kt +++ b/app/src/main/java/org/p2p/wallet/striga/di/StrigaWalletModule.kt @@ -13,6 +13,7 @@ import org.p2p.wallet.infrastructure.network.NetworkModule.getRetrofit import org.p2p.wallet.infrastructure.network.interceptor.StrigaProxyApiInterceptor import org.p2p.wallet.striga.wallet.api.StrigaWalletApi import org.p2p.wallet.striga.wallet.interactor.StrigaWalletInteractor +import org.p2p.wallet.striga.wallet.repository.StrigaUserWalletsMapper import org.p2p.wallet.striga.wallet.repository.StrigaWalletRemoteRepository import org.p2p.wallet.striga.wallet.repository.StrigaWalletRepository import org.p2p.wallet.striga.wallet.repository.StrigaWalletRepositoryMapper @@ -35,6 +36,7 @@ object StrigaWalletModule : InjectionModule { ).create() } + factoryOf(::StrigaUserWalletsMapper) factoryOf(::StrigaWalletRepositoryMapper) factoryOf(::StrigaWalletRemoteRepository) bind StrigaWalletRepository::class } diff --git a/app/src/main/java/org/p2p/wallet/striga/wallet/api/StrigaWalletApi.kt b/app/src/main/java/org/p2p/wallet/striga/wallet/api/StrigaWalletApi.kt index f475059897..2af7a5f5f5 100644 --- a/app/src/main/java/org/p2p/wallet/striga/wallet/api/StrigaWalletApi.kt +++ b/app/src/main/java/org/p2p/wallet/striga/wallet/api/StrigaWalletApi.kt @@ -6,9 +6,11 @@ import org.p2p.wallet.striga.wallet.api.request.StrigaAddWhitelistedAddressReque import org.p2p.wallet.striga.wallet.api.request.StrigaEnrichAccountRequest import org.p2p.wallet.striga.wallet.api.request.StrigaGetWhitelistedAddressesRequest import org.p2p.wallet.striga.wallet.api.request.StrigaInitWithdrawalRequest +import org.p2p.wallet.striga.wallet.api.request.StrigaOnchainWithdrawalFeeRequest import org.p2p.wallet.striga.wallet.api.request.StrigaUserWalletsRequest import org.p2p.wallet.striga.wallet.api.response.StrigaEnrichFiatAccountResponse import org.p2p.wallet.striga.wallet.api.response.StrigaInitWithdrawalResponse +import org.p2p.wallet.striga.wallet.api.response.StrigaOnchainWithdrawalFeeResponse import org.p2p.wallet.striga.wallet.api.response.StrigaUserWalletsResponse import org.p2p.wallet.striga.wallet.api.response.StrigaWhitelistedAddressItemResponse import org.p2p.wallet.striga.wallet.api.response.StrigaWhitelistedAddressesResponse @@ -35,8 +37,17 @@ interface StrigaWalletApi { * So use it for fiat accounts only */ @POST("v1/wallets/account/enrich") - suspend fun enrichFiatAccount(@Body body: StrigaEnrichAccountRequest): StrigaEnrichFiatAccountResponse + suspend fun enrichFiatAccount( + @Body body: StrigaEnrichAccountRequest + ): StrigaEnrichFiatAccountResponse @POST("v1/wallets/get/all") - suspend fun getUserWallets(@Body body: StrigaUserWalletsRequest): StrigaUserWalletsResponse + suspend fun getUserWallets( + @Body body: StrigaUserWalletsRequest + ): StrigaUserWalletsResponse + + @POST("v1/wallets/send/initiate/onchain/fee-estimate") + suspend fun getOnchainWithdrawalFees( + @Body body: StrigaOnchainWithdrawalFeeRequest + ): StrigaOnchainWithdrawalFeeResponse } diff --git a/app/src/main/java/org/p2p/wallet/striga/wallet/api/request/StrigaOnchainWithdrawalFeeRequest.kt b/app/src/main/java/org/p2p/wallet/striga/wallet/api/request/StrigaOnchainWithdrawalFeeRequest.kt new file mode 100644 index 0000000000..093cf2b8e4 --- /dev/null +++ b/app/src/main/java/org/p2p/wallet/striga/wallet/api/request/StrigaOnchainWithdrawalFeeRequest.kt @@ -0,0 +1,18 @@ +package org.p2p.wallet.striga.wallet.api.request + +import com.google.gson.annotations.SerializedName + +/** + * @param amountInUnits The amount denominated in the smallest divisible unit of the sending currency. + * For example: cents or satoshis + */ +class StrigaOnchainWithdrawalFeeRequest( + @SerializedName("userId") + val userId: String, + @SerializedName("sourceAccountId") + val sourceAccountId: String, + @SerializedName("whitelistedAddressId") + val whitelistedAddressId: String, + @SerializedName("amount") + val amountInUnits: String, +) diff --git a/app/src/main/java/org/p2p/wallet/striga/wallet/api/response/StrigaInitWithdrawalResponse.kt b/app/src/main/java/org/p2p/wallet/striga/wallet/api/response/StrigaInitWithdrawalResponse.kt index b7a0c7ec8b..06f2cbab71 100644 --- a/app/src/main/java/org/p2p/wallet/striga/wallet/api/response/StrigaInitWithdrawalResponse.kt +++ b/app/src/main/java/org/p2p/wallet/striga/wallet/api/response/StrigaInitWithdrawalResponse.kt @@ -10,7 +10,7 @@ class StrigaInitWithdrawalResponse( @SerializedName("transaction") val transaction: WithdrawalTransactionResponse, @SerializedName("feeEstimate") - val feeEstimate: WithdrawalFeeEstimateResponse, + val feeEstimate: StrigaOnchainWithdrawalFeeResponse, ) { class WithdrawalTransactionResponse( @SerializedName("syncedOwnerId") @@ -34,21 +34,4 @@ class StrigaInitWithdrawalResponse( @SerializedName("transactionCurrency") val transactionCurrency: String, ) - - class WithdrawalFeeEstimateResponse( - @SerializedName("totalFee") - val totalFee: String, - @SerializedName("networkFee") - val networkFee: String, - @SerializedName("ourFee") - val ourFee: String, - @SerializedName("theirFee") - val theirFee: String, - @SerializedName("feeCurrency") - val feeCurrency: String, - @SerializedName("gasLimit") - val gasLimit: String, - @SerializedName("gasPrice") - val gasPrice: String, - ) } diff --git a/app/src/main/java/org/p2p/wallet/striga/wallet/api/response/StrigaOnchainWithdrawalFeeResponse.kt b/app/src/main/java/org/p2p/wallet/striga/wallet/api/response/StrigaOnchainWithdrawalFeeResponse.kt new file mode 100644 index 0000000000..d5093bc7cd --- /dev/null +++ b/app/src/main/java/org/p2p/wallet/striga/wallet/api/response/StrigaOnchainWithdrawalFeeResponse.kt @@ -0,0 +1,20 @@ +package org.p2p.wallet.striga.wallet.api.response + +import com.google.gson.annotations.SerializedName + +data class StrigaOnchainWithdrawalFeeResponse( + @SerializedName("totalFee") + val totalFee: String, + @SerializedName("networkFee") + val networkFee: String, + @SerializedName("ourFee") + val ourFee: String, + @SerializedName("theirFee") + val theirFee: String, + @SerializedName("feeCurrency") + val feeCurrency: String, + @SerializedName("gasLimit") + val gasLimit: String, + @SerializedName("gasPrice") + val gasPrice: String +) diff --git a/app/src/main/java/org/p2p/wallet/striga/wallet/models/StrigaInitWithdrawalDetails.kt b/app/src/main/java/org/p2p/wallet/striga/wallet/models/StrigaInitWithdrawalDetails.kt index 923c768e5f..3a35134fe1 100644 --- a/app/src/main/java/org/p2p/wallet/striga/wallet/models/StrigaInitWithdrawalDetails.kt +++ b/app/src/main/java/org/p2p/wallet/striga/wallet/models/StrigaInitWithdrawalDetails.kt @@ -2,7 +2,6 @@ package org.p2p.wallet.striga.wallet.models import android.os.Parcelable import org.threeten.bp.ZonedDateTime -import java.math.BigDecimal import java.math.BigInteger import kotlinx.parcelize.Parcelize import org.p2p.wallet.striga.wallet.models.ids.StrigaAccountId @@ -14,7 +13,7 @@ data class StrigaInitWithdrawalDetails( val challengeId: StrigaWithdrawalChallengeId, val dateExpires: ZonedDateTime, val transaction: WithdrawalTransactionDetails, - val feeEstimate: WithdrawalFeeEstimateDetails, + val feeEstimate: StrigaOnchainWithdrawalFees, ) : Parcelable { /** @@ -34,15 +33,4 @@ data class StrigaInitWithdrawalDetails( val blockchainNetwork: StrigaBlockchainNetworkInfo, val transactionCurrency: StrigaNetworkCurrency, ) : Parcelable - - @Parcelize - class WithdrawalFeeEstimateDetails( - val totalFee: BigInteger, - val networkFee: BigInteger, - val ourFee: BigInteger, - val theirFee: BigInteger, - val feeCurrency: StrigaNetworkCurrency, - val gasLimit: BigInteger, - val gasPrice: BigDecimal, - ) : Parcelable } diff --git a/app/src/main/java/org/p2p/wallet/striga/wallet/models/StrigaOnchainWithdrawalFees.kt b/app/src/main/java/org/p2p/wallet/striga/wallet/models/StrigaOnchainWithdrawalFees.kt new file mode 100644 index 0000000000..38f7cdf52c --- /dev/null +++ b/app/src/main/java/org/p2p/wallet/striga/wallet/models/StrigaOnchainWithdrawalFees.kt @@ -0,0 +1,17 @@ +package org.p2p.wallet.striga.wallet.models + +import android.os.Parcelable +import java.math.BigDecimal +import java.math.BigInteger +import kotlinx.parcelize.Parcelize + +@Parcelize +data class StrigaOnchainWithdrawalFees( + val totalFee: BigInteger, + val networkFee: BigInteger, + val ourFee: BigInteger, + val theirFee: BigInteger, + val feeCurrency: StrigaNetworkCurrency, + val gasLimit: BigInteger, + val gasPrice: BigDecimal, +) : Parcelable diff --git a/app/src/main/java/org/p2p/wallet/striga/wallet/repository/StrigaWalletRemoteRepository.kt b/app/src/main/java/org/p2p/wallet/striga/wallet/repository/StrigaWalletRemoteRepository.kt index 890fc4d749..e5fc59e1ab 100644 --- a/app/src/main/java/org/p2p/wallet/striga/wallet/repository/StrigaWalletRemoteRepository.kt +++ b/app/src/main/java/org/p2p/wallet/striga/wallet/repository/StrigaWalletRemoteRepository.kt @@ -11,10 +11,12 @@ import org.p2p.wallet.striga.wallet.api.request.StrigaAddWhitelistedAddressReque import org.p2p.wallet.striga.wallet.api.request.StrigaEnrichAccountRequest import org.p2p.wallet.striga.wallet.api.request.StrigaGetWhitelistedAddressesRequest import org.p2p.wallet.striga.wallet.api.request.StrigaInitWithdrawalRequest +import org.p2p.wallet.striga.wallet.api.request.StrigaOnchainWithdrawalFeeRequest import org.p2p.wallet.striga.wallet.api.request.StrigaUserWalletsRequest import org.p2p.wallet.striga.wallet.models.StrigaFiatAccountDetails import org.p2p.wallet.striga.wallet.models.StrigaInitWithdrawalDetails import org.p2p.wallet.striga.wallet.models.StrigaNetworkCurrency +import org.p2p.wallet.striga.wallet.models.StrigaOnchainWithdrawalFees import org.p2p.wallet.striga.wallet.models.StrigaUserWallet import org.p2p.wallet.striga.wallet.models.StrigaWhitelistedAddressItem import org.p2p.wallet.striga.wallet.models.ids.StrigaAccountId @@ -49,6 +51,28 @@ class StrigaWalletRemoteRepository( } } + override suspend fun getOnchainWithdrawalFees( + sourceAccountId: StrigaAccountId, + whitelistedAddressId: StrigaWhitelistedAddressId, + amount: BigInteger, + ): StrigaDataLayerResult { + return try { + val request = StrigaOnchainWithdrawalFeeRequest( + userId = strigaUserIdProvider.getUserIdOrThrow(), + sourceAccountId = sourceAccountId.value, + whitelistedAddressId = whitelistedAddressId.value, + amountInUnits = amount.toString() + ) + val response = api.getOnchainWithdrawalFees(request) + return mapper.fromNetwork(response).toSuccessResult() + } catch (error: Throwable) { + StrigaDataLayerError.from( + error = error, + default = StrigaDataLayerError.InternalError(error) + ) + } + } + override suspend fun whitelistAddress( address: String, currency: StrigaNetworkCurrency, diff --git a/app/src/main/java/org/p2p/wallet/striga/wallet/repository/StrigaWalletRepository.kt b/app/src/main/java/org/p2p/wallet/striga/wallet/repository/StrigaWalletRepository.kt index 691f1a4b2f..af565c7c91 100644 --- a/app/src/main/java/org/p2p/wallet/striga/wallet/repository/StrigaWalletRepository.kt +++ b/app/src/main/java/org/p2p/wallet/striga/wallet/repository/StrigaWalletRepository.kt @@ -5,6 +5,7 @@ import org.p2p.wallet.striga.model.StrigaDataLayerResult import org.p2p.wallet.striga.wallet.models.StrigaFiatAccountDetails import org.p2p.wallet.striga.wallet.models.StrigaInitWithdrawalDetails import org.p2p.wallet.striga.wallet.models.StrigaNetworkCurrency +import org.p2p.wallet.striga.wallet.models.StrigaOnchainWithdrawalFees import org.p2p.wallet.striga.wallet.models.StrigaUserWallet import org.p2p.wallet.striga.wallet.models.StrigaWhitelistedAddressItem import org.p2p.wallet.striga.wallet.models.ids.StrigaAccountId @@ -63,4 +64,10 @@ interface StrigaWalletRepository { ): StrigaDataLayerResult suspend fun getUserWallet(): StrigaDataLayerResult + + suspend fun getOnchainWithdrawalFees( + sourceAccountId: StrigaAccountId, + whitelistedAddressId: StrigaWhitelistedAddressId, + amount: BigInteger + ): StrigaDataLayerResult } diff --git a/app/src/main/java/org/p2p/wallet/striga/wallet/repository/StrigaWalletRepositoryMapper.kt b/app/src/main/java/org/p2p/wallet/striga/wallet/repository/StrigaWalletRepositoryMapper.kt index 2fe475ed7d..ccb220da75 100644 --- a/app/src/main/java/org/p2p/wallet/striga/wallet/repository/StrigaWalletRepositoryMapper.kt +++ b/app/src/main/java/org/p2p/wallet/striga/wallet/repository/StrigaWalletRepositoryMapper.kt @@ -6,15 +6,17 @@ import org.p2p.core.utils.toBigIntegerOrZero import org.p2p.wallet.striga.wallet.api.response.StrigaBlockchainNetworkResponse import org.p2p.wallet.striga.wallet.api.response.StrigaEnrichFiatAccountResponse import org.p2p.wallet.striga.wallet.api.response.StrigaInitWithdrawalResponse +import org.p2p.wallet.striga.wallet.api.response.StrigaOnchainWithdrawalFeeResponse import org.p2p.wallet.striga.wallet.api.response.StrigaWhitelistedAddressItemResponse import org.p2p.wallet.striga.wallet.api.response.StrigaWhitelistedAddressesResponse -import org.p2p.wallet.striga.wallet.models.StrigaFiatAccountStatus import org.p2p.wallet.striga.wallet.models.StrigaBlockchainNetworkInfo import org.p2p.wallet.striga.wallet.models.StrigaFiatAccountDetails +import org.p2p.wallet.striga.wallet.models.StrigaFiatAccountStatus import org.p2p.wallet.striga.wallet.models.StrigaInitWithdrawalDetails import org.p2p.wallet.striga.wallet.models.StrigaNetworkCurrency import org.p2p.wallet.striga.wallet.models.StrigaOnchainTxStatus import org.p2p.wallet.striga.wallet.models.StrigaOnchainTxType +import org.p2p.wallet.striga.wallet.models.StrigaOnchainWithdrawalFees import org.p2p.wallet.striga.wallet.models.StrigaWhitelistedAddressItem import org.p2p.wallet.striga.wallet.models.ids.StrigaAccountId import org.p2p.wallet.striga.wallet.models.ids.StrigaWalletId @@ -56,6 +58,10 @@ class StrigaWalletRepositoryMapper { ) } + fun fromNetwork(response: StrigaOnchainWithdrawalFeeResponse): StrigaOnchainWithdrawalFees { + return response.toDetailsFeeEstimate() + } + fun fromNetwork(item: StrigaWhitelistedAddressItemResponse): StrigaWhitelistedAddressItem { return StrigaWhitelistedAddressItem( id = StrigaWhitelistedAddressId(item.id), @@ -74,9 +80,8 @@ class StrigaWalletRepositoryMapper { ) } - private fun StrigaInitWithdrawalResponse.WithdrawalFeeEstimateResponse.toDetailsFeeEstimate(): - StrigaInitWithdrawalDetails.WithdrawalFeeEstimateDetails { - return StrigaInitWithdrawalDetails.WithdrawalFeeEstimateDetails( + private fun StrigaOnchainWithdrawalFeeResponse.toDetailsFeeEstimate(): StrigaOnchainWithdrawalFees { + return StrigaOnchainWithdrawalFees( totalFee = totalFee.toBigIntegerOrZero(), networkFee = networkFee.toBigIntegerOrZero(), ourFee = ourFee.toBigIntegerOrZero(), diff --git a/app/src/main/res/values/environment_config.xml b/app/src/main/res/values/environment_config.xml index c195d15dc9..f7376a616c 100644 --- a/app/src/main/res/values/environment_config.xml +++ b/app/src/main/res/values/environment_config.xml @@ -42,7 +42,7 @@ https://oncall.keyapp.org/ - https://payment.keyapp.org/striga/api/ - https://payment.key.app/striga/api/ + https://payment-rust.keyapp.org/striga/api/v1/ + https://payment-rust.keyapp.org/striga/api/v1/