Skip to content

Commit

Permalink
feat(wallet)_: Activity - clean up, moved to new session rpc and adde…
Browse files Browse the repository at this point in the history
…d bridge, swap and approval types

status-im/status-go@032eb5b...2e3dd26

Signed-off-by: Mohamed Javid <[email protected]>
  • Loading branch information
smohamedjavid committed Nov 26, 2024
1 parent 4b2a1db commit 2f85bf3
Show file tree
Hide file tree
Showing 22 changed files with 605 additions and 440 deletions.
3 changes: 2 additions & 1 deletion src/quo/components/wallet/wallet_activity/schema.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
[:catn
[:props
[:map
[:transaction {:optional true} [:maybe [:enum :receive :send :swap :bridge :buy :destroy :mint]]]
[:transaction {:optional true}
[:maybe [:enum :receive :send :swap :bridge :buy :destroy :mint :approval]]]
[:status {:optional true} [:maybe [:enum :pending :confirmed :finalised :failed]]]
[:counter {:optional true} [:maybe :int]]
[:timestamp {:optional true} [:maybe :string]]
Expand Down
3 changes: 2 additions & 1 deletion src/quo/components/wallet/wallet_activity/style.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
colors/white-opa-10)})

(def timestamp-container
{:margin-left 4})
{:margin-left 4
:flex 1})

(defn timestamp
[theme blur?]
Expand Down
45 changes: 27 additions & 18 deletions src/quo/components/wallet/wallet_activity/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,24 @@
[utils.i18n :as i18n]))

(def transaction-translation
{:receive [i18n/label :t/receive]
:send [i18n/label :t/send]
:swap [i18n/label :t/swap]
:bridge [i18n/label :t/bridge]
:buy [i18n/label :t/buy]
:destroy [i18n/label :t/destroy]
:mint [i18n/label :t/mint]})
{:receive [i18n/label :t/receive]
:send [i18n/label :t/send]
:swap [i18n/label :t/swap]
:bridge [i18n/label :t/bridge]
:buy [i18n/label :t/buy]
:destroy [i18n/label :t/destroy]
:mint [i18n/label :t/mint]
:approval [i18n/label :t/set-spending-cap]})

(def transaction-icon
{:receive :i/receive
:send :i/send
:swap :i/transaction
:bridge :i/bridge
:buy :i/buy
:destroy :i/destroy
:mint :i/mint})
{:receive :i/receive
:send :i/send
:swap :i/transaction
:bridge :i/bridge
:buy :i/buy
:destroy :i/destroy
:mint :i/mint
:approval :i/token-sales})

(def status-icon
{:pending :i/pending-state
Expand All @@ -39,7 +41,8 @@
[{:keys [transaction
timestamp
counter
blur?]
blur?
on-press-options]
:or {transaction :receive
counter 1}}
theme]
Expand All @@ -64,7 +67,13 @@
:size :label
:style (style/timestamp theme blur?)
:accessibility-label :transaction-timestamp}
timestamp]]])
timestamp]]
(when on-press-options
[rn/pressable
{:on-press on-press-options
:hit-slop {:top 10 :bottom 10 :left 10 :right 10}}
[icon/icon :i/options
{:size 20}]])])

(defn transaction-icon-view
[{:keys [blur? transaction status]
Expand Down Expand Up @@ -120,8 +129,8 @@
:accessibility-label :wallet-activity
:disabled (= state :disabled)
:on-press on-press
:on-press-in on-press-in
:on-press-out on-press-out}
:on-press-in (when on-press on-press-in)
:on-press-out (when on-press on-press-out)}
[rn/view {:style style/container}
[transaction-icon-view props theme]
[rn/view {:style {:flex 1}}
Expand Down
6 changes: 6 additions & 0 deletions src/status_im/config.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
(def sepolia-chain-explorer-link "https://sepolia.etherscan.io/address/")
(def optimism-sepolia-chain-explorer-link "https://sepolia-optimistic.etherscan.io/address/")
(def arbitrum-sepolia-chain-explorer-link "https://sepolia.arbiscan.io/address/")
(def mainnet-tx-details-base-link "https://etherscan.io/tx")
(def optimism-mainnet-tx-details-base-link "https://optimistic.etherscan.io/tx")
(def arbitrum-mainnet-tx-details-base-link "https://arbiscan.io/tx")
(def mainnet-sepolia-tx-details-base-link "https://sepolia.etherscan.io/tx")
(def optimism-sepolia-tx-details-base-link "https://sepolia-optimistic.etherscan.io/tx")
(def arbitrum-sepolia-tx-details-base-link "https://sepolia.arbiscan.io/tx")
(def opensea-link "https://opensea.io")
(def opensea-tesnet-link "https://testnets.opensea.io")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@
{:key :bridge}
{:key :buy}
{:key :destroy}
{:key :mint}]}
{:key :mint}
{:key :approval}]}
{:key :status
:type :select
:options [{:key :pending}
Expand Down Expand Up @@ -219,7 +220,8 @@
:descriptor descriptor
:blur? (:blur? @component-state)
:show-blur-background? true}
[rn/view {:style {:align-self :center}}
[rn/view {:style {:flex 1}}
[quo/wallet-activity
(merge {:on-press #(js/alert "Dropdown pressed")}
(merge {:on-press #(js/alert "Activity pressed")
:on-press-options #(js/alert "Options pressed")}
@component-state)]]])))
2 changes: 0 additions & 2 deletions src/status_im/contexts/wallet/account/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
(hot-reload/use-safe-unmount (fn []
(rf/dispatch [:wallet/close-account-page])
(rf/dispatch [:wallet/clean-current-viewing-account])))
(rn/use-mount
#(rf/dispatch [:wallet/fetch-activities-for-current-account]))
[rn/view {:style {:flex 1}}
[account-switcher/view
{:type :wallet-networks
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
(ns status-im.contexts.wallet.common.activity-tab.activity-types.view
(:require [quo.core :as quo]
[status-im.contexts.wallet.common.activity-tab.options.view :as activity-options]
[utils.re-frame :as rf]))

;; Common helpers
(defn- open-options
[transactions]
(rf/dispatch
[:show-bottom-sheet
{:content #(activity-options/view (first transactions))}]))

(defn- common-activity-props
[{:keys [tx-type relative-date status transactions]}]
{:transaction tx-type
:timestamp relative-date
:status status
:blur? false
:on-press-options #(open-options transactions)})

(defn- network-tag
[{:keys [network-name network-logo]}]
{:type :network
:network-name network-name
:network-logo network-logo})

(defn- collectible-tag
[{:keys [nft-url nft-name amount token-id]}]
{:type :collectible
:collectible nft-url
:collectible-name (if (> amount 1)
(str amount " " nft-name)
nft-name)
:collectible-number (when (not= token-id "0")
token-id)})

(defn- token-tag
[{:keys [token amount]}]
{:type :token
:token token
:amount amount})

;; Activity type views
(defn send-activity
[{:keys [symbol-out amount-out token-id sender-tag recipient-tag network-name-out network-logo-out]
:as activity-data}]
(let [base-props (common-activity-props activity-data)
first-tag (if token-id
(collectible-tag activity-data)
(token-tag {:token symbol-out :amount amount-out}))]
[quo/wallet-activity
(assoc base-props
:first-tag first-tag
:second-tag-prefix :t/from
:second-tag sender-tag
:third-tag-prefix :t/to
:third-tag recipient-tag
:fourth-tag-prefix :t/on
:fourth-tag (network-tag {:network-name network-name-out
:network-logo network-logo-out}))]))

(defn bridge-activity
[{:keys [symbol-out amount-out network-name-out network-logo-out network-name-in network-logo-in
sender-tag]
:as activity-data}]
[quo/wallet-activity
(assoc (common-activity-props activity-data)
:first-tag (token-tag {:token symbol-out :amount amount-out})
:second-tag-prefix :t/from
:second-tag (network-tag {:network-name network-name-out
:network-logo network-logo-out})
:third-tag-prefix :t/to
:third-tag (network-tag {:network-name network-name-in
:network-logo network-logo-in})
:fourth-tag-prefix :t/in
:fourth-tag sender-tag)])

(defn swap-activity
[{:keys [symbol-out amount-out symbol-in amount-in sender-tag network-name-out network-logo-out]
:as activity-data}]
[quo/wallet-activity
(assoc (common-activity-props activity-data)
:first-tag (token-tag {:token symbol-out :amount amount-out})
:second-tag-prefix :t/to
:second-tag (token-tag {:token symbol-in :amount amount-in})
:third-tag-prefix :t/in
:third-tag sender-tag
:fourth-tag-prefix :t/on
:fourth-tag (network-tag {:network-name network-name-out
:network-logo network-logo-out}))])

(defn approval-activity
[{:keys [symbol-out amount-out sender-tag spender-tag network-name-out network-logo-out]
:as activity-data}]
[quo/wallet-activity
(assoc (common-activity-props activity-data)
:first-tag (token-tag {:token symbol-out :amount amount-out})
:second-tag-prefix :t/in
:second-tag sender-tag
:third-tag-prefix :t/for
:third-tag spender-tag
:fourth-tag-prefix :t/on
:fourth-tag (network-tag {:network-name network-name-out
:network-logo network-logo-out}))])
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
(ns status-im.contexts.wallet.common.activity-tab.constants)


(def ^:const wallet-activity-error-code-success 1)
(def ^:const wallet-activity-error-code-task-canceled 2)
(def ^:const wallet-activity-error-code-failed 3)
Expand All @@ -12,6 +11,7 @@
(def ^:const wallet-activity-type-bridge 4)
(def ^:const wallet-activity-type-contract-deployment 5)
(def ^:const wallet-activity-type-mint 6)
(def ^:const wallet-activity-type-approval 7)

(def ^:const wallet-activity-status-failed 0)
(def ^:const wallet-activity-status-pending 1)
Expand Down Expand Up @@ -62,4 +62,3 @@
wallet-activity-type-buy :t/via
wallet-activity-type-swap :t/via
wallet-activity-type-bridge :t/in})

Loading

0 comments on commit 2f85bf3

Please sign in to comment.