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

Feature/dapp refactor ethereum provider #2702

Conversation

weilbith
Copy link
Contributor

@weilbith weilbith commented May 5, 2021

Preparation for #2689 #2630 #2631 #2598

Short description
This adds no new feature and just shapes/refactors code.

I spend a lot of time to make sure everything remains working as is. Especially the end-to-end tests where quite helpful for many cases. Though the injected provider does not get tested with it and required manual work.

No CHANGELOG entry required.

I had a tough time with Jest mocking system. I'm not 100% happy about the shape of the mocks. But we are on a clock right now.

I did not test after the final rebase on master where I had to fix some conflicts. I trust the CI pipeline.

Some commits in-between had wrong formatting applied. I locally have a slightly different formatting for rare cases. Unfortunately I have not git commit hook. As I had serious issues with rebasing fixup commits and making manual edits to old commits I did not again solved those minor issues. Sorry.

PS:
@taleldayekh if you like we can review this PR together in the office to save time and keep you motivation high for such a big one.

Definition of Done

  • Steps to manually test the change have been documented
  • Acceptance criteria are met
  • Change has been manually tested by the reviewer (dApp)

Steps to manually test the change (dApp)

  1. Make sure all 3 connection methods do still works as before...

The connect dialog does nothing anymore. It shows the first time the
user connects and has the configuration option to use a subkey (which
defaults to true). Besides that is just delays the connection. Also it
does not add any valid information in terms of that the subkey gets
regenerated each time the user connects anyways.
But after all the major reason to get rid of this stuff is because of
the upcoming connection manager. Thereby it will become obsolete anyway.
With this step to remove it, it helps to clean the code a little to
provide a more flat basement to draft on.
Due to multiple historic changes, the connection status got kinda
complicated. This could be simplified by getting rid of the global
loading state. Also is the status now directly part of the state and is
no more a derived property. This simplified a few old test which haven't
been refactored yet. In general it simplifies the usage/management and
readability.
This must have been forgotten at some point in time.
The RaidenService class is closely tight to the Web3Provider and
ConfigProvider classes. At best it should not even know those exist.
Rather a higher level ("dirty") module should orchestrate the usage
between them. This is important as in future there will be different
provider options with according configurations.
To loose the components, the RaidenService now takes all necessary
values - including the ethereum provider instance - as parameters. It is
now the Home view components job to get the provider and configuration
to connect the SDK. Later it is possible to opt in as user to specify
different providers and configurations with visual components.
The whole usage of account, address, main, raiden-*, ... is quite
confusing/inconsistent in the dApp. To keep the changes minimal for the
moment, this just makes clear for this specific part what the parameter
is actually about.
The too complex RaidenService connect function gets more and more
simplified and less tight to its environment. One part it still did was
to evaluate different errors of the SDK and push error states to the
Vuex store. There they got picked up by the Home view component which
uses another component to translate and display them to the user.
Futhermore the stores state got used for the condiational flow.
This is completely over the top. The Home view component calls the
RaidenService plugin directly. Thereby it can get errors directly and
handle them directly. The whole detour is just not necessary. Moving the
error handling directly into the caller is more naturual and heavily
reduces the complexity of the whole information flow and the
RaidenService class.

Furthermore the translation of errors was kinda cumbersome as well. Plus
is was hard to extend, especially for a more generic scenario not only
for connecting. Therefore this got simplified as well, allwing to strip
the whole NoAccessMessage component. In future extension it probably
makes sense to have a small Vue plugin or a Mixin to map the error
codes to translation keys at a single place.
The dialog which handles the upload of a backup state got broken. This
was causes by the recent changes of the RaidenService connect function.
But actually the dialog must not call the connect function anyway.
Rather the backup is stored into the Vuex store and there gets picked up
by the next connection procedure. This was rather an uncontrolled
behavior which eventually could cause bugs. Cleaning this up also
removes the origin issue.

Furthermore while working on this, I detected that the backup state
never gets cleared from the store while the browser tab is active. This
means is the user connects with a backup, then logs out and reconnets
again, it would again use the backup state and overwrite any change that
got applied in-between or causes a failure at the SDK. To fix this, the
backup state gets cleared when the connection prodedure finishes.
The custom EthereumProvider type was a tool to act between the type
conjunction of the SDKs interface and the actual connection methods as
used by the dApp. This could be simplified to make sure that all
connection methods return an JsonRpcProvider. In fact the last not
unified method was the String as direct URL of an Json RPC server.
Within the SDK this is a one-liner to pack it into a JsonRpcProvider
object. As it (heavily) simplifies the typing in the dApp it is good to
just do the packing right here. This is especially attractive when
having the planned connection manager in mind.
@weilbith weilbith requested a review from taleldayekh May 5, 2021 14:27
@codecov
Copy link

