Skip to content

Commit

Permalink
feat: thorchain lp disable smart contract deposits
Browse files Browse the repository at this point in the history
  • Loading branch information
gomesalexandre committed Feb 13, 2024
1 parent 081e94a commit a75ce30
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useQuery } from '@tanstack/react-query'
import { useMemo } from 'react'
import { isAddress } from 'viem'
import { isSmartContractAddress } from 'lib/address/utils'

export const useIsSmartContractAddress = (address: string) => {
Expand All @@ -13,7 +14,7 @@ export const useIsSmartContractAddress = (address: string) => {
},
],
queryFn: () => isSmartContractAddress(userAddress),
enabled: Boolean(userAddress.length),
enabled: Boolean(userAddress.length && isAddress(address)),
})

return query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { TradeAssetInput } from 'components/MultiHopTrade/components/TradeAssetI
import { Row } from 'components/Row/Row'
import { SlideTransition } from 'components/SlideTransition'
import { useBrowserRouter } from 'hooks/useBrowserRouter/useBrowserRouter'
import { useIsSmartContractAddress } from 'hooks/useIsSmartContractAddress/useIsSmartContractAddress'
import { useModal } from 'hooks/useModal/useModal'
import { useWallet } from 'hooks/useWallet/useWallet'
import { bn, bnOrZero, convertPrecision } from 'lib/bignumber/bignumber'
Expand Down Expand Up @@ -153,6 +154,9 @@ export const AddLiquidityInput: React.FC<AddLiquidityInputProps> = ({
const [poolAssetAccountAddress, setPoolAssetAccountAddress] = useState<string | undefined>(
undefined,
)
const { data: isSmartContractAccountAddress, isLoading: isSmartContractAccountAddressLoading } =
useIsSmartContractAddress(poolAssetAccountAddress ?? '')

const [activeOpportunityId, setActiveOpportunityId] = useState(
opportunityId ?? defaultOpportunityId,
)
Expand Down Expand Up @@ -1050,12 +1054,15 @@ export const AddLiquidityInput: React.FC<AddLiquidityInputProps> = ({
const errorCopy = useMemo(() => {
// Order matters here. Since we're dealing with two assets potentially, we want to show the most relevant error message possible i.e
// 1. pool halted
// 2. pool asset balance
// 3. pool asset fee balance, since gas would usually be more expensive on the pool asset fee side vs. RUNE side
// 4. RUNE balance
// 5. RUNE fee balance
// 2. smart contract deposits disabled
// 3. pool asset balance
// 4. pool asset fee balance, since gas would usually be more expensive on the pool asset fee side vs. RUNE side
// 5. RUNE balance
// 6. RUNE fee balance
// Not enough *pool* asset, but possibly enough *fee* asset
if (isTradingActive === false) return translate('common.poolHalted')
if (isSmartContractAccountAddress === true)
return translate('trade.errors.smartContractWalletNotSupported')
if (poolAsset && notEnoughPoolAssetError) return translate('common.insufficientFunds')
// Not enough *fee* asset
if (poolAssetFeeAsset && notEnoughFeeAssetError)
Expand All @@ -1072,6 +1079,7 @@ export const AddLiquidityInput: React.FC<AddLiquidityInputProps> = ({

return null
}, [
isSmartContractAccountAddress,
isTradingActive,
notEnoughFeeAssetError,
notEnoughPoolAssetError,
Expand Down Expand Up @@ -1198,7 +1206,8 @@ export const AddLiquidityInput: React.FC<AddLiquidityInputProps> = ({
isApprovalTxPending ||
isSweepNeededLoading ||
isInboundAddressesDataLoading ||
isEstimatedPoolAssetFeesDataLoading
isEstimatedPoolAssetFeesDataLoading ||
isSmartContractAccountAddressLoading
}
onClick={handleSubmit}
>
Expand Down

0 comments on commit a75ce30

Please sign in to comment.