Skip to content

Commit

Permalink
feat: implement explorer fee break down
Browse files Browse the repository at this point in the history
  • Loading branch information
alfetopito committed Dec 30, 2024
1 parent b0857c2 commit 9ec0deb
Showing 1 changed file with 46 additions and 46 deletions.
92 changes: 46 additions & 46 deletions apps/explorer/src/components/orders/GasFeeDisplay/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useMemo } from 'react'

import { isSellOrder } from '@cowprotocol/common-utils'
import { Nullish } from '@cowprotocol/ui'

import { TokenErc20 } from '@gnosis.pm/dex-js'
Expand All @@ -12,7 +11,6 @@ import { formatSmartMaxPrecision, safeTokenName } from 'utils'

import { Order } from 'api/operator'


const Wrapper = styled.div`
> span {
margin: 0 0.5rem 0 0;
Expand Down Expand Up @@ -71,51 +69,53 @@ export function GasFeeDisplay({ order }: Props): React.ReactNode | null {
)
}

function getFeeDisplayAmounts(order: Order) {
const {
kind,
networkCosts,
protocolFees,
sellToken,
sellTokenAddress,
buyToken,
buyTokenAddress,
totalFee,
feeAmount,
} = order

const isSell = isSellOrder(kind)

let quoteSymbol = ''
let formattedNetworkCosts = ''
let formattedProtocolFees = ''
let formattedExecutedFee = ''
let formattedTotalFee = ''

// When these 2 are set, for sure we have new style fees
if (networkCosts || protocolFees) {
if (isSell) {
quoteSymbol = buyToken ? safeTokenName(buyToken) : buyTokenAddress
formattedNetworkCosts = getFormattedAmount(networkCosts || ZERO_BIG_NUMBER, buyToken)
formattedProtocolFees = getFormattedAmount(protocolFees || ZERO_BIG_NUMBER, buyToken)
formattedExecutedFee = getFormattedAmount(totalFee, buyToken)
formattedTotalFee = getFormattedAmount(feeAmount, buyToken)
} else {
quoteSymbol = sellToken ? safeTokenName(sellToken) : sellTokenAddress
formattedNetworkCosts = getFormattedAmount(networkCosts || ZERO_BIG_NUMBER, sellToken)
formattedProtocolFees = getFormattedAmount(protocolFees || ZERO_BIG_NUMBER, sellToken)
formattedExecutedFee = getFormattedAmount(totalFee, sellToken)
formattedTotalFee = getFormattedAmount(feeAmount, sellToken)
}
} else {
// Otherwise, it can have no fees OR be old style fees, without the policies
// TODO: handle old and new styles, as the fee token will vary! (always sell for old vs surplus token for new)
quoteSymbol = sellToken ? safeTokenName(sellToken) : sellTokenAddress
formattedNetworkCosts = ''
formattedProtocolFees = ''
formattedExecutedFee = getFormattedAmount(totalFee, sellToken)
formattedTotalFee = getFormattedAmount(feeAmount, sellToken)
function getFeeToken(order: Order) {
const { sellToken, buyToken } = order
const { executedFeeToken } = order
if (sellToken?.address.toLowerCase() === executedFeeToken?.toLowerCase()) {
return sellToken
}
if (buyToken?.address.toLowerCase() === executedFeeToken?.toLowerCase()) {
return buyToken
}
return undefined
}

function getFeeDisplayAmounts(order: Order) {
const { networkCosts, protocolFees, totalFee, executedFeeToken, feeAmount } = order

const feeToken = getFeeToken(order)

const quoteSymbol = feeToken ? safeTokenName(feeToken) : executedFeeToken
const formattedNetworkCosts = getFormattedAmount(networkCosts || ZERO_BIG_NUMBER, feeToken)
const formattedProtocolFees = getFormattedAmount(protocolFees || ZERO_BIG_NUMBER, feeToken)
const formattedExecutedFee = getFormattedAmount(totalFee, feeToken)
const formattedTotalFee = getFormattedAmount(feeAmount, feeToken)
//
// // When these 2 are set, for sure we have new style fees
// if (networkCosts || protocolFees) {
// if (isSell) {
// quoteSymbol = feeToken ? safeTokenName(feeToken) : executedFeeToken
// formattedNetworkCosts = getFormattedAmount(networkCosts || ZERO_BIG_NUMBER, feeToken)
// formattedProtocolFees = getFormattedAmount(protocolFees || ZERO_BIG_NUMBER, feeToken)
// formattedExecutedFee = getFormattedAmount(totalFee, feeToken)
// formattedTotalFee = getFormattedAmount(feeAmount, feeToken)
// } else {
// quoteSymbol = feeToken ? safeTokenName(feeToken) : executedFeeToken
// formattedNetworkCosts = getFormattedAmount(networkCosts || ZERO_BIG_NUMBER, feeToken)
// formattedProtocolFees = getFormattedAmount(protocolFees || ZERO_BIG_NUMBER, feeToken)
// formattedExecutedFee = getFormattedAmount(totalFee, feeToken)
// formattedTotalFee = getFormattedAmount(feeAmount, feeToken)
// }
// } else {
// // Otherwise, it can have no fees OR be old style fees, without the policies
// // TODO: handle old and new styles, as the fee token will vary! (always sell for old vs surplus token for new)
// quoteSymbol = sellToken ? safeTokenName(sellToken) : sellTokenAddress
// formattedNetworkCosts = ''
// formattedProtocolFees = ''
// formattedExecutedFee = getFormattedAmount(totalFee, sellToken)
// formattedTotalFee = getFormattedAmount(feeAmount, sellToken)
// }

return {
quoteSymbol,
Expand Down

0 comments on commit 9ec0deb

Please sign in to comment.