Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,19 @@ jobs:
distribution: 'temurin'
java-version: '21'

- name: Code Style
run: ./gradlew ktlintCheck

- name: Generate code style fixes
if: failure()
run: ./gradlew ktlintFormat

- name: Suggest code style fixes
if: failure()
run: git diff

- name: Test
run: ./gradlew clean assemble check
run: ./gradlew assemble check

- name: Fingerprints
run: ./gradlew checkFingerPrints
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ jobs:
distribution: 'temurin'
java-version: '21'

- name: Code Style
run: ./gradlew ktlintCheck

- name: Test
run: ./gradlew clean assemble check
run: ./gradlew assemble check

- name: Assemble all APKs
run: ./gradlew createReleaseNotes
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.jetbrains.kotlin.android) apply false
alias(libs.plugins.compose.compiler) apply false
alias(libs.plugins.ktlint) apply false
}

tasks.register("createReleaseNotes") {
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ test-json = "20231013"
coroutines = "1.10.1"
androidxtest = "1.6.1"
softauth = "0.1.2"
ktlint = "12.2.0"

[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
Expand Down Expand Up @@ -50,3 +51,4 @@ softauth = { group = "io.github.adessose", name = "softauthn", version.ref = "so
android-application = { id = "com.android.application", version.ref = "agp" }
jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint" }
17 changes: 14 additions & 3 deletions wrapper/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.jetbrains.kotlin.android)
alias(libs.plugins.compose.compiler)
alias(libs.plugins.ktlint)
}

android {
Expand Down Expand Up @@ -46,7 +47,7 @@ android {
isMinifyEnabled = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
"proguard-rules.pro",
)
}

Expand All @@ -60,7 +61,6 @@ android {
targetCompatibility = JavaVersion.VERSION_11
}


kotlinOptions {
jvmTarget = "11"
}
Expand Down Expand Up @@ -94,7 +94,6 @@ android {
}

dependencies {

implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
Expand Down Expand Up @@ -127,3 +126,15 @@ dependencies {
debugImplementation(libs.androidx.ui.tooling)
debugImplementation(libs.androidx.ui.test.manifest)
}

configure<org.jlleitschuh.gradle.ktlint.KtlintExtension> {
verbose.set(true)
android.set(true)

additionalEditorconfig.set(
mapOf(
"max_line_length" to "200",
"ktlint_function_naming_ignore_when_annotated_with" to "Composable",
),
)
}
31 changes: 18 additions & 13 deletions wrapper/src/androidTest/java/StartUpTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,24 @@ class StartUpTest {
val webView = view as WebView

activityRule.scenario.onActivity {
val injectionSnippet = JSCodeSnippet.fromRawResource(
context = webView.context,
resource = "injectjs.js",
replacements = listOf(
"JAVASCRIPT_BRIDGE" to JAVASCRIPT_BRIDGE_NAME,
"JAVASCRIPT_VISUALIZE_INJECTION" to "${BuildConfig.VISUALIZE_INJECTION}"
val injectionSnippet =
JSCodeSnippet.fromRawResource(
context = webView.context,
resource = "injectjs.js",
replacements =
listOf(
"JAVASCRIPT_BRIDGE" to JAVASCRIPT_BRIDGE_NAME,
"JAVASCRIPT_VISUALIZE_INJECTION" to "${BuildConfig.VISUALIZE_INJECTION}",
),
)
)

// add syntax exception handler
webView.evaluateJavascript("err = '';window.onerror = (e) => err += String(e);") {}

// execute snipped injection, and catch errors
webView.evaluateJavascript("try {\n${injectionSnippet.code}\n} catch (e) {\nerr += 'Exception: ' + JSON.stringify(e);\n}") {}
webView.evaluateJavascript(
"try {\n${injectionSnippet.code}\n} catch (e) {\nerr += 'Exception: ' + JSON.stringify(e);\n}",
) {}

webView.evaluateJavascript("err") {
error = it
Expand Down Expand Up @@ -101,11 +105,12 @@ class StartUpTest {
val webView = view as WebView
activityRule.scenario.onActivity {
webView.evaluateJavascript("navigator.credentials") {
webNavigator = if (it == "null") {
null
} else {
it
}
webNavigator =
if (it == "null") {
null
} else {
it
}
latch.countDown()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,43 +28,42 @@ class DebugMenuHandler(
val context: Context,
val showUrlRow: (Boolean) -> Unit,
) {
private var maxSeparatorsCount = 1;
private val actions: Map<String, (JSExecutor) -> Unit> = mapOf(
SHOW_URL_ROW to { js -> showUrlRow(true) },
HIDE_URL_ROW to { js -> showUrlRow(false) },

LIST_SEPARATOR * maxSeparatorsCount++ to {},

OVERRIDE_HINT_WITH_SECURITY_KEY to { it("$JAVASCRIPT_BRIDGE_NAME.overrideHints(['security-key'])") {} },
OVERRIDE_HINT_WITH_CLIENT_DEVICE to { it("$JAVASCRIPT_BRIDGE_NAME.overrideHints(['client-device'])") {} },
OVERRIDE_HINT_WITH_EMULATOR to { it("$JAVASCRIPT_BRIDGE_NAME.overrideHints(['emulator'])") {} },
DO_NOT_OVERRIDE_HINT to { it("$JAVASCRIPT_BRIDGE_NAME.overrideHints([])") {} },

LIST_SEPARATOR * maxSeparatorsCount++ to {},

SEND_FEEDBACK to { js ->
js("$JAVASCRIPT_BRIDGE_NAME.__captured_logs__") { logsJson ->
val jsonArray = JSONArray(logsJson)
val logs = jsonArray.toList().map { "$it" }
val body = createIssueBody(logs, Int.MAX_VALUE)
val title = "Wwwwallet wrapper issue"
private var maxSeparatorsCount = 1
private val actions: Map<String, (JSExecutor) -> Unit> =
mapOf(
SHOW_URL_ROW to { js -> showUrlRow(true) },
HIDE_URL_ROW to { js -> showUrlRow(false) },
LIST_SEPARATOR * maxSeparatorsCount++ to {},
OVERRIDE_HINT_WITH_SECURITY_KEY to { it("$JAVASCRIPT_BRIDGE_NAME.overrideHints(['security-key'])") {} },
OVERRIDE_HINT_WITH_CLIENT_DEVICE to { it("$JAVASCRIPT_BRIDGE_NAME.overrideHints(['client-device'])") {} },
OVERRIDE_HINT_WITH_EMULATOR to { it("$JAVASCRIPT_BRIDGE_NAME.overrideHints(['emulator'])") {} },
DO_NOT_OVERRIDE_HINT to { it("$JAVASCRIPT_BRIDGE_NAME.overrideHints([])") {} },
LIST_SEPARATOR * maxSeparatorsCount++ to {},
SEND_FEEDBACK to { js ->
js("$JAVASCRIPT_BRIDGE_NAME.__captured_logs__") { logsJson ->
val jsonArray = JSONArray(logsJson)
val logs = jsonArray.toList().map { "$it" }
val body = createIssueBody(logs, Int.MAX_VALUE)
val title = "Wwwwallet wrapper issue"

// TODO: Once Github is public, move over from email to github issue creation.
// val uri =
// "https://github.com/wwWallet/wwwallet-android-wrapper/issues/new?title=${title}&body=${body.urlSafe()}".toUri()
// context.startActivity(Intent(Intent.ACTION_VIEW, uri))

val intent = Intent(Intent.ACTION_SEND).apply {
setType("text/html")
putExtra(Intent.EXTRA_EMAIL, arrayOf("mario.bodemann@yubico.com"))
putExtra(Intent.EXTRA_SUBJECT, title)
putExtra(Intent.EXTRA_HTML_TEXT, body)
putExtra(Intent.EXTRA_TEXT, body) // fallback
}
val intent =
Intent(Intent.ACTION_SEND).apply {
setType("text/html")
putExtra(Intent.EXTRA_EMAIL, arrayOf("mario.bodemann@yubico.com"))
putExtra(Intent.EXTRA_SUBJECT, title)
putExtra(Intent.EXTRA_HTML_TEXT, body)
putExtra(Intent.EXTRA_TEXT, body) // fallback
}

context.startActivity(intent) }
},
)
context.startActivity(intent)
}
},
)

fun onMenuOpened(jsExecutor: JSExecutor) {
jsExecutor("console.log('Developer encountered.')") {}
Expand All @@ -74,7 +73,7 @@ class DebugMenuHandler(
AlertDialog.Builder(context, theme)
.setTitle("Debug Menu")
.setItems(
items
items,
) { dialog, which ->
val key = items[which]
if (key in actions) {
Expand All @@ -96,26 +95,29 @@ class DebugMenuHandler(
}
}

private operator fun String.times(times: Int): String =
(0 until times).joinToString(separator = "") { this }
private operator fun String.times(times: Int): String = (0 until times).joinToString(separator = "") { this }

private fun createIssueBody(logs: List<String>, maxLogLineCount: Int = 50): String {
private fun createIssueBody(
logs: List<String>,
maxLogLineCount: Int = 50,
): String {
val digits = log10(logs.size.toFloat()).nextUp().toInt() + 1

// truncate log to max lines (otherwise request to github becomes to big)
val truncatedLogs = if (logs.size > maxLogLineCount) {
logs.takeLast(maxLogLineCount)
} else {
logs
}
val truncatedLogs =
if (logs.size > maxLogLineCount) {
logs.takeLast(maxLogLineCount)
} else {
logs
}

val truncated = truncatedLogs.size < logs.size
val truncatedOffset = if (truncated) {
logs.size - truncatedLogs.size
} else {
0
}

val truncatedOffset =
if (truncated) {
logs.size - truncatedLogs.size
} else {
0
}

return """Hey wwwallet team,

Expand Down
Loading