Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

CoinSpot: leave the Add Account modal at the top level when setup can't open (#4276)

alexcastgonzb0b954ebdf38
diff --git a/app/controllers/coinspot_items_controller.rb b/app/controllers/coinspot_items_controller.rb
index 6b9e35a05c..f64778d744 100644
--- a/app/controllers/coinspot_items_controller.rb
+++ b/app/controllers/coinspot_items_controller.rb
@@ -69,7 +69,12 @@ class CoinspotItemsController < ApplicationController
coinspot_item = account_flow[:coinspot_item]
unless coinspot_item
- redirect_to settings_providers_path, alert: coinspot_item_selection_message(account_flow[:credentialed_items])
+ message = coinspot_item_selection_message(account_flow[:credentialed_items])
+ if turbo_frame_request?
+ render_frame_redirect(settings_providers_path, alert: message)
+ else
+ redirect_to settings_providers_path, alert: message
+ end
return
end
@@ -329,4 +334,16 @@ class CoinspotItemsController < ApplicationController
encoded_second_character = return_to[1, 3]
%w[%2F %5C].include?(encoded_second_character)
end
+
+ # Add Account opens select_accounts inside the "modal" turbo frame, and a
+ # plain redirect would be followed within it, losing the page and its
+ # alert. Answer with the frame carrying a redirect stream action instead,
+ # which performs a full-page visit (as PlaidItemsController does).
+ def render_frame_redirect(path, alert:)
+ flash[:alert] = alert
+
+ render html: helpers.turbo_frame_tag(turbo_frame_request_id) {
+ helpers.turbo_stream.action(:redirect, path)
+ }
+ end
end
diff --git a/test/controllers/coinspot_items_controller_test.rb b/test/controllers/coinspot_items_controller_test.rb
index 606d11ce0a..9a41976755 100644
--- a/test/controllers/coinspot_items_controller_test.rb
+++ b/test/controllers/coinspot_items_controller_test.rb
@@ -130,6 +130,15 @@ class CoinspotItemsControllerTest < ActionDispatch::IntegrationTest
assert_equal "Choose a CoinSpot connection in Provider Settings.", flash[:alert]
end
+ test "select accounts leaves the Add Account modal for Settings at the top level" do
+ get select_accounts_coinspot_items_url, params: { accountable_type: "Crypto" }, headers: { "Turbo-Frame" => "modal" }
+
+ # A redirect would be followed inside the frame and the flash lost.
+ assert_response :success
+ assert_select "turbo-frame#modal turbo-stream[action=redirect][target=?]", settings_providers_path
+ assert_equal I18n.t("coinspot_items.select_accounts.select_connection"), flash[:alert]
+ end
+
test "select accounts targets selected coinspot item" do
get select_accounts_coinspot_items_url, params: {
coinspot_item_id: @second_item.id,