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

refactor(renterd): settings APIs and daemon explorer exchange rates #741

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/fluffy-emus-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@siafoundation/renterd-js': minor
'@siafoundation/renterd-react': minor
'@siafoundation/renterd-types': minor
---

Removed deprecated setting APIs.
7 changes: 7 additions & 0 deletions .changeset/four-plums-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@siafoundation/renterd-js': minor
'@siafoundation/renterd-react': minor
'@siafoundation/renterd-types': minor
---

Added new strong settings APIs.
5 changes: 5 additions & 0 deletions .changeset/loud-rockets-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'renterd': minor
---

The configuration feature now internally uses the new strong settings APIs.
5 changes: 5 additions & 0 deletions .changeset/lovely-bikes-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'renterd': minor
---

The configuration feature no longer includes the enable pinning or forex endpoint options under price pinning.
5 changes: 5 additions & 0 deletions .changeset/old-jars-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'renterd': minor
---

Contracts can now be filtered and sorted by deletions and sector roots spending.
5 changes: 5 additions & 0 deletions .changeset/silver-pears-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'renterd': minor
---

The app now uses the daemon configured explorer for exchange rates.
5 changes: 5 additions & 0 deletions .changeset/six-moons-relax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'renterd': minor
---

The keys feature now internally uses the new S3 settings API format.
7 changes: 7 additions & 0 deletions .changeset/sour-masks-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@siafoundation/renterd-js': minor
'@siafoundation/renterd-react': minor
'@siafoundation/renterd-types': minor
---

