~singpolyma/sgx-jmp

039a86fe066840a6b1757b1c690224b872298e05 — Stephen Paul Weber 1 year, 30 days ago 977e286
Allow prev from Bitcoin registration
2 files changed, 25 insertions(+), 17 deletions(-)

M lib/registration.rb
M test/test_registration.rb
M lib/registration.rb => lib/registration.rb +22 -14
@@ 185,7 185,8 @@ class Registration
				REDIS.setex("pending_tel_for-#{@customer.jid}", THIRTY_DAYS, tel)
			end

			def note_text(amount, addr)
			def note_text(rate, addr)
				amount = CONFIG[:activation_amount] / rate
				<<~NOTE
					Activate your account by sending at least #{'%.6f' % amount} BTC to
					#{addr}


@@ 195,24 196,31 @@ class Registration
			end

			def write
				EMPromise.all([
					addr,
					save,
					BTC_SELL_PRICES.public_send(@customer.currency.to_s.downcase)
				]).then do |(addr, _, rate)|
					min = CONFIG[:activation_amount] / rate
					Command.finish(
						note_text(min, addr) + @final_message.to_s, status: :canceled
					)
				EMPromise.all([addr_and_rate, save]).then do |((addr, rate), _)|
					Command.reply { |reply|
						reply.allowed_actions = [:prev]
						reply.status = :canceled
						reply.note_type = :info
						reply.note_text = note_text(rate, addr) + @final_message.to_s
					}.then(&method(:handle_possible_prev))
				end
			end

		protected

			def addr
				@addr ||= @customer.btc_addresses.then { |addrs|
					addrs.first || @customer.add_btc_address
				}
			def handle_possible_prev(iq)
				raise "Action not allowed" unless iq.prev?

				Activation.for(@customer, @tel).then(&:write)
			end

			def addr_and_rate
				EMPromise.all([
					@customer.btc_addresses.then { |addrs|
						addrs.first || @customer.add_btc_address
					},
					BTC_SELL_PRICES.public_send(@customer.currency.to_s.downcase)
				])
			end
		end


M test/test_registration.rb => test/test_registration.rb +3 -3
@@ 337,9 337,9 @@ class RegistrationTest < Minitest::Test
					You will receive a notification when your payment is complete.
				NOTE
				blather = Minitest::Mock.new
				blather.expect(
					:<<,
					nil,
				Command::COMMAND_MANAGER.expect(
					:write,
					EMPromise.reject(SessionManager::Timeout.new),
					[Matching.new do |reply|
						assert_equal :canceled, reply.status
						assert_equal :info, reply.note_type