Skip to content

Conversation

@Ikari-Shinji-re
Copy link
Member

Summary

Please include a summary of the changes and the related issue. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes # (issue)

How did you test this change?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Test A
  • Test B

Checklist:

  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • Implemented a user interface (UI) change, referencing our Figma design to ensure pixel-perfect precision.

Copy link
Contributor

@arlert-armin arlert-armin left a comment

Choose a reason for hiding this comment

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

Thanks for your effort on this. I've just left some comments.

Comment on lines +309 to +322
if (requiredChains.length === 1) {
const walletAddressError =
!selectedWallets.customDestination &&
selectedWallets.sourceWallet?.address !==
selectedWallets.destinationWallet?.address;

if (walletAddressError) {
return {
title: swapButtonTitles().swap,
action: 'show-wallet-address-error',
disabled: false,
};
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need nested ifs? would this also work?

Suggested change
if (requiredChains.length === 1) {
const walletAddressError =
!selectedWallets.customDestination &&
selectedWallets.sourceWallet?.address !==
selectedWallets.destinationWallet?.address;
if (walletAddressError) {
return {
title: swapButtonTitles().swap,
action: 'show-wallet-address-error',
disabled: false,
};
}
}
if (
requiredChains.length === 1 &&
!selectedWallets.customDestination &&
selectedWallets.sourceWallet?.address !== selectedWallets.destinationWallet?.address
) {
return {
title: swapButtonTitles().swap,
action: 'show-wallet-address-error',
disabled: false,
};
}

Also please add a comment explaining what are you checking in here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don’t agree with you. This error occurs only when executing a simple on-chain swap, so we should check for it only in that specific case. I also think extracting the long condition into a variable improves readability — but I’ve added a comment for clarity as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you are missing my point I didn't say you extract condition into a variable I did the exact opposite to reduce nesting.

Copy link
Contributor

@arlert-armin arlert-armin left a comment

Choose a reason for hiding this comment

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

Just add a few comments.

import { useQuoteStore } from '../../store/quote';
import { useConfirmSwap } from '../useConfirmSwap';

export function useHandleConfirmSwap() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Names are too similar to each other; please change the other hook to something more meaningful since currently it's not only responsible for confirming swaps.

Comment on lines +309 to +322
if (requiredChains.length === 1) {
const walletAddressError =
!selectedWallets.customDestination &&
selectedWallets.sourceWallet?.address !==
selectedWallets.destinationWallet?.address;

if (walletAddressError) {
return {
title: swapButtonTitles().swap,
action: 'show-wallet-address-error',
disabled: false,
};
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you are missing my point I didn't say you extract condition into a variable I did the exact opposite to reduce nesting.

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.

3 participants