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

refactor(send): execute prepared transaction in saga #5001

Merged
merged 7 commits into from
Mar 4, 2024

Conversation

satish-ravi
Copy link
Contributor

@satish-ravi satish-ravi commented Feb 28, 2024

Description

Execute prepared tx directly in the send saga instead of using the viem/saga's send payment method, which was simulating a contract call and then executing it.

Test plan

Manual, CI

Related issues

Backwards compatibility

Yes

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)

src/viem/saga.ts Outdated
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was using the wrapSendTransactionWithRetry method, which attempts to retry after a timeout of 90s, but the retry count was set to only 1, all of this is removed in the send saga, which now matches with what the swap saga is doing currently.
Also, this was firing events at each stage of the transaction, but the send saga already covers most of it, we only lose out on some intermediate events,transaction_hash_received and transaction_receipt_received, which seem more like debugging events.
I don't think either of these are required anymore, but can add these back if there's a strong reason

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there harm in including these in the updated saga? Seems like there are clear places where they would fit?

If these are truly never used by anyone though, I think it's fine to get rid of them. Are there any other actual uses of these events in code though? If we remove them here, can we clean them up from the app entirely?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would be weird just to include those tx events and don't fire other tx events. These aren't fired for swaps, so don't think we need to fire them for sends.
These are still used in the old contract-kit sends, we can clean them up once we remove it.

Copy link

codecov bot commented Feb 28, 2024

Codecov Report

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

Project coverage is 85.49%. Comparing base (722017d) to head (b225571).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5001      +/-   ##
==========================================
- Coverage   85.54%   85.49%   -0.05%     
==========================================
  Files         724      723       -1     
  Lines       29612    29462     -150     
  Branches     5127     5099      -28     
==========================================
- Hits        25331    25188     -143     
+ Misses       4046     4039       -7     
  Partials      235      235              
Files Coverage Δ
src/send/SendConfirmation.tsx 91.33% <ø> (ø)
src/send/actions.ts 100.00% <100.00%> (ø)
src/send/saga.ts 68.05% <93.10%> (+9.85%) ⬆️

... and 2 files 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 722017d...b225571. Read the comment docs.

Base automatically changed from satish/act-1049-send-confirmation to main February 29, 2024 02:57
Copy link

emerge-tools bot commented Feb 29, 2024

1 build increased size

Name Version Download Change Install Change Approval
⚠️ Celo (test)
org.celo.mobile.test
1.79.0 (144) 26.5 MB ⬆️ 2.4 MB (9.81%) 63.0 MB ⬆️ 2.7 MB (4.44%) N/A

Celo (test) 1.79.0 (144)
org.celo.mobile.test

⚖️ Compare build
📦 Install build
⏱️ Analyze build performance

Total install size change: ⬆️ 2.7 MB (4.44%)
Total download size change: ⬆️ 2.4 MB (9.81%)

Largest size changes

Item Install Size Change
📝 splashBackground@3x.jpg ⬆️ 600.2 kB
📝 background@3x.jpg ⬆️ 368.6 kB
📝 boost-rewards@3x.png ⬆️ 188.4 kB
📝 background@2x.jpg ⬆️ 176.1 kB
📝 boost-rewards@2x.png ⬆️ 90.1 kB
View Treemap

Image of diff


🛸 Powered by Emerge Tools

}
} else {
throw new Error('No address found on recipient')
if (tokenInfo?.symbol === 'CELO') {
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 worth having a test for this event?

src/viem/saga.ts Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there harm in including these in the updated saga? Seems like there are clear places where they would fit?

If these are truly never used by anyone though, I think it's fine to get rid of them. Are there any other actual uses of these events in code though? If we remove them here, can we clean them up from the app entirely?

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.

Great!!

Looking forward to when we can combine the logic for send/swap/wc too, but that will be more work :D

src/send/saga.ts Outdated
)

if (receipt.status === 'reverted') {
throw new Error('transaction reverted')
Copy link
Member

Choose a reason for hiding this comment

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

nit: would be nice to include the txHash in the error message for debugging purposes.

src/send/saga.ts Outdated
Comment on lines 288 to 289
yield* put(showErrorOrFallback(err, ErrorMessages.SEND_PAYMENT_FAILED))
yield* put(sendPaymentFailure())
Copy link
Member

Choose a reason for hiding this comment

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

Looks like we wouldn't want the error message if the pin was cancelled.

And maybe not the sendPaymentFailure()? Unless it's used for switching the button state back to enabled.

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 showErrorOrFallback will show a pin required error message, and sendPaymentFailure just resets the isSending state so should be fine to include.
I was confused by this as well originally 😄. left a couple of comments

Copy link
Member

Choose a reason for hiding this comment

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

ok, I guess what I'm suggesting is we change the UX to not display an error message if the pin was cancelled, and not proceed. It's slightly annoying to see the error in that case, since the user decided to cancel.
We did that for swap.

wallet/src/swap/saga.ts

Lines 378 to 383 in fb39d99

} catch (err) {
if (err === CANCELLED_PIN_INPUT) {
Logger.info(TAG, 'Swap cancelled by user')
yield* put(swapCancel(swapId))
return
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

makes sense, I think there are a few differences with how send and swap UX works, like for swap we navigate immediately after submitting the tx to the chain but we block on the confirmation screen for send. Would be good to address all that in a separate PR with all the UX changes.

}
Logger.error(`${TAG}/sendPaymentSaga`, 'Send payment failed', error)
ValoraAnalytics.track(SendEvents.send_tx_error, { error: error.message })
SentryTransactionHub.finishTransaction(SentryTransaction.send_payment)
Copy link
Member

Choose a reason for hiding this comment

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

Should the sentry transaction be in a finally block?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was my original plan, but if the pin is cancelled, we don't start the transaction, so I included it here. But looking at finishTransaction, it looks like it does nothing if a tx with given name isn't found, so should be safe and clean to do it in finally.

@satish-ravi satish-ravi added this pull request to the merge queue Mar 4, 2024
Merged via the queue into main with commit 5b3b1ea Mar 4, 2024
16 checks passed
@satish-ravi satish-ravi deleted the satish/act-1049-saga branch March 4, 2024 22:07
shottah pushed a commit to zed-io/kolektivo that referenced this pull request May 15, 2024
### Description

Execute prepared tx directly in the send saga instead of using the
viem/saga's send payment method, which was simulating a contract call
and then executing it.

### Test plan

Manual, CI

### Related issues

- Fixes ACT-1049

### Backwards compatibility

Yes

### 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.

None yet

3 participants