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

feat(positions): multichain positions #5093

Merged
merged 19 commits into from
Apr 11, 2024
Merged

Conversation

cajubelt
Copy link
Contributor

@cajubelt cajubelt commented Mar 14, 2024

Description

gets positions and shortcuts for whichever networks are enabled in our dynamic config, rather than just celo

relies on valora-inc/hooks#362

Test plan

  • ci
  • manual test with local hooks api on wallet with both ethereum and celo positions (also unearthed a redux migration bug with this! hooray for testing!)

Related issues

fixes https://linear.app/valora/issue/RET-941/%5Bhooks%5D-multichain-support

Backwards compatibility

there is only one place where the new API will affect application code for old app versions, which is in the keyExtractor function in AssetList.tsx. The function returns the following for positions: ${activeTab}-${item.appId}-${item.networkId}-${item.address}-${index}. I think this is ok, since old app versions only get celo positions right now, so when item.networkId evaluates to undefined for them, it shouldn't cause collisions with other positions on other networks.

the other changes are all in analytics events, which should be something we can live with

Network scalability

If a new NetworkId and/or Network are added in the future, the changes in this PR will:

  • Continue to work without code changes, OR trigger a compilation error (guaranteeing we find it when a new network is added)

@MuckT
Copy link
Collaborator

MuckT commented Mar 18, 2024

Looks like there's a schema update needed and some tests that also need to be updated in:

  • src/tokens/PositionItem.test.tsx
  • src/account/SupportContact.test.tsx
  • src/account/zendesk.test.ts
  • src/analytics/selectors.test.ts

I also see one case where we use celoNetwork in src/analytics/ValoraAnalytics.test.ts should this also be updated?

@cajubelt cajubelt marked this pull request as draft March 19, 2024 20:01
@cajubelt cajubelt changed the title chore: update positions types WIP chore: update positions types Mar 19, 2024
Copy link

emerge-tools bot commented Mar 21, 2024

1 build had no size change

Name Version Download Change Install Change Approval
Celo (test)
org.celo.mobile.test
1.82.0 (147) 24.4 MB ⬆️ 2.3 kB 61.0 MB - N/A

Celo (test) 1.82.0 (147)
org.celo.mobile.test

No changes to report


🛸 Powered by Emerge Tools

