class Token < ActiveRecord::Base
  enum standard: [:dip20, :icrc1, :unknown]
  validates :canister_id, presence: true, uniqueness: true

  def transfer_fee_to_f
    if self.transfer_fee.present?
      return self.transfer_fee/(10.0**self.decimals)
    else
      return nil
    end
  end

  def get_holder_number
    if self.standard == "dip20"
      tokenInfo = `dfx canister --network ic call #{self.canister_id} getTokenInfo 2>&1`
      tokenInfo.lines[2].split[2]
    else
      "Get holder number coming soon."
    end
  end

  def get_token_info
    if self.standard == "dip20"
      tokenInfo = `dfx canister --network ic call #{self.canister_id} getTokenInfo 2>&1`
    else
      "Get token_info coming soon."
    end
  end
end
