Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add accept trade flow #2268

Merged
merged 8 commits into from
Jul 19, 2024
Merged

feat: add accept trade flow #2268

merged 8 commits into from
Jul 19, 2024

Conversation

meelrossi
Copy link
Contributor

Add flow to accept bids from offchain marketplace

Copy link

vercel bot commented Jul 16, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
marketplace ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 18, 2024 11:14pm

@coveralls
Copy link

coveralls commented Jul 17, 2024

Coverage Status

coverage: 66.468% (-0.2%) from 66.682%
when pulling 67fe170 on feat/accept-trade
into e51db0a on feat/offchain-bids.

<Button primary onClick={() => history.push(locations.bid(bid.contractAddress, bid.tokenId))}>
{t('global.update')}
</Button>
{'bidAddress' in bid && (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we show a disabled state/message when the bidAddress is not present in the bid?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the bidaddress is not in the bid then it means that is one of the "new" bids created by a trade. This new bids can't be updated. The process requires the cancellation of the previous trade and hte addition of the new one. That is why the button should not even appear.

@@ -108,7 +108,7 @@ const BidsTable = (props: Props) => {
handleSortByChange={(value: string) => setSortBy(value as BidSortBy)}
sortBy={sortBy}
/>
{showConfirmationModal.bid && showConfirmationModal.display ? (
{showConfirmationModal.bid && showConfirmationModal.display && 'tokenId' in showConfirmationModal.bid ? (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we refactor this check as isLegacyBid(bid), it might be faster to understand what's being asserted, right? If this function also uses the is keyword, it can help you correctly type each type of bid.

@@ -99,7 +99,7 @@ export const cancelBidSuccess = (bid: Bid, txHash: string) =>
action(CANCEL_BID_SUCCESS, {
bid,
...buildTransactionPayload(bid.chainId, txHash, {
tokenId: bid.tokenId,
...('tokenId' in bid ? { tokenId: bid.tokenId } : { itemId: bid.itemId }),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change will affect the Transaction component in the ActivityPage, we might wat to add the support for these types of transactions as well.

Comment on lines +106 to +110
txHash = yield call(
sendTransaction as (contract: ContractData, contractMethodName: string, ...contractArguments: any[]) => Promise<string>,
offchainMarketplaceContract,
'function accept(Trade[] calldata _trades) external;',
[tradeToAccept]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a future refactor, we might want to consider moving this section of code to the service, with a dedicated acceptOfChain method. It will make it easier to test as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added one task to the backlog to handle this

@@ -111,7 +98,44 @@ export async function getTradeSignature(trade: Omit<TradeCreation, 'signature'>)
beneficiary: asset.beneficiary
}))
}
}

export function getTradeToAccept(trade: Trade) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be importante to test these function to be sure that the trade is being built correctly, would you mind adding tests for them?

Comment on lines 183 to 186
sellerBids = ((yield call([marketplaceAPI, 'fetchBids'])) as Awaited<ReturnType<typeof marketplaceAPI.fetchBids>>).results // TODO: add seller filter
bidderBids = (
(yield call([marketplaceAPI, 'fetchBids'], { bidder: address })) as Awaited<ReturnType<typeof marketplaceAPI.fetchBids>>
).results
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we make this request using yield all as the one below is doing? That should speed up the loading of the bids.

marketplaceAPIMock = { fetchTrade: jest.fn().mockResolvedValue(trade) } as unknown as jest.Mocked<MarketplaceAPI>
})

it.only('should dispatch an action signaling the success of the action handling', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A wild only has appeared

@meelrossi meelrossi changed the base branch from master to feat/offchain-bids July 18, 2024 21:10
@meelrossi meelrossi merged commit fce5433 into feat/offchain-bids Jul 19, 2024
9 checks passed
@meelrossi meelrossi deleted the feat/accept-trade branch July 19, 2024 13:53
@meelrossi meelrossi mentioned this pull request Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants