Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix start agent balance thresholds #154

Merged
merged 4 commits into from
May 29, 2024

Conversation

truemiller
Copy link
Collaborator

@truemiller truemiller commented May 29, 2024

  • start agent button was disabled in some states where it shouldn't be

if (!services) return false;

// deployment statuses where agent should not be deployed
// if (serviceStatus === DeploymentStatus.DEPLOYED) return false; // condition already checked above
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this commented code line? if yes, don't understand how it's checked above

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the condition is covered on L179:

if (serviceStatus === DeploymentStatus.DEPLOYED) {

had left the comment for context around why it's not included in the statuses where agent should not be deployable

can remove though, let me know 🙏

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good, but it might be personal preference, I haven't commonly seen IIFE being used. Also, regarding condition, can be added just to avoid confusion, but it is up to you.

function checkDeployability() {
  // case where required values are undefined (not fetched from the server)
  if (totalEthBalance === undefined || totalOlasBalance === undefined || !services) {
    return false;
  }

  // deployment statuses where agent should not be deployed
  if (
    serviceStatus === DeploymentStatus.DEPLOYED || 
    serviceStatus === DeploymentStatus.DEPLOYING ||
    serviceStatus === DeploymentStatus.STOPPING
  ) {
    return false;
  }

  // case where service exists & user has initial funded
  if (services[0] && storeState?.isInitialFunded) {
    return totalOlasBalance >= requiredOlas; // at present agent will always require staked/bonded OLAS
  }

  return totalOlasBalance >= requiredOlas && totalEthBalance > requiredGas;
}

const isDeployable = checkDeployability();

if (!isDeployable) {
  return (
    <Button type="default" size="large" disabled>
      Start agent
    </Button>
  );
}

frontend/components/Setup/SetupWelcome.tsx Outdated Show resolved Hide resolved
if (!services) return false;

// deployment statuses where agent should not be deployed
// if (serviceStatus === DeploymentStatus.DEPLOYED) return false; // condition already checked above
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good, but it might be personal preference, I haven't commonly seen IIFE being used. Also, regarding condition, can be added just to avoid confusion, but it is up to you.

function checkDeployability() {
  // case where required values are undefined (not fetched from the server)
  if (totalEthBalance === undefined || totalOlasBalance === undefined || !services) {
    return false;
  }

  // deployment statuses where agent should not be deployed
  if (
    serviceStatus === DeploymentStatus.DEPLOYED || 
    serviceStatus === DeploymentStatus.DEPLOYING ||
    serviceStatus === DeploymentStatus.STOPPING
  ) {
    return false;
  }

  // case where service exists & user has initial funded
  if (services[0] && storeState?.isInitialFunded) {
    return totalOlasBalance >= requiredOlas; // at present agent will always require staked/bonded OLAS
  }

  return totalOlasBalance >= requiredOlas && totalEthBalance > requiredGas;
}

const isDeployable = checkDeployability();

if (!isDeployable) {
  return (
    <Button type="default" size="large" disabled>
      Start agent
    </Button>
  );
}

@truemiller truemiller merged commit d8f414f into main May 29, 2024
2 of 4 checks passed
@truemiller truemiller deleted the josh/fix-start-agent-balance-threshold branch July 26, 2024 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants