mango-ui-v3/components/MarketSelect.tsx

71 lines
2.3 KiB
TypeScript
Raw Normal View History

import useMangoGroupConfig from '../hooks/useMangoGroupConfig'
2021-04-06 15:11:42 -07:00
import useMangoStore from '../stores/useMangoStore'
import { getMarketByBaseSymbolAndKind } from '@blockworks-foundation/mango-client'
2021-04-06 15:11:42 -07:00
const MarketSelect = () => {
const groupConfig = useMangoGroupConfig()
const selectedMarket = useMangoStore((s) => s.selectedMarket.config)
2021-04-06 15:11:42 -07:00
const setMangoStore = useMangoStore((s) => s.set)
const handleChange = (symbol, kind) => {
const newMarket = getMarketByBaseSymbolAndKind(groupConfig, symbol, kind)
2021-04-06 15:11:42 -07:00
setMangoStore((state) => {
state.selectedMarket.current = null
state.selectedMarket.config = newMarket
2021-04-06 15:11:42 -07:00
})
}
return (
<div className="bg-th-bkg-3 py-2">
<div className="flex justify-between items-center">
<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) => (
<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')}
key={s.key.toBase58()}
>
{s.name}
</div>
))}
2021-06-18 15:51:34 -07:00
{groupConfig.spotMarkets.map((s) => (
<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, 'spot')}
key={s.key.toBase58()}
>
{s.name}
</div>
))}
</div>
<div className="mr-10 text-xs">
<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-06-08 07:59:39 -07:00
Go to Mango V1
</a>
</div>
2021-04-12 09:20:17 -07:00
</div>
2021-04-06 15:11:42 -07:00
</div>
)
}
export default MarketSelect