Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing incorrectly typed token decimal attribute #10666

Merged
merged 1 commit into from
Mar 19, 2021

Conversation

ryanml
Copy link
Contributor

@ryanml ryanml commented Mar 17, 2021

Fixes: #10665

Essentially if you are to add an NFT, or something with a 0 decimal value that does not allow for override, that gets saved to the state as "0" as opposed to 0, so we causing some component issues. Migrations added to back-fix the issue.

Manual testing steps:
Defined in issue

@ryanml ryanml requested a review from a team as a code owner March 17, 2021 06:31
@ryanml ryanml requested a review from danjm March 17, 2021 06:31
@metamaskbot
Copy link
Collaborator

Builds ready [c8b5794]
Page Load Metrics (1277 ± 101 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaintNaNNaNNaNNaNNaN
domContentLoaded103818511273208100
load104018661277209101
domInteractive103718501272208100


function transformState(state) {
const newState = state;

Copy link
Contributor

Choose a reason for hiding this comment

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

A migration of accountTokens will also be needed. Check out this PR which is also about to migrate tokens and accountTokens: /~https://github.com/MetaMask/metamask-extension/pull/10593/files#diff-0ee44923cc3a183d3803fea2022e1b17f127940f603909b954588cc7c7aa2439R47

And for reference on what those are, see this thread: https://consensys.slack.com/archives/GTQAGKY5V/p1615395521395500?thread_ts=1615332992.380200&cid=GTQAGKY5V

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch here 👍 I believe having these incorrectly typed in part of accountTokens does not produce the UI error in question, but for structural parity they should absolutely be the same.

Copy link
Member

Choose a reason for hiding this comment

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

I see that this is addressed now, but for future reference: it does end up indirectly causing the problem, because tokens gets derived from accountTokens whenever the user switches accounts or networks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Gudahtt - ah, thank you for pointing this out

Copy link
Contributor

@danjm danjm left a comment

Choose a reason for hiding this comment

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

I left one comment that needs to be addressed

@ryanml ryanml force-pushed the token-demical-type-fix branch from c8b5794 to 84facd5 Compare March 17, 2021 18:44
@ryanml ryanml requested a review from danjm March 17, 2021 18:45
}
newState.PreferencesController.tokens = tokens;

const { accountTokens } = newState.PreferencesController || {};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to clean up this pyramid but the linter wasn't having it ;)

@metamaskbot
Copy link
Collaborator

Builds ready [84facd5]
Page Load Metrics (807 ± 80 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaintNaNNaNNaNNaNNaN
domContentLoaded585107480516579
load586107580716680
domInteractive584107480416579

@ryanml ryanml requested a review from Gudahtt March 17, 2021 22:10
danjm
danjm previously approved these changes Mar 18, 2021
Copy link
Contributor

@danjm danjm left a comment

Choose a reason for hiding this comment

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

LGTM

app/scripts/migrations/054.js Outdated Show resolved Hide resolved
const { tokens } = newState.PreferencesController || [];
if (Array.isArray(tokens)) {
for (const token of tokens) {
if (token.decimals === '0') {
Copy link
Member

@Gudahtt Gudahtt Mar 18, 2021

Choose a reason for hiding this comment

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

Are you sure that 0 was the only possible string? 🤔 We could check the type here instead.

The same goes for this comparison in the accountTokens loop as well of course

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Gudahtt - 0 was the only default decimal value I had seen occur during testing of numerous NFT's, but I think you're right that things should extend to check for strings in general. I can make needed updates here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

per our conversation, we are now doing general string primitive checks, as well as looking for an potential corruption that could result in being unable to perform a numerical conversion.

app/scripts/migrations/054.js Outdated Show resolved Hide resolved
@ryanml ryanml force-pushed the token-demical-type-fix branch from 84facd5 to d2af4f2 Compare March 18, 2021 21:47
@ryanml ryanml requested a review from Gudahtt March 18, 2021 21:49
@metamaskbot
Copy link
Collaborator

Builds ready [d2af4f2]
Page Load Metrics (897 ± 100 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint50141812110
domContentLoaded5631174895209100
load5691175897209100
domInteractive5631174895209100

@ryanml ryanml force-pushed the token-demical-type-fix branch from d2af4f2 to 4e3d223 Compare March 19, 2021 03:44
for (const token of validTokens) {
// In the case of a decimal value type string, set to 0.
if (typeof token.decimals === 'string') {
// eslint-disable-next-line radix
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note, per discussion with @Gudahtt we'll let the radix be inferred

@metamaskbot
Copy link
Collaborator

Builds ready [4e3d223]
Page Load Metrics (591 ± 11 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint44685484
domContentLoaded5416385892311
load5426395912311
domInteractive5406375892311

Gudahtt
Gudahtt previously approved these changes Mar 19, 2021
Copy link
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! Couple of comment issues and one suggestion, but looks good otherwise.

app/scripts/migrations/054.js Outdated Show resolved Hide resolved
app/scripts/migrations/054.js Outdated Show resolved Hide resolved
app/scripts/migrations/054.js Outdated Show resolved Hide resolved
@ryanml ryanml force-pushed the token-demical-type-fix branch from 6040195 to 2d32d6f Compare March 19, 2021 16:49
@ryanml ryanml requested a review from Gudahtt March 19, 2021 16:51
Copy link
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!

@metamaskbot
Copy link
Collaborator

Builds ready [2d32d6f]
Page Load Metrics (600 ± 14 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint48845594
domContentLoaded5446615972914
load5456636002914
domInteractive5436615972914

@ryanml ryanml merged commit 530e8c1 into develop Mar 19, 2021
@ryanml ryanml deleted the token-demical-type-fix branch March 19, 2021 17:17
@github-actions github-actions bot locked and limited conversation to collaborators Mar 19, 2021
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.

Warning: Failed prop type: Invalid prop token.decimals of type string supplied to TokenAsset, expected number
4 participants