mars-v2-frontend/src/components/Trade/TradeModule/SwapForm/AssetAmountInput.tsx
Linkie Link 1bf93670a3
Transaction loader component (#449)
* feat: added transaction loader screen to modals

* tidy: refactor

* 🐛 fix: borrow not updating vault values (#436)

*  Merge FundAccount and AccountFund (#431)

*  Merge FundAccount and AccountFund

* fix build

* 🐛 fundAccount not showing, small typos/text corrections

* MP-3376: overpay on repay (#438)

* MP-3376: overpay on repay

* fix: remove Buffer and fix NaN on useSpring

* feat: added transaction loader screen to modals

* fix: updated AccountFundContent

* fix: fixed the animated-loader issues

* 🐛 UNSAFE_COMPONENT error (#439)

* 🐛 UNSAFE_COMPONENT error

* 🐛 fix unit tests for react-helmet-async

* Small text fixes (#440)

* 🐛 text fix on fund for new account

* 🐛 make toggle account-wide lending on new-account

* Styling alert dialog (#441)

* 🐛 text fix on fund for new account

* 🐛 make toggle account-wide lending on new-account

* 💅🏼Update styling of alertDialogs

* Fixes bob (#443)

* 🐛 Trading chart title

* 🐛 Trading chart title

* 🐛 fix incorrect vault deposit amounts

* 🐛 fix incorrect vault borrow calc

* 🧽 run format

* 🧽 fix comments

* 🧽 update code owners

* Build(deps): bump bignumber.js from 9.1.1 to 9.1.2 (#444)

Bumps [bignumber.js](https://github.com/MikeMcl/bignumber.js) from 9.1.1 to 9.1.2.
- [Release notes](https://github.com/MikeMcl/bignumber.js/releases)
- [Changelog](https://github.com/MikeMcl/bignumber.js/blob/master/CHANGELOG.md)
- [Commits](https://github.com/MikeMcl/bignumber.js/compare/v9.1.1...v9.1.2)

---
updated-dependencies:
- dependency-name: bignumber.js
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Build(deps-dev): bump @types/react from 18.2.19 to 18.2.21 (#448)

Bumps [@types/react](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/react) from 18.2.19 to 18.2.21.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/react)

---
updated-dependencies:
- dependency-name: "@types/react"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Build(deps): bump next from 13.4.9 to 13.4.19 (#446)

Bumps [next](https://github.com/vercel/next.js) from 13.4.9 to 13.4.19.
- [Release notes](https://github.com/vercel/next.js/releases)
- [Changelog](https://github.com/vercel/next.js/blob/canary/release.js)
- [Commits](https://github.com/vercel/next.js/compare/v13.4.9...v13.4.19)

---
updated-dependencies:
- dependency-name: next
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Build(deps-dev): bump @types/node from 20.4.8 to 20.6.0 (#447)

Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 20.4.8 to 20.6.0.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

---
updated-dependencies:
- dependency-name: "@types/node"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Linkie Link <linkielink.dev@gmail.com>

* feat: refactored the toast responses (#442)

* feat: refactored the toast responses

* fix: fixed the map return

* feat: added a recent transaction center

* tidy: removed logs

* fix: fixed autolend

* feat: added global lending on first account funding

* fix: added endOfLine setting

* feat: added eslint warnings for lineEnds

* fix: made the vault message generic

* feat: added transaction loader screen to modals

* 🐛 fix: borrow not updating vault values (#436)

*  Merge FundAccount and AccountFund (#431)

*  Merge FundAccount and AccountFund

* fix build

* 🐛 fundAccount not showing, small typos/text corrections

* feat: added transaction loader screen to modals

* fix: updated AccountFundContent

* fix: fixed the animated-loader issues

* tidy: refactor

* fix: set pendingTransaction inside the broadcast slice

* fix: fixed the pipeline

* fix: setting showTxLoader

* fix: fixed the pipeline

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Bob van der Helm <34470358+bobthebuidlr@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-11 12:51:44 +02:00

94 lines
2.7 KiB
TypeScript

import classNames from 'classnames'
import { useCallback, useMemo } from 'react'
import NumberInput from 'components/NumberInput'
import { formatValue } from 'utils/formatters'
interface Props {
label?: string
max: BigNumber
asset: Asset
amount: BigNumber
disabled: boolean
maxButtonLabel: string
assetUSDValue: BigNumber
amountValueText?: string
containerClassName?: string
setAmount: (amount: BigNumber) => void
onFocus?: () => void
onBlur?: () => void
}
export default function AssetAmountInput(props: Props) {
const {
max,
label,
amount,
asset,
disabled,
setAmount,
assetUSDValue,
maxButtonLabel,
containerClassName,
onFocus,
onBlur,
} = props
const handleMaxClick = useCallback(() => {
setAmount(max)
}, [max, setAmount])
const maxValue = useMemo(() => {
const val = max.shiftedBy(-asset.decimals)
return val.isGreaterThan(1) ? val.toFixed(2) : val.toPrecision(2)
}, [asset.decimals, max])
return (
<div className={classNames(className.container, containerClassName)}>
<label>
{label}
<div className={className.inputWrapper}>
<NumberInput
asset={asset}
amount={amount}
className={className.input}
maxDecimals={asset.decimals}
max={max}
disabled={disabled}
onChange={setAmount}
onFocus={onFocus}
onBlur={onBlur}
/>
<span>{asset.symbol}</span>
</div>
<div className={className.footer}>
<div className={className.maxButtonWrapper}>
<span className={className.maxButtonLabel}>{maxButtonLabel}</span>
<span className={className.maxValue}>{maxValue}</span>
<div className={className.maxButton} onClick={handleMaxClick}>
MAX
</div>
</div>
<div className={className.assetValue}>
{formatValue(assetUSDValue.toString(), { prefix: '~ $', minDecimals: 2 })}
</div>
</div>
</label>
</div>
)
}
const className = {
container: '',
inputWrapper:
'flex flex-1 flex-row py-3 border-[1px] border-white border-opacity-20 rounded bg-white bg-opacity-5 pl-3 pr-2 mt-2',
input: 'border-none bg-transparent outline-none flex-1 !text-left',
footer: 'flex flex-1 flex-row',
maxButtonWrapper: 'flex flex-1 flex-row mt-2',
maxButtonLabel: 'font-bold text-xs',
maxValue: 'font-bold text-xs text-white text-opacity-60 mx-1',
maxButton:
'hover:cursor-pointer select-none bg-white bg-opacity-20 text-2xs !leading-3 font-bold py-0.5 px-1.5 rounded',
assetValue: 'text-xs text-white text-opacity-60 mt-2',
}