-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e3e57d
commit 2c95417
Showing
16 changed files
with
383 additions
and
107 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
test/e2e/tests/confirmations/transactions/revoke-allowance-redesign.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* eslint-disable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires */ | ||
import { MockttpServer } from 'mockttp'; | ||
import { WINDOW_TITLES } from '../../../helpers'; | ||
import { Driver } from '../../../webdriver/driver'; | ||
import { scrollAndConfirmAndAssertConfirm } from '../helpers'; | ||
import { mocked4BytesApprove } from './erc20-approve-redesign.spec'; | ||
import { | ||
assertChangedSpendingCap, | ||
editSpendingCap, | ||
} from './increase-token-allowance-redesign.spec'; | ||
import { openDAppWithContract, TestSuiteArguments } from './shared'; | ||
|
||
const { | ||
defaultGanacheOptions, | ||
defaultGanacheOptionsForType2Transactions, | ||
withFixtures, | ||
} = require('../../../helpers'); | ||
const FixtureBuilder = require('../../../fixture-builder'); | ||
const { SMART_CONTRACTS } = require('../../../seeder/smart-contracts'); | ||
|
||
describe('Confirmation Redesign ERC20 Revoke Allowance', function () { | ||
const smartContract = SMART_CONTRACTS.HST; | ||
|
||
describe('Submit an revoke transaction @no-mmi', function () { | ||
it('Sends a type 0 transaction (Legacy)', async function () { | ||
await withFixtures( | ||
{ | ||
dapp: true, | ||
fixtures: new FixtureBuilder() | ||
.withPermissionControllerConnectedToTestDapp() | ||
.withPreferencesController({ | ||
preferences: { | ||
redesignedConfirmationsEnabled: true, | ||
isRedesignedConfirmationsDeveloperEnabled: true, | ||
}, | ||
}) | ||
.build(), | ||
ganacheOptions: defaultGanacheOptions, | ||
smartContract, | ||
testSpecificMock: mocks, | ||
title: this.test?.fullTitle(), | ||
}, | ||
async ({ driver, contractRegistry }: TestSuiteArguments) => { | ||
await openDAppWithContract(driver, contractRegistry, smartContract); | ||
|
||
await createERC20ApproveTransaction(driver); | ||
|
||
const NEW_SPENDING_CAP = '0'; | ||
await editSpendingCap(driver, NEW_SPENDING_CAP); | ||
|
||
await driver.waitForSelector({ | ||
css: 'h2', | ||
text: 'Remove permission', | ||
}); | ||
|
||
await scrollAndConfirmAndAssertConfirm(driver); | ||
|
||
await assertChangedSpendingCap(driver, NEW_SPENDING_CAP); | ||
}, | ||
); | ||
}); | ||
|
||
it('Sends a type 2 transaction (EIP1559)', async function () { | ||
await withFixtures( | ||
{ | ||
dapp: true, | ||
fixtures: new FixtureBuilder() | ||
.withPermissionControllerConnectedToTestDapp() | ||
.withPreferencesController({ | ||
preferences: { | ||
redesignedConfirmationsEnabled: true, | ||
isRedesignedConfirmationsDeveloperEnabled: true, | ||
}, | ||
}) | ||
.build(), | ||
ganacheOptions: defaultGanacheOptionsForType2Transactions, | ||
smartContract, | ||
testSpecificMock: mocks, | ||
title: this.test?.fullTitle(), | ||
}, | ||
async ({ driver, contractRegistry }: TestSuiteArguments) => { | ||
await openDAppWithContract(driver, contractRegistry, smartContract); | ||
|
||
await createERC20ApproveTransaction(driver); | ||
|
||
const NEW_SPENDING_CAP = '0'; | ||
await editSpendingCap(driver, NEW_SPENDING_CAP); | ||
|
||
await driver.waitForSelector({ | ||
css: 'h2', | ||
text: 'Remove permission', | ||
}); | ||
|
||
await scrollAndConfirmAndAssertConfirm(driver); | ||
|
||
await assertChangedSpendingCap(driver, NEW_SPENDING_CAP); | ||
}, | ||
); | ||
}); | ||
}); | ||
}); | ||
|
||
async function mocks(server: MockttpServer) { | ||
return [await mocked4BytesApprove(server)]; | ||
} | ||
|
||
async function createERC20ApproveTransaction(driver: Driver) { | ||
await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp); | ||
await driver.clickElement('#approveTokens'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
ui/pages/confirmations/components/confirm/info/approve/hooks/use-custom-spending-cap.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { useState } from 'react'; | ||
|
||
export const useCustomSpendingCap = () => { | ||
const [customSpendingCap, setCustomSpendingCap] = useState(''); | ||
|
||
return { customSpendingCap, setCustomSpendingCap }; | ||
}; |
11 changes: 11 additions & 0 deletions
11
ui/pages/confirmations/components/confirm/info/approve/revoke-details/revoke-details.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react'; | ||
import { ConfirmInfoSection } from '../../../../../../../components/app/confirm/info/row/section'; | ||
import { OriginRow } from '../../shared/transaction-details/transaction-details'; | ||
|
||
export const RevokeDetails = () => { | ||
return ( | ||
<ConfirmInfoSection> | ||
<OriginRow /> | ||
</ConfirmInfoSection> | ||
); | ||
}; |
53 changes: 53 additions & 0 deletions
53
...ons/components/confirm/info/approve/revoke-static-simulation/revoke-static-simulation.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { NameType } from '@metamask/name-controller'; | ||
import { TransactionMeta } from '@metamask/transaction-controller'; | ||
import React from 'react'; | ||
import { ConfirmInfoRow } from '../../../../../../../components/app/confirm/info/row'; | ||
import Name from '../../../../../../../components/app/name'; | ||
import { Box } from '../../../../../../../components/component-library'; | ||
import { Display } from '../../../../../../../helpers/constants/design-system'; | ||
import { useI18nContext } from '../../../../../../../hooks/useI18nContext'; | ||
import { useConfirmContext } from '../../../../../context/confirm'; | ||
import StaticSimulation from '../../shared/static-simulation/static-simulation'; | ||
|
||
export const RevokeStaticSimulation = () => { | ||
const t = useI18nContext(); | ||
|
||
const { currentConfirmation: transactionMeta } = useConfirmContext() as { | ||
currentConfirmation: TransactionMeta; | ||
}; | ||
|
||
const simulationElements = ( | ||
<> | ||
<ConfirmInfoRow label={t('spendingCap')}> | ||
<Box style={{ marginLeft: 'auto', maxWidth: '100%' }}> | ||
<Box display={Display.Flex}> | ||
<Name | ||
value={transactionMeta.txParams.to as string} | ||
type={NameType.ETHEREUM_ADDRESS} | ||
/> | ||
</Box> | ||
</Box> | ||
</ConfirmInfoRow> | ||
|
||
<ConfirmInfoRow label={t('spender')}> | ||
<Box style={{ marginLeft: 'auto', maxWidth: '100%' }}> | ||
<Box display={Display.Flex}> | ||
<Name | ||
value={transactionMeta.txParams.from as string} | ||
type={NameType.ETHEREUM_ADDRESS} | ||
/> | ||
</Box> | ||
</Box> | ||
</ConfirmInfoRow> | ||
</> | ||
); | ||
|
||
return ( | ||
<StaticSimulation | ||
title={t('simulationDetailsTitle')} | ||
titleTooltip={t('simulationDetailsTitleTooltip')} | ||
description={t('revokeSimulationDetailsDesc')} | ||
simulationElements={simulationElements} | ||
/> | ||
); | ||
}; |
Oops, something went wrong.