~singpolyma/sgx-jmp

ref: 94298f5def79ee9a115022ae30d35aa9666f338c sgx-jmp/lib/alt_top_up_form.rb -rw-r--r-- 574 bytes
94298f5dStephen Paul Weber Refactor alt top up to use FormTemplate 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# frozen_string_literal: true

class AltTopUpForm
	def self.for(customer)
		customer.btc_addresses.then do |addrs|
			AltTopUpForm.new(customer, addrs)
		end
	end

	def initialize(customer, btc_addresses)
		@balance = customer.balance
		@currency = customer.currency
		@btc_addresses = btc_addresses
	end

	def form
		FormTemplate.render(
			"alt_top_up",
			balance: @balance,
			currency: @currency,
			btc_addresses: @btc_addresses
		)
	end

	def parse(form)
		{
			add_btc_address: ["1", "true"].include?(
				form.field("add_btc_address")&.value.to_s
			)
		}
	end
end