Skip to content
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

Feature/#574 chart legend #763

Open
wants to merge 32 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0ffb783
curr price to legend && tooltip restyle
maria-vslvn Jul 6, 2021
ab14aa7
#723 orderbook chart layout
maria-vslvn Jul 6, 2021
1801ae2
confl resolved in own fixes
maria-vslvn Jul 6, 2021
e6832cd
curr price tooltip upd
maria-vslvn Jul 8, 2021
d451162
Merge branch 'develop' of https://github.com/gnosis/ido-ux into featu…
maria-vslvn Jul 11, 2021
db4d083
chart legend lbls added
maria-vslvn Jul 11, 2021
5be2d62
Merge branch 'develop' of github.com:gnosis/ido-ux into feature/#574-…
henrypalacios Jul 15, 2021
bfc0ac1
display the currentPrice in legend (#771)
henrypalacios Jul 19, 2021
155b078
Merge branch 'feature/#574-chart-legend' of https://github.com/gnosis…
Jul 20, 2021
57d2059
legend moved to top
Jul 20, 2021
78cba80
Merge branch 'develop' of https://github.com/gnosis/ido-ux into featu…
Jul 21, 2021
e98f8d8
chart legend position updated
Jul 21, 2021
9a0ec4f
Merge branch 'develop' of https://github.com/gnosis/ido-ux into featu…
Jul 26, 2021
eb84542
Merge branch 'develop' of https://github.com/gnosis/ido-ux into featu…
Jul 27, 2021
c168352
legend items customization
Jul 29, 2021
1803dc8
chart legend upd
Aug 6, 2021
c2f215a
upds
Aug 30, 2021
e63327d
Merge branch 'develop' of https://github.com/gnosis/ido-ux into featu…
Aug 30, 2021
a2f08d0
chart legend redraw
Aug 30, 2021
a2e1cd4
chart legend redraw
Aug 30, 2021
d64bd4b
tooltips fix
Aug 31, 2021
25dab57
yarn to fix pr bot link
Sep 1, 2021
d8e81f9
yarn to fix pr bot link
Sep 1, 2021
ff96ef4
fix eslint errs
Sep 1, 2021
e658c0b
fix eslint errs for ReactGA
Sep 1, 2021
8b8c9e7
ios bug fic with regexes & lookbehind
Sep 7, 2021
2fb2fb5
ios bug fic with regexes & lookbehind
Sep 7, 2021
59b5cd9
ios bug fic with regexes & lookbehind
Sep 8, 2021
99b8890
linter fixes
Sep 8, 2021
c123937
lookbehind safari fix
Sep 8, 2021
8ad25c5
lookbehind safari fix
Sep 8, 2021
c02a6a8
regex fixed
Sep 8, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"homepage": ".",
"private": true,
"engines": {
"node": ">=4.4.7 <=14.16.4"
"node": ">=4.4.7 <=14.17.3"
},
"scripts": {
"start": "react-scripts start",
Expand Down Expand Up @@ -162,6 +162,8 @@
}
},
"jest": {
"transformIgnorePatterns": ["/node_modules/(?!@amcharts)"]
"transformIgnorePatterns": [
"/node_modules/(?!@amcharts)"
]
}
}
3 changes: 3 additions & 0 deletions src/assets/images/bidsLegendItem.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/images/currPriceLegendItem.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/images/newOrderLegendItem.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/images/sellSupplyLegendItem.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/components/auction/AuctionBody/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import OrdersTable from '../OrdersTable'
const Grid = styled.div`
display: flex;
flex-direction: column;
margin: 0 0 40px;

@media (min-width: ${({ theme }) => theme.themeBreakPoints.xxl}) {
display: grid;
Expand All @@ -28,6 +27,7 @@ const GridCol = styled.div`
flex-direction: column;
max-width: 100%;
justify-content: flex-end;
margin: 0 0 40px;
@media (max-width: ${({ theme }) => theme.themeBreakPoints.xxl}) {
overflow-x: auto;
}
Expand Down
6 changes: 2 additions & 4 deletions src/components/auction/AuctionDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,8 @@ const AuctionDetails = (props: Props) => {
const { auctionDetails } = useAuctionDetails(auctionIdentifier)

const { showPriceInverted } = useOrderPlacementState()
const {
orderbookPrice: auctionCurrentPrice,
orderbookPriceReversed: auctionPriceReversed,
} = useOrderbookState()
const { orderbookPrice: auctionCurrentPrice, orderbookPriceReversed: auctionPriceReversed } =
useOrderbookState()
const { onInvertPrices } = useSwapActionHandlers()

// Start with inverted prices, if orderbook is also show inverted,
Expand Down
93 changes: 72 additions & 21 deletions src/components/auction/Charts/XYChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import * as am4core from '@amcharts/amcharts4/core'
import am4themesSpiritedaway from '@amcharts/amcharts4/themes/spiritedaway'
import { Decimal } from 'decimal.js'

import bidsPic from '../../../assets/images/bidsLegendItem.svg'
import currPricePic from '../../../assets/images/currPriceLegendItem.svg'
import newOrderPic from '../../../assets/images/newOrderLegendItem.svg'
import sellSupplyPic from '../../../assets/images/sellSupplyLegendItem.svg'
import { ChainId, getTokenDisplay } from '../../../utils'

// Recalculates very big and very small numbers by reducing their length according to rules and applying suffix/prefix.
const numberFormatter = new am4core.NumberFormatter()
numberFormatter.numberFormat = '###.00 a'
Expand Down Expand Up @@ -34,7 +37,7 @@ export const XYChart = (props: XYChartProps): am4charts.XYChart => {

chart.paddingTop = 20
chart.marginTop = 20
chart.paddingBottom = 0
chart.paddingBottom = 20
chart.paddingLeft = 0
chart.paddingRight = 0
chart.marginBottom = 0
Expand All @@ -46,10 +49,37 @@ export const XYChart = (props: XYChartProps): am4charts.XYChart => {
white: '#FFFFFF',
grey: '#565A69',
orange: '#FF6347',
tooltipBg: '#001429',
tooltipBorder: '#174172',
darkBlue: '#001429',
blue: '#174172',
}

// Legend
chart.legend = new am4charts.Legend()
chart.legend.position = 'bottom'
chart.legend.marginBottom = 15
chart.legend.marginTop = 10

chart.legend.useDefaultMarker = true
/* Remove square from marker template */
const marker = chart.legend.markers.template
marker.disposeChildren()
marker.width = 23
marker.height = 23

/* Add custom image instead */
const flag = marker.createChild(am4core.Image)
flag.width = 23
flag.height = 23
flag.verticalCenter = 'top'
flag.horizontalCenter = 'left'
flag.adapter.add('href', (href: any, target: any) => {
if (target.dataItem && target.dataItem.dataContext && target.dataItem.dataContext.dummyData) {
return target.dataItem.dataContext.dummyData.flag
} else {
return href
}
})

// Create axes
const priceAxis = chart.xAxes.push(new am4charts.ValueAxis())
const volumeAxis = chart.yAxes.push(new am4charts.ValueAxis())
Expand All @@ -76,55 +106,60 @@ export const XYChart = (props: XYChartProps): am4charts.XYChart => {
const bidSeries = chart.series.push(new am4charts.StepLineSeries())
bidSeries.dataFields.valueX = 'priceNumber'
bidSeries.dataFields.valueY = 'bidValueY'
bidSeries.strokeWidth = 1
bidSeries.name = 'Bids'
bidSeries.stroke = am4core.color(colors.green)
bidSeries.fill = bidSeries.stroke
bidSeries.startLocation = 0.5
bidSeries.fillOpacity = 0.1
bidSeries.dummyData = {
flag: bidsPic,
description:
'Shows the price (x axis) and size (y axis) of the bids that have been placed, both expressed in the bid token',
'Shows the price (x axis) and size (y axis)<br/> of the bids that have been placed,<br/> both expressed in the bid token',
}

// Create serie, red line, shows the minimum sell price (x axis) the auctioneer is willing to accept
const askSeries = chart.series.push(new am4charts.LineSeries())
askSeries.dataFields.valueX = 'priceNumber'
askSeries.dataFields.valueY = 'askValueY'
askSeries.strokeWidth = 1
askSeries.name = 'Sell Supply'
askSeries.stroke = am4core.color(colors.red)
askSeries.fill = askSeries.stroke
askSeries.fillOpacity = 0.1
askSeries.dummyData = {
flag: sellSupplyPic,
description:
'Shows sell supply of the auction based on the price and nominated in the bidding token',
'Shows sell supply of the auction<br/> based on the price and nominated<br/> in the bidding token',
}

// New order to be placed
const inputSeries = chart.series.push(new am4charts.LineSeries())
inputSeries.dataFields.valueX = 'priceNumber'
inputSeries.dataFields.valueY = 'newOrderValueY'
inputSeries.strokeWidth = 1
inputSeries.name = 'New orders'
inputSeries.stroke = am4core.color(colors.orange)
inputSeries.fill = inputSeries.stroke
inputSeries.fillOpacity = 0.1
inputSeries.dummyData = {
flag: newOrderPic,
description:
'Shows the new order that would be placed based on the current amount and price input',
'Shows the new order<br/> that would be placed based<br/> on the current amount and price input',
}

// Dotted white line -> shows the Current price, which is the closing price of the auction if
// no more bids are submitted or cancelled and the auction ends
const currPriceMockVal = '4.05 DAI'
const priceSeries = chart.series.push(new am4charts.LineSeries())
priceSeries.dataFields.valueX = 'priceNumber'
priceSeries.dataFields.valueY = 'clearingPriceValueY'
priceSeries.name = 'Current price'
priceSeries.strokeWidth = 2
priceSeries.strokeDasharray = '3,3'
priceSeries.stroke = am4core.color(colors.white)
priceSeries.fill = inputSeries.stroke
priceSeries.fillOpacity = 0.1
priceSeries.dummyData = {
description:
'Shows the current price. This price would be the closing price of the auction if no more bids are submitted or cancelled',
flag: currPricePic,
description: `Shows the current price: <strong style="font-size:14px;">[${currPriceMockVal}]</strong> <br/>This price would be<br/> the closing price of the auction<br/> if no more bids are submitted or cancelled`,
}

// Add cursor
Expand All @@ -147,15 +182,12 @@ export const XYChart = (props: XYChartProps): am4charts.XYChart => {
chart.zoomOutButton.icon.strokeWidth = 2
chart.zoomOutButton.tooltip.text = 'Zoom out'

// Legend
chart.legend = new am4charts.Legend()
chart.legend.labels.template.fill = am4core.color(colors.white)
chart.tooltip.getFillFromObject = false
chart.tooltip.background.fill = am4core.color(colors.tooltipBg)
chart.tooltip.background.stroke = am4core.color(colors.tooltipBorder)
chart.legend.itemContainers.template.tooltipHTML =
'<div style="white-space: normal!important;max-width: 300px;padding:0 5px 5px;">{dataContext.dummyData.description}</div>'

'<div>{dataContext.dummyData.description}</div>'
chart.tooltip.getFillFromObject = false
chart.tooltip.background.stroke = am4core.color(colors.blue)
chart.tooltip.background.fill = am4core.color(colors.darkBlue)
return chart
}

Expand All @@ -164,6 +196,7 @@ interface DrawInformation {
baseToken: Token
quoteToken: Token
chainId: ChainId
textAuctionCurrentPrice: string
}

const formatNumberForChartTooltip = (n: number) => {
Expand All @@ -175,7 +208,7 @@ const formatNumberForChartTooltip = (n: number) => {
}

export const drawInformation = (props: DrawInformation) => {
const { baseToken, chainId, chart, quoteToken } = props
const { baseToken, chainId, chart, quoteToken, textAuctionCurrentPrice } = props
const baseTokenLabel = baseToken.symbol
const quoteTokenLabel = getTokenDisplay(quoteToken, chainId)
const market = quoteTokenLabel + '-' + baseTokenLabel
Expand All @@ -188,11 +221,29 @@ export const drawInformation = (props: DrawInformation) => {

xAxis.title.text = priceTitle
yAxis.title.text = volumeTitle
const renderCurrentPriceLegendText = (textToReplace: string) => {
const regex = '(?<=">)[^<\\/strong>]*'
const match = textToReplace.match(new RegExp(regex))
if (match) {
return textToReplace.replace(regex, textAuctionCurrentPrice)
}
return textToReplace
}

const {
values: [askPricesSeries, bidPricesSeries],
values: [askPricesSeries, bidPricesSeries, inputSeries, priceSeries],
} = chart.series

inputSeries.dummyData = {
flag: newOrderPic,
description: renderCurrentPriceLegendText(inputSeries.dummyData.description),
}

priceSeries.dummyData = {
flag: currPricePic,
description: renderCurrentPriceLegendText(priceSeries.dummyData.description),
}

askPricesSeries.adapter.add('tooltipText', (text, target) => {
const valueX = target?.tooltipDataItem?.values?.valueX?.value ?? 0
const valueY = target?.tooltipDataItem?.values?.valueY?.value ?? 0
Expand Down
16 changes: 8 additions & 8 deletions src/components/auction/Claimer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ const Claimer: React.FC<Props> = (props) => {
setUserConfirmedTx(false)
})

const biddingTokenDisplay = useMemo(() => getTokenDisplay(biddingToken, chainId), [
biddingToken,
chainId,
])
const biddingTokenDisplay = useMemo(
() => getTokenDisplay(biddingToken, chainId),
[biddingToken, chainId],
)

const biddingTokenDisplayWrapped = useMemo(
() =>
Expand All @@ -137,10 +137,10 @@ const Claimer: React.FC<Props> = (props) => {
[biddingTokenDisplay],
)

const auctioningTokenDisplay = useMemo(() => getTokenDisplay(auctioningToken, chainId), [
auctioningToken,
chainId,
])
const auctioningTokenDisplay = useMemo(
() => getTokenDisplay(auctioningToken, chainId),
[auctioningToken, chainId],
)

const isLoading = useMemo(
() =>
Expand Down
37 changes: 20 additions & 17 deletions src/components/auction/OrderPlacement/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,15 @@ const OrderPlacement: React.FC<OrderPlacementProps> = (props) => {
const [pendingConfirmation, setPendingConfirmation] = useState<boolean>(true) // waiting for user confirmation
const [txHash, setTxHash] = useState<string>('')

const auctioningToken = React.useMemo(() => derivedAuctionInfo.auctioningToken, [
derivedAuctionInfo.auctioningToken,
])
const auctioningToken = React.useMemo(
() => derivedAuctionInfo.auctioningToken,
[derivedAuctionInfo.auctioningToken],
)

const biddingToken = React.useMemo(() => derivedAuctionInfo.biddingToken, [
derivedAuctionInfo.biddingToken,
])
const biddingToken = React.useMemo(
() => derivedAuctionInfo.biddingToken,
[derivedAuctionInfo.biddingToken],
)

const parsedBiddingAmount = tryParseAmount(sellAmount, biddingToken)
const approvalTokenAmount: TokenAmount | undefined = parsedBiddingAmount
Expand Down Expand Up @@ -222,14 +224,14 @@ const OrderPlacement: React.FC<OrderPlacementProps> = (props) => {
}

const pendingText = `Placing order`
const biddingTokenDisplay = useMemo(() => getTokenDisplay(biddingToken, chainId), [
biddingToken,
chainId,
])
const auctioningTokenDisplay = useMemo(() => getTokenDisplay(auctioningToken, chainId), [
auctioningToken,
chainId,
])
const biddingTokenDisplay = useMemo(
() => getTokenDisplay(biddingToken, chainId),
[biddingToken, chainId],
)
const auctioningTokenDisplay = useMemo(
() => getTokenDisplay(auctioningToken, chainId),
[auctioningToken, chainId],
)
const notApproved = approval === ApprovalState.NOT_APPROVED || approval === ApprovalState.PENDING
const orderPlacingOnly = auctionState === AuctionState.ORDER_PLACING
const coversClearingPrice = (price: string | undefined, showPriceInverted: boolean): boolean => {
Expand Down Expand Up @@ -278,9 +280,10 @@ const OrderPlacement: React.FC<OrderPlacementProps> = (props) => {
[derivedAuctionInfo?.auctionEndDate, derivedAuctionInfo?.orderCancellationEndDate],
)

const isPrivate = React.useMemo(() => auctionDetails && auctionDetails.isPrivateAuction, [
auctionDetails,
])
const isPrivate = React.useMemo(
() => auctionDetails && auctionDetails.isPrivateAuction,
[auctionDetails],
)
const signatureAvailable = React.useMemo(() => signature && signature.length > 10, [signature])

const onMaxInput = React.useCallback(() => {
Expand Down
1 change: 1 addition & 0 deletions src/components/auction/Orderbook/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const Wrapper = styled(BaseCard)`
height: 100%;
min-height: 352px;
min-width: 100%;
padding-bottom: 0;
`
interface OrderbookProps {
derivedAuctionInfo: DerivedAuctionInfo
Expand Down
Loading