Skip to content

Commit

Permalink
Merge pull request #1003 from Itheum/d-damian
Browse files Browse the repository at this point in the history
HOTFIX: Callback URL from web wallet tx shouldn't be an offer when that offer does not exist anymore
  • Loading branch information
newbreedofgeek authored Sep 11, 2023
2 parents eecf0f7 + 496a27f commit fdddf06
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "data-dex",
"version": "1.4.0",
"version": "1.4.1",
"description": "The Itheum Data DEX enables you to trade your data using web3 tech",
"dependencies": {
"@chakra-ui/icons": "2.1.0",
Expand Down
9 changes: 7 additions & 2 deletions src/components/ProcureDataNFTModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import {
backendApi,
} from "libs/utils";
import { useAccountStore, useMarketStore } from "store";
import { set } from "react-hook-form";

export interface ProcureAccessModalProps {
isOpen: boolean;
Expand Down Expand Up @@ -178,12 +177,18 @@ export default function ProcureDataNFTModal({ isOpen, onClose, buyerFee, nftData
marketContract.sendAcceptOfferEgldTransaction(offer.index, paymentAmount.toFixed(), amount, address);
} else {
if (offer.wanted_token_nonce === 0) {
//Check if we buy all quantity, use web wallet and are on that offer's details page and thus should use callback route
const isOnOfferPage = window.location.pathname.includes("/offer-");
const shouldUseCallbackRoute = isWebWallet && amount == offer.quantity && isOnOfferPage;
const callbackRoute = "/datanfts/wallet";

const { sessionId } = await marketContract.sendAcceptOfferEsdtTransaction(
offer.index,
paymentAmount.toFixed(),
offer.wanted_token_identifier,
amount as never,
address
address,
shouldUseCallbackRoute ? callbackRoute : undefined
);
setPurchaseSessionId(sessionId);
if (isWebWallet) {
Expand Down
18 changes: 14 additions & 4 deletions src/libs/MultiversX/dataNftMarket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class DataNftMarketContract {
}
}

async sendAcceptOfferEsdtTransaction(index: number, paymentAmount: string, tokenId: string, amount: number, sender: string) {
async sendAcceptOfferEsdtTransaction(index: number, paymentAmount: string, tokenId: string, amount: number, sender: string, callbackRoute?: string) {
const data =
new BigNumber(paymentAmount).comparedTo(0) > 0
? new ContractCallPayloadBuilder()
Expand Down Expand Up @@ -117,13 +117,22 @@ export class DataNftMarketContract {
errorMessage: "Error occurred during accepting offer",
successMessage: "Offer accepted successfully",
},
redirectAfterSign: false,
redirectAfterSign: callbackRoute ? true : false,
callbackRoute: callbackRoute ?? window.location.pathname,
});

return { sessionId, error };
}

async sendAcceptOfferNftEsdtTransaction(index: number, paymentAmount: string, tokenId: string, nonce: number, amount: number, senderAddress: string) {
async sendAcceptOfferNftEsdtTransaction(
index: number,
paymentAmount: string,
tokenId: string,
nonce: number,
amount: number,
senderAddress: string,
callbackRoute?: string
) {
const offerEsdtTx = new Transaction({
value: 0,
data: new ContractCallPayloadBuilder()
Expand Down Expand Up @@ -151,7 +160,8 @@ export class DataNftMarketContract {
errorMessage: "Error occurred during accepting offer",
successMessage: "Offer accepted successfully",
},
redirectAfterSign: false,
redirectAfterSign: callbackRoute ? true : false,
callbackRoute: callbackRoute ?? window.location.pathname,
});

return { sessionId, error };
Expand Down

0 comments on commit fdddf06

Please sign in to comment.