add_bitcoin_address.rb

 1# frozen_string_literal: true
 2
 3class AddBitcoinAddress
 4	def self.for(iq, alt_form, customer)
 5		if alt_form.parse(iq.form)[:add_btc_address]
 6			new(iq, customer)
 7		else
 8			DoNot.new(iq)
 9		end
10	end
11
12	def initialize(iq, customer)
13		@reply = iq.reply
14		@reply.status = :completed
15		@customer = customer
16	end
17
18	def write
19		@customer.add_btc_address.then do |addr|
20			form.fields = [{
21				var: "btc_address",
22				type: "fixed",
23				label: "Bitcoin Address",
24				value: addr
25			}]
26			BLATHER << @reply
27		end
28	end
29
30protected
31
32	def form
33		form = @reply.form
34		form.type = :result
35		form.title = "New Bitcoin Address"
36		form.instructions = "Your new address has been created"
37		form
38	end
39
40	class DoNot
41		def initialize(iq)
42			@reply = iq.reply
43			@reply.status = :completed
44		end
45
46		def write
47			BLATHER << @reply
48		end
49	end
50end