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 quick pay show additional costs #2955

Conversation

weilbith
Copy link
Contributor

@weilbith weilbith commented Sep 22, 2021

Thank you for submitting this pull request :)

Fixes #2954

Short description

I'm happy about the user flow we have designed here. But I'm not too happy with the code. The quick pay route has become way too big and complex. Though it is quite hard to split it in a helpful way. Somehow it would be nice to outsource the whole payment information stuff with the new mediation interactive logic. But it is to much tied with all the other stuff that it produces more overhead than actual gain.
Furthermore have the latest updates shown that the combination of actions with the channel action form is not flexible enough. While a nice feature, it must become improved with a more generic form approach.

Finally this issue has shown us how much important it is to have #2929 implemented.

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)

Due to recent decisions, the user must always be able to see the full
costs of his transactions before confirming them. This means that
the fully automated transfer by the SDK can not be used anymore as it
might end up in a mediated transfer with additional hidden costs.
To solve this issue the dApp must always decide to do a direct or
mediated transfer. Therefore the former transfer action got replaced by
two new actions: direct transfer and mediated transfer.
The direct transfer will also construct the to use direct route itself.
This is necessary to ensure it will be a direct transfer. Furthermore it
is fine to put this into the action itself, as it will not cause any
hidden costs. This is different for the mediated transfer. Here the user
must decide himself to first query a route (paying the pathfinding
service) and then use this route with the additional fees. Therefore the
mediated transfer action is expecting the route as parameter.
@codecov
Copy link

codecov bot commented Sep 22, 2021

Codecov Report

Merging #2955 (cb46032) into master (490b7b4) will increase coverage by 0.12%.
The diff coverage is 93.44%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2955      +/-   ##
==========================================
+ Coverage   93.32%   93.45%   +0.12%     
==========================================
  Files         207      208       +1     
  Lines        8830     8917      +87     
  Branches     1382     1394      +12     
==========================================
+ Hits         8241     8333      +92     
+ Misses        488      480       -8     
- Partials      101      104       +3     
Flag Coverage Δ
dapp 89.36% <93.44%> (+0.40%) ⬆️
dapp.unit 89.36% <93.44%> (+0.40%) ⬆️
sdk 95.89% <ø> (+0.01%) ⬆️
sdk.e2e 72.43% <ø> (+0.34%) ⬆️
sdk.integration 79.79% <ø> (ø)
sdk.unit 49.04% <ø> (ø)

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

Impacted Files Coverage Δ
raiden-dapp/src/components/icons/Spinner.vue 100.00% <ø> (ø)
raiden-dapp/src/views/QuickPayRoute.vue 87.42% <87.69%> (+2.46%) ⬆️
raiden-dapp/src/components/AmountDisplay.vue 100.00% <100.00%> (ø)
...dapp/src/components/channels/ChannelActionForm.vue 100.00% <100.00%> (ø)
...nents/channels/ChannelDepositAndTransferAction.vue 100.00% <100.00%> (ø)
...mponents/channels/ChannelOpenAndTransferAction.vue 94.73% <100.00%> (ø)
...p/src/components/transfer/DirectTransferAction.vue 100.00% <100.00%> (ø)
...src/components/transfer/MediatedTransferAction.vue 100.00% <100.00%> (ø)
raiden-dapp/src/mixins/action-mixin.ts 94.91% <100.00%> (+12.15%) ⬆️
...aiden-dapp/src/router/guards/no-connected-token.ts 86.66% <100.00%> (+0.95%) ⬆️
... and 3 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 490b7b4...cb46032. Read the comment docs.

Copy link
Contributor

@manuelwedler manuelwedler left a comment

Choose a reason for hiding this comment

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

Thanks for the effort on this great feature! Looks good to me apart from the nitpicks and some questions. As you already pointed out, it will be worth it to refactor the quick pay route later.

