Skip to content

Commit

Permalink
Merge pull request #575 from ensdomains/default-toggle-off
Browse files Browse the repository at this point in the history
Send name default toggle off
  • Loading branch information
LeonmanRolls authored Aug 24, 2023
2 parents 38f320a + 968abd1 commit 5827cc2
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 100 deletions.
32 changes: 0 additions & 32 deletions e2e/specs/stateless/profileEditor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import { emptyAddress } from '@app/utils/constants'

const oldResolver = '0x84eA74d481Ee0A5332c457a4d796187F6Ba67fEB'
const newResolver = '0x0E801D84Fa97b50751Dbf25036d067dCf18858bF'
// This not an actual resovler but a dummy address that has been inserted to the second to last known resolver
// to test the situation where unwrapped do not show a warning when editing profile.
const dummyRersolver = '0xd7a4F6473f32aC2Af804B3686AE8F1932bC35750'

const DEFAULT_RECORDS = {
texts: [
Expand Down Expand Up @@ -324,35 +321,6 @@ test.describe('wrapped', () => {
})
})

test.describe('resolver status', () => {
test('should not show warning when editing unwrapped name with second to last resolver', async ({
page,
login,
makeName,
makePageObject,
}) => {
const name = await makeName({
label: 'unwrapped',
type: 'legacy',
resolver: dummyRersolver,
})

const morePage = makePageObject('MorePage')
const profilePage = makePageObject('ProfilePage')

await morePage.goto(name)
await login.connect()

await expect(morePage.resolver).toHaveText(dummyRersolver)
await expect(page.getByText('Latest')).toBeVisible()

await profilePage.goto(name)

await profilePage.editProfileButton.click()
await expect(profilePage.profileEditor.getByText('Edit your profile')).toBeVisible()
})
})

test.describe('subgraph errors', () => {
test('should disable edit profile button when there is a subgraph error', async ({
page,
Expand Down
17 changes: 14 additions & 3 deletions e2e/specs/stateless/sendFlow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test.describe('Happy', () => {

await morePage.sendButton.click()
await page.getByTestId('dogfood').type(accounts.getAddress('user3'))
await page.getByTestId('owner-checkbox').click()
await page.getByTestId('manager-checkbox').click()
await sendNameModal.clickNextButton()
await transactionModal.autoComplete()

Expand Down Expand Up @@ -55,6 +55,7 @@ test.describe('Happy', () => {
await login.connect()

await morePage.sendButton.click()
await page.getByTestId('manager-checkbox').click()

// Should not allow the manager to change the owner
await expect(page.getByTestId('Make Owner')).toHaveCount(0)
Expand Down Expand Up @@ -89,7 +90,7 @@ test.describe('Happy', () => {
await login.connect()

await morePage.sendButton.click()
await page.getByTestId('manager-checkbox').click()
await page.getByTestId('owner-checkbox').click()
await page.getByTestId('dogfood').type(accounts.getAddress('user3'))
await sendNameModal.clickNextButton()

Expand Down Expand Up @@ -124,7 +125,7 @@ test.describe('Happy', () => {

await morePage.sendButton.click()

await page.getByTestId('owner-checkbox').click()
await page.getByTestId('manager-checkbox').click()
await page.getByTestId('dogfood').type(accounts.getAddress('user3'))
await sendNameModal.clickNextButton()

Expand Down Expand Up @@ -157,6 +158,8 @@ test.describe('Happy', () => {

await morePage.sendButton.click()

await page.getByTestId('manager-checkbox').click()
await page.getByTestId('owner-checkbox').click()
await page.getByTestId('dogfood').type(accounts.getAddress('user3'))
await sendNameModal.clickNextButton()
await transactionModal.confirm()
Expand All @@ -165,6 +168,8 @@ test.describe('Happy', () => {

// Should work after going back after first transaction
await page.getByTestId('dogfood').type(accounts.getAddress('user3'))
await page.getByTestId('manager-checkbox').click()
await page.getByTestId('owner-checkbox').click()
await sendNameModal.clickNextButton()

await transactionModal.autoComplete()
Expand Down Expand Up @@ -209,6 +214,7 @@ test.describe('Unwrapped subnames', () => {
await login.connect()

await morePage.sendButton.click()
await page.getByTestId('manager-checkbox').click()
await page.getByTestId('dogfood').type(accounts.getAddress('user3'))
await sendNameModal.clickNextButton()

Expand Down Expand Up @@ -246,6 +252,7 @@ test.describe('Unwrapped subnames', () => {
await login.connect()

await morePage.sendButton.click()
await page.getByTestId('manager-checkbox').click()
await page.getByTestId('dogfood').type(accounts.getAddress('user3'))
await sendNameModal.clickNextButton()
await transactionModal.autoComplete()
Expand Down Expand Up @@ -343,6 +350,7 @@ test.describe('Wrapped subnames', () => {

await morePage.sendButton.click()

await page.getByTestId('manager-checkbox').click()
await expect(page.getByText('Make manager')).toBeVisible()
await page.getByTestId('dogfood').type(accounts.getAddress('user3'))
await sendNameModal.clickNextButton()
Expand Down Expand Up @@ -382,6 +390,7 @@ test.describe('Wrapped subnames', () => {
await login.connect()

await morePage.sendButton.click()
await page.getByTestId('manager-checkbox').click()
await expect(page.getByText('Make manager')).toBeVisible()
await page.getByTestId('dogfood').type(accounts.getAddress('user3'))
await sendNameModal.clickNextButton()
Expand Down Expand Up @@ -450,6 +459,7 @@ test.describe('Wrapped subname with PCC burned', () => {
await login.connect()

await morePage.sendButton.click()
await page.getByTestId('owner-checkbox').click()
await expect(page.getByText('Make owner')).toBeVisible()
await page.getByTestId('dogfood').type(accounts.getAddress('user3'))
await sendNameModal.clickNextButton()
Expand Down Expand Up @@ -483,6 +493,7 @@ test.describe('Wrapped name', () => {
await login.connect()

await morePage.sendButton.click()
await page.getByTestId('owner-checkbox').click()
await expect(page.getByText('Make owner')).toBeVisible()
await page.getByTestId('dogfood').type(accounts.getAddress('user3'))
await sendNameModal.clickNextButton()
Expand Down
96 changes: 37 additions & 59 deletions src/components/pages/profile/[name]/tabs/MoreTab/Resolver.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { useTranslation } from 'react-i18next'
import styled, { css } from 'styled-components'

import { Skeleton, Tag, Typography, mq } from '@ensdomains/thorin'
import { Typography, mq } from '@ensdomains/thorin'

import { cacheableComponentStyles } from '@app/components/@atoms/CacheableComponent'
import { DisabledButtonWithTooltip } from '@app/components/@molecules/DisabledButtonWithTooltip'
import RecordItem from '@app/components/RecordItem'
import { useHasGlobalError } from '@app/hooks/errors/useHasGlobalError'
import { useResolverType } from '@app/hooks/resolver/useResolverType'
import { useTransactionFlow } from '@app/transaction-flow/TransactionFlowProvider'

import { TabWrapper } from '../../../TabWrapper'
Expand Down Expand Up @@ -60,16 +59,6 @@ const InnerHeading = styled.div(
`,
)

const TagsContainer = styled.div(
({ theme }) => css`
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-start;
gap: ${theme.space['1']};
`,
)

const Resolver = ({
name,
canEditResolver,
Expand All @@ -96,54 +85,43 @@ const Resolver = ({
})
}

const { data: { type: resolverType, tone, isWildcard } = {}, isLoading: isResolverTypeLoading } =
useResolverType(name)

return (
<Skeleton loading={isResolverTypeLoading} style={{ width: '100%', borderRadius: '16px' }}>
<Container $isCached={isCachedData}>
<HeadingContainer>
<InnerHeading>
<Typography color="text" fontVariant="headingFour" weight="bold">
{t('tabs.more.resolver.label')}
</Typography>
<TagsContainer>
<Tag colorStyle={tone!}>{t(`tabs.more.resolver.${resolverType}`)}</Tag>
{isWildcard && (
<Tag colorStyle="greySecondary">{t('tabs.more.resolver.wildcard')}</Tag>
)}
</TagsContainer>
</InnerHeading>
{canEdit && !hasGlobalError && (
<>
{canEditResolver ? (
<button
style={{ cursor: 'pointer' }}
type="button"
onClick={handleEditClick}
data-testid="edit-resolver-button"
>
{t('action.edit', { ns: 'common' })}
</button>
) : (
<DisabledButtonWithTooltip
{...{
buttonId: 'set-resolver-disabled-button',
content: t(`errors.permissionRevoked`),
buttonText: 'Edit',
mobileWidth: 150,
buttonWidth: '15',
mobileButtonWidth: 'initial',
colorStyle: 'transparent',
}}
/>
)}
</>
)}
</HeadingContainer>
<RecordItem type="text" data-testid="resolver-address" value={resolverAddress || ''} />
</Container>
</Skeleton>
<Container $isCached={isCachedData}>
<HeadingContainer>
<InnerHeading>
<Typography color="text" fontVariant="headingFour" weight="bold">
{t('tabs.more.resolver.label')}
</Typography>
</InnerHeading>
{canEdit && !hasGlobalError && (
<>
{canEditResolver ? (
<button
style={{ cursor: 'pointer' }}
type="button"
onClick={handleEditClick}
data-testid="edit-resolver-button"
>
{t('action.edit', { ns: 'common' })}
</button>
) : (
<DisabledButtonWithTooltip
{...{
buttonId: 'set-resolver-disabled-button',
content: t(`errors.permissionRevoked`),
buttonText: 'Edit',
mobileWidth: 150,
buttonWidth: '15',
mobileButtonWidth: 'initial',
colorStyle: 'transparent',
}}
/>
)}
</>
)}
</HeadingContainer>
<RecordItem type="text" data-testid="resolver-address" value={resolverAddress || ''} />
</Container>
)
}

Expand Down
13 changes: 7 additions & 6 deletions src/transaction-flow/input/SendName-flow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,23 @@ export const SendName = ({ data, dispatch, onDismiss }: Props) => {
} = useForm<FormData>({
mode: 'onChange',
defaultValues: {
managerChoice: 'manager',
ownerChoice: 'owner',
managerChoice: '',
ownerChoice: '',
dogfoodRaw: '',
address: '',
},
})

const managerChoiceWatch = watch('managerChoice')
const ownerChoiceWatch = watch('ownerChoice')
const addressWatch = watch('address')
const abilities = useAbilities(name)
const { canSendManager, canSendOwner, sendNameFunctionCallDetails } = abilities.data || {}
const loadingAbilities = abilities.isLoading
const hasChoice =
(canSendManager && managerChoiceWatch) || (canSendOwner && ownerChoiceWatch) || loadingAbilities
!loadingAbilities &&
addressWatch &&
((canSendManager && managerChoiceWatch) || (canSendOwner && ownerChoiceWatch))

const hasErrors = Object.keys(formState.errors || {}).length > 0

Expand Down Expand Up @@ -203,7 +206,6 @@ export const SendName = ({ data, dispatch, onDismiss }: Props) => {
<Toggle
size="large"
value="owner"
defaultChecked
data-testid="owner-checkbox"
{...register('ownerChoice', { shouldUnregister: true })}
/>
Expand All @@ -220,7 +222,6 @@ export const SendName = ({ data, dispatch, onDismiss }: Props) => {
<Toggle
size="large"
value="manager"
defaultChecked
data-testid="manager-checkbox"
{...register('managerChoice', { shouldUnregister: true })}
/>
Expand Down Expand Up @@ -257,7 +258,7 @@ export const SendName = ({ data, dispatch, onDismiss }: Props) => {
</Button>
}
trailing={
<Button type="submit" disabled={!hasChoice || !formState.isDirty || hasErrors}>
<Button type="submit" disabled={!hasChoice || hasErrors}>
{t('action.next', { ns: 'common' })}
</Button>
}
Expand Down

0 comments on commit 5827cc2

Please sign in to comment.