Fixed incorrect parameters provided to Command#yield-control
Signed-off-by: Julien Eluard <julien.eluard@gmail.com> Signed-off-by: Pedro Pombeiro <pombeirp@users.noreply.github.com>
This commit is contained in:
parent
cee18d23b8
commit
a825175aea
|
@ -6,6 +6,7 @@
|
||||||
[status-im.chat.constants :as chat.constants]
|
[status-im.chat.constants :as chat.constants]
|
||||||
[status-im.chat.commands.protocol :as protocol]
|
[status-im.chat.commands.protocol :as protocol]
|
||||||
[status-im.chat.commands.impl.transactions :as transactions]
|
[status-im.chat.commands.impl.transactions :as transactions]
|
||||||
|
[status-im.contact.db :as db]
|
||||||
[status-im.utils.handlers :as handlers]
|
[status-im.utils.handlers :as handlers]
|
||||||
[status-im.utils.fx :as fx]))
|
[status-im.utils.fx :as fx]))
|
||||||
|
|
||||||
|
@ -34,13 +35,16 @@
|
||||||
[type]
|
[type]
|
||||||
(keyword (str (protocol/id type) "-button")))
|
(keyword (str (protocol/id type) "-button")))
|
||||||
|
|
||||||
|
(defn- contact->address [contact]
|
||||||
|
(str "0x" (db/public-key->address contact)))
|
||||||
|
|
||||||
(defn add-chat-contacts
|
(defn add-chat-contacts
|
||||||
"Enrich command-message by adding contact list of the current private or group chat"
|
"Enrich command-message by adding contact list of the current private or group chat"
|
||||||
[contacts {:keys [public? group-chat] :as command-message}]
|
[contacts {:keys [public? group-chat] :as command-message}]
|
||||||
(cond
|
(cond
|
||||||
public? command-message
|
public? command-message
|
||||||
group-chat (assoc command-message :contacts (map status-im.contact.db/public-key->address contacts))
|
group-chat (assoc command-message :contacts (map contact->address contacts))
|
||||||
:else (assoc command-message :contact (status-im.contact.db/public-key->address (first contacts)))))
|
:else (assoc command-message :contact (contact->address (first contacts)))))
|
||||||
|
|
||||||
(defn enrich-command-message-for-events
|
(defn enrich-command-message-for-events
|
||||||
"adds new pairs to command-message to be consumed by extension events"
|
"adds new pairs to command-message to be consumed by extension events"
|
||||||
|
|
|
@ -294,7 +294,7 @@
|
||||||
(preview [_ command-message]
|
(preview [_ command-message]
|
||||||
(send-preview command-message))
|
(send-preview command-message))
|
||||||
protocol/Yielding
|
protocol/Yielding
|
||||||
(yield-control [_ {:keys [amount asset]} {:keys [db] :as cofx}]
|
(yield-control [_ {{{amount :amount asset :asset} :params} :content} {:keys [db] :as cofx}]
|
||||||
;; Prefill wallet and navigate there
|
;; Prefill wallet and navigate there
|
||||||
(let [recipient-contact (get-in db [:contacts/contacts (:current-chat-id db)])
|
(let [recipient-contact (get-in db [:contacts/contacts (:current-chat-id db)])
|
||||||
sender-account (:account/account db)
|
sender-account (:account/account db)
|
||||||
|
|
|
@ -31,13 +31,13 @@
|
||||||
;; errors during validation
|
;; errors during validation
|
||||||
{:db (chat/set-chat-ui-props db {:validation-messages validation-error})}
|
{:db (chat/set-chat-ui-props db {:validation-messages validation-error})}
|
||||||
;; no errors
|
;; no errors
|
||||||
|
(let [command-message (commands/enrich-command-message-for-events db (create-command-message chat-id type parameter-map cofx))]
|
||||||
(if (satisfies? protocol/Yielding type)
|
(if (satisfies? protocol/Yielding type)
|
||||||
;; yield control implemented, don't send the message
|
;; yield control implemented, don't send the message
|
||||||
(protocol/yield-control type parameter-map cofx)
|
(protocol/yield-control type command-message cofx)
|
||||||
;; no yield control, proceed with sending the command message
|
;; no yield control, proceed with sending the command message
|
||||||
(let [command-message (create-command-message chat-id type parameter-map cofx)]
|
|
||||||
(fx/merge cofx
|
(fx/merge cofx
|
||||||
#(protocol/on-send type (commands/enrich-command-message-for-events db command-message) %)
|
#(protocol/on-send type command-message %)
|
||||||
(commands.input/set-command-reference nil)
|
(commands.input/set-command-reference nil)
|
||||||
(chat.message/send-message command-message)))))))
|
(chat.message/send-message command-message)))))))
|
||||||
|
|
||||||
|
|
|
@ -111,9 +111,9 @@
|
||||||
"0x04b790f2c3f4079f35a1fa396465ceb243cc446c9af211d0a1774f869eb9632a67a6e664e24075ec5c5a8a95a509a2a8173dbfeb88af372e784a37fecc1b5c0ba5"
|
"0x04b790f2c3f4079f35a1fa396465ceb243cc446c9af211d0a1774f869eb9632a67a6e664e24075ec5c5a8a95a509a2a8173dbfeb88af372e784a37fecc1b5c0ba5"
|
||||||
"0x04cc3cec3f88dc1a39e224388f0304023fc78c2a7d05e4ebd61638192cc592d2c13d8f081b5d9995dbfcbe45a4ca7eb80d5c505eee660e8fee0df2da222f047287"})
|
"0x04cc3cec3f88dc1a39e224388f0304023fc78c2a7d05e4ebd61638192cc592d2c13d8f081b5d9995dbfcbe45a4ca7eb80d5c505eee660e8fee0df2da222f047287"})
|
||||||
|
|
||||||
(def contacts_addresses '("5adf1b9e1fa4bd4889fecd598b45079045d98f0e"
|
(def contacts_addresses '("0x5adf1b9e1fa4bd4889fecd598b45079045d98f0e"
|
||||||
"21631d18d9681d4ffdd460fc45fa52159fcd95c8"
|
"0x21631d18d9681d4ffdd460fc45fa52159fcd95c8"
|
||||||
"5541e3be81b76d76cdbf968516caa5a5b773763b"))
|
"0x5541e3be81b76d76cdbf968516caa5a5b773763b"))
|
||||||
|
|
||||||
(deftest enrich-command-message-for-events-test-public
|
(deftest enrich-command-message-for-events-test-public
|
||||||
(let [db {:chats {"1" {:contacts nil :public? true :group-chat false}}}
|
(let [db {:chats {"1" {:contacts nil :public? true :group-chat false}}}
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
(is (= (protocol/validate personal-send-command {:asset "ETH" :amount "0.01"} cofx)
|
(is (= (protocol/validate personal-send-command {:asset "ETH" :amount "0.01"} cofx)
|
||||||
nil)))
|
nil)))
|
||||||
(testing "Yielding control prefills wallet"
|
(testing "Yielding control prefills wallet"
|
||||||
(let [fx (protocol/yield-control personal-send-command {:asset "ETH" :amount "0.01"} cofx)]
|
(let [fx (protocol/yield-control personal-send-command {:content {:params {:asset "ETH" :amount "0.01"}}} cofx)]
|
||||||
(is (= (get-in fx [:db :wallet :send-transaction :amount-text]) "0.01"))
|
(is (= (get-in fx [:db :wallet :send-transaction :amount-text]) "0.01"))
|
||||||
(is (= (get-in fx [:db :wallet :send-transaction :symbol]) :ETH)))))
|
(is (= (get-in fx [:db :wallet :send-transaction :symbol]) :ETH)))))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue