This PR attempts to improve the way we handle failed mutations. There are few instances on QA and Production where actions were failing due to apollo 403 errors, the transaction would still succeed but the form would not proceed to the completed action screen due to the failed apollo calls. This meant the form could be resubmitted over and over resulting in multiple transactions.
It is likely these issues are caused by auth proxy rejecting the mutation. This can happen if auth proxy restarted after the saga has started running as the user will no longer be authenticated.
This PR attempts to improve this experiencing by adding a retry with re-authentication mechanism to all mutations and authentication attempts. If auth proxy rejects the mutation it will prompt the user to sign in again with metamask and reattempt the mutation. If the mutation still fails after this, the form will show an error message and the submit button will be disabled. This is a real edge case scenario and hopefully will never actually be seen in production.
Testing
This is going to be a bit of a pain to test I'm afraid and involves running a deliberately broken version of auth proxy locally to facilitate testing.
Step 1 - Spin up the dev environment as usual and run the create-data script.
Step 2 - Clear your metamask activity and nonce data by opening the metamask extension, going to settings, advanced and then clicking the "Clear activity tab data" button.
Step 3 - Connect your metamask wallet and open the Planex colony.
Step 6 - Switch to the tmp/3669-testing branch on auth proxy. I've made some changes here which will cause the following calls to occasionally fail (this obviously won't be merged in and is just for the sake of testing the changes here): createTransaction, updateTransaction, createDomainMetadata. The authentication check and handler functions will also occasionally fail. The updateDomainMetadata call will always fail.
Step 7 - Run npm run dev on the auth proxy.
From this point on, if your wallet is disconnected and you end up getting kicked out of the colony, it may take a couple of attempts to reconnect the wallet. This is due to the auth proxy changes. I've not added retries to the main wallet connect authentication as we haven't had issues raised in this area.
Step 8 - Okay, back on the Planex colony! Create a new team action and submit the form. Due to the auth proxy changes, we are expecting some of the calls to fail. The CDapp changes introduced in this PR allow us to reattempt these calls and we will be prompted to sign in with metamask when this happens. Whenever a metamask pop up appears, accept the transactions and sign in prompts. Eventually you should make it through.
Compared to master, there is no automatic retry mechanism so the submit button will simply get stuck on "Pending" when a call fails.
Step 9 - Now let's try an "Edit team" action. Submit the form. Due to the auth proxy changes we are expecting this one to fail completely. Accept your way through the metamask prompts until it gets to the metadata mutation which should fail. An error message should appear and the submit button should be disabled to prevent the user from reattempting the transaction. (Note: If the transaction itself fails, the UserHub will open to show the transaction error and the form itself will not show the new apollo error message.)
Step 10 - Feel free to try out some other actions, they should all work similarly to the create team action.
Further testing
Step 11 - Kill your local auth proxy instance, and restart the auth container in docker.
Step 12 - Okay we're back to a bit more of a normal environment now. Try running a bunch of actions and check nothing has broken. Test this with both the metamask wallet and the dev wallet.
Diffs
New stuff ✨
Added mutateWithAuthRetry function
Added authenticateWalletWithRetry function
Changes 🏗
Action form calls authenticateWalletWithRetry instead of authenticateWallet before calling saga
Action form now shows an error on the frontend when there is an apollo error.
All instances of apolloClient.mutate are now wrapped in mutateWithAuthRetry
TODO
[ ] Delete the tmp/3669-testing branch on auth proxy once this is merged
[ ] Remove the transaction retry mechanism to come in a later PR
Description
This PR attempts to improve the way we handle failed mutations. There are few instances on QA and Production where actions were failing due to apollo 403 errors, the transaction would still succeed but the form would not proceed to the completed action screen due to the failed apollo calls. This meant the form could be resubmitted over and over resulting in multiple transactions.
It is likely these issues are caused by auth proxy rejecting the mutation. This can happen if auth proxy restarted after the saga has started running as the user will no longer be authenticated.
This PR attempts to improve this experiencing by adding a retry with re-authentication mechanism to all mutations and authentication attempts. If auth proxy rejects the mutation it will prompt the user to sign in again with metamask and reattempt the mutation. If the mutation still fails after this, the form will show an error message and the submit button will be disabled. This is a real edge case scenario and hopefully will never actually be seen in production.
Testing
This is going to be a bit of a pain to test I'm afraid and involves running a deliberately broken version of auth proxy locally to facilitate testing.
npm install
if you have never used it before.tmp/3669-testing
branch on auth proxy. I've made some changes here which will cause the following calls to occasionally fail (this obviously won't be merged in and is just for the sake of testing the changes here): createTransaction, updateTransaction, createDomainMetadata. The authentication check and handler functions will also occasionally fail. The updateDomainMetadata call will always fail.npm run dev
on the auth proxy.From this point on, if your wallet is disconnected and you end up getting kicked out of the colony, it may take a couple of attempts to reconnect the wallet. This is due to the auth proxy changes. I've not added retries to the main wallet connect authentication as we haven't had issues raised in this area.
https://github.com/user-attachments/assets/38da06c1-8678-4862-a198-ccaa3b0ed6e1
Compared to master, there is no automatic retry mechanism so the submit button will simply get stuck on "Pending" when a call fails.
https://github.com/user-attachments/assets/8c019c4a-641b-401a-8388-ce3e0ac1e954
Further testing
Step 11 - Kill your local auth proxy instance, and restart the auth container in docker.
Step 12 - Okay we're back to a bit more of a normal environment now. Try running a bunch of actions and check nothing has broken. Test this with both the metamask wallet and the dev wallet.
Diffs
New stuff ✨
mutateWithAuthRetry
functionauthenticateWalletWithRetry
functionChanges 🏗
authenticateWalletWithRetry
instead ofauthenticateWallet
before calling sagaapolloClient.mutate
are now wrapped inmutateWithAuthRetry
TODO
tmp/3669-testing
branch on auth proxy once this is mergedResolves #3523 Contributes to #3510