Skip to content

Commit

Permalink
merge(#27): remove Passbase
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubsta authored Feb 22, 2023
2 parents d18efba + aa265e7 commit d5ba8ae
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 168 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ allprojects {
google()
mavenCentral()
maven { url "https://jitpack.io" }
maven { url 'https://button.passbase.com/__android' }
}
}

Expand Down
8 changes: 3 additions & 5 deletions rampsdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ android {
defaultConfig {
minSdkVersion 21
targetSdkVersion 32
versionCode 15
versionName "2.0.1"

versionCode 16
versionName "3.0.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
buildConfigField 'String', 'VERSION', "\"${defaultConfig.versionName}\""
Expand Down Expand Up @@ -61,7 +60,6 @@ dependencies {
implementation 'com.squareup.moshi:moshi-kotlin:1.14.0'

kapt("com.squareup.moshi:moshi-kotlin-codegen:1.14.0")
implementation 'com.passbase:passbase_sdk:2.13.6'

def dagger_version = "2.40.4"
implementation "com.google.dagger:dagger:$dagger_version"
Expand All @@ -86,7 +84,7 @@ afterEvaluate {
from components.release
groupId = 'com.github.RampNetwork'
artifactId = 'ramp-sdk-android'
version = '2.0.1'
version = '3.0.0'
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions rampsdk/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
package="network.ramp.sdk">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" android:required="true"/>

<application
android:label="@string/app_name"
Expand Down
24 changes: 0 additions & 24 deletions rampsdk/src/main/java/network/ramp/sdk/events/model/Events.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,6 @@ internal data class WidgetConfigFailed(var payload: String?) : Event(EventType.W
@JsonClass(generateAdapter = true)
internal data class BackButtonPressed(var payload: String?) : Event(EventType.BACK_BUTTON_PRESSED)

@JsonClass(generateAdapter = true)
internal data class KycInit(var payload: KycInitPayload) : Event(EventType.KYC_INIT)

@JsonClass(generateAdapter = true)
internal data class KycStarted(var payload: KycStartedPayload) : Event(EventType.KYC_STARTED)

@JsonClass(generateAdapter = true)
internal data class KycFinished(var payload: KycFinishedPayload) : Event(EventType.KYC_FINISHED)

@JsonClass(generateAdapter = true)
internal data class KycAborted(var payload: KycAbortedPayload) : Event(EventType.KYC_ABORTED)

@JsonClass(generateAdapter = true)
internal data class KycSubmitted(var payload: KycSubmittedPayload) : Event(EventType.KYC_SUBMITTED)

@JsonClass(generateAdapter = true)
internal data class KycError(var payload: KycErrorPayload) : Event(EventType.KYC_ERROR)

@JsonClass(generateAdapter = true)
internal data class SendCrypto(
var payload: SendCryptoPayload,
Expand All @@ -68,17 +50,11 @@ internal data class OfframpSaleCreated(var payload: OfframpSaleCreatedPayload) :
enum class EventType {
WIDGET_CLOSE,
OPEN_LINK,
KYC_INIT,
WIDGET_CONFIG_DONE,
WIDGET_CONFIG_FAILED,
BACK_BUTTON_PRESSED,
PURCHASE_FAILED,
PURCHASE_CREATED,
KYC_STARTED,
KYC_FINISHED,
KYC_ABORTED,
KYC_SUBMITTED,
KYC_ERROR,
SEND_CRYPTO,
SEND_CRYPTO_RESULT,
OFFRAMP_SALE_CREATED
Expand Down
31 changes: 0 additions & 31 deletions rampsdk/src/main/java/network/ramp/sdk/events/model/Payloads.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,6 @@ data class WidgetClosePayload(
val rejectText: String? = null
)

@JsonClass(generateAdapter = true)
internal data class KycInitPayload(
val email: String,
val countryCode: String,
val verificationId: Int,
val metaData: String?,
val apiKey: String,
val provider: String
)

@JsonClass(generateAdapter = true)
internal data class KycStartedPayload(var verificationId: Int = 0)

@JsonClass(generateAdapter = true)
internal data class KycFinishedPayload(
var verificationId: Int = 0,
var identityAccessKey: String = ""
)

@JsonClass(generateAdapter = true)
internal data class KycAbortedPayload(var verificationId: Int = 0)

@JsonClass(generateAdapter = true)
internal data class KycSubmittedPayload(
var verificationId: Int = 0,
var identityAccessKey: String = ""
)

@JsonClass(generateAdapter = true)
internal data class KycErrorPayload(var verificationId: Int = 0)

@JsonClass(generateAdapter = true)
internal data class SendCryptoPayload(
var assetInfo: Asset,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package network.ramp.sdk.ui.activity

import android.content.Context
import com.passbase.passbase_sdk.PassbaseSDK
import com.passbase.passbase_sdk.PassbaseSDKListener
import com.squareup.moshi.Moshi
import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
Expand All @@ -11,19 +8,18 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import network.ramp.sdk.BuildConfig
import network.ramp.sdk.events.EventBus
import network.ramp.sdk.events.model.*
import network.ramp.sdk.facade.Config
import network.ramp.sdk.utils.UrlSafeChecker
import timber.log.Timber

internal class RampPresenter(
private val view: Contract.View,
private val context: Context
) : Contract.Presenter, PassbaseSDKListener {
private val view: Contract.View
) : Contract.Presenter {
private val scope = CoroutineScope(Dispatchers.Main + SupervisorJob())

private var kycInitPayload: KycInitPayload? = null
private var configDone = false

private val moshi: Moshi = Moshi.Builder()
Expand All @@ -36,18 +32,12 @@ internal class RampPresenter(
.withSubtype(WidgetConfigDone::class.java, EventType.WIDGET_CONFIG_DONE.name)
.withSubtype(WidgetConfigFailed::class.java, EventType.WIDGET_CONFIG_FAILED.name)
.withSubtype(BackButtonPressed::class.java, EventType.BACK_BUTTON_PRESSED.name)
.withSubtype(KycInit::class.java, EventType.KYC_INIT.name)
.withSubtype(KycStarted::class.java, EventType.KYC_STARTED.name)
.withSubtype(KycFinished::class.java, EventType.KYC_FINISHED.name)
.withSubtype(KycAborted::class.java, EventType.KYC_ABORTED.name)
.withSubtype(KycSubmitted::class.java, EventType.KYC_SUBMITTED.name)
.withSubtype(SendCrypto::class.java, EventType.SEND_CRYPTO.name)
.withSubtype(SendCryptoResult::class.java, EventType.SEND_CRYPTO_RESULT.name)
.withSubtype(
OfframpSaleCreated::class.java,
EventType.OFFRAMP_SALE_CREATED.name
)
.withSubtype(KycError::class.java, EventType.KYC_ERROR.name)
)
.add(KotlinJsonAdapterFactory())
.build()
Expand Down Expand Up @@ -93,12 +83,6 @@ internal class RampPresenter(
}

}
EventType.KYC_INIT -> {
(event as? KycInit)?.payload?.let {
Timber.d("kycInit $it ")
runPassbase(it)
}
}

EventType.PURCHASE_FAILED -> {
scope.launch {
Expand Down Expand Up @@ -162,79 +146,12 @@ internal class RampPresenter(
if (config.useSendCryptoCallback == true) Config.SEND_CRYPTO_CALLBACK_VERSION.toString() else ""
) +
"&variant=$VARIANT" +
"&deepLinkScheme=$DEEP_LINK_SCHEME"
}

private fun runPassbase(kycInit: KycInitPayload) {
val passbaseRef = PassbaseSDK(context)

kycInitPayload = kycInit
passbaseRef.initialize(
kycInit.apiKey
)
passbaseRef.prefillCountry = kycInit.countryCode
passbaseRef.prefillUserEmail = kycInit.email
kycInit.metaData?.let {
passbaseRef.metaData = it
}
passbaseRef.callback(this)
passbaseRef.startVerification()
}

override fun onError(errorCode: String) {

Timber.e("Passbase onError $errorCode")

val eventJson = moshi
.adapter(Event::class.java)
.toJson(
when (errorCode) {
PASSBASE_CANCELLED_BY_USER -> KycAborted(
KycAbortedPayload(
kycInitPayload?.verificationId ?: 0
)
)
else -> KycError(KycErrorPayload(kycInitPayload?.verificationId ?: 0))
}
)

view.sendPostMessage(eventJson)
}

override fun onFinish(identityAccessKey: String) {
val eventJson = moshi
.adapter(Event::class.java)
.toJson(
KycFinished(
KycFinishedPayload(
kycInitPayload?.verificationId ?: 0,
identityAccessKey
)
)
)
view.sendPostMessage(eventJson)
}
"&deepLinkScheme=$DEEP_LINK_SCHEME" +
"&sdkType=ANDROID" +
"&sdkVersion=${BuildConfig.VERSION}"

override fun onSubmitted(identityAccessKey: String) {
postMessage(
KycSubmitted(
KycSubmittedPayload(
kycInitPayload?.verificationId ?: 0,
identityAccessKey
)
)
)
}

override fun onStart() {
postMessage(
KycStarted(
KycStartedPayload(
kycInitPayload?.verificationId ?: 0
)
)
)
}

fun onBackPressed(systemOnBackPressed: () -> Unit) {
if (configDone)
Expand Down Expand Up @@ -264,6 +181,5 @@ internal class RampPresenter(
const val VARIANT = "sdk-mobile"
const val DEEP_LINK_SCHEME = "ramp"
const val LABEL_KEY_TYPE = "type"
const val PASSBASE_CANCELLED_BY_USER = "CANCELLED_BY_USER"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package network.ramp.sdk.ui.activity


import android.content.Intent
import android.content.pm.PackageManager
import android.os.Bundle
import android.webkit.WebView
import androidx.appcompat.app.AppCompatActivity
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand All @@ -16,6 +18,7 @@ import network.ramp.sdk.facade.RampSDK.Companion.CONFIG_EXTRA
import timber.log.Timber
import network.ramp.sdk.events.model.*
import network.ramp.sdk.facade.RampSDK.Companion.URL_EXTRA
import network.ramp.sdk.ui.webview.RampWidgetWebViewChromeClient.Companion.CAMERA_PERMISSION_REQUEST
import network.ramp.sdk.ui.webview.RampWidgetWebViewClient


Expand All @@ -40,12 +43,14 @@ internal class RampWidgetActivity : AppCompatActivity(), Contract.View {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = WidgetActivityBinding.inflate(layoutInflater)

setContentView(binding.root)

rampPresenter = RampPresenter(this, this)
binding.webView.setupWebView(RampWidgetWebViewClient(binding.progressBar), jsInterface)

rampPresenter = RampPresenter(this)
binding.webView.setupWebView(
this,
RampWidgetWebViewClient(binding.progressBar),
jsInterface
)
intent.extras?.getParcelable<Config>(CONFIG_EXTRA)?.let {
config = it
} ?: returnOnError("Config object cannot be null")
Expand Down Expand Up @@ -119,6 +124,22 @@ internal class RampWidgetActivity : AppCompatActivity(), Contract.View {
finish()
}

override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)

if (requestCode == CAMERA_PERMISSION_REQUEST) {
for (i in grantResults.indices) {
if (grantResults[i] == PackageManager.PERMISSION_GRANTED)
Timber.d("PERMISSION GRANTED ${permissions[i]}")
}

}
}

companion object {
const val ACTION_VIEW_INTENT = "android.intent.action.VIEW"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,26 @@ import android.webkit.WebView
import android.webkit.WebViewClient
import network.ramp.sdk.events.RampSdkJsInterface
import network.ramp.sdk.events.RampSdkJsInterface.Companion.RampSdkInterfaceName
import network.ramp.sdk.ui.activity.RampWidgetActivity


internal class RampWidgetWebView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : WebView(context, attrs, defStyleAttr) {

@SuppressLint("SetJavaScriptEnabled")
fun setupWebView(wvClient: WebViewClient, jsInterface: RampSdkJsInterface?) {
fun setupWebView(activity: RampWidgetActivity, wvClient: WebViewClient, jsInterface: RampSdkJsInterface?) {
webChromeClient = RampWidgetWebViewChromeClient(activity)
webViewClient = wvClient
settings.javaScriptEnabled = true
settings.javaScriptCanOpenWindowsAutomatically = true
settings.allowContentAccess = true
settings.domStorageEnabled = true
settings.mediaPlaybackRequiresUserGesture = false
settings.setSupportMultipleWindows(true)

webViewClient = wvClient
settings.mediaPlaybackRequiresUserGesture = false
jsInterface?.let {
addJavascriptInterface(it, RampSdkInterfaceName)
}
webChromeClient = RampWidgetWebViewChromeClient(context)
}
}
Loading

0 comments on commit d5ba8ae

Please sign in to comment.