2021-06-23 06:16:37 -07:00
|
|
|
import { useState } from 'react'
|
|
|
|
import styled from '@emotion/styled'
|
|
|
|
import { RadioGroup } from '@headlessui/react'
|
2021-07-01 07:12:42 -07:00
|
|
|
// import useLocalStorageState from '../hooks/useLocalStorageState'
|
2021-06-18 15:38:09 -07:00
|
|
|
import useMangoGroupConfig from '../hooks/useMangoGroupConfig'
|
2021-04-06 15:11:42 -07:00
|
|
|
import useMangoStore from '../stores/useMangoStore'
|
2021-06-16 22:37:35 -07:00
|
|
|
import { getMarketByBaseSymbolAndKind } from '@blockworks-foundation/mango-client'
|
2021-04-06 15:11:42 -07:00
|
|
|
|
2021-06-23 06:16:37 -07:00
|
|
|
const StyledMarketTypeToggleWrapper = styled.div`
|
|
|
|
background: rgba(255, 255, 255, 0.12);
|
|
|
|
`
|
|
|
|
|
|
|
|
const StyledArrow = styled.div`
|
|
|
|
width: 0;
|
|
|
|
height: 0;
|
|
|
|
border-top: 20px solid transparent;
|
|
|
|
border-bottom: 20px solid transparent;
|
|
|
|
border-left: 20px solid rgba(255, 255, 255, 0.12);
|
|
|
|
`
|
|
|
|
|
2021-04-06 15:11:42 -07:00
|
|
|
const MarketSelect = () => {
|
2021-06-23 06:16:37 -07:00
|
|
|
// const [lastViewedMarket, setLastViewedMarket] = useLocalStorageState(
|
|
|
|
// 'lastViewedMarket',
|
|
|
|
// { baseSymbol: 'BTC', kind: 'spot' }
|
|
|
|
// )
|
|
|
|
const [marketType, setMarketType] = useState('spot')
|
2021-06-18 15:38:09 -07:00
|
|
|
const groupConfig = useMangoGroupConfig()
|
2021-06-16 22:37:35 -07:00
|
|
|
const selectedMarket = useMangoStore((s) => s.selectedMarket.config)
|
2021-04-06 15:11:42 -07:00
|
|
|
const setMangoStore = useMangoStore((s) => s.set)
|
|
|
|
|
2021-06-16 22:37:35 -07:00
|
|
|
const handleChange = (symbol, kind) => {
|
2021-06-18 15:38:09 -07:00
|
|
|
const newMarket = getMarketByBaseSymbolAndKind(groupConfig, symbol, kind)
|
2021-04-06 15:11:42 -07:00
|
|
|
setMangoStore((state) => {
|
2021-06-16 22:37:35 -07:00
|
|
|
state.selectedMarket.current = null
|
|
|
|
state.selectedMarket.config = newMarket
|
2021-04-06 15:11:42 -07:00
|
|
|
})
|
2021-06-23 06:16:37 -07:00
|
|
|
// setLastViewedMarket({ baseSymbol: symbol, kind: kind })
|
2021-04-06 15:11:42 -07:00
|
|
|
}
|
|
|
|
|
2021-06-23 06:16:37 -07:00
|
|
|
const markets =
|
|
|
|
marketType === 'perp' ? groupConfig.perpMarkets : groupConfig.spotMarkets
|
2021-06-16 22:37:35 -07:00
|
|
|
|
2021-06-23 06:16:37 -07:00
|
|
|
return (
|
|
|
|
<div className="bg-th-bkg-3 flex h-10">
|
|
|
|
<StyledMarketTypeToggleWrapper className="flex items-center pl-6 md:pl-9 pr-1">
|
|
|
|
<RadioGroup
|
|
|
|
value={marketType}
|
|
|
|
onChange={(t) => setMarketType(t)}
|
|
|
|
className="flex font-bold rounded-md text-xs w-30"
|
|
|
|
>
|
|
|
|
<RadioGroup.Option value="spot" className="flex-1 focus:outline-none">
|
|
|
|
{({ checked }) => (
|
|
|
|
<button
|
|
|
|
className={`${
|
|
|
|
checked
|
|
|
|
? 'bg-th-primary text-th-bkg-1'
|
|
|
|
: 'bg-th-bkg-2 hover:bg-th-bkg-1'
|
|
|
|
} rounded-r-none text-th-fgd-3 text-center py-1 px-2.5 h-full w-full focus:outline-none`}
|
|
|
|
>
|
|
|
|
Spot
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
</RadioGroup.Option>
|
|
|
|
<RadioGroup.Option value="perp" className="flex-1 focus:outline-none">
|
|
|
|
{({ checked }) => (
|
|
|
|
<button
|
|
|
|
className={`${
|
|
|
|
checked
|
|
|
|
? 'bg-th-primary text-th-bkg-1'
|
|
|
|
: 'bg-th-bkg-2 hover:bg-th-bkg-1'
|
|
|
|
} rounded-l-none text-th-fgd-3 text-center py-1 px-2.5 h-full w-full focus:outline-none`}
|
|
|
|
>
|
|
|
|
Perp
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
</RadioGroup.Option>
|
|
|
|
</RadioGroup>
|
|
|
|
</StyledMarketTypeToggleWrapper>
|
|
|
|
<StyledArrow />
|
|
|
|
<div className="flex items-center justify-between w-full">
|
|
|
|
<div className="flex items-center">
|
|
|
|
{markets.map((s) => (
|
2021-04-22 08:33:40 -07:00
|
|
|
<div
|
2021-06-23 06:16:37 -07:00
|
|
|
className={`cursor-pointer default-transition flex font-bold px-4 text-xs hover:text-th-primary
|
2021-04-12 09:49:02 -07:00
|
|
|
${
|
2021-06-16 22:37:35 -07:00
|
|
|
selectedMarket.name === s.name
|
2021-04-12 13:01:55 -07:00
|
|
|
? `text-th-primary`
|
2021-05-17 22:33:04 -07:00
|
|
|
: `text-th-fgd-3`
|
2021-04-12 09:49:02 -07:00
|
|
|
}
|
|
|
|
`}
|
2021-06-23 06:16:37 -07:00
|
|
|
onClick={() => handleChange(s.baseSymbol, marketType)}
|
2021-06-18 15:57:13 -07:00
|
|
|
key={s.publicKey.toBase58()}
|
2021-04-22 08:33:40 -07:00
|
|
|
>
|
2021-06-16 22:37:35 -07:00
|
|
|
{s.name}
|
2021-04-22 08:33:40 -07:00
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
2021-05-07 12:41:26 -07:00
|
|
|
<div className="mr-10 text-xs">
|
2021-04-24 15:02:13 -07:00
|
|
|
<a
|
2021-06-08 08:04:56 -07:00
|
|
|
href="https://usdt.mango.markets"
|
2021-06-08 07:59:39 -07:00
|
|
|
className="text-primary default-transition underline hover:text-th-primary hover:no-underline border-1"
|
2021-04-24 15:02:13 -07:00
|
|
|
>
|
2021-06-08 07:59:39 -07:00
|
|
|
Go to Mango V1
|
2021-04-22 08:33:40 -07:00
|
|
|
</a>
|
|
|
|
</div>
|
2021-04-12 09:20:17 -07:00
|
|
|
</div>
|
2021-04-06 15:11:42 -07:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default MarketSelect
|