Skip to content

Commit

Permalink
feat: add support for trades in cross chain flow
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmahidalgo committed Sep 30, 2024
1 parent 0167790 commit 1d9795f
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions webapp/src/components/Modals/BuyWithCryptoModal/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import { Wallet } from 'decentraland-dapps/dist/modules/wallet'
import type { CrossChainProvider, Route, RouteResponse, Token } from 'decentraland-transactions/crossChain'
import { ContractName, getContract } from 'decentraland-transactions'
import { NFT } from '../../../modules/nft/types'
import { TradeService } from '../../../modules/vendor/decentraland/TradeService'
import * as events from '../../../utils/events'
import { getOnChainTrade } from '../../../utils/trades'
import { estimateBuyNftGas, estimateMintNftGas, estimateNameMintingGas, formatPrice, getShouldUseMetaTx } from './utils'

export const NATIVE_TOKEN = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE'
Expand Down Expand Up @@ -219,7 +221,14 @@ export const useCrossChainMintNftRoute = (
item: {
collectionAddress: item.contractAddress,
itemId: item.itemId,
price: item.price
price: item.price,
tradeId: item.tradeId
},
fetchTradeData: async () => {
const trade = await new TradeService(() => undefined).fetchTrade(item.tradeId as string)
return {
onChainTrade: getOnChainTrade(trade, fromAddress)
}
}
}),
[item]
Expand Down Expand Up @@ -256,11 +265,16 @@ export const useCrossChainBuyNftRoute = (
fromToken,
toAmount: order.price,
toChain: order.chainId,
nft: {
collectionAddress: order.contractAddress,
tokenId: order.tokenId,
price: order.price
},
order,
fetchTradeData:
order.tradeId && wallet?.address
? async () => {
const trade = await new TradeService(() => undefined).fetchTrade(order.tradeId as string)
return {
onChainTrade: getOnChainTrade(trade, wallet.address)

Check failure on line 274 in webapp/src/components/Modals/BuyWithCryptoModal/hooks.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `·`

Check failure on line 274 in webapp/src/components/Modals/BuyWithCryptoModal/hooks.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `·`
}
}
: undefined,
slippage
}),
[order]
Expand Down

0 comments on commit 1d9795f

Please sign in to comment.