Skip to content

Remove dash from token value in swap#9739

Closed
tmashuang wants to merge 3 commits intodevelopfrom
remove-dash
Closed

Remove dash from token value in swap#9739
tmashuang wants to merge 3 commits intodevelopfrom
remove-dash

Conversation

@tmashuang
Copy link
Copy Markdown
Contributor

The swapTokenValue is coming in with a - prefix already during the conversion process. This removes/replaces the -.

Before
After

@tmashuang tmashuang requested a review from a team as a code owner October 27, 2020 22:36
@tmashuang tmashuang requested a review from Gudahtt October 27, 2020 22:36
@github-actions
Copy link
Copy Markdown
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

Copy link
Copy Markdown
Member

@Gudahtt Gudahtt 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 taking a look at this! We do need to eliminate this extra dash, but I think this would give the wrong answer in some cases.


export function removeDash (str = '') {
return str
.replace(/[-]/u, '')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the square brackets here are unnecessary:

Suggested change
.replace(/[-]/u, '')
.replace(/-/u, '')

? currentAsset.symbol
: initialTransaction.sourceTokenSymbol
primaryDisplayValue = swapTokenValue
primaryDisplayValue = removeDash(swapTokenValue)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this would give us the wrong answer in any case where the dash exists. It is important to know whether this is a negative value or not.

For example, in this case I encountered:

plus-minus

In this case, isViewingReceivedTokenFromSwap was true, so the prefix would be +. But we're losing ETH here, so the correct prefix is -.

I think we want to do two things here:

  • "reverse" the prefix used (e.g. add or remove a dash, or multiply by -1, whichever) if isViewingReceivedTokenFromSwap is false, and
  • add + if the resulting number is positive.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems like something we should handle in useSwappedTokenValue 🤔 . We already look at isViewingReceivedTokenFromSwap in that hook.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

But we're losing ETH here, so the correct prefix is -.

Wait if you swap a token to ETH, we are losing ETH?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Wait if you swap a token to ETH, we are losing ETH?

Potentially, yep! In this case, I lost money because the transaction failed on-chain. I had to pay the gas fee but I got nothing in return.

@tmashuang tmashuang marked this pull request as draft October 27, 2020 23:16
@tmashuang
Copy link
Copy Markdown
Contributor Author

Also, seems when a swap is pending the swapTokenValue is null. Maybe conditional should be used there, but seems that there needs to be a bigger PR that addresses some of the comments.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 28, 2020
@HowardBraham HowardBraham deleted the remove-dash branch January 19, 2026 18:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants