Skip to content

Commit

Permalink
#PRODUCT-15779 fiatValue and fiatExchangeRateEur fix (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubsta authored Mar 18, 2024
2 parents 5b9b5e1 + a52cd5b commit 9521e24
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 30 deletions.
7 changes: 2 additions & 5 deletions demo/src/main/java/ramp/network/demo/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions rampsdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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}\""
Expand Down Expand Up @@ -84,7 +84,7 @@ afterEvaluate {
from components.release
groupId = 'com.github.RampNetwork'
artifactId = 'ramp-sdk-android'
version = '3.0.4'
version = '4.0.0'
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions rampsdk/src/main/java/network/ramp/sdk/events/model/Events.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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,
Expand Down
14 changes: 4 additions & 10 deletions rampsdk/src/main/java/network/ramp/sdk/events/model/Payloads.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
4 changes: 0 additions & 4 deletions rampsdk/src/main/java/network/ramp/sdk/facade/RampCallback.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 0 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 @@ -63,9 +63,6 @@ class RampSDK {
payload.apiUrl
)
}
EventType.PURCHASE_FAILED -> {
callback?.onPurchaseFailed()
}

EventType.OFFRAMP_SALE_CREATED -> {
val payload = (it as OfframpSaleCreated).payload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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} ")
Expand Down Expand Up @@ -117,6 +121,7 @@ internal class RampPresenter(
EventType.WIDGET_CONFIG_DONE -> {
configDone = true
}

else -> Timber.w("Unhandled event $json")
}
}
Expand Down Expand Up @@ -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 <T : Event> postMessage(event: T) {
val eventJson = moshi
.adapter(Event::class.java)
Expand Down

0 comments on commit 9521e24

Please sign in to comment.