Skip to content

Commit

Permalink
fix: spending limit validation (#1681)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamacook authored and katspaugh committed Feb 20, 2023
1 parent 14271ec commit f3fb93c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
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

0 comments on commit f3fb93c

Please sign in to comment.