~singpolyma/sgx-jmp

ref: d799a928330b0a8709084e8ea6a431979949a37e sgx-jmp/lib/command_list.rb -rw-r--r-- 1.5 KiB
d799a928Stephen Paul Weber Ask electrum to notify on new BTC addresses 1 year, 3 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# frozen_string_literal: true

class CommandList
	include Enumerable

	def self.for(customer)
		EMPromise.resolve(customer&.registered?).catch { nil }.then do |reg|
			next Registered.for(customer, reg.phone) if reg
			CommandList.new
		end
	end

	def each
		yield node: "jabber:iq:register", name: "Register"
	end

	class Registered < CommandList
		def self.for(customer, tel)
			EMPromise.all([
				REDIS.get("catapult_fwd-#{tel}"),
				customer.plan_name ? customer.payment_methods : []
			]).then do |(fwd, payment_methods)|
				Registered.new(*[
					(HAS_CREDIT_CARD unless payment_methods.empty?),
					(HAS_CURRENCY if customer.currency),
					(HAS_FORWARDING if fwd)
				].compact)
			end
		end

		def initialize(*args)
			@extra = args
		end

		ALWAYS = [
			{ node: "number-display", name: "Display JMP Number" },
			{ node: "configure-calls", name: "Configure Calls" },
			{ node: "usage", name: "Show Monthly Usage" },
			{ node: "reset sip account", name: "Create or Reset SIP Account" },
			{
				node: "credit cards",
				name: "Credit Card Settings and Management"
			}
		].freeze

		def each
			super
			([ALWAYS] + @extra).each do |commands|
				commands.each { |x| yield x }
			end
		end
	end

	HAS_CURRENCY = [
		node: "alt top up",
		name: "Buy Account Credit by Bitcoin, Mail, or Interac eTransfer"
	].freeze

	HAS_FORWARDING = [
		node: "record-voicemail-greeting",
		name: "Record Voicemail Greeting"
	].freeze

	HAS_CREDIT_CARD = [
		node: "top up", name: "Buy Account Credit by Credit Card"
	].freeze
end