import { observable, action, computed } from 'mobx';
export default class WalletStore {
  @observable isLoading = false;
  @observable data = {
    wallet: 1,
    point: 1
  };

  constructor(context) {
    this.context = context;
    this.http = context.http;
  }

  @action
  getData() {
    this.isLoading = true;
    return this.http.get("wallet")
      .then(res => {
        this.isLoading = false;
        this.data = res;
        return res;
      })
      .catch(err => {
        this.isLoading = false;
        throw err;
      })
  }

  @action
  redeemVoucherCode(voucherCode) {
    return this.http.post("wallet/redeem", {
      unique_code: voucherCode
    })
      .then(res => {
        this.getData();
      });
  }
}
