Class: Solrengine::Ui::ExplorerLinkComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/solrengine/ui/explorer_link_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value:, type: :address, network: "mainnet-beta", truncate: true) ⇒ ExplorerLinkComponent

Returns a new instance of ExplorerLinkComponent.



8
9
10
11
12
13
# File 'app/components/solrengine/ui/explorer_link_component.rb', line 8

def initialize(value:, type: :address, network: "mainnet-beta", truncate: true)
  @value = value
  @type = type
  @network = network
  @truncate = truncate
end

Instance Attribute Details

#networkObject (readonly)

Returns the value of attribute network.



6
7
8
# File 'app/components/solrengine/ui/explorer_link_component.rb', line 6

def network
  @network
end

#truncateObject (readonly)

Returns the value of attribute truncate.



6
7
8
# File 'app/components/solrengine/ui/explorer_link_component.rb', line 6

def truncate
  @truncate
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'app/components/solrengine/ui/explorer_link_component.rb', line 6

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



6
7
8
# File 'app/components/solrengine/ui/explorer_link_component.rb', line 6

def value
  @value
end

Instance Method Details

#display_textObject



15
16
17
18
19
20
21
# File 'app/components/solrengine/ui/explorer_link_component.rb', line 15

def display_text
  if truncate && value.length > 12
    "#{value[0..7]}...#{value[-4..]}"
  else
    value
  end
end

#explorer_urlObject



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/components/solrengine/ui/explorer_link_component.rb', line 23

def explorer_url
  if network == "mainnet-beta"
    case type
    when :address
      "https://solscan.io/account/#{value}"
    when :tx
      "https://solscan.io/tx/#{value}"
    end
  else
    path = type == :tx ? "tx" : "address"
    "https://explorer.solana.com/#{path}/#{value}?cluster=#{network}"
  end
end