import React, { useEffect, useMemo, useState } from 'react' import Image from 'next/image' import { Transition, Dialog, Switch } from '@headlessui/react' import BigNumber from 'bignumber.js' import { toast } from 'react-toastify' import useLocalStorageState from 'use-local-storage-state' import { getTokenDecimals, getTokenSymbol } from 'utils/tokens' import ContainerSecondary from './ContainerSecondary' import useCreditManagerStore from 'stores/useCreditManagerStore' import Button from './Button' import Spinner from './Spinner' import useAllBalances from 'hooks/useAllBalances' import useAllowedCoins from 'hooks/useAllowedCoins' import useDepositCreditAccount from 'hooks/mutations/useDepositCreditAccount' import Slider from 'components/Slider' const FundAccountModal = ({ show, onClose }: any) => { const [amount, setAmount] = useState(0) const [selectedToken, setSelectedToken] = useState('') const selectedAccount = useCreditManagerStore((s) => s.selectedAccount) const [lendAssets, setLendAssets] = useLocalStorageState(`lendAssets_${selectedAccount}`, { defaultValue: false, }) const { data: balancesData } = useAllBalances() const { data: allowedCoinsData, isLoading: isLoadingAllowedCoins } = useAllowedCoins() const { mutate, isLoading } = useDepositCreditAccount( selectedAccount || '', selectedToken, BigNumber(amount) .times(10 ** getTokenDecimals(selectedToken)) .toNumber(), { onSuccess: () => { setAmount(0) toast.success(`${amount} ${getTokenSymbol(selectedToken)} successfully Deposited`) onClose() }, } ) useEffect(() => { if (allowedCoinsData && allowedCoinsData.length > 0) { // initialize selected token when allowedCoins fetch data is available setSelectedToken(allowedCoinsData[0]) } }, [allowedCoinsData]) const walletAmount = useMemo(() => { if (!selectedToken) return 0 return BigNumber(balancesData?.find((balance) => balance.denom === selectedToken)?.amount ?? 0) .div(10 ** getTokenDecimals(selectedToken)) .toNumber() }, [balancesData, selectedToken]) const handleValueChange = (value: number) => { if (value > walletAmount) { setAmount(walletAmount) return } setAmount(value) } const maxValue = walletAmount const percentageValue = isNaN(amount) ? 0 : (amount * 100) / maxValue return (
{isLoading && (
)}

About

Bringing the next generation of video creation to the Metaverse.
Powered by deep-learning.

mars
Fund Account {selectedAccount}

Transfer assets from your injective wallet to your Mars credit account. If you don’t have any assets in your injective wallet use the injective bridge to transfer funds to your injective wallet.

{isLoadingAllowedCoins ? (

Loading...

) : ( <>
Asset:
Amount:
handleValueChange(e.target.valueAsNumber)} onBlur={(e) => { if (e.target.value === '') setAmount(0) }} />

In wallet: {walletAmount.toLocaleString()}

{ const decimal = value[0] / 100 const tokenDecimals = getTokenDecimals(selectedToken) // limit decimal precision based on token contract decimals const newAmount = Number((decimal * maxValue).toFixed(tokenDecimals)) setAmount(newAmount) }} onMaxClick={() => setAmount(maxValue)} /> )}

Lending Assets

Lend assets from account to earn yield.
) } export default FundAccountModal