diff --git a/lib/sanbase/accounts/eth_account.ex b/lib/sanbase/accounts/eth_account.ex index fdb7096f94..8cc6cbb639 100644 --- a/lib/sanbase/accounts/eth_account.ex +++ b/lib/sanbase/accounts/eth_account.ex @@ -125,16 +125,27 @@ defmodule Sanbase.Accounts.EthAccount do # Helpers defp contract_data_map(contract) do - %{ - total_supply: UniswapPair.total_supply(contract), - reserves: UniswapPair.reserves(contract) |> elem(UniswapPair.get_san_position(contract)) - } + with total_supply when is_float(total_supply) <- UniswapPair.total_supply(contract), + {reserves, _} when is_float(reserves) <- UniswapPair.reserves(contract) do + %{ + total_supply: total_supply, + reserves: reserves |> elem(UniswapPair.get_san_position(contract)) + } + else + {:error, _} -> %{total_supply: 0.0, reserves: 0.0} + _ -> %{total_supply: 0.0, reserves: 0.0} + end end defp calculate_san_staked(address_staked_tokens, _data_map) when address_staked_tokens == 0.0 do +0.0 end + defp calculate_san_staked(_address_staked_tokens, %{total_supply: total_supply}) + when total_supply == 0.0 do + +0.0 + end + defp calculate_san_staked(address_staked_tokens, data_map) do # Convert the LP tokens to the actual value of SAN tokens address_share = address_staked_tokens / data_map.total_supply diff --git a/lib/sanbase_web/graphql/resolvers/project/project_list_resolver.ex b/lib/sanbase_web/graphql/resolvers/project/project_list_resolver.ex index ea41374148..450d4d0155 100644 --- a/lib/sanbase_web/graphql/resolvers/project/project_list_resolver.ex +++ b/lib/sanbase_web/graphql/resolvers/project/project_list_resolver.ex @@ -51,6 +51,10 @@ defmodule SanbaseWeb.Graphql.Resolvers.ProjectListResolver do end end + def all_projects_by_function(_root, _args, _resolution) do + {:error, "Invalid arguments provided to all_projects_by_function"} + end + def all_projects_by_ticker(_root, %{ticker: ticker}, _resolution) do projects = Project.List.projects_by_ticker(ticker) |> Enum.uniq_by(& &1.id) diff --git a/lib/sanbase_web/live/ecosystem_labeling/suggest_ecosystems_labels_change_live.ex b/lib/sanbase_web/live/ecosystem_labeling/suggest_ecosystems_labels_change_live.ex index 3cd111ef72..fbff974049 100644 --- a/lib/sanbase_web/live/ecosystem_labeling/suggest_ecosystems_labels_change_live.ex +++ b/lib/sanbase_web/live/ecosystem_labeling/suggest_ecosystems_labels_change_live.ex @@ -33,17 +33,23 @@ defmodule SanbaseWeb.SuggestEcosystemLabelsChangeLive do socket slug -> - project = Enum.find(socket.assigns.projects, &(&1.slug == slug)) - stored_ecosystems = project.ecosystems - - socket - |> assign( - selected_project: project, - stored_project_ecosystems: stored_ecosystems, - new_project_ecosystems: [], - removed_project_ecosystems: [], - ecosystems: order_ecosystems(socket.assigns.ecosystems, stored_ecosystems) - ) + case Enum.find(socket.assigns.projects, &(&1.slug == slug)) do + nil -> + socket + |> put_flash(:error, "Project not found") + + project -> + stored_ecosystems = project.ecosystems + + socket + |> assign( + selected_project: project, + stored_project_ecosystems: stored_ecosystems, + new_project_ecosystems: [], + removed_project_ecosystems: [], + ecosystems: order_ecosystems(socket.assigns.ecosystems, stored_ecosystems) + ) + end end {:noreply, socket} diff --git a/lib/sanbase_web/live/github_organizations/suggest_github_organizations_live.ex b/lib/sanbase_web/live/github_organizations/suggest_github_organizations_live.ex index 99bf89eabc..16c9535afd 100644 --- a/lib/sanbase_web/live/github_organizations/suggest_github_organizations_live.ex +++ b/lib/sanbase_web/live/github_organizations/suggest_github_organizations_live.ex @@ -32,17 +32,23 @@ defmodule SanbaseWeb.SuggestGithubOrganizationsLive do socket slug -> - project = Enum.find(socket.assigns.projects, &(&1.slug == slug)) - stored_organizations = project.github_organizations |> Enum.map(& &1.organization) - - socket - |> assign( - selected_project: project, - stored_organizations: stored_organizations, - seen_organizations: stored_organizations, - new_organizations: [], - removed_organizations: [] - ) + case Enum.find(socket.assigns.projects, &(&1.slug == slug)) do + nil -> + socket + |> put_flash(:error, "Project not found") + + project -> + stored_organizations = project.github_organizations |> Enum.map(& &1.organization) + + socket + |> assign( + selected_project: project, + stored_organizations: stored_organizations, + seen_organizations: stored_organizations, + new_organizations: [], + removed_organizations: [] + ) + end end {:noreply, socket}