~singpolyma/sgx-jmp

ref: f571b5e726750cf8c4523c22d77e110194c3e16a sgx-jmp/lib/add_bitcoin_address.rb -rw-r--r-- 819 bytes
f571b5e7Stephen Paul Weber Postgres#query_one 7 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# frozen_string_literal: true

class AddBitcoinAddress
	def self.for(iq, alt_form, customer)
		if alt_form.parse(iq.form)[:add_btc_address]
			new(iq, customer)
		else
			DoNot.new(iq)
		end
	end

	def initialize(iq, customer)
		@reply = iq.reply
		@reply.status = :completed
		@customer = customer
	end

	def write
		@customer.add_btc_address.then do |addr|
			form.fields = [{
				var: "btc_address",
				type: "fixed",
				label: "Bitcoin Address",
				value: addr
			}]
			BLATHER << @reply
		end
	end

protected

	def form
		form = @reply.form
		form.type = :result
		form.title = "New Bitcoin Address"
		form.instructions = "Your new address has been created"
		form
	end

	class DoNot
		def initialize(iq)
			@reply = iq.reply
			@reply.status = :completed
		end

		def write
			BLATHER << @reply
		end
	end
end