This commit is contained in:
tjs 2023-10-02 00:06:19 -04:00
parent af188cade9
commit 8ad79f5966
6 changed files with 39 additions and 32 deletions

View File

@ -14,6 +14,7 @@
"@next/next/no-img-element": 0,
"react-hooks/rules-of-hooks": "error", // Checks rules of Hooks
"react-hooks/exhaustive-deps": "warn", // Checks effect dependencies
"tailwindcss/no-custom-classname": 0,
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-unused-vars": [
2,

View File

@ -65,12 +65,12 @@ const HydrateStore = () => {
// )
// refetch trade history and activity feed when switching accounts
useEffect(() => {
const actions = mangoStore.getState().actions
if (mangoAccountAddress) {
actions.fetchActivityFeed(mangoAccountAddress)
}
}, [mangoAccountAddress])
// useEffect(() => {
// const actions = mangoStore.getState().actions
// if (mangoAccountAddress) {
// actions.fetchActivityFeed(mangoAccountAddress)
// }
// }, [mangoAccountAddress])
// reload and parse market fills from the event queue
// useInterval(

View File

@ -28,12 +28,13 @@ import LeverageSlider from './shared/LeverageSlider'
import useMangoGroup from 'hooks/useMangoGroup'
import FormatNumericValue from './shared/FormatNumericValue'
import { stakeAndCreate } from 'utils/transactions'
import { MangoAccount } from '@blockworks-foundation/mango-v4'
// import { MangoAccount } from '@blockworks-foundation/mango-v4'
import { AnchorProvider } from '@project-serum/anchor'
import useBankRates from 'hooks/useBankRates'
import { Disclosure } from '@headlessui/react'
import SheenLoader from './shared/SheenLoader'
import useLeverageMax from 'hooks/useLeverageMax'
import { STAKEABLE_TOKENS } from 'utils/constants'
const set = mangoStore.getState().set
@ -65,18 +66,18 @@ export const walletBalanceForToken = (
}
}
const getNextAccountNumber = (accounts: MangoAccount[]): number => {
if (accounts.length > 1) {
return (
accounts
.map((a) => a.accountNum)
.reduce((a, b) => Math.max(a, b), -Infinity) + 1
)
} else if (accounts.length === 1) {
return accounts[0].accountNum + 1
}
return 0
}
// const getNextAccountNumber = (accounts: MangoAccount[]): number => {
// if (accounts.length > 1) {
// return (
// accounts
// .map((a) => a.accountNum)
// .reduce((a, b) => Math.max(a, b), -Infinity) + 1
// )
// } else if (accounts.length === 1) {
// return accounts[0].accountNum + 1
// }
// return 0
// }
function StakeForm({ token: selectedToken }: StakeFormProps) {
const { t } = useTranslation(['common', 'account'])
@ -147,7 +148,7 @@ function StakeForm({ token: selectedToken }: StakeFormProps) {
const client = mangoStore.getState().client
const group = mangoStore.getState().group
const actions = mangoStore.getState().actions
const mangoAccounts = mangoStore.getState().mangoAccounts
// const mangoAccounts = mangoStore.getState().mangoAccounts
const mangoAccount = mangoStore.getState().mangoAccount.current
if (!group || !stakeBank || !publicKey) return
@ -155,8 +156,11 @@ function StakeForm({ token: selectedToken }: StakeFormProps) {
set((state) => {
state.submittingBoost = true
})
const tokenNum = STAKEABLE_TOKENS.findIndex(
(t) => t.toLowerCase() === stakeBank.name.toLowerCase(),
)
try {
const newAccountNum = getNextAccountNumber(mangoAccounts)
// const newAccountNum = getNextAccountNumber(mangoAccounts)
const { signature: tx, slot } = await stakeAndCreate(
client,
group,
@ -164,18 +168,16 @@ function StakeForm({ token: selectedToken }: StakeFormProps) {
amountToBorrow,
stakeBank.mint,
parseFloat(inputAmount),
newAccountNum + 300,
420 + tokenNum,
)
notify({
title: 'Transaction confirmed',
type: 'success',
txid: tx,
})
if (!mangoAccount) {
await actions.fetchMangoAccounts(
(client.program.provider as AnchorProvider).wallet.publicKey,
)
}
await actions.fetchMangoAccounts(
(client.program.provider as AnchorProvider).wallet.publicKey,
)
await actions.reloadMangoAccount(slot)
await actions.fetchWalletTokens(publicKey)
set((state) => {

View File

@ -201,7 +201,7 @@ function UnstakeForm({ token: selectedToken }: UnstakeFormProps) {
return (
<>
<EnterBottomExitBottom
className={`absolute bottom-0 left-0 z-20 h-[${ACCOUNT_ACTION_MODAL_INNER_HEIGHT}] w-full overflow-auto rounded-lg bg-th-bkg-1 p-6`}
className={`h-[${ACCOUNT_ACTION_MODAL_INNER_HEIGHT}] absolute bottom-0 left-0 z-20 w-full overflow-auto rounded-lg bg-th-bkg-1 p-6`}
show={showTokenList}
>
<BackButton onClick={() => setShowTokenList(false)} />
@ -311,8 +311,8 @@ function UnstakeForm({ token: selectedToken }: UnstakeFormProps) {
</span>
<ChevronDownIcon
className={`${
open ? 'rotate-180' : 'rotate-360'
} h-6 w-6 flex-shrink-0 text-th-fgd-1`}
open ? 'rotate-180' : ''
} h-6 w-6 shrink-0 text-th-fgd-1`}
/>
</div>
</div>
@ -362,7 +362,7 @@ function UnstakeForm({ token: selectedToken }: UnstakeFormProps) {
<Loading className="mr-2 h-5 w-5" />
) : showInsufficientBalance ? (
<div className="flex items-center">
<ExclamationCircleIcon className="icon-shadow mr-2 h-5 w-5 flex-shrink-0" />
<ExclamationCircleIcon className="icon-shadow mr-2 h-5 w-5 shrink-0" />
{t('swap:insufficient-balance', {
symbol: formatTokenSymbol(selectedToken),
})}

View File

@ -130,6 +130,7 @@
"rate": "Rate (APR)",
"rates": "Rates (APR)",
"refresh-data": "Manually refresh data",
"refresh-balance": "Refresh Balance",
"remove": "Remove",
"remove-delegate": "Remove Delegate",
"repay": "Repay",

View File

@ -84,7 +84,10 @@ export const unstakeAndClose = async (
mangoAccountPk: mangoAccount.publicKey,
owner: payer,
inputMintPk: stakeBank.mint,
amountIn: toUiDecimals(selectedRoute.inAmount, stakeBank.mintDecimals),
amountIn: toUiDecimals(
selectedRoute.inAmount + 10,
stakeBank.mintDecimals,
),
outputMintPk: solBank.mint,
userDefinedInstructions: jupiterIxs,
userDefinedAlts: jupiterAlts,