raiden-dapp/src/mixins/action-mixin.ts Outdated Show resolved Hide resolved
raiden-dapp/src/views/QuickPayRoute.vue Show resolved Hide resolved
raiden-dapp/src/components/AmountDisplay.vue Show resolved Hide resolved
@weilbith
Copy link
Contributor Author

weilbith commented Oct 28, 2021

As you already pointed out, it will be worth it to refactor the quick pay route later.

Btw: I'm so unhappy with how cluttered this code is and also the recent changes to the action mixin etc, that I was working on an alternative approach in my private time. I think I have a promising approach and it works well so far. Though I just recently started to refactor this whole new approach to make the code more nice and easy for the future (same solution, different code/technique).
Nevertheless I think there will be also the need to outsource the component for the route finding part. We already have such a component but it works completely different for a different workflow. I need to analyze this again and find a solution how to make it generic enough.
Having these both changes I hope we will get back a way more easy to understand and to maintain feature. Also the test should become more simple.

Unfortunately I have/get no time to work on this at work atm. And I'm not always motivated to work on it in my free time. So this might take a little longer. I apologize for the code style here. This is actually not the standard I try to produce.

@weilbith
Copy link
Contributor Author

Proposal:

gscreenshot_2021-10-28-181309

The action components, based on the action mixin are quiet some special
components. But some of them are slightly different than the others.
These are those which include (also) a transfer. So far action are quite
tightly coupled to the usage with action forms in may cases. Though this
might become improved in future, at the moment there is the need for
some actions to take more options to perform their action then the
action form provides (e.g. payment identifier). These have been provided
as special properties which are only defined on a couple of those
actions. This lead to different interfaces of the actions, which is not
nice. Especially where actions are used interchangeable like for the
quick pay feature it is necessary to have a unified interface.

So far this situation was accepted, because all actions that were
different where different the same. And on the quick pay route only
those special actions where used. But with the recent addition of direct
and mediated transfer actions, this has changed. The mediated transfer
now also needs to be provided with a route. This also causes issues in
the quick pay route.

To solve it, a new property has been added to the base action mixin.
This piece of data works the same as the generic `options` argument to
the `handleAction` function of the actions. It is an object that can be
specified individually by each implementing action. The same goes now
for the `fixedRunOptions`. They are supposed to be provided as
an optional component property and can be used as any other data in the
respective actions implementation. Those actions who don't need any
additional options just ignore them.

After all there are some downsides to this approach: type safety. Having
this generic new properties does not allow for any static type checks.
The action will basically fail (or not) when the respective action logic
can not handle the undefined parameters which are expected. But it could
also lead to unintended behavior if they can but work differently then.
After all typical JavaScript issues.
We accept these issues for the moment. The actions were not safe
beforehand as well as this is just the same approach as we took for the
direct/"flexible" action options. There are different approaches to
tackle this issue to detect miss-usage early. Though probably not on
a static code analysis base. Unfortunately none of these approaches is
really the best and it requires more thoughts how to solve it
completely with something that works for both option datasets.
This new features allows to provide a custom slot element to the display
amount. The optional slot will be displayed instead of the actual amount.
The intention behind this feature is to provide a very generic approach
to make the component more adaptive for special cases. An example would
be the case where the amount is not yet known and needs to be fetched
asynchronously. Then the slot can be filled with a spinner component. If
the fetching has been completed, the spinner gets removed (conditionally
rendering) and the amount gets displayed as usual. This also allows to
use the amount display component is cases where the amount might be
undefined in the beginning, but still having this component contributing
to the layout and maybe have a label to it.
The slot approach keeps the component very simple without much impact
and much customization for special scenarios only. So it remains a very
basic component that can be used everywhere.

Furthermore there were small improvements to the code itself. In the
components implementation/template as well as the tests (make them more
explicit).

