Commit 34431bcb authored by Jack Short's avatar Jack Short Committed by GitHub

feat: porting over transaction screens (#4720)

* feat: porting over transaction screens

* cannot trigger unless flag enabled

* inital comment addressings

* adjusting zIndex

* changing zIndex when modal is open
parent 0041b787
...@@ -2,6 +2,7 @@ import { useWeb3React } from '@web3-react/core' ...@@ -2,6 +2,7 @@ import { useWeb3React } from '@web3-react/core'
import AddressClaimModal from 'components/claim/AddressClaimModal' import AddressClaimModal from 'components/claim/AddressClaimModal'
import ConnectedAccountBlocked from 'components/ConnectedAccountBlocked' import ConnectedAccountBlocked from 'components/ConnectedAccountBlocked'
import TokensBanner from 'components/Tokens/TokensBanner' import TokensBanner from 'components/Tokens/TokensBanner'
import { NftVariant, useNftFlag } from 'featureFlags/flags/nft'
import { TokensVariant, useTokensFlag } from 'featureFlags/flags/tokens' import { TokensVariant, useTokensFlag } from 'featureFlags/flags/tokens'
import useAccountRiskCheck from 'hooks/useAccountRiskCheck' import useAccountRiskCheck from 'hooks/useAccountRiskCheck'
import { lazy } from 'react' import { lazy } from 'react'
...@@ -11,6 +12,7 @@ import { ApplicationModal } from 'state/application/reducer' ...@@ -11,6 +12,7 @@ import { ApplicationModal } from 'state/application/reducer'
const Cart = lazy(() => import('nft/components/sell/modal/ListingTag')) const Cart = lazy(() => import('nft/components/sell/modal/ListingTag'))
const Bag = lazy(() => import('nft/components/bag/Bag')) const Bag = lazy(() => import('nft/components/bag/Bag'))
const TransactionCompleteModal = lazy(() => import('nft/components/collection/TransactionCompleteModal'))
export default function TopLevelModals() { export default function TopLevelModals() {
const addressClaimOpen = useModalIsOpen(ApplicationModal.ADDRESS_CLAIM) const addressClaimOpen = useModalIsOpen(ApplicationModal.ADDRESS_CLAIM)
...@@ -30,6 +32,7 @@ export default function TopLevelModals() { ...@@ -30,6 +32,7 @@ export default function TopLevelModals() {
(location.pathname.includes('/pool') || location.pathname.includes('/swap')) && <TokensBanner />} (location.pathname.includes('/pool') || location.pathname.includes('/swap')) && <TokensBanner />}
<Cart /> <Cart />
<Bag /> <Bag />
{useNftFlag() === NftVariant.Enabled && <TransactionCompleteModal />}
</> </>
) )
} }
...@@ -13,7 +13,6 @@ export const bagContainer = style([ ...@@ -13,7 +13,6 @@ export const bagContainer = style([
color: 'textPrimary', color: 'textPrimary',
paddingTop: '20', paddingTop: '20',
paddingBottom: '24', paddingBottom: '24',
zIndex: { sm: 'offcanvas', md: '3' },
}), }),
{ {
'@media': { '@media': {
......
...@@ -314,7 +314,7 @@ const Bag = () => { ...@@ -314,7 +314,7 @@ const Bag = () => {
<> <>
{bagExpanded && shouldShowBag ? ( {bagExpanded && shouldShowBag ? (
<Portal> <Portal>
<Column className={styles.bagContainer}> <Column zIndex={isMobile || isOpen ? 'modal' : '3'} className={styles.bagContainer}>
<BagHeader numberOfAssets={itemsInBag.length} toggleBag={toggleBag} resetFlow={reset} /> <BagHeader numberOfAssets={itemsInBag.length} toggleBag={toggleBag} resetFlow={reset} />
{itemsInBag.length === 0 && bagStatus === BagStatus.ADDING_TO_BAG && <EmptyState />} {itemsInBag.length === 0 && bagStatus === BagStatus.ADDING_TO_BAG && <EmptyState />}
<ScrollingIndicator top show={userCanScroll && scrollProgress > 0} /> <ScrollingIndicator top show={userCanScroll && scrollProgress > 0} />
......
This diff is collapsed.
This diff is collapsed.
...@@ -11,7 +11,7 @@ export const overlay = style([ ...@@ -11,7 +11,7 @@ export const overlay = style([
position: 'fixed', position: 'fixed',
display: 'block', display: 'block',
background: 'black', background: 'black',
zIndex: '2', zIndex: 'modalBackdrop',
}), }),
{ {
opacity: 0.72, opacity: 0.72,
......
...@@ -12,14 +12,6 @@ import CryptoPunksMarket from '../abis/CryptoPunksMarket.json' ...@@ -12,14 +12,6 @@ import CryptoPunksMarket from '../abis/CryptoPunksMarket.json'
import { GenieAsset, RouteResponse, RoutingItem, TxResponse, TxStateType, UpdatedGenieAsset } from '../types' import { GenieAsset, RouteResponse, RoutingItem, TxResponse, TxStateType, UpdatedGenieAsset } from '../types'
import { combineBuyItemsWithTxRoute } from '../utils/txRoute/combineItemsWithTxRoute' import { combineBuyItemsWithTxRoute } from '../utils/txRoute/combineItemsWithTxRoute'
// Shortens a given txHash. With standard charsToShorten var of 4, a hash will become 0x1234...1234
export const shortenTxHash = (txHash: string, charsToShorten = 4, addCharsToBack = 0): string => {
return `${txHash.substring(0, charsToShorten + 2)}...${txHash.substring(
txHash.length - charsToShorten,
txHash.length - (charsToShorten + addCharsToBack)
)}`
}
interface TxState { interface TxState {
state: TxStateType state: TxStateType
setState: (state: TxStateType) => void setState: (state: TxStateType) => void
......
import { TxResponse } from 'nft/types'
import create from 'zustand' import create from 'zustand'
import { devtools } from 'zustand/middleware' import { devtools } from 'zustand/middleware'
import { TxResponse } from '../types'
type TransactionResponseValue = TxResponse | undefined type TransactionResponseValue = TxResponse | undefined
type TransactionResponseState = { type TransactionResponseState = {
......
...@@ -2,8 +2,11 @@ export * from './buildActivityAsset' ...@@ -2,8 +2,11 @@ export * from './buildActivityAsset'
export * from './buildSellObject' export * from './buildSellObject'
export * from './calcPoolPrice' export * from './calcPoolPrice'
export * from './currency' export * from './currency'
export * from './fetchPrice'
export * from './isAudio' export * from './isAudio'
export * from './isVideo' export * from './isVideo'
export * from './listNfts' export * from './listNfts'
export * from './putCommas' export * from './putCommas'
export * from './rarity' export * from './rarity'
export * from './transactionResponse'
export * from './updatedAssets'
import { BigNumber } from '@ethersproject/bignumber'
import { formatEther } from '@ethersproject/units'
import { TxResponse, UpdatedGenieAsset } from 'nft/types'
import { getTotalNftValue } from 'nft/utils'
// Shortens a given txHash. With standard charsToShorten var of 4, a hash will become 0x1234...1234
export const shortenTxHash = (txHash: string, charsToShorten = 4, addCharsToBack = 0): string => {
return `${txHash.substring(0, charsToShorten + 2)}...${txHash.substring(
txHash.length - charsToShorten,
txHash.length - (charsToShorten + addCharsToBack)
)}`
}
export const parseTransactionResponse = (transactionResponse: TxResponse | undefined, ethPrice: number) => {
let nftsPurchased: UpdatedGenieAsset[] = []
let nftsNotPurchased: UpdatedGenieAsset[] = []
let showPurchasedModal = false
let showRefundModal = false
let totalPurchaseValue = BigNumber.from(0)
let totalRefundValue = BigNumber.from(0)
let totalUSDRefund = 0
let txFeeFiat = 0
if (transactionResponse !== undefined) {
const { nftsPurchased: purchasedNfts, nftsNotPurchased: notPurchasedNfts, txReceipt } = transactionResponse
if (nftsPurchased && nftsNotPurchased && txReceipt) {
nftsPurchased = purchasedNfts
nftsNotPurchased = notPurchasedNfts
showPurchasedModal = nftsPurchased.length >= 1
showRefundModal = nftsNotPurchased.length >= 1
totalPurchaseValue = getTotalNftValue(nftsPurchased)
totalRefundValue = getTotalNftValue(nftsNotPurchased)
totalUSDRefund = totalRefundValue && parseFloat(formatEther(totalRefundValue)) * ethPrice
const txFee = BigNumber.from(txReceipt ? txReceipt.gasUsed : 0).mul(
BigNumber.from(txReceipt ? txReceipt.effectiveGasPrice : 0)
)
txFeeFiat = parseFloat(formatEther(txFee)) * ethPrice
}
}
return {
nftsPurchased,
nftsNotPurchased,
showPurchasedModal,
showRefundModal,
totalPurchaseValue,
totalRefundValue,
totalUSDRefund,
txFeeFiat,
}
}
// Given the length of the array of successfully purchased NFTs, returns the maxHeight and maxWidth of each asset preview
export const getSuccessfulImageSize = (numSuccessful: number, isMobile: boolean) => {
const sizeModifier = isMobile ? 2 : 1
if (numSuccessful === 1) {
return 574 / sizeModifier
} else if (numSuccessful === 2) {
return 280 / sizeModifier
} else if (numSuccessful === 3 || (numSuccessful >= 5 && numSuccessful < 7)) {
return 184 / sizeModifier
} else if (numSuccessful === 4 || (numSuccessful >= 7 && numSuccessful < 13)) {
return 136 / sizeModifier
} else if (numSuccessful >= 13 && numSuccessful < 21) {
return 108 / sizeModifier
} else return isMobile ? 39 : 64
}
...@@ -9,3 +9,14 @@ export const updatedAssetPriceDifference = (asset: UpdatedGenieAsset) => { ...@@ -9,3 +9,14 @@ export const updatedAssetPriceDifference = (asset: UpdatedGenieAsset) => {
export const sortUpdatedAssets = (x: UpdatedGenieAsset, y: UpdatedGenieAsset) => { export const sortUpdatedAssets = (x: UpdatedGenieAsset, y: UpdatedGenieAsset) => {
return updatedAssetPriceDifference(x).gt(updatedAssetPriceDifference(y)) ? -1 : 1 return updatedAssetPriceDifference(x).gt(updatedAssetPriceDifference(y)) ? -1 : 1
} }
export const getTotalNftValue = (nfts: UpdatedGenieAsset[]): BigNumber => {
return (
nfts &&
nfts.reduce(
(ethTotal, nft) =>
ethTotal.add(BigNumber.from(nft.updatedPriceInfo ? nft.updatedPriceInfo.ETHPrice : nft.priceInfo.ETHPrice)),
BigNumber.from(0)
)
)
}
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