fixed wallet adapter type issues
This commit is contained in:
parent
1b7c251870
commit
99664f97e9
|
@ -27,7 +27,7 @@ const AccountNameModal: FunctionComponent<AccountNameModalProps> = ({
|
|||
}) => {
|
||||
const [name, setName] = useState(accountName || '')
|
||||
const [invalidNameMessage, setInvalidNameMessage] = useState('')
|
||||
const wallet = useMangoStore.getState().wallet.current
|
||||
const wallet = useMangoStore.getState().wallet.current as any
|
||||
const selectedMangoGroup = useMangoStore((s) => s.selectedMangoGroup.current)
|
||||
const selectedMarginAccount = useMangoStore(
|
||||
(s) => s.selectedMarginAccount.current
|
||||
|
|
|
@ -21,7 +21,7 @@ const BalancesTable = () => {
|
|||
)
|
||||
const marginAccount = useMangoStore.getState().selectedMarginAccount.current
|
||||
const mangoGroup = useMangoStore.getState().selectedMangoGroup.current
|
||||
const wallet = useMangoStore.getState().wallet.current
|
||||
const wallet = useMangoStore.getState().wallet.current as any
|
||||
|
||||
try {
|
||||
await settleAll(
|
||||
|
|
|
@ -145,7 +145,7 @@ const BorrowModal: FunctionComponent<BorrowModalProps> = ({
|
|||
setSubmitting(true)
|
||||
const marginAccount = useMangoStore.getState().selectedMarginAccount.current
|
||||
const mangoGroup = useMangoStore.getState().selectedMangoGroup.current
|
||||
const wallet = useMangoStore.getState().wallet.current
|
||||
const wallet = useMangoStore.getState().wallet.current as any
|
||||
if (!marginAccount || !mangoGroup) return
|
||||
|
||||
borrowAndWithdraw(
|
||||
|
|
|
@ -176,7 +176,7 @@ const DepositModal: FunctionComponent<DepositModalProps> = ({
|
|||
setSubmitting(true)
|
||||
const marginAccount = useMangoStore.getState().selectedMarginAccount.current
|
||||
const mangoGroup = useMangoStore.getState().selectedMangoGroup.current
|
||||
const wallet = useMangoStore.getState().wallet.current
|
||||
const wallet = useMangoStore.getState().wallet.current as any
|
||||
|
||||
if (!marginAccount && mangoGroup) {
|
||||
initMarginAccountAndDeposit(
|
||||
|
|
|
@ -10,196 +10,190 @@ interface DepositWithdrawHistoryTableProps {
|
|||
type: 'deposits' | 'withdrawals'
|
||||
}
|
||||
|
||||
const DepositWithdrawHistoryTable: FunctionComponent<DepositWithdrawHistoryTableProps> =
|
||||
({ type }) => {
|
||||
const depositHistory = useMangoStore((s) => s.depositHistory)
|
||||
const withdrawalHistory = useMangoStore((s) => s.withdrawalHistory)
|
||||
const history = type === 'deposits' ? depositHistory : withdrawalHistory
|
||||
const DepositWithdrawHistoryTable: FunctionComponent<
|
||||
DepositWithdrawHistoryTableProps
|
||||
> = ({ type }) => {
|
||||
const depositHistory = useMangoStore((s) => s.depositHistory)
|
||||
const withdrawalHistory = useMangoStore((s) => s.withdrawalHistory)
|
||||
const history = type === 'deposits' ? depositHistory : withdrawalHistory
|
||||
|
||||
const { items, requestSort, sortConfig } = useSortableData(history)
|
||||
|
||||
const renderTransactionTime = (timestamp) => {
|
||||
const date = new Date(timestamp)
|
||||
return (
|
||||
<>
|
||||
<div>{date.toLocaleDateString()}</div>
|
||||
<div className="text-xs text-th-fgd-3">
|
||||
{date.toLocaleTimeString()}
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
const { items, requestSort, sortConfig } = useSortableData(history)
|
||||
|
||||
const renderTransactionTime = (timestamp) => {
|
||||
const date = new Date(timestamp)
|
||||
return (
|
||||
<div className={`flex flex-col py-4`}>
|
||||
<div className={`-my-2 overflow-x-auto sm:-mx-6 lg:-mx-8`}>
|
||||
<div
|
||||
className={`align-middle inline-block min-w-full sm:px-6 lg:px-8`}
|
||||
>
|
||||
{history.length > 0 ? (
|
||||
<div
|
||||
className={`overflow-hidden border-b border-th-bkg-2 sm:rounded-md`}
|
||||
>
|
||||
<Table className={`min-w-full divide-y divide-th-bkg-2`}>
|
||||
<Thead>
|
||||
<Tr className="text-th-fgd-3 text-xs">
|
||||
<Th
|
||||
scope="col"
|
||||
className={`px-6 py-3 text-left font-normal`}
|
||||
>
|
||||
<LinkButton
|
||||
className="flex items-center no-underline"
|
||||
onClick={() => requestSort('block_time')}
|
||||
>
|
||||
Date/Time
|
||||
<ArrowSmDownIcon
|
||||
className={`default-transition flex-shrink-0 h-4 w-4 ml-1 ${
|
||||
sortConfig?.key === 'block_time'
|
||||
? sortConfig.direction === 'ascending'
|
||||
? 'transform rotate-180'
|
||||
: 'transform rotate-360'
|
||||
: null
|
||||
}`}
|
||||
/>
|
||||
</LinkButton>
|
||||
</Th>
|
||||
<Th
|
||||
scope="col"
|
||||
className={`px-6 py-3 text-left font-normal`}
|
||||
>
|
||||
<LinkButton
|
||||
className="flex items-center no-underline"
|
||||
onClick={() => requestSort('symbol')}
|
||||
>
|
||||
Asset
|
||||
<ArrowSmDownIcon
|
||||
className={`default-transition flex-shrink-0 h-4 w-4 ml-1 ${
|
||||
sortConfig?.key === 'symbol'
|
||||
? sortConfig.direction === 'ascending'
|
||||
? 'transform rotate-180'
|
||||
: 'transform rotate-360'
|
||||
: null
|
||||
}`}
|
||||
/>
|
||||
</LinkButton>
|
||||
</Th>
|
||||
<Th
|
||||
scope="col"
|
||||
className={`px-6 py-3 text-left font-normal`}
|
||||
>
|
||||
<LinkButton
|
||||
className="flex items-center no-underline"
|
||||
onClick={() => requestSort('quantity')}
|
||||
>
|
||||
Quantity
|
||||
<ArrowSmDownIcon
|
||||
className={`default-transition flex-shrink-0 h-4 w-4 ml-1 ${
|
||||
sortConfig?.key === 'quantity'
|
||||
? sortConfig.direction === 'ascending'
|
||||
? 'transform rotate-180'
|
||||
: 'transform rotate-360'
|
||||
: null
|
||||
}`}
|
||||
/>
|
||||
</LinkButton>
|
||||
</Th>
|
||||
<Th
|
||||
scope="col"
|
||||
className={`px-6 py-3 text-left font-normal`}
|
||||
>
|
||||
<LinkButton
|
||||
className="flex items-center no-underline"
|
||||
onClick={() => requestSort('usd_equivalent')}
|
||||
>
|
||||
Value
|
||||
<ArrowSmDownIcon
|
||||
className={`default-transition flex-shrink-0 h-4 w-4 ml-1 ${
|
||||
sortConfig?.key === 'usd_equivalent'
|
||||
? sortConfig.direction === 'ascending'
|
||||
? 'transform rotate-180'
|
||||
: 'transform rotate-360'
|
||||
: null
|
||||
}`}
|
||||
/>
|
||||
</LinkButton>
|
||||
</Th>
|
||||
</Tr>
|
||||
</Thead>
|
||||
<Tbody>
|
||||
{items.map((transaction, index) => (
|
||||
<Tr
|
||||
key={`${index}`}
|
||||
className={`border-b border-th-bkg-3
|
||||
${index % 2 === 0 ? `bg-th-bkg-3` : `bg-th-bkg-2`}
|
||||
`}
|
||||
>
|
||||
<Td
|
||||
className={`px-6 py-3 whitespace-nowrap text-sm text-th-fgd-1`}
|
||||
>
|
||||
{renderTransactionTime(transaction.block_datetime)}
|
||||
</Td>
|
||||
<Td
|
||||
className={`px-6 py-3 whitespace-nowrap text-sm text-th-fgd-1`}
|
||||
>
|
||||
<div className="flex items-center">
|
||||
<img
|
||||
alt=""
|
||||
width="20"
|
||||
height="20"
|
||||
src={`/assets/icons/${transaction.symbol.toLowerCase()}.svg`}
|
||||
className={`mr-2.5`}
|
||||
/>
|
||||
<div>{transaction.symbol}</div>
|
||||
</div>
|
||||
</Td>
|
||||
<Td
|
||||
className={`px-6 py-3 whitespace-nowrap text-sm text-th-fgd-1`}
|
||||
>
|
||||
{transaction.quantity.toLocaleString(undefined, {
|
||||
maximumFractionDigits:
|
||||
tokenPrecision[transaction.symbol],
|
||||
})}
|
||||
</Td>
|
||||
<Td
|
||||
className={`px-6 py-3 whitespace-nowrap text-sm text-th-fgd-1`}
|
||||
>
|
||||
$
|
||||
{transaction.usd_equivalent.toLocaleString(
|
||||
undefined,
|
||||
{
|
||||
maximumFractionDigits: 2,
|
||||
}
|
||||
)}
|
||||
</Td>
|
||||
<Td
|
||||
className={`px-6 py-3 whitespace-nowrap text-sm text-th-fgd-1`}
|
||||
>
|
||||
<a
|
||||
className="default-transition flex items-center justify-end text-th-fgd-2"
|
||||
href={`https://explorer.solana.com/tx/${transaction.signature}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<span>View Transaction</span>
|
||||
<ExternalLinkIcon className={`h-4 w-4 ml-1.5`} />
|
||||
</a>
|
||||
</Td>
|
||||
</Tr>
|
||||
))}
|
||||
</Tbody>
|
||||
</Table>
|
||||
</div>
|
||||
) : (
|
||||
<div
|
||||
className={`w-full text-center py-6 bg-th-bkg-1 text-th-fgd-3 rounded-md`}
|
||||
>
|
||||
{type === 'deposits' ? 'No deposits' : 'No withdrawals'}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<>
|
||||
<div>{date.toLocaleDateString()}</div>
|
||||
<div className="text-xs text-th-fgd-3">{date.toLocaleTimeString()}</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={`flex flex-col py-4`}>
|
||||
<div className={`-my-2 overflow-x-auto sm:-mx-6 lg:-mx-8`}>
|
||||
<div className={`align-middle inline-block min-w-full sm:px-6 lg:px-8`}>
|
||||
{history.length > 0 ? (
|
||||
<div
|
||||
className={`overflow-hidden border-b border-th-bkg-2 sm:rounded-md`}
|
||||
>
|
||||
<Table className={`min-w-full divide-y divide-th-bkg-2`}>
|
||||
<Thead>
|
||||
<Tr className="text-th-fgd-3 text-xs">
|
||||
<Th
|
||||
scope="col"
|
||||
className={`px-6 py-3 text-left font-normal`}
|
||||
>
|
||||
<LinkButton
|
||||
className="flex items-center no-underline"
|
||||
onClick={() => requestSort('block_time')}
|
||||
>
|
||||
Date/Time
|
||||
<ArrowSmDownIcon
|
||||
className={`default-transition flex-shrink-0 h-4 w-4 ml-1 ${
|
||||
sortConfig?.key === 'block_time'
|
||||
? sortConfig.direction === 'ascending'
|
||||
? 'transform rotate-180'
|
||||
: 'transform rotate-360'
|
||||
: null
|
||||
}`}
|
||||
/>
|
||||
</LinkButton>
|
||||
</Th>
|
||||
<Th
|
||||
scope="col"
|
||||
className={`px-6 py-3 text-left font-normal`}
|
||||
>
|
||||
<LinkButton
|
||||
className="flex items-center no-underline"
|
||||
onClick={() => requestSort('symbol')}
|
||||
>
|
||||
Asset
|
||||
<ArrowSmDownIcon
|
||||
className={`default-transition flex-shrink-0 h-4 w-4 ml-1 ${
|
||||
sortConfig?.key === 'symbol'
|
||||
? sortConfig.direction === 'ascending'
|
||||
? 'transform rotate-180'
|
||||
: 'transform rotate-360'
|
||||
: null
|
||||
}`}
|
||||
/>
|
||||
</LinkButton>
|
||||
</Th>
|
||||
<Th
|
||||
scope="col"
|
||||
className={`px-6 py-3 text-left font-normal`}
|
||||
>
|
||||
<LinkButton
|
||||
className="flex items-center no-underline"
|
||||
onClick={() => requestSort('quantity')}
|
||||
>
|
||||
Quantity
|
||||
<ArrowSmDownIcon
|
||||
className={`default-transition flex-shrink-0 h-4 w-4 ml-1 ${
|
||||
sortConfig?.key === 'quantity'
|
||||
? sortConfig.direction === 'ascending'
|
||||
? 'transform rotate-180'
|
||||
: 'transform rotate-360'
|
||||
: null
|
||||
}`}
|
||||
/>
|
||||
</LinkButton>
|
||||
</Th>
|
||||
<Th
|
||||
scope="col"
|
||||
className={`px-6 py-3 text-left font-normal`}
|
||||
>
|
||||
<LinkButton
|
||||
className="flex items-center no-underline"
|
||||
onClick={() => requestSort('usd_equivalent')}
|
||||
>
|
||||
Value
|
||||
<ArrowSmDownIcon
|
||||
className={`default-transition flex-shrink-0 h-4 w-4 ml-1 ${
|
||||
sortConfig?.key === 'usd_equivalent'
|
||||
? sortConfig.direction === 'ascending'
|
||||
? 'transform rotate-180'
|
||||
: 'transform rotate-360'
|
||||
: null
|
||||
}`}
|
||||
/>
|
||||
</LinkButton>
|
||||
</Th>
|
||||
</Tr>
|
||||
</Thead>
|
||||
<Tbody>
|
||||
{items.map((transaction, index) => (
|
||||
<Tr
|
||||
key={`${index}`}
|
||||
className={`border-b border-th-bkg-3
|
||||
${index % 2 === 0 ? `bg-th-bkg-3` : `bg-th-bkg-2`}
|
||||
`}
|
||||
>
|
||||
<Td
|
||||
className={`px-6 py-3 whitespace-nowrap text-sm text-th-fgd-1`}
|
||||
>
|
||||
{renderTransactionTime(transaction.block_datetime)}
|
||||
</Td>
|
||||
<Td
|
||||
className={`px-6 py-3 whitespace-nowrap text-sm text-th-fgd-1`}
|
||||
>
|
||||
<div className="flex items-center">
|
||||
<img
|
||||
alt=""
|
||||
width="20"
|
||||
height="20"
|
||||
src={`/assets/icons/${transaction.symbol.toLowerCase()}.svg`}
|
||||
className={`mr-2.5`}
|
||||
/>
|
||||
<div>{transaction.symbol}</div>
|
||||
</div>
|
||||
</Td>
|
||||
<Td
|
||||
className={`px-6 py-3 whitespace-nowrap text-sm text-th-fgd-1`}
|
||||
>
|
||||
{transaction.quantity.toLocaleString(undefined, {
|
||||
maximumFractionDigits:
|
||||
tokenPrecision[transaction.symbol],
|
||||
})}
|
||||
</Td>
|
||||
<Td
|
||||
className={`px-6 py-3 whitespace-nowrap text-sm text-th-fgd-1`}
|
||||
>
|
||||
$
|
||||
{transaction.usd_equivalent.toLocaleString(undefined, {
|
||||
maximumFractionDigits: 2,
|
||||
})}
|
||||
</Td>
|
||||
<Td
|
||||
className={`px-6 py-3 whitespace-nowrap text-sm text-th-fgd-1`}
|
||||
>
|
||||
<a
|
||||
className="default-transition flex items-center justify-end text-th-fgd-2"
|
||||
href={`https://explorer.solana.com/tx/${transaction.signature}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<span>View Transaction</span>
|
||||
<ExternalLinkIcon className={`h-4 w-4 ml-1.5`} />
|
||||
</a>
|
||||
</Td>
|
||||
</Tr>
|
||||
))}
|
||||
</Tbody>
|
||||
</Table>
|
||||
</div>
|
||||
) : (
|
||||
<div
|
||||
className={`w-full text-center py-6 bg-th-bkg-1 text-th-fgd-3 rounded-md`}
|
||||
>
|
||||
{type === 'deposits' ? 'No deposits' : 'No withdrawals'}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default DepositWithdrawHistoryTable
|
||||
|
|
|
@ -88,7 +88,7 @@ const NewAccount: FunctionComponent<NewAccountProps> = ({
|
|||
const handleNewAccountDeposit = () => {
|
||||
setSubmitting(true)
|
||||
const mangoGroup = useMangoStore.getState().selectedMangoGroup.current
|
||||
const wallet = useMangoStore.getState().wallet.current
|
||||
const wallet = useMangoStore.getState().wallet.current as any
|
||||
|
||||
initMarginAccountAndDeposit(
|
||||
connection,
|
||||
|
|
|
@ -23,7 +23,7 @@ const OpenOrdersTable = () => {
|
|||
const actions = useMangoStore((s) => s.actions)
|
||||
|
||||
const handleCancelOrder = async (order) => {
|
||||
const wallet = useMangoStore.getState().wallet.current
|
||||
const wallet = useMangoStore.getState().wallet.current as any
|
||||
const selectedMangoGroup =
|
||||
useMangoStore.getState().selectedMangoGroup.current
|
||||
const selectedMarginAccount =
|
||||
|
|
|
@ -200,7 +200,7 @@ export default function TradeForm() {
|
|||
|
||||
const marginAccount = useMangoStore.getState().selectedMarginAccount.current
|
||||
const mangoGroup = useMangoStore.getState().selectedMangoGroup.current
|
||||
const wallet = useMangoStore.getState().wallet.current
|
||||
const wallet = useMangoStore.getState().wallet.current as any
|
||||
|
||||
if (!mangoGroup || !marketAddress || !marginAccount || !market) return
|
||||
setSubmitting(true)
|
||||
|
|
|
@ -148,7 +148,7 @@ const WithdrawModal: FunctionComponent<WithdrawModalProps> = ({
|
|||
setSubmitting(true)
|
||||
const marginAccount = useMangoStore.getState().selectedMarginAccount.current
|
||||
const mangoGroup = useMangoStore.getState().selectedMangoGroup.current
|
||||
const wallet = useMangoStore.getState().wallet.current
|
||||
const wallet = useMangoStore.getState().wallet.current as any
|
||||
if (!marginAccount || !mangoGroup) return
|
||||
|
||||
if (!includeBorrow) {
|
||||
|
|
|
@ -13,6 +13,7 @@ import DepositModal from '../DepositModal'
|
|||
import WithdrawModal from '../WithdrawModal'
|
||||
import Button from '../Button'
|
||||
import Tooltip from '../Tooltip'
|
||||
import { Market } from '@project-serum/serum'
|
||||
|
||||
export default function AccountAssets() {
|
||||
const balances = useBalances()
|
||||
|
@ -53,12 +54,11 @@ export default function AccountAssets() {
|
|||
}
|
||||
|
||||
async function handleSettleAllTrades() {
|
||||
const markets = Object.values(
|
||||
useMangoStore.getState().selectedMangoGroup.markets
|
||||
)
|
||||
const marginAccount = useMangoStore.getState().selectedMarginAccount.current
|
||||
const mangoGroup = useMangoStore.getState().selectedMangoGroup.current
|
||||
const wallet = useMangoStore.getState().wallet.current
|
||||
const { selectedMangoGroup, selectedMarginAccount, wallet } =
|
||||
useMangoStore.getState() as any
|
||||
const markets = Object.values(selectedMangoGroup.markets) as Market[]
|
||||
const marginAccount = selectedMarginAccount.current
|
||||
const mangoGroup = selectedMangoGroup.current
|
||||
|
||||
try {
|
||||
await settleAllTrades(
|
||||
|
@ -67,7 +67,7 @@ export default function AccountAssets() {
|
|||
mangoGroup,
|
||||
marginAccount,
|
||||
markets,
|
||||
wallet
|
||||
wallet.current
|
||||
)
|
||||
await sleep(250)
|
||||
actions.fetchMarginAccounts()
|
||||
|
|
|
@ -35,9 +35,8 @@ export default function AccountBorrows() {
|
|||
const [showDepositModal, setShowDepositModal] = useState(false)
|
||||
|
||||
async function handleSettleBorrow(token, borrowQuantity, depositBalance) {
|
||||
const marginAccount = useMangoStore.getState().selectedMarginAccount.current
|
||||
const mangoGroup = useMangoStore.getState().selectedMangoGroup.current
|
||||
const wallet = useMangoStore.getState().wallet.current
|
||||
const { selectedMarginAccount, selectedMangoGroup, wallet } =
|
||||
useMangoStore.getState() as any
|
||||
|
||||
if (borrowQuantity > depositBalance) {
|
||||
const deficit = borrowQuantity - depositBalance
|
||||
|
@ -49,9 +48,9 @@ export default function AccountBorrows() {
|
|||
await settleBorrow(
|
||||
connection,
|
||||
new PublicKey(programId),
|
||||
mangoGroup,
|
||||
marginAccount,
|
||||
wallet,
|
||||
selectedMangoGroup.current,
|
||||
selectedMarginAccount.current,
|
||||
wallet.current,
|
||||
new PublicKey(symbols[token]),
|
||||
Number(borrowQuantity)
|
||||
)
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
const withTM = require('next-transpile-modules')([
|
||||
'@project-serum/sol-wallet-adapter',
|
||||
])
|
||||
|
@ -7,17 +6,18 @@ const withBundleAnalyzer = require('@next/bundle-analyzer')({
|
|||
enabled: process.env.ANALYZE === 'true',
|
||||
})
|
||||
|
||||
module.exports = withBundleAnalyzer(withTM({
|
||||
target: 'serverless',
|
||||
webpack(config, {isServer}) {
|
||||
module.exports = withBundleAnalyzer(
|
||||
withTM({
|
||||
target: 'serverless',
|
||||
webpack(config, { isServer }) {
|
||||
if (!isServer) config.resolve.fallback.fs = false
|
||||
|
||||
config.module.rules.push({
|
||||
test: /\.svg$/,
|
||||
use: ['@svgr/webpack'],
|
||||
})
|
||||
|
||||
config.module.rules.push({
|
||||
test: /\.svg$/,
|
||||
use: ['@svgr/webpack'],
|
||||
})
|
||||
|
||||
return config
|
||||
},
|
||||
}))
|
||||
return config
|
||||
},
|
||||
})
|
||||
)
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es6",
|
||||
"lib": [
|
||||
"dom",
|
||||
"dom.iterable",
|
||||
"esnext"
|
||||
],
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"strict": false,
|
||||
|
@ -19,12 +15,7 @@
|
|||
"jsx": "preserve",
|
||||
"incremental": true
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
".next",
|
||||
"out",
|
||||
"public/datafeeds"
|
||||
],
|
||||
"exclude": ["node_modules", ".next", "out", "public/datafeeds"],
|
||||
"include": [
|
||||
"next-env.d.ts",
|
||||
"**/*.ts",
|
||||
|
|
Loading…
Reference in New Issue