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(renterd): network average prices #754

Merged
merged 1 commit into from
Sep 30, 2024
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
5 changes: 5 additions & 0 deletions .changeset/cool-avocados-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'renterd': minor
---

Max RPC price and max contract price now show a suggestion instead of a network average.
5 changes: 5 additions & 0 deletions .changeset/popular-rocks-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'renterd': patch
---

Fixed a bug where the network average prices would show as 0 in the configuration fields. Closes https://github.com/SiaFoundation/renterd/issues/1565
5 changes: 5 additions & 0 deletions apps/renterd-e2e/src/fixtures/click.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ export async function clickIf(
}
return false
}

export async function clickTwice(locator: Locator) {
await locator.click()
await locator.click()
}
9 changes: 7 additions & 2 deletions apps/renterd-e2e/src/fixtures/preferences.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { Page } from 'playwright'
import { fillSelectInputByName } from './selectInput'
import { CurrencyId } from '@siafoundation/react-core'

export async function setCurrencyDisplay(
page: Page,
display: 'sc' | 'fiat' | 'bothPreferSc' | 'bothPreferFiat'
display: 'sc' | 'fiat' | 'bothPreferSc' | 'bothPreferFiat',
currency?: CurrencyId
) {
await page.getByLabel('App preferences').click()
await page.getByTestId('sidenav').getByLabel('App preferences').click()
await fillSelectInputByName(page, 'currencyDisplay', display)
if (currency) {
await fillSelectInputByName(page, 'currencyFiat', currency)
}
await page.getByRole('dialog').getByLabel('close').click()
}
21 changes: 20 additions & 1 deletion apps/renterd-e2e/src/fixtures/siascan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,26 @@ export async function mockApiSiaScanExchangeRates({ page }: { page: Page }) {
await page.route(
'https://api.siascan.com/exchange-rate/siacoin/*',
async (route) => {
await route.fulfill({ json: 0.003944045283 })
if (route.request().url().endsWith('jpy')) {
await route.fulfill({ json: 0.727779694168 })
} else {
await route.fulfill({ json: 0.003944045283 })
}
}
)
}

export async function mockApiSiaScanExchangeRatesHanging({
page,
}: {
page: Page
}) {
await page.route(
'https://api.siascan.com/exchange-rate/siacoin/*',
async () => {
await new Promise(() => {
// Never resolve, leaving the request hanging.
})
}
)
}
58 changes: 28 additions & 30 deletions apps/renterd-e2e/src/specs/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { afterTest, beforeTest } from '../fixtures/beforeTest'
import { setCurrencyDisplay } from '../fixtures/preferences'
import { configResetAllSettings } from '../fixtures/configResetAllSettings'
import { fillSelectInputByName } from '../fixtures/selectInput'
import { clickTwice } from '../fixtures/click'

test.beforeEach(async ({ page }) => {
await beforeTest(page)
Expand All @@ -20,7 +21,7 @@ test.afterEach(async () => {
await afterTest()
})

test('basic field change and save behaviour', async ({ page }) => {
test('field change and save behaviours', async ({ page }) => {
// Reset state.
await navigateToConfig({ page })
await setViewMode({ page, state: 'basic' })
Expand Down Expand Up @@ -62,33 +63,6 @@ test('basic field change and save behaviour', async ({ page }) => {
for (const part of estimateParts) {
await expect(page.getByText(part)).toBeVisible()
}

// Tips are displayed in the correct currency.
await expect(
page
.getByTestId('maxStoragePriceTBMonthGroup')
.getByLabel('Network average')
.getByText('341')
).toBeVisible()
await expect(
page
.getByTestId('maxStoragePriceTBMonthGroup')
.getByLabel('Fit current allowance')
.getByText('300')
).toBeVisible()
await setCurrencyDisplay(page, 'bothPreferFiat')
await expect(
page
.getByTestId('maxStoragePriceTBMonthGroup')
.getByLabel('Network average')
.getByText('$1.34')
).toBeVisible()
await expect(
page
.getByTestId('maxStoragePriceTBMonthGroup')
.getByLabel('Fit current allowance')
.getByText('$1.18')
).toBeVisible()
})

test('set max prices to fit current allowance', async ({ page }) => {
Expand Down Expand Up @@ -243,11 +217,11 @@ test('set max prices via individual field tips', async ({ page }) => {
await expect(
page.getByText('Current pricing may not fit allowance')
).toBeVisible()
await page
const fitButton = page
.getByTestId('maxStoragePriceTBMonthGroup')
.getByLabel('Fit current allowance')
.click()
// TODO: remove the need to click twice, there is some sort of glitch after toggling the pinning switch.
await clickTwice(fitButton)
await page
.getByTestId('maxStoragePriceTBMonthGroup')
.getByLabel('Fit current allowance')
Expand All @@ -273,3 +247,27 @@ test('set max prices via individual field tips', async ({ page }) => {
await expectTextInputByName(page, 'maxUploadPriceTBPinned', '$0.88')
await expectTextInputByName(page, 'maxDownloadPriceTB', '1,118.588756')
})

test('pinned currency and app display currency can be different', async ({
page,
}) => {
await navigateToConfig({ page })
await setViewMode({ page, state: 'basic' })
await fillSelectInputByName(page, 'pinnedCurrency', 'usd')
await setCurrencyDisplay(page, 'bothPreferFiat', 'jpy')
await setSwitchByLabel(page, 'shouldPinMaxStoragePrice', true)
await expectTextInputByName(page, 'maxStoragePriceTBMonthPinned', '$5')
await expect(
page
.getByTestId('maxStoragePriceTBMonthGroup')
.getByLabel('Network average')
.getByText('¥248.17')
).toBeVisible()
const averageButton = page
.getByTestId('maxStoragePriceTBMonthGroup')
.getByLabel('Network average')
.getByText('¥248.17')
// TODO: remove the need to click twice, there is some sort of glitch after toggling the pinning switch.
await clickTwice(averageButton)
await expectTextInputByName(page, 'maxStoragePriceTBMonthPinned', '$1.34')
})
Loading
Loading