alt_top_up_form.rb

 1# frozen_string_literal: true
 2
 3class AltTopUpForm
 4	def self.for(customer)
 5		customer.btc_addresses.then do |addrs|
 6			AltTopUpForm.new(customer, addrs)
 7		end
 8	end
 9
10	def initialize(customer, btc_addresses)
11		@balance = customer.balance
12		@currency = customer.currency
13		@btc_addresses = btc_addresses
14	end
15
16	def form
17		FormTemplate.render(
18			"alt_top_up",
19			balance: @balance,
20			currency: @currency,
21			btc_addresses: @btc_addresses
22		)
23	end
24
25	def parse(form)
26		{
27			add_btc_address: ["1", "true"].include?(
28				form.field("add_btc_address")&.value.to_s
29			)
30		}
31	end
32end