diff --git a/crates/client/src/user.rs b/crates/client/src/user.rs index 82fc7f4713..df5ce67be3 100644 --- a/crates/client/src/user.rs +++ b/crates/client/src/user.rs @@ -114,7 +114,6 @@ pub struct UserStore { trial_started_at: Option>, is_usage_based_billing_enabled: Option, account_too_young: Option, - has_overdue_invoices: Option, current_user: watch::Receiver>>, accepted_tos_at: Option>>, contacts: Vec>, @@ -190,7 +189,6 @@ impl UserStore { trial_started_at: None, is_usage_based_billing_enabled: None, account_too_young: None, - has_overdue_invoices: None, accepted_tos_at: None, contacts: Default::default(), incoming_contact_requests: Default::default(), @@ -358,7 +356,6 @@ impl UserStore { .and_then(|trial_started_at| DateTime::from_timestamp(trial_started_at as i64, 0)); this.is_usage_based_billing_enabled = message.payload.is_usage_based_billing_enabled; this.account_too_young = message.payload.account_too_young; - this.has_overdue_invoices = message.payload.has_overdue_invoices; cx.emit(Event::PlanUpdated); cx.notify(); @@ -755,11 +752,6 @@ impl UserStore { self.account_too_young.unwrap_or(false) } - /// Returns whether the current user has overdue invoices and usage should be blocked. - pub fn has_overdue_invoices(&self) -> bool { - self.has_overdue_invoices.unwrap_or(false) - } - pub fn current_user_has_accepted_terms(&self) -> Option { self.accepted_tos_at .map(|accepted_tos_at| accepted_tos_at.is_some()) diff --git a/crates/inline_completion_button/src/inline_completion_button.rs b/crates/inline_completion_button/src/inline_completion_button.rs index 81d9181cfc..d402b87382 100644 --- a/crates/inline_completion_button/src/inline_completion_button.rs +++ b/crates/inline_completion_button/src/inline_completion_button.rs @@ -1,5 +1,5 @@ use anyhow::Result; -use client::{DisableAiSettings, UserStore, zed_urls}; +use client::{CloudUserStore, DisableAiSettings, zed_urls}; use cloud_llm_client::UsageLimit; use copilot::{Copilot, Status}; use editor::{ @@ -59,7 +59,7 @@ pub struct InlineCompletionButton { file: Option>, edit_prediction_provider: Option>, fs: Arc, - user_store: Entity, + cloud_user_store: Entity, popover_menu_handle: PopoverMenuHandle, } @@ -245,13 +245,16 @@ impl Render for InlineCompletionButton { IconName::ZedPredictDisabled }; - if zeta::should_show_upsell_modal(&self.user_store, cx) { - let tooltip_meta = - match self.user_store.read(cx).current_user_has_accepted_terms() { - Some(true) => "Choose a Plan", - Some(false) => "Accept the Terms of Service", - None => "Sign In", - }; + if zeta::should_show_upsell_modal(&self.cloud_user_store, cx) { + let tooltip_meta = if self.cloud_user_store.read(cx).is_authenticated() { + if self.cloud_user_store.read(cx).has_accepted_tos() { + "Choose a Plan" + } else { + "Accept the Terms of Service" + } + } else { + "Sign In" + }; return div().child( IconButton::new("zed-predict-pending-button", zeta_icon) @@ -368,7 +371,7 @@ impl Render for InlineCompletionButton { impl InlineCompletionButton { pub fn new( fs: Arc, - user_store: Entity, + cloud_user_store: Entity, popover_menu_handle: PopoverMenuHandle, cx: &mut Context, ) -> Self { @@ -389,7 +392,7 @@ impl InlineCompletionButton { edit_prediction_provider: None, popover_menu_handle, fs, - user_store, + cloud_user_store, } } @@ -760,7 +763,7 @@ impl InlineCompletionButton { }) }) .separator(); - } else if self.user_store.read(cx).account_too_young() { + } else if self.cloud_user_store.read(cx).account_too_young() { menu = menu .custom_entry( |_window, _cx| { @@ -775,7 +778,7 @@ impl InlineCompletionButton { cx.open_url(&zed_urls::account_url(cx)) }) .separator(); - } else if self.user_store.read(cx).has_overdue_invoices() { + } else if self.cloud_user_store.read(cx).has_overdue_invoices() { menu = menu .custom_entry( |_window, _cx| { diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index 0a43ec0bbe..060efdf26a 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -336,7 +336,7 @@ pub fn initialize_workspace( let edit_prediction_button = cx.new(|cx| { inline_completion_button::InlineCompletionButton::new( app_state.fs.clone(), - app_state.user_store.clone(), + app_state.cloud_user_store.clone(), inline_completion_menu_handle.clone(), cx, ) diff --git a/crates/zeta/src/zeta.rs b/crates/zeta/src/zeta.rs index d295b7d17c..0ef6bef59d 100644 --- a/crates/zeta/src/zeta.rs +++ b/crates/zeta/src/zeta.rs @@ -16,7 +16,7 @@ pub use rate_completion_modal::*; use anyhow::{Context as _, Result, anyhow}; use arrayvec::ArrayVec; -use client::{Client, CloudUserStore, EditPredictionUsage, UserStore}; +use client::{Client, CloudUserStore, EditPredictionUsage}; use cloud_llm_client::{ AcceptEditPredictionBody, EXPIRED_LLM_TOKEN_HEADER_NAME, MINIMUM_REQUIRED_VERSION_HEADER_NAME, PredictEditsBody, PredictEditsResponse, ZED_VERSION_HEADER_NAME, @@ -120,10 +120,11 @@ impl Dismissable for ZedPredictUpsell { } } -pub fn should_show_upsell_modal(user_store: &Entity, cx: &App) -> bool { - match user_store.read(cx).current_user_has_accepted_terms() { - Some(true) => !ZedPredictUpsell::dismissed(), - Some(false) | None => true, +pub fn should_show_upsell_modal(cloud_user_store: &Entity, cx: &App) -> bool { + if cloud_user_store.read(cx).has_accepted_tos() { + !ZedPredictUpsell::dismissed() + } else { + true } } @@ -1804,6 +1805,7 @@ fn tokens_for_bytes(bytes: usize) -> usize { #[cfg(test)] mod tests { + use client::UserStore; use client::test::FakeServer; use clock::FakeSystemClock; use cloud_api_types::{