-
Notifications
You must be signed in to change notification settings - Fork 5k
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
feat: permit signature simulation info #24862
Changes from all commits
161814b
9ed12f0
df04719
fa6fc59
c3d5774
4e5c7fb
d1f85d9
737d201
18fb2c2
0be218d
d6164cf
c224117
11dc68b
a43bcf9
a75ad4a
0d7bae3
9d17164
e905920
22d2cb9
1f6feb1
80c2f99
da9f628
5406eb2
7a28886
6cfdd13
84bceab
34ab28d
7007708
ec9b3f1
d712315
13ad7c0
9b6923c
0d23c47
b7d39d0
48f49b2
afc9219
bfb99bf
4bd3ff5
23f3050
04dbe96
2768c2a
9320061
0ba6528
873059a
82538d4
d11f9d5
2b64f36
89083dd
5207569
1adb2ff
966267e
df189d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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> | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as PermitSimulation } from './permit-simulation'; |
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(); | ||
}); | ||
}); |
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> | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey @digiwand : after certain with confirm row wraps, thus this is how it will look for wider values There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Derek had made some improvements on how we display long values within simulations here: #24036 Is this something we could re-use? Ideally, we have the same pattern in both places There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep that can be done, but I would prefer to address that in separate PR. |
||
|
||
export default PermitSimulation; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again these are limitations with ConfirmInfoRow. We need to see if its ok to generically change this for all usages.