0

This is my contract:

enum State { Active, Refunding, Pending, Releasing}

function state(uint orderid) public view returns (State) {
        return State.Releasing;
    }

In one Javascript to interact with contract:

async getState(order_id) {
    const contractInstance = await this.contract.deployed()
    //const status = ['Active', 'Refunding', 'Pending', 'Releasing']
    return contractInstance.state.call(order_id);
  }

In another javascript to call that function:

case RELEASE_PAYMENT:

        console.log("order_id in orderReducer:",action.id);

        (new PaypalContract())
                    .releasePayment(action.id)
                    .then(() => (new PaypalContract()).getState(action.id))
                    .then((e)=> {
                        console.log("status in orderReducer:",e)
                        return{
                          ...state,
                          orderStatus:e
                        }
                    })
        return{
                ...state,
                orderStatus:'Releasing'
              }

From web dev tool, I can see the returned 'e' is always a object, not a string value I expected. Any ideas?

Another question is about react, it looks the react just render once with the first returned state, after I got 'e' from contract, it won't render with the updated state.

Thanks.

enter image description here

enter image description here

3
  • Your e is a promise object which you need to resolve in order to get the actual value that you seek to get. Oct 16 '20 at 10:35
  • It has been resolved by .then, the "e" is not a promise, it is another object. Oct 16 '20 at 12:47
  • Well, why don't you print the contents of that object and share them here with the rest of us then? Oct 16 '20 at 12:48
0

This is resolved:

It returned 'e' as an int object, so I use an array to take 'e' as an index.

const sta = ['Active', 'Refunding', 'Pending', 'Releasing'];
        (new PaypalContract())
                    .releasePayment(action.id)
                    .then(() => (new PaypalContract()).getState(action.id))
                    .then(function(e) {
                        console.log("status in orderReducer:",sta[e])
                        return{
                          ...state,
                          orderStatus: sta[e]
                        }
                    })

It printed out:

status in orderReducer: Releasing

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.