codecov bot commented May 5, 2021

Codecov Report

Merging #2702 (589ba42) into master (2da17ee) will decrease coverage by 0.03%.
The diff coverage is 74.69%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2702      +/-   ##
==========================================
- Coverage   92.26%   92.22%   -0.04%     
==========================================
  Files         176      177       +1     
  Lines        7224     7205      -19     
  Branches     1208     1199       -9     
==========================================
- Hits         6665     6645      -20     
- Misses        467      473       +6     
+ Partials       92       87       -5     
Flag Coverage Δ
dapp 86.59% <74.69%> (-0.20%) ⬇️
dapp.unit 86.59% <74.69%> (-0.20%) ⬇️
sdk 94.80% <ø> (+0.02%) ⬆️
sdk.e2e 75.91% <ø> (-0.17%) ⬇️
sdk.integration 80.52% <ø> (+0.02%) ⬆️
sdk.unit 41.84% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...den-dapp/src/components/account/AccountContent.vue 77.77% <0.00%> (-3.00%) ⬇️
...ponents/account/backup-state/UploadStateDialog.vue 87.87% <ø> (+5.02%) ⬆️
raiden-dapp/src/views/Home.vue 50.00% <35.71%> (-32.50%) ⬇️
.../services/ethereum-connection/injected-provider.ts 82.35% <82.35%> (ø)
raiden-dapp/src/services/raiden-service.ts 83.11% <85.48%> (-0.23%) ⬇️
...src/services/ethereum-connection/wallet-connect.ts 93.33% <93.33%> (ø)
raiden-dapp/src/components/AppHeader.vue 100.00% <100.00%> (ø)
raiden-dapp/src/components/HeaderContent.vue 100.00% <100.00%> (ø)
raiden-dapp/src/model/types.ts 100.00% <100.00%> (ø)
raiden-dapp/src/router/guards/connection.ts 90.90% <100.00%> (ø)
... and 11 more

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 2da17ee...589ba42. Read the comment docs.

Copy link
Contributor

@taleldayekh taleldayekh left a comment

Choose a reason for hiding this comment

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

Went through the changes together which gave me a good understanding of the work done. Looks good and thank you!

This commit does not add any new feature to the dApp, but refactors the
design how the dApp gets an Ethereum connection and account to
instantiate the SDK. This new approach has been developed to prepare the

The new design introduces an abstract class which represents an Ethereum
connection, holding the actual network/RPC provider and the account to
use for signing. This abstract class gets them implemented by all the
various connection methods the dApp provides. The intention is to have a
nice and clean type system where the logic to instantiate the SDK and
connect the dApp does not care about where the connection comes from,
but just takes everything that implements this interface. Thereby the
logic handling the connection process can be easily decoupled and stays
static, no matter how many new connection methods get added or removed.
Furthermore is must not care (not yet ready) about how the connections
get configured. This allows the user to take interactively control over
the configuration instead of a static file served by the web-server.

After all, for the moment, the Home view component that handles the
connection just gets a connection instance and passes its properties to
the SDK. The selection and instantiation of the connection however is
now done in the former components was well. This is the part that
becomes replaced with the connection manager at a later point.

Furthermore the does this approach improves the testability of the
touched components. The connection process module is static and
independently testable from the connection method. And each connection
method can be tested individually. Mocking becomes (theoretically) easy.
All by the bounding interface that tights everything together.
@weilbith weilbith force-pushed the feature/dapp-refactor-ethereum-provider branch from a0e2f29 to 589ba42 Compare May 6, 2021 15:35
@weilbith
Copy link
Contributor Author

weilbith commented May 6, 2021

I fixed the stupid linting issues (it was a missing semicolon).
Despite that this does not require a CHANELOG entry. The slight drop of 0.11% coverage is fine, especially as this will improve again. I'll merge this when the CI has run through.

@weilbith weilbith merged commit 89287d1 into raiden-network:master May 6, 2021
@weilbith weilbith deleted the feature/dapp-refactor-ethereum-provider branch May 6, 2021 16:04
@weilbith weilbith self-assigned this May 7, 2021
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.

2 participants