mirror of
https://github.com/we-promise/sure.git
synced 2026-04-17 11:04:14 +00:00
Improve convert-to-trade security selection with search-first UX (#703)
* Enhance security handling logic: - Prioritize user's country in sorting securities and country codes. - Add comprehensive mapping for MIC codes to user-friendly exchange names. - Revamp combobox to consistently pull from a provider when available. - Improve handling of custom ticker and exchange input fields. * Localize securities combobox display and exchange labels. --------- Co-authored-by: luckyPipewrench <luckypipewrench@proton.me>
This commit is contained in:
@@ -7,7 +7,16 @@ class Security::ComboboxOption
|
||||
"#{symbol}|#{exchange_operating_mic}"
|
||||
end
|
||||
|
||||
def exchange_name
|
||||
Security.exchange_name_for(exchange_operating_mic)
|
||||
end
|
||||
|
||||
def to_combobox_display
|
||||
"#{symbol} - #{name} (#{exchange_operating_mic})"
|
||||
I18n.t(
|
||||
"securities.combobox.display",
|
||||
symbol: symbol,
|
||||
name: name,
|
||||
exchange: exchange_name
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -21,7 +21,7 @@ module Security::Provided
|
||||
response = provider.search_securities(symbol, **params)
|
||||
|
||||
if response.success?
|
||||
response.data.map do |provider_security|
|
||||
securities = response.data.map do |provider_security|
|
||||
# Need to map to domain model so Combobox can display via to_combobox_option
|
||||
Security.new(
|
||||
ticker: provider_security.symbol,
|
||||
@@ -31,6 +31,19 @@ module Security::Provided
|
||||
country_code: provider_security.country_code
|
||||
)
|
||||
end
|
||||
|
||||
# Sort results to prioritize user's country if provided
|
||||
if country_code.present?
|
||||
user_country = country_code.upcase
|
||||
securities.sort_by do |s|
|
||||
[
|
||||
s.country_code&.upcase == user_country ? 0 : 1, # User's country first
|
||||
s.ticker.upcase == symbol.upcase ? 0 : 1 # Exact ticker match second
|
||||
]
|
||||
end
|
||||
else
|
||||
securities
|
||||
end
|
||||
else
|
||||
[]
|
||||
end
|
||||
|
||||
@@ -124,9 +124,17 @@ class Security::Resolver
|
||||
end
|
||||
|
||||
# Non-exhaustive list of common country codes for help in choosing "close" matches
|
||||
# These are generally sorted by market cap.
|
||||
# User's country (if provided) is prioritized first, then sorted by market cap.
|
||||
def sorted_country_codes_by_relevance
|
||||
%w[US CN JP IN GB CA FR DE CH SA TW AU NL SE KR IE ES AE IT HK BR DK SG MX RU IL ID BE TH NO]
|
||||
base_order = %w[US CN JP IN GB CA FR DE CH SA TW AU NL SE KR IE ES AE IT HK BR DK SG MX RU IL ID BE TH NO]
|
||||
|
||||
# Prioritize user's country if provided
|
||||
if country_code.present?
|
||||
user_country = country_code.upcase
|
||||
[ user_country ] + (base_order - [ user_country ])
|
||||
else
|
||||
base_order
|
||||
end
|
||||
end
|
||||
|
||||
# Non-exhaustive list of common exchange operating MICs for help in choosing "close" matches
|
||||
|
||||
Reference in New Issue
Block a user