Add more servers to the list (#1394)

- 8 more servers added to the list
- Order of servers changed to show default as 1st, custom as 2nd
This commit is contained in:
Honza Rychnovský 2024-04-24 18:47:23 +02:00 committed by GitHub
parent e0439f0ca9
commit 2ac9f5ebd4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 44 additions and 16 deletions

View File

@ -18,20 +18,40 @@ object AvailableServerProvider {
// Mainnet: mainnet.lightwalletd.com | 9067
// Testnet: lightwalletd.testnet.electriccoin.co | 9067
private const val HOST_NA = "na.lightwalletd.com" // NON-NLS
private const val HOST_SA = "sa.lightwalletd.com" // NON-NLS
private const val HOST_EU = "eu.lightwalletd.com" // NON-NLS
private const val HOST_AI = "ai.lightwalletd.com" // NON-NLS
private const val PORT = 443
private const val NH_HOST_NA = "na.lightwalletd.com" // NON-NLS
private const val NH_HOST_SA = "sa.lightwalletd.com" // NON-NLS
private const val NH_HOST_EU = "eu.lightwalletd.com" // NON-NLS
private const val NH_HOST_AI = "ai.lightwalletd.com" // NON-NLS
private const val NH_PORT = 443
private const val YW_HOST_1 = "lwd1.zcash-infra.com" // NON-NLS
private const val YW_HOST_2 = "lwd2.zcash-infra.com" // NON-NLS
private const val YW_HOST_3 = "lwd3.zcash-infra.com" // NON-NLS
private const val YW_HOST_4 = "lwd4.zcash-infra.com" // NON-NLS
private const val YW_HOST_5 = "lwd5.zcash-infra.com" // NON-NLS
private const val YW_HOST_6 = "lwd6.zcash-infra.com" // NON-NLS
private const val YW_HOST_7 = "lwd7.zcash-infra.com" // NON-NLS
private const val YW_HOST_8 = "lwd8.zcash-infra.com" // NON-NLS
private const val YW_PORT = 9067
fun toList(network: ZcashNetwork) =
buildList {
if (network == ZcashNetwork.Mainnet) {
add(LightWalletEndpoint.Mainnet)
add(LightWalletEndpoint(HOST_NA, PORT, true))
add(LightWalletEndpoint(HOST_SA, PORT, true))
add(LightWalletEndpoint(HOST_EU, PORT, true))
add(LightWalletEndpoint(HOST_AI, PORT, true))
add(LightWalletEndpoint(YW_HOST_1, YW_PORT, true))
add(LightWalletEndpoint(YW_HOST_2, YW_PORT, true))
add(LightWalletEndpoint(YW_HOST_3, YW_PORT, true))
add(LightWalletEndpoint(YW_HOST_4, YW_PORT, true))
add(LightWalletEndpoint(YW_HOST_5, YW_PORT, true))
add(LightWalletEndpoint(YW_HOST_6, YW_PORT, true))
add(LightWalletEndpoint(YW_HOST_7, YW_PORT, true))
add(LightWalletEndpoint(YW_HOST_8, YW_PORT, true))
add(LightWalletEndpoint(NH_HOST_NA, NH_PORT, true))
add(LightWalletEndpoint(NH_HOST_SA, NH_PORT, true))
add(LightWalletEndpoint(NH_HOST_EU, NH_PORT, true))
add(LightWalletEndpoint(NH_HOST_AI, NH_PORT, true))
} else {
add(LightWalletEndpoint.Testnet)
}

View File

@ -145,6 +145,8 @@ private fun ChooseServerTopAppBar(
)
}
const val CUSTOM_SERVER_OPTION_INDEX = 1
@Composable
@Suppress("LongMethod", "LongParameterList")
private fun ChooseServerMainContent(
@ -162,10 +164,10 @@ private fun ChooseServerMainContent(
// server list obtaining is implemented.
if (contains(wallet.endpoint)) {
// We define the custom server as secured by default
add(LightWalletEndpoint("", -1, true))
add(CUSTOM_SERVER_OPTION_INDEX, LightWalletEndpoint("", -1, true))
} else {
// Adding previously chosen custom endpoint
add(wallet.endpoint)
add(CUSTOM_SERVER_OPTION_INDEX, wallet.endpoint)
}
}.toImmutableList()
@ -175,9 +177,13 @@ private fun ChooseServerMainContent(
}
val initialCustomServerValue =
options.last().run {
if (options.last().isValid()) {
stringResource(R.string.choose_server_textfield_value, options.last().host, options.last().port)
options[CUSTOM_SERVER_OPTION_INDEX].run {
if (options[CUSTOM_SERVER_OPTION_INDEX].isValid()) {
stringResource(
R.string.choose_server_textfield_value,
options[CUSTOM_SERVER_OPTION_INDEX].host,
options[CUSTOM_SERVER_OPTION_INDEX].port
)
} else {
""
}
@ -243,7 +249,7 @@ fun ServerList(
options.forEachIndexed { index, endpoint ->
val isSelected = index == selectedOption
if (index == options.lastIndex) {
if (index == CUSTOM_SERVER_OPTION_INDEX) {
Column(
modifier = Modifier.animateContentSize()
) {
@ -284,6 +290,8 @@ fun ServerList(
.fillMaxWidth()
.padding(horizontal = ZcashTheme.dimens.spacingSmall)
)
Spacer(modifier = Modifier.height(ZcashTheme.dimens.spacingSmall))
}
}
} else {
@ -339,7 +347,7 @@ fun SaveButton(
text = stringResource(id = R.string.choose_server_save),
onClick = {
val selectedServer =
if (selectedOption == options.lastIndex) {
if (selectedOption == CUSTOM_SERVER_OPTION_INDEX) {
if (!validateCustomServerValue(customServerValue)) {
setShowErrorDialog(true)
return@PrimaryButton