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
28 changes: 28 additions & 0 deletions wallet-native/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@ plugins {
group = 'com.principlezerolabs.wizard'
version = '0.0.1'

// The five faces from the same packages React Native loads (mobile/src/theme.ts).
// Copied at build time so the binaries stay out of git.
def wizardFaceFiles = [
"../../node_modules/@expo-google-fonts/fraunces/400Regular/Fraunces_400Regular.ttf",
"../../node_modules/@expo-google-fonts/figtree/400Regular/Figtree_400Regular.ttf",
"../../node_modules/@expo-google-fonts/figtree/500Medium/Figtree_500Medium.ttf",
"../../node_modules/@expo-google-fonts/figtree/600SemiBold/Figtree_600SemiBold.ttf",
"../../node_modules/@expo-google-fonts/ibm-plex-mono/400Regular/IBMPlexMono_400Regular.ttf",
]
def wizardFaceAssets = layout.buildDirectory.dir("generated/wizard-faces").get().asFile

tasks.register("copyWizardFaces", Copy) {
into(new File(wizardFaceAssets, "fonts"))
from(wizardFaceFiles)
}

android {
namespace "com.principlezerolabs.wizard.wallet"
defaultConfig {
Expand All @@ -18,6 +34,18 @@ android {
versionCode 1
versionName "0.0.1"
}
sourceSets {
main {
assets.srcDir(wizardFaceAssets)
}
}
}

tasks.named("preBuild").configure { dependsOn("copyWizardFaces") }
afterEvaluate {
tasks.matching { it.name ==~ /(?i).*(merge|package).*[Aa]ssets.*/ }.configureEach {
dependsOn("copyWizardFaces")
}
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.principlezerolabs.wizard.wallet

import android.app.Activity
import android.app.Dialog
import android.graphics.Color
import android.graphics.Typeface
import android.graphics.drawable.GradientDrawable
import android.view.Gravity
Expand Down Expand Up @@ -97,7 +96,12 @@ object ConfirmSheet {
addFlags(WindowManager.LayoutParams.FLAG_SECURE)
}

fun text(s: String, size: Float, color: Int, typeface: Typeface = Typeface.DEFAULT): TextView =
val bodyFace = Face.of(activity, Face.BODY)
val strong = Face.of(activity, Face.BUTTON)
val labelFace = Face.of(activity, Face.LABEL)
val mono = Face.of(activity, Face.MONO)

fun text(s: String, size: Float, color: Int, typeface: Typeface = bodyFace): TextView =
TextView(activity).apply {
text = s
textSize = size
Expand All @@ -109,30 +113,17 @@ object ConfirmSheet {
fun add(v: View, top: Int = 12) =
body.addView(v, LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT).apply { topMargin = dp(top) })

fun button(label: String, primary: Boolean, onClick: () -> Unit) = Button(activity).apply {
text = label
isAllCaps = false
textSize = if (primary) 17f else 16f
setTextColor(if (primary) Theme.buttonText else STAR)
background = if (primary) {
GradientDrawable().apply {
setColor(Theme.buttonBackground)
cornerRadius = dp(28).toFloat()
}
} else {
null
}
if (!primary) setBackgroundColor(Color.TRANSPARENT)
setOnClickListener { onClick() }
}
fun button(label: String, primary: Boolean, onClick: () -> Unit) =
Face.button(activity, label, filled = primary, onClick)

fun header(title: String) {
val row = LinearLayout(activity).apply {
orientation = LinearLayout.HORIZONTAL
gravity = Gravity.CENTER_VERTICAL
addView(text(title, 20f, STAR, Typeface.DEFAULT_BOLD), LinearLayout.LayoutParams(0, WRAP_CONTENT, 1f))
addView(text(title, 28f, STAR, Face.of(activity, Face.TITLE)), LinearLayout.LayoutParams(0, WRAP_CONTENT, 1f))
// Only the test network is named (issue #10): mainnet is the default people never need to see.
if (WalletSettings.testnet) addView(text("TESTNET", 12f, NIGHT, Typeface.DEFAULT_BOLD).apply {
if (WalletSettings.testnet) addView(text("TESTNET", 11f, NIGHT, strong).apply {
letterSpacing = 0.05f
setPadding(dp(8), dp(3), dp(8), dp(3))
background = GradientDrawable().apply {
setColor(GOLD)
Expand All @@ -144,7 +135,7 @@ object ConfirmSheet {
}

fun field(name: String, value: View) {
add(text(name, 13f, DUST), 14)
add(text(name, 13f, DUST, labelFace), 14)
add(value, 2)
}

Expand Down Expand Up @@ -178,49 +169,49 @@ object ConfirmSheet {
val d = Format.usd(z, usdPerZec)
return if (usdFirst) "$d · $zz" else "$zz · $d"
}
if (isShield) add(text("Arrived at your exchange address", 16f, DUST, Typeface.DEFAULT_BOLD), 16)
if (isShield) add(text("Arrived at your exchange address", 15f, DUST), 16)
// The payment in the unit the person chose; the other one under it. A request's is its fee.
add(text(if (isRequest) "Fee ${both(proposal.fee)}" else if (usdFirst) usdAmount!! else zecAmount, 36f, STAR, if (WalletSettings.serifAmount) Typeface.SERIF else Typeface.DEFAULT), 16)
add(text(if (isRequest) "Fee ${both(proposal.fee)}" else if (usdFirst) usdAmount!! else zecAmount, 40f, STAR, Face.display(activity)), 16)
if (usdPerZec != null && !isRequest) {
val small = if (usdFirst) zecAmount else usdAmount!!
add(text(if (isShield) small else "$small at 1 ZEC = ${Format.usd(100_000_000uL, usdPerZec)}", 16f, DUST, Typeface.DEFAULT_BOLD), 2)
add(text(if (isShield) small else "$small at 1 ZEC = ${Format.usd(100_000_000uL, usdPerZec)}", 15f, DUST), 2)
}
if (isShield) {
field("From", text("Your public exchange address", 16f, STAR))
field("To", text("Your private balance", 16f, STAR))
field("Fee", text(both(proposal.fee), 16f, STAR))
field("Private after", text(both(proposal.shielded), 16f, STAR, Typeface.DEFAULT_BOLD))
add(text("The money stays yours: it moves from your public address to your private balance. Until then anyone can see it, and ${WalletSettings.appName} can’t pay with it.", 13f, DUST), 12)
field("Private after", text(both(proposal.shielded), 17f, STAR, strong))
add(text("The money stays yours: it moves from your public address to your private balance. Until then anyone can see it, and ${WalletSettings.appName} can’t pay with it.", 15f, DUST), 12)
} else {
val to = LinearLayout(activity).apply { orientation = LinearLayout.VERTICAL }
if (label != null) to.addView(text(label, 16f, STAR, Typeface.DEFAULT_BOLD))
for (a in proposal.to) to.addView(text(Format.grouped(a), 13f, STAR, Typeface.MONOSPACE).apply { setTextIsSelectable(true) })
if (label != null) to.addView(text(label, 17f, STAR, strong))
for (a in proposal.to) to.addView(text(Format.grouped(a), 13f, STAR, mono).apply { setTextIsSelectable(true) })
// A public address says so (#54).
when (proposal.recipient) {
WalletRecipientKind.PUBLIC -> "Public address"
WalletRecipientKind.TEX -> "Exchange address for public payments only"
WalletRecipientKind.PRIVATE -> null
}?.let { to.addView(text(it, 13f, GOLD, Typeface.DEFAULT_BOLD)) }
}?.let { to.addView(text(it, 13f, GOLD, strong)) }
field("To", to)
if (isRequest) {
memoLines.firstOrNull()?.let { field("Request", text(it, 16f, STAR)) }
add(text("Only the fee leaves your wallet. They pay the request if they choose to.", 13f, DUST), 12)
add(text("Only the fee leaves your wallet. They pay the request if they choose to.", 15f, DUST), 12)
} else {
proposal.memo?.takeIf { it.isNotEmpty() }?.let { field("Note", text(it, 16f, STAR)) }
field("Fee", text(both(proposal.fee), 16f, STAR))
field("Total", text(both(proposal.total), 16f, STAR, Typeface.DEFAULT_BOLD))
field("Total", text(both(proposal.total), 17f, STAR, strong))
}
val seen = "This payment is public. Anyone can see the amount and the address it goes to. The rest of your money stays private."
when (proposal.recipient) {
WalletRecipientKind.PUBLIC -> seen
WalletRecipientKind.TEX -> "$seen It goes in two steps, through a one-time public address of yours, so the fee covers two transactions."
WalletRecipientKind.PRIVATE -> null
}?.let { add(text(it, 13f, STAR), 12) }
}?.let { add(text(it, 16f, STAR), 12) }
}
if (usdPerZec != null && !isRequest && !isShield) {
add(text("Exactly ${Format.zec(proposal.zatoshis)} ZEC is sent. Its dollar value moves with ZEC’s price after that.", 13f, DUST), 12)
add(text("Exactly ${Format.zec(proposal.zatoshis)} ZEC is sent. Its dollar value moves with ZEC’s price after that.", 15f, DUST), 12)
}
if (error != null) add(text(error, 15f, CINNABAR), 16)
if (error != null) add(text(error, 16f, CINNABAR), 16)
val spinner = ProgressBar(activity).apply { visibility = View.GONE }
add(spinner, 16)
if (!canSend) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ package com.principlezerolabs.wizard.wallet

import android.app.Activity
import android.app.Dialog
import android.graphics.Color
import android.graphics.Typeface
import android.graphics.drawable.GradientDrawable
import android.view.Gravity
import android.view.View
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
import android.view.WindowManager
import android.widget.Button
import android.widget.LinearLayout
import android.widget.TextView

Expand Down Expand Up @@ -61,7 +59,10 @@ object ContactSheet {
addFlags(WindowManager.LayoutParams.FLAG_SECURE)
}

fun text(s: String, size: Float, color: Int, typeface: Typeface = Typeface.DEFAULT) = TextView(activity).apply {
val bodyFace = Face.of(activity, Face.BODY)
val strong = Face.of(activity, Face.BUTTON)

fun text(s: String, size: Float, color: Int, typeface: Typeface = bodyFace) = TextView(activity).apply {
text = s
textSize = size
setTextColor(color)
Expand All @@ -73,11 +74,11 @@ object ContactSheet {
body.addView(v, LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT).apply { topMargin = dp(top) })

fun field(label: String, value: View) {
add(text(label, 13f, Theme.muted), 14)
add(text(label, 13f, Theme.muted, Face.of(activity, Face.LABEL)), 14)
add(value, 2)
}

fun mono(s: String) = text(Format.grouped(s), 13f, Theme.text, Typeface.MONOSPACE).apply { setTextIsSelectable(true) }
fun mono(s: String) = text(Format.grouped(s), 13f, Theme.text, Face.of(activity, Face.MONO)).apply { setTextIsSelectable(true) }

var done = false
fun finish(ok: Boolean) {
Expand All @@ -87,39 +88,16 @@ object ContactSheet {
onResult(ok)
}

add(text(change.title, 20f, Theme.text, Typeface.DEFAULT_BOLD), 0)
field("Name", text(change.name, 18f, Theme.text, Typeface.DEFAULT_BOLD))
add(text(change.title, 28f, Theme.text, Face.of(activity, Face.TITLE)), 0)
field("Name", text(change.name, 17f, Theme.text, strong))
change.was?.let { (label, value) ->
field(label, if (change.wasAddress) mono(value) else text(value, 16f, Theme.muted))
}
change.zcashName?.let { field(".zcash name", text(it, 16f, Theme.text)) }
field(change.addressLabel, mono(change.address))
change.note?.let { add(text(it, 14f, Theme.muted), 14) }
add(
Button(activity).apply {
text = change.confirm
isAllCaps = false
textSize = 17f
setTextColor(Theme.buttonText)
background = GradientDrawable().apply {
setColor(Theme.buttonBackground)
cornerRadius = dp(28).toFloat()
}
setOnClickListener { finish(true) }
},
20,
)
add(
Button(activity).apply {
text = "Cancel"
isAllCaps = false
textSize = 16f
setTextColor(Theme.text)
setBackgroundColor(Color.TRANSPARENT)
setOnClickListener { finish(false) }
},
4,
)
change.note?.let { add(text(it, 15f, Theme.muted), 14) }
add(Face.button(activity, change.confirm, filled = true) { finish(true) }, 20)
add(Face.button(activity, "Cancel", filled = false) { finish(false) }, 4)
dialog.show()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.principlezerolabs.wizard.wallet

import android.app.Activity
import android.graphics.Color
import android.graphics.Typeface
import android.graphics.drawable.GradientDrawable
import android.util.Log
import android.widget.Button

/**
* The same faces as `mobile/src/theme.ts`. Gradle copies those files into this
* module's assets (`copyWizardFaces`). [Typeface.create] does not see Expo's
* JavaScript names, and this library does not compile against React Native.
*/
object Face {
const val TITLE = "Fraunces_400Regular"
const val BODY = "Figtree_400Regular"
const val LABEL = "Figtree_500Medium"
const val BUTTON = "Figtree_600SemiBold"
const val MONO = "IBMPlexMono_400Regular"

private const val TAG = "WizardFace"

private val files = mapOf(
TITLE to "fonts/Fraunces_400Regular.ttf",
BODY to "fonts/Figtree_400Regular.ttf",
LABEL to "fonts/Figtree_500Medium.ttf",
BUTTON to "fonts/Figtree_600SemiBold.ttf",
MONO to "fonts/IBMPlexMono_400Regular.ttf",
)
private val loaded = mutableMapOf<String, Typeface>()

fun of(activity: Activity, name: String): Typeface {
loaded[name]?.let { return it }
val path = files.getValue(name)
val face = try {
Typeface.createFromAsset(activity.assets, path)
} catch (e: Exception) {
Log.e(TAG, "could not load $path", e)
Typeface.DEFAULT
}
loaded[name] = face
return face
}

/** Fraunces when the amount setting is serif, otherwise Figtree. */
fun display(activity: Activity): Typeface =
of(activity, if (WalletSettings.serifAmount) TITLE else BODY)

fun dp(activity: Activity, v: Int) = (v * activity.resources.displayMetrics.density).toInt()

fun capsule(activity: Activity, color: Int) = GradientDrawable().apply {
setColor(color)
cornerRadius = dp(activity, 999).toFloat()
}

/** A full-width action: Figtree SemiBold 17, 52dp tall, a capsule when filled. */
fun button(activity: Activity, label: String, filled: Boolean, onClick: () -> Unit) =
Button(activity).apply {
text = label
isAllCaps = false
textSize = 17f
typeface = of(activity, BUTTON)
includeFontPadding = false
minimumHeight = dp(activity, 52)
setPadding(dp(activity, 20), 0, dp(activity, 20), 0)
setTextColor(if (filled) Theme.buttonText else Theme.text)
if (filled) {
background = capsule(activity, Theme.buttonBackground)
} else {
background = null
setBackgroundColor(Color.TRANSPARENT)
}
setOnClickListener { onClick() }
}
}
Loading
Loading