mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 03:54:08 +00:00
Implement a setting to retrieve high res logos (#725)
* Implement a setting to retrieve high res logos * Update _brand_fetch_settings.html.erb * Add fallback for stock tickers also to use Brandfetch * Update security.rb * Update toggle logic for high-res logos setting Signed-off-by: Juan José Mata <jjmata@jjmata.com> * Update security.rb * Update security.rb --------- Signed-off-by: Juan José Mata <jjmata@jjmata.com> Co-authored-by: Juan José Mata <jjmata@jjmata.com>
This commit is contained in:
@@ -7,6 +7,7 @@ class Security < ApplicationRecord
|
||||
EXCHANGES = YAML.safe_load_file(Rails.root.join("config", "exchanges.yml")).freeze
|
||||
|
||||
before_validation :upcase_symbols
|
||||
before_save :generate_logo_url_from_brandfetch, if: :should_generate_logo?
|
||||
|
||||
has_many :trades, dependent: :nullify, class_name: "Trade"
|
||||
has_many :prices, dependent: :destroy
|
||||
@@ -42,13 +43,18 @@ class Security < ApplicationRecord
|
||||
)
|
||||
end
|
||||
|
||||
def brandfetch_icon_url(width: 40, height: 40)
|
||||
return nil unless Setting.brand_fetch_client_id.present? && website_url.present?
|
||||
def brandfetch_icon_url(width: nil, height: nil)
|
||||
return nil unless Setting.brand_fetch_client_id.present?
|
||||
|
||||
domain = extract_domain(website_url)
|
||||
return nil unless domain.present?
|
||||
w = width || Setting.brand_fetch_logo_size
|
||||
h = height || Setting.brand_fetch_logo_size
|
||||
|
||||
"https://cdn.brandfetch.io/#{domain}/icon/fallback/lettermark/w/#{width}/h/#{height}?c=#{Setting.brand_fetch_client_id}"
|
||||
identifier = extract_domain(website_url) if website_url.present?
|
||||
identifier ||= ticker
|
||||
|
||||
return nil unless identifier.present?
|
||||
|
||||
"https://cdn.brandfetch.io/#{identifier}/icon/fallback/lettermark/w/#{w}/h/#{h}?c=#{Setting.brand_fetch_client_id}"
|
||||
end
|
||||
|
||||
private
|
||||
@@ -65,4 +71,18 @@ class Security < ApplicationRecord
|
||||
self.ticker = ticker.upcase
|
||||
self.exchange_operating_mic = exchange_operating_mic.upcase if exchange_operating_mic.present?
|
||||
end
|
||||
|
||||
def should_generate_logo?
|
||||
url = brandfetch_icon_url
|
||||
return false unless url.present?
|
||||
|
||||
return true if logo_url.blank?
|
||||
return false unless logo_url.include?("cdn.brandfetch.io")
|
||||
|
||||
website_url_changed? || ticker_changed?
|
||||
end
|
||||
|
||||
def generate_logo_url_from_brandfetch
|
||||
self.logo_url = brandfetch_icon_url
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user