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, "@next/next/no-img-element": 0,
"react-hooks/rules-of-hooks": "error", // Checks rules of Hooks "react-hooks/rules-of-hooks": "error", // Checks rules of Hooks
"react-hooks/exhaustive-deps": "warn", // Checks effect dependencies "react-hooks/exhaustive-deps": "warn", // Checks effect dependencies
"tailwindcss/no-custom-classname": 0,
"@typescript-eslint/no-explicit-any": "error", "@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-unused-vars": [ "@typescript-eslint/no-unused-vars": [
2, 2,

View File

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

View File

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

View File

@ -201,7 +201,7 @@ function UnstakeForm({ token: selectedToken }: UnstakeFormProps) {
return ( return (
<> <>
<EnterBottomExitBottom <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} show={showTokenList}
> >
<BackButton onClick={() => setShowTokenList(false)} /> <BackButton onClick={() => setShowTokenList(false)} />
@ -311,8 +311,8 @@ function UnstakeForm({ token: selectedToken }: UnstakeFormProps) {
</span> </span>
<ChevronDownIcon <ChevronDownIcon
className={`${ className={`${
open ? 'rotate-180' : 'rotate-360' open ? 'rotate-180' : ''
} h-6 w-6 flex-shrink-0 text-th-fgd-1`} } h-6 w-6 shrink-0 text-th-fgd-1`}
/> />
</div> </div>
</div> </div>
@ -362,7 +362,7 @@ function UnstakeForm({ token: selectedToken }: UnstakeFormProps) {
<Loading className="mr-2 h-5 w-5" /> <Loading className="mr-2 h-5 w-5" />
) : showInsufficientBalance ? ( ) : showInsufficientBalance ? (
<div className="flex items-center"> <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', { {t('swap:insufficient-balance', {
symbol: formatTokenSymbol(selectedToken), symbol: formatTokenSymbol(selectedToken),
})} })}

View File

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

View File

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