I had a function that returned the most recent 3 payment operations for an account. But I wante to change it so that it would only return the most recent 3 payment operations for only the asset being looked for so I tried adding a map and filter to the observable using pipes. Like so:

    getJohnAccountPaymentOperationsRecent(account_id: string) {
    // using .order() and .limit() to get the 3 most recent transactions(payment operations) only.
    return fromPromise(this.server.operations().forAccount(account_id).order("desc").limit(3).call())
        tap(res => console.log(res)),
        map(res => res['records'].filter(r => r['type'] == 'payment' && r['asset_code'] == 'JOHN')),

The problem is this does the limit before the filtering is done so may show less than 3 transactions (or none at all if the most recent 3 transactions didn't include the asset "JOHN".

How can I apply the filter first and then limit the returned result to only 3?

  • I figured out a work around by putting a "slice pipe" on the angular ngFor that I use to iterate through the returned operations to limit it. I will leave the question in case someone has a different or better way to do what I was trying to do. Oct 11 '18 at 11:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.