Skip to content

Commit

Permalink
Feature/AND-113 update Swipelux onramp flow (#197)
Browse files Browse the repository at this point in the history
* Update the Swipelux onramp flow

Use the new customizable page allowing pre-setting the address and the token

* Update OpenCcdOnrampSiteWithAccountUseCase

* Update OpenCcdOnrampSiteWithAccountUseCase logic
  • Loading branch information
zaiatsartem authored Nov 21, 2024
1 parent 2055dea commit f480a04
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 30 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
as it is a WalletConnect-based DEX which fetches the wallet data itself.
- The "," separator sign used on all balances in the wallet - to make it easier to read
large numbers
- Use the new customizable page allowing pre-setting the address and the token for the Swipelux
payment gateway

## [1.3.1] - 2024-11-07

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.concordium.wallet.ui.onramp

import java.io.Serializable

class CcdOnrampSite(
data class CcdOnrampSite(
val name: String,
val url: String,
val logoUrl: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class CcdOnrampSiteRepository {
private val mainnetSites = listOf(
CcdOnrampSite(
name = "Swipelux",
url = "https://swipelux.com/buy_ccd",
url = "https://track.swipelux.com",
logoUrl = "https://assets-global.website-files.com/64f060f3fc95f9d2081781db/65e825be9290e43f9d1bc29b_52c3517d-1bb0-4705-a952-8f0d2746b4c5.jpg",
type = CcdOnrampSite.Type.PAYMENT_GATEWAY,
acceptsCreditCard = true,
Expand Down Expand Up @@ -74,7 +74,7 @@ class CcdOnrampSiteRepository {
),
)

val testnetSites = listOf(
private val testnetSites = listOf(
CcdOnrampSite(
name = "Testnet CCD drop",
url = "https://radiokot.github.io/ccd-faucet/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,10 @@ class CcdOnrampSitesActivity : BaseActivity(
val accountAddress = viewModel.accountAddress

if (site.type == CcdOnrampSite.Type.DEX) {
OpenCcdOnrampSiteWithAccountUseCase(
site = site,
accountAddress = "",
onAccountAddressCopied = { },
context = this,
).invoke()
openSite(site = site)
} else {
if (accountAddress != null) {
OpenCcdOnrampSiteWithAccountUseCase(
openSite(
site = site,
accountAddress = accountAddress,
onAccountAddressCopied = {
Expand All @@ -73,23 +68,30 @@ class CcdOnrampSitesActivity : BaseActivity(
this,
getString(R.string.template_ccd_onramp_opening_site, site.name),
Toast.LENGTH_SHORT
)
.show()
},
context = this,
).invoke()
).show()
}
)
} else {
val intent = Intent(this, CcdOnrampAccountsActivity::class.java)
intent.putExtras(
CcdOnrampAccountsActivity.getBundle(
site = site,
)
)
intent.putExtras(CcdOnrampAccountsActivity.getBundle(site = site))
startActivity(intent)
}
}
}

private fun openSite(
site: CcdOnrampSite,
accountAddress: String = "",
onAccountAddressCopied: () -> Unit = {}
) {
OpenCcdOnrampSiteWithAccountUseCase(
site = site,
accountAddress = accountAddress,
onAccountAddressCopied = onAccountAddressCopied,
context = this
).invoke()
}

companion object {
private const val ACCOUNT_ADDRESS_EXTRA = "account_address"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.content.Context
import android.content.Intent
import android.net.Uri
import com.concordium.wallet.R
import com.concordium.wallet.ui.onramp.swipelux.SwipeluxSettingsHelper

class OpenCcdOnrampSiteWithAccountUseCase(
val site: CcdOnrampSite,
Expand All @@ -14,16 +15,29 @@ class OpenCcdOnrampSiteWithAccountUseCase(
val context: Context,
) {
operator fun invoke() {
val clipboardManager: ClipboardManager =
context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clipData = ClipData.newPlainText(
context.getString(R.string.account_details_address),
accountAddress,
)
onAccountAddressCopied()
clipboardManager.setPrimaryClip(clipData)
var launchSite: CcdOnrampSite = site

val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(site.url))
context.startActivity(Intent.createChooser(browserIntent, site.name))
when {
site.name == "Swipelux" -> {
launchSite =
site.copy(url = SwipeluxSettingsHelper.getWidgetSettings(accountAddress))
}

site.type == CcdOnrampSite.Type.DEX -> {}

else -> {
val clipboardManager: ClipboardManager =
context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clipData = ClipData.newPlainText(
context.getString(R.string.account_details_address),
accountAddress,
)
onAccountAddressCopied()
clipboardManager.setPrimaryClip(clipData)
}
}

val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(launchSite.url))
context.startActivity(Intent.createChooser(browserIntent, launchSite.name))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.concordium.wallet.ui.onramp.swipelux

import com.concordium.wallet.App
import java.net.URLEncoder
import java.nio.charset.StandardCharsets

object SwipeluxSettingsHelper {
private const val BASE_URL = "https://track.swipelux.com"

fun getWidgetSettings(walletAddress: String): String {

val widgetConfig = WidgetConfig(
apiKey = "6515da6d-a065-4676-a214-c83e5b18f5f3", //CCD API Key
colors = Colors(
main = "#48A2AE",
background = "#182022",
processing = "#FFA400",
warning = "#ED0A34",
success = "#58CB4E",
link = "#F24F21"
),
defaultValues = DefaultValues(
targetAddress = DefaultValue(
value = walletAddress,
editable = true
),
phone = DefaultValue(
value = "",
editable = true
),
email = DefaultValue(
value = "",
editable = true
),
fiatAmount = 100
)
)

val jsonString = App.appCore.gson.toJson(widgetConfig)
val encodedString = URLEncoder.encode(jsonString, StandardCharsets.UTF_8.toString())
val url = "$BASE_URL/?specificSettings=${encodedString}"

return url
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.concordium.wallet.ui.onramp.swipelux

data class WidgetConfig(
val apiKey: String,
val colors: Colors,
val defaultValues: DefaultValues
)

data class Colors(
val main: String,
val background: String,
val processing: String,
val warning: String,
val success: String,
val link: String
)

data class DefaultValue(
val value: String,
val editable: Boolean
)

data class DefaultValues(
val targetAddress: DefaultValue?,
val phone: DefaultValue?,
val email: DefaultValue?,
val fiatAmount: Int?
)

0 comments on commit f480a04

Please sign in to comment.