Skip to content

Commit

Permalink
swap tx
Browse files Browse the repository at this point in the history
  • Loading branch information
abrzezinski94 committed Jul 4, 2024
1 parent 4e6dc4c commit 05aa346
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion components/MangoProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const HydrateStore = () => {
actions.estimatePriorityFee(priorityFeeMultiplier)
}
},
(slowNetwork ? 60 : 10) * SECONDS,
(slowNetwork ? 60 : 20) * SECONDS,
)

// The websocket library solana/web3.js uses closes its websocket connection when the subscription list
Expand Down
35 changes: 32 additions & 3 deletions components/StakeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ import Link from 'next/link'
import LeverageSlider from './shared/LeverageSlider'
import useMangoGroup from 'hooks/useMangoGroup'
import FormatNumericValue from './shared/FormatNumericValue'
import { getNextAccountNumber, stakeAndCreate } from 'utils/transactions'
import {
getNextAccountNumber,
stakeAndCreate,
walletSwap,
} from 'utils/transactions'
// import { MangoAccount } from '@blockworks-foundation/mango-v4'
import useBankRates from 'hooks/useBankRates'
import { Disclosure } from '@headlessui/react'
Expand Down Expand Up @@ -112,7 +116,8 @@ function StakeForm({ token: selectedToken, clientContext }: StakeFormProps) {
const [refreshingWalletTokens, setRefreshingWalletTokens] = useState(false)
const { maxSolDeposit } = useSolBalance()
const { ipAllowed } = useIpAddress()

const wallet = useWallet()
const connection = mangoStore((s) => s.connection)
const storedLeverage = mangoStore((s) => s.leverage)
const { usedTokens, totalTokens } = useMangoAccountAccounts()
const { jlpGroup, lstGroup } = useMangoGroup()
Expand Down Expand Up @@ -281,10 +286,31 @@ function StakeForm({ token: selectedToken, clientContext }: StakeFormProps) {
})
try {
// const newAccountfNum = getNextAccountNumber(mangoAccounts)
if (!bestRoute && isSwapMode) {
notify({
title: 'No swap route found',
type: 'error',
})
}
notify({
title: 'Building transaction. This may take a moment.',
type: 'info',
})
if (isSwapMode && bestRoute) {
const { txid } = await walletSwap(
bestRoute,
connection,
0.5,
wallet,
client,
)
notify({
title: 'Transaction confirmed',
type: 'success',
txid: txid,
})
}

const { signature: tx, slot } = await stakeAndCreate(
client,
group,
Expand Down Expand Up @@ -327,9 +353,12 @@ function StakeForm({ token: selectedToken, clientContext }: StakeFormProps) {
ipAllowed,
stakeBank,
publicKey,
clientContext,
bestRoute,
connection,
wallet,
amountToBorrow,
inputAmount,
clientContext,
])

const showInsufficientBalance =
Expand Down

0 comments on commit 05aa346

Please sign in to comment.