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

Remove function removeFalsyOrEmpty #414

Open
barnjamin opened this issue Aug 11, 2021 · 6 comments
Open

Remove function removeFalsyOrEmpty #414

barnjamin opened this issue Aug 11, 2021 · 6 comments

Comments

@barnjamin
Copy link
Contributor

Subject of the issue

I'm trying to lookup holders of a given asset where they hold >0 tokens.

When I call client.lookupAssetBalances(asset_id).currencyGreaterThan(0).do() the resultant request has no currency-greater-than GET parameter, but setting it to 1 does produce the correct request URL.

I believe this is due to the step where it removes things that look falsy:

function removeFalsyOrEmpty(obj: Record<string, any>) {
for (const key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
// eslint-disable-next-line no-param-reassign
if (!obj[key] || obj[key].length === 0) delete obj[key];
}
}
return obj;
}

I'm not sure what the correct fix is and I've got a temporary work around.

@barnjamin barnjamin added the new-bug Bug report that needs triage label Aug 11, 2021
@Lumene98
Copy link

Lumene98 commented Sep 1, 2021

@chaihoang Do you have updates on this?

@chaihoang
Copy link

@jasonpaulos

@jasonpaulos
Copy link
Contributor

This is definitely a bug that we'd like to fix, but in the meantime community members have noticed that a workaround is to pass 0 as a string, i.e. "0".

@achidlow
Copy link

Are there any end-points in the API where it makes sense to filter out a query parameter that has been set to 0?

If not, can we just exclude that in removeFalsyOrEmpty like so:
if (!obj[key] || obj[key].length === 0)
becomes
if ((!obj[key] && obj[key] !== 0) || obj[key].length === 0)
?

@d13co
Copy link

d13co commented Jun 14, 2023

I hit this too - the '0' workaround does work but this should ideally be fixed, given how old this issue is.

If you think excluding other falsy values is going to be problematic then at least make an exception for Number(0) in that check? "Holders that have at least one micro-unit" is a fairly common use case that everyone trips over currently.

@shiqizng
Copy link
Contributor

shiqizng commented Aug 10, 2023

It may be possible to remove removeFalsyOrEmpty. We need to fix errors like this after removing this function.

Scenario: LookupAccountCreatedApplications path # tests/cucumber/features/unit/v2indexerclient_paths.feature:270
    ✔ Given mock server recording request paths # tests/cucumber/steps/index.js:490
    ✔ When we make a LookupAccountCreatedApplications call with accountID "7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q" applicationID 0 includeAll "false" limit 0 next "" # tests/cucumber/steps/index.js:508
    ✖ Then expect the path used to be "/v2/accounts/7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q/created-applications" # tests/cucumber/steps/index.js:513
        AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
        + actual - expected

        + '/v2/accounts/7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q/created-applications?application-id=0&include-all=false&limit=0&next='
        - '/v2/accounts/7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q/created-applications'

@shiqizng shiqizng removed their assignment Aug 10, 2023
@winder winder added tech debt and removed bug Something isn't working labels Aug 10, 2023
@shiqizng shiqizng changed the title Valid GET parameter of 0 filtered out Remove removeFalsyOrEmpty Aug 10, 2023
@shiqizng shiqizng changed the title Remove removeFalsyOrEmpty Remove function removeFalsyOrEmpty Aug 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants