Only ask which card to use if there is more than one

Stephen Paul Weber created

Change summary

sgx_jmp.rb | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

Detailed changes

sgx_jmp.rb 🔗

@@ -330,7 +330,7 @@ command :execute?, node: "buy-credit", sessionid: nil do |iq|
 				type: "fixed",
 				value: "Current balance: $#{balance.to_s('F')}"
 			},
-			{
+			({
 				var: "payment_method",
 				type: "list-single",
 				label: "Credit card to pay with",
@@ -342,7 +342,7 @@ command :execute?, node: "buy-credit", sessionid: nil do |iq|
 						label: "#{method.card_type} #{method.last_4}"
 					}
 				end
-			},
+			} if payment_methods.length > 1),
 			XEP0122Field.new(
 				"xs:decimal",
 				range: (0..1000),
@@ -350,7 +350,7 @@ command :execute?, node: "buy-credit", sessionid: nil do |iq|
 				label: "Amount of credit to buy",
 				required: true
 			).field
-		]
+		].compact
 
 		EMPromise.all([
 			payment_methods,
@@ -359,7 +359,7 @@ command :execute?, node: "buy-credit", sessionid: nil do |iq|
 	}.then { |(payment_methods, iq2)|
 		iq = iq2 # This allows the catch to use it also
 		payment_method = payment_methods.fetch(
-			iq.form.field("payment_method").value.to_i
+			iq.form.field("payment_method")&.value.to_i
 		)
 		BRAINTREE.transaction.sale(
 			amount: iq.form.field("amount").value.to_s,