[#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_getChatRequestRanges" {}
|
||||||
"mailservers_deleteChatRequestRange" {}})
|
"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
|
(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)]
|
(if-let [method-options (json-rpc-api method)]
|
||||||
(let [{:keys [id on-result subscription?]
|
(let [{:keys [id on-result subscription?]
|
||||||
:or {on-result identity
|
:or {on-result identity
|
||||||
id 1
|
id 1
|
||||||
params []}} method-options
|
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))]
|
#(log/warn :json-rpc/error method :error % :params params))]
|
||||||
(if (nil? method)
|
(if (nil? method)
|
||||||
(log/error :json-rpc/method-not-found method)
|
(log/error :json-rpc/method-not-found method)
|
||||||
|
@ -191,7 +198,7 @@
|
||||||
(fn [response]
|
(fn [response]
|
||||||
(if (string/blank? response)
|
(if (string/blank? response)
|
||||||
(on-error {:message "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
|
(if error
|
||||||
(on-error error)
|
(on-error error)
|
||||||
(if subscription?
|
(if subscription?
|
||||||
|
@ -200,12 +207,13 @@
|
||||||
result on-success])
|
result on-success])
|
||||||
(on-success (on-result result))))))))))
|
(on-success (on-result result))))))))))
|
||||||
|
|
||||||
(log/warn "method" method "not found" p)))
|
(log/warn "method" method "not found" arg)))
|
||||||
|
|
||||||
(defn eth-call
|
(defn eth-call
|
||||||
[{:keys [contract method params outputs on-success on-error block]
|
[{:keys [contract method params outputs on-success block]
|
||||||
:or {block "latest"
|
:or {block "latest"
|
||||||
params []}}]
|
params []}
|
||||||
|
:as arg}]
|
||||||
(call {:method "eth_call"
|
(call {:method "eth_call"
|
||||||
:params [{:to contract
|
:params [{:to contract
|
||||||
:data (abi-spec/encode method params)}
|
:data (abi-spec/encode method params)}
|
||||||
|
@ -217,7 +225,7 @@
|
||||||
#(on-success (abi-spec/decode % outputs))
|
#(on-success (abi-spec/decode % outputs))
|
||||||
on-success)
|
on-success)
|
||||||
:on-error
|
:on-error
|
||||||
on-error}))
|
(on-error-retry eth-call arg)}))
|
||||||
|
|
||||||
;; effects
|
;; effects
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
|
|
|
@ -1009,11 +1009,6 @@
|
||||||
(fn [cofx [_ id price]]
|
(fn [cofx [_ id price]]
|
||||||
(stickers/approve-pack 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
|
(handlers/register-handler-fx
|
||||||
:stickers/pack-owned
|
:stickers/pack-owned
|
||||||
(fn [cofx [_ id]]
|
(fn [cofx [_ id]]
|
||||||
|
|
|
@ -64,6 +64,7 @@
|
||||||
:method "balanceOf(address)"
|
:method "balanceOf(address)"
|
||||||
:params [address]
|
:params [address]
|
||||||
:outputs ["uint256"]
|
:outputs ["uint256"]
|
||||||
|
:number-of-retries 3
|
||||||
:on-success
|
:on-success
|
||||||
(fn [[count]]
|
(fn [[count]]
|
||||||
(dotimes [id count]
|
(dotimes [id count]
|
||||||
|
@ -73,6 +74,7 @@
|
||||||
:method "tokenOfOwnerByIndex(address,uint256)"
|
:method "tokenOfOwnerByIndex(address,uint256)"
|
||||||
:params [address id]
|
:params [address id]
|
||||||
:outputs ["uint256"]
|
:outputs ["uint256"]
|
||||||
|
:number-of-retries 3
|
||||||
:on-success
|
:on-success
|
||||||
(fn [[token-id]]
|
(fn [[token-id]]
|
||||||
(json-rpc/eth-call
|
(json-rpc/eth-call
|
||||||
|
@ -81,6 +83,7 @@
|
||||||
:method "tokenPackId(uint256)"
|
:method "tokenPackId(uint256)"
|
||||||
:params [token-id]
|
:params [token-id]
|
||||||
:outputs ["uint256"]
|
:outputs ["uint256"]
|
||||||
|
:number-of-retries 3
|
||||||
:on-success
|
:on-success
|
||||||
(fn [[pack-id]]
|
(fn [[pack-id]]
|
||||||
(re-frame/dispatch [:stickers/pack-owned pack-id]))}))})))})))
|
(re-frame/dispatch [:stickers/pack-owned pack-id]))}))})))})))
|
||||||
|
@ -127,11 +130,14 @@
|
||||||
(when (and id (string/starts-with? current-network "mainnet"))
|
(when (and id (string/starts-with? current-network "mainnet"))
|
||||||
(let [pack (or (get packs-installed id)
|
(let [pack (or (get packs-installed id)
|
||||||
(get packs 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
|
(fx/merge cofx
|
||||||
(navigation/navigate-to-cofx :stickers-pack-modal {:id id})
|
(navigation/navigate-to-cofx :stickers-pack-modal {:id id})
|
||||||
#(when (and contract-address (not pack))
|
#(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
|
(fx/defn load-pack
|
||||||
[cofx url id price]
|
[cofx url id price]
|
||||||
|
@ -197,10 +203,3 @@
|
||||||
|
|
||||||
(fx/defn pack-owned [{db :db} id]
|
(fx/defn pack-owned [{db :db} id]
|
||||||
{:db (update db :stickers/packs-owned conj 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]})))
|
|
||||||
|
|
|
@ -28,21 +28,13 @@
|
||||||
[status-im.ui.components.bottom-sheet.core :as bottom-sheet]))
|
[status-im.ui.components.bottom-sheet.core :as bottom-sheet]))
|
||||||
|
|
||||||
(defn get-balance
|
(defn get-balance
|
||||||
[{:keys [address on-success on-error number-of-retries]
|
[{:keys [address on-success on-error]}]
|
||||||
:as params
|
|
||||||
:or {number-of-retries 4}}]
|
|
||||||
(log/debug "[wallet] get-balance"
|
|
||||||
"address" address
|
|
||||||
"number-of-retries" number-of-retries)
|
|
||||||
(json-rpc/call
|
(json-rpc/call
|
||||||
{:method "eth_getBalance"
|
{:method "eth_getBalance"
|
||||||
:params [address "latest"]
|
:params [address "latest"]
|
||||||
:on-success on-success
|
:on-success on-success
|
||||||
:on-error (fn [error]
|
:number-of-retries 4
|
||||||
(if (pos? number-of-retries)
|
:on-error on-error}))
|
||||||
(get-balance
|
|
||||||
(update params :number-of-retries dec))
|
|
||||||
(on-error error)))}))
|
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
:wallet/get-balances
|
:wallet/get-balances
|
||||||
|
@ -183,15 +175,11 @@
|
||||||
balances)))
|
balances)))
|
||||||
|
|
||||||
(defn get-token-balances
|
(defn get-token-balances
|
||||||
[{:keys [addresses tokens init? assets number-of-retries]
|
[{:keys [addresses tokens init? assets]}]
|
||||||
:as params
|
|
||||||
:or {number-of-retries 4}}]
|
|
||||||
(log/debug "[wallet] get-token-balances"
|
|
||||||
"addresses" addresses
|
|
||||||
"number-of-retries" number-of-retries)
|
|
||||||
(json-rpc/call
|
(json-rpc/call
|
||||||
{:method "wallet_getTokensBalances"
|
{:method "wallet_getTokensBalances"
|
||||||
:params [addresses (keys tokens)]
|
:params [addresses (keys tokens)]
|
||||||
|
:number-of-retries 4
|
||||||
:on-success
|
:on-success
|
||||||
(fn [results]
|
(fn [results]
|
||||||
(when-let [balances (clean-up-results results tokens (if init? nil assets))]
|
(when-let [balances (clean-up-results results tokens (if init? nil assets))]
|
||||||
|
@ -201,10 +189,7 @@
|
||||||
[::tokens-found balances]
|
[::tokens-found balances]
|
||||||
[::update-tokens-balances-success balances]))))
|
[::update-tokens-balances-success balances]))))
|
||||||
:on-error
|
:on-error
|
||||||
(fn [error]
|
#(re-frame/dispatch [::update-token-balance-fail %])}))
|
||||||
(if (pos? number-of-retries)
|
|
||||||
(get-token-balances (update params :number-of-retries dec))
|
|
||||||
(re-frame/dispatch [::update-token-balance-fail error])))}))
|
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
:wallet/get-tokens-balances
|
:wallet/get-tokens-balances
|
||||||
|
|
Loading…
Reference in New Issue