From 59feb5ecd86fcb778bab9ba9acfdf29076520300 Mon Sep 17 00:00:00 2001 From: Andrey Shovkoplyas Date: Thu, 28 Feb 2019 13:31:25 +0100 Subject: [PATCH] [#7611] Update stickers contract and use "approveAndCall" feature Signed-off-by: Andrey Shovkoplyas --- src/status_im/events.cljs | 5 ----- src/status_im/stickers/core.cljs | 16 ++++------------ src/status_im/utils/ethereum/abi_spec.cljs | 4 +--- src/status_im/utils/ethereum/stickers.cljs | 2 +- 4 files changed, 6 insertions(+), 21 deletions(-) diff --git a/src/status_im/events.cljs b/src/status_im/events.cljs index 1c35f2d9c9..6c2fc850b9 100644 --- a/src/status_im/events.cljs +++ b/src/status_im/events.cljs @@ -1716,11 +1716,6 @@ (fn [cofx [_ id price]] (stickers/approve-pack cofx id price))) -(handlers/register-handler-fx - :stickers/buy-token - (fn [cofx [_ id]] - (stickers/buy-token cofx id))) - (handlers/register-handler-fx :stickers/get-owned-packs (fn [cofx _] diff --git a/src/status_im/stickers/core.cljs b/src/status_im/stickers/core.cljs index 5b698002a7..3cd043ee25 100644 --- a/src/status_im/stickers/core.cljs +++ b/src/status_im/stickers/core.cljs @@ -73,25 +73,17 @@ (when on-result {:on-result on-result}) tx)) -(fx/defn buy-token [{{:keys [network] :as db} :db} pack-id] - (let [network (get-in db [:account/account :networks network]) - address (ethereum/normalized-address (get-in db [:account/account :address])) - tx-object {:to (get ethereum.stickers/contracts (ethereum/network->chain-keyword network)) - :data (abi-spec/encode "buyToken(uint256,address)" [pack-id address])}] - (models.wallet/open-modal-wallet-for-transaction - db - (prepare-transaction "buy" tx-object [:stickers/pending-pack pack-id]) - tx-object))) - (fx/defn approve-pack [{db :db} pack-id price] (let [network (get-in db [:account/account :networks (:network db)]) + address (ethereum/normalized-address (get-in db [:account/account :address])) chain (ethereum/network->chain-keyword network) stickers-contract (get ethereum.stickers/contracts chain) + data (abi-spec/encode "buyToken(uint256,address)" [pack-id address]) tx-object {:to (get erc20/snt-contracts chain) - :data (abi-spec/encode "approve(address,uint256)" [stickers-contract price])}] + :data (abi-spec/encode "approveAndCall(address,uint256,bytes)" [stickers-contract price data])}] (models.wallet/open-modal-wallet-for-transaction db - (prepare-transaction "approve" tx-object [:stickers/buy-token pack-id]) + (prepare-transaction "approve" tx-object [:stickers/pending-pack pack-id]) tx-object))) (fx/defn pending-pack [{{:keys [web3 network] :as db} :db :as cofx} id] diff --git a/src/status_im/utils/ethereum/abi_spec.cljs b/src/status_im/utils/ethereum/abi_spec.cljs index 919d9c9850..77ead115f1 100644 --- a/src/status_im/utils/ethereum/abi_spec.cljs +++ b/src/status_im/utils/ethereum/abi_spec.cljs @@ -96,9 +96,7 @@ encoded-value (if encoded-value? (subs value 2) (from-utf8 value))] - (str (when dynamic? (enc {:type :int :value (if encoded-value? - (count encoded-value) - (/ (count encoded-value) 2))})) + (str (when dynamic? (enc {:type :int :value (/ (count encoded-value) 2)})) (right-pad encoded-value)))) ;; string: enc(X) = enc(enc_utf8(X)), i.e. X is utf-8 encoded and this diff --git a/src/status_im/utils/ethereum/stickers.cljs b/src/status_im/utils/ethereum/stickers.cljs index b5924a1d70..a7b11f228a 100644 --- a/src/status_im/utils/ethereum/stickers.cljs +++ b/src/status_im/utils/ethereum/stickers.cljs @@ -4,7 +4,7 @@ (def contracts {:mainnet nil - :testnet "0x82694E3DeabE4D6f4e6C180Fe6ad646aB8EF53ae" + :testnet "0x39d16CdB56b5a6a89e1A397A13Fe48034694316E" :rinkeby nil}) (defn pack-count [web3 contract cb]