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

feat: add listAccountTransactions method #41

Open
wants to merge 28 commits into
base: main
Choose a base branch
from

Conversation

danroc
Copy link
Contributor

@danroc danroc commented Sep 18, 2024

This method was originally part of the Chain API, but we decided to migrate it to the Keyring API since it's close related to accounts.

Also, it will allow to list the trasactions for a given account ID instead of address, which make it simpler to get the balances for Bitcoin accounts, for example.

Closes: https://github.com/MetaMask/accounts-planning/issues/460
Closes: https://github.com/MetaMask/accounts-planning/issues/453
Replaces: MetaMask/keyring-api#322

@danroc danroc self-assigned this Sep 18, 2024
@danroc danroc added the team-accounts This should be handled by the Accounts Team label Sep 18, 2024
@danroc danroc added DO-NOT-MERGE PRs related to this issue should not be merged and removed team-accounts This should be handled by the Accounts Team labels Sep 24, 2024
@danroc danroc force-pushed the feature/list-account-transactions branch from 4798162 to 9424622 Compare October 9, 2024 14:13
@danroc danroc marked this pull request as ready for review October 9, 2024 14:14
@danroc danroc requested a review from a team as a code owner October 9, 2024 14:14
@danroc danroc removed the DO-NOT-MERGE PRs related to this issue should not be merged label Oct 9, 2024
packages/keyring-api/src/api/transaction.ts Outdated Show resolved Hide resolved
packages/keyring-api/src/api/transaction.ts Outdated Show resolved Hide resolved
packages/keyring-api/src/api/transaction.ts Outdated Show resolved Hide resolved
packages/keyring-api/src/api/transaction.ts Outdated Show resolved Hide resolved
@danroc danroc force-pushed the feature/list-account-transactions branch 2 times, most recently from c77bdf0 to 59e0736 Compare October 10, 2024 08:32
Copy link

socket-security bot commented Oct 10, 2024

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@metamask/utils@9.3.0 None +1 730 kB metamaskbot

🚮 Removed packages: npm/@metamask/utils@9.2.1

View full report↗︎

packages/keyring-api/src/api/keyring.ts Outdated Show resolved Hide resolved
packages/keyring-api/src/api/transaction.ts Outdated Show resolved Hide resolved
packages/keyring-api/src/api/transaction.ts Outdated Show resolved Hide resolved
packages/keyring-api/src/api/transaction.ts Outdated Show resolved Hide resolved
packages/keyring-api/src/api/transaction.ts Outdated Show resolved Hide resolved
packages/keyring-api/src/api/transaction.ts Show resolved Hide resolved
/**
* Next cursor to iterate over the results.
*/
next: exactOptional(string()),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if we should optional(nullable(string())) here...

I was thinking of this example

const keyring = ...;

const pagination = {
  limit: 10,
  next: null, // No cursor yet
};
do {
  const page = await keyring.listAccountTransactions(accountId, pagination);
  // Do something with `page.transactions`...
  pagination.next = page.next;
} while (page.next);

I think we cannot write this code here, because of the exactOptional, right?

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 type was supposed to be used in the request, not the response:

listAccountTransactions(id, {limit: 10});
// or
listAccountTransactions(id, {limit: 10, next: '<cursor_token>'});

But now that you mentioned this case, I think we can do the change you mentioned and repurpose it to be used both ways 🤔 WDYT?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Well... I really liked the exactOptional initially yes, but I'm worried about it being hard to use, so I believe we could just allow null in this case yes.

@danroc danroc added the DO-NOT-MERGE PRs related to this issue should not be merged label Oct 11, 2024
@danroc danroc force-pushed the feature/list-account-transactions branch from 00b9d6f to ee4b6c9 Compare October 16, 2024 20:01
danroc and others added 2 commits October 18, 2024 10:27
Co-authored-by: Charly Chevalier <charly.chevalier@consensys.net>
@danroc danroc force-pushed the feature/list-account-transactions branch from a1fc8eb to ffb1c3a Compare October 19, 2024 08:37
* },
* ```
*/
const AmountStruct = object({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO: Rename to AssetAmountStruct

/**
* Total transaction fee.
*/
fee: AmountStruct,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO: Discuss if it should be an array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DO-NOT-MERGE PRs related to this issue should not be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants