* tidy: refactor text
* tidy: refactor text
* fix display of vaults table
* feat: added unstyled select
* tidy: useToggle
* tidy: useToggle
* add vaults to types
* MP-2344: first unstyled version of Select
* fix: fixed the build
* MP-2344: progress on the Select
* MP-2344: almost finished the Select
* implement basic vault modal (no logic)
* 🍱 max + displaycur for token input
* Convert to BN for TokenInputs
* env: update wallet-connector
* fix: fixed build errors and relative imports
* fix: updated TokenInput
* tidy: format
* fix: BN instead of new BigNumber
---------
Co-authored-by: Linkie Link <linkielink.dev@gmail.com>
115 lines
3.4 KiB
TypeScript
115 lines
3.4 KiB
TypeScript
'use client'
|
|
|
|
import { useCallback, useState } from 'react'
|
|
import BigNumber from 'bignumber.js'
|
|
|
|
import { Button } from 'components/Button'
|
|
import { ArrowRight, Cross } from 'components/Icons'
|
|
import SwitchWithLabel from 'components/SwitchWithLabel'
|
|
import Text from 'components/Text'
|
|
import TokenInputWithSlider from 'components/TokenInputWithSlider'
|
|
import { ASSETS } from 'constants/assets'
|
|
import useToggle from 'hooks/useToggle'
|
|
import useStore from 'store'
|
|
import { hardcodedFee } from 'utils/contants'
|
|
import { BN } from 'utils/helpers'
|
|
import useParams from 'utils/route'
|
|
|
|
interface Props {
|
|
setShowFundAccount: (show: boolean) => void
|
|
setShowMenu: (show: boolean) => void
|
|
}
|
|
|
|
export default function FundAccount(props: Props) {
|
|
const params = useParams()
|
|
const deposit = useStore((s) => s.deposit)
|
|
|
|
const [amount, setAmount] = useState(BN(0))
|
|
const [asset, setAsset] = useState<Asset>(ASSETS[0])
|
|
const [isLending, setIsLending] = useToggle()
|
|
const [isFunding, setIsFunding] = useToggle()
|
|
|
|
const onChangeAmount = useCallback((amount: BigNumber) => {
|
|
setAmount(amount)
|
|
}, [])
|
|
|
|
const onChangeAsset = useCallback((asset: Asset) => {
|
|
setAsset(asset)
|
|
}, [])
|
|
|
|
const handleLendAssets = useCallback(
|
|
(val: boolean) => {
|
|
setIsLending(val)
|
|
/* TODO: handle lending assets */
|
|
},
|
|
[setIsLending],
|
|
)
|
|
|
|
async function onDeposit() {
|
|
setIsFunding(true)
|
|
const result = await deposit({
|
|
fee: hardcodedFee,
|
|
accountId: params.accountId,
|
|
coin: {
|
|
denom: asset.denom,
|
|
amount: amount.toString(),
|
|
},
|
|
})
|
|
setIsFunding(false)
|
|
if (result) {
|
|
props.setShowMenu(false)
|
|
props.setShowFundAccount(false)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<div className='absolute right-4 top-4'>
|
|
<Button
|
|
onClick={() => props.setShowFundAccount(false)}
|
|
leftIcon={<Cross />}
|
|
className='h-8 w-8'
|
|
iconClassName='h-2 w-2'
|
|
color='tertiary'
|
|
/>
|
|
</div>
|
|
<div className='relative z-10 w-full p-4'>
|
|
<Text size='lg' className='mb-2 font-bold'>
|
|
{`Fund Account ${params.accountId}`}
|
|
</Text>
|
|
<Text className='mb-4 text-white/70'>
|
|
Deposit assets from your Osmosis address to your Mars credit account. Bridge assets if
|
|
your Osmosis address has no assets.
|
|
</Text>
|
|
<TokenInputWithSlider
|
|
onChange={onChangeAmount}
|
|
onChangeAsset={onChangeAsset}
|
|
amount={amount}
|
|
max={BN(1).shiftedBy(ASSETS[0].decimals)}
|
|
className='mb-4'
|
|
disabled={isFunding}
|
|
hasSelect
|
|
/>
|
|
<div className='mb-4 w-full border-b border-white/10' />
|
|
<SwitchWithLabel
|
|
name='isLending'
|
|
label='Lend assets to earn yield'
|
|
value={isLending}
|
|
onChange={() => handleLendAssets(!isLending)}
|
|
className='mb-4'
|
|
tooltip="Fund your account and lend assets effortlessly! By lending, you'll earn attractive interest (APY) without impacting your LTV. It's a win-win situation - don't miss out on this easy opportunity to grow your holdings!"
|
|
disabled={isFunding || amount.isEqualTo(0)}
|
|
/>
|
|
<Button
|
|
className='w-full'
|
|
showProgressIndicator={isFunding}
|
|
disabled={amount.isEqualTo(0)}
|
|
text='Fund Account'
|
|
rightIcon={<ArrowRight />}
|
|
onClick={onDeposit}
|
|
/>
|
|
</div>
|
|
</>
|
|
)
|
|
}
|