Finally it is now possible to define an empty label on purpose. Doing so
allows to maintain the layout. This makes for example sense when there
are multiple display components together or the label might change other
time. If the label is completely missing (undefined) the pure amount
will be displayed as always.
The action form component automatically focused the first input field that is
editable. But this might not be always the desired behavior. Therefore a new
property has been added to disable autofocus completely.
Sometimes an amount is associated with a warning. Prominent examples are
when a balance is too low or a price too high. To simply visualize this,
the amount display component has a new flag property to toggle the
warning. This will apply special coloring to the formatted amount then.
Due to recent decisions, the user must always be able to see the full
costs of his transactions before confirming them. This means that
the fully automated transfer by the SDK can not be used anymore as it
might end up in a mediated transfer with additional hidden costs.
To solve this issue the dApp must always decide to do a direct or
mediated transfer.
As a result of this, the quick pay route must manually fetch the available
pathfinding services and select the cheapest one. In case a direct transfer is
not possible but a mediated one, the user will get displayed more payment
information. This includes a new section for the mediation. Here the user sees
the price of the cheapest service once it is known. Then the user can decide
himself to spend the money to fetch a route.
Once the possible routes are fetched, the cheapest one gets selected and the
user can see the mediation fees for this route. The user can now see the
complete of costs the payment will charge him.

While the user has not yet asked to query the pathfinding service for a route,
the quick pay view will show him the alternative payment solution. This will
either be a channel deposit and direct transfer or a channel open and direct
transfer. Once he has received a valid route, this will switch to a mediated
transfer. So far the user can not decide against the fetched route and go back
to the alternative action. As workaround he would need to reload the page and go
straight for it.

The whole section of mediation stuff includes some nice features like visual
progress states, and the detecting if a pathfinding service is too expensive
with visual effects and disabling.

The logic to handle failed transfer got removed as it is not necessary anymore.
It was only used to check that a mediated transfer was not possible and then
decide on an alternative action. This is now build in from the very beginning
and the user has the choice between both.

I'm happy about the user flow we have designed here. But I'm not too happy with
the code. The quick pay route has become way too big and complex. Though it is
quite hard to split it in a helpful way. Somehow it would be nice to outsource
the whole payment information stuff with the new mediation interactive logic.
But it is to much tied with all the other stuff that it produces more overhead
than actual gain.
Furthermore have the latest updates shown that the combination of actions with
the channel action form is not flexible enough. While a nice feature, it must
become improved with a more generic form approach.
There is a special routing guard that checks if the user has any
connected token. If not, it will automatically forces him to route to
the screen where he can connect. There are a few exceptions to this like
the account settings.
This does also prevent a new user to use the quick pay feature right
away. But as the quick pay works also for new users, this must be a new
exception to the guard.
The autofocus features of the channel action form component were not
tested yet. This has become especially important since it is possible to
disable the automatic focus.
When the pathfinding servie is too expensive, the price was shown in red
and the button to fetch a route was disabled. This leaves the user with
no information why. To improve this, instead of the button a warning
message gets displayed. This bascially makes the former 'no routes'
approach more generic an allows to use it for other messages as well.
The price will not be shown in red color anymore as this would be too
much red then.
@weilbith
Copy link
Contributor Author

I'm optimistic and resolve the fixup commits. So we can get this PR merged soon.

@weilbith weilbith force-pushed the feature/dapp-quick-pay-show-additional-costs branch from b2c0d51 to cb46032 Compare October 28, 2021 16:42
Copy link
Contributor

@manuelwedler manuelwedler left a comment

Choose a reason for hiding this comment

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

Looks good now 👍

@weilbith
Copy link
Contributor Author

Btw, as the CHANGELOG hooks is failing due to the PRs branch comes from a fork: as the quickpay feature was not yet part of a release, I think it doesn't make sense to have another entry for it in this log as it is just an improvement of this feature within the same release.

@weilbith weilbith merged commit a50f842 into raiden-network:master Oct 28, 2021
@weilbith weilbith deleted the feature/dapp-quick-pay-show-additional-costs branch October 28, 2021 17:00
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.

dApp: adapt quick pay to show all costs and let user decide on mediation
2 participants