Skip to content

Commit

Permalink
feat(wallet): connect backend to transaction progress page
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Son89 committed Jan 15, 2024
1 parent 3616825 commit c80c17a
Show file tree
Hide file tree
Showing 14 changed files with 142 additions and 42 deletions.
3 changes: 3 additions & 0 deletions src/legacy/status_im/ethereum/subscriptions.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@
"recent-history-ready" (recent-history-fetching-ended cofx event)
"fetching-history-error" (fetching-error cofx event)
"non-archival-node-detected" (non-archival-node-detected cofx event)
"pending-transaction-status-changed" {:fx [[:dispatch
[:wallet/pending-transaction-status-changed
event]]]}
"wallet-owned-collectibles-filtering-done" {:fx [[:dispatch
[:wallet/owned-collectibles-filtering-done
event]]]}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
(ns status-im.common.floating-button-page.floating-container.style
(:require [react-native.safe-area :as safe-area]))
(ns status-im.common.floating-button-page.floating-container.style)

(defn content-container
[blur? keyboard-shown?]
(let [margin-bottom (if keyboard-shown? 0 (safe-area/get-bottom))]
[blur? keyboard-shown? bottom-inset]
(let [margin-bottom (if keyboard-shown? 0 (or bottom-inset 0))]
(cond-> {:margin-top :auto
:overflow :hidden
:margin-bottom margin-bottom
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
child]])

(defn view-internal
[{:keys [theme on-layout keyboard-shown? blur?]} child]
[{:keys [theme on-layout keyboard-shown? blur? bottom-inset]} child]
[rn/view
{:style (style/content-container blur? keyboard-shown?)
{:style (style/content-container blur? keyboard-shown? bottom-inset)
:on-layout on-layout}
(if blur?
[blur-container child theme]
Expand Down
8 changes: 5 additions & 3 deletions src/status_im/common/floating_button_page/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@
:remove-listeners remove-listeners}))

(defn view
[{:keys [header footer customization-color gradient-cover?]} &
children]
[{:keys [header footer customization-color gradient-cover? footer-bottom-inset]
:or {footer-bottom-inset (safe-area/get-bottom)}}
& children]
(reagent/with-let [window-height (:height (rn/get-window))
footer-container-height (reagent/atom 0)
header-height (reagent/atom 0)
Expand Down Expand Up @@ -99,7 +100,8 @@
[floating-container/view
{:on-layout set-footer-container-height
:keyboard-shown? keyboard-shown?
:blur? show-background?}
:blur? show-background?
:bottom-inset footer-bottom-inset}
footer]]]])
(finally
(remove-listeners))))
29 changes: 21 additions & 8 deletions src/status_im/contexts/wallet/send/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
[utils.number]
[utils.re-frame :as rf]))

(rf/reg-event-fx :wallet/clean-send-data
(fn [{:keys [db]}]
{:db (dissoc db [:wallet :ui :send])}))

(rf/reg-event-fx :wallet/select-address-tab
(fn [{:keys [db]} [tab]]

{:db (assoc-in db [:wallet :ui :send :select-address-tab] tab)}))

