Commit 897e7f45 authored by Zach Pomerantz's avatar Zach Pomerantz Committed by GitHub

fix: approval action button (#3297)

parent a7fb7dc9
...@@ -54,10 +54,17 @@ export const Overlay = styled(Row)<{ action?: boolean }>` ...@@ -54,10 +54,17 @@ export const Overlay = styled(Row)<{ action?: boolean }>`
${({ action }) => action && actionCss} ${({ action }) => action && actionCss}
` `
export interface Action {
message: ReactNode
icon?: Icon
onClick: () => void
children: ReactNode
}
export interface ActionButtonProps { export interface ActionButtonProps {
color?: Color color?: Color
disabled?: boolean disabled?: boolean
action?: { message: ReactNode; icon?: Icon; onClick: () => void; children: ReactNode } action?: Action
onClick: () => void onClick: () => void
children: ReactNode children: ReactNode
} }
......
...@@ -16,7 +16,7 @@ import { formatCurrencyAmount, formatPrice } from 'utils/formatCurrencyAmount' ...@@ -16,7 +16,7 @@ import { formatCurrencyAmount, formatPrice } from 'utils/formatCurrencyAmount'
import { computeRealizedPriceImpact } from 'utils/prices' import { computeRealizedPriceImpact } from 'utils/prices'
import { tradeMeaningfullyDiffers } from 'utils/tradeMeaningFullyDiffer' import { tradeMeaningfullyDiffers } from 'utils/tradeMeaningFullyDiffer'
import ActionButton from '../../ActionButton' import ActionButton, { Action } from '../../ActionButton'
import Column from '../../Column' import Column from '../../Column'
import { Header } from '../../Dialog' import { Header } from '../../Dialog'
import Row from '../../Row' import Row from '../../Row'
...@@ -112,7 +112,7 @@ export function SummaryDialog({ trade, allowedSlippage, onConfirm }: SummaryDial ...@@ -112,7 +112,7 @@ export function SummaryDialog({ trade, allowedSlippage, onConfirm }: SummaryDial
[confirmedTrade, trade] [confirmedTrade, trade]
) )
const action = useMemo(() => { const action = useMemo((): Action | undefined => {
if (doesTradeDiffer) { if (doesTradeDiffer) {
return { return {
message: <Trans>Price updated</Trans>, message: <Trans>Price updated</Trans>,
......
...@@ -22,7 +22,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react' ...@@ -22,7 +22,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react'
import invariant from 'tiny-invariant' import invariant from 'tiny-invariant'
import { ExplorerDataType } from 'utils/getExplorerLink' import { ExplorerDataType } from 'utils/getExplorerLink'
import ActionButton from '../ActionButton' import ActionButton, { ActionButtonProps } from '../ActionButton'
import Dialog from '../Dialog' import Dialog from '../Dialog'
import EtherscanLink from '../EtherscanLink' import EtherscanLink from '../EtherscanLink'
import Row from '../Row' import Row from '../Row'
...@@ -76,7 +76,7 @@ export default function SwapButton({ disabled }: SwapButtonProps) { ...@@ -76,7 +76,7 @@ export default function SwapButton({ disabled }: SwapButtonProps) {
}) })
}, [addTransaction, getApproval]) }, [addTransaction, getApproval])
const actionProps = useMemo(() => { const actionProps = useMemo((): Partial<ActionButtonProps> | undefined => {
if (disabled) return { disabled: true } if (disabled) return { disabled: true }
if (chainId && inputCurrencyAmount) { if (chainId && inputCurrencyAmount) {
...@@ -85,7 +85,7 @@ export default function SwapButton({ disabled }: SwapButtonProps) { ...@@ -85,7 +85,7 @@ export default function SwapButton({ disabled }: SwapButtonProps) {
} else if (approval === ApprovalState.PENDING) { } else if (approval === ApprovalState.PENDING) {
return { return {
disabled: true, disabled: true,
update: { action: {
message: ( message: (
<EtherscanLink type={ExplorerDataType.TRANSACTION} data={approvalHash}> <EtherscanLink type={ExplorerDataType.TRANSACTION} data={approvalHash}>
<Row gap={0.25}> <Row gap={0.25}>
...@@ -102,9 +102,10 @@ export default function SwapButton({ disabled }: SwapButtonProps) { ...@@ -102,9 +102,10 @@ export default function SwapButton({ disabled }: SwapButtonProps) {
} }
} else if (approval === ApprovalState.NOT_APPROVED) { } else if (approval === ApprovalState.NOT_APPROVED) {
return { return {
update: { action: {
message: <Trans>Approve {inputCurrencyAmount.currency.symbol} first</Trans>, message: <Trans>Approve {inputCurrencyAmount.currency.symbol} first</Trans>,
action: <Trans>Approve</Trans>, onClick: addApprovalTransaction,
children: <Trans>Approve</Trans>,
}, },
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment