Old wallet

This commit is contained in:
Roman Volosovskyi 2023-05-17 11:14:00 +02:00
parent e14ed7a637
commit a18cf2f786
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
19 changed files with 116 additions and 82 deletions

View File

@ -294,7 +294,7 @@
(re-frame/reg-fx
;;TODO: this could be replaced by a single API call on status-go side
::initialize-wallet
(fn [[network-id callback]]
(fn [[network-id network callback]]
(-> (js/Promise.all
(clj->js
[(js/Promise.
@ -302,12 +302,31 @@
(json-rpc/call {:method "accounts_getAccounts"
:on-success resolve
:on-error reject})))
(js/Promise.
(fn [resolve _]
(json-rpc/call
{:method "wallet_addEthereumChain"
:params
[{:isTest false
:tokenOverrides []
:rpcUrl (get-in network [:config :UpstreamConfig :URL])
:chainColor "green"
:chainName (:name network)
:nativeCurrencyDecimals 10
:shortName "erc20"
:layer 1
:chainId (int network-id)
:enabled false
:fallbackURL (get-in network [:config :UpstreamConfig :URL])}]
:on-success resolve
:on-error (fn [_] (resolve nil))})))
(js/Promise.
(fn [resolve _]
(json-rpc/call {:method "wallet_getTokens"
:params [(int network-id)]
:on-success resolve
:on-error #(resolve nil)})))
:on-error (fn [_]
(resolve nil))})))
(js/Promise.
(fn [resolve reject]
(json-rpc/call {:method "wallet_getCustomTokens"
@ -318,7 +337,7 @@
(json-rpc/call {:method "wallet_getSavedAddresses"
:on-success resolve
:on-error reject})))]))
(.then (fn [[accounts tokens custom-tokens favourites]]
(.then (fn [[accounts _ tokens custom-tokens favourites]]
(callback accounts
(normalize-tokens network-id tokens)
(mapv #(update % :symbol keyword) custom-tokens)
@ -449,6 +468,7 @@
[{:keys [db] :as cofx}]
(let [{:networks/keys [current-network networks]} db
notifications-enabled? (get-in db [:multiaccount :notifications-enabled?])
current-network-config (get networks current-network)
network-id (str (get-in networks
[current-network :config :NetworkId]))
remote-push-notifications-enabled?
@ -460,6 +480,7 @@
:on-disabled #(log/info "eip1559 is not activated")}
::initialize-wallet
[network-id
current-network-config
(fn [accounts tokens custom-tokens favourites]
(re-frame/dispatch [::initialize-wallet
accounts tokens custom-tokens favourites]))]

View File

@ -219,9 +219,10 @@
(rf/defn update-estimated-gas-success
{:events [:signing/update-estimated-gas-success]}
[{db :db} gas]
{:db (-> db
(assoc-in [:signing/tx :gas] gas)
(assoc-in [:signing/edit-fee :gas-loading?] false))})
(when (contains? db :signing/tx)
{:db (-> db
(assoc-in [:signing/tx :gas] gas)
(assoc-in [:signing/edit-fee :gas-loading?] false))}))
(rf/defn update-gas-price-success
{:events [:signing/update-gas-price-success]}

View File

@ -384,8 +384,7 @@
(fn [prices wallet-currency amount amount-error display-symbol fee-display-symbol prices-loading?]
(let [converted-value (* amount
(get-in prices
[(keyword display-symbol) (keyword (:code wallet-currency))
:price]))]
[(keyword display-symbol) (keyword (:code wallet-currency))]))]
[quo/list-item
{:size :small
:title (if amount-error
@ -412,8 +411,8 @@
show-error (reagent/atom false)]
(let [converted-fee-value (* fee
(get-in prices
[(keyword fee-display-symbol) (keyword (:code wallet-currency))
:price]))]
[(keyword fee-display-symbol)
(keyword (:code wallet-currency))]))]
[quo/list-item
{:size :small
:title (if (and (not (or gas-price-loading? gas-loading?)) gas-error)

View File

@ -1,12 +1,15 @@
(ns status-im.ui.screens.wallet.account.styles
(:require [quo.design-system.colors :as colors]
(:require [clojure.string :as string]
[quo.design-system.colors :as colors]
[status-im.ui.components.animation :as animation]))
(defn card
[window-width color]
{:width (- window-width 30)
:height 161
:background-color color
:background-color (if (string/blank? color)
colors/blue
color)
:shadow-offset {:width 0 :height 2}
:shadow-radius 8
:shadow-opacity 1

View File

@ -92,4 +92,4 @@
:accessibility-label (str (:symbol token) "-asset-value")
:icon (if icon
[wallet.components/token-icon icon]
[chat-icon/custom-icon-view-list (:name token) color])}])
[chat-icon/custom-icon-view-list (:name token) color])}])

View File

@ -1,5 +1,6 @@
(ns status-im.ui.screens.wallet.accounts.styles
(:require [quo.animated :as animated]
(:require [clojure.string :as string]
[quo.animated :as animated]
[quo.design-system.colors :as colors]))
(def dot-size 6)
@ -68,7 +69,9 @@
(defn card
[color card-width]
(merge (card-common card-width)
{:background-color color
{:background-color (if (string/blank? color)
colors/blue
color)
:justify-content :space-between
:padding-horizontal 12
:padding-top 12

View File

@ -120,7 +120,6 @@
{:horizontal true
:deceleration-rate "fast"
:snap-to-interval page-width
:snap-to-alignment "left"
:shows-horizontal-scroll-indicator false
:scroll-event-throttle 64
:on-scroll #(let [x (.-nativeEvent.contentOffset.x ^js %)]

View File

@ -80,7 +80,7 @@
[react/scroll-view
{:horizontal true
:deceleration-rate "fast"
:snap-to-alignment "left"
:snap-to-alignment "start"
:shows-horizontal-scroll-indicator
false
:scroll-event-throttle 64

View File

@ -8,16 +8,22 @@
[status-im.ui.components.react :as react]
[status-im.ui.screens.wallet.accounts.common :as common]))
(defn asset
[currency token]
[react/touchable-highlight
{:on-press #(re-frame/dispatch [:wallet.send/set-symbol (:symbol token)])}
[common/render-asset token nil nil (:code currency)]])
(views/defview assets
[address]
(views/letsubs [{:keys [tokens]} [:wallet/visible-assets-with-values address]
currency [:wallet/currency]]
[:<>
(for [token tokens]
^{:key (str (:symbol token))}
[react/touchable-highlight
{:on-press #(re-frame/dispatch [:wallet.send/set-symbol (:symbol token)])}
[common/render-asset token nil nil (:code currency)]])]))
[react/view
{:style {:height 300}}
[list/flat-list
{:data tokens
:key-fn :symbol
:render-fn (partial asset currency)}]]))
(defn render-account
[account _ _ {:keys [field event]}]

View File

@ -1,6 +1,7 @@
(ns status-im.ui.screens.wallet.send.views
(:require-macros [status-im.utils.views :refer [defview letsubs] :as views])
(:require [quo.core :as quo]
[quo2.core :as quo2]
[quo.design-system.colors :as colors]
[re-frame.core :as re-frame]
[status-im.commands.core :as commands]
@ -234,6 +235,17 @@
(let [to-norm (ethereum/normalized-hex (if (string? to) to (:address to)))]
[kb-presentation/keyboard-avoiding-view {:style {:flex 1}}
[:<>
[quo2/page-nav
{:align-mid? true
:mid-section {:type :text-only
:main-text (i18n/label :t/send-transaction)}
:left-section {:on-press #(do
(re-frame/dispatch [:navigate-back])
(re-frame/dispatch
[:wallet/cancel-transaction-command]))
:icon :i/arrow-left
:accessibility-label :back-button}}]
[react/scroll-view
{:style {:flex 1}
:keyboard-should-persist-taps :handled}

View File

@ -199,7 +199,7 @@
(-> amount-str
(js/parseFloat)
bignumber
(crypto->fiat (get-in prices [from to :price] ^js (bignumber 0)))
(crypto->fiat (get-in prices [from to] ^js (bignumber 0)))
(with-precision 2)
str))

View File

@ -4,22 +4,14 @@
(defn- format-price-resp
[resp to mainnet?]
(if mainnet?
(when (seq resp)
(into {}
(for [[from price] resp]
{from {(keyword to) {:from (name from)
:to to
:price price}}})))
resp
{:ETH (into {}
(for [[_ price] resp]
{(keyword to) {:from "ETH"
:to to
:price price}}))}))
{(keyword to) price}))}))
(defn get-prices
[from to mainnet? on-success on-error]
(let [to (first to)]
(json-rpc/call {:method "wallet_fetchPrices"
:params [from to]
:on-success (fn [resp] (on-success (format-price-resp resp to mainnet?)))
:on-error on-error})))
(json-rpc/call {:method "wallet_fetchPrices"
:params [from to]
:on-success (fn [resp] (on-success (format-price-resp resp to mainnet?)))
:on-error on-error}))

View File

@ -197,8 +197,8 @@
new-accounts (conj accounts account)]
(when account
(rf/merge cofx
{:json-rpc/call [{:method "accounts_saveAccounts"
:params [[account]]
{:json-rpc/call [{:method "accounts_saveAccount"
:params [account]
:on-success #(re-frame/dispatch [::wallet/restart])}]
:db (-> db
(assoc :multiaccount/accounts new-accounts)
@ -293,8 +293,8 @@
color (assoc :color color)
(not (nil? hidden)) (assoc :hidden hidden))
new-accounts (replace {account new-account} accounts)]
{:json-rpc/call [{:method "accounts_saveAccounts"
:params [[new-account]]
{:json-rpc/call [{:method "accounts_saveAccount"
:params [new-account]
:on-success #()}]
:db (assoc db :multiaccount/accounts new-accounts)}))

View File

@ -381,30 +381,31 @@
(rf/defn wallet-send-gas-price-success
{:events [:wallet.send/update-gas-price-success]}
[{db :db} tx-entry price {:keys [maxFeePerGas maxPriorityFeePerGas gasPrice]}]
(if (eip1559/sync-enabled?)
(let [{:keys [slow-base-fee normal-base-fee fast-base-fee
current-base-fee max-priority-fee]}
price
max-priority-fee-bn (money/with-precision (signing.gas/get-suggested-tip max-priority-fee) 0)
fee-cap (-> normal-base-fee
money/bignumber
(money/add max-priority-fee-bn)
money/to-hex)
tip-cap (money/to-hex max-priority-fee-bn)]
(when (contains? db tx-entry)
(if (eip1559/sync-enabled?)
(let [{:keys [slow-base-fee normal-base-fee fast-base-fee
current-base-fee max-priority-fee]}
price
max-priority-fee-bn (money/with-precision (signing.gas/get-suggested-tip max-priority-fee) 0)
fee-cap (-> normal-base-fee
money/bignumber
(money/add max-priority-fee-bn)
money/to-hex)
tip-cap (money/to-hex max-priority-fee-bn)]
{:db (-> db
(update tx-entry
assoc
:maxFeePerGas (or maxFeePerGas fee-cap)
:maxPriorityFeePerGas (or maxPriorityFeePerGas tip-cap))
(assoc :wallet/current-base-fee current-base-fee
:wallet/normal-base-fee normal-base-fee
:wallet/slow-base-fee slow-base-fee
:wallet/fast-base-fee fast-base-fee
:wallet/current-priority-fee max-priority-fee)
(assoc-in [:signing/edit-fee :gas-price-loading?] false))})
{:db (-> db
(update tx-entry
assoc
:maxFeePerGas (or maxFeePerGas fee-cap)
:maxPriorityFeePerGas (or maxPriorityFeePerGas tip-cap))
(assoc :wallet/current-base-fee current-base-fee
:wallet/normal-base-fee normal-base-fee
:wallet/slow-base-fee slow-base-fee
:wallet/fast-base-fee fast-base-fee
:wallet/current-priority-fee max-priority-fee)
(assoc-in [:signing/edit-fee :gas-price-loading?] false))})
{:db (-> db
(assoc-in [:wallet/prepare-transaction :gasPrice] (or gasPrice price))
(assoc-in [:signing/edit-fee :gas-price-loading?] false))}))
(assoc-in [:wallet/prepare-transaction :gasPrice] (or gasPrice price))
(assoc-in [:signing/edit-fee :gas-price-loading?] false))})))
(rf/defn set-max-amount
{:events [:wallet.send/set-max-amount]}

View File

@ -33,7 +33,7 @@
(case stack-id
:communities-stack [communities/home]
:chats-stack [chat/home]
:wallet-stack [wallet.accounts/accounts-overview]
:wallet-stack [wallet.accounts/accounts-overview-old]
:browser-stack [browser.stack/browser-stack])])
(defn lazy-screen

View File

@ -57,7 +57,7 @@
(fn [[prices {:keys [code]} {:keys [symbol]}]]
[(name symbol)
code
(get-in prices [symbol (keyword code) :price])]))
(get-in prices [symbol (keyword code)])]))
(re-frame/reg-sub
:signing/priority-fee-suggestions-range

View File

@ -45,7 +45,7 @@
:price
:<- [:prices]
(fn [prices [_ fsym tsym]]
(get-in prices [fsym tsym :price])))
(get-in prices [fsym tsym])))
(re-frame/reg-sub
:last-day
@ -62,7 +62,7 @@
(defn get-balance-total-value
[balance prices currency token->decimals]
(reduce-kv (fn [acc symbol value]
(if-let [price (get-in prices [symbol currency :price])]
(if-let [price (get-in prices [symbol currency])]
(+ acc
(or (some-> (money/internal->formatted value symbol (token->decimals symbol))
^js (money/crypto->fiat price)
@ -194,7 +194,8 @@
(defn update-value
[prices currency]
(fn [{:keys [symbol decimals amount] :as token}]
(let [price (get-in prices [symbol (-> currency :code keyword) :price])]
(let [currency-kw (-> currency :code keyword)
price (get-in prices [symbol currency-kw])]
(assoc token
:price price
:value (when (and amount price)

View File

@ -32,12 +32,8 @@
:max-block 10}}})
(def prices
{:ETH {:USD {:from "ETH"
:to "USD"
:price 1282.23}}
:SNT {:USD {:from "SNT"
:to "USD"
:price 0.0232}}})
{:ETH {:USD 1282.23}
:SNT {:USD 0.0232}})
(def tokens
{"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
@ -76,9 +72,9 @@
{:ETH (money/bignumber 1000000000000000000)
:SNT (money/bignumber 100000000000000000000)
:AST (money/bignumber 10000)}
{:ETH {:USD {:from "ETH" :to "USD" :price 677.91 :last-day 658.688}}
:SNT {:USD {:from "SNT" :to "USD" :price 0.1562 :last-day 0.15}}
:AST {:USD {:from "AST" :to "USD" :price 4 :last-day 3}}}
{:ETH {:USD 677.91}
:SNT {:USD 0.1562}
:AST {:USD 4}}
:USD
{:ETH 18
:SNT 18

View File

@ -3,7 +3,7 @@
"_comment": "Instead use: scripts/update-status-go.sh <rev>",
"owner": "status-im",
"repo": "status-go",
"version": "v0.151.15",
"commit-sha1": "75864528b130f60f9fdd58d1d404b02bab5e1a3c",
"src-sha256": "1mr26p154187jsgi0jgwakfxgnqnhzy8g0fxb118pzy3d9ax5awh"
"version": "v0.152.2",
"commit-sha1": "ee4003279aee0f8f1c80e4382fb16108aaac1384",
"src-sha256": "1a4v8bgxals5v4agbqssddq9vwjkz9k005zmyjs3mfyqsq0ahk35"
}