Skip to content

Commit

Permalink
fix(trading): fix invalid receive address in DEX swap
Browse files Browse the repository at this point in the history
  • Loading branch information
FreeWall authored and tomasklim committed Feb 27, 2025
1 parent 480c589 commit 7e92e4b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,12 @@ export const useTradingExchangeWatchSendApproval = ({

dispatch(saveSelectedQuote(updatedSelectedQuote));

if (selectedQuote.dexTx) {
await confirmTrade(selectedQuote.dexTx.from, undefined, updatedSelectedQuote);
if (selectedQuote.dexTx && selectedQuote.receiveAddress) {
await confirmTrade(
selectedQuote.receiveAddress,
undefined,
updatedSelectedQuote,
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ export const TradingOfferExchangeSendApproval = () => {
};

const selectApprovalValue = async (type: ExtendedDexApprovalType) => {
if (!selectedQuote.receiveAddress) {
return;
}

setApprovalType(type);
if (type !== 'APPROVED') {
const updatedSelectedQuote = {
Expand All @@ -96,12 +100,16 @@ export const TradingOfferExchangeSendApproval = () => {

dispatch(saveSelectedQuote(updatedSelectedQuote));

await confirmTrade(dexTx.from, undefined, updatedSelectedQuote);
await confirmTrade(selectedQuote.receiveAddress, undefined, updatedSelectedQuote);
}
};

// if the last step was change in approval, we have to recompute the swap request
const proceedToSwap = async () => {
if (!selectedQuote.receiveAddress) {
return;
}

if (selectedQuote.approvalType) {
const updatedSelectedQuote = {
...selectedQuote,
Expand All @@ -114,7 +122,11 @@ export const TradingOfferExchangeSendApproval = () => {
}),
);

const confirmedTrade = await confirmTrade(dexTx.from, undefined, updatedSelectedQuote);
const confirmedTrade = await confirmTrade(
selectedQuote.receiveAddress,
undefined,
updatedSelectedQuote,
);

if (!confirmedTrade) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,11 @@ export const TradingOfferExchangeSendSwap = () => {
if (
selectedQuote &&
selectedQuote?.dexTx &&
selectedQuote.receiveAddress &&
!customSlippageError &&
customSlippage !== selectedQuote.swapSlippage
) {
confirmTrade(selectedQuote.dexTx.from, undefined, {
confirmTrade(selectedQuote.receiveAddress, undefined, {
...selectedQuote,
swapSlippage: customSlippage,
approvalType: undefined,
Expand Down Expand Up @@ -147,9 +148,9 @@ export const TradingOfferExchangeSendSwap = () => {
if (value !== CUSTOM_SLIPPAGE) {
setCustomSlippage(value);

if (!selectedQuote.dexTx) return;
if (!selectedQuote.dexTx || !selectedQuote.receiveAddress) return;

await confirmTrade(selectedQuote.dexTx.from, undefined, {
await confirmTrade(selectedQuote.receiveAddress, undefined, {
...selectedQuote,
swapSlippage: value,
approvalType: undefined,
Expand Down

0 comments on commit 7e92e4b

Please sign in to comment.