Skip to content

Commit

Permalink
update account parsing, add regex lib to stax
Browse files Browse the repository at this point in the history
  • Loading branch information
davkutalek committed Dec 27, 2023
1 parent 2419f95 commit 41cf2cf
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 8 deletions.
10 changes: 10 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ dependencies {
"stagingImplementation"(project(":hover.sdk"))
"stagingImplementation"(libs.bundles.hover)
"productionImplementation"(libs.hover)

implementation(files("libs/named-regexp.jar"))
}

abstract class VersionTask : DefaultTask() {
Expand Down
Binary file added app/libs/named-regexp.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions app/src/main/java/com/hover/stax/domain/model/Account.kt
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ data class Account(
}
}

fun updateBalance(balance: String) {
latestBalance = balance
latestBalanceTimestamp = now()
}

fun getAccountNameExtra(): String {
return institutionAccountName ?: "1"
}
Expand Down
20 changes: 14 additions & 6 deletions app/src/main/java/com/hover/stax/hover/TransactionReceiver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package com.hover.stax.hover
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.os.Build
import androidx.annotation.RequiresApi
import com.hover.sdk.actions.HoverAction
import com.hover.sdk.transactions.Transaction
import com.hover.sdk.transactions.TransactionContract
Expand All @@ -37,7 +39,7 @@ import com.hover.stax.requests.RequestRepo
import com.hover.stax.transactions.TransactionRepo
import com.hover.stax.utils.AnalyticsUtil
import com.hover.stax.utils.Utils
import java.util.regex.Pattern
import com.google.code.regexp.Pattern;
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -190,24 +192,30 @@ class TransactionReceiver : BroadcastReceiver(), KoinComponent {
}

private suspend fun parseAccounts(ussdAccountList: String) {
val pattern = Pattern.compile("^([\\d]{1,2})[>):.\\s]+(.+)\$", Pattern.MULTILINE)
val patternRegex = action!!.account_list_regex ?: "^([\\d]{1,2})[>):.\\s]+(?<accountName>.+)\$"
val pattern = Pattern.compile(patternRegex, Pattern.MULTILINE)
val matcher = pattern.matcher(ussdAccountList)

while (matcher.find()) {
try {
val accounts = accountRepo.getAccountsByChannel(channel!!.id)
if (accounts.any { it.institutionAccountName == matcher.group(2)!! }) { break }
val accountName = matcher.group("accountName")!!

val a = if (account != null && account!!.institutionAccountName == null) {
account!!
} else if (accounts.any { it.institutionAccountName == null }) {
accounts.first { it.institutionAccountName == null }
} else {
Account(matcher.group(2)!!, channel!!, false, account?.simSubscriptionId ?: -1)
Account(accountName, channel!!, false, account?.simSubscriptionId ?: -1)
}

a.institutionAccountName = matcher.group(2)!!
if (a.institutionName == a.userAlias) a.userAlias = matcher.group(2)!!
a.institutionAccountName = accountName
if (a.institutionName == a.userAlias) a.userAlias = accountName

val balance = matcher.group("balance")
if (!balance.isNullOrEmpty()) {
a.updateBalance(balance)
}

accountRepo.saveAccount(a)
} catch (e: Exception) { AnalyticsUtil.logErrorAndReportToFirebase(TransactionReceiver::class.java.simpleName, "Failed to parse account list from USSD", e) }
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ glide = { module = "com.github.bumptech.glide:glide", version.ref = "glide" }
glide-compiler = { module = "com.github.bumptech.glide:compiler", version.ref = "glide" }
coil = "io.coil-kt:coil-compose:2.1.0"

hover = "com.hover:android-sdk:2.0.0-research"
hover = "com.hover:android-sdk:2.0.0-research2"
volley = "com.android.volley:volley:1.2.1"
play-services = "com.google.android.gms:play-services-analytics:18.0.1"
picasso = "com.squareup.picasso:picasso:2.71828"
Expand Down

0 comments on commit 41cf2cf

Please sign in to comment.