make send commands work directly with ens names
Signed-off-by: yenda <eric@status.im>
This commit is contained in:
parent
97560d3dfe
commit
db74e0431c
|
@ -137,6 +137,7 @@
|
||||||
:contact (get-contact db address)
|
:contact (get-contact db address)
|
||||||
:contract to
|
:contract to
|
||||||
:approve? (not= type :transfer)
|
:approve? (not= type :transfer)
|
||||||
|
:value value
|
||||||
:amount (money/to-fixed (money/token->unit value decimals))
|
:amount (money/to-fixed (money/token->unit value decimals))
|
||||||
:token token
|
:token token
|
||||||
:symbol symbol}))))))
|
:symbol symbol}))))))
|
||||||
|
@ -153,6 +154,7 @@
|
||||||
{:to to
|
{:to to
|
||||||
:contact (get-contact db to)
|
:contact (get-contact db to)
|
||||||
:symbol :ETH
|
:symbol :ETH
|
||||||
|
:value value
|
||||||
:amount (str eth-amount)
|
:amount (str eth-amount)
|
||||||
:token (tokens/asset-for (:wallet/all-tokens db) (ethereum/chain-keyword db) :ETH)}
|
:token (tokens/asset-for (:wallet/all-tokens db) (ethereum/chain-keyword db) :ETH)}
|
||||||
(not (nil? token))
|
(not (nil? token))
|
||||||
|
@ -182,23 +184,24 @@
|
||||||
:signing/tx tx
|
:signing/tx tx
|
||||||
:signing/sign {:type (if keycard-multiaccount? :keycard :password)
|
:signing/sign {:type (if keycard-multiaccount? :keycard :password)
|
||||||
:formatted-data (if typed? (types/json->clj data) (ethereum/hex-to-utf8 data))})}
|
:formatted-data (if typed? (types/json->clj data) (ethereum/hex-to-utf8 data))})}
|
||||||
(fx/merge cofx
|
(fx/merge
|
||||||
{:db
|
cofx
|
||||||
(assoc updated-db
|
{:db
|
||||||
:signing/in-progress? true
|
(assoc updated-db
|
||||||
:signing/queue (drop-last queue)
|
:signing/in-progress? true
|
||||||
:signing/tx (prepare-tx updated-db tx))
|
:signing/queue (drop-last queue)
|
||||||
:dismiss-keyboard
|
:signing/tx (prepare-tx updated-db tx))
|
||||||
nil}
|
:dismiss-keyboard
|
||||||
#(when-not gas
|
nil}
|
||||||
{:db (assoc-in (:db %) [:signing/edit-fee :gas-loading?] true)
|
#(when-not gas
|
||||||
:signing/update-estimated-gas {:obj tx-obj
|
{:db (assoc-in (:db %) [:signing/edit-fee :gas-loading?] true)
|
||||||
:success-event :signing/update-estimated-gas-success
|
:signing/update-estimated-gas {:obj tx-obj
|
||||||
:error-event :signing/update-estimated-gas-error}})
|
:success-event :signing/update-estimated-gas-success
|
||||||
#(when-not gasPrice
|
:error-event :signing/update-estimated-gas-error}})
|
||||||
{:db (assoc-in (:db %) [:signing/edit-fee :gas-price-loading?] true)
|
#(when-not gasPrice
|
||||||
:signing/update-gas-price {:success-event :signing/update-gas-price-success
|
{:db (assoc-in (:db %) [:signing/edit-fee :gas-price-loading?] true)
|
||||||
:error-event :signing/update-gas-price-error}})))))
|
:signing/update-gas-price {:success-event :signing/update-gas-price-success
|
||||||
|
:error-event :signing/update-gas-price-error}})))))
|
||||||
|
|
||||||
(fx/defn check-queue [{:keys [db] :as cofx}]
|
(fx/defn check-queue [{:keys [db] :as cofx}]
|
||||||
(let [{:signing/keys [in-progress? queue]} db]
|
(let [{:signing/keys [in-progress? queue]} db]
|
||||||
|
@ -207,17 +210,21 @@
|
||||||
|
|
||||||
(fx/defn send-transaction-message
|
(fx/defn send-transaction-message
|
||||||
{:events [::send-transaction-message]}
|
{:events [::send-transaction-message]}
|
||||||
[cofx chat-id transaction-hash signature]
|
[cofx chat-id value contract transaction-hash signature]
|
||||||
{::json-rpc/call [{:method "shhext_sendTransaction"
|
{::json-rpc/call [{:method "shhext_sendTransaction"
|
||||||
:params [chat-id transaction-hash (:result (types/json->clj signature))]
|
:params [chat-id value contract transaction-hash
|
||||||
:on-success #(re-frame/dispatch [:transport/message-sent % 1])}]})
|
(:result (types/json->clj signature))]
|
||||||
|
:on-success
|
||||||
|
#(re-frame/dispatch [:transport/message-sent % 1])}]})
|
||||||
|
|
||||||
(fx/defn send-accept-request-transaction-message
|
(fx/defn send-accept-request-transaction-message
|
||||||
{:events [::send-accept-transaction-message]}
|
{:events [::send-accept-transaction-message]}
|
||||||
[cofx message-id transaction-hash signature]
|
[cofx message-id transaction-hash signature]
|
||||||
{::json-rpc/call [{:method "shhext_acceptRequestTransaction"
|
{::json-rpc/call [{:method "shhext_acceptRequestTransaction"
|
||||||
:params [transaction-hash message-id (:result (types/json->clj signature))]
|
:params [transaction-hash message-id
|
||||||
:on-success #(re-frame/dispatch [:transport/message-sent % 1])}]})
|
(:result (types/json->clj signature))]
|
||||||
|
:on-success
|
||||||
|
#(re-frame/dispatch [:transport/message-sent % 1])}]})
|
||||||
|
|
||||||
(fx/defn transaction-result
|
(fx/defn transaction-result
|
||||||
[{:keys [db] :as cofx} result tx-obj]
|
[{:keys [db] :as cofx} result tx-obj]
|
||||||
|
@ -231,25 +238,28 @@
|
||||||
{:dispatch (conj on-result result)}))))
|
{:dispatch (conj on-result result)}))))
|
||||||
|
|
||||||
(fx/defn command-transaction-result
|
(fx/defn command-transaction-result
|
||||||
[{:keys [db] :as cofx} result hashed-password tx-obj]
|
[{:keys [db] :as cofx} transaction-hash hashed-password
|
||||||
(let [{:keys [on-result symbol amount]} (get db :signing/tx)]
|
{:keys [message-id chat-id from] :as tx-obj}]
|
||||||
(fx/merge cofx
|
(let [{:keys [on-result symbol amount contract value]} (get db :signing/tx)]
|
||||||
{:db (dissoc db :signing/tx :signing/in-progress? :signing/sign)
|
(fx/merge
|
||||||
:signing.fx/sign-message
|
cofx
|
||||||
{:params {:data (str (get-in db [:multiaccount :public-key])
|
{:db (dissoc db :signing/tx :signing/in-progress? :signing/sign)
|
||||||
(subs result 2))
|
:signing.fx/sign-message
|
||||||
:password hashed-password
|
{:params {:data (str (get-in db [:multiaccount :public-key])
|
||||||
:account (:from tx-obj)}
|
(subs transaction-hash 2))
|
||||||
:on-completed
|
:password hashed-password
|
||||||
#(re-frame/dispatch
|
:account from}
|
||||||
(if (:message-id tx-obj)
|
:on-completed
|
||||||
[::send-accept-transaction-message (:message-id tx-obj) result %]
|
#(re-frame/dispatch
|
||||||
[::send-transaction-message (:chat-id tx-obj) result %]))}
|
(if message-id
|
||||||
:signing/show-transaction-result nil}
|
[::send-accept-transaction-message message-id transaction-hash %]
|
||||||
(prepare-unconfirmed-transaction result tx-obj symbol amount)
|
[::send-transaction-message
|
||||||
(check-queue)
|
chat-id value contract transaction-hash %]))}
|
||||||
#(when on-result
|
:signing/show-transaction-result nil}
|
||||||
{:dispatch (conj on-result result)}))))
|
(prepare-unconfirmed-transaction transaction-hash tx-obj symbol amount)
|
||||||
|
(check-queue)
|
||||||
|
#(when on-result
|
||||||
|
{:dispatch (conj on-result transaction-hash)}))))
|
||||||
|
|
||||||
(fx/defn transaction-error
|
(fx/defn transaction-error
|
||||||
[{:keys [db]} {:keys [code message]}]
|
[{:keys [db]} {:keys [code message]}]
|
||||||
|
|
|
@ -286,12 +286,10 @@
|
||||||
(i18n/label (if (or (= command-state constants/command-state-request-address-for-transaction-declined)
|
(i18n/label (if (or (= command-state constants/command-state-request-address-for-transaction-declined)
|
||||||
(= command-state constants/command-state-request-transaction-declined))
|
(= command-state constants/command-state-request-transaction-declined))
|
||||||
:t/transaction-declined
|
:t/transaction-declined
|
||||||
(case direction
|
(case transaction-type
|
||||||
:outgoing (case transaction-type
|
:pending :t/status-pending
|
||||||
:pending :t/status-pending
|
:failed :t/transaction-failed
|
||||||
:failed :t/transaction-failed
|
:t/status-confirmed)))]])
|
||||||
:t/status-confirmed)
|
|
||||||
:incoming :t/status-confirmed)))]])
|
|
||||||
|
|
||||||
(defn- command-status-and-timestamp
|
(defn- command-status-and-timestamp
|
||||||
[command-state direction to timestamp-str transaction-type]
|
[command-state direction to timestamp-str transaction-type]
|
||||||
|
|
|
@ -68,6 +68,7 @@
|
||||||
(defn render-contact [contact from-chat?]
|
(defn render-contact [contact from-chat?]
|
||||||
(if from-chat?
|
(if from-chat?
|
||||||
[list-item/list-item {:title (multiaccounts/displayed-name contact)
|
[list-item/list-item {:title (multiaccounts/displayed-name contact)
|
||||||
|
:subtitle (:address contact)
|
||||||
:icon (multiaccounts/displayed-photo contact)}]
|
:icon (multiaccounts/displayed-photo contact)}]
|
||||||
[list-item/list-item
|
[list-item/list-item
|
||||||
{:title (utils/get-shortened-checksum-address
|
{:title (utils/get-shortened-checksum-address
|
||||||
|
|
|
@ -23,6 +23,8 @@
|
||||||
[status-im.signing.core :as signing]
|
[status-im.signing.core :as signing]
|
||||||
[clojure.string :as string]
|
[clojure.string :as string]
|
||||||
[status-im.contact.db :as contact.db]
|
[status-im.contact.db :as contact.db]
|
||||||
|
[status-im.ethereum.ens :as ens]
|
||||||
|
[status-im.ethereum.stateofus :as stateofus]
|
||||||
[status-im.ui.components.bottom-sheet.core :as bottom-sheet]))
|
[status-im.ui.components.bottom-sheet.core :as bottom-sheet]))
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
|
@ -375,21 +377,39 @@
|
||||||
{:events [:wallet.ui/sign-transaction-button-clicked-from-chat]}
|
{:events [:wallet.ui/sign-transaction-button-clicked-from-chat]}
|
||||||
[{:keys [db] :as cofx} {:keys [to amount from token request? from-chat? gas gasPrice]}]
|
[{:keys [db] :as cofx} {:keys [to amount from token request? from-chat? gas gasPrice]}]
|
||||||
(let [{:keys [symbol address]} token
|
(let [{:keys [symbol address]} token
|
||||||
|
amount-hex (str "0x" (abi-spec/number-to-hex amount))
|
||||||
to-norm (ethereum/normalized-hex (if (string? to) to (:address to)))
|
to-norm (ethereum/normalized-hex (if (string? to) to (:address to)))
|
||||||
from-address (:address from)
|
from-address (:address from)
|
||||||
identity (:current-chat-id db)]
|
identity (:current-chat-id db)
|
||||||
(fx/merge cofx
|
db (-> db
|
||||||
{:db (-> db
|
(update-in [:chat-ui-props identity] dissoc :input-bottom-sheet)
|
||||||
(update-in [:chat-ui-props identity] dissoc :input-bottom-sheet)
|
(dissoc :wallet/prepare-transaction))]
|
||||||
(dissoc :wallet/prepare-transaction))
|
(if to-norm
|
||||||
;;TODO from chat, send request message or if ens name sign tx and send tx message
|
(fx/merge
|
||||||
::json-rpc/call [{:method "shhext_requestAddressForTransaction"
|
cofx
|
||||||
:params [(:current-chat-id db)
|
{:db db}
|
||||||
from-address
|
(signing/sign {:tx-obj (if (= symbol :ETH)
|
||||||
amount
|
{:to to-norm
|
||||||
(when-not (= symbol :ETH)
|
:from from-address
|
||||||
address)]
|
:chat-id identity
|
||||||
:on-success #(re-frame/dispatch [:transport/message-sent % 1])}]})))
|
:command? true
|
||||||
|
:value amount-hex}
|
||||||
|
{:to (ethereum/normalized-hex address)
|
||||||
|
:from from-address
|
||||||
|
:chat-id identity
|
||||||
|
:command? true
|
||||||
|
:data (abi-spec/encode
|
||||||
|
"transfer(address,uint256)"
|
||||||
|
[to-norm amount-hex])})}))
|
||||||
|
{:db db
|
||||||
|
::json-rpc/call
|
||||||
|
[{:method "shhext_requestAddressForTransaction"
|
||||||
|
:params [(:current-chat-id db)
|
||||||
|
from-address
|
||||||
|
amount
|
||||||
|
(when-not (= symbol :ETH)
|
||||||
|
address)]
|
||||||
|
:on-success #(re-frame/dispatch [:transport/message-sent % 1])}]})))
|
||||||
|
|
||||||
(fx/defn request-transaction-button-clicked-from-chat
|
(fx/defn request-transaction-button-clicked-from-chat
|
||||||
{:events [:wallet.ui/request-transaction-button-clicked]}
|
{:events [:wallet.ui/request-transaction-button-clicked]}
|
||||||
|
@ -449,22 +469,21 @@
|
||||||
(fx/merge cofx
|
(fx/merge cofx
|
||||||
{:db (dissoc db :wallet/prepare-transaction)}
|
{:db (dissoc db :wallet/prepare-transaction)}
|
||||||
(fn [cofx]
|
(fn [cofx]
|
||||||
(signing/sign cofx {:tx-obj (if (= symbol :ETH)
|
(signing/sign
|
||||||
{:to to-norm
|
cofx
|
||||||
:from from-address
|
{:tx-obj (if (= symbol :ETH)
|
||||||
:message-id (:id request-parameters)
|
{:to to-norm
|
||||||
:command? true
|
:from from-address
|
||||||
:value amount-hex}
|
:message-id (:id request-parameters)
|
||||||
{:to (ethereum/normalized-hex address)
|
:command? true
|
||||||
:from from-address
|
:value amount-hex}
|
||||||
:command? true
|
{:to (ethereum/normalized-hex address)
|
||||||
:message-id (:id request-parameters)
|
:from from-address
|
||||||
:data (abi-spec/encode
|
:command? true
|
||||||
"transfer(address,uint256)"
|
:message-id (:id request-parameters)
|
||||||
[to-norm amount-hex])
|
:data (abi-spec/encode
|
||||||
;;Note: data from qr (eip681)
|
"transfer(address,uint256)"
|
||||||
:gas gas
|
[to-norm amount-hex])})})))))
|
||||||
:gasPrice gasPrice})})))))
|
|
||||||
|
|
||||||
(fx/defn sign-transaction-button-clicked
|
(fx/defn sign-transaction-button-clicked
|
||||||
{:events [:wallet.ui/sign-transaction-button-clicked]}
|
{:events [:wallet.ui/sign-transaction-button-clicked]}
|
||||||
|
@ -498,19 +517,16 @@
|
||||||
from-address (:address from)]
|
from-address (:address from)]
|
||||||
(fx/merge cofx
|
(fx/merge cofx
|
||||||
{:db (dissoc db :wallet/prepare-transaction)}
|
{:db (dissoc db :wallet/prepare-transaction)}
|
||||||
(fn [cofx]
|
(signing/sign
|
||||||
(signing/sign cofx {:tx-obj (if (= symbol :ETH)
|
{:tx-obj (merge {:from from-address}
|
||||||
{:to to-norm
|
(if (= symbol :ETH)
|
||||||
:from from-address
|
{:to to-norm
|
||||||
:value amount-hex}
|
:value amount-hex}
|
||||||
{:to (ethereum/normalized-hex address)
|
{:to (ethereum/normalized-hex address)
|
||||||
:from from-address
|
:from from-address
|
||||||
:data (abi-spec/encode
|
:data (abi-spec/encode
|
||||||
"transfer(address,uint256)"
|
"transfer(address,uint256)"
|
||||||
[to-norm amount-hex])
|
[to-norm amount-hex])}))}))))
|
||||||
;;Note: data from qr (eip681)
|
|
||||||
:gas gas
|
|
||||||
:gasPrice gasPrice})})))))
|
|
||||||
|
|
||||||
(fx/defn set-and-validate-amount-request
|
(fx/defn set-and-validate-amount-request
|
||||||
{:events [:wallet.request/set-and-validate-amount]}
|
{:events [:wallet.request/set-and-validate-amount]}
|
||||||
|
@ -521,24 +537,46 @@
|
||||||
(assoc-in [:wallet :request-transaction :amount-text] amount)
|
(assoc-in [:wallet :request-transaction :amount-text] amount)
|
||||||
(assoc-in [:wallet :request-transaction :amount-error] error))}))
|
(assoc-in [:wallet :request-transaction :amount-error] error))}))
|
||||||
|
|
||||||
;;TODO request isn't implemented
|
|
||||||
(fx/defn set-symbol-request
|
(fx/defn set-symbol-request
|
||||||
{:events [:wallet.request/set-symbol]}
|
{:events [:wallet.request/set-symbol]}
|
||||||
[{:keys [db]} symbol]
|
[{:keys [db]} symbol]
|
||||||
{:db (assoc-in db [:wallet :request-transaction :symbol] symbol)})
|
{:db (assoc-in db [:wallet :request-transaction :symbol] symbol)})
|
||||||
|
|
||||||
|
(re-frame/reg-fx
|
||||||
|
::resolve-address
|
||||||
|
(fn [{:keys [registry ens-name cb]}]
|
||||||
|
(ens/get-addr registry ens-name cb)))
|
||||||
|
|
||||||
|
(fx/defn on-recipient-address-resolved
|
||||||
|
{:events [::recipient-address-resolved]}
|
||||||
|
[{:keys [db]} address]
|
||||||
|
{:db (assoc-in db [:wallet/prepare-transaction :to :address] address)})
|
||||||
|
|
||||||
(fx/defn prepare-transaction-from-chat
|
(fx/defn prepare-transaction-from-chat
|
||||||
{:events [:wallet/prepare-transaction-from-chat]}
|
{:events [:wallet/prepare-transaction-from-chat]}
|
||||||
[{:keys [db]}]
|
[{:keys [db]}]
|
||||||
(let [identity (:current-chat-id db)]
|
(let [chain (ethereum/chain-keyword db)
|
||||||
{:db (assoc db :wallet/prepare-transaction
|
identity (:current-chat-id db)
|
||||||
{:from (ethereum/get-default-account (:multiaccount/accounts db))
|
{:keys [ens-verified name] :as contact}
|
||||||
:to (or (get-in db [:contacts/contacts identity])
|
(or (get-in db [:contacts/contacts identity])
|
||||||
(-> identity
|
(-> identity
|
||||||
contact.db/public-key->new-contact
|
contact.db/public-key->new-contact
|
||||||
contact.db/enrich-contact))
|
contact.db/enrich-contact))]
|
||||||
:symbol :ETH
|
(cond-> {:db (assoc db
|
||||||
:from-chat? true})}))
|
:wallet/prepare-transaction
|
||||||
|
{:from (ethereum/get-default-account
|
||||||
|
(:multiaccount/accounts db))
|
||||||
|
:to contact
|
||||||
|
:symbol :ETH
|
||||||
|
:from-chat? true})}
|
||||||
|
ens-verified
|
||||||
|
(assoc ::resolve-address
|
||||||
|
{:registry (get ens/ens-registries chain)
|
||||||
|
:ens-name (if (= (.indexOf name ".") -1)
|
||||||
|
(stateofus/subdomain name)
|
||||||
|
name)
|
||||||
|
;;TODO handle errors and timeout for ens name resolution
|
||||||
|
:cb #(re-frame/dispatch [::recipient-address-resolved %])}))))
|
||||||
|
|
||||||
(fx/defn prepare-request-transaction-from-chat
|
(fx/defn prepare-request-transaction-from-chat
|
||||||
{:events [:wallet/prepare-request-transaction-from-chat]}
|
{:events [:wallet/prepare-request-transaction-from-chat]}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh <tag>' instead",
|
"_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh <tag>' instead",
|
||||||
"owner": "status-im",
|
"owner": "status-im",
|
||||||
"repo": "status-go",
|
"repo": "status-go",
|
||||||
"version": "v0.39.6",
|
"version": "v0.39.8",
|
||||||
"commit-sha1": "25d46c6d82fbf3e4b6659cb96cf1789bac87f12a",
|
"commit-sha1": "456bcfa022fedb476fadb82bedaa6c07b0c5f869",
|
||||||
"src-sha256": "1m6d07hlxfp8yr94ld73m6dflrgdyjhmpr2ajnjkhjlv9ffvicgb"
|
"src-sha256": "0gd4mfai366lqpw522l9yjlxp9v0i1wfjj2bkfzmgb3lg1hl8l6h"
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
:to to
|
:to to
|
||||||
:contact {:address to}
|
:contact {:address to}
|
||||||
:symbol :ETH
|
:symbol :ETH
|
||||||
|
:value "0x8ac7230489e80000"
|
||||||
:amount "10"})))))
|
:amount "10"})))))
|
||||||
(testing "after second transaction"
|
(testing "after second transaction"
|
||||||
(testing "signing still in progress"
|
(testing "signing still in progress"
|
||||||
|
@ -55,4 +56,4 @@
|
||||||
:gasPrice nil
|
:gasPrice nil
|
||||||
:data data
|
:data data
|
||||||
:to contract
|
:to contract
|
||||||
:contact {:address contract}}))))))))))
|
:contact {:address contract}}))))))))))
|
||||||
|
|
Loading…
Reference in New Issue