Skip to content

Commit

Permalink
fix: display relevant link in Order Submitted modal (#2788)
Browse files Browse the repository at this point in the history
  • Loading branch information
shoom3301 authored Jul 6, 2023
1 parent fe875e1 commit b683402
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 26 deletions.
6 changes: 3 additions & 3 deletions src/common/pure/OrderSubmittedContent/index.cosmos.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { SupportedChainId } from '@cowprotocol/cow-sdk'

import styled from 'styled-components/macro'

import { OrderSubmittedContent } from './index'

const defaultProps = {
chainId: SupportedChainId.MAINNET,
chainId: 1,
account: '0x0001',
isSafeWallet: false,
hash: '0x62baf4be8adec4766d26a2169999cc170c3ead90ae11a28d658e6d75edc05b185b0abe214ab7875562adee331deff0fe1912fe42644d2bb7',
onDismiss() {
console.log('onDismiss')
Expand Down
22 changes: 15 additions & 7 deletions src/common/pure/OrderSubmittedContent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { Trans } from '@lingui/macro'
import styled from 'styled-components/macro'

import { ButtonPrimary } from 'legacy/components/Button'
import { ExternalLink } from 'legacy/theme'
import { getEtherscanLink as getExplorerLink } from 'legacy/utils'
import { EnhancedTransactionLink } from 'legacy/components/EnhancedTransactionLink'
import { HashType } from 'legacy/state/enhancedTransactions/reducer'

import AnimatedConfirmation from 'common/pure/AnimatedConfirmation'

Expand All @@ -31,20 +31,28 @@ const ActionButton = styled(ButtonPrimary)`
export interface OrderSubmittedContentProps {
onDismiss(): void
chainId: SupportedChainId
isSafeWallet: boolean
account: string
hash: string
}

export function OrderSubmittedContent({ chainId, hash, onDismiss }: OrderSubmittedContentProps) {
export function OrderSubmittedContent({ chainId, account, isSafeWallet, hash, onDismiss }: OrderSubmittedContentProps) {
const tx = {
hash,
hashType: isSafeWallet ? HashType.GNOSIS_SAFE_TX : HashType.ETHEREUM_TX,
safeTransaction: {
safeTxHash: hash,
safe: account,
},
}

return (
<Wrapper>
<AnimatedConfirmation />
<Caption>
<Trans>Order Submitted</Trans>
</Caption>
{/*TODO: unify and fix explorer link. Refs: ExplorerLink, DisplayLink, EnhancedTransactionLink*/}
<ExternalLink href={getExplorerLink(chainId, hash, 'transaction')}>
<Trans>View on Explorer ↗</Trans>
</ExternalLink>
<EnhancedTransactionLink chainId={chainId} tx={tx} />
<ActionButton onClick={onDismiss}>
<Trans>Close</Trans>
</ActionButton>
Expand Down
21 changes: 11 additions & 10 deletions src/legacy/components/EnhancedTransactionLink/index.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
import { ExplorerLink } from 'legacy/components/ExplorerLink'
import { EnhancedTransactionDetails, HashType } from 'legacy/state/enhancedTransactions/reducer'
import { SupportedChainId } from '@cowprotocol/cow-sdk'

import { useGnosisSafeInfo, useWalletInfo } from 'modules/wallet'
import { ExplorerLink } from 'legacy/components/ExplorerLink'
import { HashType } from 'legacy/state/enhancedTransactions/reducer'

import { SafeWalletLink } from 'common/pure/SafeWalletLink'

interface Props {
tx: EnhancedTransactionDetails
chainId: SupportedChainId
tx: {
hash: string
hashType: HashType
safeTransaction?: { safe: string; safeTxHash: string }
}
}

/**
* Creates a link to the relevant explorer: Etherscan, GP Explorer or Blockscout, or Gnosis Safe web if its a Gnosis Safe Transaction
* @param props
*/
export function EnhancedTransactionLink(props: Props) {
const { tx } = props
const { chainId } = useWalletInfo()
const gnosisSafeInfo = useGnosisSafeInfo()
const { tx, chainId } = props

if (tx.hashType === HashType.GNOSIS_SAFE_TX) {
const safeTx = tx.safeTransaction

if (!chainId || !safeTx || !gnosisSafeInfo) {
return null
}
if (!safeTx) return null

return <SafeWalletLink chainId={chainId} safeTransaction={safeTx} />
} else {
Expand Down
17 changes: 13 additions & 4 deletions src/modules/trade/containers/TradeConfirmModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react'

import { isSupportedChain } from 'legacy/utils/supportedChainId'

import { useWalletInfo } from 'modules/wallet'
import { useIsSafeWallet, useWalletInfo } from 'modules/wallet'

import { CowModal } from 'common/pure/Modal'
import { OrderSubmittedContent } from 'common/pure/OrderSubmittedContent'
Expand All @@ -21,11 +21,12 @@ export interface TradeConfirmModalProps {
export function TradeConfirmModal(props: TradeConfirmModalProps) {
const { children } = props

const { chainId } = useWalletInfo()
const { chainId, account } = useWalletInfo()
const isSafeWallet = useIsSafeWallet()
const { isOpen, pendingTrade, transactionHash, error } = useAtomValue(tradeConfirmStateAtom)
const { onDismiss } = useTradeConfirmActions()

if (!isSupportedChain(chainId)) return null
if (!isSupportedChain(chainId) || !account) return null

return (
<CowModal isOpen={isOpen} onDismiss={onDismiss}>
Expand All @@ -40,7 +41,15 @@ export function TradeConfirmModal(props: TradeConfirmModalProps) {

// TODO: use <TransactionSubmittedContent/> for Swap
if (transactionHash) {
return <OrderSubmittedContent chainId={chainId} onDismiss={onDismiss} hash={transactionHash} />
return (
<OrderSubmittedContent
chainId={chainId}
account={account}
isSafeWallet={isSafeWallet}
onDismiss={onDismiss}
hash={transactionHash}
/>
)
}

return children
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Claim/ClaimingStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ export default function ClaimingStatus({ handleChangeAccount }: ClaimNavProps) {
</p>
</AttemptFooter>
)}
{isSubmitted && chainId && lastClaimTx?.hash && <EnhancedTransactionLink tx={lastClaimTx} />}
{isSubmitted && chainId && lastClaimTx?.hash && <EnhancedTransactionLink chainId={chainId} tx={lastClaimTx} />}

{isFailure && (
<>
{chainId && lastClaimTx?.hash && <EnhancedTransactionLink tx={lastClaimTx} />}
{chainId && lastClaimTx?.hash && <EnhancedTransactionLink chainId={chainId} tx={lastClaimTx} />}
<AttemptFooter>
<p>The claim transaction failed. Please check the network parameters and try again.</p>
</AttemptFooter>
Expand Down

0 comments on commit b683402

Please sign in to comment.