Skip to content

Commit

Permalink
Merge branch 'develop' into cl-21278-typed-data-improve
Browse files Browse the repository at this point in the history
  • Loading branch information
clauxx authored Sep 26, 2024
2 parents db935cd + fdc814c commit dac775d
Show file tree
Hide file tree
Showing 15 changed files with 127 additions and 63 deletions.
2 changes: 1 addition & 1 deletion src/quo/components/settings/data_item/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
colors/neutral-50)]
[rn/pressable
{:accessibility-label :data-item
:disabled (not right-icon)
:disabled (nil? on-press)
:on-press on-press
:style (merge (style/container {:size size
:card? card?
Expand Down
1 change: 1 addition & 0 deletions src/status_im/constants.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@
(def ^:const slippages [0.1 0.5 1])
(def ^:const default-slippage 0.5)
(def ^:const max-recommended-slippage 5)
(def ^:const max-slippage 30)
(def ^:const max-slippage-decimal-places 2)
(def ^:const swap-provider-paraswap
{:name :paraswap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

(defn- navigate-to-sign-in-by-syncing
[]
(rf/dispatch [:syncing/clear-syncing-fallback-flow])
(debounce/throttle-and-dispatch
[:onboarding/navigate-to-sign-in-by-syncing]
1000))
Expand All @@ -37,6 +38,7 @@

(defn- navigate-to-sign-in-by-seed-phrase
[create-profile?]
(rf/dispatch [:syncing/clear-syncing-fallback-flow])
(rf/dispatch [:onboarding/navigate-to-sign-in-by-seed-phrase
(if create-profile?
:screen/onboarding.new-to-status
Expand Down
23 changes: 14 additions & 9 deletions src/status_im/contexts/onboarding/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,21 @@
[{:keys [db] :as cofx}]
(let [{:keys [display-name seed-phrase password image-path color] :as profile}
(:onboarding/profile db)
loading-screen (if (seq (:syncing/key-uid db))
syncing-account-recovered? (and (seq (:syncing/key-uid db))
(= (:syncing/key-uid db)
(get-in db [:onboarding/profile :key-uid])))
loading-screen (if syncing-account-recovered?
:screen/onboarding.preparing-status
:screen/onboarding.generating-keys)]
(rf/merge cofx
{:dispatch [:navigate-to-within-stack
[loading-screen
(get db
:onboarding/navigated-to-enter-seed-phrase-from-screen
:screen/onboarding.new-to-status)]]
{:fx [[:dispatch
[:navigate-to-within-stack
[loading-screen
(get db
:onboarding/navigated-to-enter-seed-phrase-from-screen
:screen/onboarding.new-to-status)]]]
(when-not syncing-account-recovered?
[:dispatch [:syncing/clear-syncing-installation-id]])]
:dispatch-later [{:ms constants/onboarding-generating-keys-animation-duration-ms
:dispatch [:navigate-to-within-stack
[:screen/onboarding.enable-notifications
Expand Down Expand Up @@ -154,15 +160,14 @@
:on-cancel #(re-frame/dispatch [:pop-to-root :multiaccounts])}}
{:db (-> db
(assoc-in [:onboarding/profile :seed-phrase] seed-phrase)
(assoc-in [:onboarding/profile :key-uid] key-uid)
(assoc-in [:onboarding/profile :color] constants/profile-default-color))
:fx [[:dispatch
[:navigate-to-within-stack
[next-screen
(get db
:onboarding/navigated-to-enter-seed-phrase-from-screen
:screen/onboarding.new-to-status)]]]
(when-not syncing-account-recovered?
[:dispatch [:syncing/clear-syncing-data]])]})))
:screen/onboarding.new-to-status)]]]]})))

(rf/defn navigate-to-create-profile
{:events [:onboarding/navigate-to-create-profile]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

(defn- navigate-to-enter-seed-phrase
[]
(rf/dispatch [:syncing/set-syncing-fallback-flow])
(debounce/debounce-and-dispatch
[:onboarding/navigate-to-sign-in-by-seed-phrase :screen/onboarding.sync-or-recover-profile]
500))
Expand Down
2 changes: 1 addition & 1 deletion src/status_im/contexts/profile/login/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
(rf/dispatch [:chats-list/load-success result])
(rf/dispatch [:communities/get-user-requests-to-join])
(rf/dispatch [:profile.login/get-chats-callback]))}]
(when (:syncing/installation-id db)
(when (and (:syncing/fallback-flow? db) (:syncing/installation-id db))
[:dispatch [:pairing/finish-seed-phrase-fallback-syncing]])
(when-not new-account?
[:dispatch [:universal-links/process-stored-event]])]})))
Expand Down
25 changes: 15 additions & 10 deletions src/status_im/contexts/syncing/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,33 @@
{:type :negative
:text error}]))))

