-
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.
feat: permit signature simulation info (#24862)
- Loading branch information
Showing
7 changed files
with
223 additions
and
4 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.
98 changes: 98 additions & 0 deletions
98
...s/confirm/info/typed-sign/permit-simulation/__snapshots__/permit-simulation.test.tsx.snap
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,98 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`PermitSimulation renders component correctly 1`] = ` | ||
<div> | ||
<div | ||
class="mm-box mm-box--margin-bottom-4 mm-box--padding-2 mm-box--background-color-background-default mm-box--rounded-md" | ||
> | ||
<div | ||
class="mm-box confirm-info-row mm-box--margin-top-2 mm-box--margin-bottom-2 mm-box--padding-right-2 mm-box--padding-left-2 mm-box--display-flex mm-box--flex-direction-row mm-box--flex-wrap-wrap mm-box--justify-content-space-between mm-box--color-text-default mm-box--rounded-lg" | ||
style="overflow-wrap: anywhere; min-height: 24px;" | ||
> | ||
<div | ||
class="mm-box mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-center mm-box--align-items-center" | ||
> | ||
<p | ||
class="mm-box mm-text mm-text--body-md-medium mm-box--color-inherit" | ||
> | ||
Estimated changes | ||
</p> | ||
<div> | ||
<div | ||
aria-describedby="tippy-tooltip-1" | ||
class="" | ||
data-original-title="Estimated changes are what might happen if you go through with this transaction. This is just a prediction, not a guarantee." | ||
data-tooltipped="" | ||
style="display: flex;" | ||
tabindex="0" | ||
> | ||
<span | ||
class="mm-box mm-icon mm-icon--size-sm mm-box--margin-left-1 mm-box--display-inline-block mm-box--color-icon-muted" | ||
style="mask-image: url('./images/icons/question.svg');" | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
<div | ||
class="mm-box mm-box--display-flex mm-box--gap-2 mm-box--flex-wrap-wrap mm-box--align-items-center" | ||
> | ||
<p | ||
class="mm-box mm-text mm-text--body-md mm-box--color-inherit" | ||
style="white-space: pre-wrap;" | ||
> | ||
This transaction gives permission to withdraw your tokens | ||
</p> | ||
</div> | ||
</div> | ||
<div | ||
class="mm-box confirm-info-row mm-box--margin-top-2 mm-box--margin-bottom-2 mm-box--padding-right-2 mm-box--padding-left-2 mm-box--display-flex mm-box--flex-direction-row mm-box--flex-wrap-wrap mm-box--justify-content-space-between mm-box--color-text-default mm-box--rounded-lg" | ||
style="overflow-wrap: anywhere; min-height: 24px;" | ||
> | ||
<div | ||
class="mm-box mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-center mm-box--align-items-center" | ||
> | ||
<p | ||
class="mm-box mm-text mm-text--body-md-medium mm-box--color-inherit" | ||
> | ||
Approve spend limit | ||
</p> | ||
</div> | ||
<div | ||
class="mm-box" | ||
> | ||
<div | ||
class="mm-box mm-box--display-flex" | ||
> | ||
<div | ||
class="mm-box mm-box--margin-inline-end-1 mm-box--display-inline" | ||
> | ||
<p | ||
class="mm-box mm-text mm-text--body-md mm-text--text-align-center mm-box--padding-inline-2 mm-box--color-text-default mm-box--background-color-background-alternative mm-box--rounded-xl" | ||
> | ||
3000 | ||
</p> | ||
</div> | ||
<div> | ||
<div | ||
class="name name__missing" | ||
> | ||
<span | ||
class="mm-box name__icon mm-icon mm-icon--size-md mm-box--display-inline-block mm-box--color-inherit" | ||
style="mask-image: url('./images/icons/question.svg');" | ||
/> | ||
<p | ||
class="mm-box mm-text name__value mm-text--body-md mm-box--color-text-default" | ||
> | ||
0xCcCCc...ccccC | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
<div | ||
class="mm-box" | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
`; |
1 change: 1 addition & 0 deletions
1
ui/pages/confirmations/components/confirm/info/typed-sign/permit-simulation/index.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 @@ | ||
export { default as PermitSimulation } from './permit-simulation'; |
21 changes: 21 additions & 0 deletions
21
...irmations/components/confirm/info/typed-sign/permit-simulation/permit-simulation.test.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,21 @@ | ||
import React from 'react'; | ||
import configureMockStore from 'redux-mock-store'; | ||
|
||
import mockState from '../../../../../../../../test/data/mock-state.json'; | ||
import { renderWithProvider } from '../../../../../../../../test/lib/render-helpers'; | ||
import { permitSignatureMsg } from '../../../../../../../../test/data/confirmations/typed_sign'; | ||
import PermitSimulation from './permit-simulation'; | ||
|
||
describe('PermitSimulation', () => { | ||
it('renders component correctly', () => { | ||
const state = { | ||
...mockState, | ||
confirm: { | ||
currentConfirmation: permitSignatureMsg, | ||
}, | ||
}; | ||
const mockStore = configureMockStore([])(state); | ||
const { container } = renderWithProvider(<PermitSimulation />, mockStore); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); |
82 changes: 82 additions & 0 deletions
82
.../confirmations/components/confirm/info/typed-sign/permit-simulation/permit-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,82 @@ | ||
import React, { useMemo } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { NameType } from '@metamask/name-controller'; | ||
|
||
import { Numeric } from '../../../../../../../../shared/modules/Numeric'; | ||
import Name from '../../../../../../../components/app/name/name'; | ||
import { | ||
ConfirmInfoRow, | ||
ConfirmInfoRowText, | ||
} from '../../../../../../../components/app/confirm/info/row'; | ||
import { useI18nContext } from '../../../../../../../hooks/useI18nContext'; | ||
import { currentConfirmationSelector } from '../../../../../../../selectors'; | ||
import { Box, Text } from '../../../../../../../components/component-library'; | ||
import { | ||
BackgroundColor, | ||
BorderRadius, | ||
Display, | ||
TextAlign, | ||
} from '../../../../../../../helpers/constants/design-system'; | ||
import { parseTypedDataMessage } from '../../../../../utils'; | ||
import { SignatureRequestType } from '../../../../../types/confirm'; | ||
import useTokenExchangeRate from '../../../../../../../components/app/currency-input/hooks/useTokenExchangeRate'; | ||
import { IndividualFiatDisplay } from '../../../../simulation-details/fiat-display'; | ||
|
||
const PermitSimulation: React.FC = () => { | ||
const t = useI18nContext(); | ||
const currentConfirmation = useSelector( | ||
currentConfirmationSelector, | ||
) as SignatureRequestType; | ||
|
||
const { | ||
domain: { verifyingContract }, | ||
message: { value }, | ||
} = parseTypedDataMessage(currentConfirmation.msgParams?.data as string); | ||
|
||
const exchangeRate = useTokenExchangeRate(verifyingContract); | ||
|
||
const fiatValue = useMemo(() => { | ||
if (exchangeRate && value) { | ||
return exchangeRate.times(new Numeric(value, 10)).toNumber(); | ||
} | ||
return undefined; | ||
}, [exchangeRate, value]); | ||
|
||
return ( | ||
<Box | ||
backgroundColor={BackgroundColor.backgroundDefault} | ||
borderRadius={BorderRadius.MD} | ||
padding={2} | ||
marginBottom={4} | ||
> | ||
<ConfirmInfoRow | ||
label={t('simulationDetailsTitle')} | ||
tooltip={t('simulationDetailsTitleTooltip')} | ||
> | ||
<ConfirmInfoRowText text={t('permitSimulationDetailInfo')} /> | ||
</ConfirmInfoRow> | ||
<ConfirmInfoRow label={t('approve')}> | ||
<Box> | ||
<Box display={Display.Flex}> | ||
<Box display={Display.Inline} marginInlineEnd={1}> | ||
<Text | ||
backgroundColor={BackgroundColor.backgroundAlternative} | ||
borderRadius={BorderRadius.XL} | ||
paddingInline={2} | ||
textAlign={TextAlign.Center} | ||
> | ||
{value} | ||
</Text> | ||
</Box> | ||
<Name value={verifyingContract} type={NameType.ETHEREUM_ADDRESS} /> | ||
</Box> | ||
<Box> | ||
{fiatValue && <IndividualFiatDisplay fiatAmount={fiatValue} />} | ||
</Box> | ||
</Box> | ||
</ConfirmInfoRow> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default PermitSimulation; |
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