|  | 
| 432 | 432 |             [:wallet.swap/set-sign-transactions-callback-fx | 
| 433 | 433 |              [:dispatch [:wallet/prepare-signatures-for-transactions :swap]]]]]}))) | 
| 434 | 434 | 
 | 
| 435 |  | -(defn transaction-approval-required? | 
| 436 |  | -  [transactions {:keys [swap-proposal approval-transaction-id]}] | 
| 437 |  | -  (let [approval-transaction (when approval-transaction-id | 
| 438 |  | -                               (get transactions approval-transaction-id)) | 
| 439 |  | -        already-approved?    (and approval-transaction | 
| 440 |  | -                                  (= (:status approval-transaction) | 
| 441 |  | -                                     :confirmed))] | 
| 442 |  | -    (and (:approval-required swap-proposal) | 
| 443 |  | -         (not already-approved?)))) | 
| 444 |  | - | 
| 445 | 435 | (rf/reg-event-fx | 
| 446 | 436 |  :wallet.swap/mark-as-pending | 
| 447 | 437 |  (fn [{:keys [db]} [transaction-id]] | 
|  | 
| 468 | 458 |                                   (-> amount-out | 
| 469 | 459 |                                       (number/hex->whole receive-token-decimals) | 
| 470 | 460 |                                       (money/to-fixed receive-token-decimals))) | 
| 471 |  | -         approval-required?     (transaction-approval-required? transactions swap)] | 
|  | 461 | +         approval-required?     (utils/transaction-approval-required? transactions swap)] | 
| 472 | 462 |      {:fx [[:dispatch | 
| 473 | 463 |             [:centralized-metrics/track | 
| 474 | 464 |              (if approval-required? | 
|  | 
| 496 | 486 |              [:dispatch [:wallet.swap/mark-as-pending (-> sent-transactions first :hash)]]) | 
| 497 | 487 |            (when-not approval-required? | 
| 498 | 488 |              ;; just end the whole transaction flow if no approval needed | 
| 499 |  | -             [:dispatch [:wallet.swap/end-transaction-flow]]) | 
| 500 |  | -           (when-not approval-required? | 
| 501 |  | -             [:dispatch-later | 
| 502 |  | -              {:ms       500 | 
| 503 |  | -               :dispatch [:toasts/upsert | 
| 504 |  | -                          {:id   :swap-transaction-pending | 
| 505 |  | -                           :icon :i/info | 
| 506 |  | -                           :type :neutral | 
| 507 |  | -                           :text (i18n/label :t/swapping-to | 
| 508 |  | -                                             {:pay-amount           amount | 
| 509 |  | -                                              :pay-token-symbol     token-id-from | 
| 510 |  | -                                              :receive-token-symbol token-id-to | 
| 511 |  | -                                              :receive-amount       receive-amount})}]}])]}))) | 
|  | 489 | +             [:dispatch [:wallet.swap/end-transaction-flow]])]}))) | 
| 512 | 490 | 
 | 
| 513 | 491 | (rf/reg-event-fx | 
| 514 |  | - :wallet.swap/transaction-failure | 
| 515 |  | - (fn [{:keys [db]} [{:keys [details] :as error}]] | 
|  | 492 | + :wallet.swap/track-transaction-execution-failed | 
|  | 493 | + (fn [{:keys [db]} [error]] | 
| 516 | 494 |    (let [transactions       (get-in db [:wallet :transactions]) | 
| 517 | 495 |          {:keys [asset-to-pay | 
| 518 | 496 |                  asset-to-receive | 
|  | 
| 521 | 499 |          swap-chain-id      (:chain-id network) | 
| 522 | 500 |          token-id-from      (:symbol asset-to-pay) | 
| 523 | 501 |          token-id-to        (:symbol asset-to-receive) | 
| 524 |  | -         approval-required? (transaction-approval-required? transactions swap)] | 
|  | 502 | +         approval-required? (utils/transaction-approval-required? transactions swap)] | 
| 525 | 503 |      {:fx [[:centralized-metrics/track | 
| 526 | 504 |             (if approval-required? | 
| 527 | 505 |               :metric/swap-approval-execution-failed | 
|  | 
| 530 | 508 |                      :error     error | 
| 531 | 509 |                      :pay_token token-id-from} | 
| 532 | 510 |               (not approval-required?) | 
| 533 |  | -              (assoc :receive_token token-id-to))] | 
| 534 |  | -           [:dispatch [:wallet.swap/end-transaction-flow]] | 
| 535 |  | -           [:dispatch | 
| 536 |  | -            [:toasts/upsert | 
| 537 |  | -             {:id   :send-transaction-error | 
| 538 |  | -              :type :negative | 
| 539 |  | -              :text (or details "An error occured")}]]]}))) | 
|  | 511 | +              (assoc :receive_token token-id-to))]]}))) | 
| 540 | 512 | 
 | 
| 541 | 513 | (rf/reg-event-fx | 
| 542 | 514 |  :wallet.swap/clean-up-transaction-flow | 
| 543 | 515 |  (fn [{:keys [db]}] | 
| 544 | 516 |    (let [transactions       (get-in db [:wallet :transactions]) | 
| 545 | 517 |          swap               (get-in db [:wallet :ui :swap]) | 
| 546 |  | -         approval-required? (transaction-approval-required? transactions swap)] | 
|  | 518 | +         approval-required? (utils/transaction-approval-required? transactions swap)] | 
| 547 | 519 |      {:db (update-in db [:wallet :ui] dissoc :swap) | 
| 548 | 520 |       :fx [[:dispatch | 
| 549 | 521 |             [:dismiss-modal | 
|  | 
| 577 | 549 |              [:dispatch | 
| 578 | 550 |               [:navigate-to-within-stack | 
| 579 | 551 |                [:screen/wallet.swap-select-asset-to-pay :screen/wallet.swap-select-account]]]])}))) | 
|  | 552 | + | 
|  | 553 | +(rf/reg-event-fx | 
|  | 554 | + :wallet.swap/show-transaction-notification | 
|  | 555 | + (fn [{:keys [db]} [{:keys [status send-details]}]] | 
|  | 556 | +   (let [transactions                                     (get-in db [:wallet :transactions]) | 
|  | 557 | +         {:keys [asset-to-pay asset-to-receive] :as swap} (get-in db [:wallet :ui :swap])] | 
|  | 558 | +     ;; show toast when approval is not required | 
|  | 559 | +     (when (and (= status :sent) | 
|  | 560 | +                (not (utils/transaction-approval-required? transactions swap))) | 
|  | 561 | +       {:fx [[:dispatch-later | 
|  | 562 | +              {:ms       500 | 
|  | 563 | +               :dispatch [:toasts/upsert | 
|  | 564 | +                          {:id   :swap-transaction-pending | 
|  | 565 | +                           :icon :i/info | 
|  | 566 | +                           :type :neutral | 
|  | 567 | +                           :text (i18n/label :t/swapping-to | 
|  | 568 | +                                             {:pay-amount           (-> send-details | 
|  | 569 | +                                                                        :from-amount | 
|  | 570 | +                                                                        (money/token->unit | 
|  | 571 | +                                                                         (:decimals asset-to-pay))) | 
|  | 572 | +                                              :receive-amount       (-> send-details | 
|  | 573 | +                                                                        :to-amount | 
|  | 574 | +                                                                        (money/token->unit | 
|  | 575 | +                                                                         (:decimals asset-to-receive))) | 
|  | 576 | +                                              :pay-token-symbol     (:from-asset send-details) | 
|  | 577 | +                                              :receive-token-symbol (:to-asset send-details)})}]}]]})))) | 
0 commit comments