Skip to content

Commit

Permalink
removed gas banner & updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav Lysak committed Sep 16, 2024
1 parent 857d153 commit ea76d2a
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 106 deletions.
4 changes: 2 additions & 2 deletions e2e/specs/stateless/extendNames.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ test('should be able to extend a single unwrapped name from profile', async ({

const extendNamesModal = makePageObject('ExtendNamesModal')
await test.step('should show warning message', async () => {
await expect(page.getByText('You do not own this name')).toBeVisible()
await expect(page.getByText(`You do not own ${name}`)).toBeVisible()
await page.getByRole('button', { name: 'I understand' }).click()
})

Expand Down Expand Up @@ -253,7 +253,7 @@ test('should be able to extend a single unwrapped name in grace period from prof
await profilePage.getExtendButton.click()

await test.step('should show warning message', async () => {
await expect(page.getByText('You do not own this name')).toBeVisible()
await expect(page.getByText(`You do not own ${name}`)).toBeVisible()
await page.getByRole('button', { name: 'I understand' }).click()
})

Expand Down
2 changes: 1 addition & 1 deletion e2e/specs/stateless/ownership.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ test.describe('Extend name', () => {
await ownershipPage.extendButton.click()

await test.step('should show ownership warning', async () => {
await expect(page.getByText('You do not own this name')).toBeVisible()
await expect(page.getByText(`You do not own ${name}`)).toBeVisible()
await page.getByRole('button', { name: 'I understand' }).click()
})
await test.step('should show the correct price data', async () => {
Expand Down
2 changes: 1 addition & 1 deletion public/locales/en/transactionFlow.json
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
"total": "Estimated total"
},
"bannerMsg": "Extending for multiple years will save money on network costs by avoiding yearly transactions.",
"gasLimitError": "Insufficient funds"
"gasLimitError": "Not enough ETH in wallet"
},
"transferProfile": {
"title": "Transfer Profile",
Expand Down
2 changes: 1 addition & 1 deletion src/components/ProfileSnippet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export const ProfileSnippet = ({
isSelf: canSelfExtend,
})
}
}, [renew, canSelfExtend])
}, [renew, name, canSelfExtend])

const ActionButton = useMemo(() => {
if (button === 'extend')
Expand Down
92 changes: 2 additions & 90 deletions src/transaction-flow/input/ExtendNames/ExtendNames-flow.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { mockFunction, render, screen, userEvent, waitFor } from '@app/test-utils'
import { mockFunction, render, screen } from '@app/test-utils'

import { describe, expect, it, vi } from 'vitest'

import { useEstimateGasWithStateOverride } from '@app/hooks/chain/useEstimateGasWithStateOverride'
import { usePrice } from '@app/hooks/ensjs/public/usePrice'

import ExtendNames from './ExtendNames-flow'
import { makeMockIntersectionObserver } from '../../../../test/mock/makeMockIntersectionObserver'
import ExtendNames from './ExtendNames-flow'

vi.mock('@app/hooks/chain/useEstimateGasWithStateOverride')
vi.mock('@app/hooks/ensjs/public/usePrice')
Expand All @@ -28,18 +28,6 @@ vi.mock('@app/components/@atoms/Invoice/Invoice', async () => {
Invoice: vi.fn(() => <div>Invoice</div>),
}
})
vi.mock(
'@app/components/@atoms/RegistrationTimeComparisonBanner/RegistrationTimeComparisonBanner',
async () => {
const originalModule = await vi.importActual(
'@app/components/@atoms/RegistrationTimeComparisonBanner/RegistrationTimeComparisonBanner',
)
return {
...originalModule,
RegistrationTimeComparisonBanner: vi.fn(() => <div>RegistrationTimeComparisonBanner</div>),
}
},
)

makeMockIntersectionObserver()

Expand All @@ -64,82 +52,6 @@ describe('Extendnames', () => {
/>,
)
})
it('should go directly to registration if isSelf is true and names.length is 1', () => {
render(
<ExtendNames
{...{
data: { names: ['nick.eth'], isSelf: true },
dispatch: () => null,
onDismiss: () => null,
}}
/>,
)
expect(screen.getByText('RegistrationTimeComparisonBanner')).toBeVisible()
})
it('should show warning message before registration if isSelf is false and names.length is 1', async () => {
render(
<ExtendNames
{...{
data: { names: ['nick.eth'], isSelf: false },
dispatch: () => null,
onDismiss: () => null,
}}
/>,
)
expect(screen.getByText('input.extendNames.ownershipWarning.description.1')).toBeVisible()
await userEvent.click(screen.getByRole('button', { name: 'action.understand' }))
await waitFor(() => expect(screen.getByText('RegistrationTimeComparisonBanner')).toBeVisible())
})
it('should show a list of names before registration if isSelf is true and names.length is greater than 1', async () => {
render(
<ExtendNames
{...{
data: { names: ['nick.eth', 'atnight.eth'], isSelf: true },
dispatch: () => null,
onDismiss: () => null,
}}
/>,
)
expect(screen.getByTestId('extend-names-names-list')).toBeVisible()
await userEvent.click(screen.getByRole('button', { name: 'action.next' }))
await waitFor(() => expect(screen.getByText('RegistrationTimeComparisonBanner')).toBeVisible())
})
it('should show a warning then a list of names before registration if isSelf is false and names.length is greater than 1', async () => {
render(
<ExtendNames
{...{
data: { names: ['nick.eth', 'atnight.eth'], isSelf: false },
dispatch: () => null,
onDismiss: () => null,
}}
/>,
)
expect(screen.getByText('input.extendNames.ownershipWarning.description.2')).toBeVisible()
await userEvent.click(screen.getByRole('button', { name: 'action.understand' }))
expect(screen.getByTestId('extend-names-names-list')).toBeVisible()
await userEvent.click(screen.getByRole('button', { name: 'action.next' }))
await waitFor(() => expect(screen.getByText('RegistrationTimeComparisonBanner')).toBeVisible())
})
it('should have RegistrationTimeComparisonBanner greyed out if gas limit estimation is still loading', () => {
mockUseEstimateGasWithStateOverride.mockReturnValueOnce({
data: { gasEstimate: 21000n, gasCost: 100n },
gasPrice: 100n,
error: null,
isLoading: true,
})
render(
<ExtendNames
{...{
data: { names: ['nick.eth'], isSelf: true },
dispatch: () => null,
onDismiss: () => null,
}}
/>,
)
const optionBar = screen.getByText('RegistrationTimeComparisonBanner')
const { parentElement } = optionBar
expect(parentElement).toHaveStyle('opacity: 0.5')
})
it('should have Invoice greyed out if gas limit estimation is still loading', () => {
mockUseEstimateGasWithStateOverride.mockReturnValueOnce({
data: { gasEstimate: 21000n, gasCost: 100n },
Expand Down
11 changes: 0 additions & 11 deletions src/transaction-flow/input/ExtendNames/ExtendNames-flow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { CacheableComponent } from '@app/components/@atoms/CacheableComponent'
import { makeCurrencyDisplay } from '@app/components/@atoms/CurrencyText/CurrencyText'
import { Invoice, InvoiceItem } from '@app/components/@atoms/Invoice/Invoice'
import { PlusMinusControl } from '@app/components/@atoms/PlusMinusControl/PlusMinusControl'
import { RegistrationTimeComparisonBanner } from '@app/components/@atoms/RegistrationTimeComparisonBanner/RegistrationTimeComparisonBanner'
import { StyledName } from '@app/components/@atoms/StyledName/StyledName'
import { DateSelection } from '@app/components/@molecules/DateSelection/DateSelection'
import { useEstimateGasWithStateOverride } from '@app/hooks/chain/useEstimateGasWithStateOverride'
Expand Down Expand Up @@ -211,7 +210,6 @@ const ExtendNames = ({ data: { names, isSelf }, dispatch, onDismiss }: Props) =>
const totalRentFee = priceData ? priceData.base + priceData.premium : 0n
const yearlyFee = priceData?.base ? deriveYearlyFee({ duration: seconds, price: priceData }) : 0n
const previousYearlyFee = usePreviousDistinct(yearlyFee) || 0n
const unsafeDisplayYearlyFee = yearlyFee !== 0n ? yearlyFee : previousYearlyFee
const isShowingPreviousYearlyFee = yearlyFee === 0n && previousYearlyFee > 0n

const transactions = [
Expand Down Expand Up @@ -254,8 +252,6 @@ const ExtendNames = ({ data: { names, isSelf }, dispatch, onDismiss }: Props) =>

const previousTransactionFee = usePreviousDistinct(transactionFee) || 0n

const unsafeDisplayTransactionFee =
transactionFee !== 0n ? transactionFee : previousTransactionFee
const isShowingPreviousTransactionFee = transactionFee === 0n && previousTransactionFee > 0n

const items: InvoiceItem[] = [
Expand Down Expand Up @@ -363,13 +359,6 @@ const ExtendNames = ({ data: { names, isSelf }, dispatch, onDismiss }: Props) =>
balance.value < estimatedGasLimit)) && (
<Helper type="warning">{t('input.extendNames.gasLimitError')}</Helper>
)}
{!!unsafeDisplayYearlyFee && !!unsafeDisplayTransactionFee && (
<RegistrationTimeComparisonBanner
yearlyFee={unsafeDisplayYearlyFee}
transactionFee={unsafeDisplayTransactionFee}
message={t('input.extendNames.bannerMsg')}
/>
)}
</GasEstimationCacheableComponent>
</>
))}
Expand Down

0 comments on commit ea76d2a

Please sign in to comment.