Skip to content

Commit

Permalink
Merge branch 'master' into mainnet
Browse files Browse the repository at this point in the history
  • Loading branch information
dpad85 committed Aug 18, 2023
2 parents 9b0de94 + be4f025 commit 6e69d54
Show file tree
Hide file tree
Showing 130 changed files with 5,715 additions and 3,166 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ FROM eclipse-temurin:11.0.20_8-jdk-alpine as ECLAIR_CORE_BUILD
COPY ./buildSrc/src/main/kotlin/Versions.kt .
RUN cat Versions.kt | grep "const val eclair =" | cut -d '"' -f 2 > eclair-core-version.txt

ARG MAVEN_VERSION=3.9.3
ARG MAVEN_VERSION=3.9.4
ARG USER_HOME_DIR="/root"
ARG SHA=400fc5b6d000c158d5ee7937543faa06b6bda8408caa2444a9c947c21472fde0f0b64ac452b8cec8855d528c0335522ed5b6c8f77085811c7e29e1bedbb5daa2
ARG SHA=deaa39e16b2cf20f8cd7d232a1306344f04020e1f0fb28d35492606f647a60fe729cc40d3cba33e093a17aed41bd161fe1240556d0f1b80e773abd408686217e
ARG BASE_URL=https://apache.osuosl.org/maven/maven-3/${MAVEN_VERSION}/binaries

