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

Finance: fix token fallbacks and error handling #813

Merged
merged 4 commits into from
Apr 18, 2019
Merged

Conversation

sohkai
Copy link
Contributor

@sohkai sohkai commented Apr 17, 2019

Fixes aragon/client#734.

With aragon/aragon.js#277 we now get the actual errors back from the RPC when a call goes wrong (e.g. naive token.symbol() on DAI) and we need to handle these explicitly.

This PR converts a lot of the token fallback-related bits into simpler Promise-based code and adds explicit handlers for their error cases.

@coveralls
Copy link

coveralls commented Apr 18, 2019

Coverage Status

Coverage remained the same at 97.015% when pulling e8ccf6c on finance-fix-dai into 0bf6ff4 on master.

@@ -167,16 +168,20 @@ class Deposit extends React.Component {
}

const [tokenSymbol, tokenDecimals] = await Promise.all([
getTokenSymbol(api, address),
token.decimals().toPromise(),
getTokenSymbol(api, address).catch(() => {}),
Copy link
Contributor

Choose a reason for hiding this comment

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

Super nitpicky but should we return explicit values (null) rather than implicit undefined in these cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah... we should probably settle on a convention for handling errors and their "safe" default values.

In the case of the balance check above, I opted for "0" since it'll show "no balances" but we could probably use "-1" as "couldn't find balance".

Copy link
Contributor Author

@sohkai sohkai Apr 18, 2019

Choose a reason for hiding this comment

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

I've now changed it to use -1 for the balance if the balance call failed and default the symbol and name values to '' (since they're optional strings for the token to implement) in a067c7c.

return ''
}

return userBalance === -1
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 this should be '-1'?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😅 this is why I need a second pair of eyes 😄

@sohkai sohkai merged commit f207a7e into master Apr 18, 2019
Copy link
Contributor

@bpierre bpierre left a comment

Choose a reason for hiding this comment

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

💯 💯 💯

@sohkai sohkai deleted the finance-fix-dai branch April 18, 2019 08:06
ramilexe pushed a commit to ConsiderItDone/aragon-apps that referenced this pull request Dec 9, 2021
Fixes aragon/client#734.

With aragon/aragon.js#277 we now get the actual errors back from the RPC when a call goes wrong (e.g. naive `token.symbol()` on DAI) and we need to handle these explicitly.

This PR converts a lot of the token fallback-related bits into simpler Promise-based code and adds explicit handlers for their error cases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DAI is not visible in Finance app after update
3 participants