From 75658ba14b40d551488dae800e9a7d2bfeb239a8 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Fri, 19 Nov 2021 21:35:46 -0500 Subject: [PATCH] Use FormTemplate for activation form --- .rubocop.yml | 2 +- forms/registration/activate.rb | 36 ++++++++++++++ forms/registration/plan_name.rb | 16 ++++++ lib/registration.rb | 86 ++++++--------------------------- test/test_registration.rb | 4 +- 5 files changed, 69 insertions(+), 75 deletions(-) create mode 100644 forms/registration/activate.rb create mode 100644 forms/registration/plan_name.rb diff --git a/.rubocop.yml b/.rubocop.yml index f201ef3..53c881f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -122,7 +122,7 @@ Style/FormatStringToken: Style/FrozenStringLiteralComment: Exclude: - - forms/* + - forms/**/*.rb Naming/AccessorMethodName: Enabled: false diff --git a/forms/registration/activate.rb b/forms/registration/activate.rb new file mode 100644 index 0000000..20e6705 --- /dev/null +++ b/forms/registration/activate.rb @@ -0,0 +1,36 @@ +form! +title "Activate JMP" + +center = " (#{@rate_center})" if @rate_center +instructions <<~I + You've selected #{@tel}#{center} as your JMP number. + To activate your account, you can either deposit $#{CONFIG[:activation_amount]} to your balance or enter your invite code if you have one. + (If you'd like to pay in a cryptocurrency other than Bitcoin, currently we recommend using a service like simpleswap.io, morphtoken.com, changenow.io, or godex.io. Manual payment via Bitcoin Cash is also available if you contact support.) +I + +field( + var: "activation_method", + type: "list-single", + label: "Activate using", + required: true, + options: [ + { + value: "credit_card", + label: "Credit Card" + }, + { + value: "bitcoin", + label: "Bitcoin" + }, + { + value: "code", + label: "Invite Code" + }, + { + value: "mail", + label: "Mail or eTransfer" + } + ] +) + +instance_eval File.read("#{__dir__}/plan_name.rb") diff --git a/forms/registration/plan_name.rb b/forms/registration/plan_name.rb new file mode 100644 index 0000000..a5c72af --- /dev/null +++ b/forms/registration/plan_name.rb @@ -0,0 +1,16 @@ +field( + var: "plan_name", + type: "list-single", + label: "What currency should your account balance be in?", + required: true, + options: [ + { + value: "cad_beta_unlimited-v20210223", + label: "Canadian Dollars" + }, + { + value: "usd_beta_unlimited-v20210223", + label: "United States Dollars" + } + ] +) diff --git a/lib/registration.rb b/lib/registration.rb index 8b64c13..83d2823 100644 --- a/lib/registration.rb +++ b/lib/registration.rb @@ -48,85 +48,27 @@ class Registration attr_reader :customer, :tel - FORM_FIELDS = [ - { - var: "activation_method", - type: "list-single", - label: "Activate using", - required: true, - options: [ - { - value: "credit_card", - label: "Credit Card" - }, - { - value: "bitcoin", - label: "Bitcoin" - }, - { - value: "code", - label: "Invite Code" - }, - { - value: "mail", - label: "Mail or eTransfer" - } - ] - }, - { - var: "plan_name", - type: "list-single", - label: "What currency should your account balance be in?", - required: true, - options: [ - { - value: "cad_beta_unlimited-v20210223", - label: "Canadian Dollars" - }, - { - value: "usd_beta_unlimited-v20210223", - label: "United States Dollars" - } - ] - } - ].freeze - - ACTIVATE_INSTRUCTION = - "To activate your account, you can either deposit " \ - "$#{CONFIG[:activation_amount]} to your balance or enter " \ - "your invite code if you have one." - - CRYPTOCURRENCY_INSTRUCTION = - "(If you'd like to pay in a cryptocurrency other than " \ - "Bitcoin, currently we recommend using a service like " \ - "simpleswap.io, morphtoken.com, changenow.io, or godex.io. " \ - "Manual payment via Bitcoin Cash is also available if you " \ - "contact support.)" - - def add_instructions(form, center) - center = " (#{center})" if center - [ - "You've selected #{tel}#{center} as your JMP number", - ACTIVATE_INSTRUCTION, - CRYPTOCURRENCY_INSTRUCTION - ].each do |txt| - form << Blather::XMPPNode.new(:instructions, form.document).tap { |i| - i << txt - } - end + def form(center) + FormTemplate.render( + "registration/activate", + tel: tel, + rate_center: center + ) end def write rate_center.then { |center| Command.reply do |reply| reply.allowed_actions = [:next] - form = reply.form - form.type = :form - form.title = "Activate JMP" - add_instructions(form, center) - form.fields = FORM_FIELDS + reply.command << form(center) end - }.then { |iq| Payment.for(iq, customer, tel) }.then(&:write) + }.then(&method(:next_step)) + end + + def next_step(iq) + EMPromise.resolve(nil).then { + Payment.for(iq, customer, tel) + }.then(&:write) end protected diff --git a/test/test_registration.rb b/test/test_registration.rb index eba4a4a..22564fd 100644 --- a/test/test_registration.rb +++ b/test/test_registration.rb @@ -100,8 +100,8 @@ class RegistrationTest < Minitest::Test [Matching.new do |iq| assert_equal :form, iq.form.type assert_equal( - "You've selected +15555550000 (FA, KE) as your JMP number", - iq.form.instructions + "You've selected +15555550000 (FA, KE) as your JMP number.", + iq.form.instructions.lines.first.chomp ) end] ) -- 2.34.2