import { defineStore } from 'pinia';
import { useBlockchain } from './useBlockchain';

export const useMintStore = defineStore('mintStore', {
  state: () => {
    return {
      inflation: '0',
      mintModuleEnabled: false,
    };
  },
  getters: {
    blockchain() {
      return useBlockchain();
    },
  },
  actions: {
    initial() {
      this.fetchInflation();
    },
    async fetchInflation() {
      try {
        const res = await this.blockchain?.rpc?.getMintInflation();
        if (res) {
          this.inflation = res.inflation;
          this.mintModuleEnabled = true;
        }
      } catch (e: any) {
        // Check if module is not implemented/enabled
        if (e?.status === 501) {
          // Module not enabled
          this.mintModuleEnabled = false;
        } else {
          console.error(e);
        }
      }
    },
  },
});
