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

[BlockchainApi] Fix exchange transactions #3565

Merged
merged 13 commits into from
Apr 24, 2020

Conversation

jeanregisser
Copy link
Contributor

@jeanregisser jeanregisser commented Apr 23, 2020

Description

This PR restores functionality for the wallet activity feed regarding exchange transactions.

The existing API we used broke because there are now events emitted when paying for fees in cUSD. See discussion in https://celo-org.slack.com/archives/CMX4JFMQW/p1586526953169900

A new API has been added to blockscout in order to get all cUSD and cGLD transfers happening in transactions.
This work has been done by @mrsmkl in celo-org/blockscout#102 which has already been deployed on alfajores.

For transactions paying for fees in cUSD we try to detect transfers related to fees (validator, gateway fee recipient, community fund).
This has risks of breaking, so I've put assertions so we can detect if it happens in the future.

Other changes

  • Removed obsolete feed events query (had been deprecated)

Tested

Deployed on alfajores and tested successfully.

Related issues

Backwards compatibility

Yes

@jeanregisser jeanregisser requested review from asaj, mrsmkl and a team April 23, 2020 16:34
@jeanregisser jeanregisser added the automerge Have PR merge automatically when checks pass label Apr 23, 2020
@codecov
Copy link

codecov bot commented Apr 23, 2020

Codecov Report

Merging #3565 into master will increase coverage by 0.07%.
The diff coverage is 81.17%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3565      +/-   ##
==========================================
+ Coverage   74.79%   74.87%   +0.07%     
==========================================
  Files         622      622              
  Lines       15848    15828      -20     
  Branches     1739     2055     +316     
==========================================
- Hits        11854    11851       -3     
+ Misses       3618     3604      -14     
+ Partials      376      373       -3     
Flag Coverage Δ
#mobile 75.41% <ø> (ø)
#web 74.19% <81.17%> (+0.16%) ⬆️
Impacted Files Coverage Δ
packages/blockchain-api/src/schema.ts 34.21% <ø> (+1.71%) ⬆️
packages/blockchain-api/src/utils.ts 37.25% <0.00%> (+2.06%) ⬆️
packages/blockchain-api/test/mockTokenTxs.ts 100.00% <ø> (ø)
packages/blockchain-api/src/blockscout.ts 78.57% <83.13%> (+6.23%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ece1aa5...59214b9. Read the comment docs.

Copy link
Contributor

@jmrossy jmrossy left a comment

Choose a reason for hiding this comment

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

LGTM, two optional comments below

}
break

case 2: // Exchange events have two corresponding transfers (in and out)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this large function be broken apart? I'm not sure having a big chunk of code in a switch case is best for readability

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep done 👍

})
default:
// Warn if anything else happens
console.warn(`Unhandled transfers for tx ${transferTx.transactionHash}`)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: maybe error here? We should probably set up alerts for this. Having an error code enum defined somewhere would help with that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes!

@jmrossy jmrossy removed the automerge Have PR merge automatically when checks pass label Apr 23, 2020
@jeanregisser jeanregisser self-assigned this Apr 24, 2020
@jeanregisser jeanregisser added the automerge Have PR merge automatically when checks pass label Apr 24, 2020
@mergify mergify bot merged commit 40cb83a into master Apr 24, 2020
mergify bot pushed a commit that referenced this pull request May 6, 2020
### Description

The notification service was picking the wrong address for the transfer, because of the events which changed at the transaction layer, similar to what we had to fix in `blockchain-api` in #3565.

Each transaction contains the actual transfer and also fee transfers. The previous code was only considering the last transfer emitted for the transaction, which was a fee transfer.

Note: we could also filter out fee transfers like we did for `blockchain-api`, but there's no harm leaving them for now (they won't have any matching fcm token).

### Other changes

- Don't create a Sentry event when a notification is received while in background. There is nothing that needs to be done. (Example: https://sentry.io/organizations/celo/issues/1648609728/?project=1250733&query=is%3Aunresolved)

### Tested

- Deployed on Alfajores:
  - Push notifications are sent again to the correct user address when sending money.

### Related issues

- Fixes #1339

### Backwards compatibility

Yes.
@jeanregisser jeanregisser deleted the jeanregisser/fix-blockchain-api-exchanges branch June 11, 2020 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Have PR merge automatically when checks pass
Projects
None yet
2 participants