Skip to content

Commit

Permalink
ErgoAuth: Show error message for read-only wallets #112
Browse files Browse the repository at this point in the history
  • Loading branch information
MrStahlfelge committed May 9, 2022
1 parent 42c1a87 commit d097b70
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.view.ViewGroup
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import org.ergoplatform.SigningSecrets
import org.ergoplatform.android.AppDatabase
import org.ergoplatform.android.R
Expand Down Expand Up @@ -72,6 +73,18 @@ class ErgoAuthenticationFragment : AbstractAuthenticationFragment(), WalletChoos
}
}

override fun startAuthFlow() {
if (authenticationWalletConfig?.secretStorage == null) {
// read only wallet not supported (yet)
MaterialAlertDialogBuilder(requireContext())
.setMessage(R.string.error_wallet_type_ergoauth_not_avail)
.setPositiveButton(R.string.zxing_button_ok, null)
.show()
} else {
super.startAuthFlow()
}
}

override val authenticationWalletConfig: WalletConfig?
get() = viewModel.uiLogic.walletConfig

Expand Down
2 changes: 2 additions & 0 deletions android/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@
<string name="button_authenticate">Authenticate</string>
<string name="desc_authentication_wallet">Wallet used for authentication:</string>
<string name="desc_auth_response_send">Authentication was sent to dApp successfully.</string>
<string name="error_wallet_type_ergoauth_not_avail">ErgoAuth is not available for read-only wallets.
Please restore from mnemonic or use another wallet.</string>

<!-- Token information dialog -->
<string name="label_minting_tx">Minting transaction</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ const val STRING_ERROR_REQUEST_TOKEN_BUT_NO_ERG = "error_request_token_but_no_er
const val STRING_ERROR_REQUEST_TOKEN_NOT_FOUND = "error_request_token_not_found"
const val STRING_ERROR_SEND_TRANSACTION = "error_send_transaction"
const val STRING_ERROR_TOKEN_AMOUNT = "error_token_amount"
const val STRING_ERROR_WALLET_TYPE_ERGOAUTH_NOT_AVAIL = "error_wallet_type_ergoauth_not_avail"
const val STRING_ERROR_WORD_CONFIRM_CREATE_WALLET = "error_word_confirm_create_wallet"
const val STRING_EXPOSED_DROPDOWN_MENU_CONTENT_DESCRIPTION = "exposed_dropdown_menu_content_description"
const val STRING_FAB_TRANSFORMATION_SCRIM_BEHAVIOR = "fab_transformation_scrim_behavior"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,12 @@ abstract class ErgoAuthUiLogic {
requestJob = coroutineScope.launch(Dispatchers.IO) {
try {
notifyStateChanged(State.FETCHING_DATA)
if (walletId >= 0) {
walletConfig = db.walletDbProvider.loadWalletConfigById(walletId)
walletConfig = if (walletId >= 0) {
db.walletDbProvider.loadWalletConfigById(walletId)
} else {
walletConfig =
db.walletDbProvider.getAllWalletConfigsSynchronous().sortedBy {
it.displayName?.lowercase()
}.firstOrNull()
db.walletDbProvider.getAllWalletConfigsSynchronous().minByOrNull {
it.displayName?.lowercase() ?: ""
}
}

if (walletConfig == null) {
Expand Down
2 changes: 2 additions & 0 deletions ios/resources/i18n/strings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ error_request_token_but_no_erg=Tokens requested, but no ERG amount. A default am
error_request_token_not_found=Could not add token \'{0}\'
error_send_transaction=Could not send transaction
error_token_amount=Please enter valid token amounts or remove the invalid token entries
error_wallet_type_ergoauth_not_avail=ErgoAuth is not available for read-only wallets. \
Please restore from mnemonic or use another wallet.
error_word_confirm_create_wallet=Word not correct
exposed_dropdown_menu_content_description=Show dropdown menu
fab_transformation_scrim_behavior=com.google.android.material.transformation.FabTransformationScrimBehavior
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,18 @@ class ErgoAuthenticationViewController(
private val authButton = PrimaryButton(texts.getString(STRING_BUTTON_AUTHENTICATE)).apply {
addOnTouchUpInsideListener { _, _ ->
uiLogic.walletConfig?.let { walletConfig ->
startAuthFlow(walletConfig) { secrets ->
uiLogic.startResponse(secrets, texts)
if (walletConfig.secretStorage != null) {
startAuthFlow(walletConfig) { secrets ->
uiLogic.startResponse(secrets, texts)
}
} else {
presentViewController(
buildSimpleAlertController(
"",
texts.getString(STRING_ERROR_WALLET_TYPE_ERGOAUTH_NOT_AVAIL),
texts.i18NBundle
), true
) {}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package org.ergoplatform.ios.ui
import com.badlogic.gdx.utils.I18NBundle
import org.ergoplatform.uilogic.StringProvider

class IosStringProvider(private val texts: I18NBundle): StringProvider {
override fun getString(stringId: String): String = texts.get(stringId)
class IosStringProvider(val i18NBundle: I18NBundle): StringProvider {
override fun getString(stringId: String): String = i18NBundle.get(stringId)

override fun getString(stringId: String, vararg formatArgs: Any): String {
return texts.format(stringId, *formatArgs)
return i18NBundle.format(stringId, *formatArgs)
}
}

0 comments on commit d097b70

Please sign in to comment.