Skip to content

Check if swapTokenValue is negative and set prefix accordingly#9743

Merged
tmashuang merged 3 commits intodevelopfrom
check-negative-swapTokenValue
Oct 28, 2020
Merged

Check if swapTokenValue is negative and set prefix accordingly#9743
tmashuang merged 3 commits intodevelopfrom
check-negative-swapTokenValue

Conversation

@tmashuang
Copy link
Copy Markdown
Contributor

Closes #9739, alternative PR that addresses how to present negative values.

Before
After

@tmashuang tmashuang requested a review from a team as a code owner October 28, 2020 06:08
@tmashuang tmashuang requested a review from rekmarks October 28, 2020 06:08
@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.

Comment on lines +148 to +154
if (isNegative) {
prefix = ''
} else if (isViewingReceivedTokenFromSwap && !isNegative) {
prefix = '+'
} else {
prefix = '-'
}
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 wrote out the four different branches to help myself think through it:

Suggested change
if (isNegative) {
prefix = ''
} else if (isViewingReceivedTokenFromSwap && !isNegative) {
prefix = '+'
} else {
prefix = '-'
}
if (isViewingReceivedTokenFromSwap) {
if (isNegative) {
// do nothing - the minus should already be there
} else {
prefix = '+'
}
} else {
if (isNegative) {
// this case should be impossible - how can you send _negative_ tokens?
} else {
// a positive value should be shown as a loss, as this is the amount of tokens sent.
prefix = '-'
}
}

The only one you're missing is where a negative amount of tokens was sent, and I can't imagine how that would be possible. So I think your logic here is sound.

Gudahtt
Gudahtt previously approved these changes Oct 28, 2020
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.

LGTM! Just one minor suggestion to simplify that one conditional.

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [5ed6711]
Page Load Metrics (433 ± 58 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint328641147
domContentLoaded27663743112158
load27763943312158
domInteractive27663743112158

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [c66dd0f]
Page Load Metrics (415 ± 55 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint298837136
domContentLoaded30061641311555
load30261741511555
domInteractive30061541311555

@tmashuang tmashuang merged commit 0494f72 into develop Oct 28, 2020
@tmashuang tmashuang deleted the check-negative-swapTokenValue branch October 28, 2020 07:08
@github-actions github-actions bot locked and limited conversation to collaborators Oct 28, 2020
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.

3 participants