FromWei seems to have stopped FromWei-ing

Morning!

I use FromWei in a few apps and up until about yesterday it worked like a dream! Today everything ends up as NaN. Is there anything that has changed with FromWei?

Thank you!

can you copy your code right here? and which version of Moralis SDK are you using?

Hi @YosephKS

Sure thing. I import from unpkg (see below), so assume that’s always the latest version? If a new version was deployed to unpkg in the last 24 to 36 hours that will be the issue, that’s about when it stopped working across all of my dapps:

<script src="https://unpkg.com/moralis/dist/moralis.js"></script>

The code is straightforward. Below is an example:

<p>A fee of <strong>{Moralis.Units.FromWei(config.Fee)}</strong> applies.</p>

Thank you!

yes there’s actually an update on that, so need to check on it, can you give a concrete number? will be helpful to check the issue

Hi @YosephKS,

Of course :). One of the numbers being turned from Wei to Eth is 1000000000000000. But I have a large range of numbers that use this is another app, calculated dynamically from changing numbers. They all currently say NaN.

Thanks.

Yes no problem, I think one example that gives NaN will be sufficient :raised_hands: will have a check on it~

Hey so just tested out on my side with your number

console.log(Moralis.Units.FromWei("1000000000000000", 18));

and seems like I got 0.001 correctly.

Great! All of my apps still say this whereas they weren’t yesterday:
image

I guess I’ll just divide by 10**18, might be easier.

Thanks.

Oh @YosephKS interesting, you have the decimals of 18 in there. Do you know when that became a requirement?

Thanks

@YosephKS would you mind trying that without the decimals in there? Thanks!

ahhh so previously don’t need decimals and default to 18? hmmm I need to check the older code to see, but I think if I try for sure it will give me NaN like what you are doing. I think might be forgot to add that default 18 in the new one, I’ll try to check and if so update it so it could be backward compatible with the older versions.

Also thanks for your feedback btw~

Just checked, seems like missing that default 18 as you mentioned, which is why the latest version you need to specify the decimals, but I’ll add it back asap now

@YosephKS super! Thank you so much :+1:

1 Like

I’ll let you know once it’s updated :raised_hands: but if you need it really urgent, best to specify all decimals to 18. Thanks a lot for your help too identifying the problem. Cheers~

Amazing, thank you again :smiley:

1 Like

Hey @keyoke, fixed the issue https://github.com/MoralisWeb3/Moralis-JS-SDK/releases/tag/v0.0.182, your issue should be fixed without specifying the decimals value :raised_hands:

Excellent, thank you @YosephKS!

1 Like