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

Adding handling for errors parsing grant round funds #621

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dgrants/app",
"version": "0.2.42-3aadf31.0",
"version": "0.2.43-5b780bb.0",
"private": true,
"scripts": {
"clean": "rimraf dist",
Expand All @@ -14,9 +14,9 @@
"prettier": "prettier --write ."
},
"dependencies": {
"@dgrants/contracts": "^0.2.30-3aadf31.0",
"@dgrants/dcurve": "^0.2.32-3aadf31.0",
"@dgrants/types": "^0.2.30-3aadf31.0",
"@dgrants/contracts": "^0.2.31-5b780bb.0",
"@dgrants/dcurve": "^0.2.33-5b780bb.0",
"@dgrants/types": "^0.2.31-5b780bb.0",
"@fusion-icons/vue": "^0.0.0",
"@headlessui/vue": "^1.2.0",
"@tailwindcss/aspect-ratio": "^0.2.1",
Expand Down
18 changes: 16 additions & 2 deletions app/src/utils/data/grantRounds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,15 @@ export async function getGrantRound(blockNumber: number, grantRoundAddress: stri
matchingToken = SUPPORTED_TOKENS_MAPPING[matchingTokenAddress];
donationToken = SUPPORTED_TOKENS_MAPPING[donationTokenAddress];
// record the funds as a human readable number
funds = parseFloat(formatUnits(BigNumber.from(funds), SUPPORTED_TOKENS_MAPPING[matchingTokenAddress].decimals));
try {
funds = parseFloat(
formatUnits(BigNumber.from(funds), SUPPORTED_TOKENS_MAPPING[matchingTokenAddress].decimals)
);
} catch {
// If parsing funds for the round fails, ignore the round
console.log('Failed to parse funds for round');
return {};
Copy link
Contributor

Choose a reason for hiding this comment

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

We normally return a grant round which has fields that are expected to be defined based on the type definitions, which aren't necessarily reflected by the LocalForage abstractions—are you sure returning an empty grantRound object like this is safe and won't cause other issues?

Copy link
Member

@metafraction metafraction Jan 20, 2022

Choose a reason for hiding this comment

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

@mds1 what issues do you anticipate? I tested it out and seems to be fixing the error (hanging load) we're seeing, but there could be some unforeseen issues

Copy link
Member

Choose a reason for hiding this comment

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

There could also be a more gracious way of fixing the error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mds1 there are a couple of places we use this method like where we update grant rounds.

We should set a standard way of doing this (if we have not already) throughout our codebase. I.E. if you request an object from a method and it does not exist, fails to retrieve, or has errors, we should consistently return the same thing across the board. That way anywhere we are implementing that method, we can handle the results consistently.

}
} else if (LocalForageData && _lsBlockNumber < blockNumber) {
// get updated metadata
const [newMetaPtr, balance] = await Promise.all([
Expand All @@ -213,7 +221,13 @@ export async function getGrantRound(blockNumber: number, grantRoundAddress: stri
// update to the new metaPtr
metaPtr = newMetaPtr;
// update to the new balance
funds = parseFloat(formatUnits(balance, SUPPORTED_TOKENS_MAPPING[matchingTokenAddress].decimals)).toString();
try {
funds = parseFloat(formatUnits(balance, SUPPORTED_TOKENS_MAPPING[matchingTokenAddress].decimals)).toString();
} catch {
// If parsing funds for the round fails, ignore the round
console.log('Failed to update funds from metadata');
return {};
}
}
// build status against now (unix)
const now = Date.now() / 1000;
Expand Down
4 changes: 2 additions & 2 deletions contracts/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@dgrants/contracts",
"version": "0.2.30-3aadf31.0",
"version": "0.2.31-5b780bb.0",
"devDependencies": {
"@dgrants/types": "^0.2.30-3aadf31.0",
"@dgrants/types": "^0.2.31-5b780bb.0",
"@nomiclabs/hardhat-ethers": "^2.0.2",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@openzeppelin/contracts": "3.4.1-solc-0.7-2",
Expand Down
4 changes: 2 additions & 2 deletions dcurve/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dgrants/dcurve",
"version": "0.2.32-3aadf31.0",
"version": "0.2.33-5b780bb.0",
"private": true,
"description": "distribution generator for GrantCLR in dgrants",
"keywords": [
Expand Down Expand Up @@ -29,7 +29,7 @@
"extends": "../package.json"
},
"dependencies": {
"@dgrants/contracts": "^0.2.30-3aadf31.0",
"@dgrants/contracts": "^0.2.31-5b780bb.0",
"@dgrants/utils": "^0.2.15-8a7e113.0",
"buffer": "^6.0.3",
"ethers": "^5.4.6"
Expand Down
2 changes: 1 addition & 1 deletion types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dgrants/types",
"version": "0.2.30-3aadf31.0",
"version": "0.2.31-5b780bb.0",
"types": "src/index.d.ts",
"scripts": {
"build": "tsc -b .",
Expand Down