(rf/defn initiate-pairing-process
{:events [:syncing/initiate-pairing-process]}
[{:keys [db]}]
{:db (assoc db :syncing/pairing-process-initiated? true)})

(rf/defn set-syncing-installation-id
{:events [:syncing/set-syncing-installation-id]}
[{:keys [db]} installation-id key-uid]
{:db (assoc db
:syncing/key-uid key-uid
:syncing/installation-id installation-id)})

(defn clear-syncing-data
(defn clear-syncing-installation-id
[{:keys [db]}]
{:db (dissoc
db
:syncing/key-uid
:syncing/installation-id
:syncing/pairing-process-initiated?)})
:syncing/installation-id)})

(re-frame/reg-event-fx :syncing/clear-syncing-installation-id clear-syncing-installation-id)

(defn set-syncing-fallback-flow
[{:keys [db]}]
{:db (assoc db :syncing/fallback-flow? true)})

(re-frame/reg-event-fx :syncing/set-syncing-fallback-flow set-syncing-fallback-flow)

(defn clear-syncing-fallback-flow
[{:keys [db]}]
{:db (dissoc db :syncing/fallback-flow?)})

(re-frame/reg-event-fx :syncing/clear-syncing-data clear-syncing-data)
(re-frame/reg-event-fx :syncing/clear-syncing-fallback-flow clear-syncing-fallback-flow)

