This commit is contained in:
Volodymyr Kozieiev 2024-06-08 21:59:22 +01:00
parent cfc86661cd
commit 895ccc26f0
No known key found for this signature in database
GPG Key ID: 82B04968DF4C0535
2 changed files with 49 additions and 37 deletions

View File

@ -318,25 +318,32 @@
(fn [{:keys [db]} [chain-id amount]] (fn [{:keys [db]} [chain-id amount]]
{:db (assoc-in db [:wallet :ui :send :from-locked-amounts chain-id] amount)})) {:db (assoc-in db [:wallet :ui :send :from-locked-amounts chain-id] amount)}))
(rf/reg-event-fx :wallet/unlock-from-amount
(fn [{:keys [db]} [chain-id]]
(let [new-locked-amounts (-> db
(get-in [:wallet :ui :send :from-locked-amounts])
(dissoc chain-id))]
{:db (assoc-in db [:wallet :ui :send :from-locked-amounts] new-locked-amounts)})))
(rf/reg-event-fx :wallet/reset-network-amounts-to-zero (rf/reg-event-fx :wallet/reset-network-amounts-to-zero
(fn [{:keys [db]}] (fn [{:keys [db]}]
(let [sender-network-values (get-in db [:wallet :ui :send :sender-network-values]) (let [sender-network-values (get-in db [:wallet :ui :send :sender-network-values])
receiver-network-values (get-in db [:wallet :ui :send :receiver-network-values]) receiver-network-values (get-in db [:wallet :ui :send :receiver-network-values])
disabled-from-chain-ids (get-in db [:wallet :ui :send :disabled-from-chain-ids]) disabled-from-chain-ids (get-in db [:wallet :ui :send :disabled-from-chain-ids])
sender-network-values (send-utils/reset-network-amounts-to-zero sender-network-values (send-utils/reset-network-amounts-to-zero
{:network-amounts sender-network-values {:network-amounts sender-network-values
:disabled-chain-ids disabled-from-chain-ids}) :disabled-chain-ids disabled-from-chain-ids})
receiver-network-values (send-utils/reset-network-amounts-to-zero receiver-network-values (send-utils/reset-network-amounts-to-zero
{:network-amounts receiver-network-values {:network-amounts receiver-network-values
:disabled-chain-ids []})] :disabled-chain-ids []})]
{:db (-> db {:db (-> db
(assoc-in [:wallet :ui :send :sender-network-values] sender-network-values) (assoc-in [:wallet :ui :send :sender-network-values] sender-network-values)
(assoc-in [:wallet :ui :send :receiver-network-values] receiver-network-values) (assoc-in [:wallet :ui :send :receiver-network-values] receiver-network-values)
(update-in [:wallet :ui :send] (update-in [:wallet :ui :send]
dissoc dissoc
:network-links :network-links
(when (empty? sender-network-values) :sender-network-values) (when (empty? sender-network-values) :sender-network-values)
(when (empty? receiver-network-values) :receiver-network-values)))}))) (when (empty? receiver-network-values) :receiver-network-values)))})))
(rf/reg-event-fx :wallet/get-suggested-routes (rf/reg-event-fx :wallet/get-suggested-routes
(fn [{:keys [db now]} [{:keys [amount updated-token ]}]] (fn [{:keys [db now]} [{:keys [amount updated-token ]}]]

View File

@ -113,11 +113,10 @@
currency (rf/sub [:profile/currency]) currency (rf/sub [:profile/currency])
currency-symbol (rf/sub [:profile/currency-symbol]) currency-symbol (rf/sub [:profile/currency-symbol])
send-from-locked-amounts (rf/sub [:wallet/wallet-send-from-locked-amounts]) send-from-locked-amounts (rf/sub [:wallet/wallet-send-from-locked-amounts])
existing-locked-amount (when send-from-locked-amounts locked-amount (get send-from-locked-amounts chain-id)
(get send-from-locked-amounts chain-id))
network-name-str (string/capitalize (name network-name)) network-name-str (string/capitalize (name network-name))
[input-state set-input-state] (rn/use-state (cond-> controlled-input/init-state [input-state set-input-state] (rn/use-state (cond-> controlled-input/init-state
existing-locked-amount (controlled-input/set-input-value existing-locked-amount))) locked-amount (controlled-input/set-input-value locked-amount)))
[crypto-currency? set-crypto-currency] (rn/use-state true) [crypto-currency? set-crypto-currency] (rn/use-state true)
conversion-rate (-> token conversion-rate (-> token
:market-values-per-currency :market-values-per-currency
@ -135,7 +134,11 @@
current-crypto-limit current-crypto-limit
current-fiat-limit) current-fiat-limit)
crypto-decimals token-decimals crypto-decimals token-decimals
input-amount (controlled-input/input-value input-state)] input-amount (controlled-input/input-value input-state)
[is-amount-locked? set-is-amount-locked] (rn/use-state (some? locked-amount))
unlock-amount (fn []
(rf/dispatch [:wallet/unlock-from-amount chain-id]))]
(rn/use-effect (rn/use-effect
(fn [] (fn []
(set-input-state #(controlled-input/set-upper-limit % current-limit))) (set-input-state #(controlled-input/set-upper-limit % current-limit)))
@ -188,22 +191,25 @@
;; :on-token-press show-select-asset-sheet ;; :on-token-press show-select-asset-sheet
}] }]
[quo/disclaimer [quo/disclaimer
{:on-change #(tap> {:checked %}) {:on-change (fn [checked?]
:checked? existing-locked-amount} (tap> {:checked checked?})
(set-is-amount-locked checked?))
:checked? is-amount-locked?}
(i18n/label :t/dont-auto-recalculate-network {:network network-name-str})] (i18n/label :t/dont-auto-recalculate-network {:network network-name-str})]
[quo/bottom-actions [quo/bottom-actions
{:actions :one-action {:actions :one-action
:button-one-label (i18n/label :t/update) :button-one-label (i18n/label :t/update)
:button-one-props {:on-press #(do :button-one-props {:on-press (fn []
(let [limit-in-crypto (if crypto-currency? (if is-amount-locked?
input-amount (let [limit-in-crypto (if crypto-currency?
(number/remove-trailing-zeroes input-amount
(.toFixed (/ input-amount (number/remove-trailing-zeroes
conversion-rate) (.toFixed (/ input-amount
crypto-decimals)))] conversion-rate)
(when on-update crypto-decimals)))]
(on-update chain-id limit-in-crypto))) (rf/dispatch [:wallet/lock-from-amount chain-id limit-in-crypto]))
(rf/dispatch [:hide-bottom-sheet])) (rf/dispatch [:wallet/unlock-from-amount chain-id]))
(rf/dispatch [:hide-bottom-sheet]))
:disabled? (or (controlled-input/empty-value? input-state) :disabled? (or (controlled-input/empty-value? input-state)
(controlled-input/input-error input-state))}}] (controlled-input/input-error input-state))}}]
[quo/numbered-keyboard [quo/numbered-keyboard
@ -216,6 +222,7 @@
regex-pattern (str "^\\d*\\.?\\d{0," max-decimals "}$") regex-pattern (str "^\\d*\\.?\\d{0," max-decimals "}$")
regex (re-pattern regex-pattern)] regex (re-pattern regex-pattern)]
(when (re-matches regex new-text) (when (re-matches regex new-text)
(set-is-amount-locked true)
(set-input-state #(controlled-input/add-character % c))))) (set-input-state #(controlled-input/add-character % c)))))
:on-delete (fn [] :on-delete (fn []
(set-input-state controlled-input/delete-last)) (set-input-state controlled-input/delete-last))
@ -372,9 +379,7 @@
:on-long-press (fn [chain-id] :on-long-press (fn [chain-id]
(edit-amount (edit-amount
{:chain-id chain-id {:chain-id chain-id
:token-symbol token-symbol :token-symbol token-symbol}))
:on-update (fn [chain-id limit-in-crypto]
(rf/dispatch [:wallet/lock-from-amount chain-id limit-in-crypto]))}))
:receiver? false :receiver? false
:theme theme :theme theme
:loading-routes? loading-routes? :loading-routes? loading-routes?