Class: Solrengine::Ui::BalanceComponent

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

Constant Summary collapse

LAMPORTS_PER_SOL =
1_000_000_000
SIZE_CLASSES =
{
  sm: "text-sm",
  md: "text-xl",
  lg: "text-3xl"
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lamports: nil, sol: nil, show_symbol: true, size: :md) ⇒ BalanceComponent

Returns a new instance of BalanceComponent.



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

def initialize(lamports: nil, sol: nil, show_symbol: true, size: :md)
  @lamports = lamports
  @sol = sol
  @show_symbol = show_symbol
  @size = size
end

Instance Attribute Details

#show_symbolObject (readonly)

Returns the value of attribute show_symbol.



13
14
15
# File 'app/components/solrengine/ui/balance_component.rb', line 13

def show_symbol
  @show_symbol
end

#sizeObject (readonly)

Returns the value of attribute size.



13
14
15
# File 'app/components/solrengine/ui/balance_component.rb', line 13

def size
  @size
end

Instance Method Details

#formatted_amountObject



32
33
34
# File 'app/components/solrengine/ui/balance_component.rb', line 32

def formatted_amount
  format("%.9f", sol_amount).sub(/0+\z/, "").sub(/\.\z/, ".0")
end

#size_classObject



36
37
38
# File 'app/components/solrengine/ui/balance_component.rb', line 36

def size_class
  SIZE_CLASSES.fetch(size, SIZE_CLASSES[:md])
end

#sol_amountObject



22
23
24
25
26
27
28
29
30
# File 'app/components/solrengine/ui/balance_component.rb', line 22

def sol_amount
  if @lamports
    @lamports.to_f / LAMPORTS_PER_SOL
  elsif @sol
    @sol.to_f
  else
    0.0
  end
end