Evaluate and add more refactor if needed into cart.js
I believe @octavioamu might be able to shed some light on the fixes which could be done
@mds1 is already on it. He is creating a component for the zksync .
As part of the zkSync refactor, instead of just cleaning up the code and moving it into it's own component, I think we should additionally update our architecture to use zkSync's new batch transfer feature. Using this instead of our "Gitcoin zkSync account" has a lot of benefits:
Because of how the current code is bit of a mess resulting from fixing various edge cases and bugs that arose from the current "Gitcoin zkSync account" approach, I don't think migrating to this new architecture will significantly impact development time, but still would like to get everyone's thoughts here.
@apbendi Please add any details if I missed something!
cc @owocki
This is mostly done, just need to add a few UX things and delete some unneeded code in cart.js.
Question: At what point do we want to save Contribution info to database? Here's my thinking of a flow, which would also resolve #7744. Let me know your thoughts:
Questions on this @mds1— for options 2.i and, especially, 2.ii, what happens if the user closes their browser before the contributions complete?
For option 2.iii, how do we currently handle transaction failures? I believe we account for them later, but I forget how. Nothing we're changing here would impact that process, would it?
for options
2.iand, especially,2.ii, what happens if the user closes their browser before the contributions complete?
There's an L1 deposit, and the user closes the whole browser before that completes: Their cart will still be populated, they'll have funds in zkSync, and they can just re-visit the cart and checkout again, but of course skip the L1 deposit this time. The standard "don't forget to checkout your cart" emails work here.
The user closes the window after the L2 checkout completes but before Gitcoin registers it: The zSync library polls every 500ms for the transaction hashes, so they'd have to close the Gitcoin tab (or the whole window) pretty quickly after checkout is complete. In this case we don't have the user's transaction hashes, but we can try to guess which ones they are by looking through all their zkSync transactions. I think this will be pretty rare, and I'd like to avoid matching up hashes like this if possible.
The user only closes the Gitcoin tab, but not the zkSync tab, before the transfers complete: The zkSync page will throw an error and prevent completing checkout
For option
2.iii, how do we currently handle transaction failures? I believe we account for them later, but I forget how. Nothing we're changing here would impact that process, would it?
The backend transaction validator parses the transaction receipt and marks the transaction as failed in the database
Let me know your thoughts on all this!
Immediately before checkout starts, save off a JSON store blob with all the cart data
@danlipert + @owocki
So when you check out starts , it means when user clicks on L1 / zksync checkout button -> we fire API which would create subscription + contribution object (with state as pending)
We could do it that way also. The reason I suggested the JSON store way is partly because right now for L1 checkouts we dump the data in the JSON store as backup, then create the contribution/subscription objects _after_ we get the transaction hash.
So I was thinking we do a similar process for L2 checkouts also. But with L2, as soon as we get the transaction hash we know the contributions were successful, which is nice.
The other reason I suggested the JSON store way is because there's two downsides I see to the "create contributions early" approach:
Is there a benefit to creating contributions that don't have transaction hashes, then updating them once we do have hashes? There might be something I'm missing!
Like @apbendi asked -> if you close the browsers before second API call frires ,the subscription / contribution objects would remain and would be in pending / failed state ? (how would it switch over to failed state)
Exactly, and that is basically downside 2 above. I don't think there's an easy answer, which is why I prefer creating the contributions/subscriptions as late as possible (only once we have a transaction hash). Because when the contributions/subscriptions don't have transaction hashes, it gets complex if, say, the user modifies their cart before finishing checkout. Now we have add logic to remove or edit certain contributions. Even if they don't edit their cart, we have to implement logic that looks at an item in the cart and matches it an incomplete contribution
Hmm it does make sense going the JSON store way even though it's ugly data !
Could we ensure we remove the entry from JSON store -> when we create a contribution so that way it's evident that
all entries in JSON store are pending contributions ?
We can definitely do that! I'll use a new key for the JSON stores here so they are easily distinguished from existing JSON stores, and will be sure to remove the entry once the contribution is created.
Most helpful comment
We can definitely do that! I'll use a new key for the JSON stores here so they are easily distinguished from existing JSON stores, and will be sure to remove the entry once the contribution is created.