Skip to content

Commit

Permalink
Misc fixes (#996)
Browse files Browse the repository at this point in the history
* No longer defaulting to Wrapped native/USDC pair on load

* If on an usupported network show cow discount 0%

* Only show activities count if > 0

* Avoid showing price impact if doing a wrap

* If there's no account when wrapping, show connect wallet button
  • Loading branch information
alfetopito authored Aug 31, 2022
1 parent 7f870cd commit 05204eb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/custom/components/AccountDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export default function AccountDetails({
</AccountGroupingRow>
</InfoCard>

{!!pendingTransactions.length || !!confirmedTransactions.length ? (
{activityTotalCount ? (
<LowerSection>
<span>
{' '}
Expand Down
7 changes: 5 additions & 2 deletions src/custom/hooks/useCowBalanceAndSubsidy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ import { BigNumber } from 'bignumber.js'
import { getDiscountFromBalance } from 'components/CowSubsidyModal/utils'
import { useCombinedBalance } from 'state/cowToken/hooks'
import { COW_SUBSIDY_DATA } from 'components/CowSubsidyModal/constants'
import { isSupportedChain } from 'utils/supportedChainId'
import { useWeb3React } from '@web3-react/core'

const ZERO_BALANCE_SUBSIDY = { subsidy: { tier: 0, discount: COW_SUBSIDY_DATA[0][1] }, balance: undefined }

export default function useCowBalanceAndSubsidy() {
const { balance } = useCombinedBalance()
const { chainId } = useWeb3React()

return useMemo(() => {
if (!balance || balance?.equalTo('0')) return ZERO_BALANCE_SUBSIDY
if (!isSupportedChain(chainId) || !balance || balance?.equalTo('0')) return ZERO_BALANCE_SUBSIDY

const balanceBn = new BigNumber(balance.quotient.toString())

return { subsidy: getDiscountFromBalance(balanceBn), balance }
}, [balance])
}, [balance, chainId])
}
32 changes: 19 additions & 13 deletions src/custom/pages/Swap/SwapMod.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ export default function Swap({
showMaxButton={false}
hideBalance={false}
fiatValue={fiatValueOutput ?? undefined}
priceImpact={onWrap ? undefined : priceImpact}
priceImpact={showWrap ? undefined : priceImpact}
priceImpactLoading={priceImpactLoading}
currency={currencies[Field.OUTPUT] ?? null}
onCurrencySelect={handleOutputSelect}
Expand Down Expand Up @@ -815,18 +815,24 @@ export default function Swap({
</Text>
</ButtonError>
) : showWrap ? (
<ButtonPrimary
disabled={Boolean(wrapInputError)}
onClick={() => onWrap && onWrap().catch((error) => console.error('Error ' + wrapType, error))}
buttonSize={ButtonSize.BIG}
>
{wrapInputError ??
(wrapType === WrapType.WRAP ? (
<Trans>Wrap</Trans>
) : wrapType === WrapType.UNWRAP ? (
<Trans>Unwrap</Trans>
) : null)}
</ButtonPrimary>
!account ? (
<ButtonPrimary buttonSize={ButtonSize.BIG} onClick={toggleWalletModal}>
<SwapButton showLoading={swapBlankState || isGettingNewQuote}>Connect Wallet</SwapButton>
</ButtonPrimary>
) : (
<ButtonPrimary
disabled={Boolean(wrapInputError)}
onClick={() => onWrap && onWrap().catch((error) => console.error('Error ' + wrapType, error))}
buttonSize={ButtonSize.BIG}
>
{wrapInputError ??
(wrapType === WrapType.WRAP ? (
<Trans>Wrap</Trans>
) : wrapType === WrapType.UNWRAP ? (
<Trans>Unwrap</Trans>
) : null)}
</ButtonPrimary>
)
) : !swapInputError && isNativeIn ? (
<SwitchToWethBtn wrappedToken={wrappedToken} />
) : quote?.error === 'fee-exceeds-sell-amount' ? (
Expand Down
9 changes: 3 additions & 6 deletions src/custom/state/swap/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { FEE_SIZE_THRESHOLD, INITIAL_ALLOWED_SLIPPAGE_PERCENT, WETH_LOGO_URI, XD
import TradeGp from './TradeGp'

import { SupportedChainId, SupportedChainId as ChainId } from 'constants/chains'
import { WRAPPED_NATIVE_CURRENCY as WETH, GpEther as ETHER, USDC } from 'constants/tokens'
import { WRAPPED_NATIVE_CURRENCY as WETH, GpEther as ETHER } from 'constants/tokens'

import { isWrappingTrade } from './utils'

Expand Down Expand Up @@ -394,15 +394,12 @@ export function queryParametersToSwapState(
): SwapState {
let inputCurrency = parseCurrencyFromURLParameter(parsedQs.inputCurrency)
let outputCurrency = parseCurrencyFromURLParameter(parsedQs.outputCurrency)
let typedValue = parseTokenAmountURLParameter(parsedQs.exactAmount)
const typedValue = parseTokenAmountURLParameter(parsedQs.exactAmount)
const independentField = parseIndependentFieldURLParameter(parsedQs.exactField)
const validChainId = supportedChainId(chainId)

if (inputCurrency === '' && outputCurrency === '' && typedValue === '' && independentField === Field.INPUT) {
// Defaults to 1 ETH -> USDC
// Defaults to having the wrapped native currency selected
inputCurrency = defaultInputCurrency // 'ETH' // mod
outputCurrency = validChainId ? USDC[validChainId].address : 'USDC' // mod
typedValue = '1'
} else if (inputCurrency === outputCurrency) {
// clear output if identical
outputCurrency = ''
Expand Down

0 comments on commit 05204eb

Please sign in to comment.