diff --git a/src/status_im/signing/core.cljs b/src/status_im/signing/core.cljs index 3b75943737..089b45af80 100644 --- a/src/status_im/signing/core.cljs +++ b/src/status_im/signing/core.cljs @@ -137,6 +137,7 @@ :contact (get-contact db address) :contract to :approve? (not= type :transfer) + :value value :amount (money/to-fixed (money/token->unit value decimals)) :token token :symbol symbol})))))) @@ -153,6 +154,7 @@ {:to to :contact (get-contact db to) :symbol :ETH + :value value :amount (str eth-amount) :token (tokens/asset-for (:wallet/all-tokens db) (ethereum/chain-keyword db) :ETH)} (not (nil? token)) @@ -182,23 +184,24 @@ :signing/tx tx :signing/sign {:type (if keycard-multiaccount? :keycard :password) :formatted-data (if typed? (types/json->clj data) (ethereum/hex-to-utf8 data))})} - (fx/merge cofx - {:db - (assoc updated-db - :signing/in-progress? true - :signing/queue (drop-last queue) - :signing/tx (prepare-tx updated-db tx)) - :dismiss-keyboard - nil} - #(when-not gas - {:db (assoc-in (:db %) [:signing/edit-fee :gas-loading?] true) - :signing/update-estimated-gas {:obj tx-obj - :success-event :signing/update-estimated-gas-success - :error-event :signing/update-estimated-gas-error}}) - #(when-not gasPrice - {:db (assoc-in (:db %) [:signing/edit-fee :gas-price-loading?] true) - :signing/update-gas-price {:success-event :signing/update-gas-price-success - :error-event :signing/update-gas-price-error}}))))) + (fx/merge + cofx + {:db + (assoc updated-db + :signing/in-progress? true + :signing/queue (drop-last queue) + :signing/tx (prepare-tx updated-db tx)) + :dismiss-keyboard + nil} + #(when-not gas + {:db (assoc-in (:db %) [:signing/edit-fee :gas-loading?] true) + :signing/update-estimated-gas {:obj tx-obj + :success-event :signing/update-estimated-gas-success + :error-event :signing/update-estimated-gas-error}}) + #(when-not gasPrice + {:db (assoc-in (:db %) [:signing/edit-fee :gas-price-loading?] true) + :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}] (let [{:signing/keys [in-progress? queue]} db] @@ -207,17 +210,21 @@ (fx/defn 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" - :params [chat-id transaction-hash (:result (types/json->clj signature))] - :on-success #(re-frame/dispatch [:transport/message-sent % 1])}]}) + :params [chat-id value contract transaction-hash + (:result (types/json->clj signature))] + :on-success + #(re-frame/dispatch [:transport/message-sent % 1])}]}) (fx/defn send-accept-request-transaction-message {:events [::send-accept-transaction-message]} [cofx message-id transaction-hash signature] {::json-rpc/call [{:method "shhext_acceptRequestTransaction" - :params [transaction-hash message-id (:result (types/json->clj signature))] - :on-success #(re-frame/dispatch [:transport/message-sent % 1])}]}) + :params [transaction-hash message-id + (:result (types/json->clj signature))] + :on-success + #(re-frame/dispatch [:transport/message-sent % 1])}]}) (fx/defn transaction-result [{:keys [db] :as cofx} result tx-obj] @@ -231,25 +238,28 @@ {:dispatch (conj on-result result)})))) (fx/defn command-transaction-result - [{:keys [db] :as cofx} result hashed-password tx-obj] - (let [{:keys [on-result symbol amount]} (get db :signing/tx)] - (fx/merge cofx - {:db (dissoc db :signing/tx :signing/in-progress? :signing/sign) - :signing.fx/sign-message - {:params {:data (str (get-in db [:multiaccount :public-key]) - (subs result 2)) - :password hashed-password - :account (:from tx-obj)} - :on-completed - #(re-frame/dispatch - (if (:message-id tx-obj) - [::send-accept-transaction-message (:message-id tx-obj) result %] - [::send-transaction-message (:chat-id tx-obj) result %]))} - :signing/show-transaction-result nil} - (prepare-unconfirmed-transaction result tx-obj symbol amount) - (check-queue) - #(when on-result - {:dispatch (conj on-result result)})))) + [{:keys [db] :as cofx} transaction-hash hashed-password + {:keys [message-id chat-id from] :as tx-obj}] + (let [{:keys [on-result symbol amount contract value]} (get db :signing/tx)] + (fx/merge + cofx + {:db (dissoc db :signing/tx :signing/in-progress? :signing/sign) + :signing.fx/sign-message + {:params {:data (str (get-in db [:multiaccount :public-key]) + (subs transaction-hash 2)) + :password hashed-password + :account from} + :on-completed + #(re-frame/dispatch + (if message-id + [::send-accept-transaction-message message-id transaction-hash %] + [::send-transaction-message + chat-id value contract transaction-hash %]))} + :signing/show-transaction-result nil} + (prepare-unconfirmed-transaction transaction-hash tx-obj symbol amount) + (check-queue) + #(when on-result + {:dispatch (conj on-result transaction-hash)})))) (fx/defn transaction-error [{:keys [db]} {:keys [code message]}] diff --git a/src/status_im/ui/screens/chat/message/message.cljs b/src/status_im/ui/screens/chat/message/message.cljs index d6e2e06df6..2d8d7cc879 100644 --- a/src/status_im/ui/screens/chat/message/message.cljs +++ b/src/status_im/ui/screens/chat/message/message.cljs @@ -286,12 +286,10 @@ (i18n/label (if (or (= command-state constants/command-state-request-address-for-transaction-declined) (= command-state constants/command-state-request-transaction-declined)) :t/transaction-declined - (case direction - :outgoing (case transaction-type - :pending :t/status-pending - :failed :t/transaction-failed - :t/status-confirmed) - :incoming :t/status-confirmed)))]]) + (case transaction-type + :pending :t/status-pending + :failed :t/transaction-failed + :t/status-confirmed)))]]) (defn- command-status-and-timestamp [command-state direction to timestamp-str transaction-type] diff --git a/src/status_im/ui/screens/wallet/send/views.cljs b/src/status_im/ui/screens/wallet/send/views.cljs index d4c93e140c..2b50e0feaa 100644 --- a/src/status_im/ui/screens/wallet/send/views.cljs +++ b/src/status_im/ui/screens/wallet/send/views.cljs @@ -68,6 +68,7 @@ (defn render-contact [contact from-chat?] (if from-chat? [list-item/list-item {:title (multiaccounts/displayed-name contact) + :subtitle (:address contact) :icon (multiaccounts/displayed-photo contact)}] [list-item/list-item {:title (utils/get-shortened-checksum-address diff --git a/src/status_im/wallet/core.cljs b/src/status_im/wallet/core.cljs index 54ed056dc7..29558055b6 100644 --- a/src/status_im/wallet/core.cljs +++ b/src/status_im/wallet/core.cljs @@ -23,6 +23,8 @@ [status-im.signing.core :as signing] [clojure.string :as string] [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])) (re-frame/reg-fx @@ -375,21 +377,39 @@ {:events [:wallet.ui/sign-transaction-button-clicked-from-chat]} [{:keys [db] :as cofx} {:keys [to amount from token request? from-chat? gas gasPrice]}] (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))) from-address (:address from) - identity (:current-chat-id db)] - (fx/merge cofx - {:db (-> db - (update-in [:chat-ui-props identity] dissoc :input-bottom-sheet) - (dissoc :wallet/prepare-transaction)) - ;;TODO from chat, send request message or if ens name sign tx and send tx message - ::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])}]}))) + identity (:current-chat-id db) + db (-> db + (update-in [:chat-ui-props identity] dissoc :input-bottom-sheet) + (dissoc :wallet/prepare-transaction))] + (if to-norm + (fx/merge + cofx + {:db db} + (signing/sign {:tx-obj (if (= symbol :ETH) + {:to to-norm + :from from-address + :chat-id identity + :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 {:events [:wallet.ui/request-transaction-button-clicked]} @@ -449,22 +469,21 @@ (fx/merge cofx {:db (dissoc db :wallet/prepare-transaction)} (fn [cofx] - (signing/sign cofx {:tx-obj (if (= symbol :ETH) - {:to to-norm - :from from-address - :message-id (:id request-parameters) - :command? true - :value amount-hex} - {:to (ethereum/normalized-hex address) - :from from-address - :command? true - :message-id (:id request-parameters) - :data (abi-spec/encode - "transfer(address,uint256)" - [to-norm amount-hex]) - ;;Note: data from qr (eip681) - :gas gas - :gasPrice gasPrice})}))))) + (signing/sign + cofx + {:tx-obj (if (= symbol :ETH) + {:to to-norm + :from from-address + :message-id (:id request-parameters) + :command? true + :value amount-hex} + {:to (ethereum/normalized-hex address) + :from from-address + :command? true + :message-id (:id request-parameters) + :data (abi-spec/encode + "transfer(address,uint256)" + [to-norm amount-hex])})}))))) (fx/defn sign-transaction-button-clicked {:events [:wallet.ui/sign-transaction-button-clicked]} @@ -498,19 +517,16 @@ from-address (:address from)] (fx/merge cofx {:db (dissoc db :wallet/prepare-transaction)} - (fn [cofx] - (signing/sign cofx {:tx-obj (if (= symbol :ETH) - {:to to-norm - :from from-address - :value amount-hex} - {:to (ethereum/normalized-hex address) - :from from-address - :data (abi-spec/encode - "transfer(address,uint256)" - [to-norm amount-hex]) - ;;Note: data from qr (eip681) - :gas gas - :gasPrice gasPrice})}))))) + (signing/sign + {:tx-obj (merge {:from from-address} + (if (= symbol :ETH) + {:to to-norm + :value amount-hex} + {:to (ethereum/normalized-hex address) + :from from-address + :data (abi-spec/encode + "transfer(address,uint256)" + [to-norm amount-hex])}))})))) (fx/defn set-and-validate-amount-request {: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-error] error))})) -;;TODO request isn't implemented (fx/defn set-symbol-request {:events [:wallet.request/set-symbol]} [{:keys [db]} 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 {:events [:wallet/prepare-transaction-from-chat]} [{:keys [db]}] - (let [identity (:current-chat-id db)] - {:db (assoc db :wallet/prepare-transaction - {:from (ethereum/get-default-account (:multiaccount/accounts db)) - :to (or (get-in db [:contacts/contacts identity]) - (-> identity - contact.db/public-key->new-contact - contact.db/enrich-contact)) - :symbol :ETH - :from-chat? true})})) + (let [chain (ethereum/chain-keyword db) + identity (:current-chat-id db) + {:keys [ens-verified name] :as contact} + (or (get-in db [:contacts/contacts identity]) + (-> identity + contact.db/public-key->new-contact + contact.db/enrich-contact))] + (cond-> {:db (assoc db + :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 {:events [:wallet/prepare-request-transaction-from-chat]} diff --git a/status-go-version.json b/status-go-version.json index 6af963ad89..d3d8a442eb 100644 --- a/status-go-version.json +++ b/status-go-version.json @@ -2,7 +2,7 @@ "_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh ' instead", "owner": "status-im", "repo": "status-go", - "version": "v0.39.6", - "commit-sha1": "25d46c6d82fbf3e4b6659cb96cf1789bac87f12a", - "src-sha256": "1m6d07hlxfp8yr94ld73m6dflrgdyjhmpr2ajnjkhjlv9ffvicgb" + "version": "v0.39.8", + "commit-sha1": "456bcfa022fedb476fadb82bedaa6c07b0c5f869", + "src-sha256": "0gd4mfai366lqpw522l9yjlxp9v0i1wfjj2bkfzmgb3lg1hl8l6h" } diff --git a/test/cljs/status_im/test/signing/core.cljs b/test/cljs/status_im/test/signing/core.cljs index 997e0e9e72..8331869284 100644 --- a/test/cljs/status_im/test/signing/core.cljs +++ b/test/cljs/status_im/test/signing/core.cljs @@ -33,6 +33,7 @@ :to to :contact {:address to} :symbol :ETH + :value "0x8ac7230489e80000" :amount "10"}))))) (testing "after second transaction" (testing "signing still in progress" @@ -55,4 +56,4 @@ :gasPrice nil :data data :to contract - :contact {:address contract}})))))))))) \ No newline at end of file + :contact {:address contract}}))))))))))