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: thorchain streaming swap progress bar #5192

Merged
merged 6 commits into from
Sep 3, 2023

Conversation

woodenfurniture
Copy link
Member

@woodenfurniture woodenfurniture commented Aug 30, 2023

Description

This adds a progress bar to thorchain streaming swaps.

Includes progress bar and ability to convey the concept of partial fulfilment with reasons for each failure - a value add over viewblock and other interfaces.

Pull Request Type

  • 🐛 Bug fix (Non-breaking Change: Fixes an issue)
  • 🛠️ Chore (Non-breaking Change: Doc updates, pkg upgrades, typos, etc..)
  • 💅 New Feature (Breaking/Non-breaking Change)

Issue (if applicable)

closes #5191

Risk

Risk of broken trade confirmation UI

Testing

  • Test streaming swaps and ensure progress bar appears and works as expected
  • Test non-streaming swaps and ensure progress bar does not appear

Engineering

☝️

Operations

☝️

Screenshots (if applicable)

Before confirmation
image

On confirmation
image

On streaming data loaded
image

On send tx confirmed
image

Progress increasing, matches viewblock
image
image

Streaming complete
image

@woodenfurniture
Copy link
Member Author

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

@woodenfurniture woodenfurniture changed the title feat: initial implementation of streaming progress bar feat: thorchain streaming swap progress bar Sep 1, 2023
@woodenfurniture woodenfurniture marked this pull request as ready for review September 1, 2023 01:55
@woodenfurniture woodenfurniture requested a review from a team as a code owner September 1, 2023 01:55
Copy link
Contributor

@0xApotheosis 0xApotheosis left a comment

Choose a reason for hiding this comment

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

Code-wise looking good, will do a functional pass now.

Copy link
Contributor

@0xApotheosis 0xApotheosis left a comment

Choose a reason for hiding this comment

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

Super cool feature, though I did end up in this state on a small swap:

Screenshot 2023-09-01 at 12 21 08 pm

The stream status never moved on from loading. It might be because the trade was so small it complete in one step?

@woodenfurniture
Copy link
Member Author

woodenfurniture commented Sep 1, 2023

Super cool feature, though I did end up in this state on a small swap:

Screenshot 2023-09-01 at 12 21 08 pm The stream status never moved on from loading. It might be because the trade was so small it complete in one step?

This is intended, the transaction succeeds before the streaming completes. Likely you didnt see the progress bar initialise because it takes about 3-5 mins to pick up the tx from the chain.

If the streaming completes before it's able to see the tx it will stay in that indeterminate loading state, but that isnt possible to work around without wiring this to a websocket watching the receiving chain. I think that should be ok to leave as-is because the user will see the funds, and the progress bar doesnt explicitly say "0%" in this case

I do think we will need to modify the tx status to not say "completed" while it's still streaming, but I hope we can do that in a follow-up because I'm working on changes that will conflict very heavily with that :P

isAnimated: !isComplete,
colorScheme: isComplete ? 'green' : 'blue',
},
attemptedSwaps: count ?? 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering if this is the best vernacular, these were not attempted but actually completed internal swaps?

@gomesalexandre
Copy link
Contributor

The stream status never moved on from loading. It might be because the trade was so small it complete in one step?

Tangentially, is this monkey patched? Such a small swap should obviously not show up as a streaming swap option

Comment on lines 11 to 12
quantity?: number
count?: number
Copy link
Contributor

Choose a reason for hiding this comment

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

These seem undefined for non-streaming swaps, can we perhaps use them as discriminator on whether or not to use the progress bar / "Loading" copy?

Waited a few minutes to ensure the Tx status is properly picked by the THOR node and still got the same response.

image

This might be an edge case, but may be nice to tackle regardless 🙏🏽

Copy link
Member Author

@woodenfurniture woodenfurniture Sep 3, 2023

Choose a reason for hiding this comment

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

In this case I erred on the side of safety and used the schema from the swagger docs to define them as optional or required, and it seems there are no required fields defined for this response.

https://daemon.thorchain.shapeshift.com/lcd/thorchain/doc
image

Copy link
Contributor

@gomesalexandre gomesalexandre left a comment

Choose a reason for hiding this comment

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

