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,8 +10,9 @@ interface DepositWithdrawHistoryTableProps {
type: 'deposits' | 'withdrawals' type: 'deposits' | 'withdrawals'
} }
const DepositWithdrawHistoryTable: FunctionComponent<DepositWithdrawHistoryTableProps> = const DepositWithdrawHistoryTable: FunctionComponent<
({ type }) => { DepositWithdrawHistoryTableProps
> = ({ type }) => {
const depositHistory = useMangoStore((s) => s.depositHistory) const depositHistory = useMangoStore((s) => s.depositHistory)
const withdrawalHistory = useMangoStore((s) => s.withdrawalHistory) const withdrawalHistory = useMangoStore((s) => s.withdrawalHistory)
const history = type === 'deposits' ? depositHistory : withdrawalHistory const history = type === 'deposits' ? depositHistory : withdrawalHistory
@ -23,9 +24,7 @@ const DepositWithdrawHistoryTable: FunctionComponent<DepositWithdrawHistoryTable
return ( return (
<> <>
<div>{date.toLocaleDateString()}</div> <div>{date.toLocaleDateString()}</div>
<div className="text-xs text-th-fgd-3"> <div className="text-xs text-th-fgd-3">{date.toLocaleTimeString()}</div>
{date.toLocaleTimeString()}
</div>
</> </>
) )
} }
@ -33,9 +32,7 @@ const DepositWithdrawHistoryTable: FunctionComponent<DepositWithdrawHistoryTable
return ( return (
<div className={`flex flex-col py-4`}> <div className={`flex flex-col py-4`}>
<div className={`-my-2 overflow-x-auto sm:-mx-6 lg:-mx-8`}> <div className={`-my-2 overflow-x-auto sm:-mx-6 lg:-mx-8`}>
<div <div className={`align-middle inline-block min-w-full sm:px-6 lg:px-8`}>
className={`align-middle inline-block min-w-full sm:px-6 lg:px-8`}
>
{history.length > 0 ? ( {history.length > 0 ? (
<div <div
className={`overflow-hidden border-b border-th-bkg-2 sm:rounded-md`} className={`overflow-hidden border-b border-th-bkg-2 sm:rounded-md`}
@ -164,12 +161,9 @@ const DepositWithdrawHistoryTable: FunctionComponent<DepositWithdrawHistoryTable
className={`px-6 py-3 whitespace-nowrap text-sm text-th-fgd-1`} className={`px-6 py-3 whitespace-nowrap text-sm text-th-fgd-1`}
> >
$ $
{transaction.usd_equivalent.toLocaleString( {transaction.usd_equivalent.toLocaleString(undefined, {
undefined,
{
maximumFractionDigits: 2, maximumFractionDigits: 2,
} })}
)}
</Td> </Td>
<Td <Td
className={`px-6 py-3 whitespace-nowrap text-sm text-th-fgd-1`} className={`px-6 py-3 whitespace-nowrap text-sm text-th-fgd-1`}
@ -200,6 +194,6 @@ const DepositWithdrawHistoryTable: FunctionComponent<DepositWithdrawHistoryTable
</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,12 +6,12 @@ const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true', enabled: process.env.ANALYZE === 'true',
}) })
module.exports = withBundleAnalyzer(withTM({ module.exports = withBundleAnalyzer(
withTM({
target: 'serverless', target: 'serverless',
webpack(config, {isServer}) { webpack(config, { isServer }) {
if (!isServer) config.resolve.fallback.fs = false if (!isServer) config.resolve.fallback.fs = false
config.module.rules.push({ config.module.rules.push({
test: /\.svg$/, test: /\.svg$/,
use: ['@svgr/webpack'], use: ['@svgr/webpack'],
@ -20,4 +19,5 @@ module.exports = withBundleAnalyzer(withTM({
return config 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",