cajubelt added a commit to valora-inc/hooks that referenced this pull request Apr 2, 2024
… and ethereum (#349)

Changes made:
- updates the api to use Valora's standard network ID's for multichain
requests
- updates curve hook to actually return some data for multichain
requests
- seals off all other hooks with comments indicating whether they can be
extended or are specific to Celo
- uses blockchain api endpoint to get token info (which returns
multichain token metadata and prices, rather than just celo token
metadata and prices)
- refactors to use Valora's standard for token ID's instead of addresses
as token identifiers, to work for positions that include native assets
lacking a contract address, like ETH

BREAKING CHANGE: 'network' becomes 'networkId' in a few places in the
API response. Requests can still use legacy 'network' request parameter,
with either 'celo' or 'celoAlfajores' recognized. The wallet is updated
in [this PR](valora-inc/wallet#5093) to adapt to
the change, but old versions should continue to work without changes,
since the 'network' request is not used for anything critical (see
description on [wallet
PR](valora-inc/wallet#5093) for details)

test plan:
- [x] **Backwards compatibility test**: run manual e2e test with 'main'
branch of wallet (which still uses 'network' in requests and expects
'network' in response data) to verify that positions are queried for and
displayed correctly for legacy app versions, e.g. that the changes are
backwards compatible enough not to break anything. use local hooks
endpoint, local wallet build, and hardcoded wallet address in the
request.
![Simulator Screen Shot - iPhone 14 - 2024-03-20 at 16 48
20](https://github.com/valora-inc/hooks/assets/7979215/ad048f3a-e379-405c-a504-d673f214ac76)

![image](https://github.com/valora-inc/hooks/assets/7979215/8c48eb0d-353c-4519-9a29-4c87fdc7d9cb)
- [x] hunt thru wallet code to make sure the legacy 'network' field on
some response data is not used for anything important
- [x] **Multichain functionality test**: run manual e2e test with
`cajubelt/multichain-positions` branch of wallet, with an account that
has a curve position on ethereum. use local hooks endpoint, local wallet
build, and hardcoded network id in the request.

![simulator_screenshot_6D05642F-8186-429F-86B1-980122A8FBC4](https://github.com/valora-inc/hooks/assets/7979215/2c72b0cf-5702-4696-8b0a-81f7582aba40)
- [x] update existing unit and e2e tests to add coverage for curve on
ethereum. sent the address used in e2e tests a curve lp token.


cc
https://linear.app/valora/issue/RET-941/%5Bhooks%5D-multichain-support
@cajubelt cajubelt changed the title WIP chore: update positions types WIP feat: multichain positions Apr 4, 2024
Copy link
Contributor Author

Choose a reason for hiding this comment

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

for analytics types I kept the "network" key the same, to avoid adding a column to BQ tables. for application code I migrated to "networkId" for consistency with other features

Copy link

codecov bot commented Apr 4, 2024

Codecov Report

Attention: Patch coverage is 95.83333% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 85.78%. Comparing base (97b9c3a) to head (796e25d).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #5093   +/-   ##
=======================================
  Coverage   85.78%   85.78%           
=======================================
  Files         744      744           
  Lines       30348    30382   +34     
  Branches     5238     5244    +6     
=======================================
+ Hits        26033    26064   +31     
- Misses       4076     4079    +3     
  Partials      239      239           
Files Coverage Δ
src/analytics/Properties.tsx 100.00% <ø> (ø)
src/dapps/DappShortcutTransactionRequest.tsx 91.48% <100.00%> (ø)
src/dapps/DappShortcutsRewards.tsx 97.18% <ø> (ø)
src/positions/saga.ts 90.64% <100.00%> (+0.16%) ⬆️
src/positions/slice.ts 28.12% <ø> (ø)
src/redux/store.ts 78.68% <ø> (ø)
src/statsig/constants.ts 100.00% <ø> (ø)
src/tokens/AssetList.tsx 97.29% <100.00%> (ø)
src/tokens/PositionItem.tsx 100.00% <ø> (ø)
test/schemas.ts 90.07% <100.00%> (+0.03%) ⬆️
... and 2 more

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

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

@cajubelt cajubelt changed the title WIP feat: multichain positions feat: multichain positions Apr 4, 2024
@cajubelt cajubelt changed the title feat: multichain positions WIP feat: multichain positions Apr 4, 2024
@cajubelt cajubelt changed the title WIP feat: multichain positions feat(positions): multichain positions Apr 5, 2024
@cajubelt cajubelt marked this pull request as ready for review April 5, 2024 00:20
@@ -74,6 +74,7 @@ const storeWithPositions = {
...storeWithTokenBalances,
positions: {
positions: mockPositions, // Total value of positions is ~$7.91 or ~₱10.52
shortcuts: [],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

previously, the mock schema had an empty list in this field, which wasn't ideal imo because it didn't guarantee that we had compile-time checks for the mock data. when I updated the "root" state mock to include a nonemtpy list of shortcuts, I needed this to simulate a store that did not have any claimable positions

}
type UpdatedToken = { networkId: NetworkId; tokens?: UpdatedToken[] }

function recursivelyUpdateToken(token: LegacyToken): UpdatedToken {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the mock data includes a nested token, so we have test coverage for this

Copy link
Member

@jeanregisser jeanregisser left a comment

Choose a reason for hiding this comment

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

Awesome 🚀

@cajubelt cajubelt added this pull request to the merge queue Apr 9, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 9, 2024
@MuckT MuckT added this pull request to the merge queue Apr 10, 2024
@MuckT MuckT removed this pull request from the merge queue due to a manual request Apr 10, 2024
@MuckT MuckT added this pull request to the merge queue Apr 10, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 10, 2024
@MuckT MuckT added this pull request to the merge queue Apr 11, 2024
Merged via the queue into main with commit 7f4b5cf Apr 11, 2024
16 checks passed
@MuckT MuckT deleted the cajubelt/multichain-positions branch April 11, 2024 15:28
shottah pushed a commit to zed-io/kolektivo that referenced this pull request May 15, 2024
### Description

gets positions and shortcuts for whichever networks are enabled in our
dynamic config, rather than just celo

relies on valora-inc/hooks#362

### Test plan

- ci
- manual test with local hooks api on wallet with both ethereum and celo
positions (also unearthed a redux migration bug with this! hooray for
testing!)

### Related issues

fixes
https://linear.app/valora/issue/RET-941/%5Bhooks%5D-multichain-support

### Backwards compatibility

there is only one place where the new API will affect application code
for old app versions, which is in the `keyExtractor` function in
`AssetList.tsx`. The function returns the following for positions:
`${activeTab}-${item.appId}-${item.networkId}-${item.address}-${index}`.
I think this is ok, since old app versions only get celo positions right
now, so when `item.networkId` evaluates to `undefined` for them, it
shouldn't cause collisions with other positions on other networks.

the other changes are all in analytics events, which should be something
we can live with

### Network scalability

If a new NetworkId and/or Network are added in the future, the changes
in this PR will:

- [x] Continue to work without code changes, OR trigger a compilation
error (guaranteeing we find it when a new network is added)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants