diff --git a/demo/src/main/java/ramp/network/demo/MainActivity.kt b/demo/src/main/java/ramp/network/demo/MainActivity.kt index 2e48e9f..a671538 100644 --- a/demo/src/main/java/ramp/network/demo/MainActivity.kt +++ b/demo/src/main/java/ramp/network/demo/MainActivity.kt @@ -34,15 +34,12 @@ class MainActivity : AppCompatActivity() { val config = Config( hostLogoUrl = "https://ramp.network/assets/images/Logo.svg", hostAppName = "My App", - url = "https://app.dev.ramp-network.org", - hostApiKey = "3qncr4yvxfpro6endeaeu6npkh8qc23e9uadtazq", + url = "https://app.demo.ramp.network", + hostApiKey = "your host api key", enabledFlows = setOf(Flow.OFFRAMP, Flow.ONRAMP) ) // 4. Implement callbacks val callback = object : RampCallback { - override fun onPurchaseFailed() { - Log.d("MainActivity", "onPurchaseFailed") - } override fun onPurchaseCreated( purchase: Purchase, diff --git a/rampsdk/build.gradle b/rampsdk/build.gradle index 0e1244e..591a242 100644 --- a/rampsdk/build.gradle +++ b/rampsdk/build.gradle @@ -22,8 +22,8 @@ android { defaultConfig { minSdkVersion 21 targetSdkVersion 32 - versionCode 18 - versionName "3.0.4" + versionCode 19 + versionName "4.0.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles 'consumer-rules.pro' buildConfigField 'String', 'VERSION', "\"${defaultConfig.versionName}\"" @@ -84,7 +84,7 @@ afterEvaluate { from components.release groupId = 'com.github.RampNetwork' artifactId = 'ramp-sdk-android' - version = '3.0.4' + version = '4.0.0' } } } diff --git a/rampsdk/src/main/java/network/ramp/sdk/events/model/Events.kt b/rampsdk/src/main/java/network/ramp/sdk/events/model/Events.kt index 5ff68b4..3f2adb8 100644 --- a/rampsdk/src/main/java/network/ramp/sdk/events/model/Events.kt +++ b/rampsdk/src/main/java/network/ramp/sdk/events/model/Events.kt @@ -9,6 +9,8 @@ sealed class Event(val type: EventType) { } } +@JsonClass(generateAdapter = true) +data class Close(var payload: WidgetClosePayload? = null) : Event(EventType.CLOSE) @JsonClass(generateAdapter = true) data class WidgetClose(var payload: WidgetClosePayload? = null) : Event(EventType.WIDGET_CLOSE) @@ -48,6 +50,7 @@ internal data class OfframpSaleCreated(var payload: OfframpSaleCreatedPayload) : @JsonClass(generateAdapter = false) enum class EventType { + CLOSE, WIDGET_CLOSE, OPEN_LINK, WIDGET_CONFIG_DONE, diff --git a/rampsdk/src/main/java/network/ramp/sdk/events/model/Payloads.kt b/rampsdk/src/main/java/network/ramp/sdk/events/model/Payloads.kt index daee3b1..0ce23b9 100644 --- a/rampsdk/src/main/java/network/ramp/sdk/events/model/Payloads.kt +++ b/rampsdk/src/main/java/network/ramp/sdk/events/model/Payloads.kt @@ -48,15 +48,9 @@ data class OfframpSaleCreatedPayload( data class Purchase( val id: String, val endTime: String, // purchase validity time, ISO date-time string - @Deprecated("This parameter will be removed in future release") - val escrowAddress: String? = null, // filled only for escrow-backend purchases val cryptoAmount: String, // number-string, in wei or token units val fiatCurrency: String, // three-letter currency code - val fiatValue: Long, // total value the user pays for the purchase, in fiatCurrency - @Deprecated("This parameter will be removed in future") - val assetExchangeRateEur: Double, - @Deprecated("This parameter will be removed in future") - val fiatExchangeRateEur: Long, + val fiatValue: Double, // total value the user pays for the purchase, in fiatCurrency val baseRampFee: Double, // base Ramp fee before any modifications, in fiatCurrency val networkFee: Double, // network fee for transferring the purchased asset, in fiatCurrency val appliedFee: Double, // final fee the user pays (included in fiatValue), in fiatCurrency @@ -65,8 +59,6 @@ data class Purchase( val asset: Asset, // description of the purchased asset (address, symbol, name, decimals) val receiverAddress: String, // blockchain address of the buyer val assetExchangeRate: Double,// price of 1 whole token of purchased asset, in fiatCurrency - @Deprecated("This parameter will be removed in future") - val purchaseViewToken: String, val status: String, // purchase status val paymentMethodType: String, // type of payment method used to pay for the swap: 'MANUAL_BANK_TRANSFER' | 'AUTO_BANK_TRANSFER' | 'CARD_PAYMENT' | 'APPLE_PAY' val finalTxHash: String? = null // hash of the crypto transfer blockchain transaction, filled once available @@ -97,8 +89,10 @@ data class Fiat( data class Asset( val address: String? = null, // 0x-prefixed address for ERC-20 tokens, `null` for ETH val symbol: String, // asset symbol, for example `ETH`, `DAI`, `USDC` + val apiV3Symbol: String, // asset symbol in API v3 val name: String, val decimals: Long, // token decimals, e.g. 18 for ETH/DAI, 6 for USDC val type: String, // asset type & network, e.g. `ETH`, `ERC20`, `MATIC_ERC20` - val chain: String // asset chain, for example `ETH`, `BSC`, `POLKADOT` + val chain: String, // asset chain, for example `ETH`, `BSC`, `POLKADOT` + val apiV3Type: String // asset type in API v3 ) : Parcelable \ No newline at end of file diff --git a/rampsdk/src/main/java/network/ramp/sdk/facade/RampCallback.kt b/rampsdk/src/main/java/network/ramp/sdk/facade/RampCallback.kt index f3ec83c..eb24fc0 100644 --- a/rampsdk/src/main/java/network/ramp/sdk/facade/RampCallback.kt +++ b/rampsdk/src/main/java/network/ramp/sdk/facade/RampCallback.kt @@ -5,10 +5,6 @@ import network.ramp.sdk.events.model.Purchase import network.ramp.sdk.events.model.Asset interface RampCallback { - - @Deprecated(message = "This method is deprecated and will be removed in future versions.") - fun onPurchaseFailed() - fun onPurchaseCreated(purchase: Purchase, purchaseViewToken: String, apiUrl: String) fun onOfframpSaleCreated( diff --git a/rampsdk/src/main/java/network/ramp/sdk/facade/RampSDK.kt b/rampsdk/src/main/java/network/ramp/sdk/facade/RampSDK.kt index 5e2ae72..836b4d3 100644 --- a/rampsdk/src/main/java/network/ramp/sdk/facade/RampSDK.kt +++ b/rampsdk/src/main/java/network/ramp/sdk/facade/RampSDK.kt @@ -63,9 +63,6 @@ class RampSDK { payload.apiUrl ) } - EventType.PURCHASE_FAILED -> { - callback?.onPurchaseFailed() - } EventType.OFFRAMP_SALE_CREATED -> { val payload = (it as OfframpSaleCreated).payload diff --git a/rampsdk/src/main/java/network/ramp/sdk/ui/activity/RampPresenter.kt b/rampsdk/src/main/java/network/ramp/sdk/ui/activity/RampPresenter.kt index fd6e7d0..1ab91cc 100644 --- a/rampsdk/src/main/java/network/ramp/sdk/ui/activity/RampPresenter.kt +++ b/rampsdk/src/main/java/network/ramp/sdk/ui/activity/RampPresenter.kt @@ -26,6 +26,7 @@ internal class RampPresenter( .add( PolymorphicJsonAdapterFactory.of(Event::class.java, LABEL_KEY_TYPE) .withSubtype(OpenLink::class.java, EventType.OPEN_LINK.name) + .withSubtype(Close::class.java, EventType.CLOSE.name) .withSubtype(WidgetClose::class.java, EventType.WIDGET_CLOSE.name) .withSubtype(PurchasedFailed::class.java, EventType.PURCHASE_FAILED.name) .withSubtype(PurchasedCreated::class.java, EventType.PURCHASE_CREATED.name) @@ -68,15 +69,18 @@ internal class RampPresenter( .fromJson(json) when (event?.type) { + EventType.CLOSE -> { + (event as? Close)?.payload?.let { + showDialogOrClose(it.showAlert) + } + } + EventType.WIDGET_CLOSE -> { (event as? WidgetClose)?.payload?.let { - if (it.showAlert) - view.showDialog() - else { - view.close() - } + showDialogOrClose(it.showAlert) } } + EventType.OPEN_LINK -> { (event as? OpenLink)?.payload?.let { Timber.d("onOpenUrl ${it.linkType} ${it.url} ") @@ -117,6 +121,7 @@ internal class RampPresenter( EventType.WIDGET_CONFIG_DONE -> { configDone = true } + else -> Timber.w("Unhandled event $json") } } @@ -164,6 +169,14 @@ internal class RampPresenter( fun isUrlSafe(url: String): Boolean = UrlSafeChecker.isUrlSafe(url) + private fun showDialogOrClose(showAlert: Boolean) { + if (showAlert) + view.showDialog() + else { + view.close() + } + } + fun postMessage(event: T) { val eventJson = moshi .adapter(Event::class.java)