[#7611] Update stickers contract and use "approveAndCall" feature
Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
This commit is contained in:
parent
38aca129cd
commit
59feb5ecd8
|
@ -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 _]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
(def contracts
|
||||
{:mainnet nil
|
||||
:testnet "0x82694E3DeabE4D6f4e6C180Fe6ad646aB8EF53ae"
|
||||
:testnet "0x39d16CdB56b5a6a89e1A397A13Fe48034694316E"
|
||||
:rinkeby nil})
|
||||
|
||||
(defn pack-count [web3 contract cb]
|
||||
|
|
Loading…
Reference in New Issue