Tested locally, LGTM minus a few naming/types comments and a possible improvement of the flow. Didn't test the actual progress bar with a large swap because something something testing funds, will leave this for ops testing.

Non-streaming swap

image image
  • Such regular swaps correctly have no "Loading" nor progress bar

Streaming swaps

Tested with the following monkey-patch

diff --git a/src/lib/swapper/swappers/ThorchainSwapper/getThorTradeQuote/getTradeQuote.ts b/src/lib/swapper/swappers/ThorchainSwapper/getThorTradeQuote/getTradeQuote.ts
index a2e8e57910..708f7d8d21 100644
--- a/src/lib/swapper/swappers/ThorchainSwapper/getThorTradeQuote/getTradeQuote.ts
+++ b/src/lib/swapper/swappers/ThorchainSwapper/getThorTradeQuote/getTradeQuote.ts
@@ -160,9 +160,7 @@ export const getThorTradeQuote = async (
 
   const perRouteValues = [getRouteValues(swapQuote, false)]
 
-  streamingSwapQuote &&
-    swapQuote.expected_amount_out !== streamingSwapQuote.expected_amount_out &&
-    perRouteValues.push(getRouteValues(streamingSwapQuote, true))
+  streamingSwapQuote && perRouteValues.push(getRouteValues(streamingSwapQuote, true))
 
   const getRouteRate = (expectedAmountOutThorBaseUnit: string) => {
     const THOR_PRECISION = 8
image image image image

Can confirm the flow stated by @0xApotheosis above, though I believe this to be an inherent issue of testing this with a monkey-patched streaming swaps for small amounts that aren't actually streaming. Added a possible fix for it in https://github.com/shapeshift/web/pull/5192/files#r1312857963

@0xApotheosis
Copy link
Contributor

The stream status never moved on from loading. It might be because the trade was so small it complete in one step?

Tangentially, is this monkey patched? Such a small swap should obviously not show up as a streaming swap option

Yep, she was indeed monkey patched!

Copy link
Contributor

@0xApotheosis 0xApotheosis left a comment

Choose a reason for hiding this comment

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

Approved as the current issues are intended. Address the suggestions at your discretion.

@woodenfurniture
Copy link
Member Author

Tested locally, LGTM minus a few naming/types comments and a possible improvement of the flow. Didn't test the actual progress bar with a large swap because something something testing funds, will leave this for ops testing.

Non-streaming swap

image image

  • Such regular swaps correctly have no "Loading" nor progress bar

Streaming swaps

Tested with the following monkey-patch

diff --git a/src/lib/swapper/swappers/ThorchainSwapper/getThorTradeQuote/getTradeQuote.ts b/src/lib/swapper/swappers/ThorchainSwapper/getThorTradeQuote/getTradeQuote.ts
index a2e8e57910..708f7d8d21 100644
--- a/src/lib/swapper/swappers/ThorchainSwapper/getThorTradeQuote/getTradeQuote.ts
+++ b/src/lib/swapper/swappers/ThorchainSwapper/getThorTradeQuote/getTradeQuote.ts
@@ -160,9 +160,7 @@ export const getThorTradeQuote = async (
 
   const perRouteValues = [getRouteValues(swapQuote, false)]
 
-  streamingSwapQuote &&
-    swapQuote.expected_amount_out !== streamingSwapQuote.expected_amount_out &&
-    perRouteValues.push(getRouteValues(streamingSwapQuote, true))
+  streamingSwapQuote && perRouteValues.push(getRouteValues(streamingSwapQuote, true))
 
   const getRouteRate = (expectedAmountOutThorBaseUnit: string) => {
     const THOR_PRECISION = 8

image image image image
Can confirm the flow stated by @0xApotheosis above, though I believe this to be an inherent issue of testing this with a monkey-patched streaming swaps for small amounts that aren't actually streaming. Added a possible fix for it in #5192 (files)

For reference some of the quirks are noted here for fix in follow-up 🙂
#5192 (comment)

@woodenfurniture woodenfurniture enabled auto-merge (squash) September 3, 2023 21:35
@0xApotheosis 0xApotheosis merged commit e342faf into develop Sep 3, 2023
3 checks passed
@0xApotheosis 0xApotheosis deleted the streaming-swap-progress-bar branch September 3, 2023 22:44
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.

Create thor streaming progress bar
4 participants