(rf/reg-event-fx :wallet/suggested-routes-success
Expand Down Expand Up @@ -113,12 +116,23 @@
(rf/reg-event-fx :wallet/add-authorized-transaction
(fn [{:keys [db]} [transaction]]
(let [transaction-hashes (:hashes transaction)
chain-id (key (first transaction-hashes))
tx-id (first (val (first transaction-hashes)))
transaction-detes {:status :pending
:id (:id transaction)
:chain-id chain-id}]
{:db (assoc-in db [:wallet :transactions tx-id] transaction-detes)
tx-ids (flatten (map (fn [[_key value]] value) transaction-hashes))
tx-id-with-details (reduce-kv (fn [m1 chain-id v1]
(merge m1
(reduce
(fn [m2 tx-id]
(assoc m2
tx-id
{:status :pending
:id (:id transaction)
:chain-id chain-id}))
{}
v1)))
{}
transaction-hashes)]
{:db (-> db
(assoc-in [:wallet :transactions] tx-id-with-details)
(assoc-in [:wallet :ui :send :transaction-ids] tx-ids))
:fx [[:dispatch [:navigate-to :wallet-transaction-progress]]]})))

(defn- transaction-bridge
Expand Down Expand Up @@ -174,4 +188,3 @@
{:event :wallet/send-transaction
:error error
:params request-params}))}]})))

Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
:customization-color account-color
:on-auth-success #(rf/dispatch [:wallet/send-transaction %])
:auth-button-label (i18n/label :t/confirm)}]
:footer-bottom-inset 0
:gradient-cover? true
:customization-color (:color account)}
[rn/view
Expand Down
59 changes: 35 additions & 24 deletions src/status_im/contexts/wallet/send/transaction_progress/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
[quo.core :as quo]
[react-native.core :as rn]
[react-native.safe-area :as safe-area]
[reagent.core :as reagent]
[status-im.common.floating-button-page.view :as floating-button-page]
[status-im.common.resources :as resources]
[status-im.contexts.wallet.send.transaction-progress.style :as style]
Expand All @@ -13,35 +12,47 @@
(defn titles
[status]
(case status
:sending (i18n/label :t/sending-with-elipsis)
:pending (i18n/label :t/sending-with-elipsis)
:confirmed (i18n/label :t/transaction-confirmed)
:finalised (i18n/label :t/transacation-finalised)
""))

(defn combined-status-overview
[transaction-details]
(cond
(every? (fn [[_k v]] (= (:status v) :finalised)) transaction-details) :finalised
(some (fn [[_k v]] (= (:status v) :pending)) transaction-details) :pending
(some (fn [[_k v]] (= (:status v) :confirmed)) transaction-details) :confirmed
:else nil))

(defn view
[]
(let [current-address (rf/sub [:wallet/current-viewing-account-address])
leave-page (fn []
(rf/dispatch [:navigate-to :wallet-accounts current-address]))
status (reagent/atom :sending)
(rf/dispatch [:navigate-to :wallet-accounts current-address])
(rf/dispatch [:wallet/clean-send-data]))

{:keys [color]} (rf/sub [:wallet/current-viewing-account])]
[floating-button-page/view
{:header [quo/page-nav
{:type :no-title
:background :blur
:icon-name :i/close
:margin-top (safe-area/get-top)
:on-press leave-page
:accessibility-label :top-bar}]
:footer [quo/button
{:customization-color color
:on-press leave-page}
(i18n/label :t/done)]
:customization-color color
:gradient-cover? true}
[rn/view {:style style/content-container}
[rn/image
{:source (resources/get-image :transaction-progress)
:style {:margin-bottom 12}}]
[quo/standard-title
{:title (titles @status)}]]]))
(fn []
(let [transaction-details (rf/sub [:wallet/send-transaction-progress])]
[floating-button-page/view
{:header [quo/page-nav
{:type :no-title
:background :blur
:icon-name :i/close
:margin-top (safe-area/get-top)
:on-press leave-page
:accessibility-label :top-bar}]
:footer [quo/button
{:customization-color color
:on-press leave-page}
(i18n/label :t/done)]
:footer-bottom-inset 0
:customization-color color
:gradient-cover? true}
[rn/view {:style style/content-container}
[rn/image
{:source (resources/get-image :transaction-progress)
:style {:margin-bottom 12}}]
[quo/standard-title
{:title (titles (combined-status-overview transaction-details))}]]]))))
10 changes: 10 additions & 0 deletions src/status_im/contexts/wallet/signals.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(ns status-im.contexts.wallet.signals
(:require [utils.re-frame :as rf]))

