Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: spending limit validation #1681

Merged
merged 2 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/components/tx/SpendingLimitRow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const SpendingLimitRow = ({
availableAmount: BigNumber
selectedToken: TokenInfo | undefined
}) => {
const { control } = useFormContext()
const { control, trigger } = useFormContext()
const isOnlySpendLimitBeneficiary = useIsOnlySpendingLimitBeneficiary()

const formattedAmount = safeFormatUnits(availableAmount, selectedToken?.decimals)
Expand All @@ -26,8 +26,16 @@ const SpendingLimitRow = ({
rules={{ required: true }}
control={control}
name={SendAssetsField.type}
render={({ field }) => (
<RadioGroup {...field} defaultValue={SendTxType.multiSig}>
render={({ field: { onChange, ...field } }) => (
<RadioGroup
onChange={async (e) => {
// Validate only after the field is changed
await onChange(e)
trigger(SendAssetsField.amount)
}}
{...field}
defaultValue={SendTxType.multiSig}
>
{!isOnlySpendLimitBeneficiary && (
<FormControlLabel
value={SendTxType.multiSig}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ const SendAssetsForm = ({
const isSpendingLimitType = type === SendTxType.spendingLimit
const spendingLimitAmount = spendingLimit ? BigNumber.from(spendingLimit.amount).sub(spendingLimit.spent) : undefined
const totalAmount = BigNumber.from(selectedToken?.balance || 0)
const maxAmount = spendingLimitAmount
? totalAmount.gt(spendingLimitAmount)
const maxAmount = isSpendingLimitType
? spendingLimitAmount && totalAmount.gt(spendingLimitAmount)
? spendingLimitAmount
: totalAmount
: totalAmount
Expand Down