0

我正在使用它,通过反应中的元掩码在智能合约中进行函数调用:

export default class EthereumForm1 extends Component {
  constructor (props) {
    super (props);
    const MyContract = window.web3.eth.contract(ContractABI);

    this.state = {
      ContractInstance: MyContract.at('ContractAddress')
    }
    this.doPause = this.doPause.bind (this);
}
  doPause() {
    const { pause } = this.state.ContractInstance;

    pause (
      {
        gas: 30000,
        gasPrice: 32000000000,
        value: window.web3.toWei (0, 'ether')
      },
      (err) => {
      if (err) console.error ('Error1::::', err);
      console.log ('Contract should be paused');
    })
  }

我想要的是运行带有加载 gif 的 jQuery 代码:$(".Loading").show(); 同时处理事务并在之后将其删除。此外,最好在 div 之后添加事务状态,例如在元掩码中(通过或拒绝)。

Metamask 交易状态图片

4

2 回答 2

0

What helped me was checking every few seconds if my transactiopn finished, and if yes hiding the loader.

if (latestTx != null) {
  window.web3.eth.getTransactionReceipt(latestTx, function (error, result) {
    if (error) {
      $(".Loading").hide();
      console.error ('Error1::::', error);
    }
    console.log(result);
    if(result != null){
      latestTx = null;
      $(".Loading").hide();
    }
  });
}
于 2018-03-18T13:43:12.417 回答
0

您不需要 jquery 来执行此操作。React state 可以自动管理进度的状态。您所要做的就是调用setState函数。

class EthereumFrom1 extends React.Component {

    state = {
        loading: false
    };

    constructor(props) {
        super(props);

        this.doPause = this.doPause.bind(this);

    }

    doPause() {
        const {pause} = this.state.ContractInstance;

        pause(
            {
                gas: 30000,
                gasPrice: 32000000000,
                value: window.web3.toWei(0, 'ether')
            },
            (err) => {
                if (err) console.error('Error1::::', err);
                this.setState({loading: true});
            })
    }

    render() {
        return (
            <div>
                {this.state.loading ?
                    <div className="Loading">
                        Loading...
                    </div> : <div>done</div>
                }
            </div>

        )
    }
}
于 2018-03-16T01:09:37.657 回答