请选择 进入手机版 | 继续访问电脑版

图文精华

【智能合约实战】-26-Redex的action定义-2

2020-1-10 18:40| 发布者: Amuro| 查看: 36| 评论: 0

我们新建一个reducer目录

 

Redux-reducer

 

Reducers/index.js

 

Export const SET_USER = SET_USER

 

Import App from ./App;

Import Button from ./Button

Import Game from ./Game;

Import Login from ./Login;

 

Export {

   App,

   Button,

   Game,

   Login,

}

 

Redux-action-type

 

import {ApiJsonRpcRpcError} from ’eosjs’;

 

import {JsSignatureProvider}from ‘eosjs/dist/eosjs-jssig’;

 

 

 

//调用合约中的ActiondataValue是参数

 

async function takeAction (action,dataValue) {

 

const key = localStorage.getItem(‘cardgame_key’)

 

const rpc =new JsonRpc(process.env.REACT_APP_EOS_HTTP_ENDPOINT)

 

const signatureProvider = new JsSignaturePiovider([key])

 

const api = new Api ({rpc,signatureProvider,textDecoder: new TextDecoder(),

 

textEncoder:new TextEncoder()})

 

}

 

 

 

class ApiService {

 

}

 

export default ApiService

 

 

 

try

 

 

 

let result =await api.transact({

 

      actions[{

 

                accountprocess.env.REACT_APP_EOS_CONTRACT_NAME,

 

                name:action,

 

                authorization:[{

 

                    actor:localStorage.getItem(‘cardgame_account’),

 

                    permission:’active’,

 

                }],

 

                Data:dataValue

 

              }]

 

},{

 

  blocksBehind:3,

 

  ExpireSeconds:30

 

}

 

   )

 

  Return result

 

}catch(error){

 

     throw(error)

 

}

 

Class ApiService{

/**

---------------------------------------------------------------------------

|登录参数:用户名,私钥

----------------------------------------------------------------------------

*/

     Static login{username,key} ) {

        localStorage.setItem‘cardgame_account’ username

        localStorage.setItem‘cardgame_key’ key

 

return new promise((resolve,reject) => {

   takeAction(‘login’, {username:username})

       .then(()=> {

             resolve()

       })

       .catch(err => {

                  localStorage.setItem‘cardgame_account’

          localStorage.setItem‘cardgame_key’

          Reject(err)

        })

    })

}

}

 

 


鲜花

握手

雷人

路过

鸡蛋
精彩评论

沙发等你来坐!

发布文章
返回顶部