-
Notifications
You must be signed in to change notification settings - Fork 142
Expand file tree
/
Copy pathLegend.tsx
More file actions
94 lines (88 loc) · 2.85 KB
/
Copy pathLegend.tsx
File metadata and controls
94 lines (88 loc) · 2.85 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
85
86
87
88
89
90
91
92
93
94
import { useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useWindowSize } from 'usehooks-ts'
import { useQuery } from 'react-query'
import {
TransactionAction,
TransactionCategory,
} from '../shared/components/Transaction/types'
import { useLocalStorage } from '../shared/hooks'
import { TransactionActionIcon } from '../shared/components/TransactionActionIcon/TransactionActionIcon'
import './css/legend.scss'
export const LEGEND_STORAGE_KEY = 'explorer-legend-previous-interaction'
export const Legend = () => {
const { t } = useTranslation()
const windowSize = useWindowSize()
const [previousInteraction, setPreviousInteraction] =
useLocalStorage<boolean>(LEGEND_STORAGE_KEY, false)
const [hidden, setHidden] = useState(previousInteraction)
// Show legend by default when on desktop sizes
useQuery(['legend-visibility', windowSize.width, previousInteraction], () => {
if (previousInteraction === false) {
setHidden(!(windowSize.width > 900))
}
return null
})
const actions = [
TransactionAction.CREATE,
TransactionAction.MODIFY,
TransactionAction.FINISH,
TransactionAction.CANCEL,
TransactionAction.SEND,
]
const categories = [
TransactionCategory.PAYMENT,
TransactionCategory.DEX,
TransactionCategory.NFT,
TransactionCategory.ACCOUNT,
TransactionCategory.PSEUDO,
TransactionCategory.UNKNOWN,
]
return (
<div className="legend">
{!hidden && (
<>
<div className="legend-heading">Shapes Legend</div>
<div className="legend-section">
{actions.map((action) => (
<div className="legend-item" key={action}>
<TransactionActionIcon action={action} />{' '}
{t(`transaction_action`, {
context: action,
defaultValue: TransactionAction.UNKNOWN,
})}
</div>
))}
</div>
<div className="legend-heading">Colors Legend</div>
<div className="legend-section">
{categories.map((category: string) => (
<div
className={`legend-item tx-category-${category}`}
key={category}
>
<div className="legend-category" />{' '}
{t(`transaction_category`, {
context: category,
defaultValue: TransactionCategory.UNKNOWN,
})}
</div>
))}
</div>
</>
)}
<button
className="btn btn-link legend-toggle"
type="button"
onClick={() => {
if (previousInteraction === false) {
setPreviousInteraction(true)
}
setHidden(!hidden)
}}
>
{t(`transaction_legend_toggle_${hidden ? 'show' : 'hide'}`)}
</button>
</div>
)
}