Skip to content

Commit

Permalink
Fix: limit spending limit tokens in menu (#1652)
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh authored Feb 9, 2023
1 parent 7d538cc commit b026a45
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
1 change: 0 additions & 1 deletion src/components/safe-apps/SafeAppsSDKLink/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
margin-bottom: var(--space-1);
}


.link {
font-weight: 400;
}
25 changes: 13 additions & 12 deletions src/components/tx/modals/TokenTransferModal/SendAssetsForm.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ReactElement } from 'react'
import { useCallback, useMemo } from 'react'
import { useForm, FormProvider, Controller } from 'react-hook-form'
import {
Button,
Expand Down Expand Up @@ -126,20 +127,19 @@ const SendAssetsForm = ({
const type = watch(SendAssetsField.type)
const spendingLimit = useSpendingLimit(selectedToken?.tokenInfo)
const isSpendingLimitType = type === SendTxType.spendingLimit

const isSafeTokenSelected = sameAddress(safeTokenAddress, tokenAddress)

const spendingLimitAmount = spendingLimit ? BigNumber.from(spendingLimit.amount).sub(spendingLimit.spent) : undefined

const items = isOnlySpendingLimitBeneficiary
? balances.items.filter(({ tokenInfo }) => {
return spendingLimits?.some(({ beneficiary, token }) => {
return sameAddress(beneficiary, wallet?.address || '') && sameAddress(tokenInfo.address, token)
const balancesItems = useMemo(() => {
return isOnlySpendingLimitBeneficiary
? balances.items.filter(({ tokenInfo }) => {
return spendingLimits?.some(({ beneficiary, token }) => {
return sameAddress(beneficiary, wallet?.address || '') && sameAddress(tokenInfo.address, token)
})
})
})
: balances.items
: balances.items
}, [balances.items, isOnlySpendingLimitBeneficiary, spendingLimits, wallet?.address])

const onMaxAmountClick = () => {
const onMaxAmountClick = useCallback(() => {
if (!selectedToken) return

const amount =
Expand All @@ -150,8 +150,9 @@ const SendAssetsForm = ({
setValue(SendAssetsField.amount, safeFormatUnits(amount, selectedToken.tokenInfo.decimals), {
shouldValidate: true,
})
}
}, [isSpendingLimitType, selectedToken, setValue, spendingLimitAmount])

const isSafeTokenSelected = sameAddress(safeTokenAddress, tokenAddress)
const isDisabled = isSafeTokenSelected && isSafeTokenPaused

return (
Expand Down Expand Up @@ -189,7 +190,7 @@ const SendAssetsForm = ({
resetField(SendAssetsField.amount)
}}
>
{balances.items.map((item) => (
{balancesItems.map((item) => (
<MenuItem key={item.tokenInfo.address} value={item.tokenInfo.address}>
<AutocompleteItem {...item} />
</MenuItem>
Expand Down

0 comments on commit b026a45

Please sign in to comment.