-
-
Notifications
You must be signed in to change notification settings - Fork 4
feat: add support for setSelectedAccounts
#543
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
base: main
Are you sure you want to change the base?
Conversation
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
const selectedAccounts = allAccounts.filter((account) => | ||
accountIdSet.has(account.id), | ||
); | ||
|
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.
BTC snap has 2 methods for updating accounts. One is a full scan which previously was used when an account was created/discovered and the other one is a lighter synchronize which identified updates.
Since now we don't do any scanning on discovery we don't really know when it is the first time we see an account (without storing anything on snaps state).
Thus, on this PR we are going to run a full scan everytime the keyring method gets called and a synchronize on the cron job running every 30 seconds.
Feel free to add your thoughts. We can always store "seen" accounts on the snap state but I am not sure how efficient is going to be if a user creates loads of them.
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.
Makes a lot of sense to me 👍
setSelectedAccounts
setSelectedAccounts
]; | ||
const request = { method: 'synchronizeAccounts' } as JsonRpcRequest; | ||
|
||
it('synchronizes all accounts', async () => { |
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.
it('synchronizes all accounts', async () => { | |
it('synchronizes selected accounts', async () => { |
}); | ||
|
||
it('filters out accounts that have no transaction history', async () => { | ||
it.skip('filters out accounts that have no transaction history', async () => { |
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.
Why do we skip it?
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.
So the filtering was happening when we were discovering accounts which included a full scan. Since now we don't scan the chain for activity we can't know if there were txs or not.
} | ||
case `${KeyringRpcMethod.SetSelectedAccounts}`: { | ||
assert(request, SetSelectedAccountsRequestStruct); | ||
await this.setSelectedAccounts((request as any).params.accountIds); |
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 don't think the as any
is needed here.
On line 149, assert
narrows the type of request
, so that on line 150 request
is of type inferred from the struct.
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 it should be await this.setSelectedAccounts(request.params.accounts);
. I have the change locally but haven't pushed it yet. Will do in a bit.
const isSubset = (first: Set<string>, second: Set<string>): boolean => { | ||
return Array.from(first).every((element) => second.has(element)); | ||
}; |
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.
👌
await this.#accountsUseCases.fullScan(account); | ||
}); | ||
|
||
await Promise.all(scanPromises); |
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.
What about this?
await Promise.all(scanPromises); | |
await Promise.allSettled(scanPromises); |
Ensures that a failing fullScan
call doesn't prevent the others to complete
const scanPromises = selectedAccounts.map(async (account) => { | ||
await this.#accountsUseCases.fullScan(account); | ||
}); |
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.
Can simplify to:
const scanPromises = selectedAccounts.map(async (account) => { | |
await this.#accountsUseCases.fullScan(account); | |
}); | |
const scanPromises = selectedAccounts.map(async (account) => this.#accountsUseCases.fullScan(account)); |
Note
Adds
setSelectedAccounts
RPC (with validation and full scans), updates cron to synchronize only selected accounts, and bumps keyring dependencies.KeyringRpcMethod.SetSelectedAccounts
inKeyringHandler
to validate IDs andfullScan
selected accounts.validateSelectedAccounts
inhandlers/validation.ts
.synchronize
tofalse
increateAccount
.discoverAccounts
now returns all discovered accounts (no history filter).CronHandler
now syncs only accounts returned bygetSelectedAccounts
(requiresSnapsProvider
); constructor and usage updated.SnapsProvider
intoCronHandler
insrc/index.ts
.fullScan
duringdiscover
inAccountUseCases.discover
.@metamask/keyring-api
to^21.1.0
and@metamask/keyring-snap-sdk
to^7.1.0
.snap.manifest.json
version to1.3.0
and shasum.synchronize=false
, and skip history-filter test.Written by Cursor Bugbot for commit 741cddf. This will update automatically on new commits. Configure here.