-
Notifications
You must be signed in to change notification settings - Fork 170
Expand file tree
/
Copy pathReceiverPanelHeader.container.tsx
More file actions
84 lines (76 loc) · 2.87 KB
/
ReceiverPanelHeader.container.tsx
File metadata and controls
84 lines (76 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { useAtomValue } from 'jotai'
import { ReactElement, ReactNode } from 'react'
import QR_CODE_ICON from '@cowprotocol/assets/cow-swap/qr-code.svg'
import { TargetChainId } from '@cowprotocol/cow-sdk'
import { Trans, useLingui } from '@lingui/react/macro'
import SVG from 'react-inlinesvg'
import { useReceiverActions } from './hooks/useReceiverActions'
import { useReceiverChainInfo } from './hooks/useReceiverChainInfo'
import { useReceiverValidation } from './hooks/useReceiverValidation'
import { QrScanModal } from './QrScanModal.modal'
import {
ActionBtn,
ActionExternalLink,
ChainIconImg,
ChainLabelGroup,
ChainNameLabel,
QrIconWrapper,
ReceiverActions,
ReceiverHeader,
} from './styled'
import { featureFlagsAtom } from '../../state/featureFlagsState'
export interface ReceiverPanelHeaderProps {
onChange(value: string): void
value: string
targetChainId?: TargetChainId
label?: ReactNode
}
export function ReceiverPanelHeader({ onChange, value, targetChainId, label }: ReceiverPanelHeaderProps): ReactElement {
const { t } = useLingui()
const { chainIcon, chainInfo, isNonEvm } = useReceiverChainInfo(targetChainId)
const { isEmpty, isError, explorerUrl } = useReceiverValidation(value, targetChainId)
const { handlePaste, handleClear, handleScan, showQrModal, setShowQrModal, canPaste } = useReceiverActions(onChange)
const { isQrScanEnabled } = useAtomValue(featureFlagsAtom)
const networkName = chainInfo?.label
const chainLabel = t`Send to ${networkName} wallet`
const computedLabel = label || (isNonEvm ? chainLabel : <Trans>Recipient</Trans>)
const showScanPaste = isEmpty || isError
return (
<>
<ReceiverHeader>
<ChainLabelGroup>
{chainIcon && <ChainIconImg src={chainIcon} alt={chainInfo?.label} />}
<ChainNameLabel>{computedLabel}</ChainNameLabel>
</ChainLabelGroup>
<ReceiverActions>
{isQrScanEnabled && showScanPaste && (
<ActionBtn onClick={() => setShowQrModal(true)}>
<QrIconWrapper>
<SVG src={QR_CODE_ICON} width="14" height="14" />
</QrIconWrapper>
<Trans>Scan</Trans>
</ActionBtn>
)}
{showScanPaste && canPaste && (
<ActionBtn onClick={handlePaste}>
<Trans>Paste</Trans>
</ActionBtn>
)}
{!isEmpty && (
<ActionBtn onClick={handleClear}>
<Trans>Clear</Trans>
</ActionBtn>
)}
{explorerUrl && (
<ActionExternalLink href={explorerUrl} target="_blank" rel="noopener noreferrer">
<Trans>View ↗</Trans>
</ActionExternalLink>
)}
</ReceiverActions>
</ReceiverHeader>
{isQrScanEnabled && (
<QrScanModal isOpen={showQrModal} onDismiss={() => setShowQrModal(false)} onScan={handleScan} />
)}
</>
)
}