2021-04-06 15:11:42 -07:00
|
|
|
import { useMemo } from 'react'
|
|
|
|
import useConnection from './useConnection'
|
|
|
|
import { PublicKey } from '@solana/web3.js'
|
|
|
|
import useMangoStore from '../stores/useMangoStore'
|
2021-06-16 18:50:16 -07:00
|
|
|
// import { IDS } from '@blockworks-foundation/mango-client'
|
2021-04-06 15:11:42 -07:00
|
|
|
|
User account page (#22)
* layout, overview, start on assets, borrows and open orders
* trade history, sortable data hook for tables, borrow page
* handle deposit and withdraw buttons
* borrow modal ui and integration + settle borrow for individual assets
* in orders balance to asset table and totals, responsive css, new connected wallet button + small tweaks
* account switch/creation flow
* accounts modal, update to usebalances hook
* handle settle, deposit before settle, save last account
* disable borrow/withdraw button when no account
2021-06-05 07:11:44 -07:00
|
|
|
export const formatTokenMints = (symbols: { [name: string]: string }) => {
|
2021-04-06 15:11:42 -07:00
|
|
|
return Object.entries(symbols).map(([name, address]) => {
|
|
|
|
return {
|
|
|
|
address: new PublicKey(address),
|
|
|
|
name: name,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const useMarket = () => {
|
2021-04-29 07:38:28 -07:00
|
|
|
const market = useMangoStore((state) => state.selectedMarket.current)
|
2021-08-17 13:51:02 -07:00
|
|
|
const selectedMarketName = useMangoStore(
|
|
|
|
(state) => state.selectedMarket.config.name
|
|
|
|
)
|
2021-06-16 18:50:16 -07:00
|
|
|
const { programId } = useConnection()
|
2021-04-06 15:11:42 -07:00
|
|
|
|
|
|
|
const marketAddress = useMemo(
|
|
|
|
() => (market ? market.publicKey.toString() : null),
|
|
|
|
[market]
|
|
|
|
)
|
|
|
|
|
2021-06-16 18:50:16 -07:00
|
|
|
// const TOKEN_MINTS = useMemo(
|
|
|
|
// () => formatTokenMints(IDS[cluster].symbols),
|
|
|
|
// [cluster]
|
|
|
|
// )
|
|
|
|
|
|
|
|
// const baseCurrency = useMemo(
|
|
|
|
// () =>
|
|
|
|
// (market?.baseMintAddress &&
|
|
|
|
// TOKEN_MINTS.find((token) =>
|
|
|
|
// token.address.equals(market.baseMintAddress)
|
|
|
|
// )?.name) ||
|
|
|
|
// '...',
|
|
|
|
// [market, TOKEN_MINTS]
|
|
|
|
// )
|
|
|
|
|
|
|
|
// const quoteCurrency = useMemo(
|
|
|
|
// () =>
|
|
|
|
// (market?.quoteMintAddress &&
|
|
|
|
// TOKEN_MINTS.find((token) =>
|
|
|
|
// token.address.equals(market.quoteMintAddress)
|
|
|
|
// )?.name) ||
|
|
|
|
// '...',
|
|
|
|
// [market, TOKEN_MINTS]
|
|
|
|
// )
|
2021-04-06 15:11:42 -07:00
|
|
|
|
|
|
|
return {
|
|
|
|
market,
|
|
|
|
marketAddress,
|
|
|
|
programId,
|
2021-04-29 07:38:28 -07:00
|
|
|
marketName: selectedMarketName,
|
2021-06-16 18:50:16 -07:00
|
|
|
// baseCurrency,
|
|
|
|
// quoteCurrency,
|
2021-04-06 15:11:42 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default useMarket
|