Compare commits
14
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
edd50dfe18 | ||
|
|
d5fa11a918 | ||
|
|
6e5214da72 | ||
|
|
9e2f590e3c | ||
|
|
23d3a2db2a | ||
|
|
a85ca5bd3d | ||
|
|
0f036ca9c4 | ||
|
|
c19128e8b1 | ||
|
|
8d615801d1 | ||
|
|
4f6e1897fe | ||
|
|
93b5f8d180 | ||
|
|
0e607dc293 | ||
|
|
9ced0e4131 | ||
|
|
55ee800e18 |
+1
-1
@@ -66,7 +66,7 @@
|
||||
"react-native-shake": "^3.3.1",
|
||||
"react-native-share": "10.0.2",
|
||||
"react-native-static-safe-area-insets": "^2.2.0",
|
||||
"react-native-status-keycard": "git+https://github.com/status-im/react-native-status-keycard.git#refs/tags/v2.6.3",
|
||||
"react-native-status-keycard": "git+https://github.com/status-im/react-native-status-keycard.git#refs/tags/v2.6.4",
|
||||
"react-native-svg": "13.10.0",
|
||||
"react-native-webview": "13.6.3",
|
||||
"react-syntax-highlighter": "^15.5.0"
|
||||
|
||||
@@ -71,6 +71,10 @@
|
||||
[callback]
|
||||
(.addListener ^js event-emitter "keyCardOnDisconnected" callback))
|
||||
|
||||
(defn on-card-new-pairing
|
||||
[callback]
|
||||
(.addListener ^js event-emitter "keyCardNewPairing" callback))
|
||||
|
||||
(defn on-nfc-user-cancelled
|
||||
[callback]
|
||||
(.addListener ^js event-emitter "keyCardOnNFCUserCancelled" callback))
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
auth-method (rf/sub [:auth-method])
|
||||
biometric-auth? (= auth-method constants/auth-method-biometric)
|
||||
on-complete-callback (rn/use-callback
|
||||
(fn [reset-slider-fn]
|
||||
(js/setTimeout #(reset-slider-fn false) 500)
|
||||
(fn []
|
||||
(rf/dispatch [:standard-auth/authorize
|
||||
{:auth-button-icon-left auth-button-icon-left
|
||||
:theme theme
|
||||
@@ -26,13 +25,19 @@
|
||||
:on-auth-fail on-auth-fail
|
||||
:auth-button-label auth-button-label}]))
|
||||
(vec (conj dependencies on-auth-success on-auth-fail)))
|
||||
on-complete (or on-complete on-complete-callback)
|
||||
on-slider-complete (rn/use-callback
|
||||
(fn [reset-slider-fn]
|
||||
(js/setTimeout #(reset-slider-fn false) 500)
|
||||
(if (fn? on-complete)
|
||||
(on-complete)
|
||||
(on-complete-callback)))
|
||||
[on-complete on-complete-callback])
|
||||
biometric-type (rf/sub [:biometrics/supported-type])]
|
||||
[quo/slide-button
|
||||
{:container-style container-style
|
||||
:size size
|
||||
:customization-color customization-color
|
||||
:on-complete on-complete
|
||||
:on-complete on-slider-complete
|
||||
:track-icon (if biometric-auth?
|
||||
(biometric/get-icon-by-type biometric-type)
|
||||
:password)
|
||||
|
||||
@@ -53,7 +53,13 @@
|
||||
(conj (navigation-event (name view-id)))
|
||||
|
||||
(= :screen/onboarding.syncing-results view-id)
|
||||
(conj (key-value-event "onboarding-completed")))))
|
||||
(conj (key-value-event "onboarding-completed"))
|
||||
|
||||
(= :screen/keycard.migrate.success view-id)
|
||||
(conj (key-value-event "keycard-migration-succeeded"))
|
||||
|
||||
(= :screen/keycard.migrate.fail view-id)
|
||||
(conj (key-value-event "keycard-migration-failed")))))
|
||||
|
||||
(defn navigated-to-collectibles-tab-event
|
||||
[location]
|
||||
|
||||
@@ -280,17 +280,31 @@
|
||||
{:style (merge style/container {:margin-horizontal 0})}
|
||||
[chat-item item]])
|
||||
|
||||
(defn- bottom-sheet-options
|
||||
[chat-id chat-type]
|
||||
(cond-> {:content (fn []
|
||||
(let [chat (rf/sub [:chats/chat-by-id chat-id])]
|
||||
[actions/chat-actions chat false]))}
|
||||
(= chat-type constants/one-to-one-chat-type)
|
||||
(assoc :selected-item
|
||||
(fn []
|
||||
(let [chat (rf/sub [:chats/chat-by-id chat-id])]
|
||||
[chat-user chat])))))
|
||||
|
||||
(defn chat-list-item
|
||||
[{:keys [chat-id chat-type]
|
||||
:as item} theme]
|
||||
(let [customization-color (rf/sub [:profile/customization-color])]
|
||||
[{:keys [chat-id]}]
|
||||
(let [{:keys [chat-type]
|
||||
:as chat} (rf/sub [:chats/chat-by-id chat-id])
|
||||
customization-color (rf/sub [:profile/customization-color])
|
||||
theme (quo.theme/use-theme)
|
||||
on-long-press (rn/use-callback
|
||||
(fn []
|
||||
(rf/dispatch [:show-bottom-sheet
|
||||
(bottom-sheet-options chat-id chat-type)]))
|
||||
[chat-id chat-type])]
|
||||
[rn/touchable-highlight
|
||||
{:style style/container
|
||||
:on-press (open-chat chat-id)
|
||||
:underlay-color (colors/resolve-color customization-color theme 5)
|
||||
:on-long-press #(rf/dispatch [:show-bottom-sheet
|
||||
(cond-> {:content (fn [] [actions/chat-actions item false])}
|
||||
(= chat-type constants/one-to-one-chat-type)
|
||||
(assoc :selected-item
|
||||
(fn [] [chat-user item])))])}
|
||||
[chat-item item]]))
|
||||
:on-long-press on-long-press}
|
||||
[chat-item chat]]))
|
||||
|
||||
@@ -23,12 +23,10 @@
|
||||
[_ index]
|
||||
#js {:length 56 :offset (* 56 index) :index index})
|
||||
|
||||
(defn filter-and-sort-items-by-tab
|
||||
(defn filter-by-tab
|
||||
[tab items]
|
||||
(let [k (if (= tab :tab/groups) :group-chat :chat-id)]
|
||||
(->> items
|
||||
(filter k)
|
||||
(sort-by :timestamp >))))
|
||||
(filter k items)))
|
||||
|
||||
(defn empty-state-content
|
||||
[theme]
|
||||
@@ -45,32 +43,43 @@
|
||||
:description (i18n/label :t/no-messages-description)
|
||||
:image (resources/get-themed-image :cat-in-box theme)}})
|
||||
|
||||
(defn on-end-reached
|
||||
[]
|
||||
(re-frame/dispatch [:chat/show-more-chats]))
|
||||
|
||||
(defn chat-key-fn
|
||||
[chat]
|
||||
(or (:chat-id chat) (:public-key chat) (:id chat)))
|
||||
|
||||
(defn chats
|
||||
[{:keys [theme selected-tab set-scroll-ref scroll-shared-value]}]
|
||||
(let [unfiltered-items (rf/sub [:chats/chats-stack-items])
|
||||
items (filter-and-sort-items-by-tab selected-tab unfiltered-items)]
|
||||
items (filter-by-tab selected-tab unfiltered-items)
|
||||
on-scroll (rn/use-callback
|
||||
(fn [event]
|
||||
(common.banner/set-scroll-shared-value
|
||||
{:scroll-input (oops/oget event
|
||||
"nativeEvent.contentOffset.y")
|
||||
:shared-value scroll-shared-value})))]
|
||||
(if (empty? items)
|
||||
[common.empty-state/view
|
||||
{:selected-tab selected-tab
|
||||
:tab->content (empty-state-content theme)}]
|
||||
[reanimated/flat-list
|
||||
{:ref set-scroll-ref
|
||||
:key-fn #(or (:chat-id %) (:public-key %) (:id %))
|
||||
:key-fn chat-key-fn
|
||||
:content-inset-adjustment-behavior :never
|
||||
:header [common.header-spacing/view]
|
||||
:get-item-layout get-item-layout
|
||||
:on-end-reached #(re-frame/dispatch [:chat/show-more-chats])
|
||||
:on-end-reached on-end-reached
|
||||
:keyboard-should-persist-taps :always
|
||||
:data items
|
||||
:render-fn (fn [item]
|
||||
(chat-list-item/chat-list-item item theme))
|
||||
:render-fn chat-list-item/chat-list-item
|
||||
:scroll-event-throttle 8
|
||||
:content-container-style {:padding-bottom
|
||||
shell.constants/floating-shell-button-height
|
||||
:padding-top 8}
|
||||
:on-scroll #(common.banner/set-scroll-shared-value
|
||||
{:scroll-input (oops/oget % "nativeEvent.contentOffset.y")
|
||||
:shared-value scroll-shared-value})}])))
|
||||
:on-scroll on-scroll}])))
|
||||
|
||||
(defn contact-item-render
|
||||
[{:keys [public-key] :as item} theme]
|
||||
|
||||
@@ -10,72 +10,73 @@
|
||||
[status-im.contexts.communities.actions.community-rules.view :as community-rules]
|
||||
[status-im.contexts.communities.actions.permissions-sheet.view :as permissions-sheet]
|
||||
[status-im.contexts.communities.utils :as communities.utils]
|
||||
[status-im.feature-flags :as ff]
|
||||
[utils.i18n :as i18n]
|
||||
[utils.re-frame :as rf]))
|
||||
|
||||
(defn view
|
||||
[]
|
||||
(let [theme (quo.theme/use-theme)
|
||||
{id :community-id} (rf/sub [:get-screen-params])
|
||||
(let [theme (quo.theme/use-theme)
|
||||
{id :community-id} (rf/sub [:get-screen-params])
|
||||
{:keys [name color images joined]} (rf/sub [:communities/community id])
|
||||
has-permissions? (rf/sub [:communities/has-permissions? id])
|
||||
airdrop-account (rf/sub [:communities/airdrop-account id])
|
||||
revealed-accounts (rf/sub [:communities/accounts-to-reveal id])
|
||||
revealed-accounts-count (count revealed-accounts)
|
||||
wallet-accounts-count (count (rf/sub [:wallet/operable-accounts]))
|
||||
addresses-shared-text (if (= revealed-accounts-count wallet-accounts-count)
|
||||
(i18n/label :t/all-addresses)
|
||||
(i18n/label-pluralize
|
||||
revealed-accounts-count
|
||||
:t/address-count))
|
||||
{:keys [highest-permission-role]} (rf/sub [:community/token-gated-overview id])
|
||||
highest-role-text (i18n/label (communities.utils/role->translation-key
|
||||
highest-permission-role
|
||||
:t/member))
|
||||
can-edit-addresses? (rf/sub [:communities/can-edit-shared-addresses? id])
|
||||
navigate-back (rn/use-callback #(rf/dispatch [:navigate-back]))
|
||||
|
||||
show-addresses-for-permissions
|
||||
(rn/use-callback
|
||||
(fn []
|
||||
(if can-edit-addresses?
|
||||
(rf/dispatch [:open-modal :addresses-for-permissions {:community-id id}])
|
||||
(rf/dispatch [:show-bottom-sheet
|
||||
{:community-id id
|
||||
:content (fn [] [addresses-for-permissions/view])}])))
|
||||
[can-edit-addresses?])
|
||||
|
||||
show-airdrop-addresses
|
||||
(rn/use-callback
|
||||
(fn []
|
||||
(if can-edit-addresses?
|
||||
(rf/dispatch [:open-modal :address-for-airdrop {:community-id id}])
|
||||
(rf/dispatch [:show-bottom-sheet
|
||||
{:community-id id
|
||||
:content (fn [] [airdrop-addresses/view])}])))
|
||||
[can-edit-addresses?])
|
||||
|
||||
confirm-choices
|
||||
(rn/use-callback
|
||||
(fn []
|
||||
(rf/dispatch
|
||||
[:standard-auth/authorize
|
||||
{:auth-button-label (if can-edit-addresses?
|
||||
(i18n/label :t/edit-shared-addresses)
|
||||
(i18n/label :t/request-to-join))
|
||||
:on-auth-success (fn [password]
|
||||
(rf/dispatch
|
||||
[:communities/request-to-join-with-addresses
|
||||
{:community-id id
|
||||
:password password}]))}])
|
||||
(navigate-back))
|
||||
[can-edit-addresses?])
|
||||
|
||||
open-permission-sheet
|
||||
(rn/use-callback (fn []
|
||||
(rf/dispatch [:show-bottom-sheet
|
||||
{:content (fn [] [permissions-sheet/view id])}]))
|
||||
[id])]
|
||||
has-permissions? (rf/sub [:communities/has-permissions? id])
|
||||
airdrop-account (rf/sub [:communities/airdrop-account id])
|
||||
revealed-accounts (rf/sub [:communities/accounts-to-reveal id])
|
||||
revealed-accounts-count (count revealed-accounts)
|
||||
wallet-accounts-count (count (rf/sub [:wallet/operable-accounts]))
|
||||
addresses-shared-text (if (= revealed-accounts-count wallet-accounts-count)
|
||||
(i18n/label :t/all-addresses)
|
||||
(i18n/label-pluralize
|
||||
revealed-accounts-count
|
||||
:t/address-count))
|
||||
{:keys [highest-permission-role]} (rf/sub [:community/token-gated-overview id])
|
||||
highest-role-text (i18n/label (communities.utils/role->translation-key
|
||||
highest-permission-role
|
||||
:t/member))
|
||||
can-edit-addresses? (rf/sub [:communities/can-edit-shared-addresses? id])
|
||||
navigate-back (rn/use-callback #(rf/dispatch [:navigate-back]))
|
||||
show-addresses-for-permissions (rn/use-callback
|
||||
(fn []
|
||||
(if can-edit-addresses?
|
||||
(rf/dispatch [:open-modal :addresses-for-permissions
|
||||
{:community-id id}])
|
||||
(rf/dispatch [:show-bottom-sheet
|
||||
{:community-id id
|
||||
:content
|
||||
addresses-for-permissions/view}])))
|
||||
[can-edit-addresses?])
|
||||
show-airdrop-addresses (rn/use-callback
|
||||
(fn []
|
||||
(if can-edit-addresses?
|
||||
(rf/dispatch [:open-modal :address-for-airdrop
|
||||
{:community-id id}])
|
||||
(rf/dispatch [:show-bottom-sheet
|
||||
{:community-id id
|
||||
:content airdrop-addresses/view}])))
|
||||
[can-edit-addresses?])
|
||||
confirm-choices (rn/use-callback
|
||||
(fn []
|
||||
(rf/dispatch
|
||||
[:standard-auth/authorize
|
||||
{:auth-button-label (if can-edit-addresses?
|
||||
(i18n/label
|
||||
:t/edit-shared-addresses)
|
||||
(i18n/label :t/request-to-join))
|
||||
:on-auth-success
|
||||
(fn [password]
|
||||
(rf/dispatch
|
||||
[:communities/request-to-join-with-addresses
|
||||
{:community-id id
|
||||
:password password}]))}])
|
||||
(navigate-back))
|
||||
[can-edit-addresses?])
|
||||
open-permission-sheet (rn/use-callback
|
||||
(fn []
|
||||
(rf/dispatch
|
||||
[:show-bottom-sheet
|
||||
{:content (fn []
|
||||
[permissions-sheet/view id])}]))
|
||||
[id])]
|
||||
(rn/use-mount
|
||||
(fn []
|
||||
(rf/dispatch [:communities/initialize-permission-addresses id])))
|
||||
@@ -86,7 +87,7 @@
|
||||
:icon-name :i/close
|
||||
:on-press navigate-back
|
||||
:accessibility-label :back-button}
|
||||
has-permissions?
|
||||
(and has-permissions? (ff/enabled? ::ff/community.view-token-requirements))
|
||||
(assoc :right-side
|
||||
[{:icon-left :i/unlocked
|
||||
:on-press open-permission-sheet
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
[status-im.constants :as constants]
|
||||
[status-im.contexts.communities.actions.addresses-for-permissions.style :as style]
|
||||
[status-im.contexts.communities.actions.permissions-sheet.view :as permissions-sheet]
|
||||
[status-im.feature-flags :as ff]
|
||||
[utils.i18n :as i18n]
|
||||
[utils.money :as money]
|
||||
[utils.re-frame :as rf]))
|
||||
@@ -122,23 +123,23 @@
|
||||
(defn- page-top
|
||||
[{:keys [community-id identical-choices? can-edit-addresses?]}]
|
||||
(let [{:keys [name logo color]} (rf/sub [:communities/for-context-tag community-id])
|
||||
has-permissions? (rf/sub [:communities/has-permissions? community-id])
|
||||
confirm-discard-changes
|
||||
(rn/use-callback
|
||||
(fn []
|
||||
(if identical-choices?
|
||||
(rf/dispatch [:dismiss-modal :addresses-for-permissions])
|
||||
(rf/dispatch [:show-bottom-sheet
|
||||
{:content (fn [] [confirm-discard-drawer
|
||||
community-id])}])))
|
||||
[identical-choices? community-id])
|
||||
|
||||
open-permission-sheet
|
||||
(rn/use-callback (fn []
|
||||
(rf/dispatch [:show-bottom-sheet
|
||||
{:content (fn [] [permissions-sheet/view
|
||||
community-id])}]))
|
||||
[community-id])]
|
||||
has-permissions? (rf/sub [:communities/has-permissions? community-id])
|
||||
confirm-discard-changes (rn/use-callback
|
||||
(fn []
|
||||
(if identical-choices?
|
||||
(rf/dispatch [:dismiss-modal :addresses-for-permissions])
|
||||
(rf/dispatch [:show-bottom-sheet
|
||||
{:content (fn []
|
||||
[confirm-discard-drawer
|
||||
community-id])}])))
|
||||
[identical-choices? community-id])
|
||||
open-permission-sheet (rn/use-callback
|
||||
(fn []
|
||||
(rf/dispatch [:show-bottom-sheet
|
||||
{:content (fn []
|
||||
[permissions-sheet/view
|
||||
community-id])}]))
|
||||
[community-id])]
|
||||
[:<>
|
||||
(when can-edit-addresses?
|
||||
[quo/page-nav
|
||||
@@ -161,7 +162,7 @@
|
||||
:community-name name
|
||||
:community-logo logo
|
||||
:customization-color color}
|
||||
has-permissions?
|
||||
(and has-permissions? (ff/enabled? ::ff/community.view-token-requirements))
|
||||
(assoc :button-icon :i/info
|
||||
:button-type :grey
|
||||
:on-button-press open-permission-sheet))])]))
|
||||
|
||||
@@ -40,7 +40,8 @@
|
||||
:right-icon :i/chevron-right
|
||||
:accessibility-label :view-token-gating
|
||||
:on-press #(rf/dispatch [:show-bottom-sheet
|
||||
{:content (fn [] [permissions-sheet/view id])
|
||||
{:content (fn []
|
||||
[permissions-sheet/view id])
|
||||
:padding-bottom-override 16}])
|
||||
:label (i18n/label :t/view-token-gating)})
|
||||
|
||||
@@ -146,7 +147,9 @@
|
||||
[{:keys [id join-pending? spectated? token-gated? intro-message test-networks-enabled?]}]
|
||||
(let [common [(show-qr id) (share-community id)]
|
||||
specific (cond
|
||||
(and token-gated? (not test-networks-enabled?))
|
||||
(and token-gated?
|
||||
(not test-networks-enabled?)
|
||||
(ff/enabled? ::ff/community.view-token-requirements))
|
||||
[(invite-contacts id) (view-token-gating id)]
|
||||
|
||||
token-gated?
|
||||
@@ -172,7 +175,8 @@
|
||||
[{:keys [id token-gated? muted? muted-till color intro-message]}]
|
||||
[[(view-members id)
|
||||
(view-rules id intro-message)
|
||||
(when token-gated? (view-token-gating id))
|
||||
(when (and token-gated? (ff/enabled? ::ff/community.view-token-requirements))
|
||||
(view-token-gating id))
|
||||
(when (ff/enabled? ::ff/community.edit-account-selection)
|
||||
(edit-shared-addresses id))
|
||||
(mark-as-read id)
|
||||
|
||||
@@ -30,7 +30,8 @@
|
||||
{:keys [color name images]} (rf/sub [:communities/community id])
|
||||
keycard? (rf/sub [:keycard/keycard-profile?])
|
||||
keycard-feature-unavailable (rn/use-callback
|
||||
#(rf/dispatch [:keycard/feature-unavailable-show]))]
|
||||
#(rf/dispatch [:keycard/feature-unavailable-show
|
||||
{:feature-name :community.request-to-join}]))]
|
||||
[rn/safe-area-view {:flex 1}
|
||||
[gesture/scroll-view {:style style/container}
|
||||
[rn/view style/page-container
|
||||
|
||||
@@ -147,7 +147,8 @@
|
||||
[:show-bottom-sheet {:content token-gated-communities-info}])
|
||||
keycard? (rf/sub [:keycard/keycard-profile?])
|
||||
keycard-feature-unavailable (rn/use-callback
|
||||
#(rf/dispatch [:keycard/feature-unavailable-show]))]
|
||||
#(rf/dispatch [:keycard/feature-unavailable-show
|
||||
{:feature-name :community.request-to-join}]))]
|
||||
|
||||
(cond
|
||||
networks-not-supported?
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
[status-im.contexts.keycard.utils :as keycard.utils]
|
||||
[status-im.contexts.profile.config :as profile.config]
|
||||
[utils.hex :as hex]
|
||||
[utils.re-frame :as rf]))
|
||||
[utils.re-frame :as rf]
|
||||
[utils.transforms :as transforms]))
|
||||
|
||||
(defonce ^:private active-listeners (atom []))
|
||||
|
||||
@@ -24,6 +25,7 @@
|
||||
(reset! active-listeners
|
||||
[(keycard/on-card-connected #(rf/dispatch [:keycard/on-card-connected]))
|
||||
(keycard/on-card-disconnected #(rf/dispatch [:keycard/on-card-disconnected]))
|
||||
(keycard/on-card-new-pairing #(rf/dispatch [:keycard/on-card-new-pairing (transforms/js->clj %)]))
|
||||
(when platform/ios?
|
||||
(keycard/on-nfc-user-cancelled #(rf/dispatch [:keycard.ios/on-nfc-user-cancelled])))
|
||||
(when platform/ios?
|
||||
|
||||
@@ -25,21 +25,22 @@
|
||||
:fx [(when-let [event (get-in db [:keycard :on-card-disconnected-event-vector])]
|
||||
[:dispatch event])]}))
|
||||
|
||||
(rf/reg-event-fx :keycard/on-card-new-pairing
|
||||
(fn [{:keys [db]} [{:keys [pairing instanceUID]}]]
|
||||
(when (and instanceUID pairing)
|
||||
(let [pairings (get-in db [:keycard :pairings])
|
||||
new-pairings (assoc pairings
|
||||
instanceUID
|
||||
{:pairing pairing
|
||||
:paired-on (utils.datetime/timestamp)})]
|
||||
{:db (assoc-in db [:keycard :pairings] new-pairings)
|
||||
:keycard/persist-pairings new-pairings}))))
|
||||
|
||||
(rf/reg-event-fx :keycard/on-retrieve-pairings-success
|
||||
(fn [{:keys [db]} [pairings]]
|
||||
{:db (assoc-in db [:keycard :pairings] pairings)
|
||||
:fx [[:effects.keycard/set-pairing-to-keycard pairings]]}))
|
||||
|
||||
(rf/reg-event-fx :keycard/update-pairings
|
||||
(fn [{:keys [db]} [instance-uid pairing]]
|
||||
(let [pairings (get-in db [:keycard :pairings])
|
||||
new-pairings (assoc pairings
|
||||
instance-uid
|
||||
{:pairing pairing
|
||||
:paired-on (utils.datetime/timestamp)})]
|
||||
{:db (assoc-in db [:keycard :pairings] new-pairings)
|
||||
:keycard/persist-pairings new-pairings})))
|
||||
|
||||
(rf/reg-event-fx :keycard/on-action-with-pin-error
|
||||
(fn [{:keys [db]} [error]]
|
||||
(let [tag-was-lost? (keycard.utils/tag-lost? (:error error))
|
||||
@@ -126,10 +127,8 @@
|
||||
(rf/reg-event-fx :keycard/get-application-info
|
||||
(fn [_ [{:keys [key-uid on-success on-error]}]]
|
||||
{:effects.keycard/get-application-info
|
||||
{:on-success (fn [{:keys [instance-uid new-pairing] :as app-info}]
|
||||
{:on-success (fn [app-info]
|
||||
(rf/dispatch [:keycard/update-application-info app-info])
|
||||
(when (and instance-uid new-pairing)
|
||||
(rf/dispatch [:keycard/update-pairings instance-uid new-pairing]))
|
||||
(if-let [error (keycard.utils/validate-application-info key-uid app-info)]
|
||||
(if on-error
|
||||
(on-error error)
|
||||
|
||||
@@ -1,12 +1,27 @@
|
||||
(ns status-im.contexts.keycard.feature-unavailable.events
|
||||
(:require
|
||||
[status-im.constants :as constants]
|
||||
[status-im.contexts.keycard.feature-unavailable.view :as feature-unavailable]
|
||||
[utils.re-frame :as rf]))
|
||||
|
||||
(rf/reg-event-fx
|
||||
:keycard/feature-unavailable-upvote
|
||||
(fn [_ [{:keys [feature-name]}]]
|
||||
{:fx [[:dispatch [:open-url constants/mobile-upvote-link]]
|
||||
[:dispatch
|
||||
[:centralized-metrics/track
|
||||
:metric/feature-unavailable-upvote
|
||||
{:feature-name feature-name}]]]}))
|
||||
|
||||
(rf/reg-event-fx
|
||||
:keycard/feature-unavailable-show
|
||||
(fn [_ [options]]
|
||||
(fn [_ [{:keys [feature-name theme] :as options}]]
|
||||
{:fx [[:dispatch
|
||||
[:show-bottom-sheet
|
||||
{:theme (:theme options)
|
||||
:content feature-unavailable/view}]]]}))
|
||||
{:theme theme
|
||||
:content (fn []
|
||||
(feature-unavailable/view options))}]]
|
||||
[:dispatch
|
||||
[:centralized-metrics/track
|
||||
:metric/feature-unavailable
|
||||
{:feature-name feature-name}]]]}))
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
(ns status-im.contexts.keycard.feature-unavailable.view
|
||||
(:require
|
||||
[quo.core :as quo]
|
||||
[status-im.constants :as constants]
|
||||
[utils.i18n :as i18n]
|
||||
[utils.re-frame :as rf]))
|
||||
|
||||
(defn on-upvote
|
||||
[]
|
||||
(rf/dispatch [:open-url constants/mobile-upvote-link]))
|
||||
[feature-name]
|
||||
(rf/dispatch [:keycard/feature-unavailable-upvote {:feature-name feature-name}]))
|
||||
|
||||
(defn view
|
||||
[]
|
||||
[{:keys [feature-name]}]
|
||||
[:<>
|
||||
[quo/drawer-top
|
||||
{:title (i18n/label :t/feature-unavailable)
|
||||
@@ -24,5 +23,5 @@
|
||||
[quo/text
|
||||
{:style {:text-decoration-line :underline}
|
||||
:size :paragraph-2
|
||||
:on-press on-upvote}
|
||||
:on-press #(on-upvote feature-name)}
|
||||
(i18n/label :t/upvote-it)]]]])
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
customization-color (rf/sub [:profile/customization-color])]
|
||||
[:<>
|
||||
[quo/page-top
|
||||
{:title (i18n/label :t/failed-to-migrate-key-pair)
|
||||
{:title (i18n/label :t/something-didnt-go-as-planned)
|
||||
:description :context-tag
|
||||
:context-tag {:full-name profile-name
|
||||
:profile-picture profile-picture
|
||||
@@ -24,9 +24,9 @@
|
||||
{:resize-mode :contain
|
||||
:source (resources/get-image :keycard-migration-failed)}]]
|
||||
[quo/divider-label (i18n/label :t/what-you-can-do)]
|
||||
[quo/markdown-list {:description (i18n/label :t/log-out-remove-profile)}]
|
||||
[quo/markdown-list {:description (i18n/label :t/recover-status-profile)}]
|
||||
[quo/markdown-list {:description (i18n/label :t/keycard-migration-failed-instruction-1)}]
|
||||
[quo/markdown-list {:description (i18n/label :t/keycard-migration-failed-instruction-2)}]
|
||||
[quo/bottom-actions
|
||||
{:actions :one-action
|
||||
:button-one-label (i18n/label :t/log-out-remove)
|
||||
:button-one-label (i18n/label :t/logout)
|
||||
:button-one-props {:on-press #(rf/dispatch [:profile/logout])}}]]))
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
[quo.foundations.colors :as colors]
|
||||
[quo.theme]
|
||||
[react-native.core :as rn]
|
||||
[status-im.common.terms.view :as terms]
|
||||
[status-im.common.privacy.view :as privacy]
|
||||
[utils.i18n :as i18n]
|
||||
[utils.re-frame :as rf]))
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
[quo/text
|
||||
{:size :paragraph-2
|
||||
:weight :bold
|
||||
:on-press #(rf/dispatch [:show-bottom-sheet {:content terms/terms-of-use :shell? true}])}
|
||||
:on-press #(rf/dispatch [:show-bottom-sheet {:content privacy/privacy-statement :shell? true}])}
|
||||
(i18n/label :t/more-details-in-privacy-policy-2)]]])
|
||||
|
||||
(defn- bullet-points
|
||||
|
||||
@@ -47,7 +47,8 @@
|
||||
settings
|
||||
{:log-level log-level}))
|
||||
(assoc-in [:activity-center :loading?] true)
|
||||
(dissoc :centralized-metrics/onboarding-enabled?))]
|
||||
(dissoc :centralized-metrics/onboarding-enabled?))
|
||||
keycard? (get-in new-db [:profile/profile :keycard-pairing])]
|
||||
{:db (cond-> new-db
|
||||
pairing-completed? (dissoc :syncing))
|
||||
:fx (into [[:json-rpc/call
|
||||
@@ -75,8 +76,10 @@
|
||||
[:effects.chat/open-last-chat (:key-uid profile-overview)])
|
||||
|
||||
(when (:centralized-metrics/onboarding-enabled? db)
|
||||
[:dispatch [:profile.settings/toggle-telemetry true]])]
|
||||
[:dispatch [:profile.settings/toggle-telemetry true]])
|
||||
|
||||
(when keycard?
|
||||
[:dispatch [:centralized-metrics/track :metric/keycard-login]])]
|
||||
(cond
|
||||
pairing-completed?
|
||||
[[:dispatch [:update-theme-and-init-root :screen/onboarding.syncing-results]]]
|
||||
|
||||
@@ -10,7 +10,9 @@
|
||||
[button-label theme keycard-profile?]
|
||||
(fn []
|
||||
(if keycard-profile?
|
||||
(rf/dispatch [:keycard/feature-unavailable-show {:theme :dark}])
|
||||
(rf/dispatch [:keycard/feature-unavailable-show
|
||||
{:theme :dark
|
||||
:feature-name :settings.enable-biometrics}])
|
||||
(rf/dispatch
|
||||
[:standard-auth/authorize-with-password
|
||||
{:blur? true
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
[status-im.feature-flags :as ff]
|
||||
[utils.address :as utils-address]
|
||||
[utils.debounce :as debounce]
|
||||
[utils.ethereum.eip.eip681 :as eip681]
|
||||
[utils.i18n :as i18n]
|
||||
[utils.url :as url]))
|
||||
|
||||
@@ -28,13 +27,6 @@
|
||||
(let [index (string/index-of scanned-text "#")]
|
||||
(subs scanned-text (inc index))))
|
||||
|
||||
(defn eip681-address?
|
||||
[scanned-text]
|
||||
(-> scanned-text
|
||||
eip681/parse-uri
|
||||
:address
|
||||
boolean))
|
||||
|
||||
(defn pairing-qr-code?
|
||||
[_]
|
||||
false)
|
||||
@@ -88,10 +80,10 @@
|
||||
(debounce/debounce-and-dispatch [:generic-scanner/scan-success address] 300)
|
||||
(debounce/debounce-and-dispatch [:shell/change-tab :wallet-stack] 300))
|
||||
|
||||
(eip681-address? scanned-text)
|
||||
(utils-address/eip-681-address? scanned-text)
|
||||
(do
|
||||
(debounce/debounce-and-dispatch [:wallet-legacy/request-uri-parsed
|
||||
(eip681/parse-uri scanned-text)]
|
||||
(debounce/debounce-and-dispatch [:generic-scanner/scan-success
|
||||
(utils-address/eip-681-address->eth-address scanned-text)]
|
||||
300)
|
||||
(debounce/debounce-and-dispatch [:shell/change-tab :wallet-stack] 300))
|
||||
|
||||
|
||||
@@ -41,8 +41,10 @@
|
||||
other-devices)
|
||||
keycard? (rf/sub [:keycard/keycard-profile?])
|
||||
keycard-feature-unavailable (rn/use-callback
|
||||
#(rf/dispatch [:keycard/feature-unavailable-show
|
||||
{:theme :dark}]))]
|
||||
#(rf/dispatch
|
||||
[:keycard/feature-unavailable-show
|
||||
{:theme :dark
|
||||
:feature-name :settings.setup-syncing}]))]
|
||||
[quo/overlay {:type :shell :top-inset? true}
|
||||
[quo/page-nav
|
||||
{:type :no-title
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
(ns status-im.contexts.wallet.bridge.bridge-to.view
|
||||
(:require
|
||||
[clojure.string :as string]
|
||||
[quo.core :as quo]
|
||||
[quo.foundations.resources :as quo.resources]
|
||||
[quo.theme]
|
||||
@@ -16,27 +15,34 @@
|
||||
(defn- bridge-token-component
|
||||
[]
|
||||
(fn [{:keys [chain-id network-name]} {:keys [supported-networks] :as token}]
|
||||
(let [network (rf/sub [:wallet/network-details-by-chain-id chain-id])
|
||||
currency (rf/sub [:profile/currency])
|
||||
currency-symbol (rf/sub [:profile/currency-symbol])
|
||||
prices-per-token (rf/sub [:wallet/prices-per-token])
|
||||
balance (utils/calculate-total-token-balance token [chain-id])
|
||||
crypto-value (utils/get-standard-crypto-format token balance prices-per-token)
|
||||
fiat-value (utils/calculate-token-fiat-value
|
||||
{:currency currency
|
||||
:balance balance
|
||||
:token token
|
||||
:prices-per-token prices-per-token})
|
||||
fiat-formatted (utils/fiat-formatted-for-ui currency-symbol
|
||||
fiat-value)
|
||||
token-available-on-network? (network-utils/token-available-on-network? supported-networks
|
||||
chain-id)]
|
||||
(let [network (rf/sub [:wallet/network-details-by-chain-id chain-id])
|
||||
currency (rf/sub [:profile/currency])
|
||||
currency-symbol (rf/sub [:profile/currency-symbol])
|
||||
prices-per-token (rf/sub [:wallet/prices-per-token])
|
||||
selected-network (rf/sub [:wallet/send-network])
|
||||
{selected-network-chain-id :chain-id} selected-network
|
||||
balance (utils/calculate-total-token-balance token [chain-id])
|
||||
crypto-value (utils/get-standard-crypto-format token
|
||||
balance
|
||||
prices-per-token)
|
||||
fiat-value (utils/calculate-token-fiat-value
|
||||
{:currency currency
|
||||
:balance balance
|
||||
:token token
|
||||
:prices-per-token prices-per-token})
|
||||
fiat-formatted (utils/fiat-formatted-for-ui currency-symbol
|
||||
fiat-value)
|
||||
token-available-on-network? (network-utils/token-available-on-network?
|
||||
supported-networks
|
||||
chain-id)]
|
||||
[quo/network-list
|
||||
{:label (name network-name)
|
||||
:network-image (quo.resources/get-network (:network-name network))
|
||||
:token-value (str crypto-value " " (:symbol token))
|
||||
:fiat-value fiat-formatted
|
||||
:state (if token-available-on-network? :default :disabled)
|
||||
:state (if (and token-available-on-network? (not= chain-id selected-network-chain-id))
|
||||
:default
|
||||
:disabled)
|
||||
:on-press #(rf/dispatch [:wallet/select-bridge-network
|
||||
{:network-chain-id chain-id
|
||||
:stack-id :screen/wallet.bridge-to}])}])))
|
||||
@@ -55,8 +61,7 @@
|
||||
(assoc account-token
|
||||
:networks (:networks token)
|
||||
:supported-networks (:supported-networks token)))
|
||||
bridge-to-title (i18n/label :t/bridge-to
|
||||
{:name (string/upper-case (str token-symbol))})]
|
||||
bridge-to-title (i18n/label :t/select-network-to-receive)]
|
||||
|
||||
(hot-reload/use-safe-unmount #(rf/dispatch [:wallet/clean-bridge-to-selection]))
|
||||
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
(ns status-im.contexts.wallet.bridge.flow-config)
|
||||
|
||||
(def steps
|
||||
[{:screen-id :screen/wallet.select-from
|
||||
:skip-step? (fn [db] (some? (get-in db [:wallet :current-viewing-account-address])))}
|
||||
{:screen-id :screen/wallet.bridge-select-asset
|
||||
[{:screen-id :screen/wallet.bridge-select-asset
|
||||
:skip-step? (fn [db] (some? (get-in db [:wallet :ui :send :token])))}
|
||||
{:screen-id :screen/wallet.bridge-to
|
||||
:skip-step? (fn [db] (some? (get-in db [:wallet :ui :send :bridge-to-chain-id])))}
|
||||
|
||||
@@ -21,5 +21,4 @@
|
||||
:stack-id :screen/wallet.bridge-input-amount}]))
|
||||
:on-navigate-back (fn []
|
||||
(rf/dispatch-sync [:wallet/stop-and-clean-suggested-routes])
|
||||
(rf/dispatch [:wallet/clean-disabled-from-networks])
|
||||
(rf/dispatch [:wallet/clean-send-amount]))}]])
|
||||
|
||||
@@ -48,7 +48,8 @@
|
||||
{:icon-name :i/dapps
|
||||
:on-press #(rf/dispatch
|
||||
(if keycard?
|
||||
[:keycard/feature-unavailable-show]
|
||||
[:keycard/feature-unavailable-show
|
||||
{:feature-name :wallet.show-connected-dapps}]
|
||||
[:navigate-to :screen/wallet.connected-dapps]))})
|
||||
(when-not sending-collectible?
|
||||
{:content-type :account-switcher
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
{:title (i18n/label :t/scan-qr)
|
||||
:subtitle (i18n/label :t/scan-an-address-qr-code)
|
||||
:error-message (i18n/label :t/oops-this-qr-does-not-contain-an-address)
|
||||
:validate-fn #(utils-address/supported-address? %)
|
||||
:validate-fn #(utils-address/supported-scan-address? %)
|
||||
:on-success-scan (fn [result]
|
||||
(let [address (utils-address/supported-address->eth-address result)]
|
||||
(when on-result (on-result address))
|
||||
|
||||
@@ -77,24 +77,31 @@
|
||||
(defn token-value-drawer
|
||||
[token watch-only? entry-point]
|
||||
(let [token-symbol (:token token)
|
||||
token-data (rf/sub [:wallet/token-by-symbol token-symbol])
|
||||
token-data (rf/sub [:wallet/token-by-symbol-from-first-available-account-with-balance
|
||||
token-symbol])
|
||||
selected-account (rf/sub [:wallet/current-viewing-account-address])
|
||||
token-owners (rf/sub [:wallet/operable-addresses-with-token-symbol token-symbol])
|
||||
testnet-mode? (rf/sub [:profile/test-networks-enabled?])
|
||||
account-owns-token? (rf/sub [:wallet/current-account-owns-token token-symbol])
|
||||
network-details (rf/sub [:wallet/network-details])
|
||||
receive-token-symbol (if (= token-symbol "SNT") "ETH" "SNT")
|
||||
token-owned? (if selected-account account-owns-token? (seq token-owners))
|
||||
asset-to-receive (rf/sub [:wallet/token-by-symbol receive-token-symbol])
|
||||
params (cond-> {:start-flow? true
|
||||
:owners token-owners
|
||||
:testnet-mode? testnet-mode?
|
||||
:asset-to-receive asset-to-receive}
|
||||
unique-owner? (= (count token-owners) 1)
|
||||
params (cond-> {:start-flow? true
|
||||
:owners token-owners
|
||||
:testnet-mode? testnet-mode?}
|
||||
selected-account
|
||||
(assoc :token token-data
|
||||
:stack-id :screen/wallet.accounts
|
||||
:has-balance? (-> (get-in token [:values :fiat-unformatted-value])
|
||||
money/above-zero?))
|
||||
(not selected-account)
|
||||
(and (not selected-account) unique-owner?)
|
||||
(assoc :token-symbol token-symbol
|
||||
:token token-data
|
||||
:stack-id :wallet-stack)
|
||||
|
||||
(and (not selected-account) (not unique-owner?))
|
||||
(assoc :token-symbol token-symbol
|
||||
:stack-id :wallet-stack))]
|
||||
[quo/action-drawer
|
||||
@@ -108,9 +115,13 @@
|
||||
(action-send params entry-point))
|
||||
(action-receive selected-account)
|
||||
(when token-owned?
|
||||
(action-swap params))
|
||||
(action-swap (assoc params
|
||||
:asset-to-receive
|
||||
asset-to-receive)))
|
||||
(when token-owned?
|
||||
(action-bridge (assoc params
|
||||
:network-details
|
||||
network-details
|
||||
:bridge-disabled?
|
||||
(send-utils/bridge-disabled? token-symbol))))]))]]))
|
||||
|
||||
@@ -120,7 +131,11 @@
|
||||
(cond-> item
|
||||
(or (not watch-only?) (ff/enabled? ::ff/wallet.long-press-watch-only-asset))
|
||||
(assoc :on-long-press
|
||||
#(rf/dispatch
|
||||
[:show-bottom-sheet
|
||||
{:content (fn [] [token-value-drawer item watch-only? entry-point])
|
||||
:selected-item (fn [] [quo/token-value item])}])))])
|
||||
(fn []
|
||||
(when (= entry-point :wallet-stack)
|
||||
(rf/dispatch [:wallet/close-account-page])
|
||||
(rf/dispatch [:wallet/clean-current-viewing-account]))
|
||||
(rf/dispatch
|
||||
[:show-bottom-sheet
|
||||
{:content (fn [] [token-value-drawer item watch-only? entry-point])
|
||||
:selected-item (fn [] [quo/token-value item])}]))))])
|
||||
|
||||
@@ -404,13 +404,15 @@
|
||||
:market-values-per-token market-values-per-token}))
|
||||
calculated-tokens (map calculate-token tokens)]
|
||||
(sort-by (fn [token]
|
||||
(let [fiat-value (get-in token [:values :fiat-unformatted-value])]
|
||||
[(- fiat-value)]))
|
||||
(let [fiat-value (get-in token [:values :fiat-unformatted-value])
|
||||
priority (get constants/token-sort-priority (:token token) ##Inf)]
|
||||
[(- fiat-value) priority]))
|
||||
calculated-tokens)))
|
||||
|
||||
(defn sort-tokens
|
||||
[tokens]
|
||||
(sort-by (fn [token] (- (:balance token))) tokens))
|
||||
(let [priority #(get constants/token-sort-priority (:symbol %) ##Inf)]
|
||||
(sort-by (juxt (comp - :balance) priority) tokens)))
|
||||
|
||||
(defn- transaction-data
|
||||
[{:keys [from-address to-address token-address route data eth-transfer?]}]
|
||||
@@ -541,16 +543,23 @@
|
||||
|
||||
(defn sort-tokens-by-name
|
||||
[tokens]
|
||||
(sort-by :symbol tokens))
|
||||
(let [priority #(get constants/token-sort-priority (:symbol %) ##Inf)]
|
||||
(sort-by (juxt :symbol priority) tokens)))
|
||||
|
||||
(defn token-with-balance
|
||||
([token networks]
|
||||
(token-with-balance token networks nil))
|
||||
([token networks chain-ids]
|
||||
(assoc token
|
||||
:networks (network-utils/network-list-with-positive-balance token networks)
|
||||
:supported-networks (network-utils/network-list token networks)
|
||||
:available-balance (calculate-total-token-balance token)
|
||||
:total-balance (calculate-total-token-balance token chain-ids))))
|
||||
|
||||
(defn tokens-with-balance
|
||||
[tokens networks chain-ids]
|
||||
(map (fn [token]
|
||||
(assoc token
|
||||
:networks (network-utils/network-list-with-positive-balance token networks)
|
||||
:supported-networks (network-utils/network-list token networks)
|
||||
:available-balance (calculate-total-token-balance token)
|
||||
:total-balance (calculate-total-token-balance token chain-ids)))
|
||||
(token-with-balance token networks chain-ids))
|
||||
tokens))
|
||||
|
||||
(defn estimated-time-format
|
||||
|
||||
@@ -1,23 +1,11 @@
|
||||
(ns status-im.contexts.wallet.common.wizard.events
|
||||
(:require [status-im.contexts.wallet.bridge.flow-config :as wallet-bridge-flow]
|
||||
[status-im.contexts.wallet.send.flow-config :as wallet-send-flow]
|
||||
(:require [status-im.contexts.wallet.common.wizard.utils :as wizard-utils]
|
||||
[utils.re-frame :as rf]))
|
||||
|
||||
(defn- wizard-find-next-screen
|
||||
[db flow-id current-screen]
|
||||
(let [flow-config (case flow-id
|
||||
:wallet-send-flow wallet-send-flow/steps
|
||||
:wallet-bridge-flow wallet-bridge-flow/steps
|
||||
nil)]
|
||||
(first (filter (fn [{:keys [skip-step? screen-id]}]
|
||||
(and (not= screen-id current-screen)
|
||||
(not (and (fn? skip-step?) (skip-step? db)))))
|
||||
flow-config))))
|
||||
|
||||
(rf/reg-event-fx
|
||||
:wallet/wizard-navigate-forward
|
||||
(fn [{:keys [db]} [{:keys [current-screen flow-id start-flow?]}]]
|
||||
(let [next-screen (wizard-find-next-screen db flow-id current-screen)]
|
||||
(let [next-screen (wizard-utils/wizard-find-next-screen db flow-id current-screen)]
|
||||
{:fx [[:dispatch
|
||||
(if start-flow?
|
||||
[:open-modal (:screen-id next-screen)]
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
(ns status-im.contexts.wallet.common.wizard.utils
|
||||
(:require [status-im.contexts.wallet.bridge.flow-config :as wallet-bridge-flow]
|
||||
[status-im.contexts.wallet.send.flow-config :as wallet-send-flow]))
|
||||
|
||||
(defn wizard-find-next-screen
|
||||
[db flow-id current-screen]
|
||||
(let [flow-config (case flow-id
|
||||
:wallet-send-flow wallet-send-flow/steps
|
||||
:wallet-bridge-flow wallet-bridge-flow/steps
|
||||
nil)]
|
||||
(first (filter (fn [{:keys [skip-step? screen-id]}]
|
||||
(and (not= screen-id current-screen)
|
||||
(not (and (fn? skip-step?) (skip-step? db)))))
|
||||
flow-config))))
|
||||
@@ -10,11 +10,13 @@
|
||||
[status-im.contexts.settings.wallet.effects]
|
||||
[status-im.contexts.settings.wallet.events]
|
||||
[status-im.contexts.wallet.common.activity-tab.events]
|
||||
[status-im.contexts.wallet.common.utils :as utils]
|
||||
[status-im.contexts.wallet.common.utils.external-links :as external-links]
|
||||
[status-im.contexts.wallet.common.utils.networks :as network-utils]
|
||||
[status-im.contexts.wallet.data-store :as data-store]
|
||||
[status-im.contexts.wallet.db :as db]
|
||||
[status-im.contexts.wallet.item-types :as item-types]
|
||||
[status-im.contexts.wallet.sheets.network-selection.view :as network-selection]
|
||||
[status-im.contexts.wallet.tokens.events]
|
||||
[status-im.feature-flags :as ff]
|
||||
[taoensso.timbre :as log]
|
||||
@@ -114,7 +116,7 @@
|
||||
(rf/reg-event-fx
|
||||
:wallet/fetch-assets-for-address
|
||||
(fn [_ [address]]
|
||||
{:fx [[:dispatch [:wallet/get-wallet-token-for-account address]]
|
||||
{:fx [[:dispatch [:wallet/get-wallet-token-for-accounts [address]]]
|
||||
[:dispatch [:wallet/request-collectibles-for-account address]]]}))
|
||||
|
||||
(defn- reconcile-accounts
|
||||
@@ -204,34 +206,42 @@
|
||||
|
||||
(rf/reg-event-fx :wallet/get-wallet-token-for-all-accounts
|
||||
(fn [{:keys [db]}]
|
||||
{:fx (->> (get-in db [:wallet :accounts])
|
||||
vals
|
||||
(mapv
|
||||
(fn [{:keys [address]}]
|
||||
[:dispatch [:wallet/get-wallet-token-for-account address]])))}))
|
||||
(let [addresses (->> (get-in db [:wallet :accounts])
|
||||
(vals)
|
||||
(keep :address)
|
||||
(vec))]
|
||||
{:fx [[:dispatch [:wallet/get-wallet-token-for-accounts addresses]]]})))
|
||||
|
||||
(rf/reg-event-fx :wallet/get-wallet-token-for-account
|
||||
(fn [{:keys [db]} [address]]
|
||||
{:db (assoc-in db [:wallet :ui :tokens-loading address] true)
|
||||
(rf/reg-event-fx :wallet/get-wallet-token-for-accounts
|
||||
(fn [{:keys [db]} [addresses]]
|
||||
{:db (reduce
|
||||
(fn [db address]
|
||||
(assoc-in db [:wallet :ui :tokens-loading address] true))
|
||||
db
|
||||
addresses)
|
||||
:fx [[:json-rpc/call
|
||||
[{:method "wallet_fetchOrGetCachedWalletBalances"
|
||||
:params [[address] true]
|
||||
:on-success [:wallet/store-wallet-token address]
|
||||
:on-error [:wallet/get-wallet-token-for-account-failed address]}]]]}))
|
||||
:params [addresses true]
|
||||
:on-success [:wallet/store-wallet-token addresses]
|
||||
:on-error [:wallet/get-wallet-token-for-accounts-failed addresses]}]]]}))
|
||||
|
||||
(rf/reg-event-fx
|
||||
:wallet/get-wallet-token-for-account-failed
|
||||
(fn [{:keys [db]} [address error]]
|
||||
:wallet/get-wallet-token-for-accounts-failed
|
||||
(fn [{:keys [db]} [addresses error]]
|
||||
(log/info "failed to get wallet token "
|
||||
{:error error
|
||||
:event :wallet/get-wallet-token-for-account
|
||||
:params address})
|
||||
:event :wallet/get-wallet-token-for-accounts
|
||||
:params addresses})
|
||||
{:fx [[:dispatch [:wallet/get-last-wallet-token-update-if-needed]]]
|
||||
:db (assoc-in db [:wallet :ui :tokens-loading address] false)}))
|
||||
:db (reduce
|
||||
(fn [db address]
|
||||
(assoc-in db [:wallet :ui :tokens-loading address] false))
|
||||
db
|
||||
addresses)}))
|
||||
|
||||
(rf/reg-event-fx
|
||||
:wallet/store-wallet-token
|
||||
(fn [{:keys [db]} [address raw-tokens-data]]
|
||||
(fn [{:keys [db]} [addresses raw-tokens-data]]
|
||||
(let [supported-chains-by-token-symbol (get-in db [:wallet :tokens :supported-chains-by-symbol])
|
||||
profile-currency (get-in db [:profile/profile :currency])
|
||||
tokens (data-store/rpc->tokens raw-tokens-data
|
||||
@@ -244,13 +254,18 @@
|
||||
accounts))
|
||||
stored-accounts
|
||||
tokens-per-account))
|
||||
symbols (reduce-kv (fn [acc _ v]
|
||||
(into acc (map :symbol v)))
|
||||
#{}
|
||||
tokens)]
|
||||
symbols (reduce-kv
|
||||
(fn [acc _ tokens-data]
|
||||
(into acc (map :symbol tokens-data)))
|
||||
#{}
|
||||
tokens)]
|
||||
{:db (-> db
|
||||
(update-in [:wallet :accounts] add-tokens tokens)
|
||||
(assoc-in [:wallet :ui :tokens-loading address] false))
|
||||
((fn [db]
|
||||
(reduce (fn [db address]
|
||||
(assoc-in db [:wallet :ui :tokens-loading address] false))
|
||||
db
|
||||
addresses))))
|
||||
:fx [[:dispatch [:wallet/get-last-wallet-token-update-if-needed]]
|
||||
[:effects.wallet.tokens/fetch-market-values
|
||||
{:symbols symbols
|
||||
@@ -342,19 +357,79 @@
|
||||
(rf/reg-event-fx :wallet/get-keypairs get-keypairs)
|
||||
|
||||
(rf/reg-event-fx :wallet/bridge-select-token
|
||||
(fn [{:keys [db]} [{:keys [token token-symbol stack-id start-flow?]}]]
|
||||
(let [missing-recipient? (-> db :wallet :ui :send :to-address nil?)
|
||||
to-address (-> db :wallet :current-viewing-account-address)]
|
||||
(fn [{:keys [db]}
|
||||
[{:keys [token token-symbol stack-id network owners network-details start-flow?] :as params}]]
|
||||
(let [{:keys [wallet]} db
|
||||
unique-owner (when (= (count owners) 1)
|
||||
(first owners))
|
||||
token (if (and unique-owner (nil? token))
|
||||
(let [token (utils/get-token-from-account db
|
||||
token-symbol
|
||||
unique-owner)]
|
||||
(utils/token-with-balance token network-details))
|
||||
token)
|
||||
missing-recipient? (-> db :wallet :ui :send :to-address nil?)
|
||||
to-address (or unique-owner
|
||||
(-> db :wallet :current-viewing-account-address)
|
||||
(utils/get-default-account (-> db :wallet :accounts)))
|
||||
view-id (:view-id db)
|
||||
root-screen? (or (= view-id :wallet-stack) (nil? view-id))
|
||||
multi-account-balance? (-> (utils/get-accounts-with-token-balance (:accounts wallet)
|
||||
token)
|
||||
(count)
|
||||
(> 1))
|
||||
account-not-defined? (and (not unique-owner) multi-account-balance?)
|
||||
networks-with-balance (when (and token (:balances-per-chain token))
|
||||
(filter #(not= (:balance %) "0")
|
||||
(vals (:balances-per-chain token))))
|
||||
balance-in-only-one-network? (when networks-with-balance (= (count networks-with-balance) 1))
|
||||
test-networks-enabled? (get-in db [:profile/profile :test-networks-enabled?])
|
||||
network-details (-> (get-in db
|
||||
[:wallet :networks
|
||||
(if test-networks-enabled? :test :prod)])
|
||||
(network-utils/sorted-networks-with-details))
|
||||
network (if balance-in-only-one-network?
|
||||
(first (filter #(= (:chain-id %)
|
||||
(:chain-id (first networks-with-balance)))
|
||||
network-details))
|
||||
network)]
|
||||
{:db (cond-> db
|
||||
:always (assoc-in [:wallet :ui :send :tx-type] :tx/bridge)
|
||||
token (assoc-in [:wallet :ui :send :token] token)
|
||||
token-symbol (assoc-in [:wallet :ui :send :token-symbol] token-symbol)
|
||||
network (assoc-in [:wallet :ui :send :network] network)
|
||||
missing-recipient? (assoc-in [:wallet :ui :send :to-address] to-address))
|
||||
:fx [[:dispatch
|
||||
[:wallet/wizard-navigate-forward
|
||||
{:current-screen stack-id
|
||||
:start-flow? start-flow?
|
||||
:flow-id :wallet-bridge-flow}]]]})))
|
||||
:fx (cond
|
||||
;; If the token has a balance in more than one account and this was dispatched from the
|
||||
;; general wallet screen, open the account selection screen.
|
||||
(and account-not-defined? root-screen?)
|
||||
[[:dispatch [:open-modal :screen/wallet.select-from]]]
|
||||
|
||||
;; If the token has a balance in only one account (or this was dispatched from the
|
||||
;; account screen) and the network is already set, navigate forward in the bridge flow.
|
||||
(some? network)
|
||||
[[:dispatch
|
||||
[:wallet/wizard-navigate-forward
|
||||
{:current-screen stack-id
|
||||
:start-flow? start-flow?
|
||||
:flow-id :wallet-bridge-flow}]]]
|
||||
|
||||
;; If we know which account to bridge the token from but the network is not set yet,
|
||||
;; show the network selection drawer.
|
||||
:else
|
||||
[[:dispatch [:wallet/switch-current-viewing-account to-address]]
|
||||
[:dispatch
|
||||
[:show-bottom-sheet
|
||||
{:content (fn []
|
||||
[network-selection/view
|
||||
{:title (i18n/label :t/select-network-to-bridge-from)
|
||||
:token-symbol (or token-symbol (:symbol token))
|
||||
:source :bridge
|
||||
:on-select-network (fn [network]
|
||||
(rf/dispatch [:hide-bottom-sheet])
|
||||
(rf/dispatch
|
||||
[:wallet/bridge-select-token
|
||||
(assoc params :network network)]))}])}]]])})))
|
||||
|
||||
(rf/reg-event-fx :wallet/start-bridge
|
||||
(fn [{:keys [db]}]
|
||||
|
||||
@@ -116,20 +116,19 @@
|
||||
address-2 "0x2"]
|
||||
(reset! rf-db/app-db {:wallet {:accounts {address-1 {:address address-1}
|
||||
address-2 {:address address-2}}}})
|
||||
(is (match? [[:dispatch [:wallet/get-wallet-token-for-account address-1]]
|
||||
[:dispatch [:wallet/get-wallet-token-for-account address-2]]]
|
||||
(is (match? [[:dispatch [:wallet/get-wallet-token-for-accounts [address-1 address-2]]]]
|
||||
(:fx (dispatch [event-id]))))))
|
||||
|
||||
(h/deftest-event :wallet/get-wallet-token-for-account
|
||||
(h/deftest-event :wallet/get-wallet-token-for-accounts
|
||||
[event-id dispatch]
|
||||
(let [expected-effects {:db {:wallet {:ui {:tokens-loading {address true}}}}
|
||||
:fx [[:json-rpc/call
|
||||
[{:method "wallet_fetchOrGetCachedWalletBalances"
|
||||
:params [[address] true]
|
||||
:on-success [:wallet/store-wallet-token address]
|
||||
:on-error [:wallet/get-wallet-token-for-account-failed
|
||||
address]}]]]}]
|
||||
(is (match? expected-effects (dispatch [event-id address])))))
|
||||
:on-success [:wallet/store-wallet-token [address]]
|
||||
:on-error [:wallet/get-wallet-token-for-accounts-failed
|
||||
[address]]}]]]}]
|
||||
(is (match? expected-effects (dispatch [event-id [address]])))))
|
||||
|
||||
(h/deftest-event :wallet/reconcile-keypairs
|
||||
[event-id dispatch]
|
||||
|
||||
@@ -15,19 +15,24 @@
|
||||
|
||||
(defn new-account
|
||||
[]
|
||||
[quo/action-drawer
|
||||
[[{:icon :i/add
|
||||
:accessibility-label :start-a-new-chat
|
||||
:label (i18n/label :t/add-account)
|
||||
:sub-label (i18n/label :t/add-account-description)
|
||||
:on-press #(rf/dispatch [:navigate-to :screen/wallet.create-account])}
|
||||
(when (ff/enabled? ::ff/wallet.add-watched-address)
|
||||
{:icon :i/reveal
|
||||
:accessibility-label :add-a-contact
|
||||
:label (i18n/label :t/add-address-to-watch)
|
||||
:sub-label (i18n/label :t/add-address-to-watch-description)
|
||||
:on-press #(rf/dispatch [:navigate-to :screen/wallet.add-address-to-watch])
|
||||
:add-divider? true})]]])
|
||||
(let [keycard? (rf/sub [:keycard/keycard-profile?])]
|
||||
[quo/action-drawer
|
||||
[[{:icon :i/add
|
||||
:accessibility-label :start-a-new-chat
|
||||
:label (i18n/label :t/add-account)
|
||||
:sub-label (i18n/label :t/add-account-description)
|
||||
:on-press (fn []
|
||||
(if keycard?
|
||||
(rf/dispatch [:keycard/feature-unavailable-show
|
||||
{:feature-name :wallet.new-account}])
|
||||
(rf/dispatch [:navigate-to :screen/wallet.create-account])))}
|
||||
(when (ff/enabled? ::ff/wallet.add-watched-address)
|
||||
{:icon :i/reveal
|
||||
:accessibility-label :add-a-contact
|
||||
:label (i18n/label :t/add-address-to-watch)
|
||||
:sub-label (i18n/label :t/add-address-to-watch-description)
|
||||
:on-press #(rf/dispatch [:navigate-to :screen/wallet.add-address-to-watch])
|
||||
:add-divider? true})]]]))
|
||||
|
||||
(defn- new-account-card-data
|
||||
[]
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
[status-im.contexts.wallet.common.utils.networks :as network-utils]
|
||||
[status-im.contexts.wallet.data-store :as data-store]
|
||||
[status-im.contexts.wallet.send.utils :as send-utils]
|
||||
[status-im.contexts.wallet.sheets.network-selection.view :as network-selection]
|
||||
[taoensso.timbre :as log]
|
||||
[utils.money :as utils.money]
|
||||
[utils.number]
|
||||
@@ -41,64 +42,42 @@
|
||||
(fn [{:keys [db]} [suggested-routes-data enough-assets?]]
|
||||
(if-not enough-assets?
|
||||
{:db (update-in db [:wallet :ui :send] add-not-enough-assets-data (:best suggested-routes-data))}
|
||||
(let [chosen-route (:best suggested-routes-data)
|
||||
(let [chosen-route (:best suggested-routes-data)
|
||||
{:keys [token collectible token-display-name
|
||||
receiver-networks
|
||||
receiver-network-values
|
||||
sender-network-values tx-type
|
||||
disabled-from-chain-ids
|
||||
from-locked-amounts]} (get-in db [:wallet :ui :send])
|
||||
token-decimals (if collectible 0 (:decimals token))
|
||||
native-token? (and token (= token-display-name "ETH"))
|
||||
routes-available? (pos? (count chosen-route))
|
||||
token-networks (:supported-networks token)
|
||||
token-networks-ids (when token-networks
|
||||
(map #(:chain-id %) token-networks))
|
||||
from-network-amounts-by-chain (send-utils/network-amounts-by-chain
|
||||
{:route chosen-route
|
||||
:token-decimals token-decimals
|
||||
:native-token? native-token?
|
||||
:receiver? false})
|
||||
to-network-amounts-by-chain (send-utils/network-amounts-by-chain
|
||||
{:route chosen-route
|
||||
:token-decimals token-decimals
|
||||
:native-token? native-token?
|
||||
:receiver? true})
|
||||
sender-possible-chain-ids (map :chain-id sender-network-values)
|
||||
sender-network-values (if routes-available?
|
||||
(send-utils/network-amounts
|
||||
{:network-values
|
||||
(if (= tx-type :tx/bridge)
|
||||
from-network-amounts-by-chain
|
||||
(send-utils/add-zero-values-to-network-values
|
||||
from-network-amounts-by-chain
|
||||
sender-possible-chain-ids))
|
||||
:disabled-chain-ids disabled-from-chain-ids
|
||||
:receiver-networks receiver-networks
|
||||
:token-networks-ids token-networks-ids
|
||||
:from-locked-amounts from-locked-amounts
|
||||
:tx-type tx-type
|
||||
:receiver? false})
|
||||
(send-utils/reset-loading-network-amounts-to-zero
|
||||
sender-network-values))
|
||||
receiver-network-values (if routes-available?
|
||||
(send-utils/network-amounts
|
||||
{:network-values to-network-amounts-by-chain
|
||||
:disabled-chain-ids disabled-from-chain-ids
|
||||
:receiver-networks receiver-networks
|
||||
:token-networks-ids token-networks-ids
|
||||
:tx-type tx-type
|
||||
:receiver? true})
|
||||
(cond->
|
||||
(send-utils/reset-loading-network-amounts-to-zero
|
||||
receiver-network-values)
|
||||
|
||||
(not= tx-type :tx/bridge)
|
||||
send-utils/safe-add-type-edit))
|
||||
network-links (when routes-available?
|
||||
(send-utils/network-links chosen-route
|
||||
sender-network-values
|
||||
receiver-network-values))]
|
||||
sender-network-values tx-type]} (get-in db [:wallet :ui :send])
|
||||
token-decimals (if collectible 0 (:decimals token))
|
||||
native-token? (and token (= token-display-name "ETH"))
|
||||
routes-available? (pos? (count chosen-route))
|
||||
from-network-amounts-by-chain (send-utils/network-amounts-by-chain
|
||||
{:route chosen-route
|
||||
:token-decimals token-decimals
|
||||
:native-token? native-token?
|
||||
:receiver? false})
|
||||
to-network-amounts-by-chain (send-utils/network-amounts-by-chain
|
||||
{:route chosen-route
|
||||
:token-decimals token-decimals
|
||||
:native-token? native-token?
|
||||
:receiver? true})
|
||||
sender-possible-chain-ids (map :chain-id sender-network-values)
|
||||
sender-network-values (if routes-available?
|
||||
(send-utils/network-amounts
|
||||
(if (= tx-type :tx/bridge)
|
||||
from-network-amounts-by-chain
|
||||
(send-utils/add-zero-values-to-network-values
|
||||
from-network-amounts-by-chain
|
||||
sender-possible-chain-ids)))
|
||||
(send-utils/reset-loading-network-amounts-to-zero
|
||||
sender-network-values))
|
||||
receiver-network-values (if routes-available?
|
||||
(send-utils/network-amounts
|
||||
to-network-amounts-by-chain)
|
||||
(send-utils/reset-loading-network-amounts-to-zero
|
||||
receiver-network-values))
|
||||
network-links (when routes-available?
|
||||
(send-utils/network-links chosen-route
|
||||
sender-network-values
|
||||
receiver-network-values))]
|
||||
{:db (update-in db
|
||||
[:wallet :ui :send]
|
||||
assoc
|
||||
@@ -137,34 +116,19 @@
|
||||
(fn [{:keys [db]}]
|
||||
{:db (update-in db [:wallet :ui :send] dissoc :amount)}))
|
||||
|
||||
(rf/reg-event-fx :wallet/clean-disabled-from-networks
|
||||
(fn [{:keys [db]}]
|
||||
{:db (update-in db [:wallet :ui :send] dissoc :disabled-from-chain-ids)}))
|
||||
|
||||
(rf/reg-event-fx :wallet/clean-from-locked-amounts
|
||||
(fn [{:keys [db]}]
|
||||
{:db (update-in db [:wallet :ui :send] dissoc :from-locked-amounts)}))
|
||||
|
||||
(rf/reg-event-fx
|
||||
:wallet/select-send-address
|
||||
(fn [{:keys [db]} [{:keys [address recipient stack-id start-flow?]}]]
|
||||
(let [[prefix to-address] (utils/split-prefix-and-address address)
|
||||
testnet-enabled? (get-in db [:profile/profile :test-networks-enabled?])
|
||||
receiver-networks (network-utils/resolve-receiver-networks
|
||||
{:prefix prefix
|
||||
:testnet-enabled? testnet-enabled?})
|
||||
collectible-tx? (send-utils/tx-type-collectible?
|
||||
(-> db :wallet :ui :send :tx-type))
|
||||
collectible (when collectible-tx?
|
||||
(-> db :wallet :ui :send :collectible))
|
||||
one-collectible? (when collectible-tx?
|
||||
(= (collectible.utils/collectible-balance collectible) 1))]
|
||||
(let [[_ to-address] (utils/split-prefix-and-address address)
|
||||
collectible-tx? (send-utils/tx-type-collectible?
|
||||
(-> db :wallet :ui :send :tx-type))
|
||||
collectible (when collectible-tx?
|
||||
(-> db :wallet :ui :send :collectible))
|
||||
one-collectible? (when collectible-tx?
|
||||
(= (collectible.utils/collectible-balance collectible) 1))]
|
||||
{:db (-> db
|
||||
(assoc-in [:wallet :ui :send :recipient] (or recipient address))
|
||||
(assoc-in [:wallet :ui :send :to-address] to-address)
|
||||
(assoc-in [:wallet :ui :send :address-prefix] prefix)
|
||||
(assoc-in [:wallet :ui :send :receiver-preferred-networks] receiver-networks)
|
||||
(assoc-in [:wallet :ui :send :receiver-networks] receiver-networks))
|
||||
(assoc-in [:wallet :ui :send :to-address] to-address))
|
||||
:fx [(when (and collectible-tx? one-collectible?)
|
||||
[:dispatch [:wallet/start-get-suggested-routes {:amount 1}]])
|
||||
[:dispatch
|
||||
@@ -182,32 +146,47 @@
|
||||
|
||||
(rf/reg-event-fx
|
||||
:wallet/set-token-to-send
|
||||
(fn [{:keys [db]} [{:keys [token-symbol token stack-id start-flow? owners]} entry-point]]
|
||||
(fn [{:keys [db]}
|
||||
[{:keys [token-symbol token network stack-id start-flow? owners] :as params} entry-point]]
|
||||
;; `token` is a map extracted from the sender, but in the wallet home page we don't know the
|
||||
;; sender yet, so we only provide the `token-symbol`, later in
|
||||
;; `:wallet/select-from-account` the `token` key will be set.
|
||||
(let [{:keys [networks]} token
|
||||
receiver-networks (get-in db [:wallet :ui :send :receiver-networks])
|
||||
token-networks-ids (map :chain-id networks)
|
||||
unsupported-token? (not-any? (set receiver-networks) token-networks-ids)
|
||||
unique-owner (when (= (count owners) 1)
|
||||
(first owners))
|
||||
unique-owner-tokens (get-in db [:wallet :accounts unique-owner :tokens])
|
||||
token-data (or token
|
||||
(when (and token-symbol unique-owner)
|
||||
(some #(when (= (:symbol %) token-symbol) %)
|
||||
unique-owner-tokens)))
|
||||
test-networks-enabled? (get-in db [:profile/profile :test-networks-enabled?])
|
||||
network-details (-> (get-in db
|
||||
[:wallet :networks (if test-networks-enabled? :test :prod)])
|
||||
(network-utils/sorted-networks-with-details))]
|
||||
(let [{:keys [wallet]} db
|
||||
unique-owner (when (= (count owners) 1)
|
||||
(first owners))
|
||||
unique-owner-tokens (get-in db [:wallet :accounts unique-owner :tokens])
|
||||
token-data (or token
|
||||
(when (and token-symbol unique-owner)
|
||||
(some #(when (= (:symbol %) token-symbol) %)
|
||||
unique-owner-tokens)))
|
||||
view-id (:view-id db)
|
||||
root-screen? (or (= view-id :wallet-stack) (nil? view-id))
|
||||
multi-account-balance? (-> (utils/get-accounts-with-token-balance (:accounts wallet)
|
||||
token)
|
||||
(count)
|
||||
(> 1))
|
||||
account-not-defined? (and (not unique-owner) multi-account-balance?)
|
||||
networks-with-balance (when (and token-data (:balances-per-chain token))
|
||||
(filter #(not= (:balance %) "0")
|
||||
(vals (:balances-per-chain token))))
|
||||
balance-in-only-one-network? (when networks-with-balance (= (count networks-with-balance) 1))
|
||||
test-networks-enabled? (get-in db [:profile/profile :test-networks-enabled?])
|
||||
network-details (-> (get-in db
|
||||
[:wallet :networks
|
||||
(if test-networks-enabled? :test :prod)])
|
||||
(network-utils/sorted-networks-with-details))
|
||||
network (if balance-in-only-one-network?
|
||||
(first (filter #(= (:chain-id %)
|
||||
(:chain-id (first networks-with-balance)))
|
||||
network-details))
|
||||
network)]
|
||||
(println multi-account-balance? "43247329479847392")
|
||||
(when (or token-data token-symbol)
|
||||
{:db (cond-> db
|
||||
:always (update-in [:wallet :ui :send]
|
||||
network (update-in [:wallet :ui :send]
|
||||
#(-> %
|
||||
(dissoc :collectible :tx-type)
|
||||
(assoc :token-not-supported-in-receiver-networks?
|
||||
unsupported-token?)))
|
||||
(assoc :network network)))
|
||||
token-symbol (assoc-in [:wallet :ui :send :token-symbol] token-symbol)
|
||||
token-data (update-in [:wallet :ui :send]
|
||||
#(assoc %
|
||||
@@ -216,20 +195,45 @@
|
||||
(network-utils/network-list
|
||||
token-data
|
||||
network-details))
|
||||
:token-display-name (:symbol token-data)))
|
||||
:token-display-name (:symbol token-data)
|
||||
:token-symbol (:symbol token-data)))
|
||||
unique-owner (assoc-in [:wallet :current-viewing-account-address] unique-owner)
|
||||
entry-point (assoc-in [:wallet :ui :send :entry-point] entry-point))
|
||||
:fx [[:dispatch [:wallet/stop-and-clean-suggested-routes]]
|
||||
[:dispatch
|
||||
;; ^:flush-dom allows us to make sure the re-frame DB state is always synced
|
||||
;; before the navigation occurs, so the new screen is always rendered with
|
||||
;; the DB state set by this event. By adding the metadata we are omitting
|
||||
;; a 1-frame blink when the screen is mounted.
|
||||
^:flush-dom
|
||||
[:wallet/wizard-navigate-forward
|
||||
{:current-screen stack-id
|
||||
:start-flow? start-flow?
|
||||
:flow-id :wallet-send-flow}]]]}))))
|
||||
:fx (cond
|
||||
;; If the token has a balance in more than one account and this was dispatched from
|
||||
;; the general wallet screen, open the account selection screen.
|
||||
(and account-not-defined? root-screen?)
|
||||
[[:dispatch [:open-modal :screen/wallet.select-from]]]
|
||||
|
||||
;; If the token has a balance in only one account (or this was dispatched from the
|
||||
;; account screen) and the network is already set, stop and clean suggested routes,
|
||||
;; then navigate forward in the send flow.
|
||||
(some? network)
|
||||
[[:dispatch [:wallet/stop-and-clean-suggested-routes]]
|
||||
[:dispatch
|
||||
;; ^:flush-dom allows us to make sure the re-frame DB state is always synced
|
||||
;; before the navigation occurs, so the new screen is always rendered with
|
||||
;; the DB state set by this event. By adding the metadata we are omitting
|
||||
;; a 1-frame blink when the screen is mounted.
|
||||
^:flush-dom
|
||||
[:wallet/wizard-navigate-forward
|
||||
{:current-screen stack-id
|
||||
:start-flow? start-flow?
|
||||
:flow-id :wallet-send-flow}]]]
|
||||
|
||||
;; If we don't know the network but need to set it, show the network selection drawer.
|
||||
:else
|
||||
[[:dispatch
|
||||
[:show-bottom-sheet
|
||||
{:content (fn []
|
||||
[network-selection/view
|
||||
{:token-symbol (or token-symbol (:symbol token-data))
|
||||
:source :send
|
||||
:on-select-network (fn [network]
|
||||
(rf/dispatch [:hide-bottom-sheet])
|
||||
(rf/dispatch
|
||||
[:wallet/set-token-to-send
|
||||
(assoc params :network network)]))}])}]]])}))))
|
||||
|
||||
(rf/reg-event-fx
|
||||
:wallet/edit-token-to-send
|
||||
@@ -246,8 +250,7 @@
|
||||
(assoc-in [:wallet :ui :send :token-not-supported-in-receiver-networks?]
|
||||
token-not-supported-in-receiver-networks?))
|
||||
:fx [[:dispatch [:hide-bottom-sheet]]
|
||||
[:dispatch [:wallet/stop-and-clean-suggested-routes]]
|
||||
[:dispatch [:wallet/clean-from-locked-amounts]]]})))
|
||||
[:dispatch [:wallet/stop-and-clean-suggested-routes]]]})))
|
||||
|
||||
(rf/reg-event-fx :wallet/clean-selected-token
|
||||
(fn [{:keys [db]}]
|
||||
@@ -367,32 +370,15 @@
|
||||
(fn [{:keys [db]}]
|
||||
(let [keys-to-remove [:to-values-by-chain :network-links :sender-network-values :route
|
||||
:receiver-network-values :suggested-routes :from-values-by-chain
|
||||
:loading-suggested-routes? :amount]]
|
||||
:loading-suggested-routes? :amount :enough-assets?]]
|
||||
{:db (update-in db [:wallet :ui :send] #(apply dissoc % keys-to-remove))})))
|
||||
|
||||
(rf/reg-event-fx :wallet/disable-from-networks
|
||||
(fn [{:keys [db]} [chain-ids]]
|
||||
{:db (assoc-in db [:wallet :ui :send :disabled-from-chain-ids] chain-ids)}))
|
||||
|
||||
(rf/reg-event-fx :wallet/lock-from-amount
|
||||
(fn [{:keys [db]} [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]]
|
||||
{:db (update-in db [:wallet :ui :send :from-locked-amounts] dissoc chain-id)}))
|
||||
|
||||
(rf/reg-event-fx :wallet/reset-network-amounts-to-zero
|
||||
(fn [{:keys [db]}]
|
||||
(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])
|
||||
disabled-from-chain-ids (get-in db [:wallet :ui :send :disabled-from-chain-ids])
|
||||
sender-network-values (send-utils/reset-network-amounts-to-zero
|
||||
{:network-amounts sender-network-values
|
||||
:disabled-chain-ids disabled-from-chain-ids})
|
||||
receiver-network-values (send-utils/reset-network-amounts-to-zero
|
||||
{:network-amounts receiver-network-values
|
||||
:disabled-chain-ids []})]
|
||||
sender-network-values (send-utils/reset-network-amounts-to-zero sender-network-values)
|
||||
receiver-network-values (send-utils/reset-network-amounts-to-zero receiver-network-values)]
|
||||
{:db (-> db
|
||||
(assoc-in [:wallet :ui :send :sender-network-values] sender-network-values)
|
||||
(assoc-in [:wallet :ui :send :receiver-network-values] receiver-network-values)
|
||||
@@ -404,89 +390,62 @@
|
||||
|
||||
(rf/reg-event-fx :wallet/start-get-suggested-routes
|
||||
(fn [{:keys [db]} [{:keys [amount amount-out updated-token] :as args :or {amount-out "0"}}]]
|
||||
(let [wallet-address (get-in db [:wallet :current-viewing-account-address])
|
||||
(let [wallet-address (get-in db [:wallet :current-viewing-account-address])
|
||||
{:keys [token tx-type collectible to-address
|
||||
receiver-networks disabled-from-chain-ids
|
||||
from-locked-amounts bridge-to-chain-id]
|
||||
network bridge-to-chain-id]
|
||||
:or {token updated-token}} (get-in db [:wallet :ui :send])
|
||||
test-networks-enabled? (get-in db [:profile/profile :test-networks-enabled?])
|
||||
networks (get-in db [:wallet :networks (if test-networks-enabled? :test :prod)])
|
||||
network-chain-ids (map :chain-id networks)
|
||||
token-decimal (when token (:decimals token))
|
||||
token-id (utils/format-token-id token collectible)
|
||||
to-token-id ""
|
||||
gas-rates constants/gas-rate-medium
|
||||
to-hex (fn [v] (send-utils/amount-in-hex v (if token token-decimal 0)))
|
||||
amount-in (to-hex amount)
|
||||
amount-out (to-hex amount-out)
|
||||
from-address wallet-address
|
||||
disabled-to-chain-ids (if (= tx-type :tx/bridge)
|
||||
(filter #(not= % bridge-to-chain-id) network-chain-ids)
|
||||
(filter (fn [chain-id]
|
||||
(not (some #(= chain-id %)
|
||||
receiver-networks)))
|
||||
network-chain-ids))
|
||||
from-locked-amount (update-vals from-locked-amounts to-hex)
|
||||
send-type (case tx-type
|
||||
:tx/collectible-erc-721 constants/send-type-erc-721-transfer
|
||||
:tx/collectible-erc-1155 constants/send-type-erc-1155-transfer
|
||||
:tx/bridge constants/send-type-bridge
|
||||
constants/send-type-transfer)
|
||||
balances-per-chain (when token (:balances-per-chain token))
|
||||
sender-token-available-networks-for-suggested-routes
|
||||
(when token
|
||||
(send-utils/token-available-networks-for-suggested-routes
|
||||
{:balances-per-chain balances-per-chain
|
||||
:disabled-chain-ids disabled-from-chain-ids
|
||||
:only-with-balance? true}))
|
||||
receiver-token-available-networks-for-suggested-routes
|
||||
(when token
|
||||
(send-utils/token-available-networks-for-suggested-routes
|
||||
{:balances-per-chain balances-per-chain
|
||||
:disabled-chain-ids disabled-from-chain-ids
|
||||
:only-with-balance? false}))
|
||||
token-networks-ids (when token (map #(:chain-id %) (:supported-networks token)))
|
||||
sender-network-values (when sender-token-available-networks-for-suggested-routes
|
||||
(send-utils/loading-network-amounts
|
||||
{:valid-networks
|
||||
(if (= tx-type :tx/bridge)
|
||||
(remove #(= bridge-to-chain-id %)
|
||||
sender-token-available-networks-for-suggested-routes)
|
||||
sender-token-available-networks-for-suggested-routes)
|
||||
:disabled-chain-ids disabled-from-chain-ids
|
||||
:receiver-networks receiver-networks
|
||||
:token-networks-ids token-networks-ids
|
||||
:tx-type tx-type
|
||||
:receiver? false}))
|
||||
receiver-network-values (when receiver-token-available-networks-for-suggested-routes
|
||||
(send-utils/loading-network-amounts
|
||||
{:valid-networks
|
||||
(if (= tx-type :tx/bridge)
|
||||
(filter
|
||||
#(= bridge-to-chain-id %)
|
||||
receiver-token-available-networks-for-suggested-routes)
|
||||
receiver-token-available-networks-for-suggested-routes)
|
||||
:disabled-chain-ids disabled-from-chain-ids
|
||||
:receiver-networks receiver-networks
|
||||
:token-networks-ids token-networks-ids
|
||||
:tx-type tx-type
|
||||
:receiver? true}))
|
||||
request-uuid (str (random-uuid))
|
||||
params [{:uuid request-uuid
|
||||
:sendType send-type
|
||||
:addrFrom from-address
|
||||
:addrTo to-address
|
||||
:amountIn amount-in
|
||||
:amountOut amount-out
|
||||
:tokenID token-id
|
||||
:toTokenID to-token-id
|
||||
:disabledFromChainIDs disabled-from-chain-ids
|
||||
:disabledToChainIDs disabled-to-chain-ids
|
||||
:gasFeeMode gas-rates
|
||||
:fromLockedAmount from-locked-amount
|
||||
:username (:username args)
|
||||
:publicKey (:publicKey args)
|
||||
:packID (:packID args)}]]
|
||||
test-networks-enabled? (get-in db [:profile/profile :test-networks-enabled?])
|
||||
networks (get-in db
|
||||
[:wallet :networks
|
||||
(if test-networks-enabled? :test :prod)])
|
||||
network-chain-ids (map :chain-id networks)
|
||||
token-decimal (when token (:decimals token))
|
||||
token-id (utils/format-token-id token collectible)
|
||||
to-token-id ""
|
||||
gas-rates constants/gas-rate-medium
|
||||
to-hex (fn [v] (send-utils/amount-in-hex v (if token token-decimal 0)))
|
||||
amount-in (to-hex amount)
|
||||
amount-out (to-hex amount-out)
|
||||
from-address wallet-address
|
||||
network-chain-id (if collectible
|
||||
(get-in collectible [:id :contract-id :chain-id])
|
||||
(:chain-id network))
|
||||
disabled-from-chain-ids (filter #(not= % network-chain-id) network-chain-ids)
|
||||
disabled-to-chain-ids (filter #(not= %
|
||||
(if (= tx-type :tx/bridge)
|
||||
bridge-to-chain-id
|
||||
network-chain-id))
|
||||
network-chain-ids)
|
||||
send-type (case tx-type
|
||||
:tx/collectible-erc-721 constants/send-type-erc-721-transfer
|
||||
:tx/collectible-erc-1155 constants/send-type-erc-1155-transfer
|
||||
:tx/bridge constants/send-type-bridge
|
||||
constants/send-type-transfer)
|
||||
sender-network-values (when (= tx-type :tx/bridge)
|
||||
(send-utils/loading-network-amounts
|
||||
{:networks [network-chain-id]
|
||||
:values {network-chain-id amount}
|
||||
:receiver? false}))
|
||||
receiver-network-values (when (= tx-type :tx/bridge)
|
||||
(send-utils/loading-network-amounts
|
||||
{:networks [bridge-to-chain-id]
|
||||
:receiver? true}))
|
||||
request-uuid (str (random-uuid))
|
||||
params [{:uuid request-uuid
|
||||
:sendType send-type
|
||||
:addrFrom from-address
|
||||
:addrTo to-address
|
||||
:amountIn amount-in
|
||||
:amountOut amount-out
|
||||
:tokenID token-id
|
||||
:toTokenID to-token-id
|
||||
:disabledFromChainIDs disabled-from-chain-ids
|
||||
:disabledToChainIDs disabled-to-chain-ids
|
||||
:gasFeeMode gas-rates
|
||||
:fromLockedAmount {}
|
||||
:username (:username args)
|
||||
:publicKey (:publicKey args)
|
||||
:packID (:packID args)}]]
|
||||
(when (and to-address from-address amount-in token-id)
|
||||
{:db (update-in db
|
||||
[:wallet :ui :send]
|
||||
@@ -623,7 +582,6 @@
|
||||
[:dispatch [:wallet/clean-scanned-address]]
|
||||
[:dispatch [:wallet/clean-local-suggestions]]
|
||||
[:dispatch [:wallet/clean-send-address]]
|
||||
[:dispatch [:wallet/clean-disabled-from-networks]]
|
||||
[:dispatch [:wallet/select-address-tab nil]]]}))
|
||||
|
||||
(rf/reg-event-fx :wallet/end-transaction-flow
|
||||
@@ -712,34 +670,60 @@
|
||||
|
||||
(rf/reg-event-fx
|
||||
:wallet/select-from-account
|
||||
(fn [{db :db} [{:keys [address stack-id network-details start-flow?]}]]
|
||||
(fn [{db :db} [{:keys [address stack-id network-details network start-flow?] :as params}]]
|
||||
(let [{:keys [token-symbol
|
||||
tx-type]} (-> db :wallet :ui :send)
|
||||
token (when token-symbol
|
||||
;; When this flow has started in the wallet home page, we know the
|
||||
;; token or collectible to send, but we don't know from which
|
||||
;; account, so we extract the token data from the picked account.
|
||||
(let [token (utils/get-token-from-account db token-symbol address)]
|
||||
(assoc token
|
||||
:networks (network-utils/network-list-with-positive-balance
|
||||
token
|
||||
network-details)
|
||||
:supported-networks (network-utils/network-list token
|
||||
network-details)
|
||||
:total-balance (utils/calculate-total-token-balance token))))
|
||||
bridge-tx? (= tx-type :tx/bridge)
|
||||
flow-id (if bridge-tx?
|
||||
:wallet-bridge-flow
|
||||
:wallet-send-flow)]
|
||||
tx-type]} (-> db :wallet :ui :send)
|
||||
token (when token-symbol
|
||||
;; When this flow has started in the wallet home page, we
|
||||
;; know the token or collectible to send, but we don't know
|
||||
;; from which account, so we extract the token data from the
|
||||
;; picked account.
|
||||
(let [token (utils/get-token-from-account db
|
||||
token-symbol
|
||||
address)]
|
||||
(utils/token-with-balance token network-details)))
|
||||
bridge-tx? (= tx-type :tx/bridge)
|
||||
flow-id (if bridge-tx?
|
||||
:wallet-bridge-flow
|
||||
:wallet-send-flow)
|
||||
networks-with-balance (when (and token (:balances-per-chain token))
|
||||
(filter #(not= (:balance %) "0")
|
||||
(vals (:balances-per-chain token))))
|
||||
balance-in-only-one-network? (when networks-with-balance (= (count networks-with-balance) 1))
|
||||
test-networks-enabled? (get-in db [:profile/profile :test-networks-enabled?])
|
||||
network-details (-> (get-in db
|
||||
[:wallet :networks
|
||||
(if test-networks-enabled? :test :prod)])
|
||||
(network-utils/sorted-networks-with-details))
|
||||
network (if balance-in-only-one-network?
|
||||
(first (filter #(= (:chain-id %)
|
||||
(:chain-id (first networks-with-balance)))
|
||||
network-details))
|
||||
network)]
|
||||
{:db (cond-> db
|
||||
network (assoc-in [:wallet :ui :send :network] network)
|
||||
token-symbol (assoc-in [:wallet :ui :send :token] token)
|
||||
bridge-tx? (assoc-in [:wallet :ui :send :to-address] address))
|
||||
:fx [[:dispatch [:wallet/switch-current-viewing-account address]]
|
||||
[:dispatch
|
||||
[:wallet/wizard-navigate-forward
|
||||
{:current-screen stack-id
|
||||
:start-flow? start-flow?
|
||||
:flow-id flow-id}]]]})))
|
||||
:fx (if (some? network)
|
||||
[[:dispatch [:wallet/switch-current-viewing-account address]]
|
||||
[:dispatch
|
||||
[:wallet/wizard-navigate-forward
|
||||
{:current-screen stack-id
|
||||
:start-flow? (and start-flow? (not balance-in-only-one-network?))
|
||||
:flow-id flow-id}]]]
|
||||
[[:dispatch [:dismiss-modal :screen/wallet.select-from]]
|
||||
[:dispatch [:wallet/switch-current-viewing-account address]]
|
||||
[:dispatch
|
||||
[:show-bottom-sheet
|
||||
{:content (fn []
|
||||
[network-selection/view
|
||||
{:token-symbol (or token-symbol (:symbol token))
|
||||
:source :send
|
||||
:on-select-network (fn [network]
|
||||
(rf/dispatch [:hide-bottom-sheet])
|
||||
(rf/dispatch
|
||||
[:wallet/select-from-account
|
||||
(assoc params :network network)]))}])}]]])})))
|
||||
|
||||
(rf/reg-event-fx
|
||||
:wallet/transaction-confirmation-navigate-back
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
(ns status-im.contexts.wallet.send.events-test
|
||||
(:require
|
||||
[cljs.test :refer-macros [is testing]]
|
||||
[matcher-combinators.matchers :as m]
|
||||
matcher-combinators.test
|
||||
[re-frame.db :as rf-db]
|
||||
[status-im.contexts.wallet.common.utils.networks :as network-utils]
|
||||
status-im.contexts.wallet.send.events
|
||||
[status-im.contexts.wallet.send.utils :as send-utils]
|
||||
[test-helpers.unit :as h]
|
||||
@@ -40,19 +40,17 @@
|
||||
receiver-networks [421614 11155420]]
|
||||
(testing "can be called with :token"
|
||||
(let [initial-db {:wallet {:ui {:send {:receiver-networks receiver-networks}}}}
|
||||
expected-db {:wallet {:ui {:send {:token-display-name token-symbol
|
||||
:token-not-supported-in-receiver-networks? false}}}}
|
||||
expected-db {:wallet {:ui {:send {:token-display-name token-symbol
|
||||
:token-symbol token-symbol}}}}
|
||||
_ (reset! rf-db/app-db initial-db)
|
||||
result (dispatch [event-id {:token token}])]
|
||||
(is (match? expected-db (:db result)))))
|
||||
(testing "can be called with :token-symbol"
|
||||
(testing "can be called with :token"
|
||||
(let [initial-db {:wallet {:ui {:send {:receiver-networks receiver-networks}}}}
|
||||
expected-db {:wallet {:ui {:send {:token-symbol token-symbol
|
||||
:token-not-supported-in-receiver-networks? true}}}}
|
||||
_ (reset! rf-db/app-db initial-db)
|
||||
result (dispatch [event-id {:token-symbol token-symbol}])]
|
||||
(is (match? expected-db (:db result))))))
|
||||
(let [initial-db {:wallet {:ui {:send {:receiver-networks receiver-networks}}}}
|
||||
expected-db {:wallet {:ui {:send {:token-symbol token-symbol}}}}
|
||||
_ (reset! rf-db/app-db initial-db)
|
||||
result (dispatch [event-id {:token-symbol token-symbol}])]
|
||||
(is (match? expected-db (:db result)))))
|
||||
(testing "shouldn't have changes if called without :token or :token-symbol")
|
||||
(let [initial-db {:wallet {:ui {:send {:receiver-networks receiver-networks}}}}
|
||||
expected-db nil
|
||||
@@ -62,16 +60,16 @@
|
||||
(testing "should clean :collectible set"
|
||||
(let [initial-db {:wallet {:ui {:send {:receiver-networks receiver-networks
|
||||
:collectible "some-collectible"}}}}
|
||||
expected-db {:wallet {:ui {:send {:token-display-name token-symbol
|
||||
:token-not-supported-in-receiver-networks? false}}}}
|
||||
expected-db {:wallet {:ui {:send {:token-display-name token-symbol}}}}
|
||||
_ (reset! rf-db/app-db initial-db)
|
||||
result (dispatch [event-id {:token token}])]
|
||||
result (dispatch [event-id
|
||||
{:token token
|
||||
:network "network"}])]
|
||||
(is (match? expected-db (:db result)))
|
||||
(is (match? nil (get-in result [:db :wallet :ui :send :collectible])))))
|
||||
(testing "should set :token-not-supported-in-receiver-networks?"
|
||||
(let [initial-db {:wallet {:ui {:send {:receiver-networks []}}}}
|
||||
expected-db {:wallet {:ui {:send {:token-display-name token-symbol
|
||||
:token-not-supported-in-receiver-networks? true}}}}
|
||||
expected-db {:wallet {:ui {:send {:token-display-name token-symbol}}}}
|
||||
_ (reset! rf-db/app-db initial-db)
|
||||
result (dispatch [event-id {:token token}])]
|
||||
(is (match? expected-db (:db result)))))))
|
||||
@@ -211,47 +209,6 @@
|
||||
:other-props :value}}}})
|
||||
(is (match-strict? expected-db (:db (dispatch [event-id]))))))
|
||||
|
||||
(h/deftest-event :wallet/clean-disabled-from-networks
|
||||
[event-id dispatch]
|
||||
(let [expected-db {:wallet {:ui {:send {:other-props :value}}}}]
|
||||
(reset! rf-db/app-db
|
||||
{:wallet {:ui {:send {:disabled-from-chain-ids [:optimism]
|
||||
:other-props :value}}}})
|
||||
(is (match-strict? expected-db (:db (dispatch [event-id]))))))
|
||||
|
||||
(h/deftest-event :wallet/clean-from-locked-amounts
|
||||
[event-id dispatch]
|
||||
(let [expected-db {:wallet {:ui {:send {:other-props :value}}}}]
|
||||
(reset! rf-db/app-db
|
||||
{:wallet {:ui {:send {:from-locked-amounts "value"
|
||||
:other-props :value}}}})
|
||||
(is (match-strict? expected-db (:db (dispatch [event-id]))))))
|
||||
|
||||
(h/deftest-event :wallet/disable-from-networks
|
||||
[event-id dispatch]
|
||||
(let [expected-db {:wallet {:ui {:send {:disabled-from-chain-ids [:optimism]
|
||||
:other-props :value}}}}]
|
||||
(reset! rf-db/app-db
|
||||
{:wallet {:ui {:send {:other-props :value}}}})
|
||||
(is (match? expected-db (:db (dispatch [event-id [:optimism]]))))))
|
||||
|
||||
(h/deftest-event :wallet/unlock-from-amount
|
||||
[event-id dispatch]
|
||||
(let [expected-db {:wallet {:ui {:send {:other-props :value
|
||||
:from-locked-amounts {}}}}}]
|
||||
(reset! rf-db/app-db
|
||||
{:wallet {:ui {:send {:other-props :value
|
||||
:from-locked-amounts {:chain-id [1 10]}}}}})
|
||||
(is (match? expected-db (:db (dispatch [event-id :chain-id]))))))
|
||||
|
||||
(h/deftest-event :wallet/lock-from-amount
|
||||
[event-id dispatch]
|
||||
(let [expected-db {:wallet {:ui {:send {:other-props :value
|
||||
:from-locked-amounts {:amount 10}}}}}]
|
||||
(reset! rf-db/app-db
|
||||
{:wallet {:ui {:send {:other-props :value}}}})
|
||||
(is (match? expected-db (:db (dispatch [event-id :amount 10]))))))
|
||||
|
||||
(h/deftest-event :wallet/clean-selected-token
|
||||
[event-id dispatch]
|
||||
(let [expected-db {:wallet {:ui {:send {:other-props :value}}}}]
|
||||
@@ -303,13 +260,8 @@
|
||||
(let [sender-network-values [{:chain-id 1 :total-amount (money/bignumber "100") :type :default}
|
||||
{:chain-id 10 :total-amount (money/bignumber "200") :type :default}]
|
||||
receiver-network-values [{:chain-id 1 :total-amount (money/bignumber "100") :type :loading}]
|
||||
disabled-from-chain-ids [:ethereum]
|
||||
sender-network-zero (send-utils/reset-network-amounts-to-zero
|
||||
{:network-amounts sender-network-values
|
||||
:disabled-chain-ids disabled-from-chain-ids})
|
||||
receiver-network-zero (send-utils/reset-network-amounts-to-zero
|
||||
{:network-amounts receiver-network-values
|
||||
:disabled-chain-ids []})]
|
||||
sender-network-zero (send-utils/reset-network-amounts-to-zero sender-network-values)
|
||||
receiver-network-zero (send-utils/reset-network-amounts-to-zero receiver-network-values)]
|
||||
(testing "if sender-network-value and receiver-network-value are not empty"
|
||||
(let [expected-db {:wallet {:ui {:send {:other-props :value
|
||||
:sender-network-values sender-network-zero
|
||||
@@ -347,7 +299,6 @@
|
||||
(h/deftest-event :wallet/select-send-address
|
||||
[event-id dispatch]
|
||||
(let [address "eth:arb1:0x01"
|
||||
prefix "eth:arb1:"
|
||||
to-address "0x01"
|
||||
recipient {:type :saved-address
|
||||
:label "0x01...23f"}
|
||||
@@ -355,27 +306,20 @@
|
||||
start-flow? false
|
||||
tx-type :tx/collectible-erc-721]
|
||||
(testing "testing when collectible balance is more than 1"
|
||||
(let [collectible (collectible-with-balance 2)
|
||||
testnet-enabled? false
|
||||
receiver-networks (network-utils/resolve-receiver-networks
|
||||
{:prefix prefix
|
||||
:testnet-enabled? testnet-enabled?})
|
||||
expected-result {:db {:wallet {:ui {:send {:other-props :value
|
||||
:recipient recipient
|
||||
:to-address to-address
|
||||
:address-prefix prefix
|
||||
:receiver-preferred-networks
|
||||
receiver-networks
|
||||
:receiver-networks receiver-networks
|
||||
:tx-type tx-type
|
||||
:collectible collectible}}}
|
||||
:profile/profile {:test-networks-enabled? false}}
|
||||
:fx [nil
|
||||
[:dispatch
|
||||
[:wallet/wizard-navigate-forward
|
||||
{:current-screen stack-id
|
||||
:start-flow? start-flow?
|
||||
:flow-id :wallet-send-flow}]]]}]
|
||||
(let [collectible (collectible-with-balance 2)
|
||||
testnet-enabled? false
|
||||
expected-result {:db {:wallet {:ui {:send {:other-props :value
|
||||
:recipient recipient
|
||||
:to-address to-address
|
||||
:tx-type tx-type
|
||||
:collectible collectible}}}
|
||||
:profile/profile {:test-networks-enabled? false}}
|
||||
:fx [nil
|
||||
[:dispatch
|
||||
[:wallet/wizard-navigate-forward
|
||||
{:current-screen stack-id
|
||||
:start-flow? start-flow?
|
||||
:flow-id :wallet-send-flow}]]]}]
|
||||
(reset! rf-db/app-db
|
||||
{:wallet {:ui {:send {:other-props :value
|
||||
:tx-type tx-type
|
||||
@@ -388,27 +332,20 @@
|
||||
:stack-id stack-id
|
||||
:start-flow? start-flow?}])))))
|
||||
(testing "testing when collectible balance is 1"
|
||||
(let [collectible (collectible-with-balance 1)
|
||||
testnet-enabled? false
|
||||
receiver-networks (network-utils/resolve-receiver-networks
|
||||
{:prefix prefix
|
||||
:testnet-enabled? testnet-enabled?})
|
||||
expected-result {:db {:wallet {:ui {:send {:other-props :value
|
||||
:recipient recipient
|
||||
:to-address to-address
|
||||
:address-prefix prefix
|
||||
:receiver-preferred-networks
|
||||
receiver-networks
|
||||
:receiver-networks receiver-networks
|
||||
:tx-type tx-type
|
||||
:collectible collectible}}}
|
||||
:profile/profile {:test-networks-enabled? false}}
|
||||
:fx [[:dispatch [:wallet/start-get-suggested-routes {:amount 1}]]
|
||||
[:dispatch
|
||||
[:wallet/wizard-navigate-forward
|
||||
{:current-screen stack-id
|
||||
:start-flow? start-flow?
|
||||
:flow-id :wallet-send-flow}]]]}]
|
||||
(let [collectible (collectible-with-balance 1)
|
||||
testnet-enabled? false
|
||||
expected-result {:db {:wallet {:ui {:send {:other-props :value
|
||||
:recipient recipient
|
||||
:to-address to-address
|
||||
:tx-type tx-type
|
||||
:collectible collectible}}}
|
||||
:profile/profile {:test-networks-enabled? false}}
|
||||
:fx [[:dispatch [:wallet/start-get-suggested-routes {:amount 1}]]
|
||||
[:dispatch
|
||||
[:wallet/wizard-navigate-forward
|
||||
{:current-screen stack-id
|
||||
:start-flow? start-flow?
|
||||
:flow-id :wallet-send-flow}]]]}]
|
||||
(reset! rf-db/app-db
|
||||
{:wallet {:ui {:send {:other-props :value
|
||||
:tx-type tx-type
|
||||
@@ -484,7 +421,6 @@
|
||||
:networks #{{:chain-id 421614}
|
||||
{:chain-id 11155420}
|
||||
{:chain-id 11155111}}}
|
||||
token-networks (:networks token)
|
||||
routes-available? (pos? (count chosen-route))
|
||||
sender-network-values [1 10]
|
||||
receiver-network-values [1 10]
|
||||
@@ -506,37 +442,18 @@
|
||||
to-network-values-for-ui (send-utils/network-values-for-ui to-network-amounts-by-chain)
|
||||
tx-type :tx/collectible-erc-1155
|
||||
from-network-values-for-ui (send-utils/network-values-for-ui from-network-amounts-by-chain)
|
||||
disabled-from-chain-ids [:421614]
|
||||
token-networks-ids (when token-networks (mapv #(:chain-id %) token-networks))
|
||||
sender-possible-chain-ids (mapv :chain-id sender-network-values)
|
||||
receiver-network-values (if routes-available?
|
||||
(send-utils/network-amounts
|
||||
{:network-values to-network-values-for-ui
|
||||
:disabled-chain-ids disabled-from-chain-ids
|
||||
:receiver-networks receiver-networks
|
||||
:token-networks-ids token-networks-ids
|
||||
:tx-type tx-type
|
||||
:receiver? true})
|
||||
(cond->
|
||||
(send-utils/reset-loading-network-amounts-to-zero
|
||||
receiver-network-values)
|
||||
|
||||
(not= tx-type :tx/bridge)
|
||||
send-utils/safe-add-type-edit))
|
||||
(send-utils/network-amounts to-network-values-for-ui)
|
||||
(send-utils/reset-loading-network-amounts-to-zero
|
||||
receiver-network-values))
|
||||
sender-network-values (if routes-available?
|
||||
(send-utils/network-amounts
|
||||
{:network-values
|
||||
(if (= tx-type :tx/bridge)
|
||||
(if (= tx-type :tx/bridge)
|
||||
from-network-values-for-ui
|
||||
(send-utils/add-zero-values-to-network-values
|
||||
from-network-values-for-ui
|
||||
(send-utils/add-zero-values-to-network-values
|
||||
from-network-values-for-ui
|
||||
sender-possible-chain-ids))
|
||||
:disabled-chain-ids disabled-from-chain-ids
|
||||
:receiver-networks receiver-networks
|
||||
:token-networks-ids token-networks-ids
|
||||
:from-locked-amounts {}
|
||||
:tx-type tx-type
|
||||
:receiver? false})
|
||||
sender-possible-chain-ids)))
|
||||
(send-utils/reset-loading-network-amounts-to-zero
|
||||
sender-network-values))
|
||||
expected-db {:wallet {:ui {:send
|
||||
@@ -544,7 +461,6 @@
|
||||
:suggested-routes suggested-routes-data
|
||||
:route chosen-route
|
||||
:token token
|
||||
:disabled-from-chain-ids disabled-from-chain-ids
|
||||
:suggested-routes-call-timestamp timestamp
|
||||
:collectible (collectible-with-balance 1)
|
||||
:token-display-name token-symbol
|
||||
@@ -559,8 +475,7 @@
|
||||
chosen-route
|
||||
sender-network-values
|
||||
receiver-network-values))
|
||||
:loading-suggested-routes? false
|
||||
:from-locked-amounts {}}}}}]
|
||||
:loading-suggested-routes? false}}}}]
|
||||
(reset! rf-db/app-db
|
||||
{:wallet {:ui {:send {:other-props :value
|
||||
:suggested-routes-call-timestamp timestamp
|
||||
@@ -570,17 +485,29 @@
|
||||
:receiver-networks receiver-networks
|
||||
:receiver-network-values [1 10]
|
||||
:sender-network-values [1 10]
|
||||
:tx-type tx-type
|
||||
:disabled-from-chain-ids disabled-from-chain-ids
|
||||
:from-locked-amounts {}}}}})
|
||||
:tx-type tx-type}}}})
|
||||
(is (match? expected-db (:db (dispatch [event-id suggested-routes timestamp]))))))
|
||||
|
||||
(h/deftest-event :wallet/select-from-account
|
||||
[event-id dispatch]
|
||||
(let [stack-id :screen/stack
|
||||
start-flow? false
|
||||
address "0x01"]
|
||||
address "0x01"
|
||||
network {:chain-id 1}]
|
||||
(testing "when tx-type is :tx/bridge and token-symbol is nil"
|
||||
(let [tx-type :tx/bridge
|
||||
expected-result {:db {:wallet {:ui {:send {:to-address address
|
||||
:tx-type tx-type}}}}
|
||||
:fx [[:dispatch [:dismiss-modal :screen/wallet.select-from]]
|
||||
[:dispatch [:wallet/switch-current-viewing-account address]]
|
||||
[:dispatch [:show-bottom-sheet {:content (m/pred fn?)}]]]}]
|
||||
(reset! rf-db/app-db {:wallet {:ui {:send {:tx-type tx-type}}}})
|
||||
(is (match? expected-result
|
||||
(dispatch [event-id
|
||||
{:address address
|
||||
:stack-id stack-id
|
||||
:start-flow? start-flow?}])))))
|
||||
(testing "when tx-type is :tx/bridge, network is selected and token-symbol is nil"
|
||||
(let [flow-id :wallet-bridge-flow
|
||||
tx-type :tx/bridge
|
||||
expected-result {:db {:wallet {:ui {:send {:to-address address
|
||||
@@ -596,6 +523,7 @@
|
||||
(dispatch [event-id
|
||||
{:address address
|
||||
:stack-id stack-id
|
||||
:network network
|
||||
:start-flow? start-flow?}])))))
|
||||
(testing "when tx-type is not :tx/bridge and token-symbol is nil"
|
||||
(let [flow-id :wallet-send-flow
|
||||
@@ -612,42 +540,22 @@
|
||||
(dispatch [event-id
|
||||
{:address address
|
||||
:stack-id stack-id
|
||||
:network network
|
||||
:start-flow? start-flow?}])))))
|
||||
(testing "when tx-type is :tx/bridge and token-symbol is not nil"
|
||||
(let [flow-id :wallet-bridge-flow
|
||||
tx-type :tx/bridge
|
||||
tokens [{:symbol "ETH"
|
||||
:chain-id 1
|
||||
:balances-per-chain {1 {:raw-balance (money/bignumber 100)}
|
||||
10 {:raw-balance (money/bignumber 200)}
|
||||
42161 {:raw-balance (money/bignumber 300)}}
|
||||
:decimals 2}]
|
||||
network-details #{{:chain-id 1}
|
||||
{:chain-id 10}
|
||||
{:chain-id 42161}}
|
||||
expected-result {:db {:wallet {:ui {:send {:to-address address
|
||||
:tx-type tx-type
|
||||
:token-symbol "ETH"
|
||||
:token (assoc (first tokens)
|
||||
:networks #{nil}
|
||||
:total-balance
|
||||
(money/bignumber 6))}}
|
||||
:accounts {address {:tokens tokens}}}}
|
||||
:fx [[:dispatch [:wallet/switch-current-viewing-account address]]
|
||||
[:dispatch
|
||||
[:wallet/wizard-navigate-forward
|
||||
{:current-screen stack-id
|
||||
:start-flow? start-flow?
|
||||
:flow-id flow-id}]]]}]
|
||||
(reset! rf-db/app-db {:wallet {:ui {:send {:tx-type tx-type
|
||||
:token-symbol "ETH"}}
|
||||
:accounts {address {:tokens tokens}}}})
|
||||
(let [tx-type :tx/bridge
|
||||
expected-result {:db {:wallet {:ui {:send {:to-address address
|
||||
:tx-type tx-type}}}}
|
||||
:fx [[:dispatch [:dismiss-modal :screen/wallet.select-from]]
|
||||
[:dispatch [:wallet/switch-current-viewing-account address]]
|
||||
[:dispatch [:show-bottom-sheet {:content (m/pred fn?)}]]]}]
|
||||
(reset! rf-db/app-db {:wallet {:ui {:send {:tx-type tx-type
|
||||
:token-symbol "ETH"}}}})
|
||||
(is (match? expected-result
|
||||
(dispatch [event-id
|
||||
{:address address
|
||||
:stack-id stack-id
|
||||
:start-flow? start-flow?
|
||||
:netork-details network-details}])))))
|
||||
{:address address
|
||||
:stack-id stack-id
|
||||
:start-flow? start-flow?}])))))
|
||||
(testing "when tx-type is not :tx/bridge and token-symbol is not nil"
|
||||
(let [flow-id :wallet-send-flow
|
||||
tx-type :tx/collectible-erc-721
|
||||
@@ -680,5 +588,6 @@
|
||||
(dispatch [event-id
|
||||
{:address address
|
||||
:stack-id stack-id
|
||||
:network network
|
||||
:start-flow? start-flow?
|
||||
:netork-details network-details}])))))))
|
||||
|
||||
@@ -14,9 +14,7 @@
|
||||
(-> db :wallet :ui :send :token some?))
|
||||
|
||||
(def steps
|
||||
[{:screen-id :screen/wallet.select-from
|
||||
:skip-step? (fn [db] (some? (get-in db [:wallet :current-viewing-account-address])))}
|
||||
{:screen-id :screen/wallet.select-address
|
||||
[{:screen-id :screen/wallet.select-address
|
||||
:skip-step? (fn [db] (some? (get-in db [:wallet :ui :send :recipient])))}
|
||||
{:screen-id :screen/wallet.select-asset
|
||||
:skip-step? (fn [db] (or (token-selected? db) (collectible-selected? db)))}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
(ns status-im.contexts.wallet.send.from.view
|
||||
(:require
|
||||
[clojure.string :as string]
|
||||
[quo.core :as quo]
|
||||
[react-native.core :as rn]
|
||||
[react-native.safe-area :as safe-area]
|
||||
[status-im.common.floating-button-page.view :as floating-button-page]
|
||||
[status-im.contexts.wallet.common.account-switcher.view :as account-switcher]
|
||||
[status-im.contexts.wallet.send.from.style :as style]
|
||||
[status-im.setup.hot-reload :as hot-reload]
|
||||
[utils.i18n :as i18n]
|
||||
[utils.money :as money]
|
||||
[utils.re-frame :as rf]))
|
||||
|
||||
(defn- on-account-press
|
||||
@@ -15,27 +16,29 @@
|
||||
(rf/dispatch [:wallet/select-from-account
|
||||
{:address address
|
||||
:network-details network-details
|
||||
:stack-id :screen/wallet.select-from}]))
|
||||
|
||||
(defn- on-close
|
||||
[]
|
||||
(rf/dispatch [:wallet/clean-current-viewing-account]))
|
||||
:stack-id :screen/wallet.select-from
|
||||
:start-flow? true}]))
|
||||
|
||||
(defn- render-fn
|
||||
[item _ _ {:keys [network-details]}]
|
||||
(let [transformed-address (rf/sub [:wallet/account-address (:address item)
|
||||
(:network-preferences-names item)])]
|
||||
(let [has-balance (money/above-zero? (string/replace-first (:asset-pay-balance item) "<" ""))]
|
||||
[quo/account-item
|
||||
{:on-press #(on-account-press (:address item) network-details)
|
||||
{:type (if has-balance :tag :default)
|
||||
:on-press #(on-account-press (:address item) network-details)
|
||||
:state (if has-balance :default :disabled)
|
||||
:token-props {:symbol (:asset-pay-symbol item)
|
||||
:value (:asset-pay-balance item)}
|
||||
:account-props (assoc item
|
||||
:address transformed-address
|
||||
:address (:formatted-address item)
|
||||
:full-address? true)}]))
|
||||
|
||||
(defn view
|
||||
[]
|
||||
(let [accounts (rf/sub [:wallet/accounts-with-current-asset])
|
||||
(let [token-symbol (rf/sub [:wallet/send-token-symbol])
|
||||
token (rf/sub [:wallet/token-by-symbol-from-first-available-account-with-balance
|
||||
token-symbol])
|
||||
accounts (rf/sub [:wallet/accounts-with-balances token])
|
||||
network-details (rf/sub [:wallet/network-details])]
|
||||
(hot-reload/use-safe-unmount on-close)
|
||||
[floating-button-page/view
|
||||
{:footer-container-padding 0
|
||||
:header [account-switcher/view
|
||||
|
||||
@@ -12,103 +12,92 @@
|
||||
(set! debounce/debounce-and-dispatch #())
|
||||
|
||||
(def sub-mocks
|
||||
{:profile/profile {:currency :usd}
|
||||
:wallet/selected-network-details [{:source 525
|
||||
:short-name "eth"
|
||||
:network-name :mainnet
|
||||
:chain-id 1
|
||||
:related-chain-id 5}]
|
||||
:wallet/current-viewing-account-address "0x1"
|
||||
:wallet/current-viewing-account {:path "m/44'/60'/0'/0/1"
|
||||
:emoji "💎"
|
||||
:key-uid "0x2f5ea39"
|
||||
:address "0x1"
|
||||
:wallet false
|
||||
:name "Account One"
|
||||
:type :generated
|
||||
:watch-only? false
|
||||
:chat false
|
||||
:test-preferred-chain-ids #{5 420 421613}
|
||||
:color :purple
|
||||
:hidden false
|
||||
:prod-preferred-chain-ids #{1 10 42161}
|
||||
:network-preferences-names #{:mainnet :arbitrum
|
||||
:optimism}
|
||||
:position 1
|
||||
:clock 1698945829328
|
||||
:created-at 1698928839000
|
||||
:operable :fully
|
||||
:mixedcase-address "0x7bcDfc75c431"
|
||||
:public-key "0x04371e2d9d66b82f056bc128064"
|
||||
:removed false}
|
||||
:wallet/current-viewing-account-color :purple
|
||||
:wallet/wallet-send-enough-assets? true
|
||||
:wallet/wallet-send-token {:symbol "ETH"
|
||||
:networks [{:source 879
|
||||
:short-name "eth"
|
||||
:network-name :mainnet
|
||||
:abbreviated-name
|
||||
"Eth."
|
||||
:full-name "Mainnet"
|
||||
:chain-id 1
|
||||
:related-chain-id 1
|
||||
:layer 1}]
|
||||
:balances-per-chain {1 {:raw-balance
|
||||
(money/bignumber
|
||||
"2500")
|
||||
:has-error false}}
|
||||
:total-balance 100
|
||||
:available-balance 100}
|
||||
:wallet/wallet-send-loading-suggested-routes? false
|
||||
:wallet/wallet-send-route [{:from {:chainid 1
|
||||
:native-currency-symbol "ETH"}
|
||||
:to {:chain-id 1
|
||||
:native-currency-symbol "ETH"}
|
||||
:gas-amount "23487"
|
||||
:gas-fees {:base-fee "32.325296406"
|
||||
:max-priority-fee-per-gas "0.011000001"
|
||||
:eip1559-enabled true}}]
|
||||
:wallet/wallet-send-suggested-routes nil
|
||||
:wallet/wallet-send-receiver-networks [1]
|
||||
:view-id :screen/wallet.send-input-amount
|
||||
:wallet/wallet-send-to-address "0x04371e2d9d66b82f056bc128064"
|
||||
:profile/currency-symbol "$"
|
||||
:profile/currency :usd
|
||||
:wallet/token-by-symbol {:symbol "ETH"
|
||||
:total-balance 100
|
||||
:available-balance 100
|
||||
:balances-per-chain {1 {:raw-balance
|
||||
(money/bignumber
|
||||
"2500")
|
||||
:has-error false}}}
|
||||
:wallet/wallet-send-disabled-from-chain-ids []
|
||||
:wallet/wallet-send-from-locked-amounts {}
|
||||
:wallet/wallet-send-from-values-by-chain {1 (money/bignumber "250")}
|
||||
:wallet/wallet-send-to-values-by-chain {1 (money/bignumber "250")}
|
||||
:wallet/wallet-send-sender-network-values nil
|
||||
:wallet/wallet-send-receiver-network-values nil
|
||||
:wallet/wallet-send-network-links nil
|
||||
:wallet/wallet-send-receiver-preferred-networks [1]
|
||||
:wallet/wallet-send-enabled-networks [{:source 879
|
||||
:short-name "eth"
|
||||
:network-name :mainnet
|
||||
:abbreviated-name "Eth."
|
||||
:full-name "Mainnet"
|
||||
:chain-id 1
|
||||
:related-chain-id 1
|
||||
:layer 1}]
|
||||
:wallet/wallet-send-enabled-from-chain-ids [1]
|
||||
:wallet/send-amount nil
|
||||
:wallet/wallet-send-tx-type :tx/send
|
||||
:wallet/wallet-send-fee-fiat-formatted "$5,00"
|
||||
:wallet/sending-collectible? false
|
||||
:wallet/selected-keypair-keycard? false
|
||||
:wallet/send-total-amount-formatted "250 ETH"
|
||||
:wallet/total-amount (money/bignumber "250")
|
||||
:wallet/prices-per-token {:ETH {:usd 10}}
|
||||
:wallet/bridge-to-network-details nil
|
||||
:wallet/send-amount-fixed ""
|
||||
:wallet/send-display-token-decimals 5})
|
||||
{:profile/profile {:currency :usd}
|
||||
:wallet/selected-network-details [{:source 525
|
||||
:short-name "eth"
|
||||
:network-name :mainnet
|
||||
:chain-id 1
|
||||
:related-chain-id 5}]
|
||||
:wallet/current-viewing-account-address "0x1"
|
||||
:wallet/current-viewing-account {:path "m/44'/60'/0'/0/1"
|
||||
:emoji "💎"
|
||||
:key-uid "0x2f5ea39"
|
||||
:address "0x1"
|
||||
:wallet false
|
||||
:name "Account One"
|
||||
:type :generated
|
||||
:watch-only? false
|
||||
:chat false
|
||||
:test-preferred-chain-ids #{5 420 421613}
|
||||
:color :purple
|
||||
:hidden false
|
||||
:prod-preferred-chain-ids #{1 10 42161}
|
||||
:network-preferences-names #{:mainnet :arbitrum
|
||||
:optimism}
|
||||
:position 1
|
||||
:clock 1698945829328
|
||||
:created-at 1698928839000
|
||||
:operable :fully
|
||||
:mixedcase-address "0x7bcDfc75c431"
|
||||
:public-key "0x04371e2d9d66b82f056bc128064"
|
||||
:removed false}
|
||||
:wallet/current-viewing-account-color :purple
|
||||
:wallet/wallet-send-enough-assets? true
|
||||
:wallet/wallet-send-token {:symbol "ETH"
|
||||
:networks [{:source 879
|
||||
:short-name "eth"
|
||||
:network-name :mainnet
|
||||
:abbreviated-name
|
||||
"Eth."
|
||||
:full-name "Mainnet"
|
||||
:chain-id 1
|
||||
:related-chain-id 1
|
||||
:layer 1}]
|
||||
:balances-per-chain {1 {:raw-balance
|
||||
(money/bignumber
|
||||
"2500")
|
||||
:has-error false}}
|
||||
:total-balance 100
|
||||
:available-balance 100}
|
||||
:wallet/wallet-send-loading-suggested-routes? false
|
||||
:wallet/wallet-send-route [{:from {:chainid 1
|
||||
:native-currency-symbol "ETH"}
|
||||
:to {:chain-id 1
|
||||
:native-currency-symbol "ETH"}
|
||||
:gas-amount "23487"
|
||||
:gas-fees {:base-fee "32.325296406"
|
||||
:max-priority-fee-per-gas "0.011000001"
|
||||
:eip1559-enabled true}}]
|
||||
:wallet/wallet-send-suggested-routes nil
|
||||
:wallet/wallet-send-receiver-networks [1]
|
||||
:view-id :screen/wallet.send-input-amount
|
||||
:wallet/wallet-send-to-address "0x04371e2d9d66b82f056bc128064"
|
||||
:profile/currency-symbol "$"
|
||||
:profile/currency :usd
|
||||
:wallet/token-by-symbol {:symbol "ETH"
|
||||
:total-balance 100
|
||||
:available-balance 100
|
||||
:balances-per-chain {1 {:raw-balance
|
||||
(money/bignumber
|
||||
"2500")
|
||||
:has-error false}}}
|
||||
:wallet/wallet-send-from-values-by-chain {1 (money/bignumber "250")}
|
||||
:wallet/wallet-send-to-values-by-chain {1 (money/bignumber "250")}
|
||||
:wallet/wallet-send-sender-network-values nil
|
||||
:wallet/wallet-send-receiver-network-values nil
|
||||
:wallet/wallet-send-network-links nil
|
||||
:wallet/send-amount nil
|
||||
:wallet/wallet-send-tx-type :tx/send
|
||||
:wallet/wallet-send-fee-fiat-formatted "$5,00"
|
||||
:wallet/sending-collectible? false
|
||||
:wallet/selected-keypair-keycard? false
|
||||
:wallet/send-total-amount-formatted "250 ETH"
|
||||
:wallet/total-amount (money/bignumber "250")
|
||||
:wallet/prices-per-token {:ETH {:usd 10}}
|
||||
:wallet/bridge-to-network-details nil
|
||||
:wallet/send-amount-fixed ""
|
||||
:wallet/send-display-token-decimals 5
|
||||
:wallet/send-network {:chain-id 1}})
|
||||
|
||||
(h/describe "Send > input amount screen"
|
||||
(h/setup-restorable-re-frame)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
(ns status-im.contexts.wallet.send.input-amount.estimated-fees
|
||||
(:require
|
||||
[quo.core :as quo]
|
||||
[quo.foundations.colors :as colors]
|
||||
[quo.theme]
|
||||
[react-native.core :as rn]
|
||||
[status-im.common.not-implemented :as not-implemented]
|
||||
@@ -30,38 +31,40 @@
|
||||
(let [amount (rf/sub [:wallet/send-total-amount-formatted])
|
||||
tx-type (rf/sub [:wallet/wallet-send-tx-type])
|
||||
{:keys [full-name]} (rf/sub [:wallet/bridge-to-network-details])]
|
||||
[quo/data-item
|
||||
(cond-> {:container-style style/amount-data-item
|
||||
:status (if loading-routes? :loading :default)
|
||||
:size :small
|
||||
:title (i18n/label :t/recipient-gets)
|
||||
:subtitle amount}
|
||||
|
||||
(= tx-type :tx/bridge)
|
||||
(assoc
|
||||
:title-icon :i/info
|
||||
:title (i18n/label :t/bridged-to
|
||||
{:network full-name})
|
||||
:on-press show-bonder-fee-info))]))
|
||||
(when (= tx-type :tx/bridge)
|
||||
[quo/data-item
|
||||
{:container-style style/amount-data-item
|
||||
:status (if loading-routes? :loading :default)
|
||||
:size :small
|
||||
:title-icon :i/info
|
||||
:title (i18n/label :t/bridged-to
|
||||
{:network full-name})
|
||||
:subtitle amount
|
||||
:on-press show-bonder-fee-info}])))
|
||||
|
||||
(defn view
|
||||
[{:keys [loading-routes? fees]}]
|
||||
[rn/view {:style style/estimated-fees-container}
|
||||
(when (ff/enabled? ::ff/wallet.advanced-sending)
|
||||
[rn/view {:style style/estimated-fees-content-container}
|
||||
[quo/button
|
||||
{:icon-only? true
|
||||
:type :outline
|
||||
:size 32
|
||||
:inner-style {:opacity 1}
|
||||
:accessibility-label :advanced-button
|
||||
:disabled? loading-routes?
|
||||
:on-press not-implemented/alert}
|
||||
:i/advanced]])
|
||||
[quo/data-item
|
||||
{:container-style style/fees-data-item
|
||||
:status (if loading-routes? :loading :default)
|
||||
:size :small
|
||||
:title (i18n/label :t/fees)
|
||||
:subtitle fees}]
|
||||
[received-amount {:loading-routes? loading-routes?}]])
|
||||
[{:keys [not-enough-asset? loading-routes? fees]}]
|
||||
(let [theme (quo.theme/use-theme)]
|
||||
[rn/view {:style style/estimated-fees-container}
|
||||
(when (ff/enabled? ::ff/wallet.advanced-sending)
|
||||
[rn/view {:style style/estimated-fees-content-container}
|
||||
[quo/button
|
||||
{:icon-only? true
|
||||
:type :outline
|
||||
:size 32
|
||||
:inner-style {:opacity 1}
|
||||
:accessibility-label :advanced-button
|
||||
:disabled? loading-routes?
|
||||
:on-press not-implemented/alert}
|
||||
:i/advanced]])
|
||||
[quo/data-item
|
||||
(cond-> {:container-style style/fees-data-item
|
||||
:status (if loading-routes? :loading :default)
|
||||
:size :small
|
||||
:title (i18n/label :t/max-fees)
|
||||
:subtitle fees}
|
||||
not-enough-asset? (assoc :subtitle-color
|
||||
(colors/theme-colors colors/danger-50
|
||||
colors/danger-60
|
||||
theme)))]
|
||||
[received-amount {:loading-routes? loading-routes?}]]))
|
||||
|
||||
@@ -25,10 +25,9 @@
|
||||
:height 40})
|
||||
|
||||
(def fees-data-item
|
||||
{:flex 1
|
||||
:height 40
|
||||
:margin-horizontal 16
|
||||
:background-color :transparent})
|
||||
{:flex 1
|
||||
:height 40
|
||||
:background-color :transparent})
|
||||
|
||||
(def amount-data-item
|
||||
{:flex 1
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
(:require
|
||||
[clojure.string :as string]
|
||||
[quo.core :as quo]
|
||||
[quo.foundations.colors :as colors]
|
||||
[quo.theme]
|
||||
[react-native.core :as rn]
|
||||
[react-native.safe-area :as safe-area]
|
||||
@@ -15,29 +14,18 @@
|
||||
[status-im.contexts.wallet.send.input-amount.style :as style]
|
||||
[status-im.contexts.wallet.send.routes.view :as routes]
|
||||
[status-im.contexts.wallet.sheets.buy-token.view :as buy-token]
|
||||
[status-im.contexts.wallet.sheets.unpreferred-networks-alert.view :as unpreferred-networks-alert]
|
||||
[status-im.setup.hot-reload :as hot-reload]
|
||||
[utils.debounce :as debounce]
|
||||
[utils.i18n :as i18n]
|
||||
[utils.money :as money]
|
||||
[utils.re-frame :as rf]))
|
||||
|
||||
(defn- every-network-value-is-zero?
|
||||
[sender-network-values]
|
||||
(every? (fn [{:keys [total-amount]}]
|
||||
(and
|
||||
total-amount
|
||||
(money/bignumber? total-amount)
|
||||
(money/equal-to total-amount
|
||||
(money/bignumber "0"))))
|
||||
sender-network-values))
|
||||
|
||||
(defn select-asset-bottom-sheet
|
||||
[clear-input!]
|
||||
(let [{preselected-token-symbol :symbol} (rf/sub [:wallet/wallet-send-token])]
|
||||
[:<> ;; Need to be a `:<>` to keep `asset-list` scrollable.
|
||||
[quo/drawer-top
|
||||
{:title (i18n/label :t/select-asset)
|
||||
{:title (i18n/label :t/select-token)
|
||||
:container-style {:padding-bottom 8}}]
|
||||
[asset-list/view
|
||||
{:content-container-style {:padding-horizontal 8
|
||||
@@ -47,37 +35,6 @@
|
||||
(rf/dispatch [:wallet/edit-token-to-send token])
|
||||
(clear-input!))}]]))
|
||||
|
||||
(defn- token-not-available
|
||||
[token-symbol receiver-networks token-networks]
|
||||
(let [theme (quo.theme/use-theme)
|
||||
add-token-networks (fn []
|
||||
(let [chain-ids (concat receiver-networks
|
||||
(mapv #(:chain-id %) token-networks))]
|
||||
(rf/dispatch [:wallet/update-receiver-networks chain-ids])))]
|
||||
[rn/view {:style (style/token-not-available-container theme)}
|
||||
[rn/view
|
||||
[quo/icon :i/alert
|
||||
{:size 16
|
||||
:color (colors/resolve-color :danger theme)}]]
|
||||
[rn/view {:style style/token-not-available-content-container}
|
||||
[quo/text
|
||||
{:style (style/token-not-available-text theme)
|
||||
:size :paragraph-2}
|
||||
(i18n/label :t/token-not-available-on-receiver-networks {:token-symbol token-symbol})]
|
||||
[quo/button
|
||||
{:size 24
|
||||
:customization-color (colors/resolve-color :danger theme)
|
||||
:on-press add-token-networks}
|
||||
(i18n/label :t/add-networks-token-can-be-sent-to {:token-symbol token-symbol})]]]))
|
||||
|
||||
(defn- show-unpreferred-networks-alert
|
||||
[on-confirm]
|
||||
(rf/dispatch
|
||||
[:show-bottom-sheet
|
||||
{:content (fn []
|
||||
[unpreferred-networks-alert/view
|
||||
{:on-confirm on-confirm}])}]))
|
||||
|
||||
(defn- no-routes-found
|
||||
[]
|
||||
[rn/view {:style style/no-routes-found-container}
|
||||
@@ -118,8 +75,7 @@
|
||||
(rf/sub [:wallet/wallet-send-fee-fiat-formatted native-currency-symbol])))
|
||||
|
||||
(defn- insufficient-asset-amount?
|
||||
[{:keys [token-symbol owned-eth-token input-state no-routes-found? limit-exceeded?
|
||||
sender-network-values enough-assets?]}]
|
||||
[{:keys [token-symbol owned-eth-token input-state limit-exceeded? enough-assets?]}]
|
||||
(let [eth-selected? (= token-symbol (string/upper-case constants/mainnet-short-name))
|
||||
zero-owned-eth? (money/equal-to (:total-balance owned-eth-token) 0)
|
||||
input-at-max-owned-amount? (money/equal-to
|
||||
@@ -128,9 +84,9 @@
|
||||
exceeded-input? (if eth-selected?
|
||||
input-at-max-owned-amount?
|
||||
zero-owned-eth?)]
|
||||
(and (or no-routes-found? limit-exceeded?)
|
||||
(seq sender-network-values)
|
||||
(or exceeded-input? (not enough-assets?)))))
|
||||
(or exceeded-input?
|
||||
limit-exceeded?
|
||||
(false? enough-assets?))))
|
||||
|
||||
(defn view
|
||||
;; crypto-decimals, limit-crypto and initial-crypto-currency? args are needed
|
||||
@@ -142,122 +98,103 @@
|
||||
button-one-props :button-one-props
|
||||
current-screen-id :current-screen-id
|
||||
initial-crypto-currency? :initial-crypto-currency?
|
||||
enabled-from-chain-ids :enabled-from-chain-ids
|
||||
from-enabled-networks :from-enabled-networks
|
||||
:or {initial-crypto-currency? true}}]
|
||||
(let [view-id (rf/sub [:view-id])
|
||||
active-screen? (= view-id current-screen-id)
|
||||
bottom (safe-area/get-bottom)
|
||||
[crypto-currency?
|
||||
set-crypto-currency] (rn/use-state initial-crypto-currency?)
|
||||
handle-on-confirm (fn [amount]
|
||||
(rf/dispatch [:wallet/set-token-amount-to-send
|
||||
{:amount amount
|
||||
:stack-id current-screen-id}]))
|
||||
{fiat-currency :currency} (rf/sub [:profile/profile])
|
||||
{token-symbol :symbol
|
||||
token-networks :networks
|
||||
:as token} (rf/sub [:wallet/wallet-send-token])
|
||||
send-from-locked-amounts (rf/sub [:wallet/wallet-send-from-locked-amounts])
|
||||
(let [view-id (rf/sub [:view-id])
|
||||
{fiat-currency :currency} (rf/sub [:profile/profile])
|
||||
currency (rf/sub [:profile/currency])
|
||||
{token-symbol :symbol
|
||||
:as token} (rf/sub [:wallet/wallet-send-token])
|
||||
network (rf/sub [:wallet/send-network])
|
||||
{:keys [total-balance]
|
||||
:as token-by-symbol} (rf/sub [:wallet/token-by-symbol
|
||||
(str token-symbol)
|
||||
enabled-from-chain-ids])
|
||||
token-balance (or default-limit-crypto total-balance)
|
||||
prices-per-token (rf/sub [:wallet/prices-per-token])
|
||||
usd-conversion-rate (utils/token-usd-price token prices-per-token)
|
||||
currency (rf/sub [:profile/currency])
|
||||
token-decimals (rf/sub [:wallet/send-display-token-decimals])
|
||||
|
||||
conversion-rate (utils/token-price-by-symbol prices-per-token
|
||||
token-symbol
|
||||
currency)
|
||||
[input-state set-input-state] (rn/use-state controlled-input/init-state)
|
||||
clear-input! #(set-input-state controlled-input/delete-all)
|
||||
currency-symbol (rf/sub [:profile/currency-symbol])
|
||||
loading-routes? (rf/sub [:wallet/wallet-send-loading-suggested-routes?])
|
||||
route (rf/sub [:wallet/wallet-send-route])
|
||||
on-confirm (or default-on-confirm handle-on-confirm)
|
||||
max-limit (if crypto-currency?
|
||||
(utils/cut-crypto-decimals-to-fit-usd-cents
|
||||
token-balance
|
||||
usd-conversion-rate)
|
||||
(utils/cut-fiat-balance-to-two-decimals
|
||||
(money/crypto->fiat token-balance conversion-rate)))
|
||||
input-value (controlled-input/input-value input-state)
|
||||
valid-input? (not (or (controlled-input/empty-value? input-state)
|
||||
(controlled-input/input-error input-state)))
|
||||
amount-in-crypto (if crypto-currency?
|
||||
input-value
|
||||
(rf/sub [:wallet/send-amount-fixed
|
||||
(/ input-value conversion-rate)]))
|
||||
show-select-asset-sheet #(rf/dispatch
|
||||
[:show-bottom-sheet
|
||||
{:content (fn []
|
||||
[select-asset-bottom-sheet
|
||||
clear-input!])}])
|
||||
sender-network-values (rf/sub [:wallet/wallet-send-sender-network-values])
|
||||
receiver-network-values (rf/sub [:wallet/wallet-send-receiver-network-values])
|
||||
tx-type (rf/sub [:wallet/wallet-send-tx-type])
|
||||
unsupported-token-in-receiver? (and (not= tx-type :tx/bridge)
|
||||
(->> receiver-network-values
|
||||
(remove #(= (:type %) :add))
|
||||
(every? #(= (:type %) :not-available))))
|
||||
suggested-routes (rf/sub [:wallet/wallet-send-suggested-routes])
|
||||
routes (when suggested-routes
|
||||
(or (:best suggested-routes) []))
|
||||
no-routes-found? (and
|
||||
(every-network-value-is-zero? sender-network-values)
|
||||
(some? routes)
|
||||
(not loading-routes?)
|
||||
(not unsupported-token-in-receiver?))
|
||||
receiver-networks (rf/sub [:wallet/wallet-send-receiver-networks])
|
||||
receiver-preferred-networks (rf/sub [:wallet/wallet-send-receiver-preferred-networks])
|
||||
receiver-preferred-network? (set receiver-preferred-networks)
|
||||
sending-to-unpreferred-networks? (some (comp not receiver-preferred-network?)
|
||||
receiver-networks)
|
||||
input-error (controlled-input/input-error input-state)
|
||||
limit-exceeded? (controlled-input/upper-limit-exceeded? input-state)
|
||||
current-address (rf/sub [:wallet/current-viewing-account-address])
|
||||
current-color (rf/sub [:wallet/current-viewing-account-color])
|
||||
enough-assets? (rf/sub [:wallet/wallet-send-enough-assets?])
|
||||
owned-eth-token (rf/sub [:wallet/token-by-symbol
|
||||
(string/upper-case constants/mainnet-short-name)
|
||||
enabled-from-chain-ids])
|
||||
not-enough-asset? (insufficient-asset-amount?
|
||||
{:enough-assets? enough-assets?
|
||||
:token-symbol token-symbol
|
||||
:owned-eth-token owned-eth-token
|
||||
:input-state input-state
|
||||
:no-routes-found? no-routes-found?
|
||||
:limit-exceeded? limit-exceeded?
|
||||
:sender-network-values sender-network-values})
|
||||
should-try-again? (and (not limit-exceeded?)
|
||||
no-routes-found?
|
||||
(not not-enough-asset?))
|
||||
show-no-routes? (and (or no-routes-found? limit-exceeded?)
|
||||
(not-empty sender-network-values)
|
||||
(not not-enough-asset?))
|
||||
confirm-disabled? (or (nil? route)
|
||||
(empty? route)
|
||||
(not valid-input?))
|
||||
fee-formatted (when (or (not confirm-disabled?) not-enough-asset?)
|
||||
(get-fee-formatted route))
|
||||
request-fetch-routes (fn [bounce-duration-ms]
|
||||
(fetch-routes
|
||||
{:amount amount-in-crypto
|
||||
:valid-input? valid-input?
|
||||
:bounce-duration-ms bounce-duration-ms
|
||||
:token token
|
||||
:reset-amounts-to-zero? (and limit-exceeded?
|
||||
(some? routes))}))
|
||||
swap-between-fiat-and-crypto (fn []
|
||||
(if crypto-currency?
|
||||
(set-input-state
|
||||
#(controlled-input/->fiat % conversion-rate))
|
||||
(set-input-state
|
||||
#(controlled-input/->crypto % conversion-rate)))
|
||||
(set-crypto-currency (not crypto-currency?)))]
|
||||
:as token-by-symbol} (rf/sub [:wallet/token-by-symbol
|
||||
(str token-symbol)
|
||||
[(:chain-id network)]])
|
||||
currency-symbol (rf/sub [:profile/currency-symbol])
|
||||
loading-routes? (rf/sub [:wallet/wallet-send-loading-suggested-routes?])
|
||||
route (rf/sub [:wallet/wallet-send-route])
|
||||
current-address (rf/sub [:wallet/current-viewing-account-address])
|
||||
current-color (rf/sub [:wallet/current-viewing-account-color])
|
||||
enough-assets? (rf/sub [:wallet/wallet-send-enough-assets?])
|
||||
owned-eth-token (rf/sub [:wallet/token-by-symbol
|
||||
(string/upper-case constants/mainnet-short-name)
|
||||
[(:chain-id network)]])
|
||||
suggested-routes (rf/sub [:wallet/wallet-send-suggested-routes])
|
||||
tx-type (rf/sub [:wallet/wallet-send-tx-type])
|
||||
token-decimals (rf/sub [:wallet/send-display-token-decimals])
|
||||
prices-per-token (rf/sub [:wallet/prices-per-token])
|
||||
[crypto-currency?
|
||||
set-crypto-currency] (rn/use-state initial-crypto-currency?)
|
||||
[input-state set-input-state] (rn/use-state controlled-input/init-state)
|
||||
active-screen? (= view-id current-screen-id)
|
||||
bottom (safe-area/get-bottom)
|
||||
token-balance (or default-limit-crypto total-balance)
|
||||
usd-conversion-rate (utils/token-usd-price token prices-per-token)
|
||||
conversion-rate (utils/token-price-by-symbol prices-per-token
|
||||
token-symbol
|
||||
currency)
|
||||
clear-input! #(set-input-state controlled-input/delete-all)
|
||||
max-limit (if crypto-currency?
|
||||
(utils/cut-crypto-decimals-to-fit-usd-cents
|
||||
token-balance
|
||||
usd-conversion-rate)
|
||||
(utils/cut-fiat-balance-to-two-decimals
|
||||
(money/crypto->fiat token-balance conversion-rate)))
|
||||
input-value (controlled-input/input-value input-state)
|
||||
valid-input? (not (or (controlled-input/empty-value? input-state)
|
||||
(controlled-input/input-error input-state)))
|
||||
amount-in-crypto (if crypto-currency?
|
||||
input-value
|
||||
(rf/sub [:wallet/send-amount-fixed
|
||||
(/ input-value conversion-rate)]))
|
||||
routes-request-uuid (when suggested-routes
|
||||
(:uuid suggested-routes))
|
||||
no-routes-found? (and
|
||||
routes-request-uuid
|
||||
(empty? route)
|
||||
(not loading-routes?))
|
||||
input-error (controlled-input/input-error input-state)
|
||||
limit-exceeded? (controlled-input/upper-limit-exceeded? input-state)
|
||||
not-enough-asset? (insufficient-asset-amount?
|
||||
{:enough-assets? enough-assets?
|
||||
:token-symbol token-symbol
|
||||
:owned-eth-token owned-eth-token
|
||||
:input-state input-state
|
||||
:limit-exceeded? limit-exceeded?})
|
||||
should-try-again? (and (not limit-exceeded?)
|
||||
no-routes-found?
|
||||
(not not-enough-asset?))
|
||||
show-no-routes? (and (or no-routes-found? limit-exceeded?)
|
||||
(not not-enough-asset?))
|
||||
confirm-disabled? (or (nil? route)
|
||||
(empty? route)
|
||||
(not valid-input?))
|
||||
fee-formatted (when (or (not confirm-disabled?) not-enough-asset?)
|
||||
(get-fee-formatted route))
|
||||
handle-on-confirm (fn [amount]
|
||||
(rf/dispatch [:wallet/set-token-amount-to-send
|
||||
{:amount amount
|
||||
:stack-id current-screen-id}]))
|
||||
on-confirm (or default-on-confirm handle-on-confirm)
|
||||
show-select-asset-sheet #(rf/dispatch
|
||||
[:show-bottom-sheet
|
||||
{:content (fn []
|
||||
[select-asset-bottom-sheet
|
||||
clear-input!])}])
|
||||
request-fetch-routes (fn [bounce-duration-ms]
|
||||
(fetch-routes
|
||||
{:amount amount-in-crypto
|
||||
:valid-input? valid-input?
|
||||
:bounce-duration-ms bounce-duration-ms
|
||||
:token token
|
||||
:reset-amounts-to-zero? (and limit-exceeded?
|
||||
(some? route))}))
|
||||
swap-between-fiat-and-crypto (fn []
|
||||
(if crypto-currency?
|
||||
(set-input-state
|
||||
#(controlled-input/->fiat % conversion-rate))
|
||||
(set-input-state
|
||||
#(controlled-input/->crypto % conversion-rate)))
|
||||
(set-crypto-currency (not crypto-currency?)))]
|
||||
(rn/use-effect
|
||||
(fn []
|
||||
(when active-screen?
|
||||
@@ -282,13 +219,13 @@
|
||||
(rn/use-effect
|
||||
(fn []
|
||||
(clear-input!)
|
||||
(rf/dispatch [:wallet/stop-and-clean-suggested-routes])
|
||||
(rf/dispatch [:wallet/clean-disabled-from-networks]))
|
||||
(rf/dispatch [:wallet/stop-and-clean-suggested-routes]))
|
||||
[current-address])
|
||||
(rn/use-effect
|
||||
(fn []
|
||||
(request-fetch-routes 0))
|
||||
[send-from-locked-amounts])
|
||||
(when active-screen?
|
||||
(request-fetch-routes 2000)))
|
||||
[amount-in-crypto valid-input?])
|
||||
[rn/view
|
||||
{:style style/screen
|
||||
:accessibility-label (str "container"
|
||||
@@ -316,7 +253,7 @@
|
||||
conversion-rate)
|
||||
conversion-rate))
|
||||
:hint-component [quo/network-tags
|
||||
{:networks (seq from-enabled-networks)
|
||||
{:networks (seq [network])
|
||||
:title (i18n/label
|
||||
:t/send-limit
|
||||
{:limit (if crypto-currency?
|
||||
@@ -328,24 +265,16 @@
|
||||
(controlled-input/upper-limit-bn
|
||||
input-state)))})
|
||||
:status (when (controlled-input/input-error input-state) :error)}]}]
|
||||
[routes/view
|
||||
{:token token-by-symbol
|
||||
:input-value input-value
|
||||
:valid-input? valid-input?
|
||||
:token-not-supported-in-receiver-networks? unsupported-token-in-receiver?
|
||||
:current-screen-id current-screen-id
|
||||
:request-fetch-routes request-fetch-routes}]
|
||||
(when (and (not loading-routes?)
|
||||
sender-network-values
|
||||
unsupported-token-in-receiver?)
|
||||
[token-not-available token-symbol receiver-networks token-networks])
|
||||
(if (= tx-type :tx/bridge)
|
||||
[routes/view]
|
||||
[rn/view {:style {:flex 1}}])
|
||||
(when not-enough-asset?
|
||||
[not-enough-asset])
|
||||
(when (or (and (not no-routes-found?) (or loading-routes? route))
|
||||
not-enough-asset?)
|
||||
(when (or loading-routes? route)
|
||||
[estimated-fees/view
|
||||
{:loading-routes? loading-routes?
|
||||
:fees fee-formatted}])
|
||||
{:not-enough-asset? not-enough-asset?
|
||||
:loading-routes? loading-routes?
|
||||
:fees fee-formatted}])
|
||||
(when show-no-routes?
|
||||
[no-routes-found])
|
||||
[quo/bottom-actions
|
||||
@@ -359,14 +288,10 @@
|
||||
loading-routes?
|
||||
(and (not should-try-again?)
|
||||
confirm-disabled?))
|
||||
:on-press (cond
|
||||
should-try-again?
|
||||
:on-press (if should-try-again?
|
||||
#(rf/dispatch [:wallet/start-get-suggested-routes
|
||||
{:amount amount-in-crypto
|
||||
:updated-token token-by-symbol}])
|
||||
sending-to-unpreferred-networks?
|
||||
#(show-unpreferred-networks-alert on-confirm)
|
||||
:else
|
||||
#(on-confirm amount-in-crypto))
|
||||
:customization-color current-color}
|
||||
(when should-try-again?
|
||||
|
||||
@@ -34,19 +34,3 @@
|
||||
:top margin-top}
|
||||
inverted?
|
||||
(assoc :transform [{:scaleY -1}])))
|
||||
|
||||
(def disclaimer
|
||||
{:margin-horizontal 20
|
||||
:margin-top 20
|
||||
:margin-bottom 8})
|
||||
|
||||
(def input-container
|
||||
{:margin-top 8
|
||||
:margin-bottom 12})
|
||||
|
||||
(defn keyboard-container
|
||||
[bottom]
|
||||
{:padding-bottom bottom})
|
||||
|
||||
(def error-box
|
||||
{:margin-horizontal 20})
|
||||
|
||||
@@ -1,122 +1,39 @@
|
||||
(ns status-im.contexts.wallet.send.routes.view
|
||||
(:require
|
||||
[quo.core :as quo]
|
||||
[quo.theme]
|
||||
[react-native.core :as rn]
|
||||
[status-im.contexts.wallet.common.utils :as common-utils]
|
||||
[status-im.contexts.wallet.common.utils.networks :as network-utils]
|
||||
[status-im.contexts.wallet.send.routes.style :as style]
|
||||
[status-im.contexts.wallet.send.utils :as send-utils]
|
||||
[status-im.contexts.wallet.sheets.network-preferences.view :as network-preferences]
|
||||
[utils.i18n :as i18n]
|
||||
[utils.re-frame :as rf]))
|
||||
|
||||
|
||||
(def row-height 44)
|
||||
(def space-between-rows 11)
|
||||
(def network-link-linear-height 10)
|
||||
(def network-link-1x-height 56)
|
||||
(def network-link-2x-height 111)
|
||||
|
||||
|
||||
(defn- open-preferences
|
||||
[]
|
||||
(rf/dispatch
|
||||
[:show-bottom-sheet
|
||||
{:content
|
||||
(fn []
|
||||
(let [receiver-networks (rf/sub [:wallet/wallet-send-receiver-networks])
|
||||
receiver-preferred-networks (rf/sub
|
||||
[:wallet/wallet-send-receiver-preferred-networks])
|
||||
{token-symbol :symbol
|
||||
token-networks :supported-networks} (rf/sub [:wallet/wallet-send-token])
|
||||
token-chain-ids-set (set (mapv #(:chain-id %) token-networks))
|
||||
[selected-receiver-networks
|
||||
set-selected-receiver-networks] (rn/use-state receiver-networks)
|
||||
receiver-preferred-networks-set (set receiver-preferred-networks)
|
||||
receiver-selected-preferred-networks (filter #(contains?
|
||||
receiver-preferred-networks-set
|
||||
%)
|
||||
selected-receiver-networks)
|
||||
receiver-selected-non-preferred-networks (filter #(not (contains?
|
||||
receiver-preferred-networks-set
|
||||
%))
|
||||
selected-receiver-networks)
|
||||
not-available-preferred-networks (filter (fn [preferred-chain-id]
|
||||
(not (contains? token-chain-ids-set
|
||||
preferred-chain-id)))
|
||||
receiver-selected-preferred-networks)
|
||||
not-available-non-preferred-networks (filter (fn [preferred-chain-id]
|
||||
(not (contains?
|
||||
token-chain-ids-set
|
||||
preferred-chain-id)))
|
||||
receiver-selected-non-preferred-networks)
|
||||
first-section-warning-label (when (not-empty not-available-preferred-networks)
|
||||
(i18n/label
|
||||
:t/token-not-available-on-networks
|
||||
{:token-symbol token-symbol
|
||||
:networks
|
||||
(network-utils/network-ids->formatted-text
|
||||
not-available-preferred-networks)}))
|
||||
second-section-warning-label (when (not-empty
|
||||
not-available-non-preferred-networks)
|
||||
(i18n/label
|
||||
:t/token-not-available-on-networks
|
||||
{:token-symbol token-symbol
|
||||
:networks
|
||||
(network-utils/network-ids->formatted-text
|
||||
not-available-non-preferred-networks)}))]
|
||||
[network-preferences/view
|
||||
{:title (i18n/label :t/edit-receiver-networks)
|
||||
:first-section-label (i18n/label :t/preferred-by-receiver)
|
||||
:second-section-label (i18n/label :t/not-preferred-by-receiver)
|
||||
:selected-networks (set (map network-utils/id->network
|
||||
receiver-networks))
|
||||
:receiver-preferred-networks receiver-preferred-networks
|
||||
:button-label (i18n/label :t/apply-changes)
|
||||
:first-section-warning-label first-section-warning-label
|
||||
:second-section-warning-label second-section-warning-label
|
||||
:on-change #(set-selected-receiver-networks %)
|
||||
:on-save (fn [chain-ids]
|
||||
(rf/dispatch [:hide-bottom-sheet])
|
||||
(rf/dispatch [:wallet/update-receiver-networks
|
||||
chain-ids]))}]))}]))
|
||||
|
||||
(defn render-network-values
|
||||
[{:keys [network-values token-symbol on-press on-long-press receiver? loading-routes?
|
||||
token-not-supported-in-receiver-networks?]}]
|
||||
[{:keys [network-values token-symbol token-decimals receiver?]}]
|
||||
[rn/view
|
||||
(doall
|
||||
(map-indexed (fn [index
|
||||
{chain-id :chain-id
|
||||
network-value-type :type
|
||||
total-amount :total-amount}]
|
||||
(let [status (cond (and (= network-value-type :not-available)
|
||||
loading-routes?
|
||||
token-not-supported-in-receiver-networks?)
|
||||
:loading
|
||||
(= network-value-type :not-available)
|
||||
:disabled
|
||||
:else network-value-type)
|
||||
amount-formatted (-> (rf/sub [:wallet/send-amount-fixed total-amount])
|
||||
(let [amount-formatted (-> total-amount
|
||||
(common-utils/sanitized-token-amount-to-display
|
||||
token-decimals)
|
||||
(str " " token-symbol))]
|
||||
[rn/view
|
||||
{:key (str (if receiver? "to" "from") "-" chain-id)
|
||||
:style {:margin-top (if (pos? index) 11 7.5)}}
|
||||
[quo/network-bridge
|
||||
{:amount (if (= network-value-type :not-available)
|
||||
(i18n/label :t/not-available)
|
||||
amount-formatted)
|
||||
:network (network-utils/id->network chain-id)
|
||||
:status status
|
||||
:on-press #(when (not loading-routes?)
|
||||
(cond
|
||||
(= network-value-type :edit)
|
||||
(open-preferences)
|
||||
on-press (on-press chain-id total-amount)))
|
||||
:on-long-press #(when (and (not loading-routes?) (not= status :disabled))
|
||||
(cond
|
||||
(= network-value-type :add)
|
||||
(open-preferences)
|
||||
on-long-press (on-long-press chain-id total-amount)))}]]))
|
||||
{:amount amount-formatted
|
||||
:network (network-utils/id->network chain-id)
|
||||
:status network-value-type}]]))
|
||||
network-values))])
|
||||
|
||||
(defn render-network-links
|
||||
@@ -156,59 +73,14 @@
|
||||
:destination destination}]]]))
|
||||
network-links)])
|
||||
|
||||
(defn disable-chain
|
||||
[chain-id disabled-from-chain-ids token-available-networks-for-suggested-routes]
|
||||
(let [disabled-chain-ids
|
||||
(if (contains? (set
|
||||
disabled-from-chain-ids)
|
||||
chain-id)
|
||||
(vec (remove #(= % chain-id)
|
||||
disabled-from-chain-ids))
|
||||
(conj disabled-from-chain-ids
|
||||
chain-id))
|
||||
re-enabling-chain?
|
||||
(< (count disabled-chain-ids)
|
||||
(count disabled-from-chain-ids))]
|
||||
(if (or re-enabling-chain?
|
||||
(> (count token-available-networks-for-suggested-routes) 1))
|
||||
(rf/dispatch [:wallet/disable-from-networks
|
||||
disabled-chain-ids])
|
||||
(rf/dispatch [:toasts/upsert
|
||||
{:id :disable-chain-error
|
||||
:type :negative
|
||||
:text (i18n/label :t/at-least-one-network-must-be-activated)}]))))
|
||||
|
||||
(defn view
|
||||
[{:keys [token theme valid-input? request-fetch-routes on-press-to-network current-screen-id
|
||||
token-not-supported-in-receiver-networks? input-value]}]
|
||||
(let [token-symbol (:symbol token)
|
||||
nav-current-screen-id (rf/sub [:view-id])
|
||||
active-screen? (= nav-current-screen-id current-screen-id)
|
||||
loading-routes? (rf/sub
|
||||
[:wallet/wallet-send-loading-suggested-routes?])
|
||||
sender-network-values (rf/sub
|
||||
[:wallet/wallet-send-sender-network-values])
|
||||
receiver-network-values (rf/sub
|
||||
[:wallet/wallet-send-receiver-network-values])
|
||||
network-links (rf/sub [:wallet/wallet-send-network-links])
|
||||
disabled-from-chain-ids (rf/sub
|
||||
[:wallet/wallet-send-disabled-from-chain-ids])
|
||||
{token-balances-per-chain :balances-per-chain} (rf/sub [:wallet/wallet-send-token])
|
||||
token-available-networks-for-suggested-routes
|
||||
(send-utils/token-available-networks-for-suggested-routes
|
||||
{:balances-per-chain token-balances-per-chain
|
||||
:disabled-chain-ids disabled-from-chain-ids})
|
||||
show-routes? (not-empty sender-network-values)]
|
||||
(rn/use-effect
|
||||
(fn []
|
||||
(when (and active-screen?
|
||||
(> (count token-available-networks-for-suggested-routes) 0))
|
||||
(request-fetch-routes 2000)))
|
||||
[input-value valid-input?])
|
||||
(rn/use-effect
|
||||
#(when (and active-screen? (> (count token-available-networks-for-suggested-routes) 0))
|
||||
(request-fetch-routes 0))
|
||||
[disabled-from-chain-ids])
|
||||
[]
|
||||
(let [token-symbol (rf/sub [:wallet/wallet-send-token-symbol])
|
||||
sender-network-values (rf/sub [:wallet/wallet-send-sender-network-values])
|
||||
receiver-network-values (rf/sub [:wallet/wallet-send-receiver-network-values])
|
||||
network-links (rf/sub [:wallet/wallet-send-network-links])
|
||||
token-decimals (rf/sub [:wallet/send-display-token-decimals])
|
||||
show-routes? (not-empty sender-network-values)]
|
||||
[rn/scroll-view {:content-container-style style/routes-container}
|
||||
(when show-routes?
|
||||
[rn/view {:style style/routes-header-container}
|
||||
@@ -220,27 +92,16 @@
|
||||
:container-style style/section-label-right}]])
|
||||
[rn/view {:style style/routes-inner-container}
|
||||
[render-network-values
|
||||
{:token-symbol token-symbol
|
||||
:network-values sender-network-values
|
||||
:on-press (fn [chain-id-to-disable]
|
||||
(disable-chain
|
||||
chain-id-to-disable
|
||||
disabled-from-chain-ids
|
||||
token-available-networks-for-suggested-routes))
|
||||
:receiver? false
|
||||
:theme theme
|
||||
:loading-routes? loading-routes?
|
||||
:token-not-supported-in-receiver-networks? false}]
|
||||
{:token-symbol token-symbol
|
||||
:network-values sender-network-values
|
||||
:token-decimals token-decimals
|
||||
:receiver? false}]
|
||||
[render-network-links
|
||||
{:network-links network-links
|
||||
:sender-network-values sender-network-values}]
|
||||
[render-network-values
|
||||
{:token-symbol token-symbol
|
||||
:network-values receiver-network-values
|
||||
:on-press on-press-to-network
|
||||
:receiver? true
|
||||
:loading-routes? loading-routes?
|
||||
:theme theme
|
||||
:token-not-supported-in-receiver-networks? token-not-supported-in-receiver-networks?
|
||||
:on-save #(request-fetch-routes 0)}]]]))
|
||||
{:token-symbol token-symbol
|
||||
:network-values receiver-network-values
|
||||
:token-decimals token-decimals
|
||||
:receiver? true}]]]))
|
||||
|
||||
|
||||
@@ -176,7 +176,6 @@
|
||||
(rf/dispatch [:wallet/clean-local-suggestions])
|
||||
(rf/dispatch [:wallet/clean-selected-collectible])
|
||||
(rf/dispatch [:wallet/clean-send-address])
|
||||
(rf/dispatch [:wallet/clean-disabled-from-networks])
|
||||
(rf/dispatch [:wallet/select-address-tab nil])
|
||||
(rf/dispatch [:wallet/clean-current-viewing-account
|
||||
:ignore-just-complete-transaction]))
|
||||
|
||||
@@ -78,7 +78,7 @@
|
||||
:on-press on-close
|
||||
:switcher-type :select-account}]
|
||||
[quo/page-top
|
||||
{:title (i18n/label :t/select-asset)
|
||||
{:title (i18n/label :t/select-token)
|
||||
:title-accessibility-label :title-label}]
|
||||
[quo/segmented-control
|
||||
{:size 32
|
||||
|
||||
@@ -8,12 +8,8 @@
|
||||
(defn view
|
||||
[]
|
||||
[input-amount/view
|
||||
{:current-screen-id :screen/wallet.send-input-amount
|
||||
:button-one-label (i18n/label :t/review-send)
|
||||
:enabled-from-chain-ids (rf/sub [:wallet/wallet-send-enabled-from-chain-ids])
|
||||
:from-enabled-networks (rf/sub [:wallet/wallet-send-enabled-networks])
|
||||
:on-navigate-back (fn []
|
||||
(rf/dispatch-sync [:wallet/stop-and-clean-suggested-routes])
|
||||
(rf/dispatch [:wallet/clean-disabled-from-networks])
|
||||
(rf/dispatch [:wallet/clean-from-locked-amounts])
|
||||
(rf/dispatch [:wallet/clean-send-amount]))}])
|
||||
{:current-screen-id :screen/wallet.send-input-amount
|
||||
:button-one-label (i18n/label :t/review-send)
|
||||
:on-navigate-back (fn []
|
||||
(rf/dispatch-sync [:wallet/stop-and-clean-suggested-routes])
|
||||
(rf/dispatch [:wallet/clean-send-amount]))}])
|
||||
|
||||
@@ -48,11 +48,10 @@
|
||||
(defn- path-amount-out
|
||||
[path]
|
||||
(if (= (:bridge-name path) constants/bridge-name-hop)
|
||||
(let [{:keys [token-fees bonder-fees amount-in]} path]
|
||||
(let [{:keys [token-fees amount-in]} path]
|
||||
(-> amount-in
|
||||
money/from-hex
|
||||
(money/sub token-fees)
|
||||
(money/add bonder-fees)))
|
||||
(money/sub token-fees)))
|
||||
(-> path :amount-out money/from-hex)))
|
||||
|
||||
(defn convert-wei-to-eth
|
||||
@@ -138,12 +137,6 @@
|
||||
:optimism 2
|
||||
:arbitrum 3})
|
||||
|
||||
(defn safe-add-type-edit
|
||||
[network-values]
|
||||
(if (or (empty? network-values) (some #(= (:type %) :edit) network-values))
|
||||
network-values
|
||||
(conj network-values {:type :edit})))
|
||||
|
||||
(defn reset-loading-network-amounts-to-zero
|
||||
[network-amounts]
|
||||
(mapv
|
||||
@@ -155,118 +148,39 @@
|
||||
network-amounts))
|
||||
|
||||
(defn reset-network-amounts-to-zero
|
||||
[{:keys [network-amounts disabled-chain-ids]}]
|
||||
[network-amounts]
|
||||
(map
|
||||
(fn [network-amount]
|
||||
(let [disabled-chain-ids-set (set disabled-chain-ids)
|
||||
disabled? (contains? disabled-chain-ids-set
|
||||
(:chain-id network-amount))]
|
||||
(cond-> network-amount
|
||||
(and (not= (:type network-amount) :edit)
|
||||
(not= (:type network-amount) :not-available))
|
||||
(assoc :total-amount (money/bignumber "0")
|
||||
:type (if disabled? :disabled :default)))))
|
||||
(assoc network-amount
|
||||
:total-amount (money/bignumber "0")
|
||||
:type :default))
|
||||
network-amounts))
|
||||
|
||||
(defn network-amounts
|
||||
[{:keys [network-values disabled-chain-ids receiver-networks token-networks-ids tx-type receiver?
|
||||
from-locked-amounts]}]
|
||||
(let [disabled-set (set disabled-chain-ids)
|
||||
receiver-networks-set (set receiver-networks)
|
||||
network-values-keys (set (keys network-values))
|
||||
routes-found? (pos? (count network-values-keys))
|
||||
token-networks-ids-set (set token-networks-ids)
|
||||
not-available-networks (if receiver?
|
||||
(filter #(not (token-networks-ids-set %))
|
||||
receiver-networks)
|
||||
[])
|
||||
not-available-networks-set (set not-available-networks)
|
||||
network-values-with-disabled-chains (when routes-found?
|
||||
(reduce
|
||||
(fn [acc k]
|
||||
(if (or (contains? network-values-keys k)
|
||||
receiver?)
|
||||
acc
|
||||
(assoc acc k (money/bignumber "0"))))
|
||||
network-values
|
||||
disabled-chain-ids))
|
||||
network-values-with-not-available-chains (if (and receiver? routes-found?)
|
||||
(let [network-values-keys
|
||||
(set (keys
|
||||
network-values-with-disabled-chains))]
|
||||
(reduce
|
||||
(fn [acc k]
|
||||
(if (not (contains? network-values-keys k))
|
||||
(assoc acc k nil)
|
||||
acc))
|
||||
network-values-with-disabled-chains
|
||||
not-available-networks))
|
||||
network-values-with-disabled-chains)]
|
||||
(cond-> (->>
|
||||
network-values-with-not-available-chains
|
||||
(map
|
||||
(fn [[chain-id amount]]
|
||||
{:chain-id chain-id
|
||||
:total-amount (get from-locked-amounts chain-id amount)
|
||||
:type (cond
|
||||
(contains? from-locked-amounts chain-id) :locked
|
||||
(contains? not-available-networks-set chain-id) :not-available
|
||||
(or receiver? (not (contains? disabled-set chain-id))) :default
|
||||
(and (not receiver?) (contains? disabled-set chain-id)) :disabled)}))
|
||||
(sort-by (fn [network-amount]
|
||||
(get network-priority-score
|
||||
(network-utils/id->network (:chain-id network-amount)))))
|
||||
(filter
|
||||
(fn [network-amount]
|
||||
(or (and receiver?
|
||||
(or (contains? receiver-networks-set (:chain-id network-amount))
|
||||
(money/above-zero? (:total-amount network-amount))))
|
||||
(not receiver?))))
|
||||
(vec))
|
||||
(and receiver?
|
||||
routes-found?
|
||||
(not= tx-type :tx/bridge))
|
||||
safe-add-type-edit)))
|
||||
[network-values]
|
||||
(->> network-values
|
||||
(map
|
||||
(fn [[chain-id amount]]
|
||||
{:chain-id chain-id
|
||||
:total-amount amount
|
||||
:type :default}))
|
||||
(sort-by (fn [network-amount]
|
||||
(get network-priority-score
|
||||
(network-utils/id->network (:chain-id network-amount)))))
|
||||
(vec)))
|
||||
|
||||
(defn loading-network-amounts
|
||||
[{:keys [valid-networks disabled-chain-ids receiver-networks token-networks-ids tx-type receiver?]}]
|
||||
(let [disabled-set (set disabled-chain-ids)
|
||||
receiver-networks-set (set receiver-networks)
|
||||
token-networks-ids-set (set token-networks-ids)
|
||||
valid-networks-set (set valid-networks)
|
||||
not-available-networks (if receiver?
|
||||
(filter #(not (token-networks-ids-set %)) receiver-networks)
|
||||
[])
|
||||
not-available-networks-set (set not-available-networks)
|
||||
valid-networks (-> (concat valid-networks
|
||||
(when (not (and receiver? (= tx-type :tx/bridge)))
|
||||
disabled-chain-ids)
|
||||
(when receiver?
|
||||
(filter #(not (valid-networks-set %))
|
||||
not-available-networks)))
|
||||
(distinct))]
|
||||
(->> valid-networks
|
||||
(map
|
||||
(fn [chain-id]
|
||||
(cond->
|
||||
{:chain-id chain-id
|
||||
:type (cond
|
||||
(contains? not-available-networks-set chain-id) :not-available
|
||||
(or receiver?
|
||||
(not (contains? disabled-set chain-id))) :loading
|
||||
(and (not receiver?) (contains? disabled-set chain-id)) :disabled)}
|
||||
(and (not receiver?) (contains? disabled-set chain-id))
|
||||
(assoc :total-amount (money/bignumber "0")))))
|
||||
(filter
|
||||
(fn [network-amount]
|
||||
(or (and receiver?
|
||||
(or (= tx-type :tx/bridge)
|
||||
(contains? receiver-networks-set (:chain-id network-amount))))
|
||||
(not receiver?))))
|
||||
(sort-by (fn [network-amount]
|
||||
(get network-priority-score
|
||||
(network-utils/id->network (:chain-id network-amount)))))
|
||||
(vec))))
|
||||
[{:keys [networks values receiver?]}]
|
||||
(->> networks
|
||||
(map
|
||||
(fn [chain-id]
|
||||
(let [network-value (when values (get values chain-id))]
|
||||
(cond-> {:chain-id chain-id
|
||||
:type (if network-value :default :loading)}
|
||||
network-value (assoc :total-amount
|
||||
(money/bignumber network-value))
|
||||
(and (not network-value) (not receiver?)) (assoc :total-amount (money/bignumber "0"))))))
|
||||
(vec)))
|
||||
|
||||
(defn network-links
|
||||
[route from-values-by-chain to-values-by-chain]
|
||||
|
||||
@@ -85,11 +85,9 @@
|
||||
(testing "Correctly calculates network (out) amounts for bridge transaction"
|
||||
(let [route [{:bridge-name "Hop"
|
||||
:amount-in "0xde0b6b3a7640000"
|
||||
:bonder-fees (money/bignumber "200000000000000")
|
||||
:token-fees (money/bignumber "230000000000000")
|
||||
:to {:chain-id 1}}
|
||||
{:bridge-name "Hop"
|
||||
:bonder-fees (money/bignumber "300000000000000")
|
||||
:token-fees (money/bignumber "410000000000000")
|
||||
:amount-in "0xde0b6b3a7640000"
|
||||
:to {:chain-id 10}}]
|
||||
@@ -100,8 +98,8 @@
|
||||
:token-decimals token-decimals
|
||||
:native-token? native-token?
|
||||
:receiver? receiver?})
|
||||
expected {1 (money/bignumber "0.99997")
|
||||
10 (money/bignumber "0.99989")}]
|
||||
expected {1 (money/bignumber "0.99977")
|
||||
10 (money/bignumber "0.99959")}]
|
||||
(doseq [[chain-id exp-value] expected]
|
||||
(is (money/equal-to (get result chain-id) exp-value))))))
|
||||
|
||||
@@ -350,171 +348,12 @@
|
||||
(is (every? identity comparisons)))))
|
||||
|
||||
(deftest network-amounts-test
|
||||
(testing "Handles disabled and receiver networks correctly when receiver? is true"
|
||||
(let [network-values {10 (money/bignumber "200")}
|
||||
disabled-chain-ids [1]
|
||||
receiver-networks [10]
|
||||
token-networks-ids [1 10 42161]
|
||||
receiver? true
|
||||
expected [{:chain-id 10
|
||||
:total-amount (money/bignumber "200")
|
||||
:type :default}
|
||||
{:type :edit}]
|
||||
tx-type :tx/send
|
||||
result (utils/network-amounts {:network-values network-values
|
||||
:disabled-chain-ids disabled-chain-ids
|
||||
:receiver-networks receiver-networks
|
||||
:token-networks-ids token-networks-ids
|
||||
:tx-type tx-type
|
||||
:receiver? receiver?})]
|
||||
(is (every? identity (map #(map/deep-compare %1 %2) expected result)))))
|
||||
|
||||
(testing "Adds default amount for non-disabled non-receiver networks when receiver? is false"
|
||||
(let [network-values {1 (money/bignumber "100")}
|
||||
disabled-chain-ids [10]
|
||||
receiver-networks []
|
||||
token-networks-ids [1 10 42161]
|
||||
receiver? false
|
||||
expected [{:chain-id 1
|
||||
:total-amount (money/bignumber "100")
|
||||
:type :default}
|
||||
{:chain-id 10
|
||||
:total-amount (money/bignumber "0")
|
||||
:type :disabled}]
|
||||
tx-type :tx/send
|
||||
result (utils/network-amounts {:network-values network-values
|
||||
:disabled-chain-ids disabled-chain-ids
|
||||
:receiver-networks receiver-networks
|
||||
:token-networks-ids token-networks-ids
|
||||
:tx-type tx-type
|
||||
:receiver? receiver?})]
|
||||
(is (every? identity (map #(map/deep-compare %1 %2) expected result)))))
|
||||
|
||||
(testing "Handles empty inputs correctly"
|
||||
(let [network-values {}
|
||||
disabled-chain-ids []
|
||||
receiver-networks []
|
||||
token-networks-ids []
|
||||
receiver? true
|
||||
expected []
|
||||
tx-type :tx/send
|
||||
result (utils/network-amounts {:network-values network-values
|
||||
:disabled-chain-ids disabled-chain-ids
|
||||
:receiver-networks receiver-networks
|
||||
:token-networks-ids token-networks-ids
|
||||
:tx-type tx-type
|
||||
:receiver? receiver?})]
|
||||
(is (= expected result))))
|
||||
|
||||
(testing "Processes case with multiple network interactions"
|
||||
(let [network-values {1 (money/bignumber "300")
|
||||
10 (money/bignumber "400")
|
||||
42161 (money/bignumber "500")}
|
||||
disabled-chain-ids [1 42161]
|
||||
receiver-networks [10]
|
||||
token-networks-ids [1 10 42161]
|
||||
receiver? true
|
||||
expected [{:chain-id 1
|
||||
:total-amount (money/bignumber "300")
|
||||
:type :default}
|
||||
{:chain-id 10
|
||||
:total-amount (money/bignumber "400")
|
||||
:type :default}
|
||||
{:chain-id 42161
|
||||
:total-amount (money/bignumber "500")
|
||||
:type :default}
|
||||
{:type :edit}]
|
||||
tx-type :tx/send
|
||||
result (utils/network-amounts {:network-values network-values
|
||||
:disabled-chain-ids disabled-chain-ids
|
||||
:receiver-networks receiver-networks
|
||||
:token-networks-ids token-networks-ids
|
||||
:tx-type tx-type
|
||||
:receiver? receiver?})]
|
||||
(is (every? identity (map #(map/deep-compare %1 %2) expected result)))))
|
||||
|
||||
(testing "Does not assign :not-available type when receiver? is false"
|
||||
(let [network-values {1 (money/bignumber "100")}
|
||||
disabled-chain-ids [10]
|
||||
receiver-networks [1]
|
||||
token-networks-ids [1 10]
|
||||
receiver? false
|
||||
expected [{:chain-id 1
|
||||
:total-amount (money/bignumber "100")
|
||||
:type :default}
|
||||
{:chain-id 10
|
||||
:total-amount (money/bignumber "0")
|
||||
:type :disabled}]
|
||||
tx-type :tx/send
|
||||
result (utils/network-amounts {:network-values network-values
|
||||
:disabled-chain-ids disabled-chain-ids
|
||||
:receiver-networks receiver-networks
|
||||
:token-networks-ids token-networks-ids
|
||||
:tx-type tx-type
|
||||
:receiver? receiver?})]
|
||||
(is (every? identity (map #(map/deep-compare %1 %2) expected result)))))
|
||||
|
||||
(testing
|
||||
"Assigns :not-available type to networks not available in token-networks-ids when receiver? is true"
|
||||
(let [network-values {1 (money/bignumber "100")}
|
||||
disabled-chain-ids []
|
||||
receiver-networks [1 10]
|
||||
token-networks-ids [1]
|
||||
receiver? false
|
||||
expected [{:chain-id 1
|
||||
:total-amount (money/bignumber "100")
|
||||
:type :default}
|
||||
{:chain-id 10
|
||||
:total-amount nil
|
||||
:type :not-available}]
|
||||
tx-type :tx/send
|
||||
result (utils/network-amounts {:network-values network-values
|
||||
:disabled-chain-ids disabled-chain-ids
|
||||
:receiver-networks receiver-networks
|
||||
:token-networks-ids token-networks-ids
|
||||
:tx-type tx-type
|
||||
:receiver? receiver?})]
|
||||
(is (every? identity (map #(map/deep-compare %1 %2) expected result)))))
|
||||
|
||||
(testing
|
||||
"Handles disabled and receiver networks correctly when receiver? is false and tx-type is :tx/bridge"
|
||||
(let [network-values {10 (money/bignumber "200")}
|
||||
disabled-chain-ids [1]
|
||||
receiver-networks [10]
|
||||
token-networks-ids [1 10]
|
||||
tx-type :tx/bridge
|
||||
receiver? false
|
||||
expected [{:chain-id 1
|
||||
:total-amount (money/bignumber "0")
|
||||
:type :disabled}
|
||||
{:chain-id 10
|
||||
:total-amount (money/bignumber "200")
|
||||
:type :default}]
|
||||
result (utils/network-amounts {:network-values network-values
|
||||
:disabled-chain-ids disabled-chain-ids
|
||||
:receiver-networks receiver-networks
|
||||
:token-networks-ids token-networks-ids
|
||||
:tx-type tx-type
|
||||
:receiver? receiver?})]
|
||||
(is (every? identity (map #(map/deep-compare %1 %2) expected result)))))
|
||||
|
||||
(testing
|
||||
"Handles disabled and receiver networks correctly when receiver? is true and tx-type is :tx/bridge"
|
||||
(let [network-values {10 (money/bignumber "200")}
|
||||
disabled-chain-ids [1]
|
||||
receiver-networks [10]
|
||||
token-networks-ids [1 10]
|
||||
tx-type :tx/bridge
|
||||
receiver? true
|
||||
expected [{:chain-id 10
|
||||
:total-amount (money/bignumber "200")
|
||||
:type :default}]
|
||||
result (utils/network-amounts {:network-values network-values
|
||||
:disabled-chain-ids disabled-chain-ids
|
||||
:receiver-networks receiver-networks
|
||||
:token-networks-ids token-networks-ids
|
||||
:tx-type tx-type
|
||||
:receiver? receiver?})]
|
||||
(testing "Handles network values with one chain"
|
||||
(let [network-values {10 (money/bignumber "200")}
|
||||
expected [{:chain-id 10
|
||||
:total-amount (money/bignumber "200")
|
||||
:type :default}]
|
||||
result (utils/network-amounts network-values)]
|
||||
(is (every? identity (map #(map/deep-compare %1 %2) expected result))))))
|
||||
|
||||
(deftest loading-network-amounts-test
|
||||
@@ -538,27 +377,6 @@
|
||||
result)]
|
||||
(is (every? identity comparisons))))
|
||||
|
||||
(testing "Assigns :disabled type with zero total-amount to disabled networks when receiver? is false"
|
||||
(let [valid-networks [1 10 42161]
|
||||
disabled-chain-ids [10 42161]
|
||||
receiver-networks [1]
|
||||
token-networks-ids [1 10 42161]
|
||||
receiver? false
|
||||
expected [{:chain-id 1 :type :loading}
|
||||
{:chain-id 10 :type :disabled :total-amount (money/bignumber "0")}
|
||||
{:chain-id 42161 :type :disabled :total-amount (money/bignumber "0")}]
|
||||
tx-type :tx/send
|
||||
result (utils/loading-network-amounts {:valid-networks valid-networks
|
||||
:disabled-chain-ids disabled-chain-ids
|
||||
:receiver-networks receiver-networks
|
||||
:token-networks-ids token-networks-ids
|
||||
:tx-type tx-type
|
||||
:receiver? receiver?})
|
||||
comparisons (map #(map/deep-compare %1 %2)
|
||||
expected
|
||||
result)]
|
||||
(is (every? identity comparisons))))
|
||||
|
||||
(testing "Filters out networks not in receiver networks when receiver? is true"
|
||||
(let [valid-networks [1 10 42161 59144]
|
||||
disabled-chain-ids [10]
|
||||
|
||||
@@ -8,12 +8,14 @@
|
||||
[utils.re-frame :as rf]))
|
||||
|
||||
(defn- network-item
|
||||
[{:keys [network on-select-network]}]
|
||||
(let [{:keys [network-name
|
||||
chain-id]} network
|
||||
[{:keys [network on-select-network source]}]
|
||||
(let [{:keys [network-name chain-id]} network
|
||||
{balance-in-crypto :crypto
|
||||
balance-in-fiat :fiat} (rf/sub [:wallet/swap-asset-to-pay-network-balance chain-id])
|
||||
mainnet? (= network-name constants/mainnet-network-name)]
|
||||
balance-in-fiat :fiat} (if (= source :swap)
|
||||
(rf/sub [:wallet/swap-asset-to-pay-network-balance chain-id])
|
||||
(rf/sub [:wallet/send-token-network-balance chain-id]))
|
||||
mainnet?
|
||||
(= network-name constants/mainnet-network-name)]
|
||||
[quo/network-list
|
||||
{:label (name network-name)
|
||||
:network-image (quo.resources/get-network network-name)
|
||||
@@ -23,21 +25,24 @@
|
||||
:container-style (style/network-list-container mainnet?)}]))
|
||||
|
||||
(defn view
|
||||
[{:keys [on-select-network]}]
|
||||
(let [token-symbol (rf/sub [:wallet/swap-asset-to-pay-token-symbol])
|
||||
{mainnet-network :mainnet-network
|
||||
layer-2-networks :layer-2-networks} (rf/sub [:wallet/swap-asset-to-pay-networks])
|
||||
[{:keys [token-symbol on-select-network source title]
|
||||
:or {source :swap
|
||||
title (i18n/label :t/select-network)}}]
|
||||
(let [{mainnet-network :mainnet-network
|
||||
layer-2-networks :layer-2-networks} (if (= source :swap)
|
||||
(rf/sub [:wallet/swap-asset-to-pay-networks])
|
||||
(rf/sub [:wallet/send-token-grouped-networks]))
|
||||
render-fn (rn/use-callback (fn [network]
|
||||
[network-item
|
||||
{:network network
|
||||
:on-select-network
|
||||
on-select-network}]))]
|
||||
{:network network
|
||||
:on-select-network on-select-network
|
||||
:source source}]))]
|
||||
[:<>
|
||||
[rn/view {:style style/header-container}
|
||||
[quo/text
|
||||
{:size :heading-2
|
||||
:weight :semi-bold}
|
||||
(i18n/label :t/select-network)]
|
||||
title]
|
||||
[quo/context-tag
|
||||
{:type :token
|
||||
:size 24
|
||||
@@ -46,7 +51,8 @@
|
||||
(when mainnet-network
|
||||
[network-item
|
||||
{:network mainnet-network
|
||||
:on-select-network on-select-network}])
|
||||
:on-select-network on-select-network
|
||||
:source source}])
|
||||
[quo/divider-label {:container-style style/divider-label}
|
||||
(i18n/label :t/layer-2)]
|
||||
[rn/flat-list
|
||||
|
||||
@@ -34,7 +34,8 @@
|
||||
|
||||
(defn view
|
||||
[]
|
||||
(let [accounts (rf/sub [:wallet/accounts-with-balances])]
|
||||
(let [asset-to-pay (rf/sub [:wallet/swap-asset-to-pay])
|
||||
accounts (rf/sub [:wallet/accounts-with-balances asset-to-pay])]
|
||||
[floating-button-page/view
|
||||
{:footer-container-padding 0
|
||||
:header [quo/page-nav
|
||||
|
||||
@@ -36,7 +36,9 @@
|
||||
(cond
|
||||
|
||||
keycard?
|
||||
{:fx [[:dispatch [:keycard/feature-unavailable-show]]]}
|
||||
{:fx [[:dispatch
|
||||
[:keycard/feature-unavailable-show
|
||||
{:feature-name :wallet.scan-dapp-connection}]]]}
|
||||
|
||||
(or (not valid-wc-uri?)
|
||||
(not version-supported?)
|
||||
|
||||
@@ -11,13 +11,13 @@
|
||||
|
||||
(def ^:private initial-flags
|
||||
{::community.edit-account-selection (enabled-in-env? :FLAG_EDIT_ACCOUNT_SELECTION_ENABLED)
|
||||
::community.view-token-requirements (enabled-in-env? :FLAG_VIEW_TOKEN_REQUIREMENTS)
|
||||
|
||||
;; Feature toggled (off by default) because the desktop app disabled this
|
||||
;; feature and we want both clients in sync. We keep the code because it
|
||||
;; works and we may re-enable it by default.
|
||||
::profile-pictures-visibility (enabled-in-env? :FLAG_PROFILE_PICTURES_VISIBILITY_ENABLED)
|
||||
::settings.import-all-keypairs (enabled-in-env?
|
||||
:FLAG_WALLET_SETTINGS_IMPORT_ALL_KEYPAIRS)
|
||||
::settings.import-all-keypairs (enabled-in-env? :FLAG_WALLET_SETTINGS_IMPORT_ALL_KEYPAIRS)
|
||||
::wallet.add-watched-address (enabled-in-env? :FLAG_ADD_WATCHED_ADDRESS)
|
||||
::wallet.advanced-sending (enabled-in-env? :FLAG_ADVANCED_SENDING)
|
||||
::wallet.assets-modal-hide (enabled-in-env? :FLAG_ASSETS_MODAL_HIDE)
|
||||
|
||||
@@ -53,22 +53,18 @@
|
||||
(fn [[{:keys [chats]}] [_ community-id chat-id]]
|
||||
(get chats (string/replace chat-id community-id ""))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
:chats/home-list-chats
|
||||
(re-frame/reg-sub :chats/home-list-chats
|
||||
:<- [:chats/chats]
|
||||
:<- [:chats-home-list]
|
||||
:<- [:multiaccount/public-key]
|
||||
(fn [[chats active-chats my-public-key]]
|
||||
(reduce #(if-let [item (get chats %2)]
|
||||
(let [group-chat-member? (and (chat.events/group-chat? item)
|
||||
(group-chats.db/member? my-public-key item))]
|
||||
(conj %1
|
||||
(assoc item
|
||||
:group-chat-member?
|
||||
group-chat-member?)))
|
||||
%1)
|
||||
[]
|
||||
active-chats)))
|
||||
(fn [[chats active-chats-ids]]
|
||||
(->> active-chats-ids
|
||||
(keep #(get chats %))
|
||||
(sort-by :timestamp >)
|
||||
(map (fn [{:keys [chat-id id public-key group-chat]}]
|
||||
{:chat-id chat-id
|
||||
:group-chat group-chat
|
||||
:id id
|
||||
:public-key public-key})))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
:chats/chat-by-id
|
||||
@@ -391,3 +387,58 @@
|
||||
(re-frame/subscribe [:chats/chat chat-id]))
|
||||
:->
|
||||
:image)
|
||||
|
||||
(comment
|
||||
;; Create a large list of chats
|
||||
(def total-chats 200)
|
||||
(def chat' (first (vals (:chats @re-frame.db/app-db))))
|
||||
|
||||
(let [new-chats (->> (repeat total-chats chat')
|
||||
(map (fn [chat]
|
||||
(-> chat
|
||||
(assoc :chat-id (str (random-uuid)))
|
||||
(assoc-in [:last-message :content :text]
|
||||
(str "Initial " (str (random-uuid)))))))
|
||||
(utils.collection/index-by :chat-id))]
|
||||
(swap! re-frame.db/app-db assoc
|
||||
:chats new-chats
|
||||
:chats-home-list (set (keys new-chats))))
|
||||
|
||||
;; Check the update works for one.
|
||||
(swap! re-frame.db/app-db assoc-in
|
||||
[:chats
|
||||
(:chat-id (nth (vals (:chats @re-frame.db/app-db)) 0))
|
||||
:last-message
|
||||
:content
|
||||
:text]
|
||||
(str (rand-int 10000)))
|
||||
|
||||
;; Randomly update individual chats.
|
||||
(def interval-id
|
||||
(atom
|
||||
(js/setInterval
|
||||
(fn []
|
||||
(let [chats (vals (:chats @re-frame.db/app-db))
|
||||
rand-index (rand-int (dec (count chats)))
|
||||
rand-chat (nth chats rand-index)]
|
||||
(swap! re-frame.db/app-db
|
||||
(fn [db]
|
||||
(-> db
|
||||
(assoc-in [:chats
|
||||
(:chat-id rand-chat)
|
||||
:last-message
|
||||
:content
|
||||
:text]
|
||||
(str (rand-int 10000)))
|
||||
(assoc-in [:chats
|
||||
(:chat-id rand-chat)
|
||||
:timestamp]
|
||||
(utils.datetime/timestamp)))))))
|
||||
;; Exagerate the frequency of updates, but even longer delays will cause problems in
|
||||
;; `develop`.
|
||||
1000)))
|
||||
|
||||
(do
|
||||
(js/clearInterval @interval-id)
|
||||
(reset! interval-id nil))
|
||||
)
|
||||
|
||||
@@ -56,12 +56,12 @@
|
||||
(re-frame/reg-sub
|
||||
:wallet/network-values
|
||||
:<- [:wallet/wallet-send]
|
||||
:<- [:wallet/send-display-token-decimals]
|
||||
(fn [[{:keys [from-values-by-chain to-values-by-chain token-display-name] :as send-data} token-decimals]
|
||||
(fn [{:keys [from-values-by-chain to-values-by-chain token-display-name token] :as send-data}
|
||||
[_ to-values?]]
|
||||
(let [network-values (if to-values? to-values-by-chain from-values-by-chain)
|
||||
token-symbol (or token-display-name
|
||||
(-> send-data :token :symbol))]
|
||||
(-> send-data :token :symbol))
|
||||
token-decimals (:decimals token)]
|
||||
(reduce-kv
|
||||
(fn [acc chain-id amount]
|
||||
(let [network-name (network-utils/id->network chain-id)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
(:require
|
||||
[re-frame.core :as rf]
|
||||
[status-im.constants :as constants]
|
||||
[status-im.contexts.wallet.common.activity-tab.constants :as activity-constants]
|
||||
[status-im.contexts.wallet.common.activity-tab.constants :as activity-tab-constants]
|
||||
[status-im.contexts.wallet.common.utils :as common-utils]
|
||||
[status-im.contexts.wallet.send.utils :as send-utils]
|
||||
[utils.money :as money]
|
||||
@@ -34,6 +34,11 @@
|
||||
:<- [:wallet/wallet-send]
|
||||
:-> :token)
|
||||
|
||||
(rf/reg-sub
|
||||
:wallet/send-token-symbol
|
||||
:<- [:wallet/wallet-send]
|
||||
:-> :token-symbol)
|
||||
|
||||
(rf/reg-sub
|
||||
:wallet/send-transaction-ids
|
||||
:<- [:wallet/wallet-send]
|
||||
@@ -54,6 +59,11 @@
|
||||
:<- [:wallet/wallet-send]
|
||||
:-> :tx-type)
|
||||
|
||||
(rf/reg-sub
|
||||
:wallet/send-network
|
||||
:<- [:wallet/wallet-send]
|
||||
:-> :network)
|
||||
|
||||
(rf/reg-sub
|
||||
:wallet/sending-collectible?
|
||||
:<- [:wallet/send-tx-type]
|
||||
@@ -77,7 +87,7 @@
|
||||
(->> address-activity
|
||||
(sort :timestamp)
|
||||
(keep (fn [{:keys [activity-type recipient]}]
|
||||
(when (= activity-constants/wallet-activity-type-send activity-type)
|
||||
(when (= activity-tab-constants/wallet-activity-type-send activity-type)
|
||||
recipient)))
|
||||
(distinct)))))
|
||||
|
||||
@@ -173,3 +183,39 @@
|
||||
(= (:chain-id network) bridge-to-chain-id)
|
||||
network))
|
||||
networks))))
|
||||
|
||||
(rf/reg-sub
|
||||
:wallet/send-token-grouped-networks
|
||||
:<- [:wallet/wallet-send-token]
|
||||
(fn [token]
|
||||
(let [{token-networks :networks} token
|
||||
grouped-networks (group-by :layer
|
||||
token-networks)
|
||||
mainnet-network (first (get grouped-networks constants/layer-1-network))
|
||||
layer-2-networks (get grouped-networks constants/layer-2-network)]
|
||||
{:mainnet-network mainnet-network
|
||||
:layer-2-networks layer-2-networks})))
|
||||
|
||||
(rf/reg-sub
|
||||
:wallet/send-token-network-balance
|
||||
:<- [:wallet/wallet-send-token]
|
||||
:<- [:profile/currency]
|
||||
:<- [:profile/currency-symbol]
|
||||
:<- [:wallet/prices-per-token]
|
||||
(fn [[token currency currency-symbol prices-per-token] [_ chain-id]]
|
||||
(let [{:keys [balances-per-chain
|
||||
decimals]} token
|
||||
balance-for-chain (get balances-per-chain chain-id)
|
||||
total-balance (money/token->unit (:raw-balance balance-for-chain) decimals)
|
||||
fiat-value (common-utils/calculate-token-fiat-value
|
||||
{:currency currency
|
||||
:balance total-balance
|
||||
:token token
|
||||
:prices-per-token prices-per-token})
|
||||
crypto-formatted (common-utils/get-standard-crypto-format token
|
||||
total-balance
|
||||
prices-per-token)
|
||||
fiat-formatted (common-utils/fiat-formatted-for-ui currency-symbol
|
||||
fiat-value)]
|
||||
{:crypto (str crypto-formatted " " (:symbol token))
|
||||
:fiat fiat-formatted})))
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
[re-frame.core :as rf]
|
||||
[status-im.constants :as constants]
|
||||
[status-im.contexts.wallet.common.utils :as utils]
|
||||
[status-im.contexts.wallet.common.utils.networks :as network-utils]
|
||||
[status-im.contexts.wallet.send.utils :as send-utils]
|
||||
[utils.money :as money]
|
||||
[utils.number :as number]))
|
||||
@@ -334,24 +333,3 @@
|
||||
:token token-for-fees
|
||||
:prices-per-token prices-per-token})]
|
||||
fee-in-fiat)))
|
||||
|
||||
(rf/reg-sub
|
||||
:wallet/accounts-with-balances
|
||||
:<- [:wallet/operable-accounts]
|
||||
:<- [:wallet/swap-asset-to-pay]
|
||||
(fn [[accounts asset-to-pay]]
|
||||
(let [token-symbol (:symbol asset-to-pay)]
|
||||
(map
|
||||
(fn [account]
|
||||
(let [tokens (:tokens account)
|
||||
filtered-tokens (filter #(= (:symbol %) token-symbol) tokens)
|
||||
asset-pay-balance (utils/calculate-total-token-balance filtered-tokens)
|
||||
formatted-address (network-utils/format-address (:address account)
|
||||
(:network-preferences-names account))]
|
||||
(assoc account
|
||||
:formatted-address formatted-address
|
||||
:asset-pay-balance (utils/sanitized-token-amount-to-display
|
||||
asset-pay-balance
|
||||
constants/min-token-decimals-to-display)
|
||||
:asset-pay-symbol token-symbol)))
|
||||
accounts))))
|
||||
|
||||
@@ -152,21 +152,11 @@
|
||||
:<- [:wallet/wallet-send]
|
||||
:-> :to-address)
|
||||
|
||||
(rf/reg-sub
|
||||
:wallet/wallet-send-address-prefix
|
||||
:<- [:wallet/wallet-send]
|
||||
:-> :address-prefix)
|
||||
|
||||
(rf/reg-sub
|
||||
:wallet/wallet-send-receiver-networks
|
||||
:<- [:wallet/wallet-send]
|
||||
:-> :receiver-networks)
|
||||
|
||||
(rf/reg-sub
|
||||
:wallet/wallet-send-receiver-preferred-networks
|
||||
:<- [:wallet/wallet-send]
|
||||
:-> :receiver-preferred-networks)
|
||||
|
||||
(rf/reg-sub
|
||||
:wallet/wallet-send-route
|
||||
:<- [:wallet/wallet-send]
|
||||
@@ -181,14 +171,11 @@
|
||||
:wallet/wallet-send-token
|
||||
:<- [:wallet/wallet-send]
|
||||
:<- [:wallet/network-details]
|
||||
:<- [:wallet/wallet-send-disabled-from-chain-ids]
|
||||
(fn [[wallet-send networks disabled-from-chain-ids]]
|
||||
(let [token (:token wallet-send)
|
||||
disabled-from-chain-ids? (set disabled-from-chain-ids)
|
||||
enabled-from-chain-ids (->> networks
|
||||
(map :chain-id)
|
||||
(remove disabled-from-chain-ids?)
|
||||
set)]
|
||||
(fn [[wallet-send networks]]
|
||||
(let [token (:token wallet-send)
|
||||
enabled-from-chain-ids (->> networks
|
||||
(map :chain-id)
|
||||
set)]
|
||||
(some-> token
|
||||
(assoc :networks (network-utils/network-list-with-positive-balance token networks)
|
||||
:supported-networks (network-utils/network-list token networks)
|
||||
@@ -203,16 +190,6 @@
|
||||
(fn [{:keys [token-symbol token]}]
|
||||
(or token-symbol (:symbol token))))
|
||||
|
||||
(rf/reg-sub
|
||||
:wallet/wallet-send-disabled-from-chain-ids
|
||||
:<- [:wallet/wallet-send]
|
||||
:-> :disabled-from-chain-ids)
|
||||
|
||||
(rf/reg-sub
|
||||
:wallet/wallet-send-from-locked-amounts
|
||||
:<- [:wallet/wallet-send]
|
||||
:-> :from-locked-amounts)
|
||||
|
||||
(rf/reg-sub
|
||||
:wallet/wallet-send-from-values-by-chain
|
||||
:<- [:wallet/wallet-send]
|
||||
@@ -578,6 +555,28 @@
|
||||
(string/lower-case token-symbol)))
|
||||
first)))
|
||||
|
||||
(rf/reg-sub
|
||||
:wallet/token-by-symbol-from-first-available-account-with-balance
|
||||
:<- [:wallet/accounts]
|
||||
:<- [:wallet/current-viewing-account-or-default]
|
||||
:<- [:wallet/network-details]
|
||||
(fn [[accounts {:keys [tokens]} networks] [_ token-symbol chain-ids]]
|
||||
(when token-symbol
|
||||
(or
|
||||
(->> (utils/tokens-with-balance tokens networks chain-ids)
|
||||
(filter #(and (= (string/lower-case (:symbol %))
|
||||
(string/lower-case token-symbol))
|
||||
(money/greater-than (:total-balance %) 0)))
|
||||
first)
|
||||
(some
|
||||
(fn [{:keys [tokens]}]
|
||||
(->> (utils/tokens-with-balance tokens networks chain-ids)
|
||||
(filter #(and (= (string/lower-case (:symbol %))
|
||||
(string/lower-case token-symbol))
|
||||
(money/greater-than (:total-balance %) 0)))
|
||||
first))
|
||||
accounts)))))
|
||||
|
||||
(rf/reg-sub
|
||||
:wallet/accounts-without-current-viewing-account
|
||||
:<- [:wallet/accounts]
|
||||
@@ -831,22 +830,6 @@
|
||||
:<- [:wallet/create-account]
|
||||
:-> :public-address)
|
||||
|
||||
(rf/reg-sub
|
||||
:wallet/wallet-send-enabled-networks
|
||||
:<- [:wallet/wallet-send-token]
|
||||
:<- [:wallet/wallet-send-disabled-from-chain-ids]
|
||||
(fn [[{:keys [networks]} disabled-from-chain-ids]]
|
||||
(->> networks
|
||||
(filter #(not (contains? (set disabled-from-chain-ids)
|
||||
(:chain-id %))))
|
||||
set)))
|
||||
|
||||
(rf/reg-sub
|
||||
:wallet/wallet-send-enabled-from-chain-ids
|
||||
:<- [:wallet/wallet-send-enabled-networks]
|
||||
(fn [send-enabled-networks]
|
||||
(map :chain-id send-enabled-networks)))
|
||||
|
||||
(rf/reg-sub
|
||||
:wallet/wallet-send-fee-fiat-formatted
|
||||
:<- [:wallet/current-viewing-account]
|
||||
@@ -909,3 +892,23 @@
|
||||
:<- [:wallet/accounts-without-current-viewing-account]
|
||||
(fn [accounts]
|
||||
(get-emoji-and-colors-from-accounts accounts)))
|
||||
|
||||
(rf/reg-sub
|
||||
:wallet/accounts-with-balances
|
||||
:<- [:wallet/operable-accounts]
|
||||
(fn [accounts [_ token]]
|
||||
(let [token-symbol (:symbol token)]
|
||||
(map
|
||||
(fn [account]
|
||||
(let [tokens (:tokens account)
|
||||
filtered-tokens (filter #(= (:symbol %) token-symbol) tokens)
|
||||
asset-pay-balance (utils/calculate-total-token-balance filtered-tokens)
|
||||
formatted-address (network-utils/format-address (:address account)
|
||||
(:network-preferences-names account))]
|
||||
(assoc account
|
||||
:formatted-address formatted-address
|
||||
:asset-pay-balance (utils/sanitized-token-amount-to-display
|
||||
asset-pay-balance
|
||||
constants/min-token-decimals-to-display)
|
||||
:asset-pay-symbol token-symbol)))
|
||||
accounts))))
|
||||
|
||||
+23
-1
@@ -2,7 +2,8 @@
|
||||
(:require
|
||||
[clojure.string :as string]
|
||||
[native-module.core :as native-module]
|
||||
[utils.ethereum.eip.eip55 :as eip55]))
|
||||
[utils.ethereum.eip.eip55 :as eip55]
|
||||
[utils.ethereum.eip.eip681 :as eip681]))
|
||||
|
||||
|
||||
(def hex-prefix "0x")
|
||||
@@ -105,11 +106,23 @@
|
||||
[address]
|
||||
(re-find regx-eip-3770-address address))
|
||||
|
||||
(defn eip-681-address?
|
||||
[scanned-text]
|
||||
(-> scanned-text
|
||||
eip681/parse-uri
|
||||
:address
|
||||
boolean))
|
||||
|
||||
(defn supported-address?
|
||||
[s]
|
||||
(boolean (or (eip-3770-address? s)
|
||||
(metamask-address? s))))
|
||||
|
||||
(defn supported-scan-address?
|
||||
[s]
|
||||
(boolean (or (eip-681-address? s)
|
||||
(supported-address? s))))
|
||||
|
||||
(defn metamask-address->eip-3770-address
|
||||
[metamask-address]
|
||||
(when-let [[_ address metamask-network-suffix] (split-metamask-address metamask-address)]
|
||||
@@ -129,9 +142,18 @@
|
||||
[eip-3770-address]
|
||||
(extract-address-without-chains-info eip-3770-address))
|
||||
|
||||
(defn eip-681-address->eth-address
|
||||
[eip-681-address]
|
||||
(-> eip-681-address
|
||||
eip681/parse-uri
|
||||
:address))
|
||||
|
||||
(defn supported-address->eth-address
|
||||
[address]
|
||||
(cond
|
||||
(eip-681-address? address)
|
||||
(eip-681-address->eth-address address)
|
||||
|
||||
(eip-3770-address? address)
|
||||
(eip-3770-address->eth-address address)
|
||||
|
||||
|
||||
+10
-9
@@ -160,15 +160,16 @@
|
||||
;;;; Timestamp formatters
|
||||
(defn- to-str
|
||||
[ms old-fmt-fn yesterday-fmt-fn today-fmt-fn]
|
||||
(let [date (t.coerce/from-long ms)
|
||||
;; NOTE(edge-case): this is wrong, it uses the current timezone offset, regardless of DST.
|
||||
local (t/plus date time-zone-offset)
|
||||
today (t/minus (t/today-at-midnight) time-zone-offset)
|
||||
yesterday (t/plus today (t/days -1))]
|
||||
(cond
|
||||
(t/before? date yesterday) (old-fmt-fn local)
|
||||
(t/before? date today) (yesterday-fmt-fn local)
|
||||
:else (today-fmt-fn local))))
|
||||
(if-let [date (t.coerce/from-long ms)]
|
||||
(let [;; NOTE(edge-case): this is wrong, it uses the current timezone offset, regardless of DST.
|
||||
local (t/plus date time-zone-offset)
|
||||
today (t/minus (t/today-at-midnight) time-zone-offset)
|
||||
yesterday (t/plus today (t/days -1))]
|
||||
(cond
|
||||
(t/before? date yesterday) (old-fmt-fn local)
|
||||
(t/before? date today) (yesterday-fmt-fn local)
|
||||
:else (today-fmt-fn local)))
|
||||
""))
|
||||
|
||||
(defn to-short-str
|
||||
[ms]
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
e.g. ethereum:0x1234@1/transfer?to=0x5678&value=1e18&gas=5000"
|
||||
(:require
|
||||
[clojure.string :as string]
|
||||
[utils.address :as address]
|
||||
[native-module.core :as native-module]
|
||||
[utils.ens.core :as utils.ens]
|
||||
[utils.ethereum.chain :as chain]))
|
||||
|
||||
@@ -18,6 +18,10 @@
|
||||
(def parameter-separator "&")
|
||||
(def key-value-separator "=")
|
||||
|
||||
(defn- address?
|
||||
[address]
|
||||
(native-module/address? address))
|
||||
|
||||
(def uri-pattern
|
||||
(re-pattern (str scheme scheme-separator "([^" query-separator "]*)(?:\\" query-separator "(.*))?")))
|
||||
(def authority-path-pattern
|
||||
@@ -63,16 +67,16 @@
|
||||
Invalid URI will be parsed as `nil`."
|
||||
[s]
|
||||
(when (string? s)
|
||||
(if (address/address? s)
|
||||
(if (address? s)
|
||||
{:address s}
|
||||
(let [[_ authority-path query] (re-find uri-pattern s)]
|
||||
(when authority-path
|
||||
(let [[_ raw-address chain-id function-name] (re-find authority-path-pattern authority-path)]
|
||||
(when (or (or (utils.ens/is-valid-eth-name? raw-address) (address/address? raw-address))
|
||||
(when (or (or (utils.ens/is-valid-eth-name? raw-address) (address? raw-address))
|
||||
(when (string/starts-with? raw-address "pay-")
|
||||
(let [pay-address (string/replace-first raw-address "pay-" "")]
|
||||
(or (utils.ens/is-valid-eth-name? pay-address)
|
||||
(address/address? pay-address)))))
|
||||
(address? pay-address)))))
|
||||
(let [address (if (string/starts-with? raw-address "pay-")
|
||||
(string/replace-first raw-address "pay-" "")
|
||||
raw-address)]
|
||||
@@ -80,7 +84,7 @@
|
||||
(let [contract-address (get-in arguments [:function-arguments :address])]
|
||||
(if-not (or (not contract-address)
|
||||
(or (utils.ens/is-valid-eth-name? contract-address)
|
||||
(address/address? contract-address)))
|
||||
(address? contract-address)))
|
||||
nil
|
||||
(merge {:address address
|
||||
:chain-id (if chain-id
|
||||
@@ -98,7 +102,7 @@
|
||||
"Generate a EIP 681 URI based on `address` and a map (keywords / {bignumbers/strings} ) of extra properties.
|
||||
No validation of address format is performed."
|
||||
[address {:keys [chain-id function-name function-arguments] :as m}]
|
||||
(when (address/address? address)
|
||||
(when (address? address)
|
||||
(let [parameters (dissoc (into {} (filter second m)) :chain-id)] ;; filter nil values
|
||||
(str scheme
|
||||
scheme-separator
|
||||
|
||||
@@ -226,7 +226,7 @@ class TestFallbackMultipleDevice(MultipleSharedDeviceTestCase):
|
||||
self.profile_2.click_system_back_button(times=3)
|
||||
|
||||
wallet_2.just_fyi("Device 2: check wallet balance")
|
||||
wallet_2.select_network(network_name='Arbitrum')
|
||||
wallet_2.set_network_in_wallet(network_name='Arbitrum')
|
||||
expected_balance = self.network_api.get_balance(key_pair_account_address)
|
||||
shown_balance = wallet_2.get_asset(asset_name='Ether').get_amount()
|
||||
if shown_balance != round(expected_balance, 5):
|
||||
|
||||
@@ -32,6 +32,7 @@ class TestWalletMultipleDevice(MultipleSharedDeviceTestCase):
|
||||
self.wallet_1, self.wallet_2 = self.sign_in_1.get_wallet_view(), self.sign_in_2.get_wallet_view()
|
||||
self.wallet_1.wallet_tab.click()
|
||||
self.wallet_2.wallet_tab.click()
|
||||
self.network = "Arbitrum"
|
||||
|
||||
def _get_balances_before_tx(self):
|
||||
sender_balance = self.network_api.get_balance(self.sender['wallet_address'])
|
||||
@@ -85,8 +86,8 @@ class TestWalletMultipleDevice(MultipleSharedDeviceTestCase):
|
||||
(self.home_2.reopen_app, {'user_name': self.receiver_username}))))
|
||||
self.wallet_1.wallet_tab.wait_and_click()
|
||||
self.wallet_2.wallet_tab.wait_and_click()
|
||||
self.wallet_1.select_network(network_name='Arbitrum')
|
||||
self.wallet_2.select_network(network_name='Arbitrum')
|
||||
self.wallet_1.set_network_in_wallet(network_name=self.network)
|
||||
self.wallet_2.set_network_in_wallet(network_name=self.network)
|
||||
self.loop.run_until_complete(
|
||||
run_in_parallel(((wait_for_wallet_balance_to_update, {'wallet_view': self.wallet_1,
|
||||
'user_name': self.sender_username,
|
||||
@@ -123,8 +124,8 @@ class TestWalletMultipleDevice(MultipleSharedDeviceTestCase):
|
||||
|
||||
@marks.testrail_id(727229)
|
||||
def test_wallet_send_eth(self):
|
||||
self.wallet_1.select_network(network_name='Arbitrum')
|
||||
self.wallet_2.select_network(network_name='Arbitrum')
|
||||
self.wallet_1.set_network_in_wallet(network_name=self.network)
|
||||
self.wallet_2.set_network_in_wallet(network_name=self.network)
|
||||
sender_balance, receiver_balance, eth_amount_sender, eth_amount_receiver = self._get_balances_before_tx()
|
||||
|
||||
self.wallet_2.close_account_button.click()
|
||||
@@ -135,7 +136,8 @@ class TestWalletMultipleDevice(MultipleSharedDeviceTestCase):
|
||||
device_time_before_sending = self.wallet_1.driver.device_time
|
||||
self.wallet_1.send_asset(address='arb1:' + self.receiver['wallet_address'],
|
||||
asset_name='Ether',
|
||||
amount=amount_to_send)
|
||||
amount=amount_to_send,
|
||||
network_name=self.network)
|
||||
self.network_api.wait_for_confirmation_of_transaction(address=self.sender['wallet_address'],
|
||||
tx_time=device_time_before_sending)
|
||||
|
||||
@@ -167,7 +169,8 @@ class TestWalletMultipleDevice(MultipleSharedDeviceTestCase):
|
||||
device_time_before_sending = self.wallet_1.driver.device_time
|
||||
self.wallet_1.send_asset_from_drawer(address='arb1:' + self.receiver['wallet_address'],
|
||||
asset_name='Ether',
|
||||
amount=amount_to_send)
|
||||
amount=amount_to_send,
|
||||
network_name=self.network)
|
||||
self.network_api.wait_for_confirmation_of_transaction(address=self.sender['wallet_address'],
|
||||
tx_time=device_time_before_sending)
|
||||
device_time_after_sending = self.wallet_1.driver.device_time
|
||||
@@ -234,7 +237,7 @@ class TestWalletOneDevice(MultipleSharedDeviceTestCase):
|
||||
|
||||
for network in expected_balances:
|
||||
self.wallet_view.just_fyi("Checking total balance on %s network" % network)
|
||||
self.wallet_view.select_network(network)
|
||||
self.wallet_view.set_network_in_wallet(network)
|
||||
real_balance = {}
|
||||
for asset in expected_balances[network]:
|
||||
real_balance[asset] = self.wallet_view.get_asset(asset).get_amount()
|
||||
@@ -242,7 +245,7 @@ class TestWalletOneDevice(MultipleSharedDeviceTestCase):
|
||||
if real_balance[asset] != expected_balances[network][asset]:
|
||||
self.errors.append("For the %s the wrong value %s is shown, expected %s on %s" %
|
||||
(asset, real_balance[asset], expected_balances[network][asset], network))
|
||||
self.wallet_view.select_network(network)
|
||||
self.wallet_view.set_network_in_wallet(network)
|
||||
|
||||
self.errors.verify_no_errors()
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ class WalletView(BaseView):
|
||||
self.key_pair_name_input = EditBox(
|
||||
self.driver, xpath="//*[@text='Key pair name']/..//following-sibling::*/*[@content-desc='input']")
|
||||
|
||||
def select_network(self, network_name: str):
|
||||
def set_network_in_wallet(self, network_name: str):
|
||||
self.network_drop_down.click()
|
||||
Button(self.driver, accessibility_id="%s, label-component" % network_name.capitalize()).click()
|
||||
self.network_drop_down.click()
|
||||
@@ -127,8 +127,12 @@ class WalletView(BaseView):
|
||||
return element
|
||||
|
||||
def select_asset(self, asset_name: str):
|
||||
return Button(driver=self.driver,
|
||||
xpath="//*[@content-desc='token-network']/android.widget.TextView[@text='%s']" % asset_name)
|
||||
Button(driver=self.driver,
|
||||
xpath="//*[@content-desc='token-network']/android.widget.TextView[@text='%s']" % asset_name).click()
|
||||
|
||||
def select_network(self, network_name: str):
|
||||
Button(driver=self.driver,
|
||||
xpath="//*[@content-desc='network-list']/*[@text='%s']" % network_name).click()
|
||||
|
||||
def slide_and_confirm_with_password(self):
|
||||
self.slide_button_track.slide()
|
||||
@@ -148,27 +152,23 @@ class WalletView(BaseView):
|
||||
for i in '{:f}'.format(amount).rstrip('0'):
|
||||
Button(self.driver, accessibility_id='keyboard-key-%s' % i).click()
|
||||
|
||||
def disable_mainnet_in_from_network(self):
|
||||
if self.from_network_text.text == 'Mainnet':
|
||||
self.from_network_text.click()
|
||||
|
||||
def send_asset(self, address: str, asset_name: str, amount: float):
|
||||
def send_asset(self, address: str, asset_name: str, amount: float, network_name: str):
|
||||
self.send_button.click()
|
||||
self.address_text_input.send_keys(address)
|
||||
self.continue_button.click()
|
||||
self.select_asset(asset_name).click()
|
||||
self.select_asset(asset_name)
|
||||
self.select_network(network_name)
|
||||
self.set_amount(amount)
|
||||
self.disable_mainnet_in_from_network()
|
||||
self.confirm_transaction()
|
||||
|
||||
def send_asset_from_drawer(self, address: str, asset_name: str, amount: float):
|
||||
def send_asset_from_drawer(self, address: str, asset_name: str, amount: float, network_name: str):
|
||||
asset_element = self.get_asset(asset_name)
|
||||
asset_element.long_press_element()
|
||||
self.send_from_drawer_button.click()
|
||||
self.select_network(network_name)
|
||||
self.address_text_input.send_keys(address)
|
||||
self.continue_button.click()
|
||||
self.set_amount(amount)
|
||||
self.disable_mainnet_in_from_network()
|
||||
self.confirm_transaction()
|
||||
|
||||
def add_regular_account(self, account_name: str):
|
||||
|
||||
@@ -799,7 +799,6 @@
|
||||
"do-not-cheat": "Don't try to cheat",
|
||||
"do-not-cheat-description": "These 12 words give access to all of your funds so it is important that you write them in the correct order, take it seriously.",
|
||||
"do-not-quit": "Do not quit the application or turn off your device. Doing so will lead to data corruption, loss of your Status profile and the inability to use Status.",
|
||||
|
||||
"do-not-share": "Do not share",
|
||||
"documents": "Documents",
|
||||
"done": "Done",
|
||||
@@ -1387,6 +1386,8 @@
|
||||
"keycard-is-frozen-reset": "Reset with PUK",
|
||||
"keycard-is-frozen-title": "Keycard is frozen",
|
||||
"keycard-locked": "Keycard is locked",
|
||||
"keycard-migration-failed-instruction-1": "Try logging out and logging back in with Keycard; everything might work fine.",
|
||||
"keycard-migration-failed-instruction-2": "If the key pair hasn’t migrated to Keycard, remove your profile, and recover it using your recovery phrase.",
|
||||
"keycard-not-empty": "Keycard is not empty",
|
||||
"keycard-onboarding-finishing-header": "Finishing up",
|
||||
"keycard-onboarding-intro-header": "Store your keys on Keycard",
|
||||
@@ -2285,8 +2286,11 @@
|
||||
"select-chat": "Select chat to start messaging",
|
||||
"select-network": "Select network",
|
||||
"select-network-for-buying": "Select network for buying",
|
||||
"select-network-to-bridge-from": "Select network to bridge from",
|
||||
"select-network-to-receive": "Select network to receive",
|
||||
"select-networks": "Select networks",
|
||||
"select-new-location-for-keys": "Select a new location to save your private key(s)",
|
||||
"select-token": "Select token",
|
||||
"select-token-to-receive": "Select token to receive",
|
||||
"select-token-to-swap": "Select token to Swap",
|
||||
"selected": "Selected",
|
||||
@@ -2428,6 +2432,7 @@
|
||||
"slippage-should-be-more-than-0": "Slippage should be more than 0",
|
||||
"slow": "Slow",
|
||||
"something-about-you": "Something about you",
|
||||
"something-didnt-go-as-planned": "Something didn't go as planned",
|
||||
"something-went-wrong": "Something went wrong",
|
||||
"something-went-wrong-please-try-again-later": "Something went wrong. Modify swap parameters or try again later.",
|
||||
"soon": "Soon",
|
||||
|
||||
@@ -9584,9 +9584,9 @@ react-native-static-safe-area-insets@^2.2.0:
|
||||
resolved "https://registry.yarnpkg.com/react-native-static-safe-area-insets/-/react-native-static-safe-area-insets-2.2.0.tgz#dd86b6a38f43964fac8df8c0e6bc8e062527786c"
|
||||
integrity sha512-TLTW2e2kRK3COSK8gMZzwp4wHguFCtcO18itDLn5av/xQblXt9ylu84o+qD9aKJCBfvtNzGOvqqTKqC5GJRZ/g==
|
||||
|
||||
"react-native-status-keycard@git+https://github.com/status-im/react-native-status-keycard.git#refs/tags/v2.6.3":
|
||||
"react-native-status-keycard@git+https://github.com/status-im/react-native-status-keycard.git#refs/tags/v2.6.4":
|
||||
version "2.6.2"
|
||||
resolved "git+https://github.com/status-im/react-native-status-keycard.git#735bed7f9838b87712f1fd2978208186d28ea61c"
|
||||
resolved "git+https://github.com/status-im/react-native-status-keycard.git#e78f46de10d65cfef2df2f62b6f41e64e0c332b9"
|
||||
|
||||
react-native-svg@13.10.0:
|
||||
version "13.10.0"
|
||||
|
||||
Reference in New Issue
Block a user