From 72867473d03af40636c90767c642288f59da23ca Mon Sep 17 00:00:00 2001 From: acolytec3 <17355484+acolytec3@users.noreply.github.com> Date: Fri, 27 Sep 2019 15:52:56 -0400 Subject: [PATCH] Add currency conversions for signing sheet Signed-off-by: Andrey Shovkoplyas --- src/status_im/ui/screens/signing/views.cljs | 68 +++++++++++++-------- 1 file changed, 43 insertions(+), 25 deletions(-) diff --git a/src/status_im/ui/screens/signing/views.cljs b/src/status_im/ui/screens/signing/views.cljs index 5e723f1fb4..a61743664e 100644 --- a/src/status_im/ui/screens/signing/views.cljs +++ b/src/status_im/ui/screens/signing/views.cljs @@ -46,11 +46,6 @@ (defn separator [] [react/view {:height 1 :background-color colors/gray-lighter}]) -(defn acc-text [txt1 txt2] - [react/nested-text nil - txt1 " " - [{:style {:color colors/gray}} txt2]]) - (defn displayed-name [contact] (if (or (:preferred-name contact) (:name contact)) (multiaccounts/displayed-name contact) @@ -218,9 +213,13 @@ sign [:signing/sign] chain [:ethereum/chain-keyword] {:keys [amount-error gas-error]} [:signing/amount-errors (:address from)] - keycard-multiaccount? [:keycard-multiaccount?]] + keycard-multiaccount? [:keycard-multiaccount?] + prices [:prices] + wallet-currency [:wallet/currency]] (let [display-symbol (wallet.utils/display-symbol token) - fee-display-symbol (wallet.utils/display-symbol (tokens/native-currency chain))] + fee-display-symbol (wallet.utils/display-symbol (tokens/native-currency chain)) + converted-value (* amount (get-in prices [(keyword display-symbol) (keyword (:code wallet-currency)) :price])) + converted-fee-value (* fee (get-in prices [(keyword fee-display-symbol) (keyword (:code wallet-currency)) :price]))] [react/view styles/sheet [header sign tx display-symbol fee fee-display-symbol] [separator] @@ -239,24 +238,43 @@ {:type :small :title :t/send-request-amount :error amount-error - :accessories [[acc-text (if amount (str amount) "0") - (or display-symbol fee-display-symbol)]]}] - [separator]]) - [list-item/list-item - {:type :small - :title :t/network-fee - :error gas-error - :accessories [[acc-text fee fee-display-symbol] :chevron] - :on-press #(re-frame/dispatch - [:signing.ui/open-fee-sheet - {:content (fn [] [sheets/fee-bottom-sheet fee-display-symbol]) - :content-height 270}])}] - [react/view {:align-items :center :margin-top 16 :margin-bottom 40} - (if keycard-multiaccount? - [sign-with-keycard-button amount-error gas-error] - [button/button {:on-press #(re-frame/dispatch [:set :signing/sign {:type :password}]) - :disabled? (or amount-error gas-error) - :label :t/sign-with-password}])]])]))) + :accessories [[react/nested-text {:style {:color colors/gray}} + [{:style {:color colors/black}} (if amount (str amount) "0")] + " " + (or display-symbol fee-display-symbol) + " • " + [{:style {:color colors/black}} (if converted-value (str "~" (i18n/format-currency converted-value (:code wallet-currency))) + [react/activity-indicator {:color :colors/gray + :ios {:size :small} + :android {:size :16}}])] + " " + (str (:code wallet-currency))]]}] + [separator] + [list-item/list-item + {:type :small + :title :t/network-fee + :error gas-error + :accessories [[react/nested-text {:style {:color colors/gray}} + [{:style {:color colors/black}} fee] + " " + fee-display-symbol + " • " + [{:style {:color colors/black}} (if converted-fee-value (str "~" (i18n/format-currency converted-fee-value (:code wallet-currency))) + [react/activity-indicator {:color :colors/gray + :ios {:size :small} + :android {:size :16}}])] + " " + (str (:code wallet-currency))] :chevron] + :on-press #(re-frame/dispatch + [:signing.ui/open-fee-sheet + {:content (fn [] [sheets/fee-bottom-sheet fee-display-symbol]) + :content-height 270}])}] + [react/view {:align-items :center :margin-top 16 :margin-bottom 40} + (if keycard-multiaccount? + [sign-with-keycard-button amount-error gas-error] + [button/button {:on-press #(re-frame/dispatch [:set :signing/sign {:type :password}]) + :disabled? (or amount-error gas-error) + :label :t/sign-with-password}])]])])]))) (defn signing-view [tx window-height] (let [bottom-anim-value (anim/create-value window-height)