fixed wallet adapter type issues

This commit is contained in:
Maximilian Schneider 2022-07-30 17:40:11 +02:00
parent 1b7c251870
commit 99664f97e9
13 changed files with 214 additions and 230 deletions

View File

@ -27,7 +27,7 @@ const AccountNameModal: FunctionComponent<AccountNameModalProps> = ({
}) => { }) => {
const [name, setName] = useState(accountName || '') const [name, setName] = useState(accountName || '')
const [invalidNameMessage, setInvalidNameMessage] = useState('') 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 selectedMangoGroup = useMangoStore((s) => s.selectedMangoGroup.current)
const selectedMarginAccount = useMangoStore( const selectedMarginAccount = useMangoStore(
(s) => s.selectedMarginAccount.current (s) => s.selectedMarginAccount.current

View File

@ -21,7 +21,7 @@ const BalancesTable = () => {
) )
const marginAccount = useMangoStore.getState().selectedMarginAccount.current const marginAccount = useMangoStore.getState().selectedMarginAccount.current
const mangoGroup = useMangoStore.getState().selectedMangoGroup.current const mangoGroup = useMangoStore.getState().selectedMangoGroup.current
const wallet = useMangoStore.getState().wallet.current const wallet = useMangoStore.getState().wallet.current as any
try { try {
await settleAll( await settleAll(

View File

@ -145,7 +145,7 @@ const BorrowModal: FunctionComponent<BorrowModalProps> = ({
setSubmitting(true) setSubmitting(true)
const marginAccount = useMangoStore.getState().selectedMarginAccount.current const marginAccount = useMangoStore.getState().selectedMarginAccount.current
const mangoGroup = useMangoStore.getState().selectedMangoGroup.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 (!marginAccount || !mangoGroup) return
borrowAndWithdraw( borrowAndWithdraw(

View File

@ -176,7 +176,7 @@ const DepositModal: FunctionComponent<DepositModalProps> = ({
setSubmitting(true) setSubmitting(true)
const marginAccount = useMangoStore.getState().selectedMarginAccount.current const marginAccount = useMangoStore.getState().selectedMarginAccount.current
const mangoGroup = useMangoStore.getState().selectedMangoGroup.current const mangoGroup = useMangoStore.getState().selectedMangoGroup.current
const wallet = useMangoStore.getState().wallet.current const wallet = useMangoStore.getState().wallet.current as any
if (!marginAccount && mangoGroup) { if (!marginAccount && mangoGroup) {
initMarginAccountAndDeposit( initMarginAccountAndDeposit(

View File

@ -10,196 +10,190 @@ interface DepositWithdrawHistoryTableProps {
type: 'deposits' | 'withdrawals' type: 'deposits' | 'withdrawals'
} }
const DepositWithdrawHistoryTable: FunctionComponent<DepositWithdrawHistoryTableProps> = const DepositWithdrawHistoryTable: FunctionComponent<
({ type }) => { DepositWithdrawHistoryTableProps
const depositHistory = useMangoStore((s) => s.depositHistory) > = ({ type }) => {
const withdrawalHistory = useMangoStore((s) => s.withdrawalHistory) const depositHistory = useMangoStore((s) => s.depositHistory)
const history = type === 'deposits' ? depositHistory : withdrawalHistory const withdrawalHistory = useMangoStore((s) => s.withdrawalHistory)
const history = type === 'deposits' ? depositHistory : withdrawalHistory
const { items, requestSort, sortConfig } = useSortableData(history) 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 renderTransactionTime = (timestamp) => {
const date = new Date(timestamp)
return ( return (
<div className={`flex flex-col py-4`}> <>
<div className={`-my-2 overflow-x-auto sm:-mx-6 lg:-mx-8`}> <div>{date.toLocaleDateString()}</div>
<div <div className="text-xs text-th-fgd-3">{date.toLocaleTimeString()}</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>
) )
} }
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 export default DepositWithdrawHistoryTable

View File

@ -88,7 +88,7 @@ const NewAccount: FunctionComponent<NewAccountProps> = ({
const handleNewAccountDeposit = () => { const handleNewAccountDeposit = () => {
setSubmitting(true) setSubmitting(true)
const mangoGroup = useMangoStore.getState().selectedMangoGroup.current const mangoGroup = useMangoStore.getState().selectedMangoGroup.current
const wallet = useMangoStore.getState().wallet.current const wallet = useMangoStore.getState().wallet.current as any
initMarginAccountAndDeposit( initMarginAccountAndDeposit(
connection, connection,

View File

@ -23,7 +23,7 @@ const OpenOrdersTable = () => {
const actions = useMangoStore((s) => s.actions) const actions = useMangoStore((s) => s.actions)
const handleCancelOrder = async (order) => { const handleCancelOrder = async (order) => {
const wallet = useMangoStore.getState().wallet.current const wallet = useMangoStore.getState().wallet.current as any
const selectedMangoGroup = const selectedMangoGroup =
useMangoStore.getState().selectedMangoGroup.current useMangoStore.getState().selectedMangoGroup.current
const selectedMarginAccount = const selectedMarginAccount =

View File

@ -200,7 +200,7 @@ export default function TradeForm() {
const marginAccount = useMangoStore.getState().selectedMarginAccount.current const marginAccount = useMangoStore.getState().selectedMarginAccount.current
const mangoGroup = useMangoStore.getState().selectedMangoGroup.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 if (!mangoGroup || !marketAddress || !marginAccount || !market) return
setSubmitting(true) setSubmitting(true)

View File

@ -148,7 +148,7 @@ const WithdrawModal: FunctionComponent<WithdrawModalProps> = ({
setSubmitting(true) setSubmitting(true)
const marginAccount = useMangoStore.getState().selectedMarginAccount.current const marginAccount = useMangoStore.getState().selectedMarginAccount.current
const mangoGroup = useMangoStore.getState().selectedMangoGroup.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 (!marginAccount || !mangoGroup) return
if (!includeBorrow) { if (!includeBorrow) {

View File

@ -13,6 +13,7 @@ import DepositModal from '../DepositModal'
import WithdrawModal from '../WithdrawModal' import WithdrawModal from '../WithdrawModal'
import Button from '../Button' import Button from '../Button'
import Tooltip from '../Tooltip' import Tooltip from '../Tooltip'
import { Market } from '@project-serum/serum'
export default function AccountAssets() { export default function AccountAssets() {
const balances = useBalances() const balances = useBalances()
@ -53,12 +54,11 @@ export default function AccountAssets() {
} }
async function handleSettleAllTrades() { async function handleSettleAllTrades() {
const markets = Object.values( const { selectedMangoGroup, selectedMarginAccount, wallet } =
useMangoStore.getState().selectedMangoGroup.markets useMangoStore.getState() as any
) const markets = Object.values(selectedMangoGroup.markets) as Market[]
const marginAccount = useMangoStore.getState().selectedMarginAccount.current const marginAccount = selectedMarginAccount.current
const mangoGroup = useMangoStore.getState().selectedMangoGroup.current const mangoGroup = selectedMangoGroup.current
const wallet = useMangoStore.getState().wallet.current
try { try {
await settleAllTrades( await settleAllTrades(
@ -67,7 +67,7 @@ export default function AccountAssets() {
mangoGroup, mangoGroup,
marginAccount, marginAccount,
markets, markets,
wallet wallet.current
) )
await sleep(250) await sleep(250)
actions.fetchMarginAccounts() actions.fetchMarginAccounts()

View File

@ -35,9 +35,8 @@ export default function AccountBorrows() {
const [showDepositModal, setShowDepositModal] = useState(false) const [showDepositModal, setShowDepositModal] = useState(false)
async function handleSettleBorrow(token, borrowQuantity, depositBalance) { async function handleSettleBorrow(token, borrowQuantity, depositBalance) {
const marginAccount = useMangoStore.getState().selectedMarginAccount.current const { selectedMarginAccount, selectedMangoGroup, wallet } =
const mangoGroup = useMangoStore.getState().selectedMangoGroup.current useMangoStore.getState() as any
const wallet = useMangoStore.getState().wallet.current
if (borrowQuantity > depositBalance) { if (borrowQuantity > depositBalance) {
const deficit = borrowQuantity - depositBalance const deficit = borrowQuantity - depositBalance
@ -49,9 +48,9 @@ export default function AccountBorrows() {
await settleBorrow( await settleBorrow(
connection, connection,
new PublicKey(programId), new PublicKey(programId),
mangoGroup, selectedMangoGroup.current,
marginAccount, selectedMarginAccount.current,
wallet, wallet.current,
new PublicKey(symbols[token]), new PublicKey(symbols[token]),
Number(borrowQuantity) Number(borrowQuantity)
) )

View File

@ -1,4 +1,3 @@
const withTM = require('next-transpile-modules')([ const withTM = require('next-transpile-modules')([
'@project-serum/sol-wallet-adapter', '@project-serum/sol-wallet-adapter',
]) ])
@ -7,17 +6,18 @@ const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true', enabled: process.env.ANALYZE === 'true',
}) })
module.exports = withBundleAnalyzer(withTM({ module.exports = withBundleAnalyzer(
target: 'serverless', withTM({
webpack(config, {isServer}) { target: 'serverless',
webpack(config, { isServer }) {
if (!isServer) config.resolve.fallback.fs = false if (!isServer) config.resolve.fallback.fs = false
config.module.rules.push({
test: /\.svg$/,
use: ['@svgr/webpack'],
})
config.module.rules.push({ return config
test: /\.svg$/, },
use: ['@svgr/webpack'], })
}) )
return config
},
}))

View File

@ -1,11 +1,7 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "es6", "target": "es6",
"lib": [ "lib": ["dom", "dom.iterable", "esnext"],
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true, "allowJs": true,
"skipLibCheck": true, "skipLibCheck": true,
"strict": false, "strict": false,
@ -19,12 +15,7 @@
"jsx": "preserve", "jsx": "preserve",
"incremental": true "incremental": true
}, },
"exclude": [ "exclude": ["node_modules", ".next", "out", "public/datafeeds"],
"node_modules",
".next",
"out",
"public/datafeeds"
],
"include": [ "include": [
"next-env.d.ts", "next-env.d.ts",
"**/*.ts", "**/*.ts",