RUN apk add --no-cache curl tar bash git
Expand Down
4 changes: 2 additions & 2 deletions phoenix-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ android {
applicationId = "fr.acinq.phoenix.mainnet"
minSdk = 24
targetSdk = 33
versionCode = 54
versionName = "2.0.0"
versionCode = 55
versionName = gitCommitHash()
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ private fun UnitDropdown(
var selectedIndex by remember { mutableStateOf(maxOf(units.lastIndexOf(selectedUnit), 0)) }
Box(modifier = modifier.wrapContentSize(Alignment.TopStart)) {
Button(
text = units[selectedIndex].toString(),
text = units[selectedIndex].displayCode,
icon = R.drawable.ic_chevron_down,
onClick = { expanded = true },
padding = internalPadding,
Expand All @@ -572,14 +572,14 @@ private fun UnitDropdown(
onDismiss()
},
) {
units.forEachIndexed { index, s ->
units.forEachIndexed { index, unit ->
DropdownMenuItem(onClick = {
selectedIndex = index
expanded = false
onDismiss()
onUnitChange(units[index])
}) {
Text(text = s.toString())
Text(text = unit.displayCode)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fun AmountView(
if (!isRedacted && showUnit) {
Spacer(modifier = Modifier.width(separatorSpace))
Text(
text = unit.toString(),
text = unit.displayCode,
style = unitTextStyle,
modifier = Modifier.alignBy(FirstBaseline)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,30 @@ object Converter {
/** Converts [MilliSatoshi] to a fiat amount. */
fun MilliSatoshi.toFiat(rate: Double): Double = this.toUnit(BitcoinUnit.Btc) * rate

fun Double?.toPrettyString(unit: CurrencyUnit, withUnit: Boolean = false, mSatDisplayPolicy: MSatDisplayPolicy = MSatDisplayPolicy.HIDE): String = (this?.let { amount ->
when {
unit == BitcoinUnit.Sat && amount < 1.0 && mSatDisplayPolicy == MSatDisplayPolicy.SHOW_IF_ZERO_SATS -> {
SAT_FORMAT_WITH_MILLIS.format(amount)
fun Double?.toPrettyString(
unit: CurrencyUnit,
withUnit: Boolean = false,
mSatDisplayPolicy: MSatDisplayPolicy = MSatDisplayPolicy.HIDE,
): String {
val amount = this?.let {
when {
unit == BitcoinUnit.Sat && it < 1.0 && mSatDisplayPolicy == MSatDisplayPolicy.SHOW_IF_ZERO_SATS -> {
SAT_FORMAT_WITH_MILLIS.format(it)
}
unit is BitcoinUnit -> {
getCoinFormat(unit, withMillis = mSatDisplayPolicy == MSatDisplayPolicy.SHOW).format(it)
}
unit is FiatCurrency -> {
it.takeIf { it >= 0 }?.let { FIAT_FORMAT.format(it) }
}
else -> "?!"
}
unit is BitcoinUnit -> getCoinFormat(unit, withMillis = mSatDisplayPolicy == MSatDisplayPolicy.SHOW).format(amount)
unit is FiatCurrency -> amount.takeIf { it >= 0 }?.let { FIAT_FORMAT.format(it) }
else -> "?!"
} ?: "N/A"
return if (withUnit) {
"$amount ${unit.displayCode}"
} else {
amount
}
} ?: "N/A").run {
if (withUnit) "$this $unit" else this
}

fun MilliSatoshi.toPrettyStringWithFallback(unit: CurrencyUnit, rate: ExchangeRate.BitcoinPriceRate? = null, withUnit: Boolean = false, mSatDisplayPolicy: MSatDisplayPolicy = MSatDisplayPolicy.HIDE): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ object UserPrefs {
// -- unit, fiat, conversion...

private val BITCOIN_UNIT = stringPreferencesKey("BITCOIN_UNIT")
fun getBitcoinUnit(context: Context): Flow<BitcoinUnit> = prefs(context).map { BitcoinUnit.valueOf(it[BITCOIN_UNIT] ?: BitcoinUnit.Sat.name) }
fun getBitcoinUnit(context: Context): Flow<BitcoinUnit> = prefs(context).map { it[BITCOIN_UNIT]?.let { BitcoinUnit.valueOfOrNull(it) } ?: BitcoinUnit.Sat }
suspend fun saveBitcoinUnit(context: Context, coinUnit: BitcoinUnit) = context.userPrefs.edit { it[BITCOIN_UNIT] = coinUnit.name }

private val FIAT_CURRENCY = stringPreferencesKey("FIAT_CURRENCY")
fun getFiatCurrency(context: Context): Flow<FiatCurrency> = prefs(context).map { FiatCurrency.valueOf(it[FIAT_CURRENCY] ?: FiatCurrency.USD.name) }
fun getFiatCurrency(context: Context): Flow<FiatCurrency> = prefs(context).map { it[FIAT_CURRENCY]?.let { FiatCurrency.valueOfOrNull(it) } ?: FiatCurrency.USD }
suspend fun saveFiatCurrency(context: Context, currency: FiatCurrency) = context.userPrefs.edit { it[FIAT_CURRENCY] = currency.name }

private val SHOW_AMOUNT_IN_FIAT = booleanPreferencesKey("SHOW_AMOUNT_IN_FIAT")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,182 +65,25 @@ fun BitcoinUnit.label(): String = when (this) {

@Composable
fun FiatCurrency.labels(): Pair<String, String> {
val code = this.name
val context = LocalContext.current
return remember(key1 = code) {
return remember(key1 = displayCode) {
val fullName = when {
code.length == 3 -> try {
Currency.getInstance(code).displayName
// use the free market rates as default. Name for official rates gets a special tag, as those rates are usually inaccurate.
this == FiatCurrency.ARS -> context.getString(R.string.currency_ars_official)
this == FiatCurrency.ARS_BM -> context.getString(R.string.currency_ars_bm)
this == FiatCurrency.CUP -> context.getString(R.string.currency_cup_official)
this == FiatCurrency.CUP_FM -> context.getString(R.string.currency_cup_fm)
this == FiatCurrency.LBP -> context.getString(R.string.currency_lbp_official)
this == FiatCurrency.LBP_BM -> context.getString(R.string.currency_lbp_bm)
// use the JVM API otherwise to get the name
displayCode.length == 3 -> try {
Currency.getInstance(displayCode).displayName
} catch (e: Exception) {
"N/A"
}
code == "ARS_BM" -> context.getString(R.string.currency_ars_bm)
code == "CUP_FM" -> context.getString(R.string.currency_cup_fm)
code == "LBP_BM" -> context.getString(R.string.currency_lbp_bm)
else -> "N/A"
}
val flag = getFlag(code)
"$flag $code" to fullName
}
}

private fun getFlag(code: String): String {
return when (code) {
"AED" -> "🇦🇪" // United Arab Emirates Dirham
"AFN" -> "🇦🇫" // Afghan Afghani
"ALL" -> "🇦🇱" // Albanian Lek
"AMD" -> "🇦🇲" // Armenian Dram
"ANG" -> "🇳🇱" // Netherlands Antillean Guilder
"AOA" -> "🇦🇴" // Angolan Kwanza
"ARS_BM" -> "🇦🇷" // Argentine Peso (blue market)
"ARS" -> "🇦🇷" // Argentine Peso
"AUD" -> "🇦🇺" // Australian Dollar
"AWG" -> "🇦🇼" // Aruban Florin
"AZN" -> "🇦🇿" // Azerbaijani Manat
"BAM" -> "🇧🇦" // Bosnia-Herzegovina Convertible Mark
"BBD" -> "🇧🇧" // Barbadian Dollar
"BDT" -> "🇧🇩" // Bangladeshi Taka
"BGN" -> "🇧🇬" // Bulgarian Lev
"BHD" -> "🇧🇭" // Bahraini Dinar
"BIF" -> "🇧🇮" // Burundian Franc
"BMD" -> "🇧🇲" // Bermudan Dollar
"BND" -> "🇧🇳" // Brunei Dollar
"BOB" -> "🇧🇴" // Bolivian Boliviano
"BRL" -> "🇧🇷" // Brazilian Real
"BSD" -> "🇧🇸" // Bahamian Dollar
"BTN" -> "🇧🇹" // Bhutanese Ngultrum
"BWP" -> "🇧🇼" // Botswanan Pula
"BZD" -> "🇧🇿" // Belize Dollar
"CAD" -> "🇨🇦" // Canadian Dollar
"CDF" -> "🇨🇩" // Congolese Franc
"CHF" -> "🇨🇭" // Swiss Franc
"CLP" -> "🇨🇱" // Chilean Peso
"CNH" -> "🇨🇳" // Chinese Yuan (offshore)
"CNY" -> "🇨🇳" // Chinese Yuan (onshore)
"COP" -> "🇨🇴" // Colombian Peso
"CRC" -> "🇨🇷" // Costa Rican Colón
"CUP" -> "🇨🇺" // Cuban Peso
"CUP_FM" -> "🇨🇺" // Cuban Peso (free market)
"CVE" -> "🇨🇻" // Cape Verdean Escudo
"CZK" -> "🇨🇿" // Czech Koruna
"DJF" -> "🇩🇯" // Djiboutian Franc
"DKK" -> "🇩🇰" // Danish Krone
"DOP" -> "🇩🇴" // Dominican Peso
"DZD" -> "🇩🇿" // Algerian Dinar
"EGP" -> "🇪🇬" // Egyptian Pound
"ERN" -> "🇪🇷" // Eritrean Nakfa
"ETB" -> "🇪🇹" // Ethiopian Birr
"EUR" -> "🇪🇺" // Euro
"FJD" -> "🇫🇯" // Fijian Dollar
"FKP" -> "🇫🇰" // Falkland Islands Pound
"GBP" -> "🇬🇧" // British Pound Sterling
"GEL" -> "🇬🇪" // Georgian Lari
"GHS" -> "🇬🇭" // Ghanaian Cedi
"GIP" -> "🇬🇮" // Gibraltar Pound
"GMD" -> "🇬🇲" // Gambian Dalasi
"GNF" -> "🇬🇳" // Guinean Franc
"GTQ" -> "🇬🇹" // Guatemalan Quetzal
"GYD" -> "🇬🇾" // Guyanaese Dollar
"HKD" -> "🇭🇰" // Hong Kong Dollar
"HNL" -> "🇭🇳" // Honduran Lempira
"HRK" -> "🇭🇷" // Croatian Kuna
"HTG" -> "🇭🇹" // Haitian Gourde
"HUF" -> "🇭🇺" // Hungarian Forint
"IDR" -> "🇮🇩" // Indonesian Rupiah
"ILS" -> "🇮🇱" // Israeli New Sheqel
"INR" -> "🇮🇳" // Indian Rupee
"IQD" -> "🇮🇶" // Iraqi Dinar
"IRR" -> "🇮🇷" // Iranian Rial
"ISK" -> "🇮🇸" // Icelandic Króna
"JEP" -> "🇯🇪" // Jersey Pound
"JMD" -> "🇯🇲" // Jamaican Dollar
"JOD" -> "🇯🇴" // Jordanian Dinar
"JPY" -> "🇯🇵" // Japanese Yen
"KES" -> "🇰🇪" // Kenyan Shilling
"KGS" -> "🇰🇬" // Kyrgystani Som
"KHR" -> "🇰🇭" // Cambodian Riel
"KMF" -> "🇰🇲" // Comorian Franc
"KPW" -> "🇰🇵" // North Korean Won
"KRW" -> "🇰🇷" // South Korean Won
"KWD" -> "🇰🇼" // Kuwaiti Dinar
"KYD" -> "🇰🇾" // Cayman Islands Dollar
"KZT" -> "🇰🇿" // Kazakhstani Tenge
"LAK" -> "🇱🇦" // Laotian Kip
"LBP" -> "🇱🇧" // Lebanese Pound
"LBP_BM" -> "🇱🇧" // Lebanese Pound
"LKR" -> "🇱🇰" // Sri Lankan Rupee
"LRD" -> "🇱🇷" // Liberian Dollar
"LSL" -> "🇱🇸" // Lesotho Loti
"LYD" -> "🇱🇾" // Libyan Dinar
"MAD" -> "🇲🇦" // Moroccan Dirham
"MDL" -> "🇲🇩" // Moldovan Leu
"MGA" -> "🇲🇬" // Malagasy Ariary
"MKD" -> "🇲🇰" // Macedonian Denar
"MMK" -> "🇲🇲" // Myanmar Kyat
"MNT" -> "🇲🇳" // Mongolian Tugrik
"MOP" -> "🇲🇴" // Macanese Pataca
"MUR" -> "🇲🇺" // Mauritian Rupee
"MVR" -> "🇲🇻" // Maldivian Rufiyaa
"MWK" -> "🇲🇼" // Malawian Kwacha
"MXN" -> "🇲🇽" // Mexican Peso
"MYR" -> "🇲🇾" // Malaysian Ringgit
"MZN" -> "🇲🇿" // Mozambican Metical
"NAD" -> "🇳🇦" // Namibian Dollar
"NGN" -> "🇳🇬" // Nigerian Naira
"NIO" -> "🇳🇮" // Nicaraguan Córdoba
"NOK" -> "🇳🇴" // Norwegian Krone
"NPR" -> "🇳🇵" // Nepalese Rupee
"NZD" -> "🇳🇿" // New Zealand Dollar
"OMR" -> "🇴🇲" // Omani Rial
"PAB" -> "🇵🇦" // Panamanian Balboa
"PEN" -> "🇵🇪" // Peruvian Nuevo Sol
"PGK" -> "🇵🇬" // Papua New Guinean Kina
"PHP" -> "🇵🇭" // Philippine Peso
"PKR" -> "🇵🇰" // Pakistani Rupee
"PLN" -> "🇵🇱" // Polish Zloty
"PYG" -> "🇵🇾" // Paraguayan Guarani
"QAR" -> "🇶🇦" // Qatari Rial
"RON" -> "🇷🇴" // Romanian Leu
"RSD" -> "🇷🇸" // Serbian Dinar
"RUB" -> "🇷🇺" // Russian Ruble
"RWF" -> "🇷🇼" // Rwandan Franc
"SAR" -> "🇸🇦" // Saudi Riyal
"SBD" -> "🇸🇧" // Solomon Islands Dollar
"SCR" -> "🇸🇨" // Seychellois Rupee
"SDG" -> "🇸🇩" // Sudanese Pound
"SEK" -> "🇸🇪" // Swedish Krona
"SGD" -> "🇸🇬" // Singapore Dollar
"SHP" -> "🇸🇭" // Saint Helena Pound
"SLL" -> "🇸🇱" // Sierra Leonean Leone
"SOS" -> "🇸🇴" // Somali Shilling
"SRD" -> "🇸🇷" // Surinamese Dollar
"SYP" -> "🇸🇾" // Syrian Pound
"SZL" -> "🇸🇿" // Swazi Lilangeni
"THB" -> "🇹🇭" // Thai Baht
"TJS" -> "🇹🇯" // Tajikistani Somoni
"TMT" -> "🇹🇲" // Turkmenistani Manat
"TND" -> "🇹🇳" // Tunisian Dinar
"TOP" -> "🇹🇴" // Tongan Paʻanga
"TRY" -> "🇹🇷" // Turkish Lira
"TTD" -> "🇹🇹" // Trinidad and Tobago Dollar
"TWD" -> "🇹🇼" // New Taiwan Dollar
"TZS" -> "🇹🇿" // Tanzanian Shilling
"UAH" -> "🇺🇦" // Ukrainian Hryvnia
"UGX" -> "🇺🇬" // Ugandan Shilling
"USD" -> "🇺🇸" // United States Dollar
"UYU" -> "🇺🇾" // Uruguayan Peso
"UZS" -> "🇺🇿" // Uzbekistan Som
"VND" -> "🇻🇳" // Vietnamese Dong
"VUV" -> "🇻🇺" // Vanuatu Vatu
"WST" -> "🇼🇸" // Samoan Tala
"XAF" -> "🇨🇲" // CFA Franc BEAC - multiple options, chose country with highest GDP
"XCD" -> "🇱🇨" // East Caribbean Dollar - multiple options, chose country with highest GDP
"XOF" -> "🇨🇮" // CFA Franc BCEAO - multiple options, chose country with highest GDP
"XPF" -> "🇳🇨" // CFP Franc - multiple options, chose country with highest GDP
"YER" -> "🇾🇪" // Yemeni Rial
"ZAR" -> "🇿🇦" // South African Rand
"ZMW" -> "🇿🇲" // Zambian Kwacha
else -> "🏳️"
"$flag $displayCode" to fullName
}
}

Expand Down
13 changes: 8 additions & 5 deletions phoenix-android/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
<string name="send_error_amount_overpaying">Cannot pay more than %1$s.</string>
<string name="send_error_amount_below_requested">This amount is below the requested amount of %1$s.</string>
<string name="send_destination_label">Send to</string>
<string name="send_description_label">Payment description</string>
<string name="send_description_label">Description</string>
<string name="send_trampoline_fee_label">Fee</string>
<string name="send_trampoline_fee_no_amount">N/A</string>
<string name="send_trampoline_fee_loading">Loading fee…</string>
Expand Down Expand Up @@ -512,7 +512,7 @@
<!-- lnurl-pay -->

<string name="lnurl_pay_domain">Served by</string>
<string name="lnurl_pay_meta_description">Payment description</string>
<string name="lnurl_pay_meta_description">Description</string>
<string name="lnurl_pay_comment_add_button">Attach a message</string>
<string name="lnurl_pay_comment_label">My message</string>
<string name="lnurl_pay_comment_instructions">You can attach a message to the payment. This message will be sent to the recipient.</string>
Expand Down Expand Up @@ -654,9 +654,12 @@

<!-- settings: currencies -->

<string name="currency_ars_bm">Argentine Peso (blue market)</string>
<string name="currency_cup_fm">Cuban Peso (free market)</string>
<string name="currency_lbp_bm">Lebanese Pound (black market)</string>
<string name="currency_ars_official">Argentine Peso (official rate)</string>
<string name="currency_ars_bm">Argentine Peso</string>
<string name="currency_cup_official">Cuban Peso (official rate)</string>
<string name="currency_cup_fm">Cuban Peso</string>
<string name="currency_lbp_official">Lebanese Pound (official rate)</string>
<string name="currency_lbp_bm">Lebanese Pound</string>

<!-- payments history -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class LnurlAuthTest {
val legacyKeyManager = fr.acinq.eclair.crypto.LocalKeyManager(seed, Block.LivenetGenesisBlock().hash())
val kmpKeyManager = LocalKeyManager(
seed = seed.toArray().byteVector64(),
chain = NodeParams.Chain.Mainnet,
chain = NodeParams.Chain.Testnet,
remoteSwapInExtendedPublicKey = "tpubDDt5vQap1awkyDXx1z1cP7QFKSZHDCCpbU8nSq9jy7X2grTjUVZDePexf6gc6AHtRRzkgfPW87K6EKUVV6t3Hu2hg7YkHkmMeLSfrP85x41"
)

Expand Down
Loading

0 comments on commit 6e69d54

Please sign in to comment.