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

PWN-8895, PWN-8776 - striga. payment api #1878

Merged
merged 13 commits into from
Jun 28, 2023
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
11 changes: 10 additions & 1 deletion app/src/main/java/org/p2p/wallet/striga/StrigaModule.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
package org.p2p.wallet.striga

import org.koin.core.module.dsl.factoryOf
import org.koin.dsl.module
import org.p2p.wallet.common.di.InjectionModule
import org.p2p.wallet.infrastructure.network.interceptor.StrigaHeaderSignatureGenerator
import org.p2p.wallet.kyc.StrigaFragmentFactory
import org.p2p.wallet.striga.di.StrigaSignupModule
import org.p2p.wallet.striga.di.StrigaWalletModule
import org.p2p.wallet.striga.kyc.StrigaKycModule

object StrigaModule : InjectionModule {

override fun create() = module {
includes(
StrigaSignupModule.create(),
StrigaKycModule.create()
StrigaKycModule.create(),
StrigaWalletModule.create()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

such a good name, man! thanks

)

factoryOf(::StrigaUserIdProvider)
factoryOf(::StrigaHeaderSignatureGenerator)
factoryOf(::StrigaFragmentFactory)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@ import retrofit2.create
import org.p2p.wallet.R
import org.p2p.wallet.common.di.InjectionModule
import org.p2p.wallet.infrastructure.network.NetworkModule.getRetrofit
import org.p2p.wallet.infrastructure.network.interceptor.StrigaHeaderSignatureGenerator
import org.p2p.wallet.infrastructure.network.interceptor.StrigaProxyApiInterceptor
import org.p2p.wallet.kyc.StrigaFragmentFactory
import org.p2p.wallet.smsinput.SmsInputContract
import org.p2p.wallet.smsinput.SmsInputFactory
import org.p2p.wallet.smsinput.striga.StrigaSmsInputInteractor
import org.p2p.wallet.smsinput.striga.StrigaSmsInputPresenter
import org.p2p.wallet.striga.StrigaUserIdProvider
import org.p2p.wallet.striga.finish.StrigaSignupFinishContract
import org.p2p.wallet.striga.finish.StrigaSignupFinishPresenter
import org.p2p.wallet.striga.onboarding.StrigaOnboardingContract
Expand Down Expand Up @@ -100,10 +97,7 @@ object StrigaSignupModule : InjectionModule {
factoryOf(::StrigaSignupDataDatabaseRepository) bind StrigaSignupDataLocalRepository::class
factoryOf(::StrigaSignupDataMapper)

factoryOf(::StrigaUserIdProvider)
factoryOf(::StrigaItemCellMapper)
factoryOf(::StrigaHeaderSignatureGenerator)
factoryOf(::StrigaFragmentFactory)
singleOf(::StrigaUserStatusRepository)
factoryOf(::StrigaUserStatusDestinationMapper)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.p2p.wallet.striga.di

import org.koin.android.ext.koin.androidContext
import org.koin.core.module.Module
import org.koin.core.module.dsl.factoryOf
import org.koin.core.module.dsl.new
import org.koin.dsl.bind
import org.koin.dsl.module
import retrofit2.create
import org.p2p.wallet.R
import org.p2p.wallet.common.di.InjectionModule
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

object StrigaWalletModule : InjectionModule {

override fun create(): Module = module {
initDataLayer()

factoryOf(::StrigaWalletInteractor)
}

private fun Module.initDataLayer() {
single<StrigaWalletApi> {
val url = androidContext().getString(R.string.strigaProxyServiceBaseUrl)
getRetrofit(
baseUrl = url,
tag = "StrigaProxyApi",
interceptor = new(::StrigaProxyApiInterceptor)
).create()
}

factoryOf(::StrigaUserWalletsMapper)
factoryOf(::StrigaWalletRepositoryMapper)
factoryOf(::StrigaWalletRemoteRepository) bind StrigaWalletRepository::class
}
}
19 changes: 19 additions & 0 deletions app/src/main/java/org/p2p/wallet/striga/model/StrigaApiError.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,24 @@ enum class StrigaApiErrorCode(val code: String) {
@SerializedName("31008")
EXCEEDED_DAILY_RESEND_SMS_LIMIT("31008"),

// Wallet errors
@SerializedName("00013")
ADDRESS_ALREADY_WHITELISTED("00013"),

@SerializedName("41004")
ADDRESS_NOT_WHITELISTED("41004"),

@SerializedName("60001")
TOO_LARGE_AMOUNT("60001"),

@SerializedName("41008")
TOO_SMALL_AMOUNT("41008"),

@SerializedName("31004")
INSUFFICIENT_BALANCE("31004"),

@SerializedName("41005")
INVALID_DESTINATION_ADDRESS("41005"),

UNKNOWN("-1")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.p2p.wallet.striga.wallet.api

import retrofit2.http.Body
import retrofit2.http.POST
import org.p2p.wallet.striga.wallet.api.request.StrigaAddWhitelistedAddressRequest
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

interface StrigaWalletApi {

@POST("v1/wallets/send/initiate/onchain")
suspend fun initiateOnchainWithdrawal(
@Body body: StrigaInitWithdrawalRequest
): StrigaInitWithdrawalResponse

@POST("v1/wallets/get/whitelisted-addresses")
suspend fun getWhitelistedAddresses(
@Body body: StrigaGetWhitelistedAddressesRequest
): StrigaWhitelistedAddressesResponse

@POST("v1/wallets/whitelist-address")
suspend fun addWhitelistedAddress(
@Body body: StrigaAddWhitelistedAddressRequest
): StrigaWhitelistedAddressItemResponse

/**
* This method returns absolutely different responses for crypto and fiat accounts
* So use it for fiat accounts only
*/
@POST("v1/wallets/account/enrich")
suspend fun enrichFiatAccount(
@Body body: StrigaEnrichAccountRequest
): StrigaEnrichFiatAccountResponse

@POST("v1/wallets/get/all")
suspend fun getUserWallets(
@Body body: StrigaUserWalletsRequest
): StrigaUserWalletsResponse

@POST("v1/wallets/send/initiate/onchain/fee-estimate")
suspend fun getOnchainWithdrawalFees(
@Body body: StrigaOnchainWithdrawalFeeRequest
): StrigaOnchainWithdrawalFeeResponse
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.p2p.wallet.striga.wallet.api.request

import com.google.gson.annotations.SerializedName

class StrigaAddWhitelistedAddressRequest(
@SerializedName("userId")
val userId: String,
@SerializedName("address")
val addressToWhitelist: String,
@SerializedName("currency")
val currency: String,
@SerializedName("network")
val network: String,
@SerializedName("label")
val label: String? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.p2p.wallet.striga.wallet.api.request

import com.google.gson.annotations.SerializedName

class StrigaEnrichAccountRequest(
@SerializedName("userId")
val userId: String,
@SerializedName("accountId")
val accountId: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.p2p.wallet.striga.wallet.api.request

import com.google.gson.annotations.SerializedName

class StrigaGetWhitelistedAddressesRequest(
@SerializedName("userId")
val userId: String,
@SerializedName("label")
val label: String? = null,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.p2p.wallet.striga.wallet.api.request

import com.google.gson.annotations.SerializedName

/**
* @param userId The Id of the user who is sending this transaction
* @param sourceAccountId The Id of the account to debit
* @param whitelistedAddressId The Id of the whitelisted destination
* @param amount The amount denominated in the smallest divisible unit of the sending currency.
* For example: cents or satoshis
*/
class StrigaInitWithdrawalRequest(
@SerializedName("userId")
val userId: String,
@SerializedName("sourceAccountId")
val sourceAccountId: String,
@SerializedName("whitelistedAddressId")
val whitelistedAddressId: String,
@SerializedName("amount")
val amountInUnits: String,
)
Original file line number Diff line number Diff line change
@@ -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,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.p2p.wallet.striga.wallet.api.request

import com.google.gson.annotations.SerializedName
import org.p2p.core.utils.MillisSinceEpoch

class StrigaUserWalletsRequest(
@SerializedName("userId")
val userId: String,
@SerializedName("startDate")
val startDate: MillisSinceEpoch,
@SerializedName("endDate")
val endDate: MillisSinceEpoch,
@SerializedName("page")
val page: Long
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.p2p.wallet.striga.wallet.api.response

import com.google.gson.annotations.SerializedName

class StrigaBlockchainNetworkResponse(
@SerializedName("name")
val name: String,
@SerializedName("contractAddress")
val contractAddress: String?,
@SerializedName("type")
val type: String?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.p2p.wallet.striga.wallet.api.response

import com.google.gson.annotations.SerializedName

class StrigaEnrichFiatAccountResponse(
@SerializedName("currency")
val currency: String,
@SerializedName("status")
val status: String,
@SerializedName("internalAccountId")
val internalAccountId: String,
@SerializedName("bankCountry")
val bankCountry: String,
@SerializedName("bankAddress")
val bankAddress: String,
@SerializedName("iban")
val iban: String,
@SerializedName("bic")
val bic: String,
@SerializedName("accountNumber")
val accountNumber: String,
@SerializedName("bankName")
val bankName: String,
@SerializedName("bankAccountHolderName")
val bankAccountHolderName: String,
@SerializedName("provider")
val provider: String,
@SerializedName("paymentType")
val paymentType: String?,
@SerializedName("domestic")
val isDomesticAccount: Boolean,
@SerializedName("routingCodeEntries")
val routingCodeEntries: List<String>,
@SerializedName("payInReference")
val payInReference: String?,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.p2p.wallet.striga.wallet.api.response

import com.google.gson.annotations.SerializedName

class StrigaInitWithdrawalResponse(
@SerializedName("challengeId")
val challengeId: String,
@SerializedName("dateExpires")
val dateExpires: String,
@SerializedName("transaction")
val transaction: WithdrawalTransactionResponse,
@SerializedName("feeEstimate")
val feeEstimate: StrigaOnchainWithdrawalFeeResponse,
) {
class WithdrawalTransactionResponse(
@SerializedName("syncedOwnerId")
val syncedOwnerId: String,
@SerializedName("sourceAccountId")
val sourceAccountId: String,
@SerializedName("parentWalletId")
val parentWalletId: String,
@SerializedName("currency")
val currency: String,
@SerializedName("amount")
val amountInUnits: String,
@SerializedName("status")
val status: String,
@SerializedName("txType")
val txType: String,
@SerializedName("blockchainDestinationAddress")
val blockchainDestinationAddress: String,
@SerializedName("blockchainNetwork")
val blockchainNetwork: StrigaBlockchainNetworkResponse,
@SerializedName("transactionCurrency")
val transactionCurrency: String,
)
}
Original file line number Diff line number Diff line change
@@ -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
)
Loading
Loading