-
Notifications
You must be signed in to change notification settings - Fork 126
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
fix: add check to ensure WC indexedDB store had been previously initialized on disconnect #1149
Conversation
…ilability before deleting
… iyk/fix-wallet-connect-disconnect-state
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Your org has enabled the Graphite merge queue for merging into mainAdd the label “graphite-merge-queue” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link. |
@@ -46,17 +46,36 @@ export async function disconnect(config: AlchemyAccountsConfig): Promise<void> { | |||
// Persistence of Wallet Connect connection state on error. | |||
const clearWalletConnectStore = () => { | |||
// Open Wallet Connect Indexed DB | |||
let walletConnectDBExists = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should probably start with the assumption that it isn't initialized
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! Would update to reflect this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually on further testing, it is better we start with the assumption that it is in fact initialized. This is because dbRequest.onUpgradeneeded()
isn't actually called on every request, only when there is a DB version change. This means when we call disconnect()
after walletConnect has created the IDB store, we wouldn't be running that event handler, and thus if we default to false, we wouldn't have a way to change the value to true.
walletConnectDBExists = false; | ||
|
||
// Remove the Database created from the indexedDB.open() call above. | ||
indexedDB.deleteDatabase("WALLET_CONNECT_V2_INDEXED_DB"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't this throw if this state means it's not connected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, by this point the DB would actually already have been created by the previous indexedDB.open()
call made above. It's the behaviour for IDB to create a database if it doesn't exist when we call indexedDB.open()
. So it actually wouldn't throw in this case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, so lemme run this back to see if I understand
db.open
will create a db if it doesn't exist or open the existing one if it does.
if it doesn't exist and thus gets created, that fires the upgrade event here. We know it was created because version is 1 indexed (not 0 indexed?)
Since this only gets called on disconnect, there's no risk that this gets fired when WC first creates the db
@@ -46,17 +46,36 @@ export async function disconnect(config: AlchemyAccountsConfig): Promise<void> { | |||
// Persistence of Wallet Connect connection state on error. | |||
const clearWalletConnectStore = () => { | |||
// Open Wallet Connect Indexed DB | |||
let walletConnectDBExists = true; | |||
const dbOpenRequest = indexedDB.open("WALLET_CONNECT_V2_INDEXED_DB"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to do any other checks here? does indexDb.open
ever throw?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but we're already handling the error case for that with the dbOpenRequest.onerror()
handler below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, other sanity check - we don't need to remove the handlers right? they only get attached to this specific open request, not globally? Wanna make sure that, if you call disconnect (previously logged in as email) and then try to connect with WC for the first time, then you won't end up in a state where this handler deletes the DB because this handler is still registered
Yes! The handlers are only attached to this |
Pull Request Checklist
yarn test
)site
folder, and guidelines for updating/adding docs can be found in the contribution guide)feat!: breaking change
)yarn lint:check
) and fix any issues? (yarn lint:write
)PR-Codex overview
This PR focuses on enhancing the
clearWalletConnectStore
function to handle the scenario where theWALLET_CONNECT_V2_INDEXED_DB
may not exist, ensuring the database is deleted if it is outdated.Detailed summary
walletConnectDBExists
to determine if the database exists.onupgradeneeded
event to delete the database if the version is outdated.