Skip to content

Commit

Permalink
PRODUCT-16887 restored url in startTransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
pawel-zak committed Mar 5, 2024
1 parent 030a6d2 commit 95afe49
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 16 deletions.
80 changes: 79 additions & 1 deletion demo/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,79 @@
/build
# Built application files
*.apk
*.aar
*.ap_
*.aab

# Files for the ART/Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/
out/
# Uncomment the following line in case you need and you don't have the release build type files in your app
# release/

# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Android Studio Navigation editor temp files
.navigation/

# Android Studio captures folder
captures/

# IntelliJ
*.iml
.idea/runConfigurations.xml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/assetWizardSettings.xml
.idea/dictionaries
.idea/libraries
.idea/jarRepositories.xml
# Android Studio 3 in .gitignore file.
.idea/caches
.idea/modules.xml
# Comment next line if keeping position of elements in Navigation Editor is relevant for you
.idea/navEditor.xml

# Keystore files
# Uncomment the following lines if you do not want to check your keystore files in.
#*.jks
#*.keystore

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild
.cxx/

# Google Services (e.g. APIs or Firebase)
# google-services.json


# Version control
vcs.xml

# lint
lint/intermediates/
lint/generated/
lint/outputs/
lint/tmp/
# lint/reports/

# Android Profiling
*.hprof
4 changes: 3 additions & 1 deletion demo/src/main/java/ramp/network/demo/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ class MainActivity : AppCompatActivity() {
hostLogoUrl = "https://ramp.network/assets/images/Logo.svg",
hostAppName = "My App",
url = "https://app.demo.ramp.network",
hostApiKey = "your host api key",
hostApiKey = "udr4csh6vje38gvndow6p3f32j3zq3jbkfgrsn22",
userAddress = "0x81A4362705891615d7395135d5591BaaC9f21d3D",
swapAsset = "GOERLI_ETH",
enabledFlows = setOf(Flow.OFFRAMP, Flow.ONRAMP)
)
// 4. Implement callbacks
Expand Down
80 changes: 79 additions & 1 deletion rampsdk/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,79 @@
/build
# Built application files
*.apk
*.aar
*.ap_
*.aab

# Files for the ART/Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/
out/
# Uncomment the following line in case you need and you don't have the release build type files in your app
# release/

# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Android Studio Navigation editor temp files
.navigation/

# Android Studio captures folder
captures/

# IntelliJ
*.iml
.idea/runConfigurations.xml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/assetWizardSettings.xml
.idea/dictionaries
.idea/libraries
.idea/jarRepositories.xml
# Android Studio 3 in .gitignore file.
.idea/caches
.idea/modules.xml
# Comment next line if keeping position of elements in Navigation Editor is relevant for you
.idea/navEditor.xml

# Keystore files
# Uncomment the following lines if you do not want to check your keystore files in.
#*.jks
#*.keystore

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild
.cxx/

# Google Services (e.g. APIs or Firebase)
# google-services.json


# Version control
vcs.xml

# lint
lint/intermediates/
lint/generated/
lint/outputs/
lint/tmp/
# lint/reports/

# Android Profiling
*.hprof
21 changes: 18 additions & 3 deletions rampsdk/src/main/java/network/ramp/sdk/facade/RampSDK.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import network.ramp.sdk.events.EventBus
import network.ramp.sdk.events.model.*
import network.ramp.sdk.ui.activity.RampWidgetActivity
import timber.log.Timber
import java.net.URL

class RampSDK {

Expand All @@ -28,9 +29,7 @@ class RampSDK {
fun startTransaction(
activity: Activity,
config: Config,
callback: RampCallback,
//@DEPRECATED to remove in next major release
url: String? = null
callback: RampCallback
) {
Timber.d("RAMP SDK version - ${BuildConfig.VERSION}")
release()
Expand All @@ -42,6 +41,21 @@ class RampSDK {
activity.startActivity(intent)
}

fun startTransactionWithUrl(
activity: Activity,
callback: RampCallback,
url: String = ""
) {
Timber.d("RAMP SDK version - ${BuildConfig.VERSION}")
release()
this.callback = callback
val intent = Intent(activity, RampWidgetActivity::class.java)
intent.putExtra(
URL_EXTRA, url
)
activity.startActivity(intent)
}

fun onOfframpCryptoSent(txHash: String? = null, error: String? = null) {
scope.launch {
EventBus.invokeEvent(SendCryptoResult(SendCryptoResultPayload(txHash, error)))
Expand Down Expand Up @@ -100,5 +114,6 @@ class RampSDK {

companion object {
internal const val CONFIG_EXTRA = "config"
internal const val URL_EXTRA = "url"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.app.Activity
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.webkit.ValueCallback
import androidx.activity.result.ActivityResultLauncher
Expand All @@ -14,13 +15,15 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
import network.ramp.sdk.BuildConfig
import network.ramp.sdk.databinding.WidgetActivityBinding
import network.ramp.sdk.events.EventBus
import network.ramp.sdk.events.RampSdkJsInterface
import network.ramp.sdk.facade.Config
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 @@ -45,7 +48,9 @@ internal class RampWidgetActivity : AppCompatActivity(), Contract.View {

private lateinit var binding: WidgetActivityBinding

private lateinit var config: Config
private var config: Config? = null

private var url: String? = ""

private val jsInterface = RampSdkJsInterface(
onPostMessage = {
Expand All @@ -65,23 +70,36 @@ internal class RampWidgetActivity : AppCompatActivity(), Contract.View {
jsInterface = jsInterface,
fileChooserLauncher = fileChooserLauncher
) { filePathCallback = it }

intent.extras?.getParcelable<Config>(CONFIG_EXTRA)?.let {
config = it
} ?: returnOnError("Config object cannot be null")
}

url = intent.extras?.getString(URL_EXTRA)

if (savedInstanceState == null) {
Timber.d(rampPresenter.buildUrl(config))
securityCheck(intent)?.let {
binding.webView.loadUrl(it)
} ?: close()
config?.let {
Timber.d(rampPresenter.buildUrl(it))
}

val safeUrl = securityCheck(intent, config)

when {
!url.isNullOrBlank() && rampPresenter.isUrlSafe(url!!) -> binding.webView.loadUrl(url!!)

safeUrl != null -> binding.webView.loadUrl(safeUrl)

else -> {
returnOnError("UNAUTHORIZED CALL")
}
}
}
}

private fun securityCheck(intent: Intent): String? =
if (isInternalIntent(intent) && rampPresenter.isUrlSafe(config.url))
private fun securityCheck(intent: Intent, config: Config?): String? =
if (config != null && isInternalIntent(intent) && rampPresenter.isUrlSafe(config.url))
rampPresenter.buildUrl(config)
else {
Timber.e("SECURITY ALERT - UNAUTHORIZED CALL")
null
}

Expand Down Expand Up @@ -147,7 +165,6 @@ internal class RampWidgetActivity : AppCompatActivity(), Contract.View {
if (grantResults[i] == PackageManager.PERMISSION_GRANTED)
Timber.d("PERMISSION GRANTED ${permissions[i]}")
}

}
}

Expand Down

0 comments on commit 95afe49

Please sign in to comment.