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, 2020 at 10:35
  • It has been resolved by .then, the "e" is not a promise, it is another object. Oct 16, 2020 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, 2020 at 12:48

2 Answers 2

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

0
0

Hello sir have you figured out a way to do this without maintaining a enum in the frontend? and instead querying a public state variable ?

enum CaseStatus {
    CREATED,
    ACTIVE,
    FINAL
}

CaseStatus public caseState = CaseStatus.CREATED;

function getEnumValue() constant returns (uint){return uint(caseState );}

Hope This Helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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