Skip to content

Commit

Permalink
refactor(renterd): assume autopilot always exists
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Nov 18, 2024
1 parent 571da0c commit d0e8345
Show file tree
Hide file tree
Showing 20 changed files with 165 additions and 364 deletions.
68 changes: 30 additions & 38 deletions apps/renterd/components/CmdRoot/ConfigCmdGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { useDialog } from '../../contexts/dialog'
import { CommandGroup, CommandItemNav, CommandItemSearch } from './Item'
import { Page } from './types'
import { useConfig } from '../../contexts/config'
import { useApp } from '../../contexts/app'

const commandPage = {
namespace: 'configuration',
Expand All @@ -21,7 +20,6 @@ export function ConfigCmdGroup({ currentPage, parentPage, pushPage }: Props) {
const router = useRouter()
const { configViewMode } = useConfig()
const { closeDialog } = useDialog()
const { autopilotInfo } = useApp()
return (
<CommandGroup currentPage={currentPage} commandPage={commandPage}>
<CommandItemNav
Expand All @@ -44,18 +42,16 @@ export function ConfigCmdGroup({ currentPage, parentPage, pushPage }: Props) {
>
Open configuration
</CommandItemSearch>
{autopilotInfo.data?.isAutopilotEnabled && (
<CommandItemSearch
currentPage={currentPage}
commandPage={commandPage}
onSelect={() => {
router.push(routes.config.storage)
closeDialog()
}}
>
Configure storage
</CommandItemSearch>
)}
<CommandItemSearch
currentPage={currentPage}
commandPage={commandPage}
onSelect={() => {
router.push(routes.config.storage)
closeDialog()
}}
>
Configure storage
</CommandItemSearch>
<CommandItemSearch
currentPage={currentPage}
commandPage={commandPage}
Expand All @@ -68,30 +64,26 @@ export function ConfigCmdGroup({ currentPage, parentPage, pushPage }: Props) {
</CommandItemSearch>
{configViewMode === 'advanced' && (
<>
{autopilotInfo.data?.isAutopilotEnabled && (
<>
<CommandItemSearch
currentPage={currentPage}
commandPage={commandPage}
onSelect={() => {
router.push(routes.config.hosts)
closeDialog()
}}
>
Configure hosts
</CommandItemSearch>
<CommandItemSearch
currentPage={currentPage}
commandPage={commandPage}
onSelect={() => {
router.push(routes.config.wallet)
closeDialog()
}}
>
Configure wallet
</CommandItemSearch>
</>
)}
<CommandItemSearch
currentPage={currentPage}
commandPage={commandPage}
onSelect={() => {
router.push(routes.config.hosts)
closeDialog()
}}
>
Configure hosts
</CommandItemSearch>
<CommandItemSearch
currentPage={currentPage}
commandPage={commandPage}
onSelect={() => {
router.push(routes.config.wallet)
closeDialog()
}}
>
Configure wallet
</CommandItemSearch>
<CommandItemSearch
currentPage={currentPage}
commandPage={commandPage}
Expand Down
61 changes: 27 additions & 34 deletions apps/renterd/components/Config/RebalancePrices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
downloadWeight,
uploadWeight,
} from '../../contexts/config/spendingConfig'
import { useApp } from '../../contexts/app'
import { useRedundancyMultiplier } from '../../contexts/config/useRedundancyMultiplier'
import { useFormExchangeRate } from '../../contexts/config/useFormExchangeRate'
import { useSpendingEstimate } from '../../contexts/config/useSpendingEstimate'
Expand Down Expand Up @@ -89,7 +88,6 @@ function useSpendingDerivedPricingFromEnabledFields({
maxUploadPriceTBPinned?: BigNumber
}> {
const { form } = useConfig()
const { isAutopilotEnabled } = useApp()
const storageTB = form.watch('storageTB')
const downloadTBMonth = form.watch('downloadTBMonth')
const uploadTBMonth = form.watch('uploadTBMonth')
Expand All @@ -99,40 +97,35 @@ function useSpendingDerivedPricingFromEnabledFields({
})
const { rate } = useFormExchangeRate(form)
const values = useMemo(() => {
if (isAutopilotEnabled) {
const derivedPricing = derivePricingFromSpendingEstimate({
estimatedSpendingPerMonth,
maxPricingFactor,
storageTB,
downloadTBMonth,
uploadTBMonth,
redundancyMultiplier,
storageWeight,
downloadWeight,
uploadWeight,
})
if (!derivedPricing) {
return undefined
}
// Convert derived siacoin prices to pinned fiat prices.
const pinnedPricing = rate
? {
maxStoragePriceTBMonthPinned:
derivedPricing?.maxStoragePriceTBMonth.times(rate),
maxDownloadPriceTBPinned:
derivedPricing?.maxDownloadPriceTB.times(rate),
maxUploadPriceTBPinned:
derivedPricing?.maxUploadPriceTB.times(rate),
}
: undefined
return {
...derivedPricing,
...pinnedPricing,
}
const derivedPricing = derivePricingFromSpendingEstimate({
estimatedSpendingPerMonth,
maxPricingFactor,
storageTB,
downloadTBMonth,
uploadTBMonth,
redundancyMultiplier,
storageWeight,
downloadWeight,
uploadWeight,
})
if (!derivedPricing) {
return undefined
}
// Convert derived siacoin prices to pinned fiat prices.
const pinnedPricing = rate
? {
maxStoragePriceTBMonthPinned:
derivedPricing?.maxStoragePriceTBMonth.times(rate),
maxDownloadPriceTBPinned:
derivedPricing?.maxDownloadPriceTB.times(rate),
maxUploadPriceTBPinned: derivedPricing?.maxUploadPriceTB.times(rate),
}
: undefined
return {
...derivedPricing,
...pinnedPricing,
}
return undefined
}, [
isAutopilotEnabled,
estimatedSpendingPerMonth,
storageTB,
downloadTBMonth,
Expand Down
6 changes: 0 additions & 6 deletions apps/renterd/components/Config/Recommendations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ import {
CheckmarkFilled20,
PendingFilled20,
} from '@siafoundation/react-icons'
import { useApp } from '../../contexts/app'
import { routes } from '../../config/routes'
import { useConfig } from '../../contexts/config'
import { pluralize } from '@siafoundation/units'
import { HangingNavItem } from './HangingNavItem'

export function Recommendations() {
const { autopilotInfo } = useApp()
const { form, fields, evaluation } = useConfig()
const {
hostMargin50,
Expand All @@ -33,10 +31,6 @@ export function Recommendations() {
usableHostsAfterRecommendation,
} = evaluation

if (!autopilotInfo.data?.isAutopilotEnabled) {
return null
}

const tip = (
<div className="flex flex-col gap-1 px-3 py-2">
<Text size="14" color="subtle">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { useApp } from '../../../contexts/app'
import { useAutopilotState } from '@siafoundation/renterd-react'

export function useAutopilotNotConfigured() {
const { autopilotInfo } = useApp()
const autopilotState = useAutopilotState()
return {
active:
autopilotInfo.data?.isAutopilotEnabled &&
!autopilotInfo.data?.state?.configured,
active: !autopilotState.data?.configured,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { AllowBlockCmdGroup } from './AllowBlock'
import { ServerFilterItem } from '@siafoundation/design-system'
import { ContractsCmdGroup } from './Contracts'
import { UsableCmdGroup } from './Usable'
import { useApp } from '../../../../../contexts/app'
import { PublicKeyCmdGroup } from './PublicKey'

type Props = {
Expand All @@ -14,12 +13,9 @@ type Props = {
}

export function ContractFilterCmdGroups({ currentPage, select }: Props) {
const { isAutopilotEnabled } = useApp()
return (
<>
{isAutopilotEnabled && (
<UsableCmdGroup currentPage={currentPage} select={select} />
)}
<UsableCmdGroup currentPage={currentPage} select={select} />
<ContractsCmdGroup currentPage={currentPage} select={select} />
<AddressCmdGroup currentPage={currentPage} select={select} />
<PublicKeyCmdGroup currentPage={currentPage} select={select} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { ServerFilterItem } from '@siafoundation/design-system'
import { hostsFilterContractsPage } from '../HostsFilterCmdGroups/Contracts'
import { hostsFilterUsablePage } from '../HostsFilterCmdGroups/Usable'
import { PublicKeyCmdNav } from '../HostsFilterCmdGroups/PublicKey'
import { useApp } from '../../../../../contexts/app'

export const commandPage = {
namespace: 'hosts',
Expand All @@ -26,21 +25,18 @@ export function HostsFilterNav({
pushPage,
select,
}: Props) {
const { isAutopilotEnabled } = useApp()
return (
<>
{isAutopilotEnabled && (
<CommandItemNav
currentPage={currentPage}
parentPage={parentPage}
commandPage={commandPage}
onSelect={() => {
pushPage(hostsFilterUsablePage)
}}
>
{hostsFilterUsablePage.label}
</CommandItemNav>
)}
<CommandItemNav
currentPage={currentPage}
parentPage={parentPage}
commandPage={commandPage}
onSelect={() => {
pushPage(hostsFilterUsablePage)
}}
>
{hostsFilterUsablePage.label}
</CommandItemNav>
<PublicKeyCmdNav
currentPage={currentPage}
parentPage={parentPage}
Expand Down
9 changes: 4 additions & 5 deletions apps/renterd/components/OnboardingBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ import {
PendingFilled16,
Subtract24,
} from '@siafoundation/react-icons'
import { useApp } from '../contexts/app'
import { useSyncStatus } from '../hooks/useSyncStatus'
import { routes } from '../config/routes'
import { useDialog } from '../contexts/dialog'
import { useNotEnoughContracts } from './Files/checks/useNotEnoughContracts'
import { useWallet } from '@siafoundation/renterd-react'
import { useAutopilotState, useWallet } from '@siafoundation/renterd-react'
import BigNumber from 'bignumber.js'
import { humanSiacoin } from '@siafoundation/units'
import { useAppSettings } from '@siafoundation/react-core'
Expand All @@ -29,7 +28,7 @@ import { useSpendingEstimate } from '../contexts/config/useSpendingEstimate'

export function OnboardingBar() {
const { isUnlockedAndAuthedRoute } = useAppSettings()
const { isAutopilotEnabled, autopilotInfo } = useApp()
const autopilotState = useAutopilotState()
const { openDialog } = useDialog()
const wallet = useWallet()
const [maximized, setMaximized] = useLocalStorageState<boolean>(
Expand All @@ -43,15 +42,15 @@ export function OnboardingBar() {
const notEnoughContracts = useNotEnoughContracts()
const { estimatedSpendingPerMonth } = useSpendingEstimate()

if (!isUnlockedAndAuthedRoute || !isAutopilotEnabled) {
if (!isUnlockedAndAuthedRoute) {
return null
}

const walletBalance = new BigNumber(
wallet.data ? wallet.data.confirmed + wallet.data.unconfirmed : 0
)

const step1Configured = autopilotInfo.data?.state?.configured
const step1Configured = autopilotState.data?.configured
const step2Synced = syncStatus.isSynced
const step3Funded = walletBalance.gt(0)
const step4Contracts = !notEnoughContracts.active
Expand Down
5 changes: 0 additions & 5 deletions apps/renterd/contexts/app/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import React, { createContext, useContext } from 'react'
import { useAutopilotInfo } from './useAutopilotInfo'
import { useBusSdk } from './useBusSdk'

function useAppMain() {
const autopilotInfo = useAutopilotInfo()
const bus = useBusSdk()
const isAutopilotEnabled = !!autopilotInfo.data?.isAutopilotEnabled

return {
bus,
autopilotInfo,
isAutopilotEnabled,
}
}

Expand Down
41 changes: 0 additions & 41 deletions apps/renterd/contexts/app/useAutopilotInfo.tsx

This file was deleted.

Loading

0 comments on commit d0e8345

Please sign in to comment.