The personal finance app for everyone (by everyone)
Ruby
fix(onchain): let Track selected assets submit on self-hosted installs (#3940)
Lyova Potyomkin6ef4859b93ce
diff --git a/app/views/onchain_wallet_items/_token_review_form.html.erb b/app/views/onchain_wallet_items/_token_review_form.html.erbindex 21a11fb22e..aa488c7ddb 100644--- a/app/views/onchain_wallet_items/_token_review_form.html.erb+++ b/app/views/onchain_wallet_items/_token_review_form.html.erb@@ -1,60 +1,64 @@<%# Shared by initial linking and the later "review tokens" action, which is the %><%# same screen with the address left alone. %><% turbo_frame = local_assigns.fetch(:turbo_frame, "_top") %>-<%= styled_form_with url: url,- method: :post,- data: { turbo_frame: turbo_frame },- class: "space-y-4" do |form| %>- <%= hidden_field_tag :chain, chain %>- <%= hidden_field_tag :address, address %>-+<div class="space-y-4">+ <%# Outside the form: its "enable crypto prices" button is a form of its own, %>+ <%# and a nested form closes this one early, leaving the submit button inert. %><%= render "onchain_wallet_items/price_provider_warning" %>- <%= render DS::Alert.new(variant: :info, message: t("onchain_wallet_items.token_review_form.explanation")) %>+ <%= styled_form_with url: url,+ method: :post,+ data: { turbo_frame: turbo_frame },+ class: "space-y-4" do |form| %>+ <%= hidden_field_tag :chain, chain %>+ <%= hidden_field_tag :address, address %>- <% if local_assigns[:assets_truncated] %>- <%= render DS::Alert.new(- variant: :warning,- message: t("onchain_wallet_items.token_review_form.assets_truncated", count: Onchain::AssetBudget.tokens)- ) %>- <% end %>+ <%= render DS::Alert.new(variant: :info, message: t("onchain_wallet_items.token_review_form.explanation")) %>++ <% if local_assigns[:assets_truncated] %>+ <%= render DS::Alert.new(+ variant: :warning,+ message: t("onchain_wallet_items.token_review_form.assets_truncated", count: Onchain::AssetBudget.tokens)+ ) %>+ <% end %>- <% if review.rows.empty? %>- <p class="text-sm text-secondary py-4"><%= t("onchain_wallet_items.token_review_form.nothing_found") %></p>- <% else %>- <div class="space-y-2 max-h-96 overflow-y-auto">- <% review.rows.each do |row| %>- <label for="asset_<%= row.key.parameterize %>"- class="flex items-center gap-3 p-3 border border-primary rounded-lg hover:bg-surface cursor-pointer">- <%= check_box_tag "assets[]", row.key, row.preselected?,- id: "asset_#{row.key.parameterize}",- class: "checkbox checkbox--dark" %>- <div class="flex-1 min-w-0">- <p class="font-medium text-primary truncate">- <%= row.asset.symbol %>- <% if row.native? %>- <span class="text-xs text-secondary"><%= t("onchain_wallet_items.token_review_form.native") %></span>+ <% if review.rows.empty? %>+ <p class="text-sm text-secondary py-4"><%= t("onchain_wallet_items.token_review_form.nothing_found") %></p>+ <% else %>+ <div class="space-y-2 max-h-96 overflow-y-auto">+ <% review.rows.each do |row| %>+ <label for="asset_<%= row.key.parameterize %>"+ class="flex items-center gap-3 p-3 border border-primary rounded-lg hover:bg-surface cursor-pointer">+ <%= check_box_tag "assets[]", row.key, row.preselected?,+ id: "asset_#{row.key.parameterize}",+ class: "checkbox checkbox--dark" %>+ <div class="flex-1 min-w-0">+ <p class="font-medium text-primary truncate">+ <%= row.asset.symbol %>+ <% if row.native? %>+ <span class="text-xs text-secondary"><%= t("onchain_wallet_items.token_review_form.native") %></span>+ <% end %>+ </p>+ <p class="text-xs text-secondary truncate"><%= row.asset.name %></p>+ <% unless row.priceable %>+ <p class="text-xs text-warning"><%= t("onchain_wallet_items.token_review_form.no_price") %></p><% end %>+ </div>+ <p class="text-sm font-medium text-primary shrink-0 tabular-nums">+ <%= number_with_delimiter(row.asset.quantity.round(8).to_s("F")) %></p>- <p class="text-xs text-secondary truncate"><%= row.asset.name %></p>- <% unless row.priceable %>- <p class="text-xs text-warning"><%= t("onchain_wallet_items.token_review_form.no_price") %></p>- <% end %>- </div>- <p class="text-sm font-medium text-primary shrink-0 tabular-nums">- <%= number_with_delimiter(row.asset.quantity.round(8).to_s("F")) %>- </p>- </label>- <% end %>+ </label>+ <% end %>+ </div>+ <% end %>++ <div class="flex justify-end gap-2">+ <%= render DS::Link.new(+ text: t("onchain_wallet_items.token_review_form.cancel"),+ variant: "secondary",+ href: local_assigns.fetch(:cancel_path, settings_providers_path)+ ) %>+ <%= form.submit submit_label %></div><% end %>-- <div class="flex justify-end gap-2">- <%= render DS::Link.new(- text: t("onchain_wallet_items.token_review_form.cancel"),- variant: "secondary",- href: local_assigns.fetch(:cancel_path, settings_providers_path)- ) %>- <%= form.submit submit_label %>- </div>-<% end %>+</div>diff --git a/test/controllers/onchain_wallet_items_controller_test.rb b/test/controllers/onchain_wallet_items_controller_test.rbindex 5bca4508ca..2730abb0dd 100644--- a/test/controllers/onchain_wallet_items_controller_test.rb+++ b/test/controllers/onchain_wallet_items_controller_test.rb@@ -86,6 +86,26 @@ class OnchainWalletItemsControllerTest < ActionDispatch::IntegrationTestassert_select "form[action=?]", enable_crypto_prices_onchain_wallet_items_pathend+ # The one-click fix is a form of its own. Rendered inside the token review+ # form, it closed that form early and left "Track selected assets" submitting+ # nothing at all.+ test "the one-click fix does not swallow the token review form" do+ Rails.configuration.stubs(:app_mode).returns(ActiveSupport::StringInquirer.new("self_hosted"))+ stub_wallet_with_token++ post preview_wallet_onchain_wallet_items_url, params: {+ address: OnchainTestHelper::FAKE_ADDRESS,+ chain: OnchainTestHelper::FAKE_CHAIN+ }++ assert_response :success+ assert_select "form[action=?]", enable_crypto_prices_onchain_wallet_items_path+ assert_select "form[action=?]", link_wallet_onchain_wallet_items_path do+ assert_select "input[name='assets[]']", 2+ assert_select "button[type=submit]", 1+ end+ end+test "enable_crypto_prices adds the crypto provider without disabling the others" doRails.configuration.stubs(:app_mode).returns(ActiveSupport::StringInquirer.new("self_hosted"))Setting.securities_providers = "twelve_data"diff --git a/test/system/onchain_wallets_test.rb b/test/system/onchain_wallets_test.rbindex b3f27b044e..f7da923748 100644--- a/test/system/onchain_wallets_test.rb+++ b/test/system/onchain_wallets_test.rb@@ -41,47 +41,21 @@ class OnchainWalletsTest < ApplicationSystemTestCaseendtest "linking a wallet from the settings panel creates an account per ticked asset" do- visit settings_providers_path- open_onchain_panel-- # The provider panel opens in the drawer frame.- assert_text I18n.t("onchain_wallet_items.price_provider_warning.title")-- # The read-only reassurance is no longer a permanent banner here...- assert_no_text I18n.t("settings.providers.onchain_wallet_panel.keyless_title")-- click_on I18n.t("settings.providers.onchain_wallet_panel.add_wallet")-- # ...it lives where the address is pasted. Scoped to the modal, because a- # page-wide assertion would pass from any frame and prove nothing about- # where the banner actually went.- within "turbo-frame#modal" do- assert_text I18n.t("settings.providers.onchain_wallet_panel.keyless_title")- end-- # The linking modal opens on top of the drawer.- assert_text I18n.t("onchain_wallet_items.new_wallet.title")- assert_text I18n.t("onchain_wallet_items.new_wallet.bitcoin_single_address_note")-- fill_in I18n.t("onchain_wallet_items.new_wallet.address_label"), with: OnchainTestHelper::FAKE_ADDRESS- click_on I18n.t("onchain_wallet_items.new_wallet.continue")-- # Token review, in the same modal frame.- assert_text I18n.t("onchain_wallet_items.token_review.title")- assert_text "USDC"- assert_text I18n.t("onchain_wallet_items.token_review_form.no_price")-- # Priceable assets arrive ticked, the unpriceable one does not.- assert find("input[value='native']").checked?- assert find("input[value='erc20:0xusdc']").checked?- assert_not find("input[value='erc20:0xspam']").checked?+ link_wallet_from_settings_panel+ end- assert_difference -> { Account.count }, 2 do- click_on I18n.t("onchain_wallet_items.token_review.import_selected")- assert_text I18n.t("onchain_wallet_items.link_wallet.success", count: 2)+ # Self-hosted admins get a one-click "enable crypto prices" button on the+ # token screen. It is a form of its own, and while it sat inside the token+ # form the browser closed that form early: the checkboxes and "Track selected+ # assets" ended up outside it, and clicking the button did nothing at all.+ test "linking works on a self-hosted instance that offers the one-click price fix" do+ Rails.configuration.stubs(:app_mode).returns("self_hosted".inquiry)++ link_wallet_from_settings_panel do+ within "turbo-frame#modal" do+ assert_button I18n.t("onchain_wallet_items.price_provider_warning.enable")+ endend-- assert_equal %w[FAKE USDC], OnchainWalletAccount.order(:symbol).pluck(:symbol)endtest "managing a wallet reviews its tokens and disconnects one asset" do@@ -116,4 +90,53 @@ class OnchainWalletsTest < ApplicationSystemTestCaseassert Account.exists?(native_account.id)assert_not AccountProvider.exists?(provider_type: "OnchainWalletAccount", provider_id: token_asset.id)end++ private+ # The whole linking flow, from the providers page to the accounts it creates.+ # Yields on the token review screen, before anything is submitted.+ def link_wallet_from_settings_panel+ visit settings_providers_path+ open_onchain_panel++ # The provider panel opens in the drawer frame.+ assert_text I18n.t("onchain_wallet_items.price_provider_warning.title")++ # The read-only reassurance is no longer a permanent banner here...+ assert_no_text I18n.t("settings.providers.onchain_wallet_panel.keyless_title")++ click_on I18n.t("settings.providers.onchain_wallet_panel.add_wallet")++ # ...it lives where the address is pasted. Scoped to the modal, because a+ # page-wide assertion would pass from any frame and prove nothing about+ # where the banner actually went.+ within "turbo-frame#modal" do+ assert_text I18n.t("settings.providers.onchain_wallet_panel.keyless_title")+ end++ # The linking modal opens on top of the drawer.+ assert_text I18n.t("onchain_wallet_items.new_wallet.title")+ assert_text I18n.t("onchain_wallet_items.new_wallet.bitcoin_single_address_note")++ fill_in I18n.t("onchain_wallet_items.new_wallet.address_label"), with: OnchainTestHelper::FAKE_ADDRESS+ click_on I18n.t("onchain_wallet_items.new_wallet.continue")++ # Token review, in the same modal frame.+ assert_text I18n.t("onchain_wallet_items.token_review.title")+ assert_text "USDC"+ assert_text I18n.t("onchain_wallet_items.token_review_form.no_price")++ # Priceable assets arrive ticked, the unpriceable one does not.+ assert find("input[value='native']").checked?+ assert find("input[value='erc20:0xusdc']").checked?+ assert_not find("input[value='erc20:0xspam']").checked?++ yield if block_given?++ assert_difference -> { Account.count }, 2 do+ click_on I18n.t("onchain_wallet_items.token_review.import_selected")+ assert_text I18n.t("onchain_wallet_items.link_wallet.success", count: 2)+ end++ assert_equal %w[FAKE USDC], OnchainWalletAccount.order(:symbol).pluck(:symbol)+ endend