~singpolyma/sgx-jmp

ref: 23018db151ab4e6683c38ff1aeb0f588720e4d68 sgx-jmp/lib/add_bitcoin_address.rb -rw-r--r-- 819 bytes
23018db1Stephen Paul Weber Switch to rubocop 0.89.1 1 year, 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
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