diff --git a/.rubocop.yml b/.rubocop.yml index f201ef3fd6f3b5dca69b945c28d3e73dd1ad8142..53c881fd4adcc41b9775b5162ea5cccb4b7cc117 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 0000000000000000000000000000000000000000..20e6705862b7e9fd486f7aa5738771e39643798b --- /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 0000000000000000000000000000000000000000..a5c72affdfdf4d18e297b8ee1ccb1fb1c76c9a70 --- /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 8b64c13470885ef4642410c0118935ca7a1ebeb1..83d282378331a037b625a96613ef5ee8eb275f1c 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 eba4a4ae4cc00512df4a7ea75762a749d66e278f..22564fd120aa4bd7bafa95df02aaeaa2e8514389 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] )