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
|
|
|
|
|
|
|
const MarketSelect = () => {
|
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
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2021-05-17 22:33:04 -07:00
|
|
|
<div className="bg-th-bkg-3 py-2">
|
2021-04-22 08:33:40 -07:00
|
|
|
<div className="flex justify-between items-center">
|
2021-05-17 22:33:04 -07:00
|
|
|
<div className="flex items-center px-4 md:px-10">
|
|
|
|
<div className="border-r border-th-fgd-4 pr-4 text-th-fgd-4 text-xs">
|
|
|
|
MARKETS
|
|
|
|
</div>
|
2021-06-18 15:53:24 -07:00
|
|
|
{groupConfig.perpMarkets.map((s) => (
|
2021-06-16 22:37:35 -07:00
|
|
|
<div
|
|
|
|
className={`border-r border-th-fgd-4 cursor-pointer default-transition flex font-semibold px-4 text-xs hover:text-th-primary
|
|
|
|
${
|
|
|
|
selectedMarket.name === s.name
|
|
|
|
? `text-th-primary`
|
|
|
|
: `text-th-fgd-3`
|
|
|
|
}
|
|
|
|
`}
|
2021-06-18 15:53:24 -07:00
|
|
|
onClick={() => handleChange(s.baseSymbol, 'perp')}
|
2021-06-18 15:57:13 -07:00
|
|
|
key={s.publicKey.toBase58()}
|
2021-06-16 22:37:35 -07:00
|
|
|
>
|
|
|
|
{s.name}
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
|
2021-06-18 15:51:34 -07:00
|
|
|
{groupConfig.spotMarkets.map((s) => (
|
2021-04-22 08:33:40 -07:00
|
|
|
<div
|
2021-05-17 22:33:04 -07:00
|
|
|
className={`border-r border-th-fgd-4 cursor-pointer default-transition flex font-semibold 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-18 15:53:24 -07:00
|
|
|
onClick={() => handleChange(s.baseSymbol, 'spot')}
|
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
|