Skip to content

Commit

Permalink
fix: approval action button (#3297)
Browse files Browse the repository at this point in the history
  • Loading branch information
zzmp authored Feb 11, 2022
1 parent a7fb7dc commit 897e7f4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
9 changes: 8 additions & 1 deletion src/lib/components/ActionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,17 @@ export const Overlay = styled(Row)<{ action?: boolean }>`
${({ action }) => action && actionCss}
`

export interface Action {
message: ReactNode
icon?: Icon
onClick: () => void
children: ReactNode
}

export interface ActionButtonProps {
color?: Color
disabled?: boolean
action?: { message: ReactNode; icon?: Icon; onClick: () => void; children: ReactNode }
action?: Action
onClick: () => void
children: ReactNode
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/Swap/Summary/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { formatCurrencyAmount, formatPrice } from 'utils/formatCurrencyAmount'
import { computeRealizedPriceImpact } from 'utils/prices'
import { tradeMeaningfullyDiffers } from 'utils/tradeMeaningFullyDiffer'

import ActionButton from '../../ActionButton'
import ActionButton, { Action } from '../../ActionButton'
import Column from '../../Column'
import { Header } from '../../Dialog'
import Row from '../../Row'
Expand Down Expand Up @@ -112,7 +112,7 @@ export function SummaryDialog({ trade, allowedSlippage, onConfirm }: SummaryDial
[confirmedTrade, trade]
)

const action = useMemo(() => {
const action = useMemo((): Action | undefined => {
if (doesTradeDiffer) {
return {
message: <Trans>Price updated</Trans>,
Expand Down
11 changes: 6 additions & 5 deletions src/lib/components/Swap/SwapButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react'
import invariant from 'tiny-invariant'
import { ExplorerDataType } from 'utils/getExplorerLink'

import ActionButton from '../ActionButton'
import ActionButton, { ActionButtonProps } from '../ActionButton'
import Dialog from '../Dialog'
import EtherscanLink from '../EtherscanLink'
import Row from '../Row'
Expand Down Expand Up @@ -76,7 +76,7 @@ export default function SwapButton({ disabled }: SwapButtonProps) {
})
}, [addTransaction, getApproval])

const actionProps = useMemo(() => {
const actionProps = useMemo((): Partial<ActionButtonProps> | undefined => {
if (disabled) return { disabled: true }

if (chainId && inputCurrencyAmount) {
Expand All @@ -85,7 +85,7 @@ export default function SwapButton({ disabled }: SwapButtonProps) {
} else if (approval === ApprovalState.PENDING) {
return {
disabled: true,
update: {
action: {
message: (
<EtherscanLink type={ExplorerDataType.TRANSACTION} data={approvalHash}>
<Row gap={0.25}>
Expand All @@ -102,9 +102,10 @@ export default function SwapButton({ disabled }: SwapButtonProps) {
}
} else if (approval === ApprovalState.NOT_APPROVED) {
return {
update: {
action: {
message: <Trans>Approve {inputCurrencyAmount.currency.symbol} first</Trans>,
action: <Trans>Approve</Trans>,
onClick: addApprovalTransaction,
children: <Trans>Approve</Trans>,
},
}
}
Expand Down

0 comments on commit 897e7f4

Please sign in to comment.