defmodule WandererAppWeb.MapSubscription do use WandererAppWeb, :live_component use LiveViewEvents alias BetterNumber, as: Number @impl true def mount(socket) do socket = socket |> assign(title: "") |> assign(status: :alpha) |> assign(balance: 0) {:ok, socket} end @impl true def update( %{ current_user: current_user, map_slug: map_slug } = assigns, socket ) do socket = handle_info_or_assign(socket, assigns) with {:ok, %{id: map_id} = map} <- WandererApp.MapRepo.get_by_slug_with_permissions(map_slug, current_user), {:ok, %{plan: plan} = subscription} <- WandererApp.Map.SubscriptionManager.get_active_map_subscription(map_id), {:ok, map_balance} <- WandererApp.Map.SubscriptionManager.get_balance(map) do {:ok, socket |> assign(status: plan) |> assign(title: get_title(subscription)) |> assign(balance: map_balance)} else _error -> {:ok, socket} end end @impl true def render(assigns) do ~H"""