Skip to content

Commit 228a938

Browse files
show toast when approve transaction finishes
1 parent 4da2d50 commit 228a938

File tree

3 files changed

+50
-8
lines changed

3 files changed

+50
-8
lines changed

src/status_im/contexts/wallet/signals.cljs

+11-7
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88
(rf/reg-event-fx
99
:wallet/pending-transaction-status-changed-received
1010
(fn [{:keys [db]} [{:keys [message]}]]
11-
(let [details (transforms/json->clj message)
12-
tx-hash (:hash details)
13-
status (case (:status details)
14-
"Success" :confirmed
15-
"Pending" :pending
16-
"Failed" :failed)]
17-
{:db (update-in db [:wallet :transactions tx-hash] assoc :status status)})))
11+
(let [details (transforms/json->clj message)
12+
tx-hash (:hash details)
13+
status (case (:status details)
14+
"Success" :confirmed
15+
"Pending" :pending
16+
"Failed" :failed)
17+
swap-approval-transaction-id (get-in db [:wallet :ui :swap :approval-transaction-id])
18+
swap-approval-transaction? (= swap-approval-transaction-id tx-hash)]
19+
(cond-> {:db (update-in db [:wallet :transactions tx-hash] assoc :status status)}
20+
swap-approval-transaction?
21+
(assoc :fx [[:dispatch [:wallet.swap/approve-transaction-update status]]])))))
1822

1923
(rf/reg-event-fx
2024
:wallet/signal-received

src/status_im/contexts/wallet/swap/events.cljs

+33
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
[status-im.contexts.wallet.sheets.network-selection.view :as network-selection]
88
[taoensso.timbre :as log]
99
[utils.address :as address]
10+
[utils.i18n :as i18n]
1011
[utils.number]))
1112

1213
(rf/reg-event-fx :wallet.swap/start
@@ -243,3 +244,35 @@
243244
:always (assoc-in [:wallet :ui :swap :transaction-ids] transaction-ids)
244245
approval-transaction? (assoc-in [:wallet :ui :swap :approval-transaction-id]
245246
(first transaction-ids)))})))
247+
248+
(rf/reg-event-fx :wallet.swap/approve-transaction-update
249+
(fn [{:keys [db]} [status]]
250+
(let [{:keys [amount asset-to-pay swap-proposal]} (get-in db [:wallet :ui :swap])
251+
provider-name (:bridge-name swap-proposal)
252+
token-symbol (:symbol asset-to-pay)
253+
current-viewing-account-address (get-in db
254+
[:wallet :current-viewing-account-address])
255+
account-name (get-in db
256+
[:wallet :accounts
257+
current-viewing-account-address :name])
258+
transaction-confirmed-or-failed? (#{:confirmed :failed} status)
259+
transaction-confirmed? (= status :confirmed)]
260+
(when transaction-confirmed-or-failed?
261+
(cond-> {:fx
262+
[[:dispatch
263+
[:toasts/upsert
264+
{:id :approve-transaction-update
265+
:type (if transaction-confirmed? :positive :negative)
266+
:text (if transaction-confirmed?
267+
(i18n/label :t/spending-cap-set
268+
{:amount amount
269+
:token-symbol token-symbol
270+
:provider-name provider-name
271+
:account-name account-name})
272+
(i18n/label :t/spending-cap-failed
273+
{:amount amount
274+
:token-symbol token-symbol
275+
:provider-name provider-name
276+
:account-name account-name}))}]]]}
277+
(not transaction-confirmed?)
278+
(assoc :db (update-in db [:wallet :ui :swap] dissoc :approval-transaction-id)))))))

translations/en.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,10 @@
11631163
"include": "Include",
11641164
"incoming": "Incoming",
11651165
"incoming-transaction": "Incoming transaction",
1166-
"incorrect-code": ["str", "Sorry the code was incorrect, please enter it again"],
1166+
"incorrect-code": [
1167+
"str",
1168+
"Sorry the code was incorrect, please enter it again"
1169+
],
11671170
"incorrect-private-key": "This is not the private key for this key pair",
11681171
"increase-gas": "Increase Gas",
11691172
"information-you-input-and-send": "Information you input and send",
@@ -2301,6 +2304,8 @@
23012304
"specify-symbol": "Specify a symbol",
23022305
"spender-contract": "Spender contract",
23032306
"spending-cap": "Spending cap",
2307+
"spending-cap-set": "Spending cap set: {{amount}} {{token-symbol}} for {{provider-name}} in {{account-name}}",
2308+
"spending-cap-failed": "Spending cap failed: {{amount}} {{token-symbol}} for {{provider-name}} in {{account-name}}",
23042309
"start-chat": "Start chat",
23052310
"start-conversation": "Start conversation",
23062311
"start-group-chat": "Start group chat",

0 commit comments

Comments
 (0)