[refactor] use `ethereum` `current-address` and `chain-keyword`
in many places in the codebase, we are doing various destructuring and function calls to get the normalized current address and the chain keyword for the current network this PR replace all usages by utility functions introduced recently Signed-off-by: yenda <eric@status.im>
This commit is contained in:
parent
f551a3c0c5
commit
ded207ead2
|
@ -85,13 +85,12 @@
|
||||||
(re-frame/dispatch [:browser.callback/resolve-ens-multihash-error]))))
|
(re-frame/dispatch [:browser.callback/resolve-ens-multihash-error]))))
|
||||||
|
|
||||||
(fx/defn resolve-url
|
(fx/defn resolve-url
|
||||||
[{{:keys [network] :as db} :db} {:keys [error? resolved-url]}]
|
[{:keys [db]} {:keys [error? resolved-url]}]
|
||||||
(when (not error?)
|
(when (not error?)
|
||||||
(let [current-url (get-current-url (get-current-browser db))
|
(let [current-url (get-current-url (get-current-browser db))
|
||||||
host (http/url-host current-url)]
|
host (http/url-host current-url)]
|
||||||
(if (and (not resolved-url) (ens/is-valid-eth-name? host))
|
(if (and (not resolved-url) (ens/is-valid-eth-name? host))
|
||||||
(let [network (get-in db [:account/account :networks network])
|
(let [chain (ethereum/chain-keyword db)]
|
||||||
chain (ethereum/network->chain-keyword network)]
|
|
||||||
{:db (update db :browser/options assoc :resolving? true)
|
{:db (update db :browser/options assoc :resolving? true)
|
||||||
:browser/resolve-ens-content {:registry (get ens/ens-registries
|
:browser/resolve-ens-content {:registry (get ens/ens-registries
|
||||||
chain)
|
chain)
|
||||||
|
@ -100,11 +99,10 @@
|
||||||
{:db (update db :browser/options assoc :url (or resolved-url current-url) :resolving? false)}))))
|
{:db (update db :browser/options assoc :url (or resolved-url current-url) :resolving? false)}))))
|
||||||
|
|
||||||
(fx/defn resolve-ens-contenthash
|
(fx/defn resolve-ens-contenthash
|
||||||
[{{:keys [network] :as db} :db}]
|
[{:keys [db]}]
|
||||||
(let [current-url (get-current-url (get-current-browser db))
|
(let [current-url (get-current-url (get-current-browser db))
|
||||||
host (http/url-host current-url)]
|
host (http/url-host current-url)]
|
||||||
(let [network (get-in db [:account/account :networks network])
|
(let [chain (ethereum/chain-keyword db)]
|
||||||
chain (ethereum/network->chain-keyword network)]
|
|
||||||
{:db (update db :browser/options assoc :resolving? true)
|
{:db (update db :browser/options assoc :resolving? true)
|
||||||
:browser/resolve-ens-contenthash {:registry (get ens/ens-registries
|
:browser/resolve-ens-contenthash {:registry (get ens/ens-registries
|
||||||
chain)
|
chain)
|
||||||
|
|
|
@ -12,6 +12,5 @@
|
||||||
|
|
||||||
(defn get-address
|
(defn get-address
|
||||||
[db contract]
|
[db contract]
|
||||||
(let [chain-keyword (-> (get-in db [:account/account :networks (:network db)])
|
(let [chain-keyword (ethereum/chain-keyword db)]
|
||||||
ethereum/network->chain-keyword)]
|
|
||||||
(get-in contracts [contract chain-keyword])))
|
(get-in contracts [contract chain-keyword])))
|
||||||
|
|
|
@ -37,12 +37,11 @@
|
||||||
(fx/defn new-block
|
(fx/defn new-block
|
||||||
[{:keys [db] :as cofx} {:keys [number transactions] :as block}]
|
[{:keys [db] :as cofx} {:keys [number transactions] :as block}]
|
||||||
(when number
|
(when number
|
||||||
(let [{:keys [:account/account :wallet/all-tokens network
|
(let [{:keys [:wallet/all-tokens :ethereum/current-block]} db
|
||||||
:ethereum/current-block]} db
|
chain (ethereum/chain-keyword db)
|
||||||
chain (ethereum/network->chain-keyword (get-in account [:networks network]))
|
|
||||||
chain-tokens (into {} (map (juxt :address identity)
|
chain-tokens (into {} (map (juxt :address identity)
|
||||||
(tokens/tokens-for all-tokens chain)))
|
(tokens/tokens-for all-tokens chain)))
|
||||||
wallet-address (ethereum/normalized-address (:address account))
|
wallet-address (ethereum/current-address db)
|
||||||
token-contracts-addresses (into #{} (keys chain-tokens))]
|
token-contracts-addresses (into #{} (keys chain-tokens))]
|
||||||
(fx/merge cofx
|
(fx/merge cofx
|
||||||
{:db (assoc-in db [:ethereum/current-block] number)
|
{:db (assoc-in db [:ethereum/current-block] number)
|
||||||
|
@ -94,11 +93,11 @@
|
||||||
|
|
||||||
(fx/defn initialize
|
(fx/defn initialize
|
||||||
[{:keys [db] :as cofx}]
|
[{:keys [db] :as cofx}]
|
||||||
(let [{:keys [:account/account :wallet/all-tokens network]} db
|
(let [{:keys [:wallet/all-tokens]} db
|
||||||
chain (ethereum/network->chain-keyword (get-in account [:networks network]))
|
chain (ethereum/chain-keyword db)
|
||||||
chain-tokens (into {} (map (juxt :address identity)
|
chain-tokens (into {} (map (juxt :address identity)
|
||||||
(tokens/tokens-for all-tokens chain)))
|
(tokens/tokens-for all-tokens chain)))
|
||||||
normalized-address (ethereum/normalized-address (:address account))
|
normalized-address (ethereum/current-address db)
|
||||||
padded-address (transactions/add-padding normalized-address)]
|
padded-address (transactions/add-padding normalized-address)]
|
||||||
{:ethereum.subscriptions/new-block nil
|
{:ethereum.subscriptions/new-block nil
|
||||||
:ethereum.subscriptions/token-transactions
|
:ethereum.subscriptions/token-transactions
|
||||||
|
|
|
@ -161,13 +161,12 @@
|
||||||
|
|
||||||
(fx/defn fetch-history
|
(fx/defn fetch-history
|
||||||
[{:keys [db] :as cofx}]
|
[{:keys [db] :as cofx}]
|
||||||
(let [{:keys [:account/account :wallet/all-tokens network]} db
|
(let [{:keys [:account/account :wallet/all-tokens]} db
|
||||||
chain (ethereum/network->chain-keyword
|
chain (ethereum/chain-keyword db)
|
||||||
(get-in account [:networks network]))
|
|
||||||
chain-tokens (into {} (map (juxt :address identity)
|
chain-tokens (into {} (map (juxt :address identity)
|
||||||
(tokens/tokens-for all-tokens chain)))
|
(tokens/tokens-for all-tokens chain)))
|
||||||
chaos-mode? (get-in account [:settings :chaos-mode?])
|
chaos-mode? (get-in account [:settings :chaos-mode?])
|
||||||
normalized-address (ethereum/normalized-address (:address account))]
|
normalized-address (ethereum/current-address db)]
|
||||||
#:ethereum.transactions.etherscan
|
#:ethereum.transactions.etherscan
|
||||||
{:fetch-history
|
{:fetch-history
|
||||||
{:chain chain
|
{:chain chain
|
||||||
|
|
|
@ -36,9 +36,7 @@
|
||||||
(first address)
|
(first address)
|
||||||
address)]
|
address)]
|
||||||
(if (ens/is-valid-eth-name? first-address)
|
(if (ens/is-valid-eth-name? first-address)
|
||||||
(let [{:keys [network]} db
|
(let [chain (ethereum/chain-keyword db)
|
||||||
network-info (get-in db [:account/account :networks network])
|
|
||||||
chain (ethereum/network->chain-keyword network-info)
|
|
||||||
registry (get ens/ens-registries chain)]
|
registry (get ens/ens-registries chain)]
|
||||||
(ens/get-addr registry first-address
|
(ens/get-addr registry first-address
|
||||||
#(f db (assoc arguments address-keyword %))))
|
#(f db (assoc arguments address-keyword %))))
|
||||||
|
@ -376,9 +374,7 @@
|
||||||
:extensions/ethereum-resolve-ens
|
:extensions/ethereum-resolve-ens
|
||||||
(fn [{db :db} [_ _ {:keys [name on-success on-failure]}]]
|
(fn [{db :db} [_ _ {:keys [name on-success on-failure]}]]
|
||||||
(if (ens/is-valid-eth-name? name)
|
(if (ens/is-valid-eth-name? name)
|
||||||
(let [{:keys [network]} db
|
(let [chain (ethereum/chain-keyword db)
|
||||||
network-info (get-in db [:account/account :networks network])
|
|
||||||
chain (ethereum/network->chain-keyword network-info)
|
|
||||||
registry (get ens/ens-registries chain)]
|
registry (get ens/ens-registries chain)]
|
||||||
(ens/get-addr registry name
|
(ens/get-addr registry name
|
||||||
#(on-success {:value %})))
|
#(on-success {:value %})))
|
||||||
|
@ -395,7 +391,7 @@
|
||||||
(fx/merge cofx
|
(fx/merge cofx
|
||||||
{:db (assoc-in db [:wallet :send-transaction]
|
{:db (assoc-in db [:wallet :send-transaction]
|
||||||
{:id id
|
{:id id
|
||||||
:from (ethereum/normalized-address (get-in db [:account/account :address]))
|
:from (ethereum/current-address db)
|
||||||
:data (or data (str "0x" (abi-spec/from-utf8 message)))
|
:data (or data (str "0x" (abi-spec/from-utf8 message)))
|
||||||
:on-result [:extensions/wallet-ui-on-success on-success]
|
:on-result [:extensions/wallet-ui-on-success on-success]
|
||||||
:on-error [:extensions/wallet-ui-on-failure on-failure]
|
:on-error [:extensions/wallet-ui-on-failure on-failure]
|
||||||
|
|
|
@ -73,10 +73,6 @@
|
||||||
:name network-name
|
:name network-name
|
||||||
:config config}))
|
:config config}))
|
||||||
|
|
||||||
(defn get-chain [{:keys [db]}]
|
|
||||||
(let [network (get (:networks (:account/account db)) (:network db))]
|
|
||||||
(ethereum/network->chain-keyword network)))
|
|
||||||
|
|
||||||
(defn get-network [{:keys [db]} network-id]
|
(defn get-network [{:keys [db]} network-id]
|
||||||
(get-in db [:account/account :networks network-id]))
|
(get-in db [:account/account :networks network-id]))
|
||||||
|
|
||||||
|
|
|
@ -949,11 +949,11 @@
|
||||||
:<- [:balance]
|
:<- [:balance]
|
||||||
:<- [:prices]
|
:<- [:prices]
|
||||||
:<- [:wallet/currency]
|
:<- [:wallet/currency]
|
||||||
:<- [:network]
|
:<- [:ethereum/chain-keyword]
|
||||||
:<- [:wallet/all-tokens]
|
:<- [:wallet/all-tokens]
|
||||||
(fn [[balance prices currency network all-tokens] [_ currency-code]]
|
(fn [[balance prices currency chain all-tokens] [_ currency-code]]
|
||||||
(if (and balance prices)
|
(if (and balance prices)
|
||||||
(let [assets (tokens/tokens-for all-tokens (ethereum/network->chain-keyword network))
|
(let [assets (tokens/tokens-for all-tokens chain)
|
||||||
token->decimals (into {} (map #(vector (:symbol %) (:decimals %)) assets))
|
token->decimals (into {} (map #(vector (:symbol %) (:decimals %)) assets))
|
||||||
balance-total-value
|
balance-total-value
|
||||||
(get-balance-total-value balance
|
(get-balance-total-value balance
|
||||||
|
@ -984,22 +984,20 @@
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
:wallet/visible-tokens-symbols
|
:wallet/visible-tokens-symbols
|
||||||
:<- [:network]
|
:<- [:ethereum/chain-keyword]
|
||||||
:<- [:account/account]
|
:<- [:account/account]
|
||||||
(fn [[network current-account]]
|
(fn [[chain current-account]]
|
||||||
(let [chain (ethereum/network->chain-keyword network)]
|
(get-in current-account [:settings :wallet :visible-tokens chain])))
|
||||||
(get-in current-account [:settings :wallet :visible-tokens chain]))))
|
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
:wallet/visible-assets
|
:wallet/visible-assets
|
||||||
:<- [:network]
|
:<- [:ethereum/chain-keyword]
|
||||||
:<- [:wallet/visible-tokens-symbols]
|
:<- [:wallet/visible-tokens-symbols]
|
||||||
:<- [:wallet/all-tokens]
|
:<- [:wallet/all-tokens]
|
||||||
(fn [[network visible-tokens-symbols all-tokens]]
|
(fn [[chain visible-tokens-symbols all-tokens]]
|
||||||
(let [chain (ethereum/network->chain-keyword network)]
|
|
||||||
(conj (filter #(contains? visible-tokens-symbols (:symbol %))
|
(conj (filter #(contains? visible-tokens-symbols (:symbol %))
|
||||||
(tokens/sorted-tokens-for all-tokens chain))
|
(tokens/sorted-tokens-for all-tokens chain))
|
||||||
(tokens/native-currency chain)))))
|
(tokens/native-currency chain))))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
:wallet/visible-assets-with-amount
|
:wallet/visible-assets-with-amount
|
||||||
|
@ -1510,19 +1508,19 @@
|
||||||
(fn [_ [_ _ {:keys [value]}]]
|
(fn [_ [_ _ {:keys [value]}]]
|
||||||
value))
|
value))
|
||||||
|
|
||||||
(defn get-token-for [network all-tokens token]
|
(defn get-token-for [chain all-tokens token]
|
||||||
(if (= token "ETH")
|
(if (= token "ETH")
|
||||||
{:decimals 18
|
{:decimals 18
|
||||||
:address "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"}
|
:address "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"}
|
||||||
(tokens/token-for (ethereum/network->chain-keyword network) all-tokens token)))
|
(tokens/token-for chain all-tokens token)))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
:extensions.wallet/balance
|
:extensions.wallet/balance
|
||||||
:<- [:wallet/all-tokens]
|
:<- [:wallet/all-tokens]
|
||||||
:<- [:network]
|
:<- [:ethereum/chain-keyword]
|
||||||
:<- [:balance]
|
:<- [:balance]
|
||||||
(fn [[all-tokens network balance] [_ _ {token :token}]]
|
(fn [[all-tokens chain balance] [_ _ {token :token}]]
|
||||||
(let [{:keys [decimals]} (get-token-for network all-tokens token)
|
(let [{:keys [decimals]} (get-token-for chain all-tokens token)
|
||||||
value (or (get balance (keyword token)) (money/bignumber 0))]
|
value (or (get balance (keyword token)) (money/bignumber 0))]
|
||||||
{:value (money/token->unit value decimals)
|
{:value (money/token->unit value decimals)
|
||||||
:value-in-wei value})))
|
:value-in-wei value})))
|
||||||
|
@ -1544,10 +1542,10 @@
|
||||||
:extensions.wallet/tokens
|
:extensions.wallet/tokens
|
||||||
:<- [:wallet/all-tokens]
|
:<- [:wallet/all-tokens]
|
||||||
:<- [:wallet/visible-tokens-symbols]
|
:<- [:wallet/visible-tokens-symbols]
|
||||||
:<- [:network]
|
:<- [:ethereum/chain-keyword]
|
||||||
(fn [[all-tokens visible-tokens-symbols network] [_ _ {filter-vector :filter visible :visible}]]
|
(fn [[all-tokens visible-tokens-symbols chain] [_ _ {filter-vector :filter visible :visible}]]
|
||||||
(let [tokens (map normalize-token (filter #(and (not (:nft? %)) (if visible (contains? visible-tokens-symbols (:symbol %)) true))
|
(let [tokens (map normalize-token (filter #(and (not (:nft? %)) (if visible (contains? visible-tokens-symbols (:symbol %)) true))
|
||||||
(tokens/sorted-tokens-for all-tokens (ethereum/network->chain-keyword network))))]
|
(tokens/sorted-tokens-for all-tokens chain)))]
|
||||||
(if filter-vector
|
(if filter-vector
|
||||||
(filter #((set filter-vector) (:symbol %)) tokens)
|
(filter #((set filter-vector) (:symbol %)) tokens)
|
||||||
tokens))))
|
tokens))))
|
||||||
|
|
|
@ -18,8 +18,7 @@
|
||||||
(fx/defn update-settings
|
(fx/defn update-settings
|
||||||
[{:keys [db] :as cofx} {:keys [snt-amount message update] :as new-settings}]
|
[{:keys [db] :as cofx} {:keys [snt-amount message update] :as new-settings}]
|
||||||
(let [account-settings (get-in db [:account/account :settings])
|
(let [account-settings (get-in db [:account/account :settings])
|
||||||
chain-keyword (-> (get-in db [:account/account :networks (:network db)])
|
chain-keyword (ethereum/chain-keyword db)
|
||||||
ethereum/network->chain-keyword)
|
|
||||||
tribute-to-talk-settings (cond-> (merge (tribute-to-talk.db/get-settings db)
|
tribute-to-talk-settings (cond-> (merge (tribute-to-talk.db/get-settings db)
|
||||||
new-settings)
|
new-settings)
|
||||||
new-settings
|
new-settings
|
||||||
|
|
|
@ -16,8 +16,7 @@
|
||||||
|
|
||||||
(defn get-settings
|
(defn get-settings
|
||||||
[db]
|
[db]
|
||||||
(let [chain-keyword (-> (get-in db [:account/account :networks (:network db)])
|
(let [chain-keyword (ethereum/chain-keyword db)]
|
||||||
ethereum/network->chain-keyword)]
|
|
||||||
(get-in db [:account/account :settings :tribute-to-talk chain-keyword])))
|
(get-in db [:account/account :settings :tribute-to-talk chain-keyword])))
|
||||||
|
|
||||||
(defn enabled?
|
(defn enabled?
|
||||||
|
|
|
@ -22,10 +22,9 @@
|
||||||
[icons/icon :main-icons/check {:color colors/white :height 20 :width 20}]])
|
[icons/icon :main-icons/check {:color colors/white :height 20 :width 20}]])
|
||||||
|
|
||||||
(defview price-badge [price id owned pending]
|
(defview price-badge [price id owned pending]
|
||||||
(letsubs [network [:network]
|
(letsubs [chain [:ethereum/chain-keyword]
|
||||||
balance [:balance]]
|
balance [:balance]]
|
||||||
(let [chain (ethereum/network->chain-keyword network)
|
(let [snt (money/to-number (if (= :mainnet chain) (:SNT balance) (:STT balance)))
|
||||||
snt (money/to-number (if (= :mainnet chain) (:SNT balance) (:STT balance)))
|
|
||||||
not-enough-snt? (> price snt)
|
not-enough-snt? (> price snt)
|
||||||
no-snt? (or (nil? snt) (zero? snt))]
|
no-snt? (or (nil? snt) (zero? snt))]
|
||||||
[react/touchable-highlight {:on-press #(cond pending nil
|
[react/touchable-highlight {:on-press #(cond pending nil
|
||||||
|
|
|
@ -75,12 +75,9 @@
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:wallet.send/set-recipient
|
:wallet.send/set-recipient
|
||||||
(fn [{:keys [db]} [_ recipient]]
|
(fn [{:keys [db]} [_ recipient]]
|
||||||
(let [{:keys [web3 network]} db
|
(let [chain (ethereum/chain-keyword db)]
|
||||||
network-info (get-in db [:account/account :networks network])
|
|
||||||
chain (ethereum/network->chain-keyword network-info)]
|
|
||||||
(if (ens/is-valid-eth-name? recipient)
|
(if (ens/is-valid-eth-name? recipient)
|
||||||
{:resolve-address {:web3 web3
|
{:resolve-address {:registry (get ens/ens-registries chain)
|
||||||
:registry (get ens/ens-registries chain)
|
|
||||||
:ens-name recipient
|
:ens-name recipient
|
||||||
:cb #(re-frame/dispatch [:wallet.send/set-recipient %])}}
|
:cb #(re-frame/dispatch [:wallet.send/set-recipient %])}}
|
||||||
(if (ethereum/address? recipient)
|
(if (ethereum/address? recipient)
|
||||||
|
|
|
@ -156,9 +156,9 @@
|
||||||
|
|
||||||
(views/defview asset-selector [{:keys [disabled? type symbol error]}]
|
(views/defview asset-selector [{:keys [disabled? type symbol error]}]
|
||||||
(views/letsubs [balance [:balance]
|
(views/letsubs [balance [:balance]
|
||||||
network [:network]
|
chain [:ethereum/chain-keyword]
|
||||||
all-tokens [:wallet/all-tokens]]
|
all-tokens [:wallet/all-tokens]]
|
||||||
(let [{:keys [name icon decimals color] :as token} (tokens/asset-for all-tokens (ethereum/network->chain-keyword network) symbol)]
|
(let [{:keys [name icon decimals color] :as token} (tokens/asset-for all-tokens chain symbol)]
|
||||||
(when name
|
(when name
|
||||||
[react/view
|
[react/view
|
||||||
[cartouche {:disabled? disabled? :on-press #(re-frame/dispatch [:navigate-to (type->view type)])}
|
[cartouche {:disabled? disabled? :on-press #(re-frame/dispatch [:navigate-to (type->view type)])}
|
||||||
|
|
|
@ -30,14 +30,14 @@
|
||||||
|
|
||||||
(views/defview send-transaction-request []
|
(views/defview send-transaction-request []
|
||||||
;; TODO(jeluard) both send and request flows should be merged
|
;; TODO(jeluard) both send and request flows should be merged
|
||||||
(views/letsubs [network [:account/network]
|
(views/letsubs [chain [:ethereum/chain-keyword]
|
||||||
{:keys [to to-name public-key]} [:wallet.send/transaction]
|
{:keys [to to-name public-key]} [:wallet.send/transaction]
|
||||||
{:keys [amount amount-error amount-text symbol
|
{:keys [amount amount-error amount-text symbol to
|
||||||
to to-name public-key]} [:wallet.request/transaction]
|
to-name public-key]} [:wallet.request/transaction]
|
||||||
network-status [:network-status]
|
network-status [:network-status]
|
||||||
all-tokens [:wallet/all-tokens]
|
all-tokens [:wallet/all-tokens]
|
||||||
scroll (atom nil)]
|
scroll (atom nil)]
|
||||||
(let [{:keys [decimals] :as token} (tokens/asset-for all-tokens (ethereum/network->chain-keyword network) symbol)]
|
(let [{:keys [decimals] :as token} (tokens/asset-for all-tokens chain symbol)]
|
||||||
[wallet.components/simple-screen {:avoid-keyboard? true}
|
[wallet.components/simple-screen {:avoid-keyboard? true}
|
||||||
[wallet.components/toolbar (i18n/label :t/new-request)]
|
[wallet.components/toolbar (i18n/label :t/new-request)]
|
||||||
[react/view components.styles/flex
|
[react/view components.styles/flex
|
||||||
|
|
|
@ -150,10 +150,9 @@
|
||||||
:padding-vertical 14}}
|
:padding-vertical 14}}
|
||||||
(i18n/label :t/signing-phrase-warning)]])
|
(i18n/label :t/signing-phrase-warning)]])
|
||||||
|
|
||||||
(defn- render-send-transaction-view [{:keys [modal? transaction scroll advanced? keycard? signing-phrase network all-tokens amount-input network-status]}]
|
(defn- render-send-transaction-view [{:keys [chain modal? transaction scroll advanced? keycard? signing-phrase all-tokens amount-input network-status]}]
|
||||||
(let [{:keys [amount amount-text amount-error asset-error show-password-input? to to-name sufficient-funds?
|
(let [{:keys [amount amount-text amount-error asset-error show-password-input? to to-name sufficient-funds?
|
||||||
sufficient-gas? in-progress? from-chat? symbol]} transaction
|
sufficient-gas? in-progress? from-chat? symbol]} transaction
|
||||||
chain (ethereum/network->chain-keyword network)
|
|
||||||
native-currency (tokens/native-currency chain)
|
native-currency (tokens/native-currency chain)
|
||||||
{:keys [decimals] :as token} (tokens/asset-for all-tokens chain symbol)
|
{:keys [decimals] :as token} (tokens/asset-for all-tokens chain symbol)
|
||||||
online? (= :online network-status)]
|
online? (= :online network-status)]
|
||||||
|
@ -218,7 +217,7 @@
|
||||||
(defview send-transaction []
|
(defview send-transaction []
|
||||||
(letsubs [transaction [:wallet.send/transaction]
|
(letsubs [transaction [:wallet.send/transaction]
|
||||||
advanced? [:wallet.send/advanced?]
|
advanced? [:wallet.send/advanced?]
|
||||||
network [:account/network]
|
chain [:ethereum/chain-keyword]
|
||||||
scroll (atom nil)
|
scroll (atom nil)
|
||||||
network-status [:network-status]
|
network-status [:network-status]
|
||||||
all-tokens [:wallet/all-tokens]
|
all-tokens [:wallet/all-tokens]
|
||||||
|
@ -230,7 +229,7 @@
|
||||||
:advanced? advanced?
|
:advanced? advanced?
|
||||||
:keycard? keycard?
|
:keycard? keycard?
|
||||||
:signing-phrase signing-phrase
|
:signing-phrase signing-phrase
|
||||||
:network network
|
:chain chain
|
||||||
:all-tokens all-tokens
|
:all-tokens all-tokens
|
||||||
:network-status network-status}]))
|
:network-status network-status}]))
|
||||||
|
|
||||||
|
@ -238,7 +237,7 @@
|
||||||
(defview send-transaction-modal []
|
(defview send-transaction-modal []
|
||||||
(letsubs [transaction [:wallet.send/transaction]
|
(letsubs [transaction [:wallet.send/transaction]
|
||||||
advanced? [:wallet.send/advanced?]
|
advanced? [:wallet.send/advanced?]
|
||||||
network [:account/network]
|
chain [:ethereum/chain-keyword]
|
||||||
scroll (atom nil)
|
scroll (atom nil)
|
||||||
network-status [:network-status]
|
network-status [:network-status]
|
||||||
all-tokens [:wallet/all-tokens]
|
all-tokens [:wallet/all-tokens]
|
||||||
|
@ -251,7 +250,7 @@
|
||||||
:advanced? advanced?
|
:advanced? advanced?
|
||||||
:keycard? keycard?
|
:keycard? keycard?
|
||||||
:signing-phrase signing-phrase
|
:signing-phrase signing-phrase
|
||||||
:network network
|
:chain chain
|
||||||
:all-tokens all-tokens
|
:all-tokens all-tokens
|
||||||
:network-status network-status}]
|
:network-status network-status}]
|
||||||
[react/view wallet.styles/wallet-modal-container
|
[react/view wallet.styles/wallet-modal-container
|
||||||
|
|
|
@ -58,11 +58,10 @@
|
||||||
[list/item-secondary symbol]]]])
|
[list/item-secondary symbol]]]])
|
||||||
|
|
||||||
(defview manage-assets []
|
(defview manage-assets []
|
||||||
(letsubs [network [:network]
|
(letsubs [chain [:ethereum/chain-keyword]
|
||||||
visible-tokens [:wallet/visible-tokens-symbols]
|
visible-tokens [:wallet/visible-tokens-symbols]
|
||||||
all-tokens [:wallet/all-tokens]]
|
all-tokens [:wallet/all-tokens]]
|
||||||
(let [chain-key (ethereum/network->chain-keyword network)
|
(let [{custom-tokens true default-tokens nil} (group-by :custom? (tokens/sorted-tokens-for all-tokens chain))]
|
||||||
{custom-tokens true default-tokens nil} (group-by :custom? (tokens/sorted-tokens-for all-tokens chain-key))]
|
|
||||||
[react/view (merge components.styles/flex {:background-color :white})
|
[react/view (merge components.styles/flex {:background-color :white})
|
||||||
[status-bar/status-bar]
|
[status-bar/status-bar]
|
||||||
[toolbar]
|
[toolbar]
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
(defview transaction-fee []
|
(defview transaction-fee []
|
||||||
(letsubs [send-transaction [:wallet.send/transaction]
|
(letsubs [send-transaction [:wallet.send/transaction]
|
||||||
network [:account/network]
|
chain [:ethereum/chain-keyword]
|
||||||
{gas-edit :gas
|
{gas-edit :gas
|
||||||
max-fee :max-fee
|
max-fee :max-fee
|
||||||
gas-price-edit :gas-price} [:wallet/edit]
|
gas-price-edit :gas-price} [:wallet/edit]
|
||||||
|
@ -34,7 +34,6 @@
|
||||||
(let [{:keys [amount symbol]} send-transaction
|
(let [{:keys [amount symbol]} send-transaction
|
||||||
gas (:value gas-edit)
|
gas (:value gas-edit)
|
||||||
gas-price (:value gas-price-edit)
|
gas-price (:value gas-price-edit)
|
||||||
chain (ethereum/network->chain-keyword network)
|
|
||||||
native-currency (tokens/native-currency chain)
|
native-currency (tokens/native-currency chain)
|
||||||
{:keys [decimals] :as token} (tokens/asset-for all-tokens chain symbol)]
|
{:keys [decimals] :as token} (tokens/asset-for all-tokens chain symbol)]
|
||||||
[components/simple-screen {:status-bar-type :modal-wallet}
|
[components/simple-screen {:status-bar-type :modal-wallet}
|
||||||
|
|
|
@ -57,9 +57,6 @@
|
||||||
(defn network->chain-keyword [network]
|
(defn network->chain-keyword [network]
|
||||||
(chain-id->chain-keyword (network->chain-id network)))
|
(chain-id->chain-keyword (network->chain-id network)))
|
||||||
|
|
||||||
(defn get-chain-keyword [db]
|
|
||||||
(network->chain-keyword (get-in db [:account/account :networks (:network db)])))
|
|
||||||
|
|
||||||
(defn network->chain-name [network]
|
(defn network->chain-name [network]
|
||||||
(-> network
|
(-> network
|
||||||
network->chain-keyword
|
network->chain-keyword
|
||||||
|
|
|
@ -378,8 +378,8 @@
|
||||||
|
|
||||||
(fx/defn update-balances
|
(fx/defn update-balances
|
||||||
[{{:keys [network-status :wallet/all-tokens]
|
[{{:keys [network-status :wallet/all-tokens]
|
||||||
{:keys [address settings]} :account/account :as db} :db :as cofx}]
|
{:keys [settings]} :account/account :as db} :db :as cofx}]
|
||||||
(let [normalized-address (ethereum/normalized-address address)
|
(let [normalized-address (ethereum/current-address db)
|
||||||
chain (ethereum/chain-keyword db)
|
chain (ethereum/chain-keyword db)
|
||||||
assets (get-in settings [:wallet :visible-tokens chain])
|
assets (get-in settings [:wallet :visible-tokens chain])
|
||||||
tokens (->> (tokens/tokens-for all-tokens chain)
|
tokens (->> (tokens/tokens-for all-tokens chain)
|
||||||
|
@ -425,8 +425,8 @@
|
||||||
{}))))))
|
{}))))))
|
||||||
|
|
||||||
(fx/defn update-prices
|
(fx/defn update-prices
|
||||||
[{{:keys [network network-status :wallet/all-tokens]
|
[{{:keys [network-status :wallet/all-tokens]
|
||||||
{:keys [address settings networks]} :account/account :as db} :db}]
|
{:keys [address settings]} :account/account :as db} :db}]
|
||||||
(let [chain (ethereum/chain-keyword db)
|
(let [chain (ethereum/chain-keyword db)
|
||||||
mainnet? (= :mainnet chain)
|
mainnet? (= :mainnet chain)
|
||||||
assets (get-in settings [:wallet :visible-tokens chain])
|
assets (get-in settings [:wallet :visible-tokens chain])
|
||||||
|
@ -520,9 +520,8 @@
|
||||||
adjusted-gas))})))
|
adjusted-gas))})))
|
||||||
|
|
||||||
(defn update-toggle-in-settings
|
(defn update-toggle-in-settings
|
||||||
[{{:account/keys [account]} :db} symbol checked?]
|
[{{:account/keys [account] :as db} :db} symbol checked?]
|
||||||
(let [network (get (:networks account) (:network account))
|
(let [chain (ethereum/chain-keyword db)
|
||||||
chain (ethereum/network->chain-keyword network)
|
|
||||||
settings (get account :settings)]
|
settings (get account :settings)]
|
||||||
(update-in settings [:wallet :visible-tokens chain] #(set-checked % symbol checked?))))
|
(update-in settings [:wallet :visible-tokens chain] #(set-checked % symbol checked?))))
|
||||||
|
|
||||||
|
@ -532,16 +531,15 @@
|
||||||
(accounts.update/update-settings cofx new-settings {})))
|
(accounts.update/update-settings cofx new-settings {})))
|
||||||
|
|
||||||
(fx/defn add-custom-token
|
(fx/defn add-custom-token
|
||||||
[{{:account/keys [account]} :db :as cofx} {:keys [symbol address] :as token}]
|
[{:keys [db] :as cofx} {:keys [symbol address] :as token}]
|
||||||
(let [network (get (:networks account) (:network account))
|
(let [chain (ethereum/chain-keyword db)
|
||||||
chain (ethereum/network->chain-keyword network)
|
|
||||||
settings (update-toggle-in-settings cofx symbol true)
|
settings (update-toggle-in-settings cofx symbol true)
|
||||||
new-settings (assoc-in settings [:wallet :custom-tokens chain address] token)]
|
new-settings (assoc-in settings [:wallet :custom-tokens chain address] token)]
|
||||||
(accounts.update/update-settings cofx new-settings {})))
|
(accounts.update/update-settings cofx new-settings {})))
|
||||||
|
|
||||||
(fx/defn remove-custom-token [{{:account/keys [account]} :db :as cofx} {:keys [symbol address]}]
|
(fx/defn remove-custom-token
|
||||||
(let [network (get (:networks account) (:network account))
|
[{:keys [db] :as cofx} {:keys [symbol address]}]
|
||||||
chain (ethereum/network->chain-keyword network)
|
(let [chain (ethereum/chain-keyword db)
|
||||||
settings (update-toggle-in-settings cofx symbol false)
|
settings (update-toggle-in-settings cofx symbol false)
|
||||||
new-settings (update-in settings [:wallet :custom-tokens chain] dissoc address)]
|
new-settings (update-in settings [:wallet :custom-tokens chain] dissoc address)]
|
||||||
(accounts.update/update-settings cofx new-settings {})))
|
(accounts.update/update-settings cofx new-settings {})))
|
||||||
|
|
|
@ -85,7 +85,7 @@
|
||||||
|
|
||||||
(defn field-exists?
|
(defn field-exists?
|
||||||
[{:wallet/keys [all-tokens] :as db} field-key field-value]
|
[{:wallet/keys [all-tokens] :as db} field-key field-value]
|
||||||
(let [chain-key (ethereum/get-chain-keyword db)]
|
(let [chain-key (ethereum/chain-keyword db)]
|
||||||
(some #(= field-value (get % field-key))
|
(some #(= field-value (get % field-key))
|
||||||
(vals (get all-tokens chain-key)))))
|
(vals (get all-tokens chain-key)))))
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@
|
||||||
|
|
||||||
(defn token-in-list?
|
(defn token-in-list?
|
||||||
[{:wallet/keys [all-tokens] :as db} contract]
|
[{:wallet/keys [all-tokens] :as db} contract]
|
||||||
(let [chain-key (ethereum/get-chain-keyword db)
|
(let [chain-key (ethereum/chain-keyword db)
|
||||||
addresses (set (map string/lower-case (keys (get all-tokens chain-key))))]
|
addresses (set (map string/lower-case (keys (get all-tokens chain-key))))]
|
||||||
(not (nil? (get addresses (string/lower-case contract))))))
|
(not (nil? (get addresses (string/lower-case contract))))))
|
||||||
|
|
||||||
|
@ -168,7 +168,7 @@
|
||||||
(fx/defn add-custom-token
|
(fx/defn add-custom-token
|
||||||
[{:keys [db] :as cofx}]
|
[{:keys [db] :as cofx}]
|
||||||
(let [{:keys [contract name symbol decimals]} (get db :wallet/custom-token-screen)
|
(let [{:keys [contract name symbol decimals]} (get db :wallet/custom-token-screen)
|
||||||
chain-key (ethereum/get-chain-keyword db)
|
chain-key (ethereum/chain-keyword db)
|
||||||
symbol (keyword symbol)
|
symbol (keyword symbol)
|
||||||
new-token {:address contract
|
new-token {:address contract
|
||||||
:name name
|
:name name
|
||||||
|
@ -183,7 +183,7 @@
|
||||||
|
|
||||||
(fx/defn remove-custom-token
|
(fx/defn remove-custom-token
|
||||||
[{:keys [db] :as cofx} {:keys [address] :as token}]
|
[{:keys [db] :as cofx} {:keys [address] :as token}]
|
||||||
(let [chain-key (ethereum/get-chain-keyword db)]
|
(let [chain-key (ethereum/chain-keyword db)]
|
||||||
(fx/merge (update-in cofx [:db :wallet/all-tokens chain-key] dissoc address)
|
(fx/merge (update-in cofx [:db :wallet/all-tokens chain-key] dissoc address)
|
||||||
(wallet/remove-custom-token token))))
|
(wallet/remove-custom-token token))))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue