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

Feature: upgrade balance endpoint #471

Merged
merged 9 commits into from
Sep 6, 2023
Merged

Feature: upgrade balance endpoint #471

merged 9 commits into from
Sep 6, 2023

Conversation

1yam
Copy link
Collaborator

@1yam 1yam commented Sep 1, 2023

Problem:
Currently, the Balance API Endpoint only returns the total balance for an address. And user (also frontend) as no easy way to get number of locked token.

On :
/api/v0/addresses/{address}/balance

Solution:
Enhance the Balance API Endpoint to include the "locked_amount" field in the response, indicating the amount of tokens in use for a specific address.

Example:

{
    "address": "0x9319Ad3B7A8E0eE24f2E639c40D8eD124C5520Ba",
    "balance": 22192,
    "locked_amount": 2726
}

@1yam 1yam changed the title Feature: Upgrade Balance endpoint Feature: Upgrade Balance api endpoint Sep 1, 2023
Copy link
Contributor

@odesenfans odesenfans left a comment

Choose a reason for hiding this comment

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

Looks good, just add tests.

src/aleph/web/controllers/accounts.py Show resolved Hide resolved
@1yam 1yam requested a review from odesenfans September 4, 2023 12:21
@odesenfans odesenfans changed the title Feature: Upgrade Balance api endpoint Feature: upgrade balance endpoint Sep 4, 2023
with session_factory() as session:
session.add(balance)
session.commit()
insert_volume_refs(session, fixture_instance_message)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand why you insert the volumes in this fixture, as it has nothing to do with the balance. I expect 3 fixtures:

  • instance_message
  • instance_message_with_volumes_in_db (depends on the first one)
  • user_balance (depends on nothing).

tests/api/test_balance.py Outdated Show resolved Hide resolved
assert response.status == 200, await response.text()
data = await response.json()
assert data["balance"] == 22192
assert data["locked_amount"] == 6
Copy link
Contributor

Choose a reason for hiding this comment

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

How come this value is so low?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

cause i did only commit the volume and not instances

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, what's the point of importing the instance fixture if you don't use it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

now it's implement too, just miss to add

@odesenfans odesenfans merged commit a307bc1 into aleph-im:master Sep 6, 2023
2 checks passed
@odesenfans odesenfans deleted the 1yam_balance_endpoint branch September 6, 2023 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants