fix bug in repay modal
This commit is contained in:
parent
f4871fe8d2
commit
a353be17ff
|
@ -105,43 +105,47 @@ function RepayModal({ isOpen, onClose, token }: ModalCombinedProps) {
|
|||
setShowTokenList(false)
|
||||
}
|
||||
|
||||
const handleDeposit = useCallback(async () => {
|
||||
const client = mangoStore.getState().client
|
||||
const group = mangoStore.getState().group
|
||||
const actions = mangoStore.getState().actions
|
||||
const mangoAccount = mangoStore.getState().mangoAccount.current
|
||||
const handleDeposit = useCallback(
|
||||
async (amount: string) => {
|
||||
const client = mangoStore.getState().client
|
||||
const group = mangoStore.getState().group
|
||||
const actions = mangoStore.getState().actions
|
||||
const mangoAccount = mangoStore.getState().mangoAccount.current
|
||||
|
||||
if (!mangoAccount || !group || !bank || !wallet) return
|
||||
if (!mangoAccount || !group || !bank || !wallet) return
|
||||
console.log('inputAmount: ', amount)
|
||||
|
||||
try {
|
||||
setSubmitting(true)
|
||||
const tx = await client.tokenDeposit(
|
||||
group,
|
||||
mangoAccount,
|
||||
bank.mint,
|
||||
parseFloat(inputAmount)
|
||||
)
|
||||
notify({
|
||||
title: 'Transaction confirmed',
|
||||
type: 'success',
|
||||
txid: tx,
|
||||
})
|
||||
try {
|
||||
setSubmitting(true)
|
||||
const tx = await client.tokenDeposit(
|
||||
group,
|
||||
mangoAccount,
|
||||
bank.mint,
|
||||
parseFloat(amount)
|
||||
)
|
||||
notify({
|
||||
title: 'Transaction confirmed',
|
||||
type: 'success',
|
||||
txid: tx,
|
||||
})
|
||||
|
||||
await actions.reloadMangoAccount()
|
||||
actions.fetchWalletTokens(wallet.adapter as unknown as Wallet)
|
||||
setSubmitting(false)
|
||||
} catch (e: any) {
|
||||
notify({
|
||||
title: 'Transaction failed',
|
||||
description: e.message,
|
||||
txid: e?.txid,
|
||||
type: 'error',
|
||||
})
|
||||
console.error('Error repaying:', e)
|
||||
}
|
||||
await actions.reloadMangoAccount()
|
||||
actions.fetchWalletTokens(wallet.adapter as unknown as Wallet)
|
||||
setSubmitting(false)
|
||||
} catch (e: any) {
|
||||
notify({
|
||||
title: 'Transaction failed',
|
||||
description: e.message,
|
||||
txid: e?.txid,
|
||||
type: 'error',
|
||||
})
|
||||
console.error('Error repaying:', e)
|
||||
}
|
||||
|
||||
onClose()
|
||||
}, [bank, wallet])
|
||||
onClose()
|
||||
},
|
||||
[bank, wallet]
|
||||
)
|
||||
|
||||
const banks = useMemo(() => {
|
||||
const banks =
|
||||
|
@ -295,7 +299,7 @@ function RepayModal({ isOpen, onClose, token }: ModalCombinedProps) {
|
|||
</div>
|
||||
</div>
|
||||
<Button
|
||||
onClick={handleDeposit}
|
||||
onClick={() => handleDeposit(inputAmount)}
|
||||
className="flex w-full items-center justify-center"
|
||||
disabled={!inputAmount || showInsufficientBalance}
|
||||
size="large"
|
||||
|
|
Loading…
Reference in New Issue