(rf/defn preflight-outbound-check-for-local-pairing
{:events [:syncing/preflight-outbound-check]}
Expand Down Expand Up @@ -95,7 +101,6 @@
(when (sync-utils/valid-connection-string? response)
(on-valid-connection-string response)
(rf/dispatch [:syncing/update-role constants/local-pairing-role-sender])
(rf/dispatch [:syncing/initiate-pairing-process])
(rf/dispatch [:hide-bottom-sheet])))]
(when-not (and error (string/blank? error))
(let [key-uid (get-in db [:profile/profile :key-uid])
Expand Down
14 changes: 5 additions & 9 deletions src/status_im/contexts/wallet/send/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,19 @@
:token-decimals token-decimals
:native-token? native-token?
:receiver? false})
from-network-values-for-ui (send-utils/network-values-for-ui
from-network-amounts-by-chain)
to-network-amounts-by-chain (send-utils/network-amounts-by-chain
{:route chosen-route
:token-decimals token-decimals
:native-token? native-token?
:receiver? true})
to-network-values-for-ui (send-utils/network-values-for-ui
to-network-amounts-by-chain)
sender-possible-chain-ids (map :chain-id sender-network-values)
sender-network-values (if routes-available?
(send-utils/network-amounts
{:network-values
(if (= tx-type :tx/bridge)
from-network-values-for-ui
from-network-amounts-by-chain
(send-utils/add-zero-values-to-network-values
from-network-values-for-ui
from-network-amounts-by-chain
sender-possible-chain-ids))
:disabled-chain-ids disabled-from-chain-ids
:receiver-networks receiver-networks
Expand All @@ -71,7 +67,7 @@
sender-network-values))
receiver-network-values (if routes-available?
(send-utils/network-amounts
{:network-values to-network-values-for-ui
{:network-values to-network-amounts-by-chain
:disabled-chain-ids disabled-from-chain-ids
:receiver-networks receiver-networks
:token-networks-ids token-networks-ids
Expand All @@ -91,8 +87,8 @@
assoc
:suggested-routes suggested-routes-data
:route chosen-route
:from-values-by-chain from-network-values-for-ui
:to-values-by-chain to-network-values-for-ui
:from-values-by-chain from-network-amounts-by-chain
:to-values-by-chain to-network-amounts-by-chain
:sender-network-values sender-network-values
:receiver-network-values receiver-network-values
:network-links network-links
Expand Down
2 changes: 2 additions & 0 deletions src/status_im/contexts/wallet/send/send_amount/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
(:require
[quo.theme]
[status-im.contexts.wallet.send.input-amount.view :as input-amount]
[status-im.setup.hot-reload :as hot-reload]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))

(defn view
[]
(hot-reload/use-safe-unmount #(rf/dispatch [:wallet/stop-get-suggested-routes]))
[input-amount/view
{:current-screen-id :screen/wallet.send-input-amount
:button-one-label (i18n/label :t/review-send)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
[status-im.common.standard-authentication.core :as standard-auth]
[status-im.contexts.wallet.common.utils :as utils]
[status-im.contexts.wallet.send.transaction-confirmation.style :as style]
[status-im.contexts.wallet.send.utils :as send-utils]
[utils.i18n :as i18n]
[utils.re-frame :as rf]
[utils.security.core :as security]))
Expand Down Expand Up @@ -142,7 +143,7 @@
[quo/summary-info
{:type summary-info-type
:networks? true
:values network-values
:values (send-utils/network-values-for-ui network-values)
:account-props (cond-> account-props
(and account-to? (not bridge-tx?))
(assoc
Expand Down
59 changes: 46 additions & 13 deletions src/status_im/contexts/wallet/sheets/slippage_settings/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@
(:require [clojure.string :as string]
[quo.core :as quo]
[react-native.core :as rn]
[react-native.platform :as platform]
[status-im.constants :as constants]
[status-im.contexts.wallet.sheets.slippage-settings.style :as style]
[utils.i18n :as i18n]
[utils.number]
[utils.money :as money]
[utils.number :as number]
[utils.re-frame :as rf]))

(defn- validate-slippage
[slippage]
(let [slippage-value (utils.number/parse-float slippage)]
(let [slippage-value (number/parse-float slippage)]
(cond
(<= slippage-value 0)
{:message (i18n/label :t/slippage-should-be-more-than-0)
:type :error}
(> slippage-value constants/max-slippage)
{:message (i18n/label :t/slippage-cant-be-more-than-30)
:type :error}
(> (count (second (string/split slippage ".")))
constants/max-slippage-decimal-places)
{:message (i18n/label :t/max-2-decimals)
Expand All @@ -33,14 +38,37 @@
(subs s 0 (dec (count s)))
(str s k)))

(defn- calculate-receive-amount
[asset-to-receive amount-out max-slippage]
(let [receive-token-decimals (:decimals asset-to-receive)
amount-out-whole-number (number/hex->whole amount-out receive-token-decimals)
amount-out-num (number/to-fixed amount-out-whole-number
(min constants/min-token-decimals-to-display
receive-token-decimals))
slippage-num (-> (money/bignumber amount-out-num)
(money/mul (money/bignumber max-slippage))
(money/div (money/bignumber 100)))
amount-out-minus-slippage (money/sub (money/bignumber amount-out-num) slippage-num)
receive-amount (if (money/greater-than amount-out-minus-slippage
(money/bignumber 0))
(str amount-out-minus-slippage)
0)]
receive-amount))

(defn view
[]
(let [current-slippage (rf/sub [:wallet/swap-max-slippage])
account-color (rf/sub [:wallet/current-viewing-account-color])
asset-to-receive (rf/sub [:wallet/swap-asset-to-receive])
amount-out (rf/sub [:wallet/swap-proposal-amount-out])
[max-slippage set-max-slippage] (rn/use-state (str current-slippage))
[error set-error] (rn/use-state nil)
[custom? set-custom?] (rn/use-state (not-any? #{current-slippage}
constants/slippages))
receive-token-symbol (:symbol asset-to-receive)
receive-amount (calculate-receive-amount asset-to-receive
amount-out
max-slippage)
handle-slippage-change (rn/use-callback
(fn [value]
(let [new-slippage (update-string-on-keypress value
Expand All @@ -50,7 +78,8 @@
[max-slippage set-max-slippage set-error])
on-select-slippage (rn/use-callback (fn [slippage]
(set-max-slippage (str slippage))
(set-custom? (not slippage)))
(set-custom? (nil? slippage))
(when slippage (set-error nil)))
[set-max-slippage set-custom?])
save-disabled? (rn/use-memo (fn []
(or (= max-slippage (str current-slippage))
Expand All @@ -73,19 +102,23 @@
[quo/drawer-action
(cond-> {:title (str slippage "%")
:on-press #(on-select-slippage slippage)}
(= (str slippage) max-slippage) (assoc :state :selected))])
(and (= (str slippage) max-slippage) (not custom?)) (assoc :state :selected))])
constants/slippages)
[quo/drawer-action
(cond-> {:title (i18n/label :t/custom)
:action :input
:on-press #(on-select-slippage nil)
:input-props {:auto-focus true
:customization-color account-color
:placeholder (i18n/label :t/type-slippage)
:right-icon {:icon-name :i/percentage
:on-press identity
:style-fn style/percentage-icon}
:value max-slippage}}
:input-props {:auto-focus true
:customization-color account-color
:placeholder (i18n/label :t/type-slippage)
:right-icon {:icon-name :i/percentage
:on-press identity
:style-fn style/percentage-icon}
:value max-slippage
:show-soft-input-on-focus false
:on-focus (fn []
(when platform/android?
(rf/dispatch [:dismiss-keyboard])))}}
custom? (assoc :state :selected))]]
(when (and custom? error)
[quo/info-message
Expand All @@ -107,8 +140,8 @@
:description :top
:context-tag-props {:size 24
:type :token
:token "USDT"
:amount "99.97"} ;; will be replaced with real data later
:token receive-token-symbol
:amount receive-amount}
:description-top-text (i18n/label :t/receive-at-least)}]
(when custom?
[quo/numbered-keyboard
Expand Down
12 changes: 8 additions & 4 deletions src/status_im/contexts/wallet/swap/setup_swap/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
[status-im.contexts.wallet.common.account-switcher.view :as account-switcher]
[status-im.contexts.wallet.common.utils :as utils]
[status-im.contexts.wallet.sheets.buy-token.view :as buy-token]
[status-im.contexts.wallet.sheets.slippage-settings.view :as slippage-settings]
[status-im.contexts.wallet.swap.setup-swap.style :as style]
[status-im.contexts.wallet.swap.utils :as swap-utils]
[utils.debounce :as debounce]
Expand Down Expand Up @@ -39,7 +40,7 @@
{:clean-approval-transaction? clean-approval-transaction?}])))

(defn- data-item
[{:keys [title subtitle size subtitle-icon subtitle-color loading?]}]
[{:keys [title subtitle size subtitle-icon subtitle-color on-press loading?]}]
[quo/data-item
{:container-style style/detail-item
:blur? false
Expand All @@ -50,7 +51,8 @@
:subtitle subtitle
:size size
:icon subtitle-icon
:subtitle-color subtitle-color}])
:subtitle-color subtitle-color
:on-press on-press}])

(defn- transaction-details
[]
Expand All @@ -72,9 +74,11 @@
theme)))]
[data-item
{:title (i18n/label :t/max-slippage)
:subtitle max-slippage
:subtitle (str max-slippage "%")
:subtitle-icon :i/edit
:size :small}]]))
:size :small
:on-press #(rf/dispatch [:show-bottom-sheet
{:content slippage-settings/view}])}]]))

(defn- pay-token-input
[{:keys [input-state on-max-press on-input-focus on-token-press on-approve-press input-focused?]}]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[status-im.common.floating-button-page.view :as floating-button-page]
[status-im.common.standard-authentication.core :as standard-auth]
[status-im.constants :as constants]
[status-im.contexts.wallet.send.utils :as send-utils]
[status-im.contexts.wallet.swap.swap-confirmation.style :as style]
[utils.address :as address-utils]
[utils.i18n :as i18n]
Expand Down Expand Up @@ -76,7 +77,7 @@
[quo/summary-info
{:type :token
:networks? true
:values network-values
:values (send-utils/network-values-for-ui network-values)
:token-props {:token token-symbol
:label (str amount " " token-symbol)
:address (address-utils/get-shortened-compressed-key token-address)
Expand Down
Loading

0 comments on commit dac775d

Please sign in to comment.