(rf/reg-event-fx
:wallet/pending-transaction-status-changed
(fn [{:keys [db]} [{:keys [message]}]]
(let [details (js->clj (js/JSON.parse message) :keywordize-keys true)
tx-hash (:hash details)]
{:db (-> db (update-in [:wallet :transactions tx-hash] assoc :status :confirmed :blocks 1))})))

1 change: 1 addition & 0 deletions src/status_im/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
[status-im.contexts.profile.push-notifications.events :as notifications]
[status-im.contexts.shell.jump-to.state :as shell.state]
[status-im.contexts.shell.jump-to.utils :as shell.utils]
status-im.contexts.wallet.signals
status-im.events
status-im.navigation.core
[status-im.setup.dev :as dev]
Expand Down
1 change: 1 addition & 0 deletions src/status_im/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
status-im.contexts.syncing.events
status-im.contexts.wallet.events
status-im.contexts.wallet.send.events
status-im.contexts.wallet.signals
[status-im.db :as db]
[utils.re-frame :as rf]))

Expand Down
1 change: 0 additions & 1 deletion src/status_im/navigation/screens.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@
:component wallet-transaction-confirmation/view}

{:name :wallet-transaction-progress
:options {:insets {:bottom? true}}
:component wallet-transaction-progress/view}

{:name :scan-address
Expand Down
14 changes: 14 additions & 0 deletions src/status_im/subs/wallet/send.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,17 @@
:wallet/wallet-send
:<- [:wallet/ui]
:-> :send)

(rf/reg-sub
:wallet/send-transaction-ids
:<- [:wallet/wallet-send]
:-> :transaction-ids)

(rf/reg-sub
:wallet/send-transaction-progress
:<- [:wallet/send-transaction-ids]
:<- [:wallet/transactions]
(fn [[tx-ids transactions]]
(let [send-tx-ids (set (keys transactions))]
(select-keys transactions
(for [k tx-ids :when (send-tx-ids k)] k)))))
41 changes: 41 additions & 0 deletions src/status_im/subs/wallet/send_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,44 @@
(testing "returns active tab for selecting address"
(swap! rf-db/app-db assoc-in [:wallet :ui :send :select-address-tab] :tabs/recent)
(is (= :tabs/recent (rf/sub [sub-name])))))

(h/deftest-sub :wallet/send-transaction-ids
[sub-name]
(testing "returns the transaction ids attached the last send flow"
(swap! rf-db/app-db assoc-in [:wallet :ui :send :transaction-ids] ["0x123" "0x321"])
(is (= ["0x123" "0x321"] (rf/sub [sub-name])))))

(h/deftest-sub :wallet/send-transaction-progress
[sub-name]
(testing "returns transaction data for a transaction with multiple transactions"
(swap! rf-db/app-db assoc-in
[:wallet :transactions]
{"0x123" {:status :pending
:id 240
:chain-id 5}
"0x321" {:status :pending
:id 240
:chain-id 1}})
(swap! rf-db/app-db assoc-in [:wallet :ui :send :transaction-ids] ["0x123" "0x321"])
(is (= {"0x123" {:status :pending
:id 240
:chain-id 5}
"0x321" {:status :pending
:id 240
:chain-id 1}}
(rf/sub [sub-name]))))

(testing "returns transaction data for a transaction with a single transaction"
(swap! rf-db/app-db assoc-in
[:wallet :transactions]
{"0x123" {:status :pending
:id 100
:chain-id 5}
"0x321" {:status :pending
:id 240
:chain-id 1}})
(swap! rf-db/app-db assoc-in [:wallet :ui :send :transaction-ids] ["0x123"])
(is (= {"0x123" {:status :pending
:id 100
:chain-id 5}}
(rf/sub [sub-name])))))
5 changes: 5 additions & 0 deletions src/status_im/subs/wallet/wallet.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,8 @@
(map (fn [{:keys [color] :as account}]
(assoc account :customization-color color))
accounts)))

(rf/reg-sub
:wallet/transactions
:<- [:wallet]
:-> :transactions)

0 comments on commit c80c17a

Please sign in to comment.