diff --git a/wallet/res/drawable/ic_join_dashpay.xml b/wallet/res/drawable/ic_join_dashpay.xml new file mode 100644 index 000000000..0ecca52e5 --- /dev/null +++ b/wallet/res/drawable/ic_join_dashpay.xml @@ -0,0 +1,18 @@ + + + + + + diff --git a/wallet/res/layout/fragment_more.xml b/wallet/res/layout/fragment_more.xml index 6a3a64d74..cd9ff3bd8 100644 --- a/wallet/res/layout/fragment_more.xml +++ b/wallet/res/layout/fragment_more.xml @@ -179,59 +179,84 @@ - - + - + - + + + + + + + + + - - - + + - + - Accepting Contact Request Accepting There are no users that match - Searching for username "%" on the Dash Network + Searching for username \"%\" on the Dash Network Contact Request Pending Pay %s has requested to be a friend @@ -130,6 +130,7 @@ %s has sent you a contact request Your username %s has been successfully created on the Dash Network + Your username %s has been successfully requested on the Dash Network Not a valid Dash Username or Identity\n\n%s Sending to @@ -252,7 +253,7 @@ Welcome to Dash Pay Pay to usernames. No more alphanumeric addresses. Create a username - "Add your friends & family" + Add your friends & family Invite your family, find your friends by searching their usernames. Personalise profile Upload your picture, personalize your identity. @@ -301,7 +302,10 @@ Username is available Username is unavailable or blocked Username is taken - + Creating your username + Your username johndoe is being requested on the Dash network. It may take some time. + Your username request failed + For some reason, the request has failed. Please try again. Voting: This username has already been requested, but you can request it too and let the network vote to decide if you can have it Request details @@ -332,7 +336,7 @@ Your vote was submitted Your vote was cancelled Quick Voting - By tapping the "Vote for All" button, you will automatically vote for all of the filtered usernames (%d) that were submitted first + By tapping the \"Vote for All\" button, you will automatically vote for all of the filtered usernames (%d) that were submitted first Vote for All Username Voting Period Active There was a network error, you can try again at no extra cost @@ -384,7 +388,7 @@ Your credit balance is low Your credit balance is fully depleted - "You can continue to use DashPay for payments but you cannot update your profile or add more contacts until you top up your credit balance + You can continue to use DashPay for payments but you cannot update your profile or add more contacts until you top up your credit balance Top-up your credits to continue making changes to your profile and adding contacts Maybe later Buy Credits diff --git a/wallet/src/de/schildbach/wallet/database/entity/BlockchainIdentityData.kt b/wallet/src/de/schildbach/wallet/database/entity/BlockchainIdentityData.kt index 2b95dc621..f4d758658 100644 --- a/wallet/src/de/schildbach/wallet/database/entity/BlockchainIdentityData.kt +++ b/wallet/src/de/schildbach/wallet/database/entity/BlockchainIdentityData.kt @@ -244,6 +244,10 @@ open class BlockchainIdentityConfig @Inject constructor( blockchainIdentityData.usernameStatus?.let { prefs[USERNAME_REGISTRATION_STATUS] = it.name } blockchainIdentityData.privacyMode?.let { prefs[PRIVACY_MODE] = it.name } blockchainIdentityData.creditBalance?.let { prefs[BALANCE] = it.value } + blockchainIdentityData.usernameRequested?.let { prefs[USERNAME_REQUESTED] = it.name} + blockchainIdentityData.verificationLink?.let { prefs[REQUESTED_USERNAME_LINK] = it } + blockchainIdentityData.votingPeriodStart?.let { prefs[VOTING_PERIOD_START] = it } + blockchainIdentityData.cancelledVerificationLink?.let { prefs[CANCELED_REQUESTED_USERNAME_LINK] = it } } } @@ -256,6 +260,10 @@ open class BlockchainIdentityConfig @Inject constructor( blockchainIdentityBaseData.creditFundingTxId?.let { prefs[ASSET_LOCK_TXID] = it.toString() } prefs[USING_INVITE] = blockchainIdentityBaseData.usingInvite blockchainIdentityBaseData.invite?.let { prefs[INVITE_LINK] = it.link.toString() } + blockchainIdentityBaseData.usernameRequested?.let { prefs[USERNAME_REQUESTED] = it.name} + blockchainIdentityBaseData.verificationLink?.let { prefs[REQUESTED_USERNAME_LINK] = it } + blockchainIdentityBaseData.votingPeriodStart?.let { prefs[VOTING_PERIOD_START] = it } + blockchainIdentityBaseData.cancelledVerificationLink?.let { prefs[CANCELED_REQUESTED_USERNAME_LINK] = it } } } diff --git a/wallet/src/de/schildbach/wallet/service/platform/PlatformSyncService.kt b/wallet/src/de/schildbach/wallet/service/platform/PlatformSyncService.kt index 2c8449fd7..b9166b536 100644 --- a/wallet/src/de/schildbach/wallet/service/platform/PlatformSyncService.kt +++ b/wallet/src/de/schildbach/wallet/service/platform/PlatformSyncService.kt @@ -1025,30 +1025,34 @@ class PlatformSynchronizationService @Inject constructor( } override suspend fun updateUsernameRequestsWithVotes() { - val contestedNames = platform.platform.names.getContestedNames() - for (name in contestedNames) { - val voteContender = platform.platform.names.getVoteContenders(name) - voteContender.map.forEach { (identifier, contender) -> + try { + val contestedNames = platform.platform.names.getContestedNames() + for (name in contestedNames) { + val voteContender = platform.platform.names.getVoteContenders(name) + voteContender.map.forEach { (identifier, contender) -> - val contestedDocument = DomainDocument( - platform.platform.names.deserialize(contender.seralizedDocument) - ) + val contestedDocument = DomainDocument( + platform.platform.names.deserialize(contender.seralizedDocument) + ) - val identityVerifyDocument = IdentityVerify(platform.platform).get(identifier, name) - - val usernameRequest = UsernameRequest( - UsernameRequest.getRequestId(identifier.toString(), name), - contestedDocument.label, - name, - contestedDocument.createdAt?.div(1000) ?: -1L, - identifier.toString(), - identityVerifyDocument?.url, - contender.votes, - voteContender.lockVoteTally, - false - ) - usernameRequestDao.insert(usernameRequest) + val identityVerifyDocument = IdentityVerify(platform.platform).get(identifier, name) + + val usernameRequest = UsernameRequest( + UsernameRequest.getRequestId(identifier.toString(), name), + contestedDocument.label, + name, + contestedDocument.createdAt?.div(1000) ?: -1L, + identifier.toString(), + identityVerifyDocument?.url, + contender.votes, + voteContender.lockVoteTally, + false + ) + usernameRequestDao.insert(usernameRequest) + } } + } catch (e: Exception) { + log.info("problem obtaining votes:", e) } } diff --git a/wallet/src/de/schildbach/wallet/ui/dashpay/CreateIdentityService.kt b/wallet/src/de/schildbach/wallet/ui/dashpay/CreateIdentityService.kt index edd7cfe55..dc7e693e7 100644 --- a/wallet/src/de/schildbach/wallet/ui/dashpay/CreateIdentityService.kt +++ b/wallet/src/de/schildbach/wallet/ui/dashpay/CreateIdentityService.kt @@ -645,23 +645,13 @@ class CreateIdentityService : LifecycleService() { val document = DomainDocument( platformRepo.platform.names.deserialize(documentWithVotes.seralizedDocument) ) - blockchainIdentityData.verificationLink?.let { verificationLink -> - if (verificationLink.startsWith("https://") || verificationLink.startsWith("http://")) { - IdentityVerify(platformRepo.platform.platform).createForDashDomain( - blockchainIdentityData.username!!, - verificationLink, - blockchainIdentity.identity!!, - WalletSignerCallback(walletApplication.wallet!!, encryptionKey) - ) - } - } usernameRequestDao.insert( UsernameRequest( blockchainIdentity.uniqueIdString + " " + blockchainIdentityData.username!!, blockchainIdentityData.username!!, Names.normalizeString(blockchainIdentityData.username!!), - document.createdAt!! / 1000, + document.createdAt!!, blockchainIdentity.uniqueIdString, blockchainIdentityData.verificationLink, documentWithVotes.votes, @@ -681,6 +671,17 @@ class CreateIdentityService : LifecycleService() { if (blockchainIdentityData.creationState <= CreationState.REQUESTED_NAME_CHECKED) { platformRepo.updateIdentityCreationState(blockchainIdentityData, CreationState.REQUESTED_NAME_CHECKED) platformRepo.updateBlockchainIdentityData(blockchainIdentityData, blockchainIdentity) + + blockchainIdentityData.verificationLink?.let { verificationLink -> + if (verificationLink.startsWith("https://") || verificationLink.startsWith("http://")) { + IdentityVerify(platformRepo.platform.platform).createForDashDomain( + blockchainIdentityData.username!!, + verificationLink, + blockchainIdentity.identity!!, + WalletSignerCallback(walletApplication.wallet!!, encryptionKey) + ) + } + } } if (blockchainIdentityData.creationState <= CreationState.REQUESTED_NAME_LINK_SAVING) { @@ -847,7 +848,7 @@ class CreateIdentityService : LifecycleService() { UsernameRequest.getRequestId(blockchainIdentity.uniqueIdString, blockchainIdentity.currentUsername!!), contestedDocument.label, contestedDocument.normalizedLabel, - contestedDocument.createdAt!! / 1000, + contestedDocument.createdAt!!, blockchainIdentity.uniqueIdString, verifyDocument?.url, // get it from the document documentWithVotes.votes, diff --git a/wallet/src/de/schildbach/wallet/ui/dashpay/CreateIdentityViewModel.kt b/wallet/src/de/schildbach/wallet/ui/dashpay/CreateIdentityViewModel.kt new file mode 100644 index 000000000..22eaa4328 --- /dev/null +++ b/wallet/src/de/schildbach/wallet/ui/dashpay/CreateIdentityViewModel.kt @@ -0,0 +1,59 @@ +package de.schildbach.wallet.ui.dashpay + +import androidx.lifecycle.viewModelScope +import dagger.hilt.android.lifecycle.HiltViewModel +import de.schildbach.wallet.WalletApplication +import de.schildbach.wallet.database.dao.DashPayProfileDao +import de.schildbach.wallet.database.entity.BlockchainIdentityConfig +import de.schildbach.wallet.database.entity.BlockchainIdentityData +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.filterNotNull +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach +import kotlinx.coroutines.launch +import org.dash.wallet.common.services.analytics.AnalyticsService +import javax.inject.Inject + +@HiltViewModel +class CreateIdentityViewModel @Inject constructor( + private val walletApplication: WalletApplication, + private val analytics: AnalyticsService, + blockchainIdentityDataDao: BlockchainIdentityConfig, + dashPayProfileDao: DashPayProfileDao +) : BaseProfileViewModel(blockchainIdentityDataDao, dashPayProfileDao) { + + private val _creationState = MutableStateFlow(BlockchainIdentityData.CreationState.NONE) + val creationState: StateFlow + get() = _creationState + + private val _creationException = MutableStateFlow(null) + val creationException: StateFlow + get() = _creationException + init { + blockchainIdentityDataDao.observe(BlockchainIdentityConfig.CREATION_STATE) + .filterNotNull() + .onEach { + _creationState.value = BlockchainIdentityData.CreationState.valueOf(it) + } + .launchIn(viewModelScope) + + blockchainIdentityDataDao.observe(BlockchainIdentityConfig.CREATION_STATE_ERROR_MESSAGE) + .filterNotNull() + .onEach { + _creationException.value = it + } + .launchIn(viewModelScope) + } + + fun retryCreateIdentity() { + viewModelScope.launch { + val username = blockchainIdentityDataDao.get(BlockchainIdentityConfig.USERNAME) + walletApplication.startService( + CreateIdentityService.createIntentForRetry( + walletApplication + ) + ) + } + } +} \ No newline at end of file diff --git a/wallet/src/de/schildbach/wallet/ui/dashpay/work/BroadcastIdentityVerifyOperation.kt b/wallet/src/de/schildbach/wallet/ui/dashpay/work/BroadcastIdentityVerifyOperation.kt index abc77b112..c87a61d1f 100644 --- a/wallet/src/de/schildbach/wallet/ui/dashpay/work/BroadcastIdentityVerifyOperation.kt +++ b/wallet/src/de/schildbach/wallet/ui/dashpay/work/BroadcastIdentityVerifyOperation.kt @@ -45,13 +45,13 @@ class BroadcastIdentityVerifyOperation(val application: Application) { /** * Gets the list of all SendContactRequestWorker WorkInfo's */ - val allOperationsData = workManager.getWorkInfosByTagLiveData(SendContactRequestWorker::class.qualifiedName!!) + val allOperationsData = workManager.getWorkInfosByTagLiveData(BroadcastIdentityVerifyWorker::class.qualifiedName!!) @SuppressLint("EnqueueWork") fun create(username: String, url: String): WorkContinuation { val password = SecurityGuard().retrievePassword() - val sendContactRequestWorker = OneTimeWorkRequestBuilder() + val verifyIdentityWorker = OneTimeWorkRequestBuilder() .setInputData(workDataOf( BroadcastIdentityVerifyWorker.KEY_PASSWORD to password, BroadcastIdentityVerifyWorker.KEY_USERNAME to username, @@ -63,7 +63,7 @@ class BroadcastIdentityVerifyOperation(val application: Application) { return WorkManager.getInstance(application) .beginUniqueWork(uniqueWorkName(username), - ExistingWorkPolicy.KEEP, - sendContactRequestWorker) + ExistingWorkPolicy.KEEP, + verifyIdentityWorker) } } \ No newline at end of file diff --git a/wallet/src/de/schildbach/wallet/ui/invite/CreateInviteViewModel.kt b/wallet/src/de/schildbach/wallet/ui/invite/CreateInviteViewModel.kt index b73bc6dab..01d7a160b 100644 --- a/wallet/src/de/schildbach/wallet/ui/invite/CreateInviteViewModel.kt +++ b/wallet/src/de/schildbach/wallet/ui/invite/CreateInviteViewModel.kt @@ -29,17 +29,20 @@ import de.schildbach.wallet.database.dao.InvitationsDao import de.schildbach.wallet.database.entity.BlockchainIdentityConfig import de.schildbach.wallet.database.entity.BlockchainIdentityData import de.schildbach.wallet.ui.dashpay.BaseProfileViewModel +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.filterNotNull +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach import org.dash.wallet.common.WalletDataProvider -import org.dash.wallet.common.data.entity.BlockchainState import org.dash.wallet.common.services.analytics.AnalyticsService -import org.dash.wallet.common.util.observe import javax.inject.Inject @HiltViewModel class CreateInviteViewModel @Inject constructor( private val walletData: WalletDataProvider, private val analytics: AnalyticsService, - blockchainStateDao: BlockchainStateDao, + blockchainStateDao: BlockchainStateDao, invitationsDao: InvitationsDao, blockchainIdentityDataDao: BlockchainIdentityConfig, dashPayProfileDao: DashPayProfileDao diff --git a/wallet/src/de/schildbach/wallet/ui/more/MoreFragment.kt b/wallet/src/de/schildbach/wallet/ui/more/MoreFragment.kt index 4957d1cb2..daa4e93a0 100644 --- a/wallet/src/de/schildbach/wallet/ui/more/MoreFragment.kt +++ b/wallet/src/de/schildbach/wallet/ui/more/MoreFragment.kt @@ -43,6 +43,7 @@ import de.schildbach.wallet.ui.EditProfileActivity import de.schildbach.wallet.ui.LockScreenActivity import de.schildbach.wallet.ui.ReportIssueDialogBuilder import de.schildbach.wallet.ui.SettingsActivity +import de.schildbach.wallet.ui.dashpay.CreateIdentityViewModel import de.schildbach.wallet.ui.dashpay.EditProfileViewModel import de.schildbach.wallet.ui.dashpay.utils.display import de.schildbach.wallet.ui.invite.CreateInviteViewModel @@ -60,6 +61,7 @@ import org.dash.wallet.common.ui.avatar.ProfilePictureDisplay import org.dash.wallet.common.ui.viewBinding import org.dash.wallet.common.util.observe import org.dash.wallet.common.util.safeNavigate +import org.dashj.platform.sdk.platform.Names import org.slf4j.LoggerFactory import java.util.concurrent.TimeUnit import javax.inject.Inject @@ -81,6 +83,7 @@ class MoreFragment : Fragment(R.layout.fragment_more) { private val mainActivityViewModel: MainViewModel by activityViewModels() private val editProfileViewModel: EditProfileViewModel by viewModels() private val createInviteViewModel: CreateInviteViewModel by viewModels() + private val createIdentityViewModel: CreateIdentityViewModel by viewModels() @Inject lateinit var packageInfoProvider: PackageInfoProvider @Inject lateinit var configuration: Configuration @@ -175,38 +178,52 @@ class MoreFragment : Fragment(R.layout.fragment_more) { } binding.requestedUsernameContainer.setOnClickListener { - startActivity(Intent(requireContext(), CreateUsernameActivity::class.java)) + if (createIdentityViewModel.creationState.value.ordinal < BlockchainIdentityData.CreationState.VOTING.ordinal && + createIdentityViewModel.creationException.value != null) { + // Perform Retry + createIdentityViewModel.retryCreateIdentity() + } else { + startActivity(Intent(requireContext(), CreateUsernameActivity::class.java)) + } } mainActivityViewModel.blockchainIdentityDataDao.observeBase().observe(viewLifecycleOwner) { - if (it.creationState == BlockchainIdentityData.CreationState.VOTING) { + if (it.creationState.ordinal > BlockchainIdentityData.CreationState.NONE.ordinal && + it.creationState.ordinal < BlockchainIdentityData.CreationState.VOTING.ordinal && + !Names.isUsernameContestable(it.username!!)) { + + binding.joinDashpayContainer.visibility = View.GONE + binding.requestedUsernameContainer.visibility = View.VISIBLE + if (it.creationError) { + binding.requestedUsernameTitle.text = getString(R.string.requesting_your_username_error_title) + binding.requestedUsernameSubtitle.text = getString(R.string.requesting_your_username_error_message) + binding.retryRequestButton.isVisible = true + } else { + // show the status + binding.requestedUsernameTitle.text = getString(R.string.requesting_your_username_title) + binding.requestedUsernameSubtitle.text = getString(R.string.requesting_your_username_message) + binding.retryRequestButton.isVisible = false + } + } else if (it.creationState == BlockchainIdentityData.CreationState.VOTING) { binding.joinDashpayContainer.visibility = View.GONE binding.requestedUsernameContainer.visibility = View.VISIBLE binding.requestedUsernameTitle.text = mainActivityViewModel.getRequestedUsername() val votingPeriod = it.votingPeriodStart?.let { startTime -> - val endTime = startTime + TimeUnit.MILLISECONDS.toDays(14) + val endTime = startTime + TimeUnit.DAYS.toMillis(14) val dateFormat = DateFormat.getMediumDateFormat(requireContext()) - String.format("%s - %s", dateFormat.format(startTime), dateFormat.format(endTime)) + String.format("%s", dateFormat.format(endTime)) } ?: "Voting Period not found" binding.requestedUsernameSubtitleTwo.text = getString(R.string.requested_voting_duration, votingPeriod) + binding.retryRequestButton.isVisible = false } else { binding.joinDashpayContainer.visibility = View.VISIBLE binding.requestedUsernameContainer.visibility = View.GONE } } -// lifecycleScope.launch { -// mainActivityViewModel.getRequestedUsername().also { username -> -// if (username.isNotEmpty()) { -// binding.joinDashpayContainer.visibility = View.GONE -// binding.requestedUsernameContainer.visibility = View.VISIBLE -// binding.requestedUsernameTitle.text = username -// } else { -// binding.joinDashpayContainer.visibility = View.VISIBLE -// binding.requestedUsernameContainer.visibility = View.GONE -// } -// } -// } + binding.retryRequestButton.setOnClickListener { + // TODO: restart CreateIdentityService + } initViewModel() @@ -234,6 +251,12 @@ class MoreFragment : Fragment(R.layout.fragment_more) { showProfileSection(dashPayProfile) } } + createIdentityViewModel.creationState.observe(viewLifecycleOwner) { _ -> + editProfileViewModel.dashPayProfile.value?.let { dashPayProfile -> + showProfileSection(dashPayProfile) + } + } + // track the status of broadcast changes to our profile editProfileViewModel.updateProfileRequestState.observe(viewLifecycleOwner) { state -> if (state != null) { @@ -303,25 +326,30 @@ class MoreFragment : Fragment(R.layout.fragment_more) { } private fun showProfileSection(profile: DashPayProfile) { - binding.editUpdateSwitcher.visibility = View.VISIBLE - binding.editUpdateSwitcher.displayedChild = PROFILE_VIEW - if (profile.displayName.isNotEmpty()) { - binding.username1.text = profile.displayName - binding.username2.text = profile.username - } else { - binding.username1.text = profile.username - binding.username2.visibility = View.GONE - } + if (createIdentityViewModel.creationState.value.ordinal >= BlockchainIdentityData.CreationState.DONE.ordinal) { + binding.editUpdateSwitcher.visibility = View.VISIBLE + binding.editUpdateSwitcher.displayedChild = PROFILE_VIEW + if (profile.displayName.isNotEmpty()) { + binding.username1.text = profile.displayName + binding.username2.text = profile.username + } else { + binding.username1.text = profile.username + binding.username2.visibility = View.GONE + } - ProfilePictureDisplay.display(binding.dashpayUserAvatar, profile) + ProfilePictureDisplay.display(binding.dashpayUserAvatar, profile) - binding.editProfile.setOnClickListener { - editProfileViewModel.logEvent(AnalyticsConstants.UsersContacts.PROFILE_EDIT_MORE) - startActivity(Intent(requireContext(), EditProfileActivity::class.java)) - } - // if the invite section is not visible, show/hide it - if (!binding.invite.isVisible) { - binding.invite.isVisible = showInviteSection + binding.editProfile.setOnClickListener { + editProfileViewModel.logEvent(AnalyticsConstants.UsersContacts.PROFILE_EDIT_MORE) + startActivity(Intent(requireContext(), EditProfileActivity::class.java)) + } + // if the invite section is not visible, show/hide it + if (!binding.invite.isVisible) { + binding.invite.isVisible = showInviteSection + } + } else { + binding.editUpdateSwitcher.isVisible = false + binding.invite.isVisible = true } } diff --git a/wallet/src/de/schildbach/wallet/ui/username/UsernameRegistrationFragment.kt b/wallet/src/de/schildbach/wallet/ui/username/UsernameRegistrationFragment.kt index 345bb144d..85f697a97 100644 --- a/wallet/src/de/schildbach/wallet/ui/username/UsernameRegistrationFragment.kt +++ b/wallet/src/de/schildbach/wallet/ui/username/UsernameRegistrationFragment.kt @@ -64,30 +64,20 @@ class UsernameRegistrationFragment : Fragment(R.layout.fragment_username_registr private var reuseTransaction: Boolean = false private var useInvite: Boolean = false - private var handler: Handler = Handler() - private lateinit var checkUsernameNotExistRunnable: Runnable - private var createUsernameArgs: CreateUsernameArgs? = null private val slideInAnimation by lazy { AnimationUtils.loadAnimation(requireContext(), R.anim.slide_in_bottom) } private val fadeOutAnimation by lazy { AnimationUtils.loadAnimation(requireContext(), R.anim.fade_out) } private lateinit var completeUsername: String private var isProcessing = false - @SuppressLint("ResourceType") override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) binding.chooseUsernameTitle.text = getText(R.string.choose_your_username) binding.closeBtn.setOnClickListener { - if (requestUsernameViewModel.isUsernameContestable()) { - startActivity(MainActivity.createIntent(requireContext(), R.id.moreFragment)) - } else { - // go to the home screen - startActivity(MainActivity.createIntent(requireContext())) - } - requireActivity().finish() + closeActivity() } - binding.processingIdentityDismissBtn.setOnClickListener { requireActivity().finish() } + binding.processingIdentityDismissBtn.setOnClickListener { closeActivity() } initViewModel() walletApplication = requireActivity().application as WalletApplication @@ -106,7 +96,6 @@ class UsernameRegistrationFragment : Fragment(R.layout.fragment_username_registr } CreateUsernameActions.REUSE_TRANSACTION -> { reuseTransaction = true - //showKeyBoard() } CreateUsernameActions.FROM_INVITE -> { // don't show the keyboard if launched from invite @@ -118,6 +107,17 @@ class UsernameRegistrationFragment : Fragment(R.layout.fragment_username_registr } } + @SuppressLint("ResourceType") + private fun closeActivity() { + if (requestUsernameViewModel.isUsernameContestable()) { + startActivity(MainActivity.createIntent(requireContext(), R.id.moreFragment)) + } else { + // go to the home screen + startActivity(MainActivity.createIntent(requireContext(), R.id.walletFragment)) + } + requireActivity().finish() + } + private fun initViewModel() { dashPayViewModel.blockchainIdentity.observe(viewLifecycleOwner) { when { @@ -150,14 +150,21 @@ class UsernameRegistrationFragment : Fragment(R.layout.fragment_username_registr binding.orbitView.findViewById(R.id.dashpay_user_icon).visibility = View.VISIBLE binding.orbitView.findViewById(R.id.username_1st_letter).text = completeUsername[0].toString() - val text = getString(R.string.identity_complete_message, completeUsername) + val text = getString( + if (requestUsernameViewModel.isUsernameContestable()) { + R.string.request_complete_message + } else { + R.string.identity_complete_message + }, + completeUsername + ) val spannableContent = SpannableString(text) val start = text.indexOf(completeUsername) val end = start + completeUsername.length spannableContent.setSpan(StyleSpan(Typeface.BOLD), start, end, 0) binding.identityCompleteText.text = spannableContent - binding.identityCompleteButton.setOnClickListener { requireActivity().finish() } + binding.identityCompleteButton.setOnClickListener { closeActivity() } } private fun showProcessingState() { diff --git a/wallet/src/de/schildbach/wallet/ui/username/voting/RequestUserNameViewModel.kt b/wallet/src/de/schildbach/wallet/ui/username/voting/RequestUserNameViewModel.kt index 63e6a5327..587f77277 100644 --- a/wallet/src/de/schildbach/wallet/ui/username/voting/RequestUserNameViewModel.kt +++ b/wallet/src/de/schildbach/wallet/ui/username/voting/RequestUserNameViewModel.kt @@ -280,7 +280,7 @@ class RequestUserNameViewModel @Inject constructor( BroadcastIdentityVerifyOperation(walletApplication).create( requestedUserName!!, url - ) + ).enqueue() } } } diff --git a/wallet/src/de/schildbach/wallet/ui/username/voting/VotingRequestDetailsFragment.kt b/wallet/src/de/schildbach/wallet/ui/username/voting/VotingRequestDetailsFragment.kt index 1f34b86a4..f3169f314 100644 --- a/wallet/src/de/schildbach/wallet/ui/username/voting/VotingRequestDetailsFragment.kt +++ b/wallet/src/de/schildbach/wallet/ui/username/voting/VotingRequestDetailsFragment.kt @@ -45,8 +45,6 @@ class VotingRequestDetailsFragment : Fragment(R.layout.fragment_voting_request_d binding.titleBar.setNavigationOnClickListener { requireActivity().finish() } - // TODO Mock identity - binding.verify.setOnClickListener { safeNavigate( @@ -59,12 +57,12 @@ class VotingRequestDetailsFragment : Fragment(R.layout.fragment_voting_request_d binding.username.text = myUsernameRequest?.username binding.identity.text = myUsernameRequest?.identity val votingPeriod = myUsernameRequest?.createdAt?.let { startTime -> - val endTime = startTime + TimeUnit.MILLISECONDS.toDays(14) + val endTime = startTime + TimeUnit.DAYS.toMillis(14) val dateFormat = DateFormat.getMediumDateFormat(requireContext()) dateFormat.format(endTime) } ?: "Voting Period not found" binding.votingRange.text = votingPeriod - if (myUsernameRequest?.link != null) { + if (myUsernameRequest?.link != null && myUsernameRequest.link != "") { binding.link.text = myUsernameRequest.link binding.linkLayout.isVisible = true binding.verfiyNowLayout.isVisible = false @@ -93,13 +91,12 @@ class VotingRequestDetailsFragment : Fragment(R.layout.fragment_voting_request_d "" ).show(requireActivity()) } - } } binding.ivInfo.setOnClickListener { safeNavigate( - VotingRequestDetailsFragmentDirections.votingRequestDetailsFragmentToUsernameVotingInfoFragment() + VotingRequestDetailsFragmentDirections.votingRequestDetailsFragmentToUsernameVotingInfoFragment(true) ) } }