[#9886] App shows 'buy' for stickerpack user owns when pressing on sticker in chat
Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
This commit is contained in:
parent
17e5fc4dd4
commit
6e3784d671
|
@ -168,14 +168,21 @@
|
|||
"mailservers_getChatRequestRanges" {}
|
||||
"mailservers_deleteChatRequestRange" {}})
|
||||
|
||||
(defn on-error-retry [call-method {:keys [method number-of-retries on-error] :as arg}]
|
||||
(if (pos? number-of-retries)
|
||||
(fn []
|
||||
(log/debug "[on-error-retry]" method "number-of-retries" number-of-retries)
|
||||
(call-method (update arg :number-of-retries dec)))
|
||||
on-error))
|
||||
|
||||
(defn call
|
||||
[{:keys [method params on-success on-error] :as p}]
|
||||
[{:keys [method params on-success] :as arg}]
|
||||
(if-let [method-options (json-rpc-api method)]
|
||||
(let [{:keys [id on-result subscription?]
|
||||
:or {on-result identity
|
||||
id 1
|
||||
params []}} method-options
|
||||
on-error (or on-error
|
||||
on-error (or (on-error-retry call arg)
|
||||
#(log/warn :json-rpc/error method :error % :params params))]
|
||||
(if (nil? method)
|
||||
(log/error :json-rpc/method-not-found method)
|
||||
|
@ -191,7 +198,7 @@
|
|||
(fn [response]
|
||||
(if (string/blank? response)
|
||||
(on-error {:message "Blank response"})
|
||||
(let [{:keys [error result] :as response2} (types/json->clj response)]
|
||||
(let [{:keys [error result]} (types/json->clj response)]
|
||||
(if error
|
||||
(on-error error)
|
||||
(if subscription?
|
||||
|
@ -200,12 +207,13 @@
|
|||
result on-success])
|
||||
(on-success (on-result result))))))))))
|
||||
|
||||
(log/warn "method" method "not found" p)))
|
||||
(log/warn "method" method "not found" arg)))
|
||||
|
||||
(defn eth-call
|
||||
[{:keys [contract method params outputs on-success on-error block]
|
||||
[{:keys [contract method params outputs on-success block]
|
||||
:or {block "latest"
|
||||
params []}}]
|
||||
params []}
|
||||
:as arg}]
|
||||
(call {:method "eth_call"
|
||||
:params [{:to contract
|
||||
:data (abi-spec/encode method params)}
|
||||
|
@ -217,7 +225,7 @@
|
|||
#(on-success (abi-spec/decode % outputs))
|
||||
on-success)
|
||||
:on-error
|
||||
on-error}))
|
||||
(on-error-retry eth-call arg)}))
|
||||
|
||||
;; effects
|
||||
(re-frame/reg-fx
|
||||
|
|
|
@ -1009,11 +1009,6 @@
|
|||
(fn [cofx [_ id price]]
|
||||
(stickers/approve-pack cofx id price)))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:stickers/get-owned-packs
|
||||
(fn [cofx _]
|
||||
(stickers/get-owned-pack cofx)))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:stickers/pack-owned
|
||||
(fn [cofx [_ id]]
|
||||
|
|
|
@ -64,6 +64,7 @@
|
|||
:method "balanceOf(address)"
|
||||
:params [address]
|
||||
:outputs ["uint256"]
|
||||
:number-of-retries 3
|
||||
:on-success
|
||||
(fn [[count]]
|
||||
(dotimes [id count]
|
||||
|
@ -73,6 +74,7 @@
|
|||
:method "tokenOfOwnerByIndex(address,uint256)"
|
||||
:params [address id]
|
||||
:outputs ["uint256"]
|
||||
:number-of-retries 3
|
||||
:on-success
|
||||
(fn [[token-id]]
|
||||
(json-rpc/eth-call
|
||||
|
@ -81,6 +83,7 @@
|
|||
:method "tokenPackId(uint256)"
|
||||
:params [token-id]
|
||||
:outputs ["uint256"]
|
||||
:number-of-retries 3
|
||||
:on-success
|
||||
(fn [[pack-id]]
|
||||
(re-frame/dispatch [:stickers/pack-owned pack-id]))}))})))})))
|
||||
|
@ -127,11 +130,14 @@
|
|||
(when (and id (string/starts-with? current-network "mainnet"))
|
||||
(let [pack (or (get packs-installed id)
|
||||
(get packs id))
|
||||
contract-address (contracts/get-address db :status/stickers)]
|
||||
contract-address (contracts/get-address db :status/stickers)
|
||||
pack-contract (contracts/get-address db :status/sticker-pack)
|
||||
address (ethereum/default-address db)]
|
||||
(fx/merge cofx
|
||||
(navigation/navigate-to-cofx :stickers-pack-modal {:id id})
|
||||
#(when (and contract-address (not pack))
|
||||
{:stickers/pack-data-fx [contract-address id]})))))
|
||||
{:stickers/pack-data-fx [contract-address id]
|
||||
:stickers/owned-packs-fx [pack-contract address]})))))
|
||||
|
||||
(fx/defn load-pack
|
||||
[cofx url id price]
|
||||
|
@ -196,11 +202,4 @@
|
|||
{})))))
|
||||
|
||||
(fx/defn pack-owned [{db :db} id]
|
||||
{:db (update db :stickers/packs-owned conj id)})
|
||||
|
||||
(fx/defn get-owned-pack
|
||||
[{:keys [db]}]
|
||||
(let [contract (contracts/get-address db :status/sticker-pack)
|
||||
address (ethereum/default-address db)]
|
||||
(when contract
|
||||
{:stickers/owned-packs-fx [contract address]})))
|
||||
{:db (update db :stickers/packs-owned conj id)})
|
|
@ -28,21 +28,13 @@
|
|||
[status-im.ui.components.bottom-sheet.core :as bottom-sheet]))
|
||||
|
||||
(defn get-balance
|
||||
[{:keys [address on-success on-error number-of-retries]
|
||||
:as params
|
||||
:or {number-of-retries 4}}]
|
||||
(log/debug "[wallet] get-balance"
|
||||
"address" address
|
||||
"number-of-retries" number-of-retries)
|
||||
[{:keys [address on-success on-error]}]
|
||||
(json-rpc/call
|
||||
{:method "eth_getBalance"
|
||||
:params [address "latest"]
|
||||
:on-success on-success
|
||||
:on-error (fn [error]
|
||||
(if (pos? number-of-retries)
|
||||
(get-balance
|
||||
(update params :number-of-retries dec))
|
||||
(on-error error)))}))
|
||||
{:method "eth_getBalance"
|
||||
:params [address "latest"]
|
||||
:on-success on-success
|
||||
:number-of-retries 4
|
||||
:on-error on-error}))
|
||||
|
||||
(re-frame/reg-fx
|
||||
:wallet/get-balances
|
||||
|
@ -183,15 +175,11 @@
|
|||
balances)))
|
||||
|
||||
(defn get-token-balances
|
||||
[{:keys [addresses tokens init? assets number-of-retries]
|
||||
:as params
|
||||
:or {number-of-retries 4}}]
|
||||
(log/debug "[wallet] get-token-balances"
|
||||
"addresses" addresses
|
||||
"number-of-retries" number-of-retries)
|
||||
[{:keys [addresses tokens init? assets]}]
|
||||
(json-rpc/call
|
||||
{:method "wallet_getTokensBalances"
|
||||
:params [addresses (keys tokens)]
|
||||
{:method "wallet_getTokensBalances"
|
||||
:params [addresses (keys tokens)]
|
||||
:number-of-retries 4
|
||||
:on-success
|
||||
(fn [results]
|
||||
(when-let [balances (clean-up-results results tokens (if init? nil assets))]
|
||||
|
@ -201,10 +189,7 @@
|
|||
[::tokens-found balances]
|
||||
[::update-tokens-balances-success balances]))))
|
||||
:on-error
|
||||
(fn [error]
|
||||
(if (pos? number-of-retries)
|
||||
(get-token-balances (update params :number-of-retries dec))
|
||||
(re-frame/dispatch [::update-token-balance-fail error])))}))
|
||||
#(re-frame/dispatch [::update-token-balance-fail %])}))
|
||||
|
||||
(re-frame/reg-fx
|
||||
:wallet/get-tokens-balances
|
||||
|
|
Loading…
Reference in New Issue