Skip to content

Commit

Permalink
Merge pull request #1029 from radixdlt/feature/ABW-3478-preselect-per…
Browse files Browse the repository at this point in the history
…sona

Pre-select single persona when none selected
  • Loading branch information
micbakos-rdx authored Jul 4, 2024
2 parents 10a0e02 + 4a9c42e commit f171dfd
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,18 @@ class SelectPersonaViewModel @Inject constructor(
personaUiModel
}
}.sortedByDescending { it.lastUsedOnTimestamp }
val currentlySelectedPersona = state.value.personaListToDisplay.firstOrNull { it.selected }
var currentlySelectedPersona = state.value.personaListToDisplay.firstOrNull { it.selected }
?: updatedPersonas.firstOrNull { it.lastUsedOn != null }

// When we have a single persona and there are no pre-selected ones, pre-select it.
if (currentlySelectedPersona == null && updatedPersonas.size == 1) {
currentlySelectedPersona = updatedPersonas[0]
}

currentlySelectedPersona?.persona?.let {
sendEvent(DAppSelectPersonaEvent.PersonaSelected(it))
}

return updatedPersonas.map { p ->
p.copy(selected = p.persona.address == currentlySelectedPersona?.persona?.address)
}
Expand Down

0 comments on commit f171dfd

Please sign in to comment.