-
Notifications
You must be signed in to change notification settings - Fork 674
Fix issue with "Change email" behavior in Link #10706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ import com.stripe.android.link.injection.NativeLinkComponent | |
import com.stripe.android.link.model.AccountStatus | ||
import com.stripe.android.link.model.LinkAccount | ||
import com.stripe.android.link.ui.LinkAppBarState | ||
import com.stripe.android.link.ui.signup.SignUpViewModel | ||
import com.stripe.android.link.ui.signup.SignUpViewModel.Companion.DID_SELECT_TO_CHANGE_EMAIL | ||
import com.stripe.android.link.utils.LINK_DEFAULT_ANIMATION_DELAY_MILLIS | ||
import com.stripe.android.paymentelement.confirmation.ConfirmationHandler | ||
import com.stripe.android.paymentsheet.analytics.EventReporter | ||
|
@@ -64,6 +64,9 @@ internal class LinkActivityViewModel @Inject constructor( | |
private val _linkScreenState = MutableStateFlow<ScreenState>(ScreenState.Loading) | ||
val linkScreenState: StateFlow<ScreenState> = _linkScreenState | ||
|
||
private val didChangeEmail: Boolean | ||
get() = savedStateHandle.get<Boolean>(DID_SELECT_TO_CHANGE_EMAIL) == true | ||
|
||
val linkAccount: LinkAccount? | ||
get() = linkAccountManager.linkAccount.value | ||
|
||
|
@@ -131,7 +134,11 @@ internal class LinkActivityViewModel @Inject constructor( | |
fun handleBackPressed() { | ||
dismissWithResult?.invoke( | ||
LinkActivityResult.Canceled( | ||
linkAccountUpdate = linkAccountManager.linkAccountUpdate | ||
linkAccountUpdate = if (didChangeEmail) { | ||
LinkAccountUpdate.Value(null) | ||
} else { | ||
LinkAccountUpdate.Value(linkAccount) | ||
}, | ||
) | ||
) | ||
} | ||
|
@@ -157,7 +164,7 @@ internal class LinkActivityViewModel @Inject constructor( | |
} | ||
|
||
fun changeEmail() { | ||
savedStateHandle[SignUpViewModel.USE_LINK_CONFIGURATION_CUSTOMER_INFO] = false | ||
savedStateHandle[DID_SELECT_TO_CHANGE_EMAIL] = true | ||
navigate(LinkScreen.SignUp, clearStack = true) | ||
} | ||
|
||
|
@@ -248,7 +255,7 @@ internal class LinkActivityViewModel @Inject constructor( | |
|
||
DaggerNativeLinkComponent | ||
.builder() | ||
.configuration(args.configuration) | ||
.configuration(args.configurationWithUpdatedCustomerInfo) | ||
.publishableKeyProvider { args.publishableKey } | ||
.stripeAccountIdProvider { args.stripeAccountId } | ||
.paymentElementCallbackIdentifier(args.paymentElementCallbackIdentifier) | ||
|
@@ -271,3 +278,16 @@ internal sealed interface ScreenState { | |
} | ||
|
||
internal class NoArgsException : IllegalArgumentException("NativeLinkArgs not found") | ||
|
||
private val NativeLinkArgs.configurationWithUpdatedCustomerInfo: LinkConfiguration | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit - I think this is more understandable as an extension function of
|
||
// The user might have logged out on a previous Link session. We clear the customer information | ||
// to avoid us defaulting back to the account that they previously logged out of. | ||
get() { | ||
val clearCustomerDetails = linkAccount == null | ||
val effectiveCustomerInfo = if (clearCustomerDetails) { | ||
LinkConfiguration.CustomerInfo(null, null, null, null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking of only setting the email address to |
||
} else { | ||
configuration.customerInfo | ||
} | ||
return configuration.copy(customerInfo = effectiveCustomerInfo) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be weird that this happens here, but if we don't update the
configuration
, then this code will fetch the Link account associated with that email address.