-
-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(coinmarket): possibility to proceed with unverified address
- Loading branch information
1 parent
4d41257
commit 4d08a77
Showing
14 changed files
with
161 additions
and
86 deletions.
There are no files selected for viewing
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
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
111 changes: 55 additions & 56 deletions
111
.../suite/src/components/suite/modals/ReduxModal/UserContextModal/ConfirmUnverifiedModal.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 |
---|---|---|
@@ -1,101 +1,100 @@ | ||
import { useEffect } from 'react'; | ||
import styled from 'styled-components'; | ||
|
||
import { applySettings } from 'src/actions/settings/deviceSettingsActions'; | ||
import { Translation, Modal } from 'src/components/suite'; | ||
import { Translation } from 'src/components/suite'; | ||
import { TranslationKey } from 'src/components/suite/Translation'; | ||
import { useDevice, useDispatch, useSelector } from 'src/hooks/suite'; | ||
import { ThunkAction } from 'src/types/suite'; | ||
import { Button } from '@trezor/components'; | ||
import { Dispatch, GetState } from 'src/types/suite'; | ||
import { Button, H3, NewModal, Paragraph } from '@trezor/components'; | ||
import { onCancel } from 'src/actions/suite/modalActions'; | ||
import { selectDeviceLabelOrName } from '@suite-common/wallet-core'; | ||
|
||
const StyledModal = styled(Modal)` | ||
width: 520px; | ||
`; | ||
|
||
// eslint-disable-next-line local-rules/no-override-ds-component | ||
const StyledButton = styled(Button)` | ||
flex-grow: 1; | ||
`; | ||
import { applySettings } from 'src/actions/settings/deviceSettingsActions'; | ||
import { useEffect } from 'react'; | ||
|
||
interface ConfirmUnverifiedModalProps { | ||
showUnverifiedButtonText: TranslationKey; | ||
showUnverified: () => ThunkAction; | ||
verify: () => ThunkAction; | ||
action: { | ||
event: () => (dispatch: Dispatch) => void; | ||
title: TranslationKey; | ||
closeAfterEventTriggered?: boolean; | ||
}; | ||
verifyProcess?: () => (dispatch: Dispatch, getState: GetState) => Promise<void>; | ||
warningText: TranslationKey; | ||
} | ||
|
||
export const ConfirmUnverifiedModal = ({ | ||
showUnverifiedButtonText, | ||
showUnverified, | ||
verify, | ||
action, | ||
warningText, | ||
verifyProcess, | ||
}: ConfirmUnverifiedModalProps) => { | ||
const deviceLabel = useSelector(selectDeviceLabelOrName); | ||
const { device } = useDevice(); | ||
const dispatch = useDispatch(); | ||
const { device, isLocked } = useDevice(); | ||
|
||
// Device connected while the modal is open -> switch to verification modal. | ||
useEffect(() => { | ||
if (device?.connected) { | ||
dispatch(verify()); | ||
} | ||
}, [device?.connected, dispatch, verify]); | ||
|
||
// just to make TS happy | ||
if (!device) return null; | ||
const { isLocked } = useDevice(); | ||
|
||
const isDeviceLocked = isLocked(); | ||
const isPassphraseRequired = device.connected && !device.available; | ||
const isPassphraseRequired = device?.connected && !device.available; | ||
const deviceStatus = isPassphraseRequired | ||
? 'TR_DEVICE_LABEL_IS_UNAVAILABLE' | ||
: 'TR_DEVICE_LABEL_IS_NOT_CONNECTED'; | ||
const description = isPassphraseRequired | ||
? 'TR_PLEASE_ENABLE_PASSPHRASE' | ||
: 'TR_PLEASE_CONNECT_YOUR_DEVICE'; | ||
|
||
const handleClose = () => dispatch(onCancel()); | ||
const handleEvent = () => { | ||
dispatch(action.event()); | ||
|
||
if (action.closeAfterEventTriggered) { | ||
handleClose(); | ||
} | ||
}; | ||
|
||
const enablePassphraseAndContinue = async () => { | ||
if (!device.available) { | ||
if (!device?.available) { | ||
const result = await dispatch(applySettings({ use_passphrase: true })); | ||
if (!result || !result.success) return; | ||
} | ||
dispatch(verify()); | ||
}; | ||
const continueUnverified = () => dispatch(showUnverified()); | ||
const close = () => dispatch(onCancel()); | ||
|
||
// Device connected while the modal is open -> switch to verification modal. | ||
useEffect(() => { | ||
if (device?.connected && verifyProcess) { | ||
dispatch(verifyProcess()); | ||
} | ||
}, [device?.connected, dispatch, verifyProcess]); | ||
|
||
return ( | ||
<StyledModal | ||
heading={<Translation id={deviceStatus} values={{ deviceLabel }} />} | ||
isCancelable | ||
onCancel={close} | ||
description={ | ||
<Translation | ||
id={warningText} | ||
values={{ claim: <Translation id={description} /> }} | ||
/> | ||
} | ||
bottomBarComponents={ | ||
<NewModal | ||
variant="warning" | ||
size="small" | ||
icon="shieldWarning" | ||
onCancel={handleClose} | ||
bottomContent={ | ||
<> | ||
<Button variant="warning" onClick={continueUnverified}> | ||
<Translation id={showUnverifiedButtonText} /> | ||
<Button variant="warning" onClick={handleEvent}> | ||
<Translation id={action.title} /> | ||
</Button> | ||
|
||
{isPassphraseRequired && ( | ||
<StyledButton | ||
<Button | ||
variant="primary" | ||
onClick={enablePassphraseAndContinue} | ||
isDisabled={isDeviceLocked} | ||
> | ||
<Translation id="TR_ACCOUNT_ENABLE_PASSPHRASE" /> | ||
</StyledButton> | ||
</Button> | ||
)} | ||
<Button onClick={close} variant="tertiary"> | ||
<Button onClick={handleClose} variant="tertiary"> | ||
<Translation id="TR_BACK" /> | ||
</Button> | ||
</> | ||
} | ||
/> | ||
> | ||
<H3> | ||
<Translation id={deviceStatus} values={{ deviceLabel }} /> | ||
</H3> | ||
<Paragraph> | ||
<Translation | ||
id={warningText} | ||
values={{ claim: <Translation id={description} /> }} | ||
/> | ||
</Paragraph> | ||
</NewModal> | ||
); | ||
}; |
27 changes: 27 additions & 0 deletions
27
...src/components/suite/modals/ReduxModal/UserContextModal/ConfirmUnverifiedProceedModal.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,27 @@ | ||
import { ConfirmUnverifiedModal } from './ConfirmUnverifiedModal'; | ||
import { COINMARKET_BUY } from 'src/actions/wallet/constants'; | ||
import { Dispatch } from 'src/types/suite'; | ||
|
||
interface ConfirmUnverifiedProceedModalProps { | ||
value: string; | ||
} | ||
|
||
export const ConfirmUnverifiedProceedModal = ({ value }: ConfirmUnverifiedProceedModalProps) => { | ||
const proceedWithUnverifiedAddress = () => (dispatch: Dispatch) => { | ||
dispatch({ | ||
type: COINMARKET_BUY.VERIFY_ADDRESS, | ||
addressVerified: value, | ||
}); | ||
}; | ||
|
||
return ( | ||
<ConfirmUnverifiedModal | ||
action={{ | ||
event: proceedWithUnverifiedAddress, | ||
title: 'TR_PROCEED_UNVERIFIED_ADDRESS', | ||
closeAfterEventTriggered: true, | ||
}} | ||
warningText="TR_ADDRESS_PHISHING_WARNING" | ||
/> | ||
); | ||
}; |
20 changes: 20 additions & 0 deletions
20
...te/src/components/suite/modals/ReduxModal/UserContextModal/ConfirmUnverifiedXpubModal.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,20 @@ | ||
import { useCallback } from 'react'; | ||
|
||
import { ConfirmUnverifiedModal } from './ConfirmUnverifiedModal'; | ||
import { openXpubModal, showXpub } from 'src/actions/wallet/publicKeyActions'; | ||
|
||
export const ConfirmUnverifiedXpubModal = () => { | ||
const event = useCallback(() => openXpubModal(), []); | ||
const verifyProcess = useCallback(() => showXpub(), []); | ||
|
||
return ( | ||
<ConfirmUnverifiedModal | ||
action={{ | ||
event, | ||
title: 'TR_SHOW_UNVERIFIED_XPUB', | ||
}} | ||
verifyProcess={verifyProcess} | ||
warningText="TR_XPUB_PHISHING_WARNING" | ||
/> | ||
); | ||
}; |
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
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
Oops, something went wrong.