The bus state API now includes daemon configured explorer.
6 changes: 0 additions & 6 deletions apps/renterd-e2e/src/fixtures/configResetAllSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,8 @@ export async function configResetAllSettings({ page }: { page: Page }) {
await setViewMode({ page, state: 'advanced' })

// pinning
await setSwitchByLabel(page, 'pinningEnabled', true)
await fillSelectInputByName(page, 'pinnedCurrency', 'usd')
await fillTextInputByName(page, 'pinnedThreshold', '2')
await fillTextInputByName(
page,
'forexEndpointURL',
'https://api.siascan.com/exchange-rate/siacoin'
)

// storage
await fillTextInputByName(page, 'storageTB', '1')
Expand Down
7 changes: 4 additions & 3 deletions apps/renterd-e2e/src/specs/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { afterTest, beforeTest } from '../fixtures/beforeTest'
import { setCurrencyDisplay } from '../fixtures/preferences'
import { configResetAllSettings } from '../fixtures/configResetAllSettings'
import { fillSelectInputByName } from '../fixtures/selectInput'

test.beforeEach(async ({ page }) => {
await beforeTest(page)
Expand Down Expand Up @@ -147,17 +148,17 @@ test('should show warning if pinning is not fully configured', async ({

await setSwitchByLabel(page, 'shouldPinAllowance', true)
await setSwitchByLabel(page, 'shouldPinMaxStoragePrice', true)
await fillTextInputByName(page, 'forexEndpointURL', '')
await fillSelectInputByName(page, 'pinnedCurrency', '')

await expect(
page
.getByTestId('allowanceMonthGroup')
.getByText('Enter a forex endpoint URL')
.getByText('Select a pinned currency')
).toBeVisible()
await expect(
page
.getByTestId('maxStoragePriceTBMonthGroup')
.getByText('Enter a forex endpoint URL')
.getByText('Select a pinned currency')
).toBeVisible()
})

Expand Down
15 changes: 4 additions & 11 deletions apps/renterd/components/Config/PinnedCurrencyWarning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,28 @@ import { Link, Panel, Text } from '@siafoundation/design-system'
import { routes } from '../../config/routes'

export function PinnedCurrencyWarning({
pinningEnabled,
canUseExchangeRates,
pinnedCurrency,
forexEndpointURL,
}: {
pinningEnabled: boolean
canUseExchangeRates: boolean
pinnedCurrency: string
forexEndpointURL: string
}) {
return (
<Panel className="px-2 pt-1 pb-2">
<Text size="12" color="subtle">
To pin this field:
</Text>
<div className="flex flex-col">
{!pinningEnabled && (
{!canUseExchangeRates && !!pinnedCurrency && (
<Link size="12" href={routes.config.pinning} underline="hover">
- Enable the pinning feature
- Enable an exchange rate API
</Link>
)}
{!pinnedCurrency && (
<Link size="12" href={routes.config.pinning} underline="hover">
- Select a pinned currency
</Link>
)}
{!forexEndpointURL && (
<Link size="12" href={routes.config.pinning} underline="hover">
- Enter a forex endpoint URL
</Link>
)}
</div>
</Panel>
)
Expand Down
28 changes: 13 additions & 15 deletions apps/renterd/components/Config/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,22 @@ import { StateConnError } from './StateConnError'
import { Recommendations } from './Recommendations'
import { ShouldPinSwitch } from './ShouldPinSwitch'
import { PinnedCurrencyWarning } from './PinnedCurrencyWarning'
import { useExchangeRate } from '@siafoundation/react-core'

export function Config() {
const { openDialog } = useDialog()
const { form, fields, remoteError, configRef } = useConfig()

const pinningEnabled = form.watch('pinningEnabled')
const pinnedCurrency = form.watch('pinnedCurrency')
const forexEndpointURL = form.watch('forexEndpointURL')
const shouldPinAllowance = form.watch('shouldPinAllowance')
const shouldPinMaxStoragePrice = form.watch('shouldPinMaxStoragePrice')
const shouldPinMaxUploadPrice = form.watch('shouldPinMaxUploadPrice')
const shouldPinMaxDownloadPrice = form.watch('shouldPinMaxDownloadPrice')

const canShowPinned = pinningEnabled && pinnedCurrency && forexEndpointURL
const { rate } = useExchangeRate({
currency: pinnedCurrency || undefined,
})
const canUseExchangeRates = !!rate

return (
<RenterdAuthedLayout
Expand Down Expand Up @@ -80,7 +82,7 @@ export function Config() {
fields={fields}
/>
{shouldPinAllowance ? (
canShowPinned ? (
canUseExchangeRates ? (
<ConfigurationFiat
name="allowanceMonthPinned"
form={form}
Expand All @@ -89,9 +91,8 @@ export function Config() {
/>
) : (
<PinnedCurrencyWarning
pinningEnabled={pinningEnabled}
canUseExchangeRates={canUseExchangeRates}
pinnedCurrency={pinnedCurrency}
forexEndpointURL={forexEndpointURL}
/>
)
) : (
Expand Down Expand Up @@ -148,7 +149,7 @@ export function Config() {
fields={fields}
/>
{shouldPinMaxStoragePrice ? (
canShowPinned ? (
canUseExchangeRates ? (
<ConfigurationFiat
name="maxStoragePriceTBMonthPinned"
form={form}
Expand All @@ -157,9 +158,8 @@ export function Config() {
/>
) : (
<PinnedCurrencyWarning
pinningEnabled={pinningEnabled}
canUseExchangeRates={canUseExchangeRates}
pinnedCurrency={pinnedCurrency}
forexEndpointURL={forexEndpointURL}
/>
)
) : (
Expand All @@ -184,7 +184,7 @@ export function Config() {
fields={fields}
/>
{shouldPinMaxUploadPrice ? (
canShowPinned ? (
canUseExchangeRates ? (
<ConfigurationFiat
name="maxUploadPriceTBPinned"
form={form}
Expand All @@ -193,9 +193,8 @@ export function Config() {
/>
) : (
<PinnedCurrencyWarning
pinningEnabled={pinningEnabled}
canUseExchangeRates={canUseExchangeRates}
pinnedCurrency={pinnedCurrency}
forexEndpointURL={forexEndpointURL}
/>
)
) : (
Expand All @@ -220,7 +219,7 @@ export function Config() {
fields={fields}
/>
{shouldPinMaxDownloadPrice ? (
canShowPinned ? (
canUseExchangeRates ? (
<ConfigurationFiat
name="maxDownloadPriceTBPinned"
form={form}
Expand All @@ -229,9 +228,8 @@ export function Config() {
/>
) : (
<PinnedCurrencyWarning
pinningEnabled={pinningEnabled}
canUseExchangeRates={canUseExchangeRates}
pinnedCurrency={pinnedCurrency}
forexEndpointURL={forexEndpointURL}
/>
)
) : (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useSettingContractSet } from '@siafoundation/renterd-react'
import { useSettingsUpload } from '@siafoundation/renterd-react'

export function useDefaultContractSetNotSet() {
const css = useSettingContractSet()
const su = useSettingsUpload()

return {
active: css.data && !css.data?.default,
active: su.data && !su.data?.defaultContractSet,
}
}
10 changes: 5 additions & 5 deletions apps/renterd/components/Files/checks/useNotEnoughContracts.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { useSettingRedundancy } from '@siafoundation/renterd-react'
import { useSettingsUpload } from '@siafoundation/renterd-react'
import { useContracts } from '../../../contexts/contracts'

export function useNotEnoughContracts() {
const redundancy = useSettingRedundancy()
const settingsUpload = useSettingsUpload()
const { datasetCount, isLoading: isContractsLoading } = useContracts()

const active =
redundancy.data &&
settingsUpload.data &&
!isContractsLoading &&
datasetCount < redundancy.data.totalShards
datasetCount < settingsUpload.data.redundancy.totalShards

return {
active,
count: datasetCount,
required: redundancy.data?.totalShards || 0,
required: settingsUpload.data?.redundancy.totalShards || 0,
}
}
27 changes: 16 additions & 11 deletions apps/renterd/components/Keys/KeyContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
} from '@siafoundation/design-system'
import { CaretDown16, Delete16 } from '@siafoundation/react-icons'
import {
useSettingS3Authentication,
useSettingUpdate,
useSettingsS3,
useSettingsS3Update,
} from '@siafoundation/renterd-react'
import { useCallback } from 'react'
import { omit } from '@technically/lodash'
Expand All @@ -27,24 +27,29 @@ type Props = {

export function KeyContextMenu({ s3Key, contentProps, buttonProps }: Props) {
const { openConfirmDialog } = useDialog()
const s3AuthenticationSettings = useSettingS3Authentication()
const update = useSettingUpdate()
const settingsS3 = useSettingsS3()
const settingsS3Update = useSettingsS3Update()
const deleteKey = useCallback(async () => {
const newKeys = omit(s3AuthenticationSettings.data?.v4Keypairs, s3Key)
const response = await update.put({
params: {
key: 's3authentication',
},
if (!settingsS3.data) {
triggerErrorToast({ title: 'Error deleting key' })
return
}
const newKeys = omit(settingsS3.data?.authentication.v4Keypairs, s3Key)
const response = await settingsS3Update.put({
payload: {
v4Keypairs: newKeys,
...settingsS3.data,
authentication: {
...settingsS3.data.authentication,
v4Keypairs: newKeys,
},
},
})
if (response.error) {
triggerErrorToast({ title: 'Error deleting key', body: response.error })
} else {
triggerSuccessToast({ title: `Key ${s3Key} removed` })
}
}, [s3AuthenticationSettings.data, s3Key, update])
}, [settingsS3.data, s3Key, settingsS3Update])

return (
<DropdownMenu
Expand Down
27 changes: 14 additions & 13 deletions apps/renterd/components/Keys/KeysCreateDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { useCallback, useMemo } from 'react'
import { useForm } from 'react-hook-form'
import { useDialog } from '../../contexts/dialog'
import {
useSettingS3Authentication,
useSettingUpdate,
useSettingsS3,
useSettingsS3Update,
} from '@siafoundation/renterd-react'
import { Reset16 } from '@siafoundation/react-icons'

Expand Down Expand Up @@ -100,8 +100,8 @@ function getFields({

export function KeysCreateDialog({ trigger, open, onOpenChange }: Props) {
const { closeDialog } = useDialog()
const s3AuthenticationSettings = useSettingS3Authentication()
const update = useSettingUpdate()
const settingsS3 = useSettingsS3()
const settingsS3Update = useSettingsS3Update()

const form = useForm({
mode: 'all',
Expand All @@ -111,15 +111,16 @@ export function KeysCreateDialog({ trigger, open, onOpenChange }: Props) {
const onSubmit = useCallback(
async (values: Values) => {
const v4Keypairs = {
...s3AuthenticationSettings.data?.v4Keypairs,
...settingsS3.data?.authentication.v4Keypairs,
[values.name]: values.secret,
}
const response = await update.put({
params: {
key: 's3authentication',
},
const response = await settingsS3Update.put({
payload: {
v4Keypairs,
...settingsS3.data,
authentication: {
...settingsS3.data.authentication,
v4Keypairs,
},
},
})
if (response.error) {
Expand All @@ -130,7 +131,7 @@ export function KeysCreateDialog({ trigger, open, onOpenChange }: Props) {
closeDialog()
}
},
[form, closeDialog, update, s3AuthenticationSettings.data]
[form, closeDialog, settingsS3Update, settingsS3.data]
)

const fields = useMemo(
Expand All @@ -143,10 +144,10 @@ export function KeysCreateDialog({ trigger, open, onOpenChange }: Props) {
form.setValue('secret', generateSecretAccessKey())
},
existingKeys: Object.keys(
s3AuthenticationSettings.data?.v4Keypairs || {}
settingsS3.data?.authentication.v4Keypairs || {}
),
}),
[s3AuthenticationSettings.data, form]
[settingsS3.data, form]
)

const onInvalid = useOnInvalid(fields)
Expand Down
Loading
Loading