Skip to content

Commit

Permalink
more polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
briansztamfater committed Apr 2, 2024
1 parent 213c6fe commit e37c2ef
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
:total-balance 100
:market-values-per-currency {:usd {:price 10}}}
:wallet/wallet-disabled-from-chain-ids []
:wallet/wallet-from-values-by-chain {1 (money/bignumber "1")}
:wallet/wallet-to-values-by-chain {1 (money/bignumber "1")}})
:wallet/wallet-from-values-by-chain {1 (money/bignumber "250")}
:wallet/wallet-to-values-by-chain {1 (money/bignumber "250")}})

(h/describe "Send > input amount screen"
(h/setup-restorable-re-frame)
Expand Down
11 changes: 3 additions & 8 deletions src/status_im/contexts/wallet/send/routes/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
[status-im.contexts.wallet.common.utils :as utils]
[status-im.contexts.wallet.send.routes.style :as style]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
[utils.re-frame :as rf]
[utils.vector :as vector-utils]))

(def ^:private network-priority
{:ethereum 1
Expand Down Expand Up @@ -45,19 +46,13 @@
first)
(count data))))

(defn- insert-item-at
[data item index]
(let [before (take index data)
after (drop index data)]
(vec (concat before [item] after))))

(defn- add-disabled-networks
[data disabled-from-networks loading-suggested-routes?]
(let [sorted-networks (sort-by (comp network-priority utils/id->network) disabled-from-networks)]
(reduce (fn [acc-data chain-id]
(let [index (find-insertion-index acc-data chain-id loading-suggested-routes?)
item {:status :disabled :chain-id chain-id :network (utils/id->network chain-id)}]
(insert-item-at acc-data item index)))
(vector-utils/insert-element-at acc-data item index)))
data
sorted-networks)))

Expand Down
7 changes: 7 additions & 0 deletions src/utils/vector.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(ns utils.vector)

(defn insert-element-at
[data element index]
(let [before (take index data)
after (drop index data)]
(vec (concat before [element] after))))
17 changes: 17 additions & 0 deletions src/utils/vector_test.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(ns utils.vector-test
(:require
[cljs.test :refer-macros [deftest is testing]]
[utils.vector :as vector]))

(deftest test-insert-element-at
(testing "Inserting into an empty vector"
(is (= [42] (vector/insert-element-at [] 42 0))))

(testing "Inserting at the beginning of a vector"
(is (= [42 1 2 3] (vector/insert-element-at [1 2 3] 42 0))))

(testing "Inserting in the middle of a vector"
(is (= [1 42 2 3] (vector/insert-element-at [1 2 3] 42 1))))

(testing "Inserting at the end of a vector"
(is (= [1 2 3 42] (vector/insert-element-at [1 2 3] 42 3)))))

0 comments on commit e37c2ef

Please sign in to comment.