From f29f02d9616bb6ab789b84783a740b6a577ac7e0 Mon Sep 17 00:00:00 2001 From: Julien Eluard Date: Wed, 17 Jul 2019 15:39:20 +0200 Subject: [PATCH] Migrate to latest sticker contract Signed-off-by: Andrey Shovkoplyas --- src/status_im/ethereum/contracts.cljs | 9 +++- src/status_im/stickers/core.cljs | 47 +++++++++++-------- .../wallet/choose_recipient/core.cljs | 3 +- 3 files changed, 38 insertions(+), 21 deletions(-) diff --git a/src/status_im/ethereum/contracts.cljs b/src/status_im/ethereum/contracts.cljs index 8bb655f27f..e9fa85af04 100644 --- a/src/status_im/ethereum/contracts.cljs +++ b/src/status_im/ethereum/contracts.cljs @@ -8,7 +8,14 @@ :status/tribute-to-talk {:testnet "0xC61aa0287247a0398589a66fCD6146EC0F295432"} :status/stickers - {:testnet "0x39d16CdB56b5a6a89e1A397A13Fe48034694316E"}}) + {:testnet "0x8cc272396be7583c65bee82cd7b743c69a87287d" + :mainnet "0x0577215622f43a39f4bc9640806dfea9b10d2a36"} + :status/sticker-market + {:testnet "0x6CC7274aF9cE9572d22DFD8545Fb8c9C9Bcb48AD" + :mainnet "0x12824271339304d3a9f7e096e62a2a7e73b4a7e7"} + :status/sticker-pack + {:testnet "0xf852198d0385c4b871e0b91804ecd47c6ba97351" + :mainnet "0x110101156e8F0743948B2A61aFcf3994A8Fb172e"}}) (defn get-address [db contract] diff --git a/src/status_im/stickers/core.cljs b/src/status_im/stickers/core.cljs index 92d14f3d27..ff52ff6128 100644 --- a/src/status_im/stickers/core.cljs +++ b/src/status_im/stickers/core.cljs @@ -64,21 +64,29 @@ (json-rpc/eth-call {:contract contract ;; Returns vector of owned tokens ids in the contract by address - :method "tokensOwnedBy(address)" + :method "balanceOf(address)" :params [address] - :outputs ["uint256[]"] + :outputs ["uint256"] :on-success - (fn [[tokens]] - (doseq [id tokens] + (fn [[count]] + (dotimes [id count] (json-rpc/eth-call {:contract contract ;; Returns pack id in the contract by token id - :method "tokenPackId(uint256)" - :params [id] + :method "tokenOfOwnerByIndex(address,uint256)" + :params [address id] :outputs ["uint256"] :on-success - (fn [[pack-id]] - (re-frame/dispatch [:stickers/pack-owned pack-id]))})))}))) + (fn [[token-id]] + (json-rpc/eth-call + {:contract contract + ;; Returns pack id in the contract by token id + :method "tokenPackId(uint256)" + :params [token-id] + :outputs ["uint256"] + :on-success + (fn [[pack-id]] + (re-frame/dispatch [:stickers/pack-owned pack-id]))}))})))}))) (fx/defn init-stickers-packs [{:keys [db]}] @@ -137,29 +145,30 @@ (fx/defn load-packs [{:keys [db]}] - (let [contract (contracts/get-address db :status/stickers) - address (ethereum/current-address db)] + (let [contract (contracts/get-address db :status/stickers) + pack-contract (contracts/get-address db :status/sticker-pack) + address (ethereum/current-address db)] (when contract - {:stickers/owned-packs-fx [contract address] + {:stickers/owned-packs-fx [pack-contract address] :stickers/load-packs-fx [contract]}))) (fx/defn approve-pack [{db :db :as cofx} pack-id price] - (let [address (ethereum/current-address db) - stickers-contract (contracts/get-address db :status/stickers) - snt-contract (contracts/get-address db :status/snt)] + (let [address (ethereum/current-address db) + sticker-market-contract (contracts/get-address db :status/sticker-market) + snt-contract (contracts/get-address db :status/snt)] (signing/eth-transaction-call cofx {:contract snt-contract :method "approveAndCall(address,uint256,bytes)" - :params [stickers-contract + :params [sticker-market-contract price - (abi-spec/encode "buyToken(uint256,address)" [pack-id address])] + (abi-spec/encode "buyToken(uint256,address,uint256)" [pack-id address price])] :on-result [:stickers/pending-pack pack-id]}))) (fx/defn pending-pack [{:keys [db] :as cofx} id] - (let [contract (contracts/get-address db :status/stickers) + (let [contract (contracts/get-address db :status/sticker-pack) address (ethereum/current-address db)] (when contract (fx/merge cofx @@ -171,7 +180,7 @@ (fx/defn pending-timeout [{{:stickers/keys [packs-pending packs-owned] :as db} :db}] (let [packs-diff (clojure.set/difference packs-pending packs-owned) - contract (contracts/get-address db :status/stickers) + contract (contracts/get-address db :status/sticker-pack) address (ethereum/current-address db)] (when contract (merge {:db (assoc db :stickers/packs-pending packs-diff)} @@ -184,7 +193,7 @@ (fx/defn get-owned-pack [{:keys [db]}] - (let [contract (contracts/get-address db :status/stickers) + (let [contract (contracts/get-address db :status/sticker-pack) address (ethereum/current-address db)] (when contract {:stickers/owned-packs-fx [contract address]}))) diff --git a/src/status_im/wallet/choose_recipient/core.cljs b/src/status_im/wallet/choose_recipient/core.cljs index 69de731746..84c7e4fe9b 100644 --- a/src/status_im/wallet/choose_recipient/core.cljs +++ b/src/status_im/wallet/choose_recipient/core.cljs @@ -8,7 +8,8 @@ [status-im.ethereum.ens :as ens] [status-im.i18n :as i18n] [status-im.utils.money :as money] - [status-im.utils.fx :as fx])) + [status-im.utils.fx :as fx] + [status-im.utils.handlers :as handlers])) (fx/defn toggle-flashlight {:events [:wallet